Skip to content

Commit 54e9271

Browse files
committed
Remove obsolete definitions
1 parent 1209505 commit 54e9271

File tree

7 files changed

+107
-325
lines changed

7 files changed

+107
-325
lines changed

src/defs.h

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@
2626
#define MAX_BB_DOM_SUCC 64
2727
#define MAX_BB_RDOM_SUCC 256
2828
#define MAX_GLOBAL_IR 256
29-
#define MAX_SOURCE 1048576
3029
#define MAX_CODE 262144
3130
#define MAX_DATA 262144
3231
#define MAX_SYMTAB 65536
3332
#define MAX_STRTAB 65536
3433
#define MAX_HEADER 1024
3534
#define MAX_SECTION 1024
36-
#define MAX_ALIASES 128
3735
#define MAX_CONSTANTS 1024
3836
#define MAX_CASES 128
3937
#define MAX_NESTING 128
@@ -46,7 +44,6 @@
4644
#define SMALL_ARENA_SIZE 65536 /* 64 KiB - for small allocations */
4745
#define LARGE_ARENA_SIZE 524288 /* 512 KiB - for instruction arena */
4846
#define DEFAULT_FUNCS_SIZE 64
49-
#define DEFAULT_INCLUSIONS_SIZE 16
5047

5148
/* Arena compaction bitmask flags for selective memory reclamation */
5249
#define COMPACT_ARENA_BLOCK 0x01 /* BLOCK_ARENA - variables/blocks */
@@ -219,28 +216,10 @@ typedef struct token {
219216
struct token *next;
220217
} token_t;
221218

222-
/* Token structure with metadata for enhanced lexing */
223-
typedef struct token_info {
224-
token_kind_t type;
225-
char value[MAX_TOKEN_LEN];
226-
source_location_t location;
227-
struct token_info *next; /* For freelist management */
228-
} token_info_t;
229-
230-
/* Token freelist for memory reuse */
231-
typedef struct {
232-
token_info_t *freelist;
233-
int allocated_count;
234-
} token_pool_t;
235-
236-
/* Token buffer for improved lookahead */
237-
#define TOKEN_BUFFER_SIZE 8
238-
typedef struct {
239-
token_info_t *tokens[TOKEN_BUFFER_SIZE];
240-
int head;
241-
int tail;
242-
int count;
243-
} token_buffer_t;
219+
typedef struct token_stream {
220+
token_t *head;
221+
token_t *tail;
222+
} token_stream_t;
244223

245224
/* String pool for identifier deduplication */
246225
typedef struct {
@@ -404,25 +383,13 @@ struct var {
404383
int use_count; /* Number of times variable is used */
405384
};
406385

407-
typedef struct {
408-
char name[MAX_VAR_LEN];
409-
bool is_variadic;
410-
int start_source_idx;
411-
var_t param_defs[MAX_PARAMS];
412-
int num_param_defs;
413-
int params[MAX_PARAMS];
414-
int num_params;
415-
bool disabled;
416-
} macro_t;
417-
418386
typedef struct func func_t;
419387

420388
/* block definition */
421389
struct block {
422390
var_list_t locals;
423391
struct block *parent;
424392
func_t *func;
425-
macro_t *macro;
426393
struct block *next;
427394
};
428395

@@ -476,13 +443,6 @@ typedef struct {
476443
type_t *type;
477444
} lvalue_t;
478445

479-
/* alias for #defines */
480-
typedef struct {
481-
char alias[MAX_VAR_LEN];
482-
char value[MAX_VAR_LEN];
483-
bool disabled;
484-
} alias_t;
485-
486446
/* constants for enums */
487447
typedef struct {
488448
char alias[MAX_VAR_LEN];

src/globals.c

Lines changed: 3 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,10 @@ char *intern_string(char *str);
1919
/* Lexer */
2020
token_t *cur_token;
2121

22-
/* Token memory management */
23-
token_pool_t *TOKEN_POOL;
24-
token_buffer_t *TOKEN_BUFFER;
25-
source_location_t current_location; /* Will be initialized at runtime */
26-
27-
bool preproc_match;
28-
29-
/* Point to the first character after where the macro has been called. It is
30-
* needed when returning from the macro body.
31-
*/
32-
int macro_return_idx;
33-
3422
/* Global objects */
3523

3624
hashmap_t *SRC_FILE_MAP;
37-
hashmap_t *MACROS_MAP;
3825
hashmap_t *FUNC_MAP;
39-
hashmap_t *ALIASES_MAP;
4026
hashmap_t *CONSTANTS_MAP;
4127

4228
/* Types */
@@ -326,21 +312,6 @@ constant_t *arena_alloc_constant(void)
326312
return c;
327313
}
328314

329-
alias_t *arena_alloc_alias(void)
330-
{
331-
/* alias_t is simple, can avoid zeroing */
332-
alias_t *a = arena_alloc(GENERAL_ARENA, sizeof(alias_t));
333-
a->alias[0] = '\0';
334-
a->value[0] = '\0';
335-
a->disabled = false;
336-
return a;
337-
}
338-
339-
macro_t *arena_alloc_macro(void)
340-
{
341-
return arena_calloc(GENERAL_ARENA, 1, sizeof(macro_t));
342-
}
343-
344315
bb_traversal_args_t *arena_alloc_traversal_args(void)
345316
{
346317
/* Keep using calloc for safety */
@@ -645,7 +616,7 @@ void set_var_liveout(var_t *var, int end)
645616
var->liveness = end;
646617
}
647618

648-
block_t *add_block(block_t *parent, func_t *func, macro_t *macro)
619+
block_t *add_block(block_t *parent, func_t *func)
649620
{
650621
block_t *blk = arena_alloc(BLOCK_ARENA, sizeof(block_t));
651622

@@ -656,81 +627,10 @@ block_t *add_block(block_t *parent, func_t *func, macro_t *macro)
656627
arena_alloc(BLOCK_ARENA, blk->locals.capacity * sizeof(var_t *));
657628
blk->parent = parent;
658629
blk->func = func;
659-
blk->macro = macro;
660630
blk->next = NULL;
661631
return blk;
662632
}
663633

664-
void add_alias(char *alias, char *value)
665-
{
666-
alias_t *al = hashmap_get(ALIASES_MAP, alias);
667-
if (!al) {
668-
al = arena_alloc_alias();
669-
if (!al) {
670-
printf("Failed to allocate alias_t\n");
671-
return;
672-
}
673-
/* Use interned string for alias name */
674-
strcpy(al->alias, intern_string(alias));
675-
hashmap_put(ALIASES_MAP, alias, al);
676-
}
677-
strcpy(al->value, value);
678-
al->disabled = false;
679-
}
680-
681-
char *find_alias(char alias[])
682-
{
683-
alias_t *al = hashmap_get(ALIASES_MAP, alias);
684-
if (al && !al->disabled)
685-
return al->value;
686-
return NULL;
687-
}
688-
689-
bool remove_alias(char *alias)
690-
{
691-
alias_t *al = hashmap_get(ALIASES_MAP, alias);
692-
if (al && !al->disabled) {
693-
al->disabled = true;
694-
return true;
695-
}
696-
return false;
697-
}
698-
699-
macro_t *add_macro(char *name)
700-
{
701-
macro_t *ma = hashmap_get(MACROS_MAP, name);
702-
if (!ma) {
703-
ma = arena_alloc_macro();
704-
if (!ma) {
705-
printf("Failed to allocate macro_t\n");
706-
return NULL;
707-
}
708-
/* Use interned string for macro name */
709-
strcpy(ma->name, intern_string(name));
710-
hashmap_put(MACROS_MAP, name, ma);
711-
}
712-
ma->disabled = false;
713-
return ma;
714-
}
715-
716-
macro_t *find_macro(char *name)
717-
{
718-
macro_t *ma = hashmap_get(MACROS_MAP, name);
719-
if (ma && !ma->disabled)
720-
return ma;
721-
return NULL;
722-
}
723-
724-
bool remove_macro(char *name)
725-
{
726-
macro_t *ma = hashmap_get(MACROS_MAP, name);
727-
if (ma) {
728-
ma->disabled = true;
729-
return true;
730-
}
731-
return false;
732-
}
733-
734634
void error(char *msg);
735635

736636
/* String pool global */
@@ -767,22 +667,6 @@ char *intern_string(char *str)
767667
return interned;
768668
}
769669

770-
int find_macro_param_src_idx(char *name, block_t *parent)
771-
{
772-
macro_t *macro = parent->macro;
773-
774-
if (!parent)
775-
error("The macro expansion is not supported in the global scope");
776-
if (!parent->macro)
777-
return 0;
778-
779-
for (int i = 0; i < macro->num_param_defs; i++) {
780-
if (!strcmp(macro->param_defs[i].var_name, name))
781-
return macro->params[i];
782-
}
783-
return 0;
784-
}
785-
786670
type_t *add_type(void)
787671
{
788672
if (types_idx >= MAX_TYPES) {
@@ -1206,21 +1090,11 @@ void global_init(void)
12061090
arena_alloc(GENERAL_ARENA, sizeof(string_literal_pool_t));
12071091
string_literal_pool->literals = hashmap_create(256);
12081092

1209-
SOURCE = strbuf_create(MAX_SOURCE);
12101093
SRC_FILE_MAP = hashmap_create(8);
1211-
MACROS_MAP = hashmap_create(MAX_ALIASES);
12121094
FUNC_MAP = hashmap_create(DEFAULT_FUNCS_SIZE);
1213-
INCLUSION_MAP = hashmap_create(DEFAULT_INCLUSIONS_SIZE);
1214-
ALIASES_MAP = hashmap_create(MAX_ALIASES);
12151095
CONSTANTS_MAP = hashmap_create(MAX_CONSTANTS);
12161096

12171097
/* Initialize token management globals */
1218-
current_location.line = 1;
1219-
current_location.column = 1;
1220-
current_location.filename = NULL;
1221-
TOKEN_POOL = NULL;
1222-
TOKEN_BUFFER = NULL;
1223-
12241098
elf_code = strbuf_create(MAX_CODE);
12251099
elf_data = strbuf_create(MAX_DATA);
12261100
elf_rodata = strbuf_create(MAX_DATA);
@@ -1354,10 +1228,7 @@ void global_release(void)
13541228
strbuf_free(elf_section);
13551229

13561230
hashmap_free(SRC_FILE_MAP);
1357-
hashmap_free(MACROS_MAP);
13581231
hashmap_free(FUNC_MAP);
1359-
hashmap_free(INCLUSION_MAP);
1360-
hashmap_free(ALIASES_MAP);
13611232
hashmap_free(CONSTANTS_MAP);
13621233
}
13631234

@@ -1685,39 +1556,10 @@ void error_at(char *msg, source_location_t *loc)
16851556
}
16861557

16871558
/* Reports an error and specifying a position */
1559+
/* FIXME: This function has been deprecated, use `error_at` instead. */
16881560
void error(char *msg)
16891561
{
1690-
/* Construct error source diagnostics, enabling precise identification of
1691-
* syntax and logic issues within the code.
1692-
*/
1693-
int offset, start_idx, i = 0;
1694-
char diagnostic[512 /* MAX_LINE_LEN * 2 */];
1695-
1696-
for (offset = SOURCE->size; offset >= 0 && SOURCE->elements[offset] != '\n';
1697-
offset--)
1698-
;
1699-
1700-
start_idx = offset + 1;
1701-
1702-
for (offset = 0;
1703-
offset < MAX_SOURCE && (start_idx + offset) < SOURCE->size &&
1704-
SOURCE->elements[start_idx + offset] != '\n';
1705-
offset++) {
1706-
diagnostic[i++] = SOURCE->elements[start_idx + offset];
1707-
}
1708-
diagnostic[i++] = '\n';
1709-
1710-
for (offset = start_idx; offset < SOURCE->size; offset++) {
1711-
diagnostic[i++] = ' ';
1712-
}
1713-
1714-
strcpy(diagnostic + i, "^ Error occurs here");
1715-
1716-
/* TODO: Implement line/column tracking for precise error location
1717-
* reporting. Current implementation only shows source position offset.
1718-
*/
1719-
printf("[Error]: %s\nOccurs at source location %d.\n%s\n", msg,
1720-
SOURCE->size, diagnostic);
1562+
printf("[Error]: %s\nOccurs at source location %d.\n", msg, SOURCE->size);
17211563
abort();
17221564
}
17231565

0 commit comments

Comments
 (0)