blob: dbc1bd2d97590866e8484372a145ac89ed3693f0 (
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
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "as_analyzer.h"
#include <stddef.h>
#include <string.h>
struct sym_table_entry {
const char * name;
size_t offset;
};
const char * compose_section_label(allocator_t alct, const char * section, const char * name) {
size_t section_len = strlen(section);
size_t name_len = strlen(name);
size_t sz = section_len + name_len;
char * buf = allocate(alct, sz + 1);
memcpy(buf, section, section_len);
memcpy(buf + section_len, name, name_len);
buf[sz] = '\0';
return buf;
}
void process_section_label(allocator_t alct, prog_t prog) {
const char * section = "";
stmt_t* 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 = compose_section_label(alct, section, name);
} else {
section = name;
continue;
}
}
}
size_t instr_size(instr_t instr) {
// TODO
return 0;
}
struct sym_table analyze_prog(allocator_t alct, prog_t prog) {
process_section_label(alct, prog);
stmt_t * stmts = prog->stmts->stmts;
for (int i = 0; ; i++) {
if (stmts[i] == NULL) break;
}
struct sym_table tbl;
// TODO
return tbl;
}
|