@@ -26,7 +26,7 @@ object Verilator extends VerilogLinter, VerilogSimulator:
26
26
27
27
override protected def toolFiles (using getSet : MemberGetSet ): List [String ] =
28
28
getSet.designDB.srcFiles.collect {
29
- case SourceFile (SourceOrigin .Committed , VerilatorConfig , path, _) =>
29
+ case SourceFile (SourceOrigin .Committed , _ : VerilatorToolSource , path, _) =>
30
30
path.convertWindowsToLinuxPaths
31
31
}
32
32
@@ -52,8 +52,10 @@ object Verilator extends VerilogLinter, VerilogSimulator:
52
52
constructCommand(
53
53
" --lint-only" ,
54
54
" --quiet-stats" ,
55
+ s " --top-module ${topName}" ,
55
56
if (hasTiming) " --timing" else " "
56
57
)
58
+ end lintCmdPreLangFlags
57
59
58
60
override protected def lintCmdPostLangFlags (using
59
61
CompilerOptions ,
@@ -64,17 +66,56 @@ object Verilator extends VerilogLinter, VerilogSimulator:
64
66
(! summon[LinterOptions ].Werror .toBoolean).toFlag(" -Wno-fatal" )
65
67
)
66
68
67
- override protected [dfhdl] def preprocess [D <: Design ](cd : CompiledDesign [D ])(using
69
+ override protected def simulateCmdPreLangFlags (using
70
+ CompilerOptions ,
71
+ SimulatorOptions ,
72
+ MemberGetSet
73
+ ): String =
74
+ constructCommand(
75
+ " --binary" ,
76
+ " --quiet-stats" ,
77
+ s " --top-module ${topName}"
78
+ )
79
+
80
+ override protected [dfhdl] def lintPreprocess [D <: Design ](cd : CompiledDesign [D ])(using
68
81
CompilerOptions ,
69
82
ToolOptions
70
83
): CompiledDesign [D ] =
71
84
addSourceFiles(
72
85
cd,
73
86
List (new VerilatorConfigPrinter (getInstalledVersion)(using cd.stagedDB.getSet).getSourceFile)
74
87
)
88
+
89
+ // override protected[dfhdl] def simulatePreprocess[D <: Design](cd: CompiledDesign[D])(using
90
+ // CompilerOptions,
91
+ // SimulatorOptions
92
+ // ): CompiledDesign[D] =
93
+ // addSourceFiles(
94
+ // cd,
95
+ // List(new VerilatorSimMainPrinter(getInstalledVersion)(using cd.stagedDB.getSet).getSourceFile)
96
+ // )
97
+
98
+ override protected def simulateCmdLanguageFlag (dialect : VerilogDialect ): String =
99
+ lintCmdLanguageFlag(dialect)
100
+
101
+ override def simulate [D <: Design ](
102
+ cd : CompiledDesign [D ]
103
+ )(using CompilerOptions , SimulatorOptions ): CompiledDesign [D ] =
104
+ val ret = super .simulate(cd)
105
+ given MemberGetSet = ret.stagedDB.getSet
106
+ val unixExec =
107
+ s " ${Paths .get(execPath).toAbsolutePath()}${separatorChar}obj_dir ${separatorChar}V ${topName}"
108
+ val runExec : String =
109
+ val osName : String = sys.props(" os.name" ).toLowerCase
110
+ if (osName.contains(" windows" )) s " ${unixExec}.exe " else unixExec
111
+ exec(cmd = " " , runExec = runExec)
112
+ ret
113
+
75
114
end Verilator
76
115
77
- case object VerilatorConfig extends SourceType .ToolConfig
116
+ sealed trait VerilatorToolSource extends SourceType .Tool
117
+
118
+ case object VerilatorConfig extends VerilatorToolSource
78
119
79
120
class VerilatorConfigPrinter (verilatorVersion : String )(using
80
121
getSet : MemberGetSet ,
@@ -171,3 +212,48 @@ class VerilatorConfigPrinter(verilatorVersion: String)(using
171
212
SourceFile (SourceOrigin .Compiled , VerilatorConfig , configFileName, contents)
172
213
173
214
end VerilatorConfigPrinter
215
+
216
+ case object VerilatorSimMain extends VerilatorToolSource
217
+
218
+ // class VerilatorSimMainPrinter(verilatorVersion: String)(using
219
+ // getSet: MemberGetSet,
220
+ // co: CompilerOptions,
221
+ // so: SimulatorOptions
222
+ // ):
223
+ // val designDB: DB = getSet.designDB
224
+ // val topName = designDB.top.dclName
225
+ // def mainFileName: String = s"${topName}.cpp"
226
+ // def contents: String =
227
+ // s"""|#include "V${topName}.h"
228
+ // |#include "verilated.h"
229
+ // |#include "V${topName}___024root.h"
230
+ // |
231
+ // |int main(int argc, char** argv) {
232
+ // | // Initialize Verilator
233
+ // | Verilated::commandArgs(argc, argv);
234
+ // |
235
+ // | // Create instance of our module
236
+ // | V${topName}* top = new V${topName};
237
+ // |
238
+ // | // Initialize simulation inputs
239
+ // | V${topName}___024root* rootp = top->rootp;
240
+ // | rootp->${topName}__DOT__rst = 1;
241
+ // |
242
+ // | while (!Verilated::gotFinish()) {
243
+ // | // Toggle clock
244
+ // | rootp->${topName}__DOT__clk = 0;
245
+ // | top->eval();
246
+ // | rootp->${topName}__DOT__clk = 1;
247
+ // | top->eval();
248
+ // | rootp->${topName}__DOT__rst = 0;
249
+ // | }
250
+ // |
251
+ // | // Cleanup
252
+ // | delete top;
253
+ // |
254
+ // | return 0;
255
+ // |}
256
+ // |""".stripMargin
257
+ // def getSourceFile: SourceFile =
258
+ // SourceFile(SourceOrigin.Compiled, VerilatorSimMain, mainFileName, contents)
259
+ // end VerilatorSimMainPrinter
0 commit comments