File: t_mem_multi_io2.cpp

package info (click to toggle)
verilator 5.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 162,552 kB
  • sloc: cpp: 139,204; python: 20,931; ansic: 10,222; yacc: 6,000; lex: 1,925; makefile: 1,260; sh: 494; perl: 282; fortran: 22
file content (91 lines) | stat: -rw-r--r-- 2,079 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// -*- mode: C++; c-file-style: "cc-mode" -*-
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2008 by Lane Brooks.
// SPDX-License-Identifier: CC0-1.0

#include VM_PREFIX_INCLUDE

VM_PREFIX* tb = nullptr;
bool pass = true;

double sc_time_stamp() { return 0; }

void check(const char* bus, int got, int exp) {
    if (got != exp) {
        VL_PRINTF("%%Error: Data mismatch on '%s', got=%x, exp=%x\n", bus, got, exp);
        pass = false;
    }
}

#ifdef SYSTEMC_VERSION
int sc_main(int, char**)
#else
int main()
#endif
{
    Verilated::debug(0);
    tb = new VM_PREFIX{"tb"};

#ifdef SYSTEMC_VERSION
    using namespace sc_core;
    sc_signal<uint32_t> i3;
    sc_signal<uint32_t> o3;
    sc_signal<uint32_t> i34[4];
    sc_signal<uint32_t> o34[4];
    sc_signal<uint32_t> i345[4][5];
    sc_signal<uint32_t> o345[4][5];

    tb->i3(i3);
    tb->o3(o3);
    for (int i = 0; i < 4; i++) {
        tb->i34[i](i34[i]);
        tb->o34[i](o34[i]);
        for (int j = 0; j < 5; j++) {
            tb->i345[i][j](i345[i][j]);
            tb->o345[i][j](o345[i][j]);
        }
    }
#endif

    // loop through every possibility and check the result
    // clang-format off
#ifdef SYSTEMC_VERSION
    sc_start(1, SC_NS);
# define ASSIGN(s, v) s.write(v)
# define READ(s) s.read()
#else
    tb->eval();
# define ASSIGN(s, v) tb->s = (v)
# define READ(s) tb->s
#endif
    // clang-format on

    ASSIGN(i3, 13);
    for (int i = 0; i < 4; i++) {
        ASSIGN(i34[i], i);
        for (int j = 0; j < 5; j++) ASSIGN(i345[i][j], i * 8 + j);
    }

#ifdef SYSTEMC_VERSION
    sc_start(1, SC_NS);
#else
    tb->eval();
#endif

    check("o3", READ(o3), 13);
    for (int i = 0; i < 4; i++) {
        check("o34", READ(o34[i]), i);
        for (int j = 0; j < 5; j++) check("o345", READ(o345[i][j]), i * 8 + j);
    }

    tb->final();
    VL_DO_DANGLING(delete tb, tb);

    if (pass) {
        VL_PRINTF("*-* All Finished *-*\n");
    } else {
        vl_fatal(__FILE__, __LINE__, "top", "Unexpected results from test\n");
    }
    return 0;
}