1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
7 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
9 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
14 <a href=
"start.html" class=
"wikilink1" title=
"start.html">gEDA
</a> »
<a href=
"geda-documentation.html" class=
"wikilink1" title=
"geda-documentation.html">Documentation
</a> »
<a href=
"geda-icarus.html" class=
"wikilink1" title=
"geda-icarus.html">Icarus Verilog
</a> »
<a href=
"geda-icarus_readme.txt.html" class=
"wikilink2" title=
"geda-icarus_readme.txt.html">The Icarus Verilog Compilation System
</a>
17 <h1 class=
"sectionedit1" id=
"the_icarus_verilog_compilation_system">The Icarus Verilog Compilation System
</h1>
21 Copyright
2000-
2004 Stephen Williams
25 <!-- EDIT1 SECTION "The Icarus Verilog Compilation System" [109-198] -->
26 <h2 class=
"sectionedit2" id=
"what_is_icarus_verilog">What is ICARUS Verilog?
</h2>
30 Icarus Verilog is intended to compile ALL of the Verilog HDL as
31 described in the IEEE-
1364 standard. Of course, it
's not quite there
32 yet. It does currently handle a mix of structural and behavioral
33 constructs. For a view of the current state of Icarus Verilog, see its
34 home page at
<a href=
"http://www.icarus.com/eda/verilog" class=
"urlextern" title=
"http://www.icarus.com/eda/verilog" rel=
"nofollow">http://www.icarus.com/eda/verilog
</a>.
38 Icarus Verilog is not aimed at being a simulator in the traditional
39 sense, but a compiler that generates code employed by back-end
44 For instructions on how to run Icarus Verilog, see the
<code><a href=
"geda-icarus_mp.html" class=
"wikilink1" title=
"geda-icarus_mp.html">iverilog(
1)
</a></code> man page.
48 <!-- EDIT2 SECTION "What is ICARUS Verilog?" [199-789] -->
49 <h2 class=
"sectionedit3" id=
"building_installing_icarus_verilog_from_source">Building/Installing Icarus Verilog From Source
</h2>
53 If you are starting from source, the build process is designed to be
54 as simple as practical. Someone basically familiar with the target
55 system and C/C++ compilation should be able to build the source
56 distribution with little effort. Some actual programming skills are
57 not required, but helpful in case of problems.
61 If you are building for Windows, see the mingw.txt file.
65 <!-- EDIT3 SECTION "Building/Installing Icarus Verilog From Source" [790-1223] -->
66 <h3 class=
"sectionedit4" id=
"compile_time_prerequisites">Compile Time Prerequisites
</h3>
70 You need the following software to compile Icarus Verilog from source
71 on a UNIX-like system:
74 <li class=
"level1"><div class=
"li"> <strong>GNU Make
</strong><br/>
75 The Makefiles use some GNU extensions, so a basic POSIX make will not work. Linux systems typically come with a satisfactory make. BSD based systems (i.e., NetBSD, FreeBSD) typically have GNU make as the gmake program.
</div>
79 <li class=
"level1"><div class=
"li"> <strong>ISO C++ Compiler
</strong><br/>
80 The
<code>ivl
</code> and
<code>ivlpp
</code> programs are written in C++ and make use of templates and some of the standard C++ library. egcs and recent gcc compilers with the associated libstdc++ are known to work. MSVC++
5 and
6 are known to definitely *not* work.
</div>
84 <li class=
"level1"><div class=
"li"> <strong>bison and flex
</strong></div>
88 <li class=
"level1"><div class=
"li"> <strong>gperf
2.7</strong><br/>
89 The lexical analyzer doesn
't recognize keywords directly, but instead matches symbols and looks them up in a hash table in order to get the proper lexical code. The gperf program generates the lookup table.
<br/>
90 A version problem with this program is the most common cause of difficulty. See the Icarus Verilog
<abbr title=
"Frequently Asked Questions">FAQ
</abbr>.
</div>
94 <li class=
"level1"><div class=
"li"> <strong>readline
4.2</strong><br/>
95 On Linux systems, this usually means the
<code>readline-devel
</code> rpm. In any case, it is the development headers of readline that are needed.
</div>
99 <li class=
"level1"><div class=
"li"> <strong>termcap
</strong><br/>
100 The readline library in turn uses termcap.
</div>
105 If you are building from git, you will also need software to generate
106 the configure scripts.
109 <li class=
"level1"><div class=
"li"> <strong>autoconf
2.53</strong><br/>
110 This generates configure scripts from
<code>configure.in
</code>. The
2.53 or later versions are known to work, autoconf
2.13 is reported to *not* work.
</div>
115 <!-- EDIT4 SECTION "Compile Time Prerequisites" [1224-2706] -->
116 <h3 class=
"sectionedit5" id=
"compilation">Compilation
</h3>
120 Unpack the tar-ball and cd into the
<code>verilog-#########
</code> directory and compile the source
123 <pre class=
"code">./configure
127 Normally, this command automatically figures out everything it needs
128 to know. It generally works pretty well. There are a few flags to the
129 configure script that modify its behavior:
131 <pre class=
"code"> --prefix=
<root
>
132 The default is /usr/local, which causes the tool suite to
133 be compiled for install in /usr/local/bin,
134 /usr/local/share/ivl, etc.
136 I recommend that if you are configuring for precompiled
137 binaries, use --prefix=/usr. On Solaris systems, it is
138 common to use --prefix=/opt. You can configure for a non-root
139 install with --prefix=$HOME.
142 --enable-suffix=
<your-suffix
>
144 Enable/disable changing the names of install files to use
145 a suffix string so that this version or install can co-
146 exist with other versions. This renames the installed
147 commands (iverilog, iverilog-vpi, vvp) and the installed
148 library files and include directory so that installations
149 with the same prefix but different suffix are guaranteed
150 to not interfere with each other.
</pre>
153 <!-- EDIT5 SECTION "Compilation" [2707-3922] -->
154 <h3 class=
"sectionedit6" id=
"optional_testing">(Optional) Testing
</h3>
158 To run a simple test before installation, execute
160 <pre class=
"code">make check
</pre>
163 The commands printed by this run might help you in running Icarus
164 Verilog on your own Verilog sources before the package is installed
169 <!-- EDIT6 SECTION "(Optional) Testing" [3923-4161] -->
170 <h3 class=
"sectionedit7" id=
"installation">Installation
</h3>
174 Now install the files in an appropriate place. (The makefiles by
175 default install in
<code>/usr/local
</code> unless you specify a different prefix
176 with the
<code>–prefix=
<path
></code> flag to the configure command.) You may need
177 to do this as root to gain access to installation directories.
179 <pre class=
"code">make install
</pre>
182 <!-- EDIT7 SECTION "Installation" [4162-4476] -->
183 <h3 class=
"sectionedit8" id=
"uninstallation">Uninstallation
</h3>
187 The generated Makefiles also include the
<code>uninstall
</code> target. This should
188 remove all the files that
<code>make install
</code> creates.
192 <!-- EDIT8 SECTION "Uninstallation" [4477-4630] -->
193 <h2 class=
"sectionedit9" id=
"how_icarus_verilog_works">How Icarus Verilog Works
</h2>
197 This tool includes a parser which reads in Verilog (plus extensions)
198 and generates an internal netlist. The netlist is passed to various
199 processing steps that transform the design to more optimal/practical
200 forms, then is passed to a code generator for final output. The
201 processing steps and the code generator are selected by command line
206 <!-- EDIT9 SECTION "How Icarus Verilog Works" [4631-5018] -->
207 <h3 class=
"sectionedit10" id=
"preprocessing">Preprocessing
</h3>
211 There is a separate program,
<code>ivlpp
</code>, that does the preprocessing. This
212 program implements the
<code>`include
</code> and
<code>`define
</code> directives producing
213 output that is equivalent but without the directives. The output is a
214 single file with line number directives, so that the actual compiler
215 only sees a single input file. See
<code>ivlpp/ivlpp.txt
</code> for details.
219 <!-- EDIT10 SECTION "Preprocessing" [5019-5398] -->
220 <h3 class=
"sectionedit11" id=
"parse">Parse
</h3>
224 The Verilog compiler starts by parsing the Verilog source file. The
225 output of the parse is a list of Module objects in “pform”. The pform
226 (see
<code>pform.h
</code>) is mostly a direct reflection of the compilation
227 step. There may be dangling references, and it is not yet clear which
232 One can see a human readable version of the final pform by using the
233 <code>-P
<path
></code> flag to the
<code>ivl
</code> subcommand. This will cause
<code>ivl
</code>
234 to dump the pform into the file named
<code><path
></code>. (Note that this is not
235 normally done, unless debugging the
<code>ivl
</code> subcommand.)
239 <!-- EDIT11 SECTION "Parse" [5399-5981] -->
240 <h3 class=
"sectionedit12" id=
"elaboration">Elaboration
</h3>
244 This phase takes the pform and generates a netlist. The driver selects
245 (by user request or lucky guess) the root module to elaborate,
246 resolves references and expands the instantiations to form the design
247 netlist. (See
<code>netlist.txt
</code>.) Final semantic checks are performed during
248 elaboration, and some simple optimizations are performed. The netlist
249 includes all the behavioral descriptions, as well as gates and wires.
253 The
<code>elaborate()
</code> function performs the elaboration.
257 One can see a human readable version of the final, elaborated and
258 optimized netlist by using the
<code>-N
<path
></code> flag to the compiler. If
259 elaboration succeeds, the final netlist (i.e., after optimizations but
260 before code generation) will be dumped into the file named
<code><path
></code>.
264 Elaboration is actually performed in two steps: scopes and parameters
265 first, followed by the structural and behavioral elaboration.
270 <h4 id=
"scope_elaboration">Scope Elaboration
</h4>
274 This pass scans through the pform looking for scopes and parameters. A
275 tree of
<code>NetScope
</code> objects is built up and placed in the
<code>Design
</code> object,
276 with the root module represented by the root
<code>NetScope
</code> object. The
277 <code>elab_scope.cc
</code> file contains most of the code for handling this phase.
281 The tail of the
<code>elaborate_scope
</code> behavior (after the pform is
282 traversed) includes a scan of the
<code>NetScope
</code> tree to locate defparam
283 assignments that were collected during scope elaboration. This is when
284 the defparam overrides are applied to the parameters.
289 <h4 id=
"netlist_elaboration">Netlist Elaboration
</h4>
293 After the scopes and parameters are generated and the
<code>NetScope
</code> tree
294 fully formed, the elaboration runs through the pform again, this time
295 generating the structural and behavioral netlist. Parameters are
296 elaborated and evaluated by now so all the constants of code
297 generation are now known locally, so the netlist can be generated by
298 simply passing through the pform.
302 <!-- EDIT12 SECTION "Elaboration" [5982-7876] -->
303 <h3 class=
"sectionedit13" id=
"optimization">Optimization
</h3>
307 This is actually a collection of processing steps that perform
308 optimizations that do not depend on the target technology. Examples of
309 some useful transformations are
312 <li class=
"level1"><div class=
"li"> eliminate null effect circuitry
</div>
314 <li class=
"level1"><div class=
"li"> combinational reduction
</div>
316 <li class=
"level1"><div class=
"li"> constant propagation
</div>
321 The actual functions performed are specified on the
<code>ivl
</code> command line by
322 the
<code>-F
</code> flags (see below).
326 <!-- EDIT13 SECTION "Optimization" [7877-8261] -->
327 <h3 class=
"sectionedit14" id=
"code_generation">Code Generation
</h3>
331 This step takes the design netlist and uses it to drive the code
332 generator (see
<code>target.h
</code>). This may require transforming the
333 design to suit the technology.
337 The
<code>emit()
</code> method of the
<code>Design
</code> class performs this step. It runs
338 through the design elements, calling target functions as need arises
339 to generate actual output.
343 The user selects the target code generator with the
<code>-t
</code> flag on the
348 <!-- EDIT14 SECTION "Code Generation" [8262-8706] -->
349 <h3 class=
"sectionedit15" id=
"attributes">Attributes
</h3>
351 <div class=
"notetip">The
<code>$attribute
</code> syntax will soon be deprecated in favor of the
352 Verilog-
2001 attribute syntax, which is cleaner and standardized.
356 The parser accepts, as an extension to Verilog, the
<code>$attribute
</code> module
357 item. The syntax of the
<code>$attribute
</code> item is:
359 <pre class=
"code">$attribute (
<identifier
>,
<key
>,
<value
>);
</pre>
362 The
<code>$attribute
</code> keyword looks like a system task invocation. The
363 difference here is that the parameters are more restricted than those
364 of a system task. The
<code><identifier
></code> must be an identifier. This will be
365 the item to get an attribute. The
<code><key
></code> and
<code><value
></code> are strings, not
366 expressions, that give the key and the value of the attribute to be
367 attached to the identified object.
371 Attributes are
<code>[
<key
> <value
>]
</code> pairs and are used to communicate with
372 the various processing steps. See the documentation for the processing
373 step for a list of the pertinent attributes.
377 Attributes can also be applied to gate types. When this is done, the
378 attribute is given to every instantiation of the primitive. The syntax
379 for the attribute statement is the same, except that the
<code><identifier
></code>
380 names a primitive earlier in the compilation unit and the statement is
381 placed in global scope, instead of within a module. The semicolon is
382 not part of a type attribute.
386 Note that attributes are also occasionally used for communication
387 between processing steps. Processing steps that are aware of others
388 may place attributes on netlist objects to communicate information to
393 Icarus Verilog also accepts the Verilog
2001 syntax for
394 attributes. They have the same general meaning as with the
<code>$attribute
</code>
395 syntax, but they are attached to objects by position instead of by
396 name. Also, the key is a Verilog identifier instead of a string.
400 <!-- EDIT15 SECTION "Attributes" [8707-10499] -->
401 <h2 class=
"sectionedit16" id=
"running_iverilog">Running iverilog
</h2>
405 The preferred way to invoke the compiler is with the
<code>iverilog(
1)
</code>
406 command. This program invokes the preprocessor (
<code>ivlpp
</code>) and the
407 compiler (
<code>ivl
</code>) with the proper command line options to get the job
408 done in a friendly way. See the
<code><a href=
"geda-icarus_mp.html" class=
"wikilink1" title=
"geda-icarus_mp.html">iverilog(
1)
</a></code> man page for usage details.
412 <!-- EDIT16 SECTION "Running iverilog" [10500-10828] -->
413 <h3 class=
"sectionedit17" id=
"examples">Examples
</h3>
417 Example: Compiling
<code>hello.vl
</code>
420 <dt><a href=
"/./_export/code/:geda:icarus_readme.txt?codeblock=1" title=
"Download Snippet" class=
"mediafile mf_vl_">"hello.vl
"</a></dt>
421 <dd><pre class=
"code verilog"><span class=
"kw1">module
</span> main
<span class=
"br0">(</span><span class=
"br0">)</span><span class=
"sy0">;
</span>
423 <span class=
"kw1">initial
</span>
424 <span class=
"kw1">begin
</span>
425 <span class=
"kw2">$display
</span><span class=
"br0">(</span><span class=
"st0">"Hi there
"</span><span class=
"br0">)</span><span class=
"sy0">;
</span>
426 <span class=
"kw2">$finish
</span> <span class=
"sy0">;
</span>
427 <span class=
"kw1">end
</span>
429 <span class=
"kw1">endmodule
</span></pre>
433 Ensure that
<code>iverilog
</code> is on your search path, and the
<code>vpi
</code> library
438 To compile the program:
440 <pre class=
"code">iverilog hello.vl
</pre>
443 (The above presumes that
<code>/usr/local/include
</code> and
<code>/usr/local/lib
</code> are
444 part of the compiler search path, which is usually the case for gcc.)
450 <pre class=
"code">./a.out
</pre>
453 You can use the
<code>-o
</code> switch to name the output command to be generated
454 by the compiler. See the
<code><a href=
"geda-icarus_mp.html" class=
"wikilink1" title=
"geda-icarus_mp.html">iverilog(
1)
</a></code> man page.
458 <!-- EDIT17 SECTION "Examples" [10829-11456] -->
459 <h2 class=
"sectionedit18" id=
"unsupported_constructs">Unsupported Constructs
</h2>
463 Icarus Verilog is in development—as such it still only supports a
464 (growing) subset of Verilog. Below is a description of some of the
465 currently unsupported Verilog features. This list is not exhaustive,
466 and does not account for errors in the compiler. See the Icarus
467 Verilog web page for the current state of support for Verilog, and in
468 particular, browse the bug report database for reported unsupported
472 <li class=
"level1"><div class=
"li"> System functions are supported, but the return value is a little tricky. See SYSTEM FUNCTION TABLE FILES in the
<a href=
"geda-icarus_mp.html" class=
"wikilink1" title=
"geda-icarus_mp.html">iverilog man page
</a>.
</div>
476 <li class=
"level1"><div class=
"li"> Specify blocks are parsed but ignored in general.
</div>
480 <li class=
"level1"><div class=
"li"> <code>trireg
</code> is not supported.
<code>tri0
</code> and
<code>tri1
</code> are supported.
</div>
484 <li class=
"level1"><div class=
"li"> tran primitives, i.e.
<code>tran
</code>,
<code>tranif1
</code>,
<code>tranif0
</code>,
<code>rtran
</code>,
<code>rtranif1
</code> and
<code>rtranif0
</code> are not supported.
</div>
488 <li class=
"level1"><div class=
"li"> Net delays, of the form
<code>wire #N foo;
</code> do not work. Delays in every other context do work properly, including the V2001 form
<code>wire #
5 foo = bar;
</code></div>
492 <li class=
"level1"><div class=
"li"> Event controls inside non-blocking assignments are not supported. i.e.:
<code>a ⇐ @(posedge clk) b;
</code></div>
496 <li class=
"level1"><div class=
"li"> Macro arguments are not supported.
<code>`define
</code> macros are supported, but they cannot take arguments.
</div>
501 <!-- EDIT18 SECTION "Unsupported Constructs" [11457-12676] -->
502 <h3 class=
"sectionedit19" id=
"nonstandard_constructs_or_behaviors">Nonstandard Constructs or Behaviors
</h3>
506 Icarus Verilog includes some features that are not part of the
507 IEEE1364 standard, but have well defined meaning, and also sometimes
508 gives nonstandard (but extended) meanings to some features of the
509 language that are defined. See the
<code>extensions.txt
</code> documentation for
512 <pre class=
"code"> $is_signed(
<expr
>)
513 This system function returns
1 if the expression contained is
514 signed, or
0 otherwise. This is mostly of use for compiler
517 $sizeof(
<expr
>)
519 The $bits system function returns the size in bits of the
520 expression that is its argument. The result of this
521 function is undefined if the argument doesn
't have a
522 self-determined size.
524 The $sizeof function is deprecated in favor of $bits, which is
525 the same thing, but included in the SystemVerilog definition.
528 The $simtime system function returns as a
64bit value the
529 simulation time, unscaled by the time units of local
530 scope. This is different from the $time and $stime functions
531 which return the scaled times. This function is added for
532 regression testing of the compiler and run time, but can be
533 used by applications who really want the simulation time.
535 Note that the simulation time can be confusing if there are
536 lots of different `timescales within a design. It is not in
537 general possible to predict what the simulation precision will
542 These functions are similar to the IEEE1364 standard $random
543 functions, but they use the Mersenne Twister (MT19937)
544 algorithm. This is considered an excellent random number
545 generator, but does not generate the same sequence as the
546 standardized $random.
548 Builtin system functions
550 Certain of the system functions have well defined meanings, so
551 can theoretically be evaluated at compile time, instead of
552 using runtime VPI code. Doing so means that VPI cannot
553 override the definitions of functions handled in this
554 manner. On the other hand, this makes them synthesizable, and
555 also allows for more aggressive constant propagation. The
556 functions handled in this manner are:
563 Implementations of these system functions in VPI modules will
566 Preprocessing Library Modules
568 Icarus Verilog does preprocess modules that are loaded from
569 libraries via the -y mechanism. However, the only macros
570 defined during compilation of that file are those that it
571 defines itself (or includes) or that are defined on the
572 command line or command file.
574 Specifically, macros defined in the non-library source files
575 are not remembered when the library module is loaded. This is
576 intentional. If it were otherwise, then compilation results
577 might vary depending on the order that libraries are loaded,
578 and that is too unpredictable.
580 It is said that some commercial compilers do allow macro
581 definitions to span library modules. That
's just plain weird.
583 Width in %t Time Formats
585 Standard Verilog does not allow width fields in the %t formats
586 of display strings. For example, this is illegal:
588 $display(
"Time is %
0t
", %time);
590 Standard Verilog instead relies on the $timeformat to
591 completely specify the format.
593 Icarus Verilog allows the programmer to specify the field
594 width. The
"%t
" format in Icarus Verilog works exactly as it
595 does in standard Verilog. However, if the programmer chooses
596 to specify a minimum width (i.e.,
"%
5t
"), then for that display
597 Icarus Verilog will override the $timeformat minimum width and
598 use the explicit minimum width.
600 vpiScope iterator on vpiScope objects.
602 In the VPI, the normal way to iterate over vpiScope objects
603 contained within a vpiScope object, is the vpiInternalScope
604 iterator. Icarus Verilog adds support for the vpiScope
605 iterator of a vpiScope object, that iterates over *everything*
606 the is contained in the current scope. This is useful in cases
607 where one wants to iterate over all the objects in a scope
608 without iterating over all the contained types explicitly.
610 time
0 race resolution.
612 Combinational logic is routinely modeled using always
613 blocks. However, this can lead to race conditions if the
614 inputs to the combinational block are initialized in initial
615 statements. Icarus Verilog slightly modifies time
0 scheduling
616 by arranging for always statements with ANYEDGE sensitivity
617 lists to be scheduled before any other threads. This causes
618 combinational always blocks to be triggered when the values in
619 the sensitivity list are initialized by initial threads.
623 Icarus Verilog support an extension syntax that allows nets
624 and regs to be explicitly typed. The currently supported types
625 are logic, bool and real. This implies that
"logic
" and
"bool
"
626 are new keywords. Typical syntax is:
631 ... and so forth. The syntax can be turned off by using the
632 -g2 flag to iverilog, and turned on explicitly with the -g2x
633 flag to iverilog.
</pre>
636 <!-- EDIT19 SECTION "Nonstandard Constructs or Behaviors" [12677-17701] -->
637 <h2 class=
"sectionedit20" id=
"credits">Credits
</h2>
641 Except where otherwise noted, Icarus Verilog,
<code>ivl
</code> and
<code>ivlpp
</code> are
642 Copyright Stephen Williams. The proper notices are in the head of each
643 file. However, I have early on received aid in the form of fixes,
644 Verilog guidance, and especially testing from many people. Testers in
645 particular include a larger community of people interested in a
<abbr title=
"GNU General Public License">GPL
</abbr>
650 <!-- EDIT20 SECTION "Credits" [17702-] --></body>