From 0ea0bffd9a3a173d6eac7902450f5214dcca76f3 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 4 Feb 2009 17:27:25 -0800 Subject: [PATCH] Make the addition of the local directory optional (include path). In the past we automatically added the local directory to the beginning of the include search path. This was found to conflict with what other tools do so this functionality is now only available when the -grelative-include option is given to iverilog. --- driver/iverilog.man | 9 ++++++++- driver/main.c | 23 ++++++++++++++++++++--- ivlpp/globals.h | 4 +++- ivlpp/lexor.lex | 26 ++++++++++---------------- ivlpp/main.c | 9 +++++++++ 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/driver/iverilog.man b/driver/iverilog.man index bbf275b1c..23139fbfb 100644 --- a/driver/iverilog.man +++ b/driver/iverilog.man @@ -1,4 +1,4 @@ -.TH iverilog 1 "April 22nd, 2008" "" "Version 0.9.devel" +.TH iverilog 1 "February 4th, 2009" "" "Version 0.9.devel" .SH NAME iverilog - Icarus Verilog compiler @@ -81,6 +81,13 @@ include directory after all other explicit include directories. This standard include directory is a convenient place to install standard header files that a Verilog program may include. .TP 8 +.B -grelative-include\fI|\fP-gno-relative-include +Enable or disable (default) adding the local files directory to +the beginning of the include file search path. This allows files +to be included relative to the current file not the more common +files are only found in the working directory or in the specified +include file search path. +.TP 8 .B -gxtypes\fI|\fP-gno-xtypes Enable (default) or disable support for extended types. Enabling extended types allows for new types that are supported by Icarus diff --git a/driver/main.c b/driver/main.c index 31e2190ed..96997d437 100644 --- a/driver/main.c +++ b/driver/main.c @@ -120,6 +120,10 @@ const char*gen_system_verilog = "no-system-verilog"; /* Boolean: true means use a default include dir, false means don't */ int gen_std_include = 1; +/* Boolean: true means add the local file directory to the start + of the include list. */ +int gen_relative_include = 0; + char warning_flags[16] = ""; unsigned integer_width = 32; @@ -594,6 +598,12 @@ int process_generation(const char*name) else if (strcmp(name,"no-std-include") == 0) gen_std_include = 0; + + else if (strcmp(name,"relative-include") == 0) + gen_relative_include = 1; + + else if (strcmp(name,"no-relative-include") == 0) + gen_relative_include = 0; else if (strcmp(name,"io-range-error") == 0) gen_io_range_error = "io-range-error"; @@ -613,7 +623,7 @@ int process_generation(const char*name) else if (strcmp(name,"no-verilog-ams") == 0) gen_verilog_ams = "no-verilog-ams"; - else if (strcmp(name,"system-verilog") == 0) + else if (strcmp(name,"system-verilog") == 0) gen_system_verilog = "system-verilog"; else { @@ -627,10 +637,11 @@ int process_generation(const char*name) " specify | no-specify\n" " verilog-ams | no-verilog-ams\n" " std-include | no-std-include\n" + " relative-include | no-relative-include\n" " xtypes | no-xtypes\n" " icarus-misc | no-icarus-misc\n" " io-range-error | no-io-range-error\n" - " strict-ca-eval | no-strict-ca-eval\n" + " strict-ca-eval | no-strict-ca-eval\n" " system-verilog\n"); return 1; } @@ -941,7 +952,13 @@ int main(int argc, char **argv) specifically disabled, then write that directory as the very last include directory to use... always. */ if (gen_std_include) { - fprintf(defines_file, "I:%s%cinclude", base, sep); + fprintf(defines_file, "I:%s%cinclude\n", base, sep); + } + + if (gen_relative_include) { + fprintf(defines_file, "relative include:true\n"); + } else { + fprintf(defines_file, "relative include:false\n"); } fclose(source_file); diff --git a/ivlpp/globals.h b/ivlpp/globals.h index 623baa54a..129db8bcc 100644 --- a/ivlpp/globals.h +++ b/ivlpp/globals.h @@ -1,7 +1,7 @@ #ifndef __globals_H #define __globals_H /* - * Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2009 Stephen Williams (steve@icarus.com) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -34,6 +34,8 @@ extern void dump_precompiled_defines(FILE*out); extern char**include_dir; extern unsigned include_cnt; +extern int relative_include; + /* This flag is true if #line directives are to be generated. */ extern int line_direct_flag; diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 25ce19777..dbe9371b5 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -1422,8 +1422,7 @@ static void output_init() static void include_filename() { - if(standby) - { + if(standby) { emit_pathline(istack); fprintf ( @@ -1443,14 +1442,11 @@ static void include_filename() static void do_include() { /* standby is defined by include_filename() */ - if (standby->path[0] == '/') - { + if (standby->path[0] == '/') { if ((standby->file = fopen(standby->path, "r"))) goto code_that_switches_buffers; - } - else - { - unsigned idx, start = 0; + } else { + unsigned idx, start = 1; char path[4096]; char *cp; @@ -1458,20 +1454,18 @@ static void do_include() strcpy(path, istack->path); cp = strrchr(path, '/'); - if (cp == 0) - start = 1; /* A base file so already in [1] */ - else - { + /* I may need the relative path for a planned warning even when + * we are not in relative mode, so for now keep it around. */ + if (cp != 0) { *cp = '\0'; include_dir[0] = strdup(path); + if (relative_include) start = 0; } - for (idx = start ; idx < include_cnt ; idx += 1) - { + for (idx = start ; idx < include_cnt ; idx += 1) { sprintf(path, "%s/%s", include_dir[idx], standby->path); - if ((standby->file = fopen(path, "r"))) - { + if ((standby->file = fopen(path, "r"))) { /* Free the original path before we overwrite it. */ free(standby->path); standby->path = strdup(path); diff --git a/ivlpp/main.c b/ivlpp/main.c index 15fa23907..5a3e3ee84 100644 --- a/ivlpp/main.c +++ b/ivlpp/main.c @@ -83,6 +83,8 @@ void add_source_file(const char*name) char**include_dir = 0; unsigned include_cnt = 0; +int relative_include = 0; + int line_direct_flag = 0; unsigned error_count = 0; @@ -151,6 +153,13 @@ static int flist_read_flags(const char*path) dep_path = strdup(arg); } + } else if (strcmp(cp,"relative include") == 0) { + if (strcmp(arg, "true") == 0) { + relative_include = 1; + } else { + relative_include = 0; + } + } else { fprintf(stderr, "%s: Invalid keyword %s\n", path, cp); }