Skip to content
This repository was archived by the owner on Aug 22, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ int main(int argc, char ** argv)
}
else
{
int F = 0;

// Initialise the parser.
verilog_parser_init();

// Setup the preprocessor to look in ./tests/ for include files.
ast_list_append(yy_preproc -> search_dirs, "./tests/");
ast_list_append(yy_preproc -> search_dirs, "./");

int F = 0;
for(F = 1; F < argc; F++)
{

// Initialise the parser.
verilog_parser_init();

// Setup the preprocessor to look in ./tests/ for include files.
ast_list_append(yy_preproc -> search_dirs, "./tests/");
ast_list_append(yy_preproc -> search_dirs, "./");
printf("%s ", argv[F]);fflush(stdout);

// Load the file.
Expand All @@ -52,9 +52,9 @@ int main(int argc, char ** argv)
printf(" - Parse failed\n");
if(argc<=2) return 1;
}

verilog_resolve_modules(yy_verilog_source_tree);
}
}
verilog_resolve_modules(yy_verilog_source_tree);
ast_free_all();
return 0;
}
12 changes: 2 additions & 10 deletions src/verilog_parser_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,8 @@ extern int yyparse();

void verilog_parser_init()
{
if(yy_preproc == NULL)
{
//printf("Added new preprocessor context\n");
yy_preproc = verilog_new_preprocessor_context();
}
if(yy_verilog_source_tree == NULL)
{
//printf("Added new source tree\n");
yy_verilog_source_tree = verilog_new_source_tree();
}
yy_preproc = verilog_new_preprocessor_context();
yy_verilog_source_tree = verilog_new_source_tree();
}

/*!
Expand Down
5 changes: 5 additions & 0 deletions src/verilog_preprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ void verilog_preprocessor_macro_define(

//printf("MACRO: '%s' - '%s'\n", toadd -> macro_id, toadd -> macro_value);

// Set source file of the macro
char * current_file = verilog_preprocessor_current_file(yy_preproc);
toadd -> src_file = ast_strdup(current_file);

ast_hashtable_insert(
yy_preproc -> macrodefines,
toadd -> macro_id,
Expand All @@ -243,6 +247,7 @@ void verilog_preprocessor_macro_define(
void verilog_preprocessor_macro_undefine(
char * macro_name //!< The name of the macro to remove.
){

ast_hashtable_delete(
yy_preproc -> macrodefines,
macro_name
Expand Down
1 change: 1 addition & 0 deletions src/verilog_preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct verilog_macro_directive_t{
unsigned int line; //!< Line number of the directive.
char * macro_id; //!< The name of the macro.
char * macro_value; //!< The value it expands to.
char * src_file; //!< Source file containing the macro definition
} verilog_macro_directive;

/*!
Expand Down
3 changes: 3 additions & 0 deletions src/verilog_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ TERNARY "?"
YY_BUFFER_STATE cur = YY_CURRENT_BUFFER;
YY_BUFFER_STATE n = yy_scan_string(macro -> macro_value);

// Set the "current file" to the one the macro was defined in.
ast_stack_push(yy_preproc -> current_file, macro -> src_file);

yy_switch_to_buffer(cur);
yypush_buffer_state(n);
}
Expand Down