@@ -19,24 +19,10 @@ char *intern_string(char *str);
1919/* Lexer */
2020token_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
3624hashmap_t * SRC_FILE_MAP ;
37- hashmap_t * MACROS_MAP ;
3825hashmap_t * FUNC_MAP ;
39- hashmap_t * ALIASES_MAP ;
4026hashmap_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-
344315bb_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-
734634void 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-
786670type_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. */
16881560void 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