How to parse Verilog files and translate them into an svex design
The first step in analyzing a design is to read it in.
The basic function to read and parse a Verilog design is vl::vl-load. The following form shows how to read our ALU design from the file "alu.v".
(defconsts (*alu-vl-design* state) (b* (((mv loadresult state) (vl::vl-load (vl::make-vl-loadconfig :start-files '("alu16.v") :search-path '("lib"))))) (mv (vl::vl-loadresult->design loadresult) state)))
To specify what file(s) to load, we build a vl::vl-loadconfig object.
Here we have provided a starting file to read as well as a search path, from
which we need to load the
Before we go on and translate this into an svex design, we might want to see whether there were any errors in parsing:
(cw-unformatted (vl::vl-reportcard-to-string (vl::vl-design-reportcard *alu-vl-design*)))
This prints the design's "reportcard", the list of warnings about each module. At this point, because our ALU module is well-formed and VL has no trouble parsing it, this doesn't print anything.
The
(defconsts (*alu-svex-design* *alu-simplified-good* *alu-simplified-bad*) (b* (((mv errmsg svex-design good bad) (vl::vl-design->sv-design "alu16" *alu-vl-design* (vl::make-vl-simpconfig)))) (and errmsg (raise "~@0~%" errmsg)) (mv svex-design good bad)))
This runs a series of Verilog to Verilog transforms on the parse tree to simplify it, and finally transforms the simplified hierarchy into an svex design. It returns the resulting svex design, an object of type design, as well as two additional Verilog designs: the portion of the original design that survived the simplification process, and the portion that failed for one reason or another. You can view pretty-printed versions of these:
(cw-unformatted (vl::vl-pps-modulelist (vl::vl-design->mods *alu-simplified-bad*)))
doesn't print anything because our module was OK, whereas
(cw-unformatted (vl::vl-pps-modulelist (vl::vl-design->mods *alu-simplified-good*)))
prints out a module similar to the original alu16 module. You can also print its warnings:
(cw-unformatted (vl::vl-reportcard-to-string (vl::vl-design-reportcard *alu-simplified-good*)))
The svex design
(without-evisc *alu-svex-design*)
To continue the ALU example, next see stvs-and-testing.