forked from bespoke-silicon-group/basejump_stl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bsg_nonsynth_dpi_rom.hpp
63 lines (58 loc) · 2.19 KB
/
bsg_nonsynth_dpi_rom.hpp
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
#ifndef __BSG_NONSYNTH_DPI_ROM_HPP
#define __BSG_NONSYNTH_DPI_ROM_HPP
#include <svdpi.h>
#include <bsg_nonsynth_dpi.hpp>
#include <cstring>
extern "C" {
// DPI Export function: Get the value at an index in the
// rom. Calls $fatal if an invalid index is accessed.
extern svBitVecVal bsg_dpi_rom_get(int);
}
namespace bsg_nonsynth_dpi{
// dpi_rom is the C++ wrapper class for the
// bsg_nonsynth_dpi_rom verilog module.
//
// Template Parameters:
//
// typename T: The C-type that this rom contains. While
// verilog may represent arbitrary bit-widths, C cannot,
// so this rom is restricted to C-types.
//
// unsigned int N: Number of Elements in the ROM.
//
// Superclasses are used to check template parameters at run
// time against the corresponding verilog module.
template <typename T, unsigned int N>
class dpi_rom : public dpi_base,
public dpi_width<T>,
public dpi_nels<N>{
public:
// Constructor: Creates a dpi_rom object.
//
// Arguments:
// char *hierarchy: The string describing
// the instantiation of this the corresponding
// bsg_nonsynth_dpi_rom verilog module in the
// testbench.
dpi_rom(const std::string &hierarchy)
: dpi_base(hierarchy),
dpi_width<T>(hierarchy),
dpi_nels<N>(hierarchy)
{
}
// T operator[](unsigned int idx): Returns the value
// at an index in the ROM
//
// Arguments:
// unsigned int idx: The index to read
T operator[](unsigned int idx){
T o;
prev = svSetScope(scope);
auto output = bsg_dpi_rom_get(idx);
svSetScope(prev);
svToIntegral(&output, o);
return o;
}
};
}
#endif