-
Notifications
You must be signed in to change notification settings - Fork 50
/
Symbols.h
98 lines (85 loc) · 1.92 KB
/
Symbols.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* naken_asm assembler.
* Author: Michael Kohn
* Email: [email protected]
* Web: https://www.mikekohn.net/
* License: GPLv3
*
* Copyright 2010-2023 by Michael Kohn
*
*/
#ifndef NAKEN_ASM_SYMBOLS_H
#define NAKEN_ASM_SYMBOLS_H
#include <stdint.h>
#include "MemoryPool.h"
#define SYMBOLS_HEAP_SIZE 32768
struct SymbolsIter
{
SymbolsIter() :
memory_pool (NULL),
name (NULL),
address (0),
ptr (0),
count (0),
end_flag (0),
scope (0),
flag_export (false)
{
}
void reset()
{
memory_pool = NULL;
name = NULL;
address = 0;
ptr = 0;
count = 0;
end_flag = 0;
scope = 0;
flag_export = false;
}
MemoryPool *memory_pool;
const char *name;
uint32_t address;
int ptr;
int count;
int end_flag;
uint32_t scope;
bool flag_export : 1;
};
class Symbols
{
public:
Symbols();
~Symbols();
struct Entry
{
uint8_t len; // length of name[]
bool flag_rw : 1; // can write to this
bool flag_export : 1; // ELF will export symbol
uint16_t scope; // Up to 65535 local scopes. 0 = global.
uint32_t address; // address for this name
char name[]; // null terminated name of label:
};
Entry *find(const char *name);
int append(const char *name, uint32_t address);
int set(const char *name, uint32_t address);
int export_symbol(const char *name);
int lookup(const char *name, uint32_t *address);
int iterate(SymbolsIter *iter);
int print(FILE *out);
int count();
int export_count();
int scope_start();
void scope_reset() { current_scope = 0; }
void scope_end() { in_scope = false; }
void lock() { locked = true; }
bool is_locked() { return locked; }
void set_debug() { debug = true; }
private:
MemoryPool *memory_pool;
bool locked : 1;
bool in_scope : 1;
bool debug : 1;
uint32_t current_scope;
};
#endif