Surelog Documentation
repository·master·Indexed 19 days ago
https://github.com/chipsalliance/surelogSurelog is a complete SystemVerilog 2017 front-end featuring a preprocessor, parser, and elaborator. It supports open-source cores and generates a Universal Hardware Data Model (UHDM) for use by simulators, synthesis tools, and linters. Key capabilities include incremental compilation via Cap'n'Proto, multi-threaded parsing, a Python API for custom linting, and a C++ API for interacting with design and testbench data models.
What's inside Surelog
- SVAUnit is a UVM-compliant package designed to simplify the creation of stimuli and checkers for validating SystemVerilog Assertions (SVA). It provides a structured way to verify assertions within a UVM environment.
Overview of Surelog features and capabilities
masterSurelog is a SystemVerilog 2017 front-end providing a preprocessor, parser, and elaborator for both design and testbench.
Key features include:
- Parser Engine: Uses Antlr 4.10 for preprocessor and parser generation.
- Incremental Compilation: ASTs are made persistent on disk using Cap'n'Proto.
- Performance: Built to be thread-safe with multi-threaded parsing and module/package splitting for large files.
- Compliance: Supports IEEE Simulator-compliant project specifications and issues Errors/Warning/Info/Notes regarding language compliance.
- Extensibility: A comprehensive Python API allows for custom linting rules (via Parser grammar or design data model), custom message formats, and message waiving.
- Interoperability: Generates a UHDM (Universal Hardware Data Model) compiled database that can be read by 3rd party tools (Synthesis, Simulators, Linters, Formal) via the standard VPI API.
Understand OVM testbench construction principles
masterThe OVM (Open Verification Methodology) examples provide guidance on two primary areas of testbench construction:
Mechanics: Focuses on the structural foundation of a testbench, including:
- Constructing object hierarchies.
- Connecting to hardware using virtual interfaces.
- Implementing simple transaction-based producer-consumer models.
TLM (Transaction Level Modeling): Focuses on communication between testbench components using TLM interfaces and channels to facilitate connectivity.
Simulate USB 2.0 BULK transfers using TLM 2.0 nonblocking transport
masterThis example demonstrates how to model USB 2.0 BULK transfers using UVM TLM 2.0 nonblocking transport methods (
nb_transport_fwandnb_transport_bw). Instead of modeling individual packets, the transfer is modeled as a sequence of timing points using specific phase (ph) tokens and transaction (xfer) properties.Host-to-Device (OUT) Bulk Transfer Sequence
To model a host-to-device transfer, follow these timing points until a
UVM_TLM_COMPLETEDsync value is received:- Token Phase: Call
nb_transport_fw(xfer, ph)wherexfer.kind == OUTandph == USB_TLM_TOKEN. The device responds withUVM_TLM_ACCEPTEDorUVM_TLM_COMPLETED. - Data Phase: Call
nb_transport_fw(xfer, ph)wherexfer.datacontains the bulk data andph == USB_TLM_DATA. The device responds withUVM_TLM_ACCEPTED, orUVM_TLM_COMPLETED(withxfer.statusset toACK/NAK/STALL/NYETandphupdated toUSB_TLM_HANDSHAKE). - Handshake Phase: Call
nb_transport_bw(xfer, ph)wherexfer.statusisACK/NACK/STALL/NYETandph == USB_TLM_HANDSHAKE. The host responds withUVM_TLM_COMPLETED.
- Token Phase: Call
Understand the Codec DUT specification
masterThe Device Under Test (DUT) in this example is a full-duplex parallel-to-serial codec. It handles data transmission and reception with specific character insertion and escaping rules:
Transmission Rules
- Order: Bytes written to the
TxFIFOare transmitted MSB-first. - Idle State: If no bytes are available,
IDLE(0x81) is transmitted. - Sync Character: A
SYNCcharacter (0xB2) is inserted every 7 bytes. - Escaping: To transmit
IDLE(0x81) orESC(0xE7) as valid data, they must be preceded by anESCcharacter.
Reception Rules
- Filtering:
SYNC,IDLE, andESCcharacters are ignored by the receiver unless they are part of the valid data stream (handled via escaping). - Storage: Received bytes are added to the
RxFIFOif it is not full.
Register Map
Address Bits Name Access Description 0x0000 0:0 TxEmptyRO Tx FIFO is empty 0x0000 1:1 TxLowRO Tx is at or below low water mark 0x0000 2:2 TxFullRO Tx FIFO is full (32) 0x0000 4:4 RxEmptyRO Rx FIFO is empty 0x0000 5:5 RxHighRO Rx FIFO is at or above high water mark 0x0000 6:6 RxFullRO Rx FIFO is full (32) 0x0000 8:8 SAW1C Symbol alignment acquired/lost (Resets to b000010001)0x0004 8:0 IntMaskRW Interrupt mask (0 masks source, resets to 0) 0x0010 0:0 TxEnRW Enable transmit path (Resets to 0) 0x0014 4:0 TxLWMRW Tx FIFO low water mark (Resets to 8) 0x0020 0:0 RxEnRW Enable receive path 0x0020 1:1 ALIGNRO Symbol alignment status (Resets to 0) 0x0024 4:0 RxHWMRW Rx FIFO high water mark (Resets to 16) 0x0100 7:0 TxDataWO Write data to TxFIFO 0x0100 7:0 RxDataRO Read data from RxFIFO - Order: Bytes written to the
Understand Surelog Return Codes
masterSurelog returns a bitmask as a return code. Multiple bits can be set simultaneously:
0: No issues0x1: Fatal error(s)0x2: Syntax error(s)0x4: Error(s)
Understand the PPCache Mechanism
masterSurelog uses the
PPCacheclass to persist preprocessor output andIncludeFileInforecords to disk using Cap'n Proto serialization. This enables performance gains through caching and supports incremental compilation.Key Operations
- Saving: Triggered via
PreprocessFile::saveCache()when not using a cached version. - Restoring: Attempted via
cache.restore()using the current command line parser's settings (e.g., checkinglowMem()ornoCacheHash()). - Serialization: The
cacheIncludeFileInfos()method iterates through theIncludeFileInfovector to serialize context, action, and location information, including symbol and path IDs.
- Saving: Triggered via
Understand the Surelog Preprocessor Architecture
masterSurelog's preprocessor is a full ANTLR-based parser rather than a simple text-replacement engine. It uses a dedicated grammar to accurately track file locations, macro expansions, and includes.
Preprocessing Strategy
- Include files: Replaced by their actual content.
- Macro definitions: Removed from output but replaced with equivalent whitespace to preserve line numbering.
- Whitespace preservation: This intentional strategy ensures that line numbers in the preprocessed output maintain a direct correspondence with the original source, simplifying the reconstruction of file/line information during complex nested (imbricated) macro or include usage.
Data Flow
- Parsing: ANTLR parses input using the preprocessor grammar.
- Tree Walking:
SV3_1aPpTreeShapeListenerprocesses directives and createsIncludeFileInforecords. - Output Generation: Preprocessed text and
IncludeFileInforecords are generated. - Caching: Both are serialized to disk via Cap'n Proto.
- Parser Integration: The main SystemVerilog parser consumes the output and uses
IncludeFileInfoto map errors back to original source locations.
Understand UVM API annotations and categories
masterThe UVM implementation uses specific annotations to identify the origin and status of APIs. This helps in identifying standard compliance and portability risks.
API Categories
- Standard APIs: Annotated with
@uvm-ieee 1800.2-2017 [section]to map directly to the IEEE standard. - Potential Contributions: Identified by
// @uvm-contrib Potential Contribution to 1800.2. These are being considered for the standard but are not yet part of it. - Accellera Implementation-specific: Identified by
// @uvm-accellera Accellera Implementation-specific API. These are not part of the IEEE standard and may not be portable to other 1800.2 implementations. - Deprecated UVM 1.2 APIs: These are available only when the macro
`ifdef UVM_ENABLE_DEPRECATED_APIis defined. If this macro is not defined, any code referencing these APIs will fail to compile.
Warning: Code leveraging non-standard APIs (categories 2 and 3) may lack portability across different 1800.2 implementations.
// Example of a standard API annotation // @uvm-ieee 1800.2-2017 auto 16.5.3.2 extern virtual function void get_packed_bits (ref bit unsigned stream[]); // Example of a contribution annotation // @uvm-contrib Potential Contribution to 1800.2- Standard APIs: Annotated with
Nonblocking TLM2 USB 2.0 BULK transfer sequence
masterThis example demonstrates how to model a USB 2.0 BULK transfer using UVM TLM2 nonblocking transport methods (
nb_transport_fwandnb_transport_bw). Instead of simulating individual packets, the model uses timing points (phase updates) to represent the exchange. The sequence continues until aUVM_TLM_COMPLETEDsynchronization value is received by either the host or the device.Host-to-Device (OUT) Bulk Transfer Sequence
- Token Phase: Call
nb_transport_fw(xfer, ph)wherexfer.kind == OUTandph == USB_TLM_TOKEN. The device responds withUVM_TLM_ACCEPTEDorUVM_TLM_COMPLETED. - Data Phase: Call
nb_transport_fw(xfer, ph)wherexfer.datacontains the bulk data andph == USB_TLM_DATA. The device responds withUVM_TLM_ACCEPTEDorUVM_TLM_COMPLETED. If completed,xfer.statusis set toACK/NAK/STALL/NYETandphis updated toUSB_TLM_HANDSHAKE. - Handshake Phase: Call
nb_transport_bw(xfer, ph)wherexfer.statusisACK/NACK/STALL/NYETandph == USB_TLM_HANDSHAKE. The host responds withUVM_TLM_COMPLETED.
Device-to-Host (IN) Bulk Transfer Sequence
- Token Phase: Call
nb_transport_fw(xfer, ph)wherexfer.kind == INandph == USB_TLM_TOKEN. The device responds withUVM_TLM_ACCEPTED,UVM_TLM_UPDATED(with data andphupdated toUSB_TLM_DATA), orUVM_TLM_COMPLETED(withxfer.statusasNAK/STALLandphupdated toUSB_TLM_HANDSHAKE). - Data Phase: Call
nb_transport_bw(xfer, ph)wherexfer.datacontains the bulk data andph == USB_TLM_DATA. The host responds withUVM_TLM_ACCEPTEDorUVM_TLM_COMPLETED(withxfer.status == ACKandphupdated toUSB_TLM_HANDSHAKE). - Handshake Phase: Call
nb_transport_fw(xfer, ph)wherexfer.status == ACKandph == USB_TLM_HANDSHAKE. The device responds withUVM_TLM_COMPLETED.
- Token Phase: Call
Load OVM into a design: Include vs Package methods
masterThere are two primary methods for loading OVM into a SystemVerilog design. The preferred method depends on your IUS version.
1. Include Methodology
Include the OVM header directly into the scope where it will be used:
`include "ovm.svh"When to use: Recommended for IUS versions prior to 8.2, or if you need to use
svppfor handling parameterized types and specializations.2. Package Import Methodology
Compile the OVM package first, then import it. This is the preferred method for IUS 8.2 and later because IUS 8.2+ natively supports parameterized classes without requiring
svpp.Steps:
- Compile
ovm_pkg.sv. - Import the package and include the macros:
import ovm_pkg::*; `include "ovm_macros.svh"Note: You must include
ovm_macros.svhwhen using the package model to ensure access to OVM macro definitions.Scoping Note
If you both import
ovm_pkgand`include "ovm.svh"in the same scope, the local version (viainclude) takes precedence unless you use the scope resolution operator (ovm_pkg::).- Compile
Install the VMM distribution
masterInstalling VMM requires only unpacking the distribution to a convenient location. No additional installation scripts are required.
% mkdir /some/path % cd /some/path % gunzip -c path/to/vmm-1.1.1.tar.gz | tar xvf -