summaryrefslogtreecommitdiff
path: root/src/symtab.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/symtab.h')
-rw-r--r--src/symtab.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/symtab.h b/src/symtab.h
new file mode 100644
index 0000000..ca5a726
--- /dev/null
+++ b/src/symtab.h
@@ -0,0 +1,40 @@
+/**
+ * @file symtab.h
+ * @description A basic symbol table implementation, dynamic expansion.
+ *
+ * @todo Implement hash map.
+ */
+
+#ifndef SYMTAB_H
+#define SYMTAB_H
+
+#include "sv.h"
+
+struct symbol_entry {
+ uint64_t symtype;
+ struct string_view name;
+ uintptr_t loc;
+ size_t len;
+};
+
+struct symbol_table {
+ struct symbol_entry *entries;
+ size_t count;
+ size_t cap;
+};
+
+void symtab_init(struct symbol_table *symtab);
+void symtab_expand(struct symbol_table *symtab);
+void symtab_free(struct symbol_table *symtab);
+
+struct symlookup_result {
+ struct symbol_entry *ent;
+ size_t i;
+};
+
+// Returns a pointer, should be on lookout, will reset on expansion.
+struct symlookup_result symtab_lookup(struct symbol_table *symtab,
+ struct string_view ent);
+size_t symtab_append(struct symbol_table *symtab, struct symbol_entry syment);
+
+#endif