7
7
from migen .fhdl .structure import _Fragment
8
8
from mibuild .generic_platform import *
9
9
10
- def _build_tb (platform , serial , template ):
10
+ from mibuild import tools
11
+ from mibuild .sim import common
12
+
13
+ def _build_tb (platform , vns , serial , template ):
11
14
12
15
def io_name (ressource , subsignal = None ):
13
16
res = platform .lookup_request (ressource )
14
17
if subsignal is not None :
15
18
res = getattr (res , subsignal )
16
- return platform . vns .get_name (res )
19
+ return vns .get_name (res )
17
20
18
21
ios = """
19
22
#define SYS_CLK dut->{sys_clk}
@@ -79,7 +82,7 @@ def io_name(ressource, subsignal=None):
79
82
f .close ()
80
83
tools .write_to_file ("dut_tb.cpp" , content )
81
84
82
- def _build_sim (platform , build_name , include_paths , sim_path , serial , verbose ):
85
+ def _build_sim (platform , vns , build_name , include_paths , sim_path , serial , verbose ):
83
86
include = ""
84
87
for path in include_paths :
85
88
include += "-I" + path + " "
@@ -95,7 +98,7 @@ def _build_sim(platform, build_name, include_paths, sim_path, serial, verbose):
95
98
build_script_file = "build_" + build_name + ".sh"
96
99
tools .write_to_file (build_script_file , build_script_contents , force_unix = True )
97
100
98
- _build_tb (platform , serial , os .path .join (".." , sim_path ,"dut_tb.cpp" ))
101
+ _build_tb (platform , vns , serial , os .path .join (".." , sim_path ,"dut_tb.cpp" ))
99
102
if verbose :
100
103
r = subprocess .call (["bash" , build_script_file ])
101
104
else :
@@ -112,32 +115,34 @@ def _run_sim(build_name):
112
115
if r != 0 :
113
116
raise OSError ("Subprocess failed" )
114
117
115
- class VerilatorPlatform ( GenericPlatform ) :
118
+ class SimVerilatorToolchain :
116
119
# XXX fir sim_path
117
- def build (self , soc , build_dir = "build" , build_name = "top" ,
120
+ def build (self , platform , fragment , build_dir = "build" , build_name = "top" ,
118
121
sim_path = "../migen/mibuild/sim/" , serial = "console" ,
119
122
run = True , verbose = False ):
120
123
tools .mkdir_noerror (build_dir )
121
124
os .chdir (build_dir )
122
125
123
- self . soc = soc
124
- fragment = soc .get_fragment ()
125
- self .finalize (fragment )
126
- v_src , vns = self . get_verilog ( fragment )
127
- named_sc , named_pc = self . resolve_signals ( vns )
128
- self . vns = vns
126
+ if not isinstance ( fragment , _Fragment ):
127
+ fragment = fragment .get_fragment ()
128
+ platform .finalize (fragment )
129
+
130
+ v_src , vns = platform . get_verilog ( fragment )
131
+ named_sc , named_pc = platform . resolve_signals ( vns )
129
132
v_file = "dut.v"
130
133
tools .write_to_file (v_file , v_src )
131
134
132
135
include_paths = []
133
- for source in self .sources :
136
+ for source in platform .sources :
134
137
path = os .path .dirname (source [0 ]).replace ("\\ " , "\/" )
135
138
if path not in include_paths :
136
139
include_paths .append (path )
137
- include_paths += self .verilog_include_paths
138
- _build_sim (self , build_name , include_paths , sim_path , serial , verbose )
140
+ include_paths += platform .verilog_include_paths
141
+ _build_sim (platform , vns , build_name , include_paths , sim_path , serial , verbose )
139
142
140
143
if run :
141
144
_run_sim (build_name )
142
145
143
146
os .chdir (".." )
147
+
148
+ return vns
0 commit comments