diff --git a/Changes b/Changes index 29578c769..4563c75a2 100644 --- a/Changes +++ b/Changes @@ -43,6 +43,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Add experimental config files to filter warnings outside of the source. +*** Add -CFLAGS, -LDFLAGS, .a, .o, and .so options. + *** Speed compiles by avoiding including the STL iostream header. Application programs may need to include it themselves to avoid errors. diff --git a/bin/verilator b/bin/verilator index d70e4e88e..c6e1c441f 100755 --- a/bin/verilator +++ b/bin/verilator @@ -156,9 +156,9 @@ Verilator - Convert Verilog code to C++/SystemC verilator --help verilator --version - verilator --cc [options] [top_level.v] [opt_c_files.cpp/c/cc] - verilator --sc [options] [top_level.v] [opt_c_files.cpp/c/cc] - verilator --sp [options] [top_level.v] [opt_c_files.cpp/c/cc] + verilator --cc [options] [top_level.v] [opt_c_files.cpp/c/cc/a/o/so] + verilator --sc [options] [top_level.v] [opt_c_files.cpp/c/cc/a/o/so] + verilator --sp [options] [top_level.v] [opt_c_files.cpp/c/cc/a/o/so] verilator --lint-only ... =head1 DESCRIPTION @@ -197,6 +197,7 @@ descriptions in the next sections for more information. --bbox-sys Blackbox unknown $system calls --bbox-unsup Blackbox unsupported language features --bin Override Verilator binary + -CFLAGS C++ Compiler flags for makefile --cc Create C++ output --cdc Clock domain crossing analysis --compiler Tune for specified C++ compiler @@ -218,6 +219,8 @@ descriptions in the next sections for more information. -I Directory to search for includes --inhibit-sim Create function to turn off sim --inline-mult Tune module inlining + -LDFLAGS Linker pre-object flags for makefile + -LDLIBS Linker library flags for makefile --language Language standard to parse --lint-only Lint, but do not make output --MMD Create .d dependency files @@ -277,7 +280,15 @@ Specifies optional C++ files to be linked in with the Verilog code. If any C++ files are specified in this way, Verilator will include a make rule that generates a I executable. Without any C++ files, Verilator will stop at the I__ALL.a library, and presume you'll continue -linking with make rules you write yourself. +linking with make rules you write yourself. See also the -CFLAGS option. + +=item {file.a/.o/.so} + +Specifies optional object or library files to be linked in with the Verilog +code, as a shorthand for -LDFLAGS "". If any files are specified in +this way, Verilator will include a make rule that uses these files when +linking the I executable. This generally is only useful when used +with the --exe option. =item --assert @@ -313,6 +324,12 @@ dependency (.d) file is created, this filename will become a source dependency, such that a change in this binary will have make rebuild the output files. +=item -CFLAGS I + +Add specified C compiler flags to the generated makefiles. When make is +run on the generated makefile these will be passed to the C++ compiler +(gcc/g++/msvc++). + =item --cc Specifies C++ without SystemC output mode; see also --sc and --sp. @@ -476,6 +493,16 @@ values, or a value <= 1 will inline everything, will lead to longer compile times, but potentially faster runtimes. This setting is ignored for very small modules; they will always be inlined, if allowed. +=item -LDFLAGS I + +Add specified C linker flags to the generated makefiles. When make is run +on the generated makefile these will be passed to the C++ linker (ld) +*after* the primary file being linked. This flag is called -LDFLAGS as +that's the traditional name in simulators; it's would have been better +called LDLIBS as that's the Makefile variable it controls. (In Make, +LDFLAGS is before the first object, LDLIBS after. -L libraries need to be +in the Make variable LDLIBS, not LDFLAGS.) + =item --language I Select the language to be used when first processing each Verilog file. diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 2c99f6f0e..1dc785e1b 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -151,8 +151,23 @@ public: of.puts("# Module prefix (from --prefix)\n"); of.puts(string("VM_MODPREFIX = ")+v3Global.opt.modPrefix()+"\n"); - V3StringSet dirs; + of.puts("# User CFLAGS (from -CFLAGS on Verilator command line)\n"); + of.puts("VM_USER_CFLAGS = \\\n"); + for (V3StringSet::const_iterator it = v3Global.opt.cFlags().begin(); + it != v3Global.opt.cFlags().end(); ++it) { + of.puts("\t"+*it+" \\\n"); + } + of.puts("\n"); + of.puts("# User LDLIBS (from -LDFLAGS on Verilator command line)\n"); + of.puts("VM_USER_LDLIBS = \\\n"); + for (V3StringSet::const_iterator it = v3Global.opt.ldLibs().begin(); + it != v3Global.opt.ldLibs().end(); ++it) { + of.puts("\t"+*it+" \\\n"); + } + of.puts("\n"); + + V3StringSet dirs; of.puts("# User .cpp files (from .cpp's on Verilator command line)\n"); of.puts("VM_USER_CLASSES = \\\n"); for (V3StringSet::const_iterator it = v3Global.opt.cppFiles().begin(); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 09f75c39c..f0d3cdda7 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -97,6 +97,16 @@ void V3Options::addCppFile(const string& filename) { m_cppFiles.insert(filename); } } +void V3Options::addCFlags(const string& filename) { + if (m_cFlags.find(filename) == m_cFlags.end()) { + m_cFlags.insert(filename); + } +} +void V3Options::addLdLibs(const string& filename) { + if (m_ldLibs.find(filename) == m_ldLibs.end()) { + m_ldLibs.insert(filename); + } +} void V3Options::addFuture(const string& flag) { if (m_futures.find(flag) == m_futures.end()) { m_futures.insert(flag); @@ -538,6 +548,11 @@ bool V3Options::onoff(const char* sw, const char* arg, bool& flag) { return false; } +bool V3Options::suffixed(const char* sw, const char* arg) { + if (strlen(arg) > strlen(sw)) return false; + return (0==strcmp(sw+strlen(sw)-strlen(arg), arg)); +} + void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) { // Parse parameters // Note argc and argv DO NOT INCLUDE the filename in [0]!!! @@ -717,12 +732,20 @@ void V3Options::parseOptsList(FileLine* fl, int argc, char** argv) { } } // Parameterized switches + else if ( !strcmp (sw, "-CFLAGS") && (i+1)