summaryrefslogtreecommitdiff
path: root/src/symtab.h
blob: ca5a726a804509ba006c77f38247c052c3825bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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