mirror of
https://github.com/RevCurtisP/C02.git
synced 2025-04-21 09:38:12 +00:00
Changed Variable Table from synchronized arrays to array of structs
This commit is contained in:
parent
28960cbcfa
commit
57b8e6f1e0
@ -89,7 +89,7 @@ void prolog(void) {
|
||||
}
|
||||
|
||||
void epilog(void) {
|
||||
if (!vrwrtn) vartbl(); //Write Variable Table
|
||||
if (!vrwrtn) wvrtbl(); //Write Variable Table
|
||||
if (padcnt) {
|
||||
SCMNT("PADDING BYTES")
|
||||
sprintf(word, "$%hhX", padcnt);
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
int addprm(char* prmtr) {
|
||||
reqvar(FALSE); //Get Variable Name
|
||||
if (vartyp[varidx] == VTINT) {
|
||||
if (varble.type == VTINT) {
|
||||
strcpy(prmtrx, value);
|
||||
strcpy(prmtry, value);
|
||||
strcat(prmtry, "+1");
|
||||
|
@ -117,7 +117,7 @@ int prstrm(int alwint) {
|
||||
prsval(FALSE, TRUE); //Parse Term - Disallow Registers
|
||||
if (valtyp == FUNCTION) ERROR("Function call only allowed in first term\n", 0, EXIT_FAILURE)
|
||||
strcpy(term, value);
|
||||
if (valtyp == VARIABLE && vartyp[varidx] == VTINT) {
|
||||
if (valtyp == VARIABLE && varble.type == VTINT) {
|
||||
if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", term, EXIT_FAILURE)
|
||||
prcvri(); //Process Integer Variable
|
||||
return TRUE;
|
||||
@ -226,7 +226,7 @@ void prcvri(void) {
|
||||
int prcftm(int alwint) {
|
||||
DEBUG("Processing first term '%s'\n", value)
|
||||
strcpy(term, value);
|
||||
if (valtyp == VARIABLE && vartyp[varidx] == VTINT) {
|
||||
if (valtyp == VARIABLE && varble.type == VTINT) {
|
||||
if (!alwint) ERROR("Illegal Use of Integer Variable %s\n", word, EXIT_FAILURE)
|
||||
prcvri();
|
||||
return TRUE;
|
||||
@ -310,7 +310,7 @@ void prsxpi(char trmntr) {
|
||||
if (valtyp == FUNCTION) {
|
||||
strcpy(term, value);
|
||||
prsfnc(0); //Parse Expression Function
|
||||
} else if (valtyp == VARIABLE && vartyp[varidx] == VTINT) {
|
||||
} else if (valtyp == VARIABLE && varble.type == VTINT) {
|
||||
prcvri(); //Process Integer Variable
|
||||
} else {
|
||||
ERROR("Illegal Variable %s In Integer Expression", value, EXIT_FAILURE)
|
||||
|
@ -134,7 +134,7 @@ void pzropg(void) {
|
||||
/* Process Vartable Subdirective */
|
||||
void pvrtbl(void) {
|
||||
if (vrwrtn) ERROR("Variable table already written", 0, EXIT_FAILURE)
|
||||
vartbl(); //Write Variable Table
|
||||
wvrtbl(); //Write Variable Table
|
||||
}
|
||||
|
||||
/* Parse Pragma Directive */
|
||||
|
@ -145,7 +145,7 @@ int getidx(char* idx) {
|
||||
/* Process Assignment Variable(s) */
|
||||
void prcvar(char trmntr) {
|
||||
chksym(TRUE, FALSE, word);
|
||||
if (vartyp[varidx] == VTINT) {
|
||||
if (varble.type == VTINT) {
|
||||
if (ispopr()) {if (prspst(trmntr, TRUE, word, "")) expctd("post operator");}
|
||||
else prcasi(trmntr); //Process Integer Assignment
|
||||
return;
|
||||
|
57
src/vars.c
57
src/vars.c
@ -16,13 +16,17 @@
|
||||
#include "vars.h"
|
||||
|
||||
/* Lookup variable name in variable table *
|
||||
* Sets: varidx = index into varnam array *
|
||||
* Sets: varidx = index into vartbl array *
|
||||
* varcnt if not found *
|
||||
* Returns: TRUE if found, otherwise FALSE */
|
||||
int fndvar(char *name) {
|
||||
DEBUG("Looking up variable '%s'\n", name)
|
||||
for (varidx=0; varidx<varcnt; varidx++)
|
||||
if (strcmp(varnam[varidx], name) == 0) return TRUE;
|
||||
for (varidx=0; varidx<varcnt; varidx++) {
|
||||
if (strcmp(vartbl[varidx].name, name) == 0) {
|
||||
memcpy(&varble, &vartbl[varidx], sizeof(varble));
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -65,7 +69,7 @@ void chksym(int alwreg, int alwcon, char *name) {
|
||||
}
|
||||
if (!fndvar(name))
|
||||
ERROR("Undeclared variable '%s' encountered\n", name, EXIT_FAILURE)
|
||||
if (!alwcon && (varmod[varidx] & MTCONST))
|
||||
if (!alwcon && (varble.modifr & MTCONST))
|
||||
ERROR("Illegal use of const variable '%s'\n", name, EXIT_FAILURE)
|
||||
}
|
||||
|
||||
@ -89,7 +93,7 @@ void prcmbr(char* name) {
|
||||
* valtyp - Member Type */
|
||||
void prsmbr(char* name) {
|
||||
mbrofs = 0;
|
||||
stcidx = varstc[varidx]; //Get Struct Index
|
||||
stcidx = varble.stcidx; //Get Struct Index
|
||||
prcmbr(name);
|
||||
while (membrs[mbridx].stype == STRUCTURE && nxtchr == '.') {
|
||||
stcidx = membrs[mbridx].symidx;
|
||||
@ -152,11 +156,11 @@ int psizof(void) {
|
||||
sprintf(value, "$%hhX", datlen[varidx]);
|
||||
return datlen[varidx];
|
||||
}
|
||||
if (strlen(varsiz[varidx]) == 0) {
|
||||
if (strlen(varble.size) == 0) {
|
||||
strcpy(value,"1");
|
||||
return 1;
|
||||
}
|
||||
strcpy(value, varsiz[varidx]);
|
||||
strcpy(value, varble.size);
|
||||
if (strcmp(value, "*") == 0) ERROR("Unable to Determine Size of Variable %s\n", vrname, EXIT_FAILURE);
|
||||
return atoi(value);
|
||||
}
|
||||
@ -236,11 +240,11 @@ void prsdat(int m, int t) {
|
||||
* value - variable size */
|
||||
void setvar(int m, int t) {
|
||||
DEBUG("Added variable '%s' ", vrname);
|
||||
strncpy(varnam[varcnt], vrname, VARLEN);
|
||||
varmod[varcnt] = m;
|
||||
vartyp[varcnt] = t;
|
||||
strncpy(varsiz[varcnt], value, 3);
|
||||
varstc[varcnt] = (t == VTSTRUCT) ? stcidx : -1;
|
||||
strncpy(vartbl[varcnt].name, vrname, VARLEN);
|
||||
vartbl[varcnt].modifr = m;
|
||||
vartbl[varcnt].type = t;
|
||||
strncpy(vartbl[varcnt].size, value, 3);
|
||||
vartbl[varcnt].stcidx = (t == VTSTRUCT) ? stcidx : -1;
|
||||
DETAIL("at index %d\n", varcnt);
|
||||
}
|
||||
|
||||
@ -267,7 +271,7 @@ void addvar(int m, int t) {
|
||||
prsnum(0xFFFF);
|
||||
else {
|
||||
prsvar(FALSE, FALSE);
|
||||
if (t == VTINT && vartyp[varidx] != t)
|
||||
if (t == VTINT && varble.type != t)
|
||||
ERROR("ALIAS Type Mismatch\n", 0, EXIT_FAILURE)
|
||||
}
|
||||
asmlin(EQUOP, word);
|
||||
@ -305,17 +309,18 @@ void vardef(int m) {
|
||||
fprintf(logfil, "\n%-8s %s %s %s %s %s\n", "Variable", "Mod", "Type", "Size", "Struct", "Data");
|
||||
dlen = 0;
|
||||
for (i=0; i<varcnt; i++) {
|
||||
if ((varmod[i] & MTCONST) != m) { dlen += datlen[i]; continue; }
|
||||
fprintf(logfil, "%-8s %3d %4d %4s %6d %1d-%d\n", varnam[i], varmod[i], vartyp[i], varsiz[i], varstc[i], dattyp[i], datlen[i]);
|
||||
strcpy(lblasm, varnam[i]);
|
||||
memcpy(&varble, &vartbl[i], sizeof(varble));
|
||||
if ((varble.modifr & MTCONST) != m) { dlen += datlen[i]; continue; }
|
||||
fprintf(logfil, "%-8s %3d %4d %4s %6d %1d-%d\n", varble.name, varble.modifr, varble.type, varble.size, varble.stcidx, dattyp[i], datlen[i]);
|
||||
strcpy(lblasm, varble.name);
|
||||
DEBUG("Set Label to '%s'\n", lblasm)
|
||||
if (strcmp(varsiz[i], "*") == 0) continue;
|
||||
if (varmod[i] & MTALGN) {
|
||||
DEBUG("Aligning variable '%s'\n", varnam[i])
|
||||
if (strcmp(varble.size, "*") == 0) continue;
|
||||
if (varble.modifr & MTALGN) {
|
||||
DEBUG("Aligning variable '%s'\n", varble.name)
|
||||
asmlin(ALNOP, "256");
|
||||
}
|
||||
if (datlen[i]) {
|
||||
DEBUG("Building Data for Variable '%s'", varnam[i])
|
||||
DEBUG("Building Data for Variable '%s'", varble.name)
|
||||
DETAIL(" with length %d\n", datlen[i]);
|
||||
value[0] = 0;
|
||||
for (j=0; j<datlen[i]; j++) {
|
||||
@ -328,15 +333,15 @@ void vardef(int m) {
|
||||
if (strlen(value)) strcat(value,",");
|
||||
strcat(value, "$00");
|
||||
}
|
||||
DEBUG("Allocating Data for Variable '%s'\n", varnam[i])
|
||||
DEBUG("Allocating Data for Variable '%s'\n", varble.name)
|
||||
asmlin(BYTEOP, value);
|
||||
}
|
||||
else if (strlen(varsiz[i]) > 0) {
|
||||
DEBUG("Allocating array '%s'\n", varnam[i])
|
||||
asmlin(STROP, varsiz[i]);
|
||||
else if (strlen(varble.size) > 0) {
|
||||
DEBUG("Allocating array '%s'\n", varble.name)
|
||||
asmlin(STROP, varble.size);
|
||||
}
|
||||
else {
|
||||
DEBUG("Allocating variable '%s'\n", varnam[i])
|
||||
DEBUG("Allocating variable '%s'\n", varble.name)
|
||||
asmlin(BYTEOP, "0");
|
||||
}
|
||||
}
|
||||
@ -344,7 +349,7 @@ void vardef(int m) {
|
||||
}
|
||||
|
||||
/* Write Variable Table */
|
||||
void vartbl(void) {
|
||||
void wvrtbl(void) {
|
||||
LCMNT("Variables declared CONST")
|
||||
vardef(MTCONST); //Write CONST Definitions
|
||||
//Emit Segment Mnemonic for RAM Variables here
|
||||
|
12
src/vars.h
12
src/vars.h
@ -11,16 +11,12 @@ struct varrec {
|
||||
char stcidx; //Variable Struct Index
|
||||
};
|
||||
|
||||
/* Variable Table */
|
||||
char varnam[MAXVAR+1][VARLEN+1]; //Variable Name Table (string)
|
||||
char varmod[MAXVAR+1]; //Variable Modifier (MTxxx)
|
||||
char vartyp[MAXVAR+1]; //Variable Type (VTxxx)
|
||||
char varsiz[MAXVAR+1][4]; //Variable Array Size (string)
|
||||
char varstc[MAXVAR+1]; //Variable Struct Index
|
||||
struct varrec vartbl[MAXVAR+1]; //Variable Table
|
||||
struct varrec varble; //Variable Table Entry
|
||||
|
||||
int varcnt; //Number of Variables in Table
|
||||
int varidx; //Index into Variable Tables
|
||||
char vrname[MAXVAR+1]; //Variable Name
|
||||
int vrtype; //Variable Type
|
||||
int vrwrtn; //Variables Written Flag
|
||||
|
||||
struct strctd { //Struct Definition
|
||||
@ -94,5 +90,5 @@ int pidxof(void); //Parse IndexOf Operator
|
||||
void reqvar(int alwary); //Require and Parse Variable Name
|
||||
void setdat(); //Store variable data
|
||||
void setvar(int m, int t); //Add Variable to Variable table
|
||||
void vartbl(); //Create Variable Table
|
||||
void wvrtbl(); //Create Variable Table
|
||||
void logstc(void); //Print Struct Tables to Log File
|
||||
|
Loading…
x
Reference in New Issue
Block a user