1717 "name" : "make build" ,
1818 "description" : "build verilator executable" ,
1919 "subscribes" : ["verilator.build" ],
20- "emits" : ["verilator.sim" , "verilator.cosim" ],
20+ "emits" : ["verilator.sim" ],
2121 "flows" : ["verilator" ],
2222}
2323
@@ -26,15 +26,11 @@ async def handler(data, context):
2626 bbdir = get_buckyball_path ()
2727 arch_dir = f"{ bbdir } /arch"
2828 build_dir = f"{ arch_dir } /build"
29- waveform_dir = f"{ arch_dir } /waveform"
30- log_dir = f"{ arch_dir } /log"
31- cosim = data .get ("cosim" , False )
3229 coverage = data .get ("coverage" , False )
3330
34- # ==================================================================================
35- # Execute operation
3631 # ==================================================================================
3732 # Find sources
33+ # ==================================================================================
3834 vsrcs = glob .glob (f"{ build_dir } /**/*.v" , recursive = True ) + glob .glob (
3935 f"{ build_dir } /**/*.sv" , recursive = True
4036 )
@@ -47,33 +43,71 @@ async def handler(data, context):
4743 + glob .glob (f"{ build_dir } /**/*.cpp" , recursive = True )
4844 )
4945
50- # Setup paths: fesvr from bebop/host/spike/riscv-isa-sim (install/include, install/lib)
51- bebop_isa_sim = f"{ bbdir } /bebop/host/spike/riscv-isa-sim"
46+ # Exclude testchipip's SimDRAM.cc — our SimDRAM_bb.cc overrides memory_init
47+ csrcs = [f for f in csrcs if not f .endswith ("SimDRAM.cc" ) or "src/csrc" in f ]
48+
49+ # Patch fesvr includes out of build/mm.h and build/mm.cc.
50+ # These files are auto-copied from testchipip by Verilator as SimDRAM.v
51+ # companion sources. They reference fesvr/memif.h which we don't have
52+ # (fesvr is removed). The memif_t dependency was only used by SimDRAM.cc's
53+ # load_elf — our SimDRAM_bb.cc doesn't use it.
54+ for patch_file in [f"{ build_dir } /mm.h" , f"{ build_dir } /mm.cc" ]:
55+ if os .path .exists (patch_file ):
56+ with open (patch_file , "r" ) as f :
57+ content = f .read ()
58+ patched = "\n " .join (
59+ line for line in content .splitlines ()
60+ if "fesvr/memif.h" not in line and "fesvr/elfloader.h" not in line
61+ )
62+ if patched != content :
63+ with open (patch_file , "w" ) as f :
64+ f .write (patched )
65+ context .logger .info (f"Patched fesvr includes from { patch_file } " )
66+
67+ topname = "BBSimHarness"
68+
69+ # ==================================================================================
70+ # Build flags
71+ # ==================================================================================
72+ dramsim2_dir = f"{ arch_dir } /thirdparty/chipyard/tools/DRAMSim2"
73+
74+ # Find readline headers/libs in nix store (not in standard paths under nix)
75+ rl_headers = glob .glob ("/nix/store/*readline*-dev/include/readline/readline.h" )
76+ readline_inc = os .path .dirname (os .path .dirname (rl_headers [0 ])) if rl_headers else ""
77+ rl_libs = glob .glob ("/nix/store/*readline*/lib/libreadline.so" )
78+ readline_lib = os .path .dirname (rl_libs [0 ]) if rl_libs else ""
79+
80+ # Find zlib headers/libs in nix store
81+ zlib_headers = glob .glob ("/nix/store/*zlib*-dev/include/zlib.h" )
82+ if not zlib_headers :
83+ zlib_headers = glob .glob ("/nix/store/*zlib*/include/zlib.h" )
84+ zlib_inc = os .path .dirname (zlib_headers [0 ]) if zlib_headers else ""
85+ zlib_libs = glob .glob ("/nix/store/*zlib*/lib/libz.so" )
86+ zlib_lib = os .path .dirname (zlib_libs [0 ]) if zlib_libs else ""
87+
5288 inc_paths = [
53- os .environ .get ("RISCV" , "" ) + "/include" if os .environ .get ("RISCV" ) else "" ,
54- f"{ arch_dir } /thirdparty/chipyard/tools/DRAMSim2" ,
55- f"{ bebop_isa_sim } /install/include" ,
89+ dramsim2_dir ,
5690 build_dir ,
5791 f"{ arch_dir } /src/csrc/include" ,
5892 ]
93+ if readline_inc :
94+ inc_paths .append (readline_inc )
95+ if zlib_inc :
96+ inc_paths .append (zlib_inc )
5997 inc_flags = " " .join ([f"-I{ p } " for p in inc_paths if p ])
6098
61- if cosim :
62- topname = "ToyBuckyball"
63- else :
64- topname = "TestHarness"
99+ # -DBBSIM: selects VBBSimHarness in bdb.h / main.cc
100+ cflags = f"{ inc_flags } -DBBSIM -DTOP_NAME='\" V{ topname } \" ' -std=c++17"
65101
66- cflags = f"{ inc_flags } -DTOP_NAME='\" V{ topname } \" ' -std=c++17 "
67- if cosim :
68- cflags += " -DCOSIM"
69102 ldflags = (
70- f"-lreadline -ldramsim -lfesvr -lstdc++ "
71- f"-L{ bebop_isa_sim } /install/lib "
103+ f"-lreadline -ldramsim -lstdc++ -lz "
72104 f"-L{ bbdir } /result/lib "
73- f"-L{ arch_dir } /thirdparty/chipyard/tools/DRAMSim2 "
74- f"-L{ arch_dir } /thirdparty/chipyard/toolchains/riscv-tools/riscv-isa-sim/build "
75- f"-L{ arch_dir } /thirdparty/chipyard/toolchains/riscv-tools/riscv-isa-sim/build/lib"
105+ f"-L{ dramsim2_dir } "
76106 )
107+ if readline_lib :
108+ ldflags += f"-L{ readline_lib } -Wl,-rpath,{ readline_lib } "
109+ if zlib_lib :
110+ ldflags += f"-L{ zlib_lib } -Wl,-rpath,{ zlib_lib } "
77111
78112 obj_dir = f"{ build_dir } /obj_dir"
79113 subprocess .run (f"rm -rf { obj_dir } " , shell = True )
@@ -82,23 +116,26 @@ async def handler(data, context):
82116 sources = " " .join (vsrcs + csrcs )
83117 jobs = data .get ("jobs" , "" )
84118
85- # Fix nix runtime library paths: embed rpath so binary finds nix libstdc++/glibc
119+ # Fix nix runtime library paths
86120 libstdcpp_path = subprocess .run (
87121 "g++ -print-file-name=libstdc++.so" , shell = True , capture_output = True , text = True
88122 ).stdout .strip ()
89123 if libstdcpp_path and "/" in libstdcpp_path :
90124 nix_lib_dir = os .path .dirname (os .path .realpath (libstdcpp_path ))
91125 ldflags += f" -Wl,-rpath,{ nix_lib_dir } "
92126
93- # Enable ccache for verilator C++ compilation via OBJCACHE
127+ # Enable ccache if available
94128 if subprocess .run ("command -v ccache" , shell = True , capture_output = True ).returncode == 0 :
95129 os .environ ["OBJCACHE" ] = "ccache"
96130
97- # Build acceleration: lld for faster linking (available in nix env)
131+ # Use lld for faster linking if available
98132 use_lld = subprocess .run ("command -v ld.lld" , shell = True , capture_output = True ).returncode == 0
99133 if use_lld :
100134 ldflags += " -fuse-ld=lld"
101135
136+ # ==================================================================================
137+ # Run verilator
138+ # ==================================================================================
102139 verilator_cmd = (
103140 f"verilator -MMD -cc --vpi --trace -O3 --x-assign fast --x-initial fast --noassert -Wno-fatal "
104141 f"--trace-fst --trace-threads 1 --output-split 10000 --output-split-cfuncs 100 "
@@ -148,17 +185,9 @@ async def handler(data, context):
148185 extra_fields = {"task" : "build" },
149186 )
150187
151- # ==================================================================================
152- # Continue routing
153- # ==================================================================================
154188 if data .get ("from_run_workflow" ):
155- if cosim :
156- await context .emit (
157- {"topic" : "verilator.cosim" , "data" : {** data , "task" : "run" }}
158- )
159- else :
160- await context .emit (
161- {"topic" : "verilator.sim" , "data" : {** data , "task" : "run" }}
162- )
189+ await context .emit (
190+ {"topic" : "verilator.sim" , "data" : {** data , "task" : "run" }}
191+ )
163192
164193 return
0 commit comments