diff options
author | Freya Murphy <freya@freyacat.org> | 2024-10-04 19:41:10 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-10-04 19:41:10 -0400 |
commit | 1c11a13ff33873bcc79d4597d31cd252d5c6c1ae (patch) | |
tree | a4321b97f5ad69d1a9b9d06dd629a4dc532758b0 /masm/tab.h | |
parent | update msim usage (diff) | |
download | mips-1c11a13ff33873bcc79d4597d31cd252d5c6c1ae.tar.gz mips-1c11a13ff33873bcc79d4597d31cd252d5c6c1ae.tar.bz2 mips-1c11a13ff33873bcc79d4597d31cd252d5c6c1ae.zip |
refactor masm to add codegen step
Diffstat (limited to 'masm/tab.h')
-rw-r--r-- | masm/tab.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/masm/tab.h b/masm/tab.h new file mode 100644 index 0000000..c9e66c5 --- /dev/null +++ b/masm/tab.h @@ -0,0 +1,98 @@ +/* Copyright (c) 2024 Freya Murphy */ + +#ifndef __TAB_H__ +#define __TAB_H__ + +#include <stdint.h> +#include <stddef.h> + +#include "lex.h" + +/// +/// Symbol table +/// + +#define SYM_SEC_STUB (UINT32_MAX) + +enum symbol_type { + SYM_LOCAL, + SYM_GLOBAL, + SYM_EXTERN, +}; + +struct symbol { + // the offset of the symbol in a section + uint32_t offset; + // the index of section the symbol is in + uint32_t secidx; + // index into this table + uint32_t tabidx; + // the name of the symbol + struct string name; + // type + enum symbol_type type; +}; + +struct symbol_table { + // length in size in sym ammt + size_t len; + size_t size; + + // symbols + struct symbol *symbols; +}; + +/* initalize a symbol table */ +int symtab_init(struct symbol_table *symtab); + +/* free the symbol table */ +void symtab_free(struct symbol_table *symtab); + +/* add a symbol to the symbol tbl */ +int symtab_push(struct symbol_table *symtab, struct symbol *sym); + +/* find a symbol by name in the symbol table */ +int symtab_find(struct symbol_table *symtab, struct symbol **sym, + const char *name); +/* find an existing symbol with a name or stub a temp one */ +int symtab_find_or_stub(struct symbol_table *symtab, struct symbol **sym, + const struct string *const name); + +/// +/// Reference table +/// + +enum reference_type { + REF_NONE, + REF_MIPS_16, + REF_MIPS_26, + REF_MIPS_PC16, + REF_MIPS_LO16, + REF_MIPS_HI16, +}; + +struct reference { + enum reference_type type; + struct symbol *symbol; + uint32_t offset; +}; + +struct reference_table { + // size + size_t len; + size_t size; + + // references + struct reference *references; +}; + +/* initalize a reference table */ +int reftab_init(struct reference_table *reftab); + +/* free the reference table */ +void reftab_free(struct reference_table *reftab); + +/* add a reference to the reference tbl */ +int reftab_push(struct reference_table *reftab, struct reference *ref); + +#endif /* __TAB_H__ */ |