diff options
| author | Mistivia <i@mistivia.com> | 2025-03-21 23:19:52 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-03-21 23:19:52 +0800 |
| commit | 45e53e55aa555d5a53d9d489e8447e9112eac1f0 (patch) | |
| tree | bfeb09c210557ccf9e8dcf64d917a2e0997414fb /src | |
| parent | 48f36f70413c944be9c764e846a1017dd00c63ec (diff) | |
add analyzer
Diffstat (limited to 'src')
| -rw-r--r-- | src/as_analyzer.c | 48 | ||||
| -rw-r--r-- | src/as_analyzer.h | 12 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/as_analyzer.c b/src/as_analyzer.c new file mode 100644 index 0000000..39616da --- /dev/null +++ b/src/as_analyzer.c @@ -0,0 +1,48 @@ +#include "as_analyzer.h" + +#include <stddef.h> +#include <string.h> + +struct symTableEntry { + const char * name; + size_t offset; +}; + +const char * composeSectionLabel(Allocator alct, const char * section, const char * name) { + size_t sectionLen = strlen(section); + size_t nameLen = strlen(name); + size_t sz = sectionLen + nameLen; + char * buf = allocate(alct, sz + 1); + memcpy(buf, section, sectionLen); + memcpy(buf + sectionLen, name, nameLen); + buf[sz] = '\0'; + return buf; +} + +void processSectionLabel(Allocator alct, Prog prog) { + const char * section = ""; + Stmt* stmts = prog->stmts->stmts; + for (size_t i = 0; ; i++) { + if (stmts[i] == NULL) break; + if (stmts[i]->label == NULL) continue; + const char* name = stmts[i]->label->name; + if (name[0] == '.') { + stmts[i]->label->name = composeSectionLabel(alct, section, name); + } else { + section = name; + continue; + } + } +} + +size_t instrSize(Instr instr) { + // TODO + return 0; +} + +SymTableEntry* analyzeProg(Allocator alct, Prog prog) { + processSectionLabel(alct, prog); + // TODO + return NULL; +} + diff --git a/src/as_analyzer.h b/src/as_analyzer.h new file mode 100644 index 0000000..10cce38 --- /dev/null +++ b/src/as_analyzer.h @@ -0,0 +1,12 @@ +#ifndef FVM_AS_ANALYZER_H_ +#define FVM_AS_ANALYZER_H_ + +#include "as_parser.h" +#include "utils.h" + +struct symTableEntry; +typedef struct symTableEntry * SymTableEntry; + +SymTableEntry * analyzeProg(Allocator alct, Prog prog); + +#endif // FVM_AS_ANALYZER_H_ |
