Skip to content

Commit 3cf4690

Browse files
authored
Merge pull request verilog-to-routing#697 from CAS-Atlantic/odin_preproc_filepath
Fixed preprocessor filepath
2 parents 0735cae + 2e875c8 commit 3cf4690

File tree

1 file changed

+18
-36
lines changed

1 file changed

+18
-36
lines changed

ODIN_II/SRC/verilog_preprocessor.cpp

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "odin_util.h"
1010
#include <stdbool.h>
1111
#include <regex>
12+
#include <string>
1213

1314
#include "odin_buffer.hpp"
1415

@@ -75,7 +76,6 @@ void push(veri_flag_stack *stack, int flag);
7576

7677
/* General Utility methods ------------------------------------------------- */
7778
static char* get_line(FILE *source, bool *eof, bool *multiline_comment, const char *one_line_comment, const char *n_line_comment_ST, const char *n_line_comment_END);
78-
FILE* open_source_file(char* filename, std::string parent_path);
7979

8080

8181
/* Globals */
@@ -322,39 +322,6 @@ int veri_is_defined(const char * symbol)
322322
return -1;
323323
}
324324

325-
/*
326-
* Return an open file handle
327-
* if the file is not in the pwd try the paths indicated by char* list_of_file_names int current_parse_file
328-
*
329-
* Return NULL if unable to find and open the file
330-
*/
331-
FILE* open_source_file(char* filename, std::string path)
332-
{
333-
auto loc = path.find_last_of('/');
334-
if (loc != std::string::npos) /* No other path to try to find the file */
335-
path = path.substr(0,loc+1);
336-
337-
path += filename;
338-
339-
// look in the directory where the file with the include directory resides in
340-
FILE* src_file = fopen(path.c_str(), "r");
341-
if (src_file != NULL)
342-
return src_file;
343-
344-
// else Look for the file in the PWD as a last resort TODO: this should go away... not standard behavior
345-
src_file = fopen(filename, "r");
346-
if (src_file != NULL)
347-
{
348-
fprintf(stderr, "Warning: Unable to find %s, opening in current working directory instead\n",
349-
path.c_str());
350-
return src_file;
351-
}
352-
353-
354-
355-
return NULL;
356-
}
357-
358325
/*
359326
* Bootstraps our preprocessor
360327
*/
@@ -511,7 +478,22 @@ void veri_preproc_bootstraped(FILE *original_source, FILE *preproc_producer, ver
511478
*/
512479

513480
token = strtok(NULL, "\"");
514-
FILE *included_file = open_source_file(token,current_include->path);
481+
482+
std::string current_path = current_include->path;
483+
auto loc = current_path.find_last_of('/');
484+
if (loc != std::string::npos) /* No other path to try to find the file */
485+
{
486+
current_path = current_path.substr(0,loc+1);
487+
}
488+
else
489+
{
490+
current_path = "";
491+
}
492+
493+
std::string file_path = current_path + token;
494+
495+
FILE* included_file = fopen(file_path.c_str(), "r");
496+
515497

516498
/* If we failed to open the included file handle the error */
517499
if (!included_file)
@@ -521,7 +503,7 @@ void veri_preproc_bootstraped(FILE *original_source, FILE *preproc_producer, ver
521503
perror("included_file : fopen");
522504
/*return erro or exit ? */
523505
}
524-
else if (NULL != (new_include = add_veri_include(token, line_number, current_include)))
506+
else if (NULL != (new_include = add_veri_include(file_path.c_str(), line_number, current_include)))
525507
{
526508
printf("Including file %s\n", new_include->path);
527509
veri_preproc_bootstraped(included_file, preproc_producer, new_include);

0 commit comments

Comments
 (0)