//
#include "debug.h"
-#include "sect.h"
#include "amode.h"
+#include "direct.h"
#include "mark.h"
+#include "sect.h"
+#include "token.h"
+
-static int siztab[4] = {3, 5, 9, 9};
+static int siztab[4] = { 3, 5, 9, 9 };
//
switch ((int)*tp++)
{
case SYMBOL:
- printf("`%s' ", ((SYM *)*tp)->sname);
- ++tp;
+// printf("`%s' ", ((SYM *)*tp)->sname);
+ printf("`%s' ", symbolPtr[*tp]->sname);
+ tp++;
break;
case CONST:
printf("$%ux ", *tp++);
p.cp = ch->chptr;
ep = ch->chptr + ch->ch_size;
- while(p.cp < ep)
+ while (p.cp < ep)
{
attr = *p.wp++;
loc = *p.lp++;
else
{
printf("`%s' ;\n", (*p.sy)->sname);
- ++p.lp;
+ p.sy++;
}
}
printf("CONST=%ud", *tk++);
break;
case STRING: // STRING <address>
- printf("STRING='%s'", (char *)*tk++);
+// printf("STRING='%s'", (char *)*tk++);
+ printf("STRING='%s'", string[*tk++]);
break;
case SYMBOL: // SYMBOL <address>
- printf("SYMBOL='%s'", (char *)*tk++);
+// printf("SYMBOL='%s'", (char *)*tk++);
+ printf("SYMBOL='%s'", string[*tk++]);
break;
case EOL: // End of line
printf("EOL");
{
int i;
- for(i = 1; i < NSECTS; ++i)
+ for(i=1; i<NSECTS; i++)
{
if (sect[i].scattr & SUSED)
{
#define DEF_KW
#include "kwtab.h"
-TOKEN exprbuf[128]; // Expression buffer
+TOKEN exprbuf[128]; // Expression buffer
+SYM * symbolPtr[1000000]; // Symbol pointers table
// Directive handler table
int (*dirtab[])() = {
switch(*tok)
{
case STRING:
- sprintf(prntstr, "%s", (char *)tok[1]);
+// sprintf(prntstr, "%s", (char *)tok[1]);
+ sprintf(prntstr, "%s", string[tok[1]]);
printf("%s", prntstr);
if (list_fd)
if (tok[1] != SYMBOL)
goto token_err;
- strcpy(prntstr, (char *)tok[2]);
+// strcpy(prntstr, (char *)tok[2]);
+ strcpy(prntstr, string[tok[2]]);
switch(prntstr[0])
{
return ERROR;
}
- ccname = lookup((char *)tok[1], LABEL, 0);
+// ccname = lookup((char *)tok[1], LABEL, 0);
+ ccname = lookup(string[tok[1]], LABEL, 0);
// Make sure symbol is a valid ccdef
if (!ccname || !(ccname->sattre & EQUATEDCC))
}
// Lookup and undef if equated register
- regname = lookup((char *)tok[1], LABEL, 0);
+// regname = lookup((char *)tok[1], LABEL, 0);
+ regname = lookup(string[tok[1]], LABEL, 0);
if (regname && (regname->sattre & EQUATEDREG))
regname->sattre |= UNDEF_EQUR;
return ERROR;
}
- if ((j = open((char *)tok[1], _OPEN_INC)) >= 0)
+// if ((j = open((char *)tok[1], _OPEN_INC)) >= 0)
+ if ((j = open(string[tok[1]], _OPEN_INC)) >= 0)
{
size = lseek(j, 0L, SEEK_END);
chcheck(size);
}
else
{
- errors("cannot open include binary file (%s)", (char *)tok[1]);
+// errors("cannot open include binary file (%s)", (char *)tok[1]);
+ errors("cannot open include binary file (%s)", string[tok[1]]);
return ERROR;
}
if (*tok != SYMBOL)
return error(em);
+#if 0
if ((*func)(tok[1]) != OK)
+#else
+ if ((*func)(string[tok[1]]) != OK)
+#endif
break;
tok += 2;
char buf[128];
char buf1[128];
- if (*tok == STRING) // Leave strings ALONE
+ if (*tok == STRING) // Leave strings ALONE
+#if 0
fn = (char *)*++tok;
+#else
+ fn = string[*++tok];
+#endif
else if (*tok == SYMBOL) // Try to append ".s" to symbols
{
+#if 0
strcpy(buf, (char *)*++tok);
+#else
+ strcpy(buf, string[*++tok]);
+#endif
fext(buf, ".s", 0);
fn = &buf[0];
}
- else // Punt if no STRING or SYMBOL
+ else // Punt if no STRING or SYMBOL
return error("missing filename");
// Make sure the user didn't try anything like:
if (*++tok != EOL)
return error("extra stuff after filename -- enclose it in quotes");
- // Attempt to open the include file in the current directory, then (if that failed) try list
- // of include files passed in the enviroment string or by the "-d" option.
+ // Attempt to open the include file in the current directory, then (if that
+ // failed) try list of include files passed in the enviroment string or by
+ // the "-d" option.
if ((j = open(fn, 0)) < 0)
{
for(i=0; nthpath("RMACPATH", i, buf1)!=0; ++i)
{
j = strlen(buf1);
- if (j > 0 && buf1[j-1] != SLASHCHAR) // Append path char if necessary
+ if (j > 0 && buf1[j-1] != SLASHCHAR) // Append path char if necessary
strcat(buf1, SLASHSTRING);
strcat(buf1, fn);
if ((sy = lookup(p, LABEL, 0)) == NULL)
{
- sy = newsym(p, LABEL, 0);
+ sy = NewSymbol(p, LABEL, 0);
sy->svalue = 0;
sy->sattr = GLOBAL;
}
// dc.b 'string' [,] ...
if (siz == SIZB && *tok == STRING && (tok[2] == ',' || tok[2] == EOL))
{
- i = strlen((const char*)tok[1]);
+// i = strlen((const char*)tok[1]);
+ i = strlen(string[tok[1]]);
if ((challoc - ch_size) < i)
chcheck(i);
- for(p=(char *)tok[1]; *p!=EOS; ++p)
+ for(p=string[tok[1]]; *p!=EOS; ++p)
D_byte(*p);
tok += 2;
if (*tok != SYMBOL)
return error("missing symbol");
- p = (char *)tok[1];
+// p = (char *)tok[1];
+ p = string[tok[1]];
tok += 2;
- if (*p == '.') // Cannot .comm a local symbol
+ if (*p == '.') // Cannot .comm a local symbol
return error(locgl_error);
if ((sym = lookup(p, LABEL, 0)) == NULL)
- sym = newsym(p, LABEL, 0);
+ sym = NewSymbol(p, LABEL, 0);
else
{
if (sym->sattr & DEFINED)
return error(".comm symbol already defined");
}
- sym->sattr = GLOBAL|COMMON|BSS;
+ sym->sattr = GLOBAL | COMMON | BSS;
if (*tok++ != ',')
return error(comma_error);
- if (abs_expr(&eval) != OK) // Parse size of common region
+ if (abs_expr(&eval) != OK) // Parse size of common region
return 0;
- sym->svalue = eval; // Install common symbol's size
+ sym->svalue = eval; // Install common symbol's size
at_eol();
return 0;
}
if (abs_expr(&eval) != OK)
return 0;
- if (*tok == ',') // Eat comma if it's there
+ if (*tok == ',') // Eat comma if it's there
++tok;
}
else
{
if (*tok == SYMBOL)
{
- p = (char *)tok[1];
+// p = (char *)tok[1];
+ p = string[tok[1]];
if (*p == '.')
env = curenv;
if (sy == NULL)
{
- sy = newsym(p, LABEL, env);
+ sy = NewSymbol(p, LABEL, env);
sy->sattr = 0;
}
else if (sy->sattr & DEFINED)
// Globals, Externals etc
extern TOKEN exprbuf[];
+extern SYM * symbolPtr[];
extern int (* dirtab[])();
// Prototypes
//
// Display Error Message
//
-int error(char * s)
+int error(const char * s)
{
char buf[EBUFSIZ];
unsigned int length;
printf("%s", buf);
taglist('E');
- ++errcnt;
+ errcnt++;
return ERROR;
}
extern char * err_fname;
// Prototypes
-int error(char *);
+int error(const char *);
int errors(char *, char *);
int fatal(char *);
int warn(char *);
//
#include "expr.h"
-#include "token.h"
-#include "listing.h"
+#include "direct.h"
#include "error.h"
-#include "procln.h"
-#include "symbol.h"
-#include "sect.h"
+#include "listing.h"
#include "mach.h"
+#include "procln.h"
#include "risca.h"
+#include "sect.h"
+#include "symbol.h"
+#include "token.h"
#define DEF_KW // Declare keyword values
#include "kwtab.h" // Incl generated keyword tables & defs
1 // (the end)
};
-char missym_error[] = "missing symbol";
-char * str_error = "missing symbol or string";
+const char missym_error[] = "missing symbol";
+const char str_error[] = "missing symbol or string";
// Convert expression to postfix
-static TOKEN * tk; // Deposit tokens here
-SYM * lookup();
-SYM * newsym();
+static TOKEN * tk; // Deposit tokens here (this is really a
+ // pointer to exprbuf from direct.c)
+static symbolNum; // Pointer to the entry in symbolPtr[]
//
//
void init_expr(void)
{
- int i; // Iterator
- char * p; // Token pointer
+ int i; // Iterator
+ char * p; // Token pointer
// Initialize token-class table
- for(i=0; i<128; ++i) // Mark all entries END
+ for(i=0; i<128; ++i) // Mark all entries END
tokcl[i] = END;
for(i=0, p=itokcl; *p!=1; p++)
else
tokcl[(int)(*p)] = (char)i;
}
+
+ symbolNum = 0;
}
if (*tok++ != SYMBOL)
return error(missym_error);
+#if 0
p = (char *)*tok++;
+#else
+ p = string[*tok++];
+#endif
+#if 0
if (lookup(p, MACRO, 0) == NULL)
w = 0;
else
w = 1;
+#else
+ w = (lookup(p, MACRO, 0) == NULL ? 0 : 1);
+#endif
*tk++ = CONST;
*tk++ = (TOKEN)w;
if (*tok++ != SYMBOL)
return error(missym_error);
+#if 0
p = (char *)*tok++;
+#else
+ p = string[*tok++];
+#endif
j = 0;
if (*p == '.')
j = curenv;
+#if 0
if ((sy = lookup(p, LABEL, j)) != NULL && (sy->sattr & w))
w = 1;
else
w = 0;
+#else
+ w = ((sy = lookup(p, LABEL, j)) != NULL && (sy->sattr & w) ? 1 : 0);
+#endif
*tk++ = CONST;
*tk++ = (TOKEN)w;
if (*tok != SYMBOL && *tok != STRING)
return error(str_error);
+#if 0
p = (char *)tok[1];
+#else
+ p = string[tok[1]];
+#endif
tok +=2;
if (*tok++ != ',')
if (*tok != SYMBOL && *tok != STRING)
return error(str_error);
+#if 0
p2 = (char *)tok[1];
+#else
+ p = string[tok[1]];
+#endif
tok += 2;
w = (WORD)(!strcmp(p, p2));
*tk++ = *tok++;
break;
case SYMBOL:
+#if 0
p = (char *)*tok++;
+#else
+ p = string[*tok++];
+#endif
j = 0;
if (*p == '.')
sy = lookup(p, LABEL, j);
if (sy == NULL)
- sy = newsym(p, LABEL, j);
+ sy = NewSymbol(p, LABEL, j);
// Check register bank usage
if (sy->sattre & EQUATEDREG)
}
*tk++ = SYMBOL;
+#if 0
*tk++ = (TOKEN)sy;
+#else
+ *tk++ = symbolNum;
+ symbolPtr[symbolNum] = sy;
+ symbolNum++;
+#endif
break;
case STRING:
*tk++ = CONST;
+#if 0
*tk++ = str_value((char *)*tok++);
+#else
+ *tk++ = str_value(string[*tok++]);
+#endif
break;
case '(':
if (expr0() != OK)
char * p;
int j;
- tk = otk;
+ tk = otk; // Set token pointer to 'exprbuf' (direct.c)
+// symbolNum = 0; // Set symbol number in symbolPtr[] to 0
// Optimize for single constant or single symbol.
if ((tok[1] == EOL)
}
else
{
+#if 0
p = (char *)tok[1];
+#else
+ p = string[tok[1]];
+#endif
j = 0;
if (*p == '.')
sy = lookup(p, LABEL, j);
if (sy == NULL)
- sy = newsym(p, LABEL, j);
+ sy = NewSymbol(p, LABEL, j);
sy->sattr |= REFERENCED;
}
*tk++ = SYMBOL;
+#if 0
*tk++ = (TOKEN)sy;
+#else
+ *tk++ = symbolNum;
+ symbolPtr[symbolNum] = sy;
+ symbolNum++;
+#endif
if (sy->sattr & DEFINED)
*a_value = sy->svalue;
*a_attr = (WORD)(sy->sattr & ~GLOBAL);
- if ((sy->sattr & (GLOBAL|DEFINED)) == GLOBAL && a_esym != NULL)
+ if ((sy->sattr & (GLOBAL | DEFINED)) == GLOBAL && a_esym != NULL)
*a_esym = sy;
}
SYM * esym;
WORD sym_seg;
- sval = evstk; // (Empty) initial stack
+ sval = evstk; // (Empty) initial stack
sattr = evattr;
- esym = NULL; // No external symbol involved
+ esym = NULL; // No external symbol involved
sym_seg = 0;
while (*tk != ENDEXPR)
switch ((int)*tk++)
{
case SYMBOL:
- sy = (SYM *)*tk++;
- sy->sattr |= REFERENCED; // Set "referenced" bit
+// sy = (SYM *)*tk++;
+ sy = symbolPtr[*tk++];
+ sy->sattr |= REFERENCED; // Set "referenced" bit
if (!(sy->sattr & DEFINED))
{
+ // Reference to undefined symbol
if (!(sy->sattr & GLOBAL))
- { // Reference to undefined symbol
+ {
*a_attr = 0;
*a_value = 0;
return OK;
}
- if (esym != NULL) // Check for multiple externals
+ if (esym != NULL) // Check for multiple externals
return error(seg_error);
esym = sy;
if (sy->sattr & DEFINED)
{
- *++sval = sy->svalue; // Push symbol's value
+ *++sval = sy->svalue; // Push symbol's value
}
else
{
- *++sval = 0; // 0 for undefined symbols
+ *++sval = 0; // 0 for undefined symbols
}
- *++sattr = (WORD)(sy->sattr & ~GLOBAL); // Push attribs
- sym_seg = (WORD)(sy->sattr & (TEXT|DATA|BSS));
+ *++sattr = (WORD)(sy->sattr & ~GLOBAL); // Push attribs
+ sym_seg = (WORD)(sy->sattr & (TEXT | DATA | BSS));
break;
case CONST:
- *++sval = *tk++; // Push value
- *++sattr = ABS|DEFINED; // Push simple attribs
+ *++sval = *tk++; // Push value
+ *++sattr = ABS | DEFINED; // Push simple attribs
break;
case ACONST:
- *++sval = *tk++; // Push value
- *++sattr = (WORD)*tk++; // Push attribs
+ *++sval = *tk++; // Push value
+ *++sattr = (WORD)*tk++; // Push attribs
break;
// Binary "+" and "-" matrix:
// [1] + : Error
// - : ABS
case '+':
- --sval; // Pop value
- --sattr; // Pop attrib
- *sval += sval[1]; // Compute value
+ --sval; // Pop value
+ --sattr; // Pop attrib
+ *sval += sval[1]; // Compute value
- if (!(*sattr & (TEXT|DATA|BSS)))
+ if (!(*sattr & (TEXT | DATA | BSS)))
*sattr = sattr[1];
- else if (sattr[1] & (TEXT|DATA|BSS))
+ else if (sattr[1] & (TEXT | DATA | BSS))
return error(seg_error);
break;
case '-':
- --sval; // Pop value
- --sattr; // Pop attrib
- *sval -= sval[1]; // Compute value
+ --sval; // Pop value
+ --sattr; // Pop attrib
+ *sval -= sval[1]; // Compute value
- attr = (WORD)(*sattr & (TEXT|DATA|BSS));
+ attr = (WORD)(*sattr & (TEXT | DATA | BSS));
if (!attr)
*sattr = sattr[1];
- else if (sattr[1] & (TEXT|DATA|BSS))
+ else if (sattr[1] & (TEXT | DATA | BSS))
{
if (!(attr & sattr[1]))
return error(seg_error);
else
- *sattr &= ~(TEXT|DATA|BSS);
+ *sattr &= ~(TEXT | DATA | BSS);
}
break;
- // Unary operators only work on ABS items
+ // Unary operators only work on ABS items
case UNMINUS:
- if (*sattr & (TEXT|DATA|BSS))
+ if (*sattr & (TEXT | DATA | BSS))
error(seg_error);
*sval = -(int)*sval;
- *sattr = ABS|DEFINED; // Expr becomes absolute
+ *sattr = ABS | DEFINED; // Expr becomes absolute
break;
case '!':
- if (*sattr & (TEXT|DATA|BSS))
+ if (*sattr & (TEXT | DATA | BSS))
error(seg_error);
*sval = !*sval;
- *sattr = ABS|DEFINED; // Expr becomes absolute
+ *sattr = ABS | DEFINED; // Expr becomes absolute
break;
case '~':
- if (*sattr & (TEXT|DATA|BSS))
+ if (*sattr & (TEXT | DATA | BSS))
error(seg_error);
*sval = ~*sval;
- *sattr = ABS|DEFINED; // Expr becomes absolute
+ *sattr = ABS | DEFINED; // Expr becomes absolute
break;
- // Comparison operators must have two values that
- // are in the same segment, but that's the only requirement.
+ // Comparison operators must have two values that
+ // are in the same segment, but that's the only requirement.
case LE:
--sattr;
--sval;
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval <= sval[1];
break;
case GE:
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval >= sval[1];
break;
case '>':
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval > sval[1];
break;
case '<':
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval < sval[1];
break;
case NE:
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval != sval[1];
break;
case '=':
if ((*sattr & TDB) != (sattr[1] & TDB))
error(seg_error);
- *sattr = ABS|DEFINED;
+ *sattr = ABS | DEFINED;
*sval = *sval == sval[1];
break;
- // All other binary operators must have two ABS items
- // to work with. They all produce an ABS value.
+ // All other binary operators must have two ABS items
+ // to work with. They all produce an ABS value.
default:
// GH - Removed for v1.0.15 as part of the fix for indexed loads.
//if ((*sattr & (TEXT|DATA|BSS)) || (*--sattr & (TEXT|DATA|BSS)))
//error(seg_error);
- *sattr = ABS|DEFINED; // Expr becomes absolute
+ *sattr = ABS | DEFINED; // Expr becomes absolute
switch ((int)tk[-1])
{
case '*':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval *= sval[1];
break;
case '/':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
if (sval[1] == 0)
return error("divide by zero");
break;
case '%':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
if (sval[1] == 0)
return error("mod (%) by zero");
break;
case SHL:
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval <<= sval[1];
break;
case SHR:
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval >>= sval[1];
break;
case '&':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval &= sval[1];
break;
case '^':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval ^= sval[1];
break;
case '|':
--sval;
- --sattr; // Pop attrib
+ --sattr; // Pop attrib
*sval |= sval[1];
break;
default:
- interror(5); // Bad operator in expression stream
+ interror(5); // Bad operator in expression stream
}
}
}
// overiding the symbol segments and not being included :(
//*a_attr = *sattr | sym_seg; // Copy value + attrib
- *a_attr = *sattr; // Copy value + attrib
+ *a_attr = *sattr; // Copy value + attrib
*a_value = *sval;
return OK;
//
// Print a Line to the Listing File
//
-void println(char * ln)
+void println(const char * ln)
{
unsigned int length;
//
// Ship Line `ln' Out; Do Page Breaks and Title Stuff
//
-void ship_ln(char * ln)
+void ship_ln(const char * ln)
{
// If listing level is <= 0, then don't print anything
if (listing <= 0)
if (*tok != STRING)
return error("missing string");
- strcpy(subttl, (char *)tok[1]);
+// strcpy(subttl, (char *)tok[1]);
+ strcpy(subttl, string[tok[1]]);
tok += 2;
if (*tok != STRING)
return error("missing string");
- strcpy(title, (char*)tok[1]);
+// strcpy(title, (char*)tok[1]);
+ strcpy(title, string[tok[1]]);
tok += 2;
if (pageno > 1)
// Prototypes
void init_list(void);
-void ship_ln(char *);
+void ship_ln(const char *);
void taglist(char);
-void println(char *);
+void println(const char *);
void listeol(void);
VALUE dos_date(void);
VALUE dos_time(void);
#include "kwtab.h"
// Common error messages
-char * range_error = "expression out of range";
-char * abs_error = "illegal absolute expression";
-char * seg_error = "bad (section) expression";
-char * rel_error = "illegal relative address";
-char * siz_error = "bad size specified";
-char * undef_error = "undefined expression";
-char * fwd_error = "forward or undefined expression";
+char range_error[] = "expression out of range";
+char abs_error[] = "illegal absolute expression";
+char seg_error[] = "bad (section) expression";
+char rel_error[] = "illegal relative address";
+char siz_error[] = "bad size specified";
+char undef_error[] = "undefined expression";
+char fwd_error[] = "forward or undefined expression";
extern int ea0gen(WORD);
extern int ea1gen(WORD);
{
siz = siz;
+ // Arrange for future fixup
if (!(a0exattr & DEFINED))
- { // Arrange for future fixup
- fixup(FU_BYTE|FU_SEXT, sloc+1, a0expr);
+ {
+ fixup(FU_BYTE | FU_SEXT, sloc + 1, a0expr);
a0exval = 0;
}
else if (a0exval + 0x100 >= 0x200)
#include "amode.h"
// Globals, Externals etc
-extern char *seg_error;
-extern char *undef_error;
-extern char *rel_error;
-extern char *range_error;
-extern char *abs_error;
+extern char seg_error[];
+extern char undef_error[];
+extern char rel_error[];
+extern char range_error[];
+extern char abs_error[];
extern MNTAB machtab[];
// Prototypes
//
#include "macro.h"
-#include "token.h"
+#include "debug.h"
+#include "direct.h"
#include "error.h"
#include "expr.h"
#include "listing.h"
-#include "symbol.h"
#include "procln.h"
-#include "direct.h"
-#include "debug.h"
+#include "symbol.h"
+#include "token.h"
LONG curuniq; // Current macro's unique number
-TOKEN ** argp; // Free spot in argptrs[]
+//TOKEN ** argp; // Free spot in argptrs[]
int macnum; // Unique number for macro definition
+TOKEN * argPtrs[128]; // 128 arguments ought to be enough for anyone
+static int argp;
static LONG macuniq; // Unique-per-macro number
static SYM * curmac; // Macro currently being defined
-static char ** curmln; // Previous macro line (or NULL)
+//static char ** curmln; // Previous macro line (or NULL)
static VALUE argno; // Formal argument count
static LONG * firstrpt; // First .rept line
{
macuniq = 0;
macnum = 1;
- argp = NULL;
+// argp = NULL;
+ argp = 0;
ib_macro();
}
//
// Exit from a Macro;
-// o pop any intervening include files and repeat blocks;
-// o restore argument stack;
-// o pop the macro.
+// -- pop any intervening include files and repeat blocks;
+// -- restore argument stack;
+// -- pop the macro.
//
int exitmac(void)
{
- IMACRO * imacro;
- TOKEN ** p;
-
// Pop intervening include files and .rept blocks
while (cur_inobj != NULL && cur_inobj->in_type != SRC_IMACRO)
fpop();
// o old unique number
// ...and then pop the macro.
- imacro = cur_inobj->inobj.imacro;
+ IMACRO * imacro = cur_inobj->inobj.imacro;
curuniq = imacro->im_olduniq;
- p = --argp;
- argp = (TOKEN **)*argp;
+ /*TOKEN ** p = */argp--;
+// argp = (TOKEN **)*argp;
fpop();
-
mjump_align = 0;
-
return 0;
}
SYM * arg;
if (lookup(argname, MACARG, (int)curmac->sattr) != NULL)
- return(error("multiple formal argument definition"));
- arg = newsym(argname, MACARG, (int)curmac->sattr);
+ return error("multiple formal argument definition");
+
+ arg = NewSymbol(argname, MACARG, (int)curmac->sattr);
arg->svalue = argno++;
return OK;
//
// Add a line to a macro definition; also print lines to listing file (if
// enabled). The last line of the macro (containing .endm) is not included in
-// the macro. A label on that line will be lost. `endflg' is misleading here.
-// It is -1 for all lines but the last one (.endm), when it is 0.
+// the macro. A label on that line will be lost.
+// notEndFlag is -1 for all lines but the last one (.endm), when it is 0.
//
-int defmac1(char * ln, int endflg)
+int defmac1(char * ln, int notEndFlag)
{
PTR p;
LONG len;
if (list_flag)
{
- listeol(); // Flush previous source line
- lstout('.'); // Mark macro definition with period
+ listeol(); // Flush previous source line
+ lstout('.'); // Mark macro definition with period
}
- if (endflg)
+ // This is just wrong, wrong, wrong. It makes up a weird kind of string with
+ // a pointer on front, and then uses a ** to manage them: This is a recipe
+ // for disaster.
+ // How to manage it then?
+ // Could use a linked list, like Landon uses everywhere else.
+/*
+How it works:
+Allocate a space big enough for the string + NULL + pointer.
+Set the pointer to NULL.
+Copy the string to the space after the pointer.
+If this is the 1st time through, set the SYM * "svalue" to the pointer.
+If this is the 2nd time through, derefence the ** to point to the memory you just allocated.
+Then, set the ** to the location of the memory you allocated for the next pass through.
+
+This is a really low level way to do a linked list, and by bypassing all the safety
+features of the language. Seems like we can do better here.
+*/
+ if (notEndFlag)
{
+#if 0
len = strlen(ln) + 1 + sizeof(LONG);
-// p.cp = amem(len);
p.cp = malloc(len);
*p.lp = 0;
strcpy(p.cp + sizeof(LONG), ln);
// Link line of text onto end of list
if (curmln == NULL)
- curmac->svalue = (VALUE)p.cp;
+ curmac->svalue = p.cp;
else
*curmln = p.cp;
curmln = (char **)p.cp;
- return 1; // Keep looking
+ return 1; // Keep looking
+#else
+ if (curmac->lineList == NULL)
+ {
+ curmac->lineList = malloc(sizeof(struct LineList));
+ curmac->lineList->next = NULL;
+ curmac->lineList->line = strdup(ln);
+ curmac->last = curmac->lineList;
+ }
+ else
+ {
+ curmac->last->next = malloc(sizeof(struct LineList));
+ curmac->last->next->next = NULL;
+ curmac->last->next->line = strdup(ln);
+ curmac->last = curmac->last->next;
+ }
+
+ return 1; // Keep looking
+#endif
}
- else
- return 0; // Stop looking at the end
+
+ return 0; // Stop looking at the end
}
// `defmac1' adds lines of text to the macro definition
// `defmac2' processes the formal arguments (and sticks them into the symbol table)
//
-int defmac(void)
+int DefineMacro(void)
{
- char * p;
- SYM * mac;
-
- // Setup entry in symbol table, make sure the macro isn't a duplicate entry, and that
- // it doesn't override any processor mnemonic or assembler directive.
+ // Setup entry in symbol table, make sure the macro isn't a duplicate
+ // entry, and that it doesn't override any processor mnemonic or assembler
+ // directive.
if (*tok++ != SYMBOL)
return error("missing symbol");
- p = (char *)*tok++;
+ char * name = string[*tok++];
- if (lookup(p, MACRO, 0) != NULL)
- return error("multiple macro definition");
+ if (lookup(name, MACRO, 0) != NULL)
+ return error("duplicate macro definition");
- curmac = mac = newsym(p, MACRO, 0);
- mac->svalue = 0;
- mac->sattr = (WORD)(macnum++);
+ curmac = NewSymbol(name, MACRO, 0);
+ curmac->svalue = 0;
+ curmac->sattr = (WORD)(macnum++);
// Parse and define formal arguments in symbol table
if (*tok != EOL)
// Suck in the macro definition; we're looking for an ENDM symbol on a line
// by itself to terminate the definition.
- curmln = NULL;
+// curmln = NULL;
+ curmac->lineList = NULL;
lncatch(defmac1, "endm ");
return 0;
return(0);
goto addln;
case 1: // .rept
- ++rptlevel;
+ rptlevel++;
default:
+//MORE stupidity here...
+#warning "!!! Casting (char *) as LONG !!!"
addln:
// Allocate length of line + 1('\0') + LONG
len = strlen(ln) + 1 + sizeof(LONG);
int k;
if (lnfunc != NULL)
- ++lnsave; // Tell tokenizer to keep lines
+ lnsave++; // Tell tokenizer to keep lines
for(;;)
{
if ((tok[2] == ':' || tok[2] == DCOLON))
{
if (tok[3] == SYMBOL) // label: symbol
+#if 0
p = (char *)tok[4];
+#else
+ p = string[tok[4]];
+#endif
}
else
{
+#if 0
p = (char *)tok[1]; // symbol
+#else
+ p = string[tok[1]]; // Symbol
+#endif
}
}
if (p != NULL)
{
if (*p == '.') // ignore leading '.'s
- ++p;
+ p++;
k = kwmatch(p, dirlist);
}
}
if (lnfunc != NULL)
- --lnsave; // Tell tokenizer to stop keeping lines
+ lnsave--; // Tell tokenizer to stop keeping lines
return 0;
}
++kwlist;
if (*kwlist== ' ')
- ++kwlist;
+ kwlist++;
}
return -1;
// o parse, count and copy arguments
// o push macro's string-stream
//
-int invokemac(SYM * mac, WORD siz)
+int InvokeMacro(SYM * mac, WORD siz)
{
TOKEN * p = NULL;
- IMACRO * imacro;
- INOBJ * inobj;
int dry_run;
- WORD nargs;
WORD arg_siz = 0;
- TOKEN ** argptr = NULL;
- TOKEN * beg_tok;
+// TOKEN ** argptr = NULL;
+//Doesn't need to be global! (or does it???)
+ argp = 0;
if ((!strcmp(mac->sname, "mjump") || !strcmp(mac->sname, "mpad")) && !in_main)
{
return ERROR;
}
- inobj = a_inobj(SRC_IMACRO); // Alloc and init IMACRO
- imacro = inobj->inobj.imacro;
+ INOBJ * inobj = a_inobj(SRC_IMACRO); // Alloc and init IMACRO
+ IMACRO * imacro = inobj->inobj.imacro;
imacro->im_siz = siz;
- nargs = 0;
- beg_tok = tok; // 'tok' comes from token.c
+ WORD nargs = 0;
+ TOKEN * beg_tok = tok; // 'tok' comes from token.c
- for(dry_run=1;; --dry_run)
+ for(dry_run=1; ; dry_run--)
{
for(tok=beg_tok; *tok!=EOL;)
{
if (dry_run)
nargs++;
else
+#if 0
*argptr++ = p;
+#else
+ argPtrs[argp++] = p;
+#endif
// Keep going while tok isn't pointing at a comma or EOL
while (*tok != ',' && *tok != EOL)
{
if (nargs != 0)
//Barfing here with memory corruption in glibc. TOKEN is defined as LONG, which is uint32_t
-// p = (TOKEN *)malloc(arg_siz + 1);
- p = (TOKEN *)malloc(arg_siz + sizeof(TOKEN));
+ p = (TOKEN *)malloc(arg_siz);
+// p = (TOKEN *)malloc(arg_siz + sizeof(TOKEN));
+// This construct is meant to deal with nested macros, so the simple minded way
+// we deal with them now won't work. :-/ Have to think about how to fix.
+#if 0
argptr = (TOKEN **)malloc((nargs + 1) * sizeof(LONG));
*argptr++ = (TOKEN *)argp;
argp = argptr;
+#else
+#endif
}
else
break;
// o bump `macuniq' counter and set 'curuniq' to it;
imacro->im_nargs = nargs;
imacro->im_macro = mac;
- imacro->im_nextln = (TOKEN *)mac->svalue;
+// imacro->im_nextln = (TOKEN *)mac->svalue;
+ imacro->im_nextln = mac->lineList;
imacro->im_olduniq = curuniq;
curuniq = macuniq++;
-/*IMACRO {
- IMACRO * im_link; // Pointer to ancient IMACROs
- LONG * im_nextln; // Next line to include
- WORD im_nargs; // # of arguments supplied on invocation
- WORD im_siz; // Size suffix supplied on invocation
- LONG im_olduniq; // Old value of 'macuniq'
- SYM * im_macro; // Pointer to macro we're in
- char im_lnbuf[LNSIZ]; // Line buffer
-};*/
DEBUG
{
for(nargs=0; nargs<imacro->im_nargs; ++nargs)
{
printf("arg%d=", nargs);
- dumptok(argp[imacro->im_nargs - nargs - 1]);
+// dumptok(argp[imacro->im_nargs - nargs - 1]);
+ dumptok(argPtrs[imacro->im_nargs - nargs - 1]);
}
}
//
void ib_macro(void)
{
- SYM * mac;
-
- curmac = mac = newsym("mjump", MACRO, 0);
- mac->svalue = 0;
- mac->sattr = (WORD)(macnum++);
+ curmac = NewSymbol("mjump", MACRO, 0);
+ curmac->svalue = 0;
+ curmac->sattr = (WORD)(macnum++);
argno = 0;
defmac2("cc");
defmac2("addr");
defmac2("jreg");
- curmln = NULL;
- defmac1(" nop", -1);
- defmac1(" movei #\\addr,\\jreg", -1);
- defmac1(" jump \\cc,(\\jreg)", -1);
- defmac1(" nop", -1);
- defmac1(" nop", -1);
-
- curmac = mac = newsym("mjr", MACRO, 0);
- mac->svalue = 0;
- mac->sattr = (WORD)(macnum++);
+// curmln = NULL;
+ curmac->lineList = NULL;
+ defmac1(" nop", -1);
+ defmac1(" movei #\\addr,\\jreg", -1);
+ defmac1(" jump \\cc,(\\jreg)", -1);
+ defmac1(" nop", -1);
+ defmac1(" nop", -1);
+
+ curmac = NewSymbol("mjr", MACRO, 0);
+ curmac->svalue = 0;
+ curmac->sattr = (WORD)(macnum++);
argno = 0;
defmac2("cc");
defmac2("addr");
- curmln = NULL;
- defmac1(" jr \\cc,\\addr", -1);
- defmac1(" nop", -1);
- defmac1(" nop", -1);
-
- curmac = mac = newsym("mpad", MACRO, 0);
- mac->svalue = 0;
- mac->sattr = (WORD)(macnum++);
+// curmln = NULL;
+ curmac->lineList = NULL;
+ defmac1(" jr \\cc,\\addr", -1);
+ defmac1(" nop", -1);
+ defmac1(" nop", -1);
+
+ curmac = NewSymbol("mpad", MACRO, 0);
+ curmac->svalue = 0;
+ curmac->sattr = (WORD)(macnum++);
argno = 0;
defmac2("size");
- curmln = NULL;
- defmac1(" .rept (\\size/2)", -1);
- defmac1(" nop", -1);
- defmac1(" .endr", -1);
+// curmln = NULL;
+ curmac->lineList = NULL;
+ defmac1(" .rept (\\size/2)", -1);
+ defmac1(" nop", -1);
+ defmac1(" .endr", -1);
}
// Globals, externals etc
extern LONG curuniq;
-extern TOKEN ** argp;
+//extern TOKEN ** argp;
extern int mjump_align;
+extern TOKEN * argPtrs[];
// Prototypes
void init_macro(void);
int exitmac(void);
-int defmac(void);
+int DefineMacro(void);
int defrept(void);
int lncatch(int (*)(), char *);
int kwmatch(char *, char *);
-int invokemac(SYM *, WORD);
+int InvokeMacro(SYM *, WORD);
void ib_macro(void);
#endif // __MACRO_H__
-
if (j == '=' || j == DEQUALS || j == SET || j == REG || j == EQUREG || j == CCDEF)
{
- equate = (char *)tok[1];
+// equate = (char *)tok[1];
+ equate = string[tok[1]];
equtyp = j;
tok += 3;
goto normal;
if (j == ':' || j == DCOLON)
{
as68label:
- label = (char *)tok[1]; // Get label name
+// label = (char *)tok[1]; // Get label name
+ label = string[tok[1]]; // Get label name
labtyp = tok[2]; // Get label type
tok += 3; // Go to next line token
// This is the problem here: On 64-bit platforms, this cuts the native pointer
// in half. We need to figure out how to fix this.
-#warning "!!! Bad pointer !!!"
+//#warning "!!! Bad pointer !!!"
+#if 0
opname = p = (char *)*tok++; // Store opcode name here
+#else
+ opname = p = string[*tok++];
+#endif
// Check to see if the SYMBOL is a keyword (a mnemonic or directive).
// On output, `state' will have one of the values:
if (label != NULL)
warn(lab_ignored);
- defmac();
+ DefineMacro();
}
goto loop;
if (sy == NULL)
{
- sy = newsym(equate, LABEL, j);
+ sy = NewSymbol(equate, LABEL, j);
sy->sattr = 0;
if (equtyp == DEQUALS)
// Checking for a register symbol
else if (tok[0] == SYMBOL)
{
- sy2 = lookup((char *)tok[1], LABEL, j);
+// sy2 = lookup((char *)tok[1], LABEL, j);
+ sy2 = lookup(string[tok[1]], LABEL, j);
// Make sure symbol is a valid equreg
if (!sy2 || !(sy2->sattre & EQUATEDREG))
if (tok[0] == SYMBOL)
{
- sy2 = lookup((char *)tok[1], LABEL, j);
+// sy2 = lookup((char *)tok[1], LABEL, j);
+ sy2 = lookup(string[tok[1]], LABEL, j);
if (!sy2 || !(sy2->sattre & EQUATEDCC))
{
//equ a equr
else if (*tok == SYMBOL)
{
- sy2 = lookup((char *)tok[1], LABEL, j);
+// sy2 = lookup((char *)tok[1], LABEL, j);
+ sy2 = lookup(string[tok[1]], LABEL, j);
if (sy2 && (sy2->sattre & EQUATEDREG))
{
if (sy == NULL)
{
- sy = newsym(label, LABEL, j);
+ sy = NewSymbol(label, LABEL, j);
sy->sattr = 0;
sy->sattre = RISCSYM;
}
if (state < 0)
{
if ((sy = lookup(opname, MACRO, 0)) != NULL)
- invokemac(sy, siz);
+ InvokeMacro(sy, siz);
else
errors("unknown op '%s'", opname);
// Alloc an IFENTRY
if ((rif = f_ifent) == NULL)
-// rif = (IFENT *)amem((LONG)sizeof(IFENT));
rif = (IFENT *)malloc(sizeof(IFENT));
else
f_ifent = rif->if_prev;
if (!disabled)
{
- if (expr(exprbuf, &eval, &eattr, &esym) != OK) return 0;
+ if (expr(exprbuf, &eval, &eattr, &esym) != OK)
+ return 0;
if ((eattr & DEFINED) == 0)
return error(undef_error);
#include "mark.h"
#include "amode.h"
-#define DEF_MR // Declar keyword values
-#include "risckw.h" // Incl generated risc keywords
+#define DEF_MR // Declar keyword values
+#include "risckw.h" // Incl generated risc keywords
-#define DEF_KW // Declare keyword values
-#include "kwtab.h" // Incl generated keyword tables & defs
+#define DEF_KW // Declare keyword values
+#include "kwtab.h" // Incl generated keyword tables & defs
-unsigned altbankok = 0; // Ok to use alternate register bank
-unsigned orgactive = 0; // RISC org directive active
-unsigned orgaddr = 0; // Org'd address
-unsigned orgwarning = 0; // Has an ORG warning been issued
+unsigned altbankok = 0; // Ok to use alternate register bank
+unsigned orgactive = 0; // RISC org directive active
+unsigned orgaddr = 0; // Org'd address
+unsigned orgwarning = 0; // Has an ORG warning been issued
int jpad = 0;
-unsigned previousop = 0; // Used for NOP padding checks
-unsigned currentop = 0; // Used for NOP padding checks
-unsigned mjump_defined, mjump_dest; // mjump macro flags, values etc
+unsigned previousop = 0; // Used for NOP padding checks
+unsigned currentop = 0; // Used for NOP padding checks
+unsigned mjump_defined, mjump_dest; // mjump macro flags, values etc
char reg_err[] = "missing register R0...R31";
//
int risccg(int state)
{
- unsigned short parm; // Opcode parameters
- unsigned type; // Opcode type
- int reg1; // Register 1
- int reg2; // Register 2
- int val = 0; // Constructed value
+ unsigned short parm; // Opcode parameters
+ unsigned type; // Opcode type
+ int reg1; // Register 1
+ int reg2; // Register 2
+ int val = 0; // Constructed value
char scratch[80];
SYM * ccsym;
SYM * sy;
- int i; // Iterator
+ int i; // Iterator
int t, c;
WORD tdb;
- unsigned locptr = 0; // Address location pointer
- unsigned page_jump = 0; // Memory page jump flag
- VALUE eval; // Expression value
- WORD eattr; // Expression attributes
- SYM * esym; // External symbol involved in expr.
- TOKEN r_expr[EXPRSIZE]; // Expression token list
- WORD defined; // Symbol defined flag
+ unsigned locptr = 0; // Address location pointer
+ unsigned page_jump = 0; // Memory page jump flag
+ VALUE eval; // Expression value
+ WORD eattr; // Expression attributes
+ SYM * esym; // External symbol involved in expr.
+ TOKEN r_expr[EXPRSIZE]; // Expression token list
+ WORD defined; // Symbol defined flag
WORD attrflg;
- int indexed; // Indexed register flag
+ int indexed; // Indexed register flag
- parm = (WORD)(roptbl[state-3000].parm); // Get opcode parameter and type
+ parm = (WORD)(roptbl[state-3000].parm); // Get opcode parameter and type
type = roptbl[state-3000].typ;
- // Detect whether the opcode parmeter passed determines that the opcode is specific to only one
- // of the RISC processors and ensure it is legal in the current code section.
- // If not then error and return.
+ // Detect whether the opcode parmeter passed determines that the opcode is
+ // specific to only one of the RISC processors and ensure it is legal in
+ // the current code section. If not then error and return.
if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu))
{
error("opcode is not valid in this code section");
if (*tok != '(')
goto malformed;
- ++tok;
+ tok++;
+
if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok+1) != ')'))
indexed = (*tok - KW_R0);
if (*tok == SYMBOL)
{
- sy = lookup((char *)tok[1], LABEL, 0);
+// sy = lookup((char *)tok[1], LABEL, 0);
+ sy = lookup(string[tok[1]], LABEL, 0);
+
if (!sy)
{
error(reg_err);
if (*tok == SYMBOL)
{
- sy = lookup((char *)tok[1], LABEL, 0);
+// sy = lookup((char *)tok[1], LABEL, 0);
+ sy = lookup(string[tok[1]], LABEL, 0);
if (!sy)
{
if (*tok == SYMBOL)
{
- sy = lookup((char *)tok[1], LABEL, 0);
+// sy = lookup((char *)tok[1], LABEL, 0);
+ sy = lookup(string[tok[1]], LABEL, 0);
if (!sy)
{
if (*tok == SYMBOL)
{
- sy = lookup((char *)tok[1], LABEL, 0);
+// sy = lookup((char *)tok[1], LABEL, 0);
+ sy = lookup(string[tok[1]], LABEL, 0);
if (!sy)
{
for(i=0; i<MAXINTERNCC; i++)
{
- strcpy(scratch, (char *)tok[1]);
+// strcpy(scratch, (char *)tok[1]);
+ strcpy(scratch, string[tok[1]]);
strtoupper(scratch);
if (!strcmp(condname[i], scratch))
if (val == 99)
{
- ccsym = lookup((char *)tok[1], LABEL, 0);
+// ccsym = lookup((char *)tok[1], LABEL, 0);
+ ccsym = lookup(string[tok[1]], LABEL, 0);
if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
{
in_main = 0;
// Initialise modules
- init_sym(); // Symbol table
+ InitSymbolTable(); // Symbol table
init_token(); // Tokenizer
init_procln(); // Line processor
init_expr(); // Expression analyzer
if (sy == NULL)
{
- sy = newsym(argv[argno] + 2, LABEL, 0);
+ sy = NewSymbol(argv[argno] + 2, LABEL, 0);
sy->svalue = 0;
}
// (`lo68' format, extended (postfix) format....)
// (2) generate the output file image and symbol table;
// (3) generate relocation information from left-over fixups.
- fixups(); // Do all fixups
- stopmark(); // Stop mark tape-recorder
+ ResolveAllFixups(); // Do all fixups
+ stopmark(); // Stop mark tape-recorder
if (errcnt == 0)
{
//
// TARGET SPECIFIC BUILD SETTINGS
//
-
#ifdef WIN32
#define PLATFORM "Win32" // Release platform - windows
#define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR
#endif
#endif
+//
+// Non-target specific stuff
+//
#include <inttypes.h>
+#include "symbol.h"
#define BYTE uint8_t
#define WORD uint16_t
#define MWC 1 // Mark Williams object format
#define BSD 2 // BSD object format
-// Symbols
-#define SYM struct _sym
-SYM
-{
- SYM * snext; // * -> Next symbol on hash-chain
- SYM * sorder; // * -> Next sym in order of refrence
- SYM * sdecl; // * -> Next sym in order of declaration
- BYTE stype; // Symbol type
- WORD sattr; // Attribute bits
- LONG sattre; // Extended attribute bits
- WORD senv; // Enviroment number
- LONG svalue; // Symbol value
- char * sname; // * -> Symbol's print-name
-};
-
// Pointer type that can point to (almost) anything
#define PTR union _ptr
PTR
//
#include "sect.h"
+#include "direct.h"
#include "error.h"
+#include "expr.h"
+#include "listing.h"
#include "mach.h"
-#include "token.h"
#include "mark.h"
-#include "expr.h"
-#include "symbol.h"
#include "risca.h"
-#include "listing.h"
+#include "symbol.h"
+#include "token.h"
// Section descriptors
SECT sect[NSECTS]; // All sections...
//
void switchsect(int sno)
{
- SECT * p; // Section pointer
- CHUNK * cp; // Chunk pointer
-
+ CHUNK * cp; // Chunk pointer
cursect = sno;
- p = §[sno];
+ SECT * p = §[sno];
- scattr = p->scattr; // Copy section vars
+ scattr = p->scattr; // Copy section vars
sloc = p->sloc;
scode = p->scode;
sfix = p->sfix;
+ // Copy code chunk vars
if ((cp = scode) != NULL)
- { // Copy code chunk vars
+ {
challoc = cp->challoc;
ch_size = cp->ch_size;
chptr = cp->chptr + ch_size;
else
challoc = ch_size = 0;
+ // Copy fixup chunk vars
if ((cp = sfix) != NULL)
- { // Copy fixup chunk vars
+ {
fchalloc = cp->challoc;
fchsize = cp->ch_size;
fchptr.cp = cp->chptr + fchsize;
//
void init_sect(void)
{
- int i; // Iterator
+ int i;
// Cleanup all sections
- for(i=0; i<NSECTS; ++i)
+ for(i=0; i<NSECTS; i++)
mksect(i, 0);
// Construct default sections, make TEXT the current section
- mksect(ABS, SUSED|SABS|SBSS); // ABS
- mksect(TEXT, SUSED|TEXT ); // TEXT
- mksect(DATA, SUSED|DATA ); // DATA
- mksect(BSS, SUSED|BSS |SBSS); // BSS
-// mksect(M6502, SUSED|TEXT ); // 6502 code section
+ mksect(ABS, SUSED | SABS | SBSS); // ABS
+ mksect(TEXT, SUSED | TEXT ); // TEXT
+ mksect(DATA, SUSED | DATA ); // DATA
+ mksect(BSS, SUSED | BSS | SBSS ); // BSS
+// mksect(M6502, SUSED | TEXT ); // 6502 code section
- switchsect(TEXT); // Switch to TEXT for starters
+ switchsect(TEXT); // Switch to TEXT for starters
}
WORD w;
LONG xloc;
- stopmark(); // Force update to sect[] variables
+ stopmark(); // Force update to sect[] variables
// Hairy, ugly linear search for a mark on our location;
- // the speed doesn't matter, since this is only done when generating a listing, which is SLOW.
+ // the speed doesn't matter, since this is only done when generating a
+ // listing, which is SLOW.
for(ch=sect[sno].sffix; ch!=NULL; ch=ch->chnext)
{
fup.cp = (char *)ch->chptr;
//
int chcheck(LONG amt)
{
- CHUNK * cp;
- SECT * p;
-
+ // If in BSS section, no allocation required
if (scattr & SBSS)
- return 0; // If in BSS section, forget it
+ return 0;
if (!amt)
amt = CH_THRESHOLD;
if (amt < CH_CODE_SIZE)
amt = CH_CODE_SIZE;
- p = §[cursect];
- cp = (CHUNK *)malloc(sizeof(CHUNK) + amt);
+ SECT * p = §[cursect];
+ CHUNK * cp = malloc(sizeof(CHUNK) + amt);
// First chunk in section
if (scode == NULL)
}
+// This is really wrong. We need to make some proper structures here so we don't
+// have to count sizes of objects, that's what the compiler's for! :-P
+#define FIXUP_BASE_SIZE (sizeof(WORD) + sizeof(LONG) + sizeof(WORD) + sizeof(WORD))
//
// Arrange for a fixup on a location
//
LONG len = 0;
CHUNK * cp;
SECT * p;
+ // Shamus: Expression lengths are voodoo ATM (varibale "i"). Need to fix this.
+ DEBUG printf("FIXUP@$%X: $%X\n", loc, attr);
// Compute length of expression (could be faster); determine if it's the
// single-symbol case; no expression if it's just a mark. This code assumes
// 16 bit WORDs and 32 bit LONGs
if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR)
{
- if ((attr & 0x0F00) == FU_JR) // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
+ // Just a single symbol
+ // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
+ if ((attr & 0x0F00) == FU_JR)
{
- i = 18; // Just a single symbol
+// i = 18;
+ i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2);
}
else
{
- i = 14;
+// i = 14;
+ i = FIXUP_BASE_SIZE + sizeof(SYM *);
}
}
else
}
len++; // Add 1 for ENDEXPR
- i = (len << 2) + 12;
+// i = (len << 2) + 12;
+ i = FIXUP_BASE_SIZE + sizeof(WORD) + (len * sizeof(TOKEN));
}
// Maybe alloc another fixup chunk for this one to fit in
if ((fchalloc - fchsize) < i)
{
p = §[cursect];
-// cp = (CHUNK *)amem((long)(sizeof(CHUNK) + CH_FIXUP_SIZE));
cp = (CHUNK *)malloc(sizeof(CHUNK) + CH_FIXUP_SIZE);
+ // First fixup chunk in section
if (sfix == NULL)
- { // First fixup chunk in section
+ {
cp->chprev = NULL;
p->sffix = cp;
}
+ // Add to other chunks
else
- { // Add to other chunks
+ {
cp->chprev = sfix;
sfix->chnext = cp;
sfix->ch_size = fchsize;
sfix = p->sfix = cp;
}
- // Record fixup type, fixup location, and the file number and line number the fixup is
- // located at.
+ // Record fixup type, fixup location, and the file number and line number
+ // the fixup is located at.
*fchptr.wp++ = attr;
*fchptr.lp++ = loc;
*fchptr.wp++ = cfileno;
*fchptr.wp++ = (WORD)curlineno;
- // Store postfix expression or pointer to a single symbol, or nothing for a mark.
+ // Store postfix expression or pointer to a single symbol, or nothing for a
+ // mark.
if (attr & FU_EXPR)
{
*fchptr.wp++ = (WORD)len;
}
else
{
- *fchptr.lp++ = (LONG)fexpr[1];
+// *fchptr.lp++ = (LONG)fexpr[1];
+ *fchptr.sy++ = symbolPtr[fexpr[1]];
}
- if ((attr & 0x0F00) == FU_JR) // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
+ // SCPCD : correct bit mask for attr (else other FU_xxx will match) NYAN !
+ if ((attr & 0x0F00) == FU_JR)
{
if (orgactive)
*fchptr.lp++ = orgaddr;
//
// Resolve all Fixups
//
-int fixups(void)
+int ResolveAllFixups(void)
{
unsigned i;
char buf[EBUFSIZ];
if (glob_flag)
syg_fix();
- resfix(TEXT);
- resfix(DATA);
+ DEBUG printf("Resolving TEXT sections...\n");
+ ResolveFixups(TEXT);
+ DEBUG printf("Resolving DATA sections...\n");
+ ResolveFixups(DATA);
- // We need to do a final check of forward 'jump' destination addresses that are external
+ // We need to do a final check of forward 'jump' destination addresses that
+ // are external
for(i=0; i<MAXFWDJUMPS; i++)
{
if (fwdjump[i])
//
// Resolve Fixups in a Section
//
-int resfix(int sno)
+int ResolveFixups(int sno)
{
- SECT * sc; // Section
- CHUNK * ch;
PTR fup; // Current fixup
WORD * fuend; // End of last fixup (in this chunk)
- CHUNK * cch; // Cached chunk for target
WORD w; // Fixup word (type+modes+flags)
char * locp; // Location to fix (in cached chunk)
LONG loc; // Location to fixup
unsigned j;
char buf[EBUFSIZ];
- sc = §[sno];
- ch = sc->sffix;
+ SECT * sc = §[sno];
+ CHUNK * ch = sc->sffix;
if (ch == NULL)
return 0;
- cch = sc->sfcode; // "cache" first chunk
+ CHUNK * cch = sc->sfcode; // "cache" first chunk
- if (cch == NULL) // Can't fixup a sect with nothing in it
+ if (cch == NULL) // Can't fixup a sect with nothing in it
return 0;
do
{
- fup.cp = ch->chptr; // fup -> start of chunk
- fuend = (WORD *)(fup.cp + ch->ch_size); // fuend -> end of chunk
+ fup.cp = ch->chptr; // fup -> start of chunk
+ fuend = (WORD *)(fup.cp + ch->ch_size); // fuend -> end of chunk
while (fup.wp < fuend)
{
esym = NULL;
- // Search for chunk containing location to fix up; compute a pointer to the location
- // (in the chunk). Often we will find the fixup is in the "cached" chunk, so the
- // linear-search is seldom executed.
+ // Search for chunk containing location to fix up; compute a
+ // pointer to the location (in the chunk). Often we will find the
+ // fixup is in the "cached" chunk, so the linear-search is seldom
+ // executed.
if (loc < cch->chloc || loc >= (cch->chloc + cch->ch_size))
{
for(cch=sc->sfcode; cch!=NULL; cch=cch->chnext)
if (cch == NULL)
{
- interror(7); // Fixup (loc) out of range
+ interror(7); // Fixup (loc) out of range
// NOTREACHED
}
}
locp = cch->chptr + (loc - cch->chloc);
-
eattr = 0;
// Compute expression/symbol value and attribs
+ // Complex expression
if (w & FU_EXPR)
- { // Complex expression
+ {
i = *fup.wp++;
if (evexpr(fup.tk, &eval, &eattr, &esym) != OK)
fup.lp += i;
}
+ // Simple symbol
else
- { // Simple symbol
+ {
sy = *fup.sy++;
eattr = sy->sattr;
else
eval = 0;
- if ((eattr & (GLOBAL|DEFINED)) == GLOBAL)
+ if ((eattr & (GLOBAL | DEFINED)) == GLOBAL)
esym = sy;
}
// Do the fixup
//
- // If a PC-relative fixup is undefined, its value is *not* subtracted from the location
- // (that will happen in the linker when the external reference is resolved).
+ // If a PC-relative fixup is undefined, its value is *not*
+ // subtracted from the location (that will happen in the linker
+ // when the external reference is resolved).
//
- // MWC expects PC-relative things to have the LOC subtracted from the value, if the
- // value is external (that is, undefined at this point).
+ // MWC expects PC-relative things to have the LOC subtracted from
+ // the value, if the value is external (that is, undefined at this
+ // point).
//
- // PC-relative fixups must be DEFINED and either in the same section (whereupon the
- // subtraction takes place) or ABS (with no subtract).
+ // PC-relative fixups must be DEFINED and either in the same
+ // section (whereupon the subtraction takes place) or ABS (with no
+ // subtract).
if (w & FU_PCREL)
{
if (eattr & DEFINED)
*locp = (char)eval;
break;
// Fixup WORD forward references;
- // the word could be unaligned in the section buffer, so we have to be careful.
+ // the word could be unaligned in the section buffer, so we have to
+ // be careful.
case FU_WORD:
if (((w & 0x0F00) == FU_JR) || ((w & 0x0F00) == FU_MJR))
{
if ((w & 0x0F00) == FU_MJR)
{
- // Main code destination alignment checking here for forward declared labels
+ // Main code destination alignment checking here for
+ // forward declared labels
address = (oaddr) ? oaddr : loc;
if (((address >= 0xF03000) && (address < 0xF04000)
if (page_jump)
{
- // This jump is to a page outside of the current 256 byte page
+ // This jump is to a page outside of the
+ // current 256 byte page
if (eval % 4)
{
warni("* \'jr\' at $%08X - destination address not aligned for long page jump, insert a \'nop\' before the destination address", address);
*locp = (char)eval;
break;
// Fixup LONG forward references;
- // the long could be unaligned in the section buffer, so be careful (again).
+ // the long could be unaligned in the section buffer, so be careful
+ // (again).
case FU_LONG:
if ((w & 0x0F00) == FU_MOVEI)
{
CHUNK * chnext; // Next, previous chunks in section
CHUNK * chprev;
LONG chloc; // Base addr of this chunk
- LONG challoc; // #bytes allocated for chunk
- LONG ch_size; // #bytes chunk actually uses
+ LONG challoc; // # bytes allocated for chunk
+ LONG ch_size; // # bytes chunk actually uses
char * chptr; // Data for this chunk
};
MCHUNK {
MCHUNK * mcnext; // Next mark chunk
PTR mcptr; // Vector of marks
- LONG mcalloc; // #marks allocted to mark block
- LONG mcused; // #marks used in block
+ LONG mcalloc; // # marks allocted to mark block
+ LONG mcused; // # marks used in block
};
#define MWORD 0x0000 // Marked word
int fixtest(int, LONG);
int chcheck(LONG);
int fixup(WORD, LONG, TOKEN *);
-int fixups(void);
-int resfix(int);
+int ResolveAllFixups(void);
+//int ResolveFixups(int);
#endif // __SECT_H__
#include "procln.h"
#include "error.h"
-static SYM * sytab[NBUCKETS]; // User symbol-table header
-int curenv; // Current enviroment number
-SYM * sorder; // * -> Symbols, in order of reference
-SYM * sordtail; // * -> Last symbol in sorder list
-SYM * sdecl; // * -> Symbols, in order of declaration
-SYM * sdecltail; // * -> Last symbol in sdecl list
+// Macros
+#define NBUCKETS 256 // Number of hash buckets (power of 2)
+
+static SYM * symbolTable[NBUCKETS]; // User symbol-table header
+int curenv; // Current enviroment number
+static SYM * sorder; // * -> Symbols, in order of reference
+static SYM * sordtail; // * -> Last symbol in sorder list
+static SYM * sdecl; // * -> Symbols, in order of declaration
+static SYM * sdecltail; // * -> Last symbol in sdecl list
// Tags for marking symbol spaces
// a = absolute
//
// Initialize Symbol Table
//
-void init_sym(void)
+void InitSymbolTable(void)
{
- int i; // Iterator
+ int i; // Iterator
- for(i=0; i<NBUCKETS; ++i) // Initialise symbol hash table
- sytab[i] = NULL;
+ for(i=0; i<NBUCKETS; i++) // Initialise symbol hash table
+ symbolTable[i] = NULL;
- curenv = 1; // Init local symbol enviroment
- sorder = NULL; // Init symbol-reference list
+ curenv = 1; // Init local symbol enviroment
+ sorder = NULL; // Init symbol-reference list
sordtail = NULL;
- sdecl = NULL; // Init symbol-decl list
+ sdecl = NULL; // Init symbol-decl list
sdecltail = NULL;
}
//
// Hash the Print Name and Enviroment Number
//
-int syhash(char * name, int envno)
+int HashSymbol(char * name, int envno)
{
- int sum, k = 0; // Hash calculation
+ int sum, k = 0; // Hash calculation
for(sum=envno; *name; name++)
{
//
// Make a new symbol of type `type' in enviroment `envno'
//
-SYM * newsym(char * name, int type, int envno)
+SYM * NewSymbol(char * name, int type, int envno)
{
- int hash; // Symbol hash value
- SYM * sy; // Pointer to symbol
-
// Allocate the symbol
-// sy = (SYM *)amem((long)(sizeof(SYM)));
- sy = (SYM *)malloc(sizeof(SYM));
+ SYM * symbol = malloc(sizeof(SYM));
- if (sy == NULL)
+ if (symbol == NULL)
{
printf("SYMALLOC ERROR (%s)\n", name);
return NULL;
}
-// sy->sname = nstring(name);
- sy->sname = strdup(name);
+ symbol->sname = strdup(name);
// Fill-in the symbol
- sy->stype = (BYTE)type;
- sy->senv = (WORD)envno;
- sy->sattr = 0;
-#if 0
- if (rgpu || rdsp)
- sy->sattre = RISCSYM;
- else
- sy->sattre = 0;
-#else
- sy->sattre = (rgpu || rdsp ? RISCSYM : 0);
-#endif
- sy->svalue = 0;
+ symbol->stype = (BYTE)type;
+ symbol->senv = (WORD)envno;
+ symbol->sattr = 0;
+ symbol->sattre = (rgpu || rdsp ? RISCSYM : 0);
+ symbol->svalue = 0;
// Install symbol in symbol table
- hash = syhash(name, envno);
- sy->snext = sytab[hash];
- sytab[hash] = sy;
+ int hash = HashSymbol(name, envno);
+ symbol->snext = symbolTable[hash];
+ symbolTable[hash] = symbol;
// Append symbol to symbol-order list
if (sorder == NULL)
- sorder = sy; // Add first symbol
+ sorder = symbol; // Add first symbol
else
- sordtail->sorder = sy; // Or append to tail of list
+ sordtail->sorder = symbol; // Or append to tail of list
- sy->sorder = NULL;
- sordtail = sy;
+ symbol->sorder = NULL;
+ sordtail = symbol;
- return sy; // Return pointer to symbol
+ return symbol;
}
int k, sum; // Hash bucket calculation
char * s; // String pointer
- // Pick a hash-bucket (SAME algorithm as syhash())
+ // Pick a hash-bucket (SAME algorithm as HashSymbol())
k = 0;
s = name;
sum += *s++;
}
- sy = sytab[sum & (NBUCKETS-1)];
+ sy = symbolTable[sum & (NBUCKETS-1)];
#else
- SYM * sy = sytab[syhash(name, envno)];
+ SYM * symbol = symbolTable[HashSymbol(name, envno)];
#endif
// Do linear-search for symbol in bucket
- while (sy != NULL)
+ while (symbol != NULL)
{
- if (sy->stype == type // Type, envno and name must match
- && sy->senv == envno
- && *name == *sy->sname // Fast check for first character
- && !strcmp(name, sy->sname))
+ if (symbol->stype == type // Type, envno and name must match
+ && symbol->senv == envno
+ && *name == *symbol->sname // Fast check for first character
+ && !strcmp(name, symbol->sname))
break;
else
- sy = sy->snext;
+ symbol = symbol->snext;
}
- return sy; // Return NULL or matching symbol
+ return symbol; // Return NULL or matching symbol
}
for(sy=sorder; sy!=NULL; sy=sy->sorder)
{
if (sy->stype == LABEL && sy->senv == 0
- && ((sy->sattr & (REFERENCED|DEFINED)) == REFERENCED))
+ && ((sy->sattr & (REFERENCED | DEFINED)) == REFERENCED))
sy->sattr |= GLOBAL;
}
// Export or import external references, and export COMMON blocks.
if ((sy->stype == LABEL)
- && ((sy->sattr & (GLOBAL|DEFINED)) == (GLOBAL|DEFINED)
- || (sy->sattr & (GLOBAL|REFERENCED)) == (GLOBAL|REFERENCED))
+ && ((sy->sattr & (GLOBAL | DEFINED)) == (GLOBAL | DEFINED)
+ || (sy->sattr & (GLOBAL | REFERENCED)) == (GLOBAL | REFERENCED))
|| (sy->sattr & COMMON))
{
sy->senv = (WORD)scount++;
// Export vanilla labels (but don't make them global). An exception is
// made for equates, which are not exported unless they are referenced.
else if (sy->stype == LABEL && lsym_flag
- && (sy->sattr & (DEFINED|REFERENCED)) != 0
+ && (sy->sattr & (DEFINED | REFERENCED)) != 0
&& (!as68_flag || *sy->sname != 'L'))
{
sy->senv = (WORD)scount++;
for(i=0; i<NBUCKETS; ++i)
{
- for(p=sytab[i]; p!=NULL; p=k)
+ for(p=symbolTable[i]; p!=NULL; p=k)
{
k = p->snext;
j = *p->sname;
#ifndef __SYMBOL_H__
#define __SYMBOL_H__
-#include "rmac.h"
+#include <inttypes.h>
-// Macros
-#define NBUCKETS 256 // Number of hash buckets (power of 2)
+// Line lists
+struct LineList
+{
+ struct LineList * next;
+ char * line;
+};
+
+// Symbols
+#define SYM struct _sym
+SYM
+{
+ SYM * snext; // * -> Next symbol on hash-chain
+ SYM * sorder; // * -> Next sym in order of reference
+ SYM * sdecl; // * -> Next sym in order of declaration
+ uint8_t stype; // Symbol type
+ uint16_t sattr; // Attribute bits
+ uint32_t sattre; // Extended attribute bits
+ uint16_t senv; // Enviroment number
+ uint32_t svalue; // Symbol value
+ char * sname; // * -> Symbol's print-name
+ struct LineList * lineList; // * -> Macro's linked list of lines
+ struct LineList * last; // * -> end of macro linked list
+};
// Globals, externals etc
extern int curenv;
// Prototypes
SYM * lookup(char *, int, int);
-void init_sym(void);
-SYM * newsym(char *, int, int);
+void InitSymbolTable(void);
+SYM * NewSymbol(char *, int, int);
void sym_decl(SYM *);
int syg_fix(void);
int symtable(void);
//
#include "token.h"
-#include "symbol.h"
-#include "procln.h"
-#include "macro.h"
#include "error.h"
+#include "macro.h"
+#include "procln.h"
+#include "symbol.h"
#define DECL_KW // Declare keyword arrays
#define DEF_KW // Declare keyword values
// (the colon must be in the first column). These labels are stripped before
// macro expansion takes place.
//
-int mexpand(char * src, char * dest, int destsiz)
+int ExpandMacro(char * src, char * dest, int destsiz)
{
- char * s;
- char * d = NULL;
- char * dst; // Next dest slot
- char * edst; // End+1 of dest buffer
int i;
int questmark; // \? for testing argument existence
- TOKEN * tk;
char mname[128]; // Assume max size of a formal arg name
- int macnum;
- SYM * arg;
- IMACRO * imacro;
char numbuf[20]; // Buffer for text of CONSTs
+ TOKEN * tk;
+ SYM * arg;
- imacro = cur_inobj->inobj.imacro;
- macnum = (int)(imacro->im_macro->sattr);
+ DEBUG { printf("EM: src=\"%s\"\n", src); }
- destsiz--;
- dst = dest;
- edst = dest + destsiz;
+ IMACRO * imacro = cur_inobj->inobj.imacro;
+ int macnum = (int)(imacro->im_macro->sattr);
+
+// destsiz--;
+ char * dst = dest; // Next dest slot
+ char * edst = dest + destsiz - 1; // End + 1(?) of dest buffer
// Check for (and skip over) any "label" on the line
- s = src;
+ char * s = src;
+ char * d = NULL;
if (*s == ':')
{
copystr:
d = numbuf;
copy_d:
- ++s;
+ s++;
while (*d != EOS)
{
// Get argument name: \name, \{name}
d = mname;
- // \foo
+ // \label
if (*s != '{')
{
do
}
while (chrtab[*s] & CTSYM);
}
- // \\{foo}
+ // \\{label}
else
{
for(++s; *s != EOS && *s != '}';)
if (*s != '}')
return error("missing '}'");
else
- ++s;
+ s++;
}
*d = EOS;
// Lookup the argument and copy its (string) value into the
// destination string
- DEBUG printf("mname='%s'\n", mname);
+ DEBUG printf("argument='%s'\n", mname);
if ((arg = lookup(mname, MACARG, macnum)) == NULL)
return errors("undefined argument: '%s'", mname);
tk = NULL;
if (i < imacro->im_nargs)
- tk = argp[i];
+// tk = argp[i];
+ tk = argPtrs[i];
// \?arg yields:
// 0 if the argument is empty or non-existant,
continue;
}
- if (tk != NULL) // arg# is in range, so expand it
+ if (tk != NULL) // arg # is in range, so expand it
{
while (*tk != EOL)
{
switch ((int)*tk++)
{
case SYMBOL:
- d = (char *)*tk++;
+// d = (char *)*tk++;
+ d = string[*tk++];
break;
case STRING:
- d = (char *)*tk++;
+// d = (char *)*tk++;
+ d = string[*tk++];
if (dst >= edst)
goto overflow;
unsigned source_addr;
IMACRO * imacro = cur_inobj->inobj.imacro;
- LONG * strp = imacro->im_nextln;
+// LONG * strp = imacro->im_nextln;
+ struct LineList * strp = imacro->im_nextln;
if (strp == NULL) // End-of-macro
return NULL;
- imacro->im_nextln = (LONG *)*strp;
- mexpand((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
+// imacro->im_nextln = (LONG *)*strp;
+ imacro->im_nextln = strp->next;
+// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
+ ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ);
if (!strcmp(imacro->im_macro->sname, "mjump") && !mjump_align)
{
// if we need to adjust the alignment of the jump source address to
// meet the rules of gpu main execution we need to skip the first nop
// of the macro. This is simpler than trying to insert nop's mid macro.
- source_addr = (orgactive) ? orgaddr : sloc;
+ source_addr = (orgactive ? orgaddr : sloc);
source_addr += 8;
if (source_addr % 4)
if (strp == NULL)
return NULL;
- imacro->im_nextln = (LONG *)*strp;
- mexpand((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
+// imacro->im_nextln = (LONG *)*strp;
+// ExpandMacro((char *)(strp + 1), imacro->im_lnbuf, LNSIZ);
+ imacro->im_nextln = strp->next;
+ ExpandMacro(strp->line, imacro->im_lnbuf, LNSIZ);
}
mjump_align = 1;
//
int fpop(void)
{
- INOBJ * inobj;
IFILE * ifile;
IMACRO * imacro;
LONG * p, * p1;
-
- inobj = cur_inobj;
+ INOBJ * inobj = cur_inobj;
if (inobj != NULL)
{
*ln = ';';
else
{
- for(p=ln; *p!=EOS; ++p)
+ for(p=ln; *p!=EOS; p++)
{
if (*p == '*')
{
if (c & STSYM)
{
- if (stuffnull) // Terminate old symbol
+ if (stuffnull) // Terminate old symbol from previous pass
*nullspot = EOS;
v = 0; // Assume no DOT attrib follows symbol
#warning
//problem here: nullspot is a char * but TOKEN is a uint32_t. On a 64-bit system,
//this will cause all kinds of mischief.
+#if 0
*tk++ = (TOKEN)nullspot;
+#else
+ string[stringNum] = nullspot;
+ *tk++ = stringNum;
+ stringNum++;
+#endif
}
else
{
if (v) // Record attribute token (if any)
*tk++ = (TOKEN)v;
- if (stuffnull) // Arrange for string termination
+ if (stuffnull) // Arrange for string termination on next pass
nullspot = ln;
continue;
#warning
// More char * stuffing (8 bytes) into the space of 4 (TOKEN).
// Need to figure out how to fix this crap.
+#if 0
*tk++ = (TOKEN)ln;
+#else
+ string[stringNum] = ln;
+ *tk++ = stringNum;
+ stringNum++;
+#endif
for(p=ln; *ln!=EOS && *ln!=c1;)
{
// be EOL.
//
//int d_goto(WORD siz) {
-int d_goto(void)
+//int d_goto(void)
+int d_goto(WORD unused)
{
- char * sym; // Label to search for
- LONG * defln; // Macro definition strings
+// char * sym; // Label to search for
+// LONG * defln; // Macro definition strings
char * s1; // Temps for string comparison
char * s2;
- IMACRO * imacro; // Macro invocation block
+// IMACRO * imacro; // Macro invocation block
// Setup for the search
if (*tok != SYMBOL)
return error("missing label");
- sym = (char *)tok[1];
+// sym = (char *)tok[1];
+ char * sym = string[tok[1]];
tok += 2;
if (cur_inobj->in_type != SRC_IMACRO)
return error("goto not in macro");
- imacro = cur_inobj->inobj.imacro;
- defln = (LONG *)imacro->im_macro->svalue;
+ IMACRO * imacro = cur_inobj->inobj.imacro;
+// defln = (LONG *)imacro->im_macro->svalue;
+ struct LineList * defln = imacro->im_macro->lineList;
// Find the label, starting with the first line.
- for(; defln!=NULL; defln=(LONG *)*defln)
+// for(; defln!=NULL; defln=(LONG *)*defln)
+ for(; defln!=NULL; defln=defln->next)
{
- if (*(char *)(defln + 1) == ':')
+// if (*(char *)(defln + 1) == ':')
+ if (defln->line[0] == ':')
{
// Compare names (sleazo string compare)
+ // This string compare is not right. Doesn't check for lengths.
+#warning "!!! Bad string comparison !!!"
s1 = sym;
- s2 = (char *)(defln + 1) + 1;
+// s2 = (char *)(defln + 1) + 1;
+ s2 = defln->line;
while (*s1 == *s2)
{
break;
else
{
- ++s1;
- ++s2;
+ s1++;
+ s2++;
}
}
else if (*t == ACONST)
printf("[ACONST]");
else if (*t == STRING)
- printf("[STRING]");
+// printf("[STRING]");
+ {
+ t++;
+ printf("[STRING:\"%s\"]", string[*t]);
+ }
else if (*t == SYMBOL)
{
t++;
- printf("[SYMBOL:\"%s\"]", (char *)*t);
+ printf("[SYMBOL:\"%s\"]", string[*t]);
}
else if (*t == EOS)
printf("[EOS]");
printf("[CR_DATE]");
else if (*t >= 0x20 && *t <= 0x2F)
printf("[%c]", (char)*t);
+ else if (*t >= 0x3A && *t <= 0x3F)
+ printf("[%c]", (char)*t);
else if (*t >= 0x80 && *t <= 0x87)
printf("[D%u]", ((uint32_t)*t) - 0x80);
else if (*t >= 0x88 && *t <= 0x8F)
printf("[A%u]", ((uint32_t)*t) - 0x88);
else
-// printf("[%X:%c]", (uint32_t)*t, (char)*t);
- printf("[%X]", (uint32_t)*t);
+ printf("[%X:%c]", (uint32_t)*t, (char)*t);
+// printf("[%X]", (uint32_t)*t);
}
printf("[EOL]\n");
// Information about a macro invocation
IMACRO {
IMACRO * im_link; // Pointer to ancient IMACROs
- LONG * im_nextln; // Next line to include
+// LONG * im_nextln; // Next line to include
+ struct LineList * im_nextln; // Next line to include
WORD im_nargs; // # of arguments supplied on invocation
WORD im_siz; // Size suffix supplied on invocation
LONG im_olduniq; // Old value of 'macuniq'
void setfnum(WORD);
int tokln(void);
int fpop(void);
-//int d_goto(WORD);
-int d_goto(void);
+int d_goto(WORD);
+//int d_goto(void);
INOBJ * a_inobj(int);
void DumpTokenBuffer(void);