From 3f2bccb78ab4cd59654d521c8aedfe5512ee6608 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Fri, 16 Jan 2015 11:16:33 -0600 Subject: [PATCH 1/1] Misc. whitespace cleanups, removal of unneeded code. --- amode.c | 52 ++++++------ debug.c | 14 ++-- error.c | 7 +- macro.c | 17 ++-- mark.c | 10 +-- mark.h | 8 +- object.c | 36 ++++---- object.h | 14 ++-- procln.c | 8 +- riscasm.c | 4 +- rmac.c | 242 ++++++++++++++++++------------------------------------ rmac.h | 23 +++--- sect.c | 71 ++++++++-------- symbol.c | 45 +++++----- symbol.h | 7 +- token.c | 90 +++++++++----------- 16 files changed, 278 insertions(+), 370 deletions(-) diff --git a/amode.c b/amode.c index 2c89911..915499c 100644 --- a/amode.c +++ b/amode.c @@ -18,34 +18,34 @@ #include "mntab.h" // Address-mode information -int nmodes; // Number of addr'ing modes found -int am0; // Addressing mode -int a0reg; // Register -TOKEN a0expr[EXPRSIZE]; // Expression -VALUE a0exval; // Expression's value -WORD a0exattr; // Expression's attribute -int a0ixreg; // Index register -int a0ixsiz; // Index register size (and scale) -TOKEN a0oexpr[EXPRSIZE]; // Outer displacement expression -VALUE a0oexval; // Outer displacement value -WORD a0oexattr; // Outer displacement attribute -SYM * a0esym; // External symbol involved in expr - -int am1; // Addressing mode -int a1reg; // Register -TOKEN a1expr[EXPRSIZE]; // Expression -VALUE a1exval; // Expression's value -WORD a1exattr; // Expression's attribute -int a1ixreg; // Index register -int a1ixsiz; // Index register size (and scale) -TOKEN a1oexpr[EXPRSIZE]; // Outer displacement expression -VALUE a1oexval; // Outer displacement value -WORD a1oexattr; // Outer displacement attribute -SYM * a1esym; // External symbol involved in expr +int nmodes; // Number of addr'ing modes found +int am0; // Addressing mode +int a0reg; // Register +TOKEN a0expr[EXPRSIZE]; // Expression +VALUE a0exval; // Expression's value +WORD a0exattr; // Expression's attribute +int a0ixreg; // Index register +int a0ixsiz; // Index register size (and scale) +TOKEN a0oexpr[EXPRSIZE]; // Outer displacement expression +VALUE a0oexval; // Outer displacement value +WORD a0oexattr; // Outer displacement attribute +SYM * a0esym; // External symbol involved in expr + +int am1; // Addressing mode +int a1reg; // Register +TOKEN a1expr[EXPRSIZE]; // Expression +VALUE a1exval; // Expression's value +WORD a1exattr; // Expression's attribute +int a1ixreg; // Index register +int a1ixsiz; // Index register size (and scale) +TOKEN a1oexpr[EXPRSIZE]; // Outer displacement expression +VALUE a1oexval; // Outer displacement value +WORD a1oexattr; // Outer displacement attribute +SYM * a1esym; // External symbol involved in expr // -// Parse Addressing Mode +// Parse addressing mode // int amode(int acount) { @@ -117,7 +117,7 @@ int amode(int acount) // -// Parse Register List +// Parse register list // int reglist(WORD * a_rmask) { diff --git a/debug.c b/debug.c index 5062b8f..ac57aa5 100644 --- a/debug.c +++ b/debug.c @@ -18,7 +18,7 @@ static int siztab[4] = { 3, 5, 9, 9 }; // -// Print 'c' Visibly +// Print 'c' visibly // int visprt(char c) { @@ -187,12 +187,14 @@ int mudump(void) // -// Dump memory from 'start' for 'count' bytes; `flg' is the following ORed together: +// Dump memory from 'start' for 'count' bytes; `flg' is the following ORed +// together: // 0 - bytes // 1 - words // 2 - longwords // -// if `base' is not -1, then print it at the start of each line, incremented accordingly. +// if `base' is not -1, then print it at the start of each line, incremented +// accordingly. // int mdump(char * start, LONG count, int flg, LONG base) { @@ -242,8 +244,8 @@ int mdump(char * start, LONG count, int flg, LONG base) base += 1 << (flg & 3); } - // Print remaining bit of ascii; the hairy expression computes the number of - // spaces to print to make the ascii line up nicely. + // Print remaining bit of ASCII; the hairy expression computes the number + // of spaces to print to make the ASCII line up nicely. if (j != i) { k = ((16 - (i - j)) / (1 << (flg & 3))) * siztab[flg & 3]; @@ -332,7 +334,7 @@ int dumptok(TOKEN * tk) // -// Dump Everything +// Dump everything // int dump_everything(void) { diff --git a/error.c b/error.c index 4f65cc4..75efaad 100644 --- a/error.c +++ b/error.c @@ -26,7 +26,6 @@ int at_eol(void) if (*tok != EOL) { -// error("syntax error"); sprintf(msg, "syntax error. expected EOL, found $%X ('%c')", *tok, *tok); error(msg); } @@ -36,7 +35,7 @@ int at_eol(void) // -// Cannot Create a File +// Cannot create a file // void cantcreat(const char * fn) { @@ -46,7 +45,7 @@ void cantcreat(const char * fn) // -// Setup for Error Message +// Setup for error message // o Create error listing file (if necessary) // o Set current filename // @@ -76,7 +75,7 @@ void err_setup(void) // -// Display Error Message +// Display error message // int error(const char * s) { diff --git a/macro.c b/macro.c index 6e9fd86..39c31ef 100644 --- a/macro.c +++ b/macro.c @@ -34,7 +34,7 @@ static int rptlevel; // .rept nesting level // -// Initialize Macro Processor +// Initialize macro processor // void InitMacro(void) { @@ -46,7 +46,7 @@ void InitMacro(void) // -// Exit from a Macro; +// Exit from a macro; // -- pop any intervening include files and repeat blocks; // -- restore argument stack; // -- pop the macro. @@ -86,7 +86,7 @@ of another (nested macros). Need to fix that somehow. // -// Add a Formal Argument to a Macro Definition +// Add a formal argument to a macro definition // int defmac2(char * argname) { @@ -552,12 +552,13 @@ int InvokeMacro(SYM * mac, WORD siz) Shamus: 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. -What we could do is simply move the argp with each call, and move it back by the -number of arguments in the macro that's ending. That would solve the problem nicely. +What we could do is simply move the argp with each call, and move it back by +the number of arguments in the macro that's ending. That would solve the +problem nicely. [Which we do now. But that uncovered another problem: the token strings are all -stale by the time a nested macro gets to the end. But they're supposed to be symbols, -which means if we put symbol references into the argument token streams, we can -alleviate this problem.] +stale by the time a nested macro gets to the end. But they're supposed to be +symbols, which means if we put symbol references into the argument token +streams, we can alleviate this problem.] */ #if 0 argptr = (TOKEN **)malloc((nargs + 1) * sizeof(LONG)); diff --git a/mark.c b/mark.c index 3b3bd3a..4a7fe1b 100644 --- a/mark.c +++ b/mark.c @@ -17,14 +17,14 @@ MCHUNK * curmch; // Current mark chunk PTR markptr; // Deposit point in current mark chunk LONG mcalloc; // #bytes alloc'd to current mark chunk LONG mcused; // #bytes used in current mark chunk -uint16_t curfrom; // Current "from" section +uint16_t curfrom; // Current "from" section //#define DEBUG_IMAGE_MARKING // -// Initialize Marker +// Initialize marker // void InitMark(void) { @@ -37,7 +37,7 @@ void InitMark(void) // // Wrap up marker (called after final mark is made) // -void stopmark(void) +void StopMark(void) { if (curmch) { @@ -286,7 +286,7 @@ printf(" validsegment(3): rflag = $%08X\n", rflag); { if (w & (DATA|BSS)) { - dp = objimage + BSDHDRSIZE + loc; + dp = objImage + BSDHDRSIZE + loc; diff = ((LONG)(*dp++ & 0xFF)) << 24; diff |= ((LONG)(*dp++ & 0xFF)) << 16; diff |= ((LONG)(*dp++ & 0xFF)) << 8; @@ -307,7 +307,7 @@ printf(" validsegment(4): diff = $%08X --> ", diff); if (rflag & 0x01) diff = ((diff >> 16) & 0x0000FFFF) | ((diff << 16) & 0xFFFF0000); - dp = objimage + BSDHDRSIZE + loc; + dp = objImage + BSDHDRSIZE + loc; *dp++ = (char)(diff >> 24); *dp++ = (char)(diff >> 16); *dp++ = (char)(diff >> 8); diff --git a/mark.h b/mark.h index b117bba..d234d3a 100644 --- a/mark.h +++ b/mark.h @@ -15,15 +15,15 @@ #define MARK_ALLOC_INCR 1024 // # bytes to alloc for more mark space #define MIN_MARK_MEM (3 * sizeof(WORD) + 2 * sizeof(LONG)) -// Globals, Externals etc +// Globals, externals, etc. extern MCHUNK * firstmch; -// Prototypes +// Exported functions void InitMark(void); -void stopmark(void); -//int rmark(int, LONG, int, int, SYM *); +void StopMark(void); int rmark(uint16_t, uint32_t, uint16_t, uint16_t, SYM *); int amark(void); LONG bsdmarkimg(char *, LONG, LONG, int); #endif // __MARK_H__ + diff --git a/object.c b/object.c index ffff623..772c03d 100644 --- a/object.c +++ b/object.c @@ -16,7 +16,7 @@ LONG symsize = 0; // Size of BSD symbol table LONG strindx = 0x00000004; // BSD string table index char * strtable; // Pointer to the symbol string table -char * objimage; // Global object image pointer +char * objImage; // Global object image pointer // @@ -72,9 +72,10 @@ char * constr_bsdsymtab(char * buf, SYM * sym, int globflag) // -// Generate object file +// Write an object file to the passed in file descriptor +// N.B.: Return value is ignored... // -int object(WORD fd) +int WriteObject(int fd) { LONG t; // Scratch long LONG tds; // TEXT & DATA segment size @@ -100,9 +101,9 @@ int object(WORD fd) return ERROR; } - memset(buf, 0, 0x600000); // Reset allocated memory - objimage = buf; // Set global object image pointer - strtable = malloc(0x200000); // Allocate 2mb scratch buffer + memset(buf, 0, 0x600000); // Reset allocated memory + objImage = buf; // Set global object image pointer + strtable = malloc(0x200000); // Allocate 2mb scratch buffer if (strtable == NULL) { @@ -110,18 +111,18 @@ int object(WORD fd) return ERROR; } - memset(strtable, 0, 0x200000); // Reset allocated memory + memset(strtable, 0, 0x200000); // Reset allocated memory // Build object file header - chptr = buf; // Base of header - D_long(0x00000107); // Magic number - D_long(sect[TEXT].sloc); // TEXT size - D_long(sect[DATA].sloc); // DATA size - D_long(sect[BSS].sloc); // BSS size - D_long(0x00000000); // Symbol size - D_long(0x00000000); // First entry (0L) - D_long(0x00000000); // TEXT relocation size - D_long(0x00000000); // BSD relocation size + chptr = buf; // Base of header + D_long(0x00000107); // Magic number + D_long(sect[TEXT].sloc); // TEXT size + D_long(sect[DATA].sloc); // DATA size + D_long(sect[BSS].sloc); // BSS size + D_long(0x00000000); // Symbol size + D_long(0x00000000); // First entry (0L) + D_long(0x00000000); // TEXT relocation size + D_long(0x00000000); // BSD relocation size // Construct TEXT and DATA segments (without relocation changes) p = buf + BSDHDRSIZE; @@ -130,7 +131,7 @@ int object(WORD fd) { for(cp=sect[i].sfcode; cp!=NULL; cp=cp->chnext) { - copy(p, cp->chptr, cp->ch_size); + memcpy(p, cp->chptr, cp->ch_size); p += cp->ch_size; } } @@ -172,3 +173,4 @@ int object(WORD fd) return 0; } + diff --git a/object.h b/object.h index dfb3035..77d8bcb 100644 --- a/object.h +++ b/object.h @@ -9,14 +9,14 @@ #ifndef __OBJECT_H__ #define __OBJECT_H__ -#include "rmac.h" +// Size of BSD header +#define BSDHDRSIZE 0x20 -#define BSDHDRSIZE 0x20 // Size of BSD header +// Globals, externals, etc. +extern char * objImage; -// Globals, externals etc -extern char * objimage; - -// Prototypes -int object(WORD); +// Exported functions +int WriteObject(int); #endif // __OBJECT_H__ + diff --git a/procln.c b/procln.c index e851408..d849b00 100644 --- a/procln.c +++ b/procln.c @@ -94,7 +94,7 @@ int HandleLabel(char *, int); // -// Initialize Line Processor +// Initialize line processor // void InitLineProcessor(void) { @@ -106,7 +106,7 @@ void InitLineProcessor(void) // -// Line Processor +// Line processor // void Assemble(void) { @@ -728,7 +728,7 @@ int HandleLabel(char * label, int labelType) // -// .if, Start Conditional Assembly +// .if, Start conditional assembly // int d_if(void) { @@ -763,7 +763,7 @@ int d_if(void) // -// .else, Do Alternate Case For .if +// .else, Do alternate case for .if // int d_else(void) { diff --git a/riscasm.c b/riscasm.c index b82c19d..b4a06d7 100644 --- a/riscasm.c +++ b/riscasm.c @@ -31,14 +31,14 @@ uint8_t riscImmTokenSeen; // The '#' (immediate) token was seen const char reg_err[] = "missing register R0...R31"; -// Jaguar Jump Condition Names +// Jaguar jump condition names const char condname[MAXINTERNCC][5] = { "NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ", "N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO", "PL", "MI", "F" }; -// Jaguar Jump Condition Numbers +// Jaguar jump condition numbers const char condnumber[] = { 1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26, 0, 0, 1, 2, 4, 4, 5, 8, 8, 20, 24, 31 diff --git a/rmac.c b/rmac.c index 4506a95..b2b2610 100644 --- a/rmac.c +++ b/rmac.c @@ -22,145 +22,69 @@ #include "symbol.h" #include "object.h" -int perm_verb_flag; // Permanently verbose, interactive mode -int list_flag; // "-l" Listing flag on command line -int verb_flag; // Be verbose about what's going on -int as68_flag; // as68 kludge mode -int glob_flag; // Assume undefined symbols are global -int lsym_flag; // Include local symbols in object file -int sbra_flag; // Warn about possible short branches -int legacy_flag; // Do stuff like insert code in RISC assembler -int obj_format; // Object format flag -int debug; // [1..9] Enable debugging levels -int err_flag; // '-e' specified -int err_fd; // File to write error messages to -int rgpu, rdsp; // Assembling Jaguar GPU or DSP code -int list_fd; // File to write listing to -int regbank; // RISC register bank -int segpadsize; // Segment padding size -int endian; // Host processor endianess -char * objfname; // Object filename pointer -char * firstfname; // First source filename -char * cmdlnexec; // Executable name, pointer to ARGV[0] -char * searchpath; // Search path for include files -char defname[] = "noname.o"; // Default output filename - - -// -// Copy stuff around, return pointer to dest+count+1 (doesn't handle overlap) -// -char * copy(char * dest, char * src, LONG count) -{ - while (count--) - *dest++ = *src++; - - return dest; -} - - -// -// Clear a region of memory -// -void clear(char * dest, LONG count) -{ - while(count--) - *dest++ = 0; -} - - -// -// Check to see if the string is a keyword. Returns -1, or a value from the -// 'accept[]' table -// -int kmatch(char * p, int * base, int * check, int * tab, int * accept) -{ - int state; - int j; - - for(state=0; state>=0;) - { - j = base[state] + (int)tolowertab[*p]; - - if (check[j] != state) - { // Reject, character doesn't match - state = -1; // No match - break; - } - - if (!*++p) - { // Must accept or reject at EOS - state = accept[j]; // (-1 on no terminal match) - break; - } - - state = tab[j]; - } - - return state; -} - - -// -// Auto-even a section -// -void autoeven(int sect) -{ - SwitchSection(sect); - d_even(); - SaveSection(); -} +int perm_verb_flag; // Permanently verbose, interactive mode +int list_flag; // "-l" listing flag on command line +int verb_flag; // Be verbose about what's going on +int as68_flag; // as68 kludge mode +int glob_flag; // Assume undefined symbols are global +int lsym_flag; // Include local symbols in object file +int sbra_flag; // Warn about possible short branches +int legacy_flag; // Do stuff like insert code in RISC assembler +int obj_format; // Object format flag +int debug; // [1..9] Enable debugging levels +int err_flag; // '-e' specified +int err_fd; // File to write error messages to +int rgpu, rdsp; // Assembling Jaguar GPU or DSP code +int list_fd; // File to write listing to +int regbank; // RISC register bank +int segpadsize; // Segment padding size +int endian; // Host processor endianess +char * objfname; // Object filename pointer +char * firstfname; // First source filename +char * cmdlnexec; // Executable name, pointer to ARGV[0] +char * searchpath; // Search path for include files +char defname[] = "noname.o"; // Default output filename // // Manipulate file extension. -// `name' must be large enough to hold any possible filename. -// If `stripp' is nonzero, any old extension is removed. -// Then, if the file does not already have an extension, -// `extension' is appended to the filename. +// +// 'name' must be large enough to hold any possible filename. If 'stripp' is +// nonzero, any old extension is removed. If the file does not already have an +// extension, 'extension' is appended to the filename. // char * fext(char * name, char * extension, int stripp) { - char * s, * beg; // String pointers + char * s; - // Find beginning of "real" name - beg = name + strlen(name) - 1; + // Find beginning of "real" name (strip off path) + char * beg = strrchr(name, SLASHCHAR); - for(; beg>name; --beg) - { - if (*beg == SLASHCHAR) - { - ++beg; - break; - } - } + if (beg == NULL) + beg = name; + // Clobber any old extension, if requested if (stripp) - { // Clobber any old extension + { for(s=beg; *s && *s!='.'; ++s) ; *s = '\0'; } - for(s=beg; *s!='.'; ++s) - { - if (!*s) - { // Append the new extension - strcat(beg, extension); - break; - } - } + if (strrchr(beg, '.') == NULL) + strcat(beg, extension); return name; } // -// Return `item'nth element of semicolon-seperated pathnames specified in the -// enviroment string `s'. Copy the pathname to `buf'. Return 0 if the `item' +// Return 'item'nth element of semicolon-seperated pathnames specified in the +// enviroment string 's'. Copy the pathname to 'buf'. Return 0 if the 'item' // nth path doesn't exist. // -// [`item' ranges from 0 to N-1, where N = #elements in search path] +// ['item' ranges from 0 to N-1, where N = #elements in search path] // int nthpath(char * env_var, int itemno, char * buf) { @@ -189,9 +113,9 @@ int nthpath(char * env_var, int itemno, char * buf) // -// Display Command Line Help +// Display command line help // -void display_help(void) +void DisplayHelp(void) { printf("Usage:\n" " %s [options] srcfile\n" @@ -221,9 +145,9 @@ void display_help(void) // -// Display Version Information +// Display version information // -void display_version(void) +void DisplayVersion(void) { printf("\nReboot's Macro Assembler for Atari Jaguar\n" "Copyright (C) 199x Landon Dyer, 2011 Reboot\n" @@ -232,9 +156,9 @@ void display_version(void) // -// Process Command Line Arguments and do an Assembly +// Process command line arguments and do an assembly // -int process(int argc, char ** argv) +int Process(int argc, char ** argv) { int argno; // Argument number SYM * sy; // Pointer to a symbol record @@ -284,7 +208,7 @@ int process(int argc, char ** argv) { switch (argv[argno][1]) { - case 'd': // Define symbol + case 'd': // Define symbol case 'D': for(s=argv[argno]+2; *s!=EOS;) { @@ -311,25 +235,18 @@ int process(int argc, char ** argv) } sy->sattr = DEFINED | EQUATED | ABS; -#if 0 - if (*s) - sy->svalue = (VALUE)atoi(s); - else - sy->svalue = 0; -#else sy->svalue = (*s ? (VALUE)atoi(s) : 0); -#endif break; - case 'e': // Redirect error message output + case 'e': // Redirect error message output case 'E': err_fname = argv[argno] + 2; break; - case 'f': // -f + case 'f': // -f case 'F': switch (argv[argno][2]) { case EOS: - case 'b': // -fb = BSD (Jaguar Recommended) + case 'b': // -fb = BSD (Jaguar Recommended) case 'B': obj_format = BSD; break; @@ -339,22 +256,22 @@ int process(int argc, char ** argv) return errcnt; } break; - case 'g': // Debugging flag + case 'g': // Debugging flag case 'G': printf("Debugging flag (-g) not yet implemented\n"); break; - case 'i': // Set directory search path + case 'i': // Set directory search path case 'I': searchpath = argv[argno] + 2; break; - case 'l': // Produce listing file + case 'l': // Produce listing file case 'L': list_fname = argv[argno] + 2; listing = 1; list_flag = 1; lnsave++; break; - case 'o': // Direct object file output + case 'o': // Direct object file output case 'O': if (argv[argno][2] != EOS) objfname = argv[argno] + 2; @@ -370,7 +287,7 @@ int process(int argc, char ** argv) } break; - case 'r': // Pad seg to requested boundary size + case 'r': // Pad seg to requested boundary size case 'R': switch(argv[argno][2]) { @@ -379,31 +296,31 @@ int process(int argc, char ** argv) case 'p': case 'P': segpadsize = 8; break; case 'd': case 'D': segpadsize = 16; break; case 'q': case 'Q': segpadsize = 32; break; - default: segpadsize = 2; break; // Effective autoeven(); + default: segpadsize = 2; break; // Effective autoeven(); } break; - case 's': // Warn about possible short branches + case 's': // Warn about possible short branches case 'S': sbra_flag = 1; break; - case 'u': // Make undefined symbols .globl + case 'u': // Make undefined symbols .globl case 'U': glob_flag = 1; break; - case 'v': // Verbose flag + case 'v': // Verbose flag case 'V': verb_flag++; if (verb_flag > 1) - display_version(); + DisplayVersion(); break; - case 'x': // Turn on debugging + case 'x': // Turn on debugging case 'X': debug = 1; printf("~ Debugging ON\n"); break; - case 'y': // -y + case 'y': // -y case 'Y': pagelen = atoi(argv[argno] + 2); @@ -415,29 +332,29 @@ int process(int argc, char ** argv) } break; - case EOS: // Input is stdin - if (firstfname == NULL) // Kludge first filename + case EOS: // Input is stdin + if (firstfname == NULL) // Kludge first filename firstfname = defname; include(0, "(stdin)"); Assemble(); break; - case 'h': // Display command line usage + case 'h': // Display command line usage case 'H': case '?': - display_version(); - display_help(); + DisplayVersion(); + DisplayHelp(); errcnt++; break; - case 'n': // Turn off legacy mode + case 'n': // Turn off legacy mode case 'N': legacy_flag = 0; printf("Legacy mode OFF\n"); break; default: - display_version(); + DisplayVersion(); printf("Unknown switch: %s\n\n", argv[argno]); - display_help(); + DisplayHelp(); errcnt++; break; } @@ -466,7 +383,8 @@ int process(int argc, char ** argv) // Wind-up processing; // o save current section (no more code generation) - // o do auto-even of all sections (or boundary alignment as requested through '-r') + // o do auto-even of all sections (or boundary alignment as requested + // through '-r') // o determine name of object file: // - "foo.o" for linkable output; // - "foo.prg" for GEMDOS executable (-p flag). @@ -506,7 +424,7 @@ int process(int argc, char ** argv) // (2) generate the output file image and symbol table; // (3) generate relocation information from left-over fixups. ResolveAllFixups(); // Do all fixups - stopmark(); // Stop mark tape-recorder + StopMark(); // Stop mark tape-recorder if (errcnt == 0) { @@ -519,7 +437,7 @@ int process(int argc, char ** argv) printf("[Writing %s file: %s]\n", s, objfname); } - object((WORD)fd); + WriteObject(fd); close(fd); if (errcnt != 0) @@ -546,9 +464,9 @@ int process(int argc, char ** argv) // -// Determine Processor Endianess +// Determine processor endianess // -int get_endianess(void) +int GetEndianess(void) { int i = 1; char * p = (char *)&i; @@ -561,7 +479,7 @@ int get_endianess(void) // -// Application Entry Point; Handle the Command Line +// Application entry point // int main(int argc, char ** argv) { @@ -569,16 +487,14 @@ int main(int argc, char ** argv) legacy_flag = 1; // Default is legacy mode on (:-P) cmdlnexec = argv[0]; // Obtain executable name - endian = get_endianess(); // Get processor endianess + endian = GetEndianess(); // Get processor endianess // If commands were passed in, process them if (argc > 1) - { - return process(argc - 1, argv + 1); - } + return Process(argc - 1, argv + 1); - display_version(); - display_help(); + DisplayVersion(); + DisplayHelp(); return 0; } diff --git a/rmac.h b/rmac.h index 24da33d..e0f53df 100644 --- a/rmac.h +++ b/rmac.h @@ -13,7 +13,8 @@ // TARGET SPECIFIC BUILD SETTINGS // #ifdef WIN32 - #define PLATFORM "Win32" // Release platform - windows + // Release platform - windows + #define PLATFORM "Win32" #define _OPEN_FLAGS _O_TRUNC|_O_CREAT|_O_BINARY|_O_RDWR #define _OPEN_INC _O_RDONLY|_O_BINARY #define _PERM_MODE _S_IREAD|_S_IWRITE @@ -32,7 +33,8 @@ #include #else #ifdef __GCCUNIX__ - #define PLATFORM "OSX/Linux" // Release platform - mac OS-X or linux + // Release platform - mac OS-X or linux + #define PLATFORM "OSX/Linux" #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY #define _PERM_MODE S_IREAD|S_IWRITE @@ -45,7 +47,8 @@ #include #include #else - #define PLATFORM "Unknown" // Release platform - not specified + // Release platform - not specified + #define PLATFORM "Unknown" #define _OPEN_FLAGS O_TRUNC|O_CREAT|O_RDWR #define _OPEN_INC O_RDONLY #define _PERM_MODE S_IREAD|S_IWRITE @@ -72,7 +75,7 @@ #define ERROR (-1) // Generic error return #define EOS '\0' // End of string -#define SPACE ' ' // Ascii space +#define SPACE ' ' // ASCII space #define SLASHCHAR '/' #define SLASHSTRING "/" #define VALUE LONG // Assembler value @@ -167,7 +170,7 @@ PTR //#define RISCSYM 0x00010000 -// Globals, externals etc +// Globals, externals, etc. extern int verb_flag; extern int debug; extern int rgpu, rdsp; @@ -183,16 +186,10 @@ extern int lsym_flag; extern int sbra_flag; extern int obj_format; extern int legacy_flag; -//extern LONG amemtot; -// Prototypes -void init_sym(void); -SYM * newsym(char *, int, int); +// Exported functions char * fext(char *, char *, int); -int kmatch(char *, int *, int *, int *, int *); -void autoeven(int); int nthpath(char *, int, char *); -void clear(char *, LONG); -char * copy(char *, char *, LONG); #endif // __RMAC_H__ + diff --git a/sect.c b/sect.c index d4277fc..1ff54b4 100644 --- a/sect.c +++ b/sect.c @@ -23,24 +23,24 @@ void MakeSection(int, WORD); void SwitchSection(int); // Section descriptors -SECT sect[NSECTS]; // All sections... -int cursect; // Current section number +SECT sect[NSECTS]; // All sections... +int cursect; // Current section number // These are copied from the section descriptor, the current code chunk // descriptor and the current fixup chunk descriptor when a switch is made into // a section. They are copied back to the descriptors when the section is left. -WORD scattr; // Section attributes -LONG sloc; // Current loc in section +WORD scattr; // Section attributes +LONG sloc; // Current loc in section -CHUNK * scode; // Current (last) code chunk -LONG challoc; // # bytes alloc'd to code chunk -LONG ch_size; // # bytes used in code chunk -char * chptr; // Deposit point in code chunk buffer +CHUNK * scode; // Current (last) code chunk +LONG challoc; // # bytes alloc'd to code chunk +LONG ch_size; // # bytes used in code chunk +char * chptr; // Deposit point in code chunk buffer -CHUNK * sfix; // Current (last) fixup chunk -LONG fchalloc; // # bytes alloc'd to fixup chunk -LONG fchsize; // # bytes used in fixup chunk -PTR fchptr; // Deposit point in fixup chunk buffer +CHUNK * sfix; // Current (last) fixup chunk +LONG fchalloc; // # bytes alloc'd to fixup chunk +LONG fchsize; // # bytes used in fixup chunk +PTR fchptr; // Deposit point in fixup chunk buffer // Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is // associated with a location. @@ -69,7 +69,7 @@ static char fusizoffs[] = { // -// Initialize Sections; Setup initial ABS, TEXT, DATA and BSS sections +// Initialize sections; setup initial ABS, TEXT, DATA and BSS sections // void InitSection(void) { @@ -86,12 +86,13 @@ void InitSection(void) MakeSection(BSS, SUSED | BSS | SBSS); // BSS // MakeSection(M6502, SUSED | TEXT ); // 6502 code section - SwitchSection(TEXT); // Switch to TEXT for starters + // Switch to TEXT for starters + SwitchSection(TEXT); } // -// Make a New (Clean) Section +// Make a new (clean) section // void MakeSection(int sno, WORD attr) { @@ -109,11 +110,12 @@ void MakeSection(int sno, WORD attr) // void SwitchSection(int sno) { - CHUNK * cp; // Chunk pointer + CHUNK * cp; cursect = sno; SECT * p = §[sno]; - scattr = p->scattr; // Copy section vars + // Copy section vars + scattr = p->scattr; sloc = p->sloc; scode = p->scode; sfix = p->sfix; @@ -170,11 +172,12 @@ int fixtest(int sno, LONG loc) WORD w; LONG xloc; - stopmark(); // Force update to sect[] variables + // Force update to sect[] variables + StopMark(); - // 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. + // 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. for(ch=sect[sno].sffix; ch!=NULL; ch=ch->chnext) { fup.cp = (char *)ch->chptr; @@ -195,7 +198,7 @@ int fixtest(int sno, LONG loc) fup.lp += w; } else - ++fup.lp; + fup.lp++; } } @@ -204,11 +207,11 @@ int fixtest(int sno, LONG loc) // -// Check that there are at least `amt' bytes left in the current chunk. If -// there are not, allocate another chunk of at least `amt' bytes (and probably +// Check that there are at least 'amt' bytes left in the current chunk. If +// there are not, allocate another chunk of at least 'amt' bytes (and probably // more). // -// If `amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise. +// If 'amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise. // int chcheck(LONG amt) { @@ -257,8 +260,8 @@ int chcheck(LONG amt) } -// 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 +// 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 @@ -269,7 +272,8 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) LONG len = 0; CHUNK * cp; SECT * p; - // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix this. + // Shamus: Expression lengths are voodoo ATM (variable "i"). Need to fix + // this. #warning "!!! AddFixup() is filled with VOODOO !!!" DEBUG printf("FIXUP@$%X: $%X\n", loc, attr); @@ -279,7 +283,8 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) if (*fexpr == SYMBOL && fexpr[2] == ENDEXPR) { // Just a single symbol - // 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 & FUMASKRISC) == FU_JR) { // i = 18; @@ -372,7 +377,7 @@ int AddFixup(WORD attr, LONG loc, TOKEN * fexpr) // -// Resolve all Fixups +// Resolve all fixups // int ResolveAllFixups(void) { @@ -381,7 +386,7 @@ int ResolveAllFixups(void) // Make undefined symbols GLOBL if (glob_flag) - syg_fix(); + ForceUndefinedSymbolsGlobal(); DEBUG printf("Resolving TEXT sections...\n"); ResolveFixups(TEXT); @@ -393,7 +398,7 @@ int ResolveAllFixups(void) // -// Resolve Fixups in a Section +// Resolve fixups in a section // int ResolveFixups(int sno) { @@ -425,7 +430,7 @@ int ResolveFixups(int sno) // "Cache" first chunk CHUNK * cch = sc->sfcode; - // Can't fixup a sect with nothing in it + // Can't fixup a section with nothing in it if (cch == NULL) return 0; diff --git a/symbol.c b/symbol.c index d476121..2edf9fd 100644 --- a/symbol.c +++ b/symbol.c @@ -35,7 +35,7 @@ static char tdb_text[8] = { // -// Initialize Symbol Table +// Initialize symbol table // void InitSymbolTable(void) { @@ -54,7 +54,7 @@ void InitSymbolTable(void) // -// Hash the Print Name and Enviroment Number +// Hash the print name and enviroment number // int HashSymbol(char * name, int envno) { @@ -91,7 +91,7 @@ SYM * NewSymbol(char * name, int type, int envno) symbol->stype = (BYTE)type; symbol->senv = (WORD)envno; symbol->sattr = 0; -//we don't do this, it could be a forward reference! + // Don't do this, it could be a forward reference! // symbol->sattr = DEFINED; // We just defined it... // This is a bad assumption. Not every symbol 1st seen in a RISC section is // a RISC symbol! @@ -191,11 +191,11 @@ void AddToSymbolOrderList(SYM * symbol) // // Make all referenced, undefined symbols global // -int syg_fix(void) +void ForceUndefinedSymbolsGlobal(void) { SYM * sy; - DEBUG printf("~syg_fix()\n"); + DEBUG printf("~ForceUndefinedSymbolsGlobal()\n"); // Scan through all symbols; // If a symbol is REFERENCED but not DEFINED, then make it global. @@ -205,8 +205,6 @@ int syg_fix(void) && ((sy->sattr & (REFERENCED | DEFINED)) == REFERENCED)) sy->sattr |= GLOBAL; } - - return 0; } @@ -233,10 +231,7 @@ int uc_string(char * s) int sy_assign(char * buf, char *(* constr)()) { SYM * sy; - int scount; - //int i; - - scount = 0; + int scount = 0; if (buf == NULL) { @@ -246,16 +241,16 @@ int sy_assign(char * buf, char *(* constr)()) { // Essentially the same as 'sym_decl()' above: if (sy->sattr & SDECLLIST) - continue; // Already on list + continue; // Already on list - sy->sattr |= SDECLLIST; // Mark "on the list" + sy->sattr |= SDECLLIST; // Mark "on the list" if (sdecl == NULL) - sdecl = sy; // First on decl-list + sdecl = sy; // First on decl-list else - sdecltail->sdecl = sy; // Add to end of list + sdecltail->sdecl = sy; // Add to end of list - sy->sdecl = NULL; // Fix up list's tail + sy->sdecl = NULL; // Fix up list's tail sdecltail = sy; } } @@ -322,7 +317,6 @@ int symtable(void) // Allocate storage for list headers and partition all labels. // Throw away macros and macro arguments. -// sy = (SYM **)amem((LONG)(128 * sizeof(LONG))); sy = (SYM **)malloc(128 * sizeof(LONG)); for(i=0; i<128; ++i) @@ -336,27 +330,27 @@ int symtable(void) j = *p->sname; r = NULL; - if (p->stype != LABEL) - continue; // Ignore non-labels - - if (p->sattre & UNDEF_EQUR) + // Ignore non-labels + if ((p->stype != LABEL) || (p->sattre & UNDEF_EQUR)) continue; for(q=sy[j]; q!=NULL; q=q->snext) { if (strcmp(p->sname, q->sname) < 0) break; - else - r = q; + + r = q; } if (r == NULL) - { // Insert at front of list + { + // Insert at front of list p->snext = sy[j]; sy[j] = p; } else - { // Insert in middle or append to list + { + // Insert in middle or append to list p->snext = r->snext; r->snext = p; } @@ -453,3 +447,4 @@ int symtable(void) return 0; } + diff --git a/symbol.h b/symbol.h index e183b43..767799e 100644 --- a/symbol.h +++ b/symbol.h @@ -36,18 +36,19 @@ SYM uint32_t uid; // Symbol's unique ID }; -// Globals, externals etc +// Globals, externals, etc. extern int curenv; extern char subttl[]; -// Prototypes +// Exported functions SYM * lookup(char *, int, int); void InitSymbolTable(void); SYM * NewSymbol(char *, int, int); void AddToSymbolOrderList(SYM *); -int syg_fix(void); +void ForceUndefinedSymbolsGlobal(void); int symtable(void); int sy_assign(char *, char *(*)()); char * GetSymbolNameByUID(uint32_t); #endif // __SYMBOL_H__ + diff --git a/token.c b/token.c index 6ba200c..250aa46 100644 --- a/token.c +++ b/token.c @@ -118,7 +118,7 @@ static char * riscregname[] = { // -// Initialize Tokenizer +// Initialize tokenizer // void InitTokenizer(void) { @@ -613,7 +613,7 @@ overflow: // -// Get Next Line of Text from a Macro +// Get next line of text from a macro // char * GetNextMacroLine(void) { @@ -636,7 +636,7 @@ char * GetNextMacroLine(void) // -// Get Next Line of Text from a Repeat Block +// Get next line of text from a repeat block // char * GetNextRepeatLine(void) { @@ -668,7 +668,7 @@ char * GetNextRepeatLine(void) // -// Include a Source File used at the Root, and for ".include" Files +// Include a source file used at the root, and for ".include" files // int include(int handle, char * fname) { @@ -714,7 +714,7 @@ int include(int handle, char * fname) // -// Pop the Current Input Level +// Pop the current input level // int fpop(void) { @@ -795,17 +795,9 @@ char * GetNextLine(void) // Scan for next end-of-line; handle stupid text formats by treating // \r\n the same as \n. (lone '\r' at end of buffer means we have to // check for '\n'). -#if 0 - i = 0; - j = fl->ifcnt; - d = &fl->ifbuf[fl->ifind]; - - for(p=d; iifbuf[fl->ifind]; for(p=d, i=0, j=fl->ifcnt; i= j) - break; // Need to read more, then look for '\n' to eat + break; // Need to read more, then look for '\n' to eat else if (p[1] == '\n') i++; } @@ -838,7 +830,8 @@ char * GetNextLine(void) *p = '\0'; return NULL; #else - // Really should check to see if we're at the end of the buffer! :-P + // Really should check to see if we're at the end of the buffer! + // :-P fl->ifbuf[fl->ifind + fl->ifcnt] = '\0'; fl->ifcnt = 0; return &fl->ifbuf[fl->ifind]; @@ -879,29 +872,29 @@ char * GetNextLine(void) // -// Tokenize a Line +// Tokenize a line // int TokenizeLine(void) { - char * ln = NULL; // Ptr to current position in line - char * p; // Random character ptr - TOKEN * tk; // Token-deposit ptr - int state = 0; // State for keyword detector - int j = 0; // Var for keyword detector - char c; // Random char - VALUE v; // Random value - char * nullspot = NULL; // Spot to clobber for SYMBOL terminatn - int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot + char * ln = NULL; // Ptr to current position in line + char * p; // Random character ptr + TOKEN * tk; // Token-deposit ptr + int state = 0; // State for keyword detector + int j = 0; // Var for keyword detector + char c; // Random char + VALUE v; // Random value + char * nullspot = NULL; // Spot to clobber for SYMBOL termination + int stuffnull; // 1:terminate SYMBOL '\0' at *nullspot char c1; - int stringNum = 0; // Pointer to string locations in tokenized line + int stringNum = 0; // Pointer to string locations in tokenized line retry: if (cur_inobj == NULL) // Return EOF if input stack is empty return TKEOF; - // Get another line of input from the current input source: a file, - // a macro, or a repeat-block + // Get another line of input from the current input source: a file, a + // macro, or a repeat-block switch (cur_inobj->in_type) { // Include-file: @@ -975,10 +968,10 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); strcpy(lnbuf, ln); // General house-keeping - tok = tokeol; // Set "tok" to EOL in case of error - tk = etok; // Reset token ptr - stuffnull = 0; // Don't stuff nulls - totlines++; // Bump total #lines assembled + tok = tokeol; // Set "tok" to EOL in case of error + tk = etok; // Reset token ptr + stuffnull = 0; // Don't stuff nulls + totlines++; // Bump total #lines assembled // See if the entire line is a comment. This is a win if the programmer // puts in lots of comments @@ -1074,8 +1067,8 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); j = -1; } - //make j = -1 if time, date etc with no preceeding ^^ - //defined, referenced, streq, macdef, date and time + // Make j = -1 if time, date etc with no preceeding ^^ + // defined, referenced, streq, macdef, date and time switch ((TOKEN)j) { case 112: // defined @@ -1129,7 +1122,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); { switch (*ln++) { - case '!': // ! or != + case '!': // ! or != if (*ln == '=') { *tk++ = NE; @@ -1139,8 +1132,8 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = '!'; continue; - case '\'': // 'string' - case '\"': // "string" + case '\'': // 'string' + case '\"': // "string" c1 = ln[-1]; *tk++ = STRING; //#warning @@ -1206,7 +1199,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *p++ = EOS; continue; - case '$': // $, hex constant + case '$': // $, hex constant if ((int)chrtab[*ln] & HDIGIT) { v = 0; @@ -1241,7 +1234,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = '$'; continue; - case '<': // < or << or <> or <= + case '<': // < or << or <> or <= switch (*ln) { case '<': @@ -1260,7 +1253,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = '<'; continue; } - case ':': // : or :: + case ':': // : or :: if (*ln == ':') { *tk++ = DCOLON; @@ -1270,7 +1263,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = ':'; continue; - case '=': // = or == + case '=': // = or == if (*ln == '=') { *tk++ = DEQUALS; @@ -1280,7 +1273,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = '='; continue; - case '>': // > or >> or >= + case '>': // > or >> or >= switch (*ln) { case '>': @@ -1295,7 +1288,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = '>'; continue; } - case '%': // % or binary constant + case '%': // % or binary constant if (*ln < '0' || *ln > '1') { *tk++ = '%'; @@ -1330,7 +1323,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = CONST; *tk++ = v; continue; - case '@': // @ or octal constant + case '@': // @ or octal constant if (*ln < '0' || *ln > '7') { *tk++ = '@'; @@ -1365,7 +1358,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = CONST; *tk++ = v; continue; - case '^': // ^ or ^^ + case '^': // ^ or ^^ if (*ln != '^') { *tk++ = '^'; @@ -1417,7 +1410,7 @@ if (verb_flag) printf("TokenizeLine: Calling fpop() from SRC_IREPT...\n"); *tk++ = (TOKEN)j; continue; default: - interror(2); // Bad MULTX entry in chrtab + interror(2); // Bad MULTX entry in chrtab continue; } } @@ -1492,8 +1485,7 @@ goteol: //int d_goto(void) int d_goto(WORD unused) { - char * s1; // Temps for string comparison - char * s2; + char * s1, * s2; // Setup for the search if (*tok != SYMBOL) @@ -1566,7 +1558,6 @@ void DumpTokenBuffer(void) else if (*t == ACONST) printf("[ACONST]"); else if (*t == STRING) -// printf("[STRING]"); { t++; printf("[STRING:\"%s\"]", string[*t]); @@ -1632,7 +1623,6 @@ void DumpTokenBuffer(void) printf("[A%u]", ((uint32_t)*t) - 0x88); else printf("[%X:%c]", (uint32_t)*t, (char)*t); -// printf("[%X]", (uint32_t)*t); } printf("[EOL]\n"); -- 2.37.2