Verilator – where to read about library calls, structures

  c++, verilator

I am following a Verilator tutorial here. In every example author first uses verilator to convert verilog to C++ code and then he writes a C++ driver file like this one:

// C++ headers
#include <stdio.h>
#include <stdlib.h>

// Other headers
#include "Vblinky.h"
#include "verilated.h"
#include "verilated_vcd_c.h"


////////////////////////////////////////////////////////////////////////////////////////////////////
void tick(int tick_count, Vblinky * tb, VerilatedVcdC * tfp){

    // I:
    tb->eval();

    // J:
    if(tfp){
        tfp->dump(tick_count * 10 - 2);
    }

    // K:
    tb->i_clk = 1;

    // L:
    tb->eval();

    // M:
    if(tfp){
        tfp->dump(tick_count * 10);
    }

    // N:
    tb->i_clk = 0;

    // O:
    tb->eval();

    // P:
    if(tfp){
        tfp->dump(tick_count * 10 + 5);
        tfp->flush();
    }
}


////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char ** argv){
    
    int k;
    int ll; // Last LED
    unsigned tc; // Tick count ("tick" ≠ "processor period")

    // A:
    Verilated :: commandArgs(argc, argv);

    // B:
    Vblinky * tb = new Vblinky;

    // C:
    Verilated :: traceEverOn(true);
    
    // D:
    VerilatedVcdC * tfp = new VerilatedVcdC;
    
    // E:
    tb->trace(tfp, 00);
    
    // F:
    tfp->open("blinky.vcd");

    // G:
    ll = tb->o_led;
    tc = 0;

    // H:
    for(k = 0; k < 0x100000; k++){
        tick(++tc, tb, tfp);
        
        if(ll != tb->o_led){
            printf("k = %7d, led = %dn", k, tb->o_led);
        }
        ll = tb->o_led;
    }
    
    return 0;
}

Which uses some library calls like in paragraphs A:, B:, C:, D:… Where can I read what these library calls actually do? I am new to C++ but I have some experience in C.

Makefile looks like this (it is more like a batch file I know…):

file_v = blinky
file_pcf = icebreaker
file_cpp = driver
module_top = blinky

all:
    yosys -p "synth_ice40 -top $(module_top) -blif $(file_v).blif" $(file_v).v
    arachne-pnr -d 5k -P sg48 -o $(file_v).asc -p $(file_pcf).pcf $(file_v).blif
    icepack $(file_v).asc $(file_v).bin
    iceprog $(file_v).bin
    verilator --trace -Wall -cc $(file_v).v
    make -C obj_dir -f V$(file_v).mk
    
    g++ 
    -I /usr/share/verilator/include/ 
    -I obj_dir/ 
    /usr/share/verilator/include/verilated.cpp 
    /usr/share/verilator/include/verilated_vcd_c.cpp 
    $(file_cpp).cpp 
    obj_dir/V$(file_v)__ALL.a 
    -o $(file_v).elf

    ./$(file_v).elf

Compiler g++ includes some directories and .cpp files, but I haven’t managed to find anything inside those files yet.

Source: Windows Questions C++

LEAVE A COMMENT