/************************************* * C02 Variable Management Routines * *************************************/ #include #include #include #include #include #include "common.h" #include "files.h" #include "asm.h" #include "parse.h" #include "label.h" #include "vars.h" /* Lookup variable name in variable table * * Sets: varidx = index into varnam array * * varcnt if not found * * Returns: TRUE if found, otherwise FALSE */ int fndvar(char *name) { DEBUG("Looking up variable '%s'\n", word); for (varidx=0; varidx 0) asmlin("STA", prmtra); //Store First Parameter if (prmcnt > 1) asmlin("STY", prmtry); //Store Second Parameter if (prmcnt > 2) asmlin("STX", prmtrx); //Store Third Parameter endlbl[0] = 0; //Create Dummy End Label pshlbl(LTFUNC, endlbl); //and Push onto Stack bgnblk('{'); //Start Program Block } /* (Check For and) Parse Variable Declaration*/ void pdecl(int m, int t) { DEBUG("Processing variable declarations(s) of type %d\n", t); while(TRUE) { getwrd(); if (match('(')) { if (m != MTNONE) { ERROR("Illegal Modifier %d in Function Definion", m, EXIT_FAILURE); } addfnc(); //Add Function Call return; } addvar(m, t); if (!look(',')) break; } expect(';'); DEBUG("Variable Declaration Completed\n", 0); SCMNT(""); //Clear Assembler Comment } /* Check for and Parse Type Keyword */ int ptype(int m) { int result = TRUE; if (wordis("VOID")) pdecl(m, VTVOID); //Parse 'void' declaration else if (wordis("CHAR")) pdecl(m, VTCHAR); //Parse 'char' declaration else result = FALSE; //DEBUG("Returning %d from function ptype\n", result)' return result; } /* Check for and Parse Modifier */ int pmodfr() { DEBUG("Parsing modifier '%s'\n", word); int result = TRUE; if (wordis("ALIGNED")) { getwrd(); ptype(MTALGN); } else if (wordis("ZEROPAGE")) { getwrd(); ptype(MTZP); } else result = FALSE; return result; } /* Write Variable Table */ void vartbl() { int i, j; DEBUG("Writing Variable Table", 0); fprintf(logfil, "\n%-31s %s %s %s\n", "Variable", "Type", "Size", "Data"); dlen = 0; for (i=0; i 0) { DEBUG("Allocating array '%s'\n", varnam[i]); asmlin(STROP, varsiz[i]); } else { DEBUG("Allocating variable '%s'\n", varnam[i]); asmlin(BYTEOP, "0"); } } vrwrtn = TRUE; }