/* * Primitive symbol table. */ #include #include #include "rasm.h" #include "symtab.h" #include "compile.h" #include "util.h" struct symtab_entry *symtab = NULL; struct alias_entry *aliases = NULL; void symtab_store(char *symname, int addr) { struct symtab_entry *newent; if (symtab_lookup(symname) != -1) compile_error("multiply defined location name"); newent = (struct symtab_entry *)malloc(sizeof(struct symtab_entry)); snprintf(newent->symbol, sizeof(newent->symbol), "%s", symname); newent->addr = addr; newent->next = symtab; symtab = newent; } int symtab_lookup(char *symname) { struct symtab_entry *e = symtab; while (e) { if (0 == strcmp(symname, e->symbol)) return e->addr; e = e->next; } if (is_number(symname)) return str_to_int(symname); return -1; } void symtab_preload() { } void symtab_dump() { struct symtab_entry *e = symtab; while (e) { printf("%s: %04x\n", e->symbol, e->addr); e=e->next; } } void alias_store(char *alias, char *dst) { struct alias_entry *newent; if (alias_lookup(alias) != NULL) compile_error("multiply defined alias"); newent = (struct alias_entry *)malloc(sizeof(struct alias_entry)); snprintf(newent->alias, sizeof(newent->alias), "%s", alias); snprintf(newent->dst, sizeof(newent->dst), "%s", dst); newent->next = aliases; aliases=newent; } char *alias_lookup(char *alias) { struct alias_entry *ent = aliases; while (ent) { if (0 == strcmp(ent->alias, alias)) return ent->dst; ent=ent->next; } return NULL; } char *alias_resolve(char *alias) { char *try; while ((try = alias_lookup(alias))) alias=try; return alias; } void alias_preload() { alias_store("p0", "80h"); alias_store("p1", "90h"); alias_store("p2", "0a0h"); alias_store("p3", "0b0h"); alias_store("tmod", "89h"); alias_store("tcon", "88h"); alias_store("th0", "8ch"); alias_store("th1", "8dh"); alias_store("sbuf", "99h"); alias_store("scon", "98h"); alias_store("ri", "scon.0"); alias_store("it0", "tcon.0"); alias_store("it1", "tcon.2"); alias_store("tr0", "tcon.4"); alias_store("tr1", "tcon.6"); alias_store("acc", "0e0h"); alias_store("b", "0f0h"); alias_store("sp", "81h"); alias_store("ie", "0a8h"); alias_store("ea", "ie.7"); alias_store("dpl", "82h"); alias_store("dph", "83h"); }