Navigation Bar e-mail me!

Updated 7/15/22

PLI Page

What is the PLI?

The Programming Language Interface is a way to extend the functionality of Verilog simulators. Why try to build every possible feature into a tool? The PLI lets you add your own custom applications such as C models, delay calculators, file I/O, and more.
My first piece of advice with the PLI is to not use it. Why? Because if you can do something in Verilog, it is more clear and easier to maintain and reuse. For a simple device, write a model in Verilog before trying it with the PLI.
There are four levels of the PLI. The first are the TF (task/function) routines that allow C to access arguments to the system task, as in: 
$my_monitor(signal1);

The next level are the ACC routines, which can access any signal in the design. These can be used when for delay calculators and waveform dumping applications. 
The third level are the VPI routines which use a cleaner, object-oriented interface. 
The newest level is "DirectC" type which allows Verilog code to call C code directly without any wrapper code. (The name I am using comes from the VCS implementation. SuperLog also has a Direct interface.) This PLI level trades off functionality (no event scheduling) with performance (up to 5x faster, and less memory). 

Return to top

Reading and Writing files from Verilog

Read and writing files from Verilog - Now you can read any format file into your model, and open hundreds of output files. Used by dozens of companies around the world. If you are using the latest version of VCS, NC-Verilog, and ModelSim, this is already built into your simulator.

Download the latest file I/O routines for Verilog, currently v3.6 (released 8/31/04). (If you see a page of text when you download, try the uncompressed version, or do a File > Save As > "fileio.tar" as your browser may be automatically decompressing the file.) Read about this PLI application.
Version history:
v3.6, 8/30/04 Added extra checks to $fgets to avoid buffer overflows
v3.5, Internal build
v3.4, 11/6/02 Added $fgetc to fileio.tab, gets() is disabled by default, added to the Fileio/IEEE differences section.
v3.3, 10/28/02 Fixed some documentation problems, especially around VCS and Verilog-XL.

Return to top

Other PLI applications

Read VCD files - My most frequent request from you readers is a way to look at signal changes in the simulation. Don't write it with the PLI - use VCD files instead. But how can you read them? My VCD reader package can read the files either from Unix, or back into a Verilog simulation. Think about analyzing signal behavior, replaying vectors from one simulation to another, or many other ideas.NEW 3/05 but it has been around for years...

Simple C++ example with VCS New 6/03

Read fixed patterns Updated 10/17/03Here is an application to read pattern files without having to be a programmer.

Strobe Compare - Compare the results from two Verilog simulations.

Find X - Locate the unknowns in your simulations. Great for debugging reset problems. Updated 10/17/03.

Write Stdio - How to use the VCS file pointer for stdout - useful for C programmers.

Your own idea - Ask me for help writing a new PLI application.  Please note: if a task can be done in Verilog, it will be easier to debug, probably run faster, and be more portable than writing C code with a myriad of PLI calls.  So don't ask for the C equivalent of a Verilog module.

Return to top

Learn more about the PLI

Verilog PLI Handbook - Stuart Sutherland has written great book on the PLI with detailed explanations and examples.   His encyclopedic knowledge of the PLI makes this the most comprehensive guide available.  Check out his site and place your order with him.  Even if you only use one example, it will be worth every penny.

Stu has also published Verilog 2001, A Guide to the New Features of the Verilog Hardware Description Language.  A great reference for anyone wanting to know more about what has changed, but does not want to wade through the IEEE manual. 

Return to top


Home SystemVerilog PLI Verilog Verification PMC Emacs Bike Personal Viewlogic