Skip to content

Commit 619259a

Browse files
update hll.c for .FOR fix and support assume reg:error when used in EAs
1 parent e0a4a0f commit 619259a

File tree

2 files changed

+146
-148
lines changed

2 files changed

+146
-148
lines changed

hll.c

Lines changed: 135 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ struct hll_item {
129129
char *counterlines; /* pointer to allocated memory for counters */
130130
uint_32 cmcnt; /* comma counter */
131131
enum hll_cmd cmd; /* start cmd (IF, WHILE, REPEAT) */
132-
bool cond; /* condition */
133132
enum hll_flags flags; /* v2.08: added */
134133
/* All of bellow vars are related to the SWITCH block */
135134
int_32 casecnt; /* case counter */
@@ -1471,18 +1470,6 @@ ret_code HllStartDir(int i, struct asm_tok tokenarray[])
14711470
int cmd = tokenarray[i].tokval;
14721471
char buff[16];
14731472
char buffer[MAX_LINE_LEN * 2];
1474-
char forbuff[MAX_LINE_LEN];
1475-
char forbuffinit[MAX_LINE_LEN];
1476-
char forbuffcond[MAX_LINE_LEN];
1477-
char forbuffcnt[MAX_LINE_LEN];
1478-
char transformed[MAX_LINE_LEN];
1479-
int j;
1480-
int b;
1481-
int size;
1482-
int eqcnt;
1483-
int cmcnt;
1484-
char *p;
1485-
char c;
14861473
struct expr opndx;
14871474
struct asm_tok *t;
14881475
DebugMsg1(("HllStartDir(%s) enter\n", tokenarray[i].string_ptr));
@@ -1632,132 +1619,143 @@ ret_code HllStartDir(int i, struct asm_tok tokenarray[])
16321619
AddLineQueueX(JMPPREFIX "jmp %s", GetLabelStr(hll->labels[LSTART], buff));
16331620
break;
16341621
case T_DOT_FOR:
1635-
/* create the label to loop start */
1636-
hll->labels[LSTART] = GetHllLabel();
1637-
hll->labels[LSKIP] = GetHllLabel();
1638-
hll->labels[LCONT] = 0;
1639-
hll->labels[LTEST] = 0;
1640-
hll->flags = 0;
1641-
hll->cmd = HLL_FOR;
1642-
/* check for 2 ':',if not throw an error */
1643-
p = tokenarray[i].tokpos;
1644-
for (b = 0; *p; p++)
16451622
{
1646-
if (*p == ':') b++;
1647-
if (*p == 39) break;
1648-
}
1649-
if (b < 2) {
1650-
DebugMsg(("HllStartDir .for loop \n"));
1651-
return(EmitErr(SYNTAX_ERROR_EX, "Missing ':' before ')'"));
1652-
}
1653-
else if (b > 2) {
1654-
DebugMsg(("HllStartDir .for loop \n"));
1655-
return(EmitErr(SYNTAX_ERROR_EX, "Only 2 ':' allowed before ')'"));
1656-
}
1657-
//copy string to the buffer and get read of spaces
1658-
p = tokenarray[i].tokpos;
1659-
for (b = 0; *p; p++)
1660-
{
1661-
if ((*p == ' ') || (*p == '\t')) {
1662-
//if there is QWORD PTR, DWORD PTR, WORD PTR, BYTE PTR, OFFSET or ADDR leave a space between
1663-
c = tolower(*(p + 1));
1664-
if ((c >= 'a') && (c <= 'z')) {
1665-
forbuff[b] = *p;
1666-
b++;
1667-
}
1668-
}
1669-
else {
1670-
forbuff[b] = *p;
1671-
b++;
1623+
char forbuff[MAX_LINE_LEN];
1624+
char forbuffinit[MAX_LINE_LEN];
1625+
char forbuffcond[MAX_LINE_LEN];
1626+
char forbuffcnt[MAX_LINE_LEN];
1627+
char transformed[MAX_LINE_LEN];
1628+
int j;
1629+
int b;
1630+
int size;
1631+
int eqcnt;
1632+
int cmcnt;
1633+
char* p;
1634+
char c;
1635+
1636+
/* create the label to loop start */
1637+
hll->labels[LSTART] = GetHllLabel();
1638+
hll->labels[LCONT] = 0;
1639+
hll->labels[LTEST] = 0;
1640+
hll->flags = 0;
1641+
hll->cmd = HLL_FOR;
1642+
/* check for 2 ':',if not throw an error */
1643+
p = tokenarray[i].tokpos;
1644+
for (b = 0; *p; p++)
1645+
{
1646+
if (*p == ':') b++;
1647+
if (*p == '\'') break;
16721648
}
1673-
}
1674-
forbuff[b] = NULLC;
1675-
if (0 == _memicmp(forbuff, "(::)", 4)) {
1676-
hll->cmcnt = 0;
1677-
}
1678-
else {
1679-
//count initializers
1680-
eqcnt = 1;
1681-
forbuffinit[0] = NULLC;
1682-
for (j = 1, b = 0; forbuff[j];) {
1683-
c = forbuff[j];
1684-
if (c == ':') {
1685-
if (forbuff[j - 1] != 39 && forbuff[j + 1] != 39) break;
1686-
}
1687-
if (c == ',' && forbuff[j - 1] != 39 && forbuff[j + 1] != 39) eqcnt++;
1688-
forbuffinit[b] = c;
1689-
if (c == 39 && forbuffinit[b - 2] == 39) {
1690-
b++;
1691-
forbuffinit[b] = ' ';
1692-
}
1693-
j++;
1694-
b++;
1649+
if (b < 2) {
1650+
DebugMsg(("HllStartDir .for loop \n"));
1651+
return(EmitErr(SYNTAX_ERROR_EX, "Missing ':' before ')'"));
16951652
}
1696-
forbuffinit[b] = NULLC;
1697-
j++;
1698-
//coppy the condition to the buffer
1699-
forbuffcond[0] = NULLC;
1700-
hll->labels[LTEST] = 0;
1701-
for (b = 0; forbuff[j] && forbuff[j] != ':'; forbuffcond[b] = forbuff[j], j++, b++);
1702-
if (forbuffcond[b - 2] == '>' && forbuffcond[b - 1] == '0') forbuffcond[b - 2] = NULLC;
1703-
forbuffcond[b] = NULLC;
1704-
if (!b) hll->cond = FALSE;
1705-
else hll->cond = TRUE;
1706-
j++;
1707-
//copy the counter to the buffer
1708-
cmcnt = 0;
1709-
forbuffcnt[0] = NULLC;
1710-
hll->condlines = "";
1711-
for (b = 0; forbuff[j] != ')'; b++, j++) {
1712-
forbuffcnt[b] = forbuff[j];
1713-
if (forbuffcnt[b] == ',' && forbuff[j - 1] != 39 && forbuff[j + 1] != 39) ++cmcnt;
1714-
if (forbuffcnt[b] == 39 && forbuffcnt[b - 2] == 39) {
1715-
b++;
1716-
forbuffcnt[b] = ' ';
1717-
}
1653+
else if (b > 2) {
1654+
DebugMsg(("HllStartDir .for loop \n"));
1655+
return(EmitErr(SYNTAX_ERROR_EX, "Only 2 ':' allowed before ')'"));
17181656
}
1719-
if (forbuffcnt[b - 1] == ')') b--;
1720-
forbuffcnt[b] = NULLC;
1721-
//create valid command and add to LineQueue to initiate .for loop vars
1722-
//anything that is before the first ':'
1723-
if (forbuffinit[0]) ForInitAndNext(tokenarray, eqcnt, forbuffinit);
1724-
//note hll->counterlines is new var in the struct hll_item for store of forbuffcnt used in .ENDFOR
1725-
//hll->cmcnt is also new var in the struct hll_item for commas counter used in .ENDFOR
1726-
//copy forbuffcnt context to hll->counterlines
1727-
//forbuffcnt contains anything that is written after the second ':'
1728-
hll->cmcnt = 0;
1729-
if (forbuffcnt[0])
1657+
//copy string to the buffer and get read of spaces
1658+
p = tokenarray[i].tokpos;
1659+
for (b = 0; *p; p++)
17301660
{
1731-
//skip altering conditions the first time
1732-
AddLineQueueX(" jmp %s", GetLabelStr(hll->labels[LSKIP], buff));
1733-
size = (int)strlen(forbuffcnt) + 1;
1734-
hll->counterlines = LclAlloc(size);
1735-
memcpy(hll->counterlines, forbuffcnt, size);
1736-
hll->cmcnt = cmcnt + 1;
1661+
if ((*p == ' ') || (*p == '\t')) {
1662+
//if there is QWORD PTR, DWORD PTR, WORD PTR, BYTE PTR, OFFSET or ADDR leave a space between
1663+
c = tolower(*(p + 1));
1664+
if ((c >= 'a') && (c <= 'z')) {
1665+
forbuff[b] = *p;
1666+
b++;
1667+
}
1668+
}
1669+
else {
1670+
forbuff[b] = *p;
1671+
b++;
1672+
}
17371673
}
1738-
else hll->counterlines = ""; //there is nothing after the second ':'
1739-
if (forbuffcond[0]) {
1740-
strcpy(transformed, ".for ");
1741-
strcat(transformed, forbuffcond);
1742-
strcat(transformed, "\0");
1743-
tokenarray[0].string_ptr = ".for\0";
1744-
tokenarray[0].tokpos = transformed;
1745-
Token_Count = Tokenize(tokenarray[0].tokpos, 0, tokenarray, 0);
1746-
if (tokenarray[i].token != T_FINAL) {
1747-
rc = EvaluateHllExpression(hll, &i, tokenarray, LSTART, TRUE, buffer);
1748-
if (rc == NOT_ERROR) {
1749-
size = (int)strlen(buffer) + 1;
1750-
hll->condlines = LclAlloc(size);
1751-
memcpy(hll->condlines, buffer, size);
1752-
DebugCmd(cntCond++); DebugCmd(cntCondBytes += size);
1674+
forbuff[b] = NULLC;
1675+
//{
1676+
//count initializers
1677+
eqcnt = 1;
1678+
forbuffinit[0] = NULLC;
1679+
for (j = 1, b = 0; forbuff[j];) {
1680+
c = forbuff[j];
1681+
if (c == ':') {
1682+
if (forbuff[j - 1] != 39 && forbuff[j + 1] != 39) break;
1683+
}
1684+
if (c == ',' && forbuff[j - 1] != 39 && forbuff[j + 1] != 39) eqcnt++;
1685+
forbuffinit[b] = c;
1686+
if (c == 39 && forbuffinit[b - 2] == 39) {
1687+
b++;
1688+
forbuffinit[b] = ' ';
1689+
}
1690+
j++;
1691+
b++;
17531692
}
1754-
}
1755-
else
1693+
forbuffinit[b] = NULLC;
1694+
j++;
1695+
//coppy the condition to the buffer
1696+
forbuffcond[0] = NULLC;
1697+
for (b = 0; forbuff[j] && forbuff[j] != ':'; forbuffcond[b] = forbuff[j], j++, b++);
1698+
if (forbuffcond[b - 2] == '>' && forbuffcond[b - 1] == '0') forbuffcond[b - 2] = NULLC;
1699+
forbuffcond[b] = NULLC;
1700+
j++;
1701+
//copy the counter to the buffer
1702+
cmcnt = 0;
1703+
forbuffcnt[0] = NULLC;
17561704
hll->condlines = "";
1757-
}
1705+
for (b = 0; forbuff[j] != ')'; b++, j++) {
1706+
forbuffcnt[b] = forbuff[j];
1707+
if (forbuffcnt[b] == ',' && forbuff[j - 1] != 39 && forbuff[j + 1] != 39) ++cmcnt;
1708+
if (forbuffcnt[b] == 39 && forbuffcnt[b - 2] == 39) {
1709+
b++;
1710+
forbuffcnt[b] = ' ';
1711+
}
1712+
}
1713+
if (forbuffcnt[b - 1] == ')') b--;
1714+
forbuffcnt[b] = NULLC;
1715+
//create valid command and add to LineQueue to initiate .for loop vars
1716+
//anything that is before the first ':'
1717+
if (forbuffinit[0]) ForInitAndNext(tokenarray, eqcnt, forbuffinit);
1718+
//note hll->counterlines is new var in the struct hll_item for store of forbuffcnt used in .ENDFOR
1719+
//hll->cmcnt is also new var in the struct hll_item for commas counter used in .ENDFOR
1720+
//copy forbuffcnt context to hll->counterlines
1721+
//forbuffcnt contains anything that is written after the second ':'
1722+
hll->cmcnt = 0;
1723+
if (forbuffcnt[0])
1724+
{
1725+
size = (int)strlen(forbuffcnt) + 1;
1726+
hll->counterlines = LclAlloc(size);
1727+
memcpy(hll->counterlines, forbuffcnt, size);
1728+
hll->cmcnt = cmcnt + 1;
1729+
}
1730+
else hll->counterlines = ""; //there is nothing after the second ':'
1731+
if (forbuffcond[0]) {
1732+
//jump to test the first time
1733+
hll->labels[LTEST] = GetHllLabel();
1734+
AddLineQueueX(" jmp %s", GetLabelStr(hll->labels[LTEST], buff));
1735+
strcpy(transformed, ".for ");
1736+
strcat(transformed, forbuffcond);
1737+
strcat(transformed, "\0");
1738+
tokenarray[0].string_ptr = ".for\0";
1739+
tokenarray[0].tokpos = transformed;
1740+
Token_Count = Tokenize(tokenarray[0].tokpos, 0, tokenarray, 0);
1741+
if (tokenarray[i].token != T_FINAL) {
1742+
rc = EvaluateHllExpression(hll, &i, tokenarray, LSTART, TRUE, buffer);
1743+
if (rc == NOT_ERROR) {
1744+
size = (int)strlen(buffer) + 1;
1745+
hll->condlines = LclAlloc(size);
1746+
memcpy(hll->condlines, buffer, size);
1747+
DebugCmd(cntCond++); DebugCmd(cntCondBytes += size);
1748+
}
1749+
}
1750+
else
1751+
hll->condlines = "";
1752+
}
1753+
if (forbuffcnt[0] == NULLC && forbuffcond[0] == NULLC)
1754+
hll->labels[LCONT] = hll->labels[LSTART];
1755+
//}
1756+
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LSTART], buff));
1757+
tokenarray[i].token = T_FINAL;
17581758
}
1759-
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LSTART], buff));
1760-
tokenarray[i].token = T_FINAL;
17611759
break;
17621760
//end of .FOR
17631761
case T_DOT_WHILE:
@@ -2748,31 +2746,20 @@ ret_code HllEndDir(int i, struct asm_tok tokenarray[])
27482746
}
27492747
i++;
27502748
//Insert .CONTINUE label here if there is any
2751-
if (hll->labels[LCONT])
2749+
if (hll->labels[LCONT] && (hll->counterlines[0] || hll->condlines[0]))
27522750
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LCONT], buff));
2753-
//forever loop '.for (::)'
2754-
if (hll->cmcnt == 0) goto adlabel;
2755-
//If counters exist
2756-
else if (hll->counterlines[0]) {
2757-
//here we write counters
2758-
if (hll->counterlines) { //if there is something after second ':' expand it here
2759-
ForInitAndNext(tokenarray, hll->cmcnt, hll->counterlines);
2760-
LclFree(hll->counterlines);
2761-
}
2762-
//first jump from the top happens here after the counters
2763-
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LSKIP], buff));
2751+
if (hll->counterlines[0]) {
2752+
ForInitAndNext(tokenarray, hll->cmcnt, hll->counterlines);
2753+
LclFree(hll->counterlines);
2754+
}
2755+
if (hll->condlines[0]) {
27642756
/* create test label */
2765-
if (hll->labels[LTEST]) {
2766-
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LTEST], buff));
2767-
}
2757+
AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LTEST], buff));
27682758
QueueTestLines(hll->condlines);
27692759
LclFree(hll->condlines);
27702760
}
27712761
else
27722762
AddLineQueueX(" jmp %s", GetLabelStr(hll->labels[LSTART], buff));
2773-
if (!hll->cond)
2774-
adlabel:
2775-
AddLineQueueX(" jmp %s", GetLabelStr(hll->labels[LSTART], buff));
27762763
tokenarray[i].token = T_FINAL;
27772764
break;
27782765
//end of .ENDFOR

parser.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,17 @@ static ret_code memory_operand( struct code_info *CodeInfo, unsigned CurrOpnd, s
17551755
CodeInfo->indexreg = GetRegNo(index);
17561756
}
17571757

1758+
1759+
/* UASM 2.53 check for use of register assumed to ERROR in an EA */
1760+
if (base != EMPTY && StdAssumeTable[GetRegNo(base)].error)
1761+
{
1762+
return(EmitError(USE_OF_REGISTER_ASSUMED_TO_ERROR));
1763+
}
1764+
if (index != EMPTY && StdAssumeTable[GetRegNo(index)].error)
1765+
{
1766+
return(EmitError(USE_OF_REGISTER_ASSUMED_TO_ERROR));
1767+
}
1768+
17581769
/* check for base registers */
17591770
if ( base != EMPTY )
17601771
{

0 commit comments

Comments
 (0)