77
88/* Global objects */
99
10- block_t * BLOCKS ;
11- int blocks_idx = 0 ;
10+ block_list_t BLOCKS ;
1211
1312macro_t * MACROS ;
1413int macros_idx = 0 ;
@@ -226,8 +225,16 @@ int find_label_offset(char name[])
226225
227226block_t * add_block (block_t * parent , func_t * func , macro_t * macro )
228227{
229- block_t * blk = & BLOCKS [blocks_idx ];
230- blk -> index = blocks_idx ++ ;
228+ block_t * blk = malloc (sizeof (block_t ));
229+
230+ if (!BLOCKS .head ) {
231+ BLOCKS .head = blk ;
232+ BLOCKS .tail = BLOCKS .head ;
233+ } else {
234+ BLOCKS .tail -> next = blk ;
235+ BLOCKS .tail = blk ;
236+ }
237+
231238 blk -> parent = parent ;
232239 blk -> func = func ;
233240 blk -> macro = macro ;
@@ -394,7 +401,7 @@ var_t *find_local_var(char *token, block_t *block)
394401
395402var_t * find_global_var (char * token )
396403{
397- block_t * block = & BLOCKS [ 0 ] ;
404+ block_t * block = BLOCKS . head ;
398405
399406 for (int i = 0 ; i < block -> next_local ; i ++ ) {
400407 if (!strcmp (block -> locals [i ].var_name , token ))
@@ -587,7 +594,8 @@ void global_init()
587594{
588595 elf_code_start = ELF_START + elf_header_len ;
589596
590- BLOCKS = malloc (MAX_BLOCKS * sizeof (block_t ));
597+ BLOCKS .head = NULL ;
598+ BLOCKS .tail = NULL ;
591599 MACROS = malloc (MAX_ALIASES * sizeof (macro_t ));
592600 FUNCS = malloc (MAX_FUNCS * sizeof (func_t ));
593601 FUNC_TRIES = malloc (MAX_FUNC_TRIES * sizeof (trie_t ));
@@ -613,7 +621,11 @@ void global_init()
613621
614622void global_release ()
615623{
616- free (BLOCKS );
624+ while (BLOCKS .head ) {
625+ block_t * next = BLOCKS .head -> next ;
626+ free (BLOCKS .head );
627+ BLOCKS .head = next ;
628+ }
617629 free (MACROS );
618630 free (FUNCS );
619631 free (FUNC_TRIES );
0 commit comments