aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/verilator_main.cpp
blob: 94b6a3392ccf0366bb7eedc23564a89ea722de68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdlib.h>
#include <stdio.h>
#include "Vmain.h"
#include "verilated.h"

int main(int argc, char **argv) {
    // Initialize Verilators variables
    Verilated::commandArgs(argc, argv);

    // Create an instance of our module under test
    Vmain *tb = new Vmain;

    tb->clk = 0;
    tb->start = 0;
    tb->reset = 0;
    tb->eval(); tb->clk = 1; tb->eval(); tb->clk = 0; tb->eval();
    tb->reset = 1;
    tb->eval(); tb->clk = 1; tb->eval(); tb->clk = 0; tb->eval();
    tb->reset = 0;
    tb->eval(); tb->clk = 1; tb->eval(); tb->clk = 0; tb->eval();

    size_t cycles = 1;

    // Tick the clock until we are done
    while(!tb->finish) {
        tb->clk = 1;
        tb->eval();
        tb->clk = 0;
        tb->eval();
        cycles++;
    }

    printf("cycles: %lu\nfinished: %u\n", cycles, (unsigned)tb->return_val);
    exit(EXIT_SUCCESS);
}