-
Notifications
You must be signed in to change notification settings - Fork 130
Replace MACROS with hashmap #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,12 @@ int macro_return_idx; | |
|
||
/* Global objects */ | ||
|
||
macro_t *MACROS; | ||
int macros_idx = 0; | ||
|
||
/* FUNC_MAP is used to integrate function storing and boost lookup | ||
* performance, currently it uses FNV-1a hash function to hash function | ||
* name. | ||
*/ | ||
|
||
hashmap_t *MACROS_MAP; | ||
hashmap_t *FUNC_MAP; | ||
hashmap_t *ALIASES_MAP; | ||
hashmap_t *CONSTANTS_MAP; | ||
|
@@ -557,28 +556,34 @@ bool remove_alias(char *alias) | |
|
||
macro_t *add_macro(char *name) | ||
{ | ||
macro_t *ma = &MACROS[macros_idx++]; | ||
strcpy(ma->name, name); | ||
macro_t *ma = hashmap_get(MACROS_MAP, name); | ||
if (!ma) { | ||
ma = malloc(sizeof(macro_t)); | ||
if (!ma) { | ||
printf("Failed to allocate macro_t\n"); | ||
return NULL; | ||
} | ||
strcpy(ma->name, name); | ||
hashmap_put(MACROS_MAP, name, ma); | ||
} | ||
ma->disabled = false; | ||
return ma; | ||
} | ||
|
||
macro_t *find_macro(char *name) | ||
{ | ||
for (int i = 0; i < macros_idx; i++) { | ||
if (!MACROS[i].disabled && !strcmp(name, MACROS[i].name)) | ||
return &MACROS[i]; | ||
} | ||
macro_t *ma = hashmap_get(MACROS_MAP, name); | ||
if (ma && !ma->disabled) | ||
return ma; | ||
return NULL; | ||
} | ||
|
||
bool remove_macro(char *name) | ||
{ | ||
for (int i = 0; i < macros_idx; i++) { | ||
if (!MACROS[i].disabled && !strcmp(name, MACROS[i].name)) { | ||
MACROS[i].disabled = true; | ||
return true; | ||
} | ||
macro_t *ma = hashmap_get(MACROS_MAP, name); | ||
if (ma) { | ||
ma->disabled = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
@@ -974,7 +979,7 @@ void global_init(void) | |
{ | ||
elf_code_start = ELF_START + elf_header_len; | ||
|
||
MACROS = malloc(MAX_ALIASES * sizeof(macro_t)); | ||
MACROS_MAP = hashmap_create(MAX_ALIASES); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide a analysis on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used |
||
TYPES = malloc(MAX_TYPES * sizeof(type_t)); | ||
BLOCK_ARENA = arena_init(DEFAULT_ARENA_SIZE); | ||
INSN_ARENA = arena_init(DEFAULT_ARENA_SIZE); | ||
|
@@ -996,7 +1001,7 @@ void global_init(void) | |
|
||
void global_release(void) | ||
{ | ||
free(MACROS); | ||
hashmap_free(MACROS_MAP); | ||
free(TYPES); | ||
arena_free(BLOCK_ARENA); | ||
arena_free(INSN_ARENA); | ||
|
Uh oh!
There was an error while loading. Please reload this page.