Merge branch 'master' into verilog-ams
[sverilog.git] / README.txt
blob2d447a2be410d2d8341051f9f51a89e5510b9f7b
1                 THE ICARUS VERILOG COMPILATION SYSTEM
2                 Copyright 2000-2004 Stephen Williams
5 1.0 What is ICARUS Verilog?
7 Icarus Verilog is intended to compile ALL of the Verilog HDL as
8 described in the IEEE-1364 standard. Of course, it's not quite there
9 yet. It does currently handle a mix of structural and behavioral
10 constructs. For a view of the current state of Icarus Verilog, see its
11 home page at <http://www.icarus.com/eda/verilog>.
13 Icarus Verilog is not aimed at being a simulator in the traditional
14 sense, but a compiler that generates code employed by back-end
15 tools. These back-end tools currently include a simulator engine
16 called VVP, an XNF (Xilinx Netlist Format) generator and an EDIF FPGA
17 netlist generator. In the future, backends are expected for EDIF/LPM,
18 structural Verilog, VHDL, etc.
20     For instructions on how to run Icarus Verilog,
21     see the ``iverilog'' man page.
24 2.0 Building/Installing Icarus Verilog From Source
26 If you are starting from source, the build process is designed to be
27 as simple as practical. Someone basically familiar with the target
28 system and C/C++ compilation should be able to build the source
29 distribution with little effort. Some actual programming skills are
30 not required, but helpful in case of problems.
32 If you are building for Windows, see the mingw.txt file.
34 2.1 Compile Time Prerequisites
36 You need the following software to compile Icarus Verilog from source
37 on a UNIX-like system:
39         - GNU Make
40           The Makefiles use some GNU extensions, so a basic POSIX
41           make will not work. Linux systems typically come with a
42           satisfactory make. BSD based systems (i.e., NetBSD, FreeBSD)
43           typically have GNU make as the gmake program.
45         - ISO C++ Compiler
46           The ivl and ivlpp programs are written in C++ and make use
47           of templates and some of the standard C++ library. egcs and
48           recent gcc compilers with the associated libstdc++ are known
49           to work. MSVC++ 5 and 6 are known to definitely *not* work.
51         - bison and flex
53         - gperf 2.7
54           The lexical analyzer doesn't recognize keywords directly,
55           but instead matches symbols and looks them up in a hash
56           table in order to get the proper lexical code. The gperf
57           program generates the lookup table.
59           A version problem with this program is the most common cause
60           of difficulty. See the Icarus Verilog FAQ.
62         - readline 4.2
63           On Linux systems, this usually means the readline-devel
64           rpm. In any case, it is the development headers of readline
65           that are needed.
67         - termcap
68           The readline library in turn uses termcap.
70 If you are building from CVS, you will also need software to generate
71 the configure scripts.
73         - autoconf 2.53
74           This generates configure scripts from configure.in. The 2.53
75           or later versions are known to work, autoconf 2.13 is
76           reported to *not* work.
78 2.2 Compilation
80 Unpack the tar-ball and cd into the verilog-######### directory
81 (presumably that is how you got to this README) and compile the source
82 with the commands:
84   ./configure
85   make
87 Normally, this command automatically figures out everything it needs
88 to know. It generally works pretty well. There are a few flags to the
89 configure script that modify its behavior:
91         --without-ipal
92             This turns off support for Icarus PAL, whether ipal
93             libraries are installed or not.
95         --prefix=<root>
96             The default is /usr/local, which causes the tool suite to
97             be compiled for install in /usr/local/bin,
98             /usr/local/share/ivl, etc.
100             I recommend that if you are configuring for precompiled
101             binaries, use --prefix=/usr.  On Solaris systems, it is
102             common to use --prefix=/opt.  You can configure for a non-root
103             install with --prefix=$HOME.
105         --enable-vvp32 (experimental)
106             If compiling on AMD64 systems, this enables the
107             compilation of 32bit compatible vvp (vvp32) and the vpi
108             modules that match.
110 2.2.1 Special AMD64 Instructions
112 (The Icarus Verilog RPM for x86_64 is build using these instructions.)
114 If you are building for Linux/AMD64 (a.k.a x86_64) then to get the
115 most out of your install, first make sure you have both 64bit and
116 32bit development libraries installed. Then configure with this
117 somewhat more complicated command:
119   ./configure libdir64='$(prefix)/lib64' vpidir1=vpi64 vpidir2=. --enable-vvp32
121 This reflects the convention on AMD64 systems that 64bit libraries go
122 into lib64 directories. The "--enable-vvp32" also turns on 32bit
123 compatibility files. A 32bit version of vvp (vvp32) will be created,
124 as well as 32bit versions of the development libraries and bundled VPI
125 libraries.
127 2.3 (Optional) Testing
129 To run a simple test before installation, execute
131   make check
133 The commands printed by this run might help you in running Icarus
134 Verilog on your own Verilog sources before the package is installed
135 by root.
137 2.4 Installation
139 Now install the files in an appropriate place. (The makefiles by
140 default install in /usr/local unless you specify a different prefix
141 with the --prefix=<path> flag to the configure command.) You may need
142 to do this as root to gain access to installation directories.
144   make install
146 2.5 Uninstallation
148 The generated Makefiles also include the uninstall target. This should
149 remove all the files that ``make install'' creates.
151 3.0 How Icarus Verilog Works
153 This tool includes a parser which reads in Verilog (plus extensions)
154 and generates an internal netlist. The netlist is passed to various
155 processing steps that transform the design to more optimal/practical
156 forms, then is passed to a code generator for final output. The
157 processing steps and the code generator are selected by command line
158 switches.
160 3.1 Preprocessing
162 There is a separate program, ivlpp, that does the preprocessing. This
163 program implements the `include and `define directives producing
164 output that is equivalent but without the directives. The output is a
165 single file with line number directives, so that the actual compiler
166 only sees a single input file. See ivlpp/ivlpp.txt for details.
168 3.2 Parse
170 The Verilog compiler starts by parsing the Verilog source file. The
171 output of the parse is a list of Module objects in "pform". The pform
172 (see pform.h) is mostly a direct reflection of the compilation
173 step. There may be dangling references, and it is not yet clear which
174 module is the root.
176 One can see a human readable version of the final pform by using the
177 ``-P <path>'' flag to the compiler. This will cause iverilog to dump
178 the pform into the file named <path>.
180 3.3 Elaboration
182 This phase takes the pform and generates a netlist. The driver selects
183 (by user request or lucky guess) the root module to elaborate,
184 resolves references and expands the instantiations to form the design
185 netlist. (See netlist.txt.) Final semantic checks are performed during
186 elaboration, and some simple optimizations are performed. The netlist
187 includes all the behavioral descriptions, as well as gates and wires.
189 The elaborate() function performs the elaboration.
191 One can see a human readable version of the final, elaborated and
192 optimized netlist by using the ``-N <path>'' flag to the compiler. If
193 elaboration succeeds, the final netlist (i.e., after optimizations but
194 before code generation) will be dumped into the file named <path>.
196 Elaboration is actually performed in two steps: scopes and parameters
197 first, followed by the structural and behavioral elaboration.
199 3.3.1 Scope Elaboration
201 This pass scans through the pform looking for scopes and parameters. A
202 tree of NetScope objects is built up and placed in the Design object,
203 with the root module represented by the root NetScope object. The
204 elab_scope.cc and elab_pexpr.cc files contain most of the code for
205 handling this phase.
207 The tail of the elaborate_scope behavior (after the pform is
208 traversed) includes a scan of the NetScope tree to locate defparam
209 assignments that were collected during scope elaboration. This is when
210 the defparam overrides are applied to the parameters.
212 3.3.2 Netlist Elaboration
214 After the scopes and parameters are generated and the NetScope tree
215 fully formed, the elaboration runs through the pform again, this time
216 generating the structural and behavioral netlist. Parameters are
217 elaborated and evaluated by now so all the constants of code
218 generation are now known locally, so the netlist can be generated by
219 simply passing through the pform.
221 3.4 Optimization
223 This is actually a collection of processing steps that perform
224 optimizations that do not depend on the target technology. Examples of
225 some useful transformations are
227         - eliminate null effect circuitry
228         - combinational reduction
229         - constant propagation
231 The actual functions performed are specified on the ivl command line by
232 the -F flags (see below).
234 3.5 Code Generation
236 This step takes the design netlist and uses it to drive the code
237 generator (see target.h). This may require transforming the
238 design to suit the technology.
240 The emit() method of the Design class performs this step. It runs
241 through the design elements, calling target functions as need arises
242 to generate actual output.
244 The user selects the target code generator with the -t flag on the
245 command line.
247 3.6 ATTRIBUTES
249     NOTE: The $attribute syntax will soon be deprecated in favor of the
250     Verilog-2001 attribute syntax, which is cleaner and standardized.
252 The parser accepts, as an extension to Verilog, the $attribute module
253 item. The syntax of the $attribute item is:
255         $attribute (<identifier>, <key>, <value>);
257 The $attribute keyword looks like a system task invocation. The
258 difference here is that the parameters are more restricted then those
259 of a system task. The <identifier> must be an identifier. This will be
260 the item to get an attribute. The <key> and <value> are strings, not
261 expressions, that give the key and the value of the attribute to be
262 attached to the identified object.
264 Attributes are [<key> <value>] pairs and are used to communicate with
265 the various processing steps. See the documentation for the processing
266 step for a list of the pertinent attributes.
268 Attributes can also be applied to gate types. When this is done, the
269 attribute is given to every instantiation of the primitive. The syntax
270 for the attribute statement is the same, except that the <identifier>
271 names a primitive earlier in the compilation unit and the statement is
272 placed in global scope, instead of within a module. The semicolon is
273 not part of a type attribute.
275 Note that attributes are also occasionally used for communication
276 between processing steps. Processing steps that are aware of others
277 may place attributes on netlist objects to communicate information to
278 later steps.
280 Icarus Verilog also accepts the Verilog 2001 syntax for
281 attributes. They have the same general meaning as with the $attribute
282 syntax, but they are attached to objects by position instead of by
283 name. Also, the key is a Verilog identifier instead of a string.
285 4.0 Running iverilog
287 The preferred way to invoke the compiler is with the iverilog(1)
288 command. This program invokes the preprocessor (ivlpp) and the
289 compiler (ivl) with the proper command line options to get the job
290 done in a friendly way. See the iverilog(1) man page for usage details.
293 4.1 EXAMPLES
295 Example: Compiling "hello.vl"
297 ------------------------ hello.vl ----------------------------
298 module main();
300 initial
301   begin
302     $display("Hi there");
303     $finish ;
304   end
306 endmodule
308 --------------------------------------------------------------
310 Ensure that "iverilog" is on your search path, and the vpi library
311 is available.
313 To compile the program:
315   iverilog hello.vl
317 (The above presumes that /usr/local/include and /usr/local/lib are
318 part of the compiler search path, which is usually the case for gcc.)
320 To run the program:
322   ./a.out
324 You can use the "-o" switch to name the output command to be generated
325 by the compiler. See the iverilog(1) man page.
327 5.0 Unsupported Constructs
329 Icarus Verilog is in development - as such it still only supports a
330 (growing) subset of Verilog.  Below is a description of some of the
331 currently unsupported Verilog features. This list is not exhaustive,
332 and does not account for errors in the compiler. See the Icarus
333 Verilog web page for the current state of support for Verilog, and in
334 particular, browse the bug report database for reported unsupported
335 constructs.
337   - System functions are supported, but the return value is a little
338     tricky. See SYSTEM FUNCTION TABLE FILES in the iverilog man page.
340   - Specify blocks are parsed but ignored in general.
342   - trireg is not supported. tri0 and tri1 are supported.
344   - tran primitives, i.e. tran, tranif1, tranif0, rtran, rtranif1
345     and rtranif0 are not supported.
347   - Net delays, of the form "wire #N foo;" do not work. Delays in
348     every other context do work properly, including the V2001 form
349     "wire #5 foo = bar;"
351   - Event controls inside non-blocking assignments are not supported.
352     i.e.: a <= @(posedge clk) b;
354   - Macro arguments are not supported. `define macros are supported,
355     but they cannot take arguments.
357 5.1 Nonstandard Constructs or Behaviors
359 Icarus Verilog includes some features that are not part of the
360 IEEE1364 standard, but have well defined meaning, and also sometimes
361 gives nonstandard (but extended) meanings to some features of the
362 language that are defined. See the "extensions.txt" documentation for
363 more details.
365     $is_signed(<expr>)
366         This system function returns 1 if the expression contained is
367         signed, or 0 otherwise. This is mostly of use for compiler
368         regression tests.
370     $sizeof(<expr>)
371     $bits(<expr>)
372         The $bits system function returns the size in bits of the
373         expression that is its argument. The result of this
374         function is undefined if the argument doesn't have a
375         self-determined size.
377         The $sizeof function is deprecated in favor of $bits, which is
378         the same thing, but included in the SystemVerilog definition.
380     $simtime
381         The $simtime system function returns as a 64bit value the
382         simulation time, unscaled by the time units of local
383         scope. This is different from the $time and $stime functions
384         which return the scaled times. This function is added for
385         regression testing of the compiler and run time, but can be
386         used by applications who really want the simulation time.
388         Note that the simulation time can be confusing if there are
389         lots of different `timescales within a design. It is not in
390         general possible to predict what the simulation precision will
391         turn out to be.
393     $mti_random()
394     $mti_dist_uniform
395         These functions are similar to the IEEE1364 standard $random
396         functions, but they use the Mersenne Twister (MT19937)
397         algorithm. This is considered an excellent random number
398         generator, but does not generate the same sequence as the
399         standardized $random.
401     Builtin system functions
403         Certain of the system functions have well defined meanings, so
404         can theoretically be evaluated at compile time, instead of
405         using runtime VPI code. Doing so means that VPI cannot
406         override the definitions of functions handled in this
407         manner. On the other hand, this makes them synthesizable, and
408         also allows for more aggressive constant propagation. The
409         functions handled in this manner are:
411                 $bits
412                 $signed
413                 $sizeof
414                 $unsigned
416         Implementations of these system functions in VPI modules will
417         be ignored.
419     Preprocessing Library Modules
421         Icarus Verilog does preprocess modules that are loaded from
422         libraries via the -y mechanism. However, the only macros
423         defined during compilation of that file are those that it
424         defines itself (or includes) or that are defined on the
425         command line or command file.
427         Specifically, macros defined in the non-library source files
428         are not remembered when the library module is loaded. This is
429         intentional. If it were otherwise, then compilation results
430         might vary depending on the order that libraries are loaded,
431         and that is too unpredictable.
433         It is said that some commercial compilers do allow macro
434         definitions to span library modules. That's just plain weird.
436     Width in %t Time Formats
438         Standard Verilog does not allow width fields in the %t formats
439         of display strings. For example, this is illegal:
441                 $display("Time is %0t", %time);
443         Standard Verilog instead relies on the $timeformat to
444         completely specify the format.
446         Icarus Verilog allows the programmer to specify the field
447         width. The "%t" format in Icarus Verilog works exactly as it
448         does in standard Verilog. However, if the programmer chooses
449         to specify a minimum width (i.e., "%5t"), then for that display
450         Icarus Verilog will override the $timeformat minimum width and
451         use the explicit minimum width.
453     vpiScope iterator on vpiScope objects.
455         In the VPI, the normal way to iterate over vpiScope objects
456         contained within a vpiScope object, is the vpiInternalScope
457         iterator. Icarus Verilog adds support for the vpiScope
458         iterator of a vpiScope object, that iterates over *everything*
459         the is contained in the current scope. This is useful in cases
460         where one wants to iterate over all the objects in a scope
461         without iterating over all the contained types explicitly.
463     time 0 race resolution.
465         Combinational logic is routinely modeled using always
466         blocks. However, this can lead to race conditions if the
467         inputs to the combinational block are initialized in initial
468         statements. Icarus Verilog slightly modifies time 0 scheduling
469         by arranging for always statements with ANYEDGE sensitivity
470         lists to be scheduled before any other threads. This causes
471         combinational always blocks to be triggered when the values in
472         the sensitivity list are initialized by initial threads.
474     Nets with Types
476         Icarus Verilog support an extension syntax that allows nets
477         and regs to be explicitly typed. The currently supported types
478         are logic, bool and real. This implies that "logic" and "bool"
479         are new keywords. Typical syntax is:
481         wire real foo = 1.0;
482         reg logic bar, bat;
484         ... and so forth. The syntax can be turned off by using the
485         -g2 flag to iverilog, and turned on explicitly with the -g2x
486         flag to iverilog.
488 6.0 CREDITS
490 Except where otherwise noted, Icarus Verilog, ivl and ivlpp are
491 Copyright Stephen Williams. The proper notices are in the head of each
492 file. However, I have early on received aid in the form of fixes,
493 Verilog guidance, and especially testing from many people. Testers in
494 particular include a larger community of people interested in a GPL
495 Verilog for Linux.