14
|
1 #include <string.h>
|
|
2 #include "SymTable.h"
|
|
3
|
20
|
4 SymTable::~SymTable(void)
|
|
5 {
|
|
6 SymTbPtr tb;
|
|
7
|
|
8 for (int i = 0; i < symtb_index; i++) {
|
|
9 tb = &symtb[i];
|
|
10 delete [] tb->sym;
|
|
11 }
|
|
12
|
|
13 delete [] symtb;
|
|
14 }
|
|
15
|
14
|
16 void
|
|
17 SymTable::init(void)
|
|
18 {
|
|
19 symtb = new SymTb[SYM_MAX_SIZE];
|
|
20 symtb_index = 0;
|
|
21 }
|
|
22
|
|
23 void
|
|
24 SymTable::set_symbol(const char *sym, void *addr)
|
|
25 {
|
|
26 SymTbPtr tb = &symtb[symtb_index++];
|
|
27
|
|
28 tb->sym = new char[strlen(sym)+1];
|
|
29 memcpy(tb->sym, sym, strlen(sym)+1);
|
|
30 tb->address = addr;
|
|
31 }
|
|
32
|
|
33 void*
|
|
34 SymTable::get_address(int fd)
|
|
35 {
|
|
36 if (fd >= symtb_index) {
|
|
37 // Fix me
|
|
38 // error process
|
|
39 }
|
|
40
|
|
41 return symtb[fd].address;
|
|
42 }
|
|
43
|
|
44
|
|
45 int
|
|
46 SymTable::get_fd(const char *sym)
|
|
47 {
|
|
48 SymTbPtr tb;
|
|
49
|
|
50 for (int i = 0; i < SYM_MAX_SIZE; i++) {
|
|
51 tb = &symtb[i];
|
|
52 if (strcmp(tb->sym, sym) == 0) {
|
|
53 return i;
|
|
54 }
|
|
55 }
|
|
56
|
|
57 return -1;
|
|
58 }
|