CIRCT  20.0.0git
Firtool.cpp
Go to the documentation of this file.
1 //===- Firtool.cpp - Definitions for the firtool pipeline setup -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
18 #include "circt/Support/Passes.h"
20 #include "mlir/Transforms/Passes.h"
21 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/Path.h"
23 
24 using namespace llvm;
25 using namespace circt;
26 
27 LogicalResult firtool::populatePreprocessTransforms(mlir::PassManager &pm,
28  const FirtoolOptions &opt) {
29  pm.nest<firrtl::CircuitOp>().addPass(
31  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createCheckLayers());
32  // Legalize away "open" aggregates to hw-only versions.
33  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerOpenAggsPass());
34 
35  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createResolvePathsPass());
36 
37  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotationsPass(
42 
43  if (opt.shouldEnableDebugInfo())
44  pm.nest<firrtl::CircuitOp>().addNestedPass<firrtl::FModuleOp>(
46 
47  pm.nest<firrtl::CircuitOp>().addPass(
49  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
51 
52  return success();
53 }
54 
55 LogicalResult firtool::populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm,
56  const FirtoolOptions &opt,
57  StringRef inputFilename) {
58  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerSignaturesPass());
59 
60  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInjectDUTHierarchyPass());
61 
62  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
64 
65  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
67 
68  if (!opt.shouldDisableOptimization())
69  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
70  mlir::createCSEPass());
71 
72  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
74 
75  // Run LowerMatches before InferWidths, as the latter does not support the
76  // match statement, but it does support what they lower to.
77  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
79 
80  // Width inference creates canonicalization opportunities.
81  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferWidthsPass());
82 
83  pm.nest<firrtl::CircuitOp>().addPass(
86 
87  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInferResetsPass());
88 
89  if (opt.shouldExportChiselInterface()) {
90  StringRef outdir = opt.getChiselInterfaceOutputDirectory();
91  if (opt.isDefaultOutputFilename() && outdir.empty()) {
92  pm.nest<firrtl::CircuitOp>().addPass(createExportChiselInterfacePass());
93  } else {
94  if (outdir.empty())
95  outdir = opt.getOutputFilename();
96  pm.nest<firrtl::CircuitOp>().addPass(
98  }
99  }
100 
101  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDropConstPass());
102 
103  if (opt.shouldDedup())
104  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createDedupPass());
105 
106  if (opt.shouldConvertVecOfBundle()) {
107  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
109  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createVBToBVPass());
110  }
111 
112  if (!opt.shouldLowerMemories())
113  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
115 
116  // The input mlir file could be firrtl dialect so we might need to clean
117  // things up.
118  // pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerSignaturesPass());
119  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createLowerFIRRTLTypesPass(
120  opt.getPreserveAggregate(), firrtl::PreserveAggregate::None));
121 
122  {
123  auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
124  modulePM.addPass(firrtl::createExpandWhensPass());
125  modulePM.addPass(firrtl::createSFCCompatPass());
126  }
127 
128  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createCheckCombLoopsPass());
129 
130  // Must run this pass after all diagnostic passes have run, otherwise it can
131  // hide errors.
132  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createSpecializeLayersPass());
133 
134  // Run after inference, layer specialization.
136  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createProbesToSignalsPass());
137 
138  {
139  auto &modulePM = pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>();
140  modulePM.addPass(firrtl::createLayerMergePass());
141  modulePM.addPass(firrtl::createLayerSinkPass());
142  }
143 
144  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createInlinerPass());
145 
146  // Preset the random initialization parameters for each module. The current
147  // implementation assumes it can run at a time where every register is
148  // currently in the final module it will be emitted in, all registers have
149  // been created, and no registers have yet been removed.
150  if (opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg))
151  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
153 
154  // If we parsed a FIRRTL file and have optimizations enabled, clean it up.
155  if (!opt.shouldDisableOptimization())
156  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
158 
159  // Run the infer-rw pass, which merges read and write ports of a memory with
160  // mutually exclusive enables.
161  if (!opt.shouldDisableOptimization())
162  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
164 
166  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerMemoryPass());
167 
168  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createPrefixModulesPass());
169 
170  if (opt.shouldAddCompanionAssume())
171  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
173 
174  if (!opt.shouldDisableOptimization())
175  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
176 
177  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerLayersPass());
178 
179  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createAddSeqMemPortsPass());
180 
184 
185  pm.addNestedPass<firrtl::CircuitOp>(firrtl::createExtractInstancesPass());
186 
187  // Run passes to resolve Grand Central features. This should run before
188  // BlackBoxReader because Grand Central needs to inform BlackBoxReader where
189  // certain black boxes should be placed. Note: all Grand Central Taps related
190  // collateral is resolved entirely by LowerAnnotations.
191  pm.addNestedPass<firrtl::CircuitOp>(
193 
194  // Run SymbolDCE as late as possible, but before InnerSymbolDCE. This is for
195  // hierpathop's and just for general cleanup.
196  pm.addNestedPass<firrtl::CircuitOp>(mlir::createSymbolDCEPass());
197 
198  // Run InnerSymbolDCE as late as possible, but before IMDCE.
199  pm.addPass(firrtl::createInnerSymbolDCEPass());
200 
201  // The above passes, IMConstProp in particular, introduce additional
202  // canonicalization opportunities that we should pick up here before we
203  // proceed to output-specific pipelines.
204  if (!opt.shouldDisableOptimization()) {
205  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
207  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
209  // Re-run IMConstProp to propagate constants produced by register
210  // optimizations.
211  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createIMConstPropPass());
212  pm.addPass(firrtl::createIMDeadCodeElimPass());
213  }
214 
215  if (opt.shouldEmitOMIR())
216  pm.nest<firrtl::CircuitOp>().addPass(
218 
219  // Always run this, required for legalization.
220  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
223 
224  if (!opt.shouldDisableOptimization())
225  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
227 
228  auto outputFilename = opt.getOutputFilename();
229  if (outputFilename == "-")
230  outputFilename = "";
231 
232  pm.nest<firrtl::CircuitOp>().addPass(
233  firrtl::createAssignOutputDirsPass(outputFilename));
234 
235  // Read black box source files into the IR.
236  StringRef blackBoxRoot = opt.getBlackBoxRootPath().empty()
237  ? llvm::sys::path::parent_path(inputFilename)
238  : opt.getBlackBoxRootPath();
239  pm.nest<firrtl::CircuitOp>().addPass(
240  firrtl::createBlackBoxReaderPass(blackBoxRoot));
241  return success();
242 }
243 
244 LogicalResult firtool::populateLowFIRRTLToHW(mlir::PassManager &pm,
245  const FirtoolOptions &opt) {
246  // Remove TraceAnnotations and write their updated paths to an output
247  // annotation file.
248  pm.nest<firrtl::CircuitOp>().addPass(
250 
251  // Lower the ref.resolve and ref.send ops and remove the RefType ports.
252  // LowerToHW cannot handle RefType so, this pass must be run to remove all
253  // RefType ports and ops.
254  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerXMRPass());
255 
256  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerDPIPass());
257  pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerClassesPass());
258  pm.nest<firrtl::CircuitOp>().addPass(om::createVerifyObjectFieldsPass());
259 
260  // Check for static asserts.
261  pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
263 
265  opt.getVerificationFlavor()));
266 
267  if (!opt.shouldDisableOptimization()) {
268  auto &modulePM = pm.nest<hw::HWModuleOp>();
269  modulePM.addPass(mlir::createCSEPass());
270  modulePM.addPass(createSimpleCanonicalizerPass());
271  }
272 
273  // Check inner symbols and inner refs.
275 
276  // Check OM object fields.
277  pm.addPass(om::createVerifyObjectFieldsPass());
278 
279  // Run the verif op verification pass
281 
282  return success();
283 }
284 
285 LogicalResult firtool::populateHWToSV(mlir::PassManager &pm,
286  const FirtoolOptions &opt) {
287 
288  if (opt.shouldExtractTestCode())
293 
295  pm.addPass(circt::createLowerSimToSVPass());
297  {/*disableRegRandomization=*/!opt.isRandomEnabled(
298  FirtoolOptions::RandomKind::Reg),
299  /*disableMemRandomization=*/
300  !opt.isRandomEnabled(FirtoolOptions::RandomKind::Mem),
301  /*emitSeparateAlwaysBlocks=*/
303  pm.addNestedPass<hw::HWModuleOp>(createLowerVerifToSVPass());
304  pm.addPass(seq::createHWMemSimImplPass(
305  {/*disableMemRandomization=*/!opt.isRandomEnabled(
306  FirtoolOptions::RandomKind::Mem),
307  /*disableRegRandomization=*/
308  !opt.isRandomEnabled(FirtoolOptions::RandomKind::Reg),
309  /*replSeqMem=*/opt.shouldReplaceSequentialMemories(),
310  /*readEnableMode=*/opt.shouldIgnoreReadEnableMemories()
311  ? seq::ReadEnableMode::Ignore
312  : seq::ReadEnableMode::Undefined,
313  /*addMuxPragmas=*/opt.shouldAddMuxPragmas(),
314  /*addVivadoRAMAddressConflictSynthesisBugWorkaround=*/
316 
317  // If enabled, run the optimizer.
318  if (!opt.shouldDisableOptimization()) {
319  auto &modulePM = pm.nest<hw::HWModuleOp>();
320  modulePM.addPass(mlir::createCSEPass());
321  modulePM.addPass(createSimpleCanonicalizerPass());
322  modulePM.addPass(mlir::createCSEPass());
323  modulePM.addPass(sv::createHWCleanupPass(
324  /*mergeAlwaysBlocks=*/!opt.shouldEmitSeparateAlwaysBlocks()));
325  }
326 
327  // Check inner symbols and inner refs.
329 
330  // Check OM object fields.
331  pm.addPass(om::createVerifyObjectFieldsPass());
332 
333  return success();
334 }
335 
336 namespace detail {
337 LogicalResult
338 populatePrepareForExportVerilog(mlir::PassManager &pm,
339  const firtool::FirtoolOptions &opt) {
340 
341  // Run the verif op verification pass
343 
344  // Legalize unsupported operations within the modules.
345  pm.nest<hw::HWModuleOp>().addPass(sv::createHWLegalizeModulesPass());
346 
347  // Tidy up the IR to improve verilog emission quality.
348  if (!opt.shouldDisableOptimization())
349  pm.nest<hw::HWModuleOp>().addPass(sv::createPrettifyVerilogPass());
350 
351  if (opt.shouldStripFirDebugInfo())
352  pm.addPass(circt::createStripDebugInfoWithPredPass([](mlir::Location loc) {
353  if (auto fileLoc = dyn_cast<FileLineColLoc>(loc))
354  return fileLoc.getFilename().getValue().ends_with(".fir");
355  return false;
356  }));
357 
358  if (opt.shouldStripDebugInfo())
360  [](mlir::Location loc) { return true; }));
361 
362  // Emit module and testbench hierarchy JSON files.
363  if (opt.shouldExportModuleHierarchy())
365 
366  // Check inner symbols and inner refs.
368 
369  // Check OM object fields.
370  pm.addPass(om::createVerifyObjectFieldsPass());
371 
372  return success();
373 }
374 } // namespace detail
375 
376 LogicalResult
377 firtool::populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt,
378  std::unique_ptr<llvm::raw_ostream> os) {
379  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
380  return failure();
381 
382  pm.addPass(createExportVerilogPass(std::move(os)));
383  return success();
384 }
385 
386 LogicalResult firtool::populateExportVerilog(mlir::PassManager &pm,
387  const FirtoolOptions &opt,
388  llvm::raw_ostream &os) {
389  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
390  return failure();
391 
392  pm.addPass(createExportVerilogPass(os));
393  return success();
394 }
395 
396 LogicalResult firtool::populateExportSplitVerilog(mlir::PassManager &pm,
397  const FirtoolOptions &opt,
398  llvm::StringRef directory) {
399  if (failed(::detail::populatePrepareForExportVerilog(pm, opt)))
400  return failure();
401 
402  pm.addPass(createExportSplitVerilogPass(directory));
403  return success();
404 }
405 
406 LogicalResult firtool::populateFinalizeIR(mlir::PassManager &pm,
407  const FirtoolOptions &opt) {
408  pm.addPass(firrtl::createFinalizeIRPass());
409  pm.addPass(om::createFreezePathsPass());
410 
411  return success();
412 }
413 
414 LogicalResult firtool::populateHWToBTOR2(mlir::PassManager &pm,
415  const FirtoolOptions &opt,
416  llvm::raw_ostream &os) {
417  pm.addNestedPass<hw::HWModuleOp>(circt::createLowerLTLToCorePass());
420  pm.addNestedPass<hw::HWModuleOp>(circt::createConvertHWToBTOR2Pass(os));
421  return success();
422 }
423 
424 //===----------------------------------------------------------------------===//
425 // FIRTOOL CommandLine Options
426 //===----------------------------------------------------------------------===//
427 
428 namespace {
429 /// This struct contains command line options that can be used to initialize
430 /// various bits of a Firtool pipeline. This uses a struct wrapper to avoid the
431 /// need for global command line options.
432 struct FirtoolCmdOptions {
433  llvm::cl::opt<std::string> outputFilename{
434  "o",
435  llvm::cl::desc("Output filename, or directory for split output"),
436  llvm::cl::value_desc("filename"),
437  llvm::cl::init("-"),
438  };
439 
440  llvm::cl::opt<bool> disableAnnotationsUnknown{
441  "disable-annotation-unknown",
442  llvm::cl::desc("Ignore unknown annotations when parsing"),
443  llvm::cl::init(false)};
444 
445  llvm::cl::opt<bool> disableAnnotationsClassless{
446  "disable-annotation-classless",
447  llvm::cl::desc("Ignore annotations without a class when parsing"),
448  llvm::cl::init(false)};
449 
450  llvm::cl::opt<bool> lowerAnnotationsNoRefTypePorts{
451  "lower-annotations-no-ref-type-ports",
452  llvm::cl::desc(
453  "Create real ports instead of ref type ports when resolving "
454  "wiring problems inside the LowerAnnotations pass"),
455  llvm::cl::init(false), llvm::cl::Hidden};
456 
457  llvm::cl::opt<bool> allowAddingPortsOnPublic{
458  "allow-adding-ports-on-public-modules",
459  llvm::cl::desc("Allow adding ports to public modules"),
460  llvm::cl::init(false), llvm::cl::Hidden};
461 
462  llvm::cl::opt<bool> probesToSignals{
463  "probes-to-signals",
464  llvm::cl::desc("Convert probes to non-probe signals"),
465  llvm::cl::init(false), llvm::cl::Hidden};
466 
468  preserveAggregate{
469  "preserve-aggregate",
470  llvm::cl::desc("Specify input file format:"),
471  llvm::cl::values(
472  clEnumValN(circt::firrtl::PreserveAggregate::None, "none",
473  "Preserve no aggregate"),
474  clEnumValN(circt::firrtl::PreserveAggregate::OneDimVec, "1d-vec",
475  "Preserve only 1d vectors of ground type"),
476  clEnumValN(circt::firrtl::PreserveAggregate::Vec, "vec",
477  "Preserve only vectors"),
478  clEnumValN(circt::firrtl::PreserveAggregate::All, "all",
479  "Preserve vectors and bundles")),
481  };
482 
484  "preserve-values",
485  llvm::cl::desc("Specify the values which can be optimized away"),
486  llvm::cl::values(
487  clEnumValN(firrtl::PreserveValues::Strip, "strip",
488  "Strip all names. No name is preserved"),
489  clEnumValN(firrtl::PreserveValues::None, "none",
490  "Names could be preserved by best-effort unlike `strip`"),
491  clEnumValN(firrtl::PreserveValues::Named, "named",
492  "Preserve values with meaningful names"),
493  clEnumValN(firrtl::PreserveValues::All, "all",
494  "Preserve all values")),
495  llvm::cl::init(firrtl::PreserveValues::None)};
496 
497  llvm::cl::opt<bool> enableDebugInfo{
498  "g", llvm::cl::desc("Enable the generation of debug information"),
499  llvm::cl::init(false)};
500 
501  // Build mode options.
503  "O", llvm::cl::desc("Controls how much optimization should be performed"),
504  llvm::cl::values(clEnumValN(firtool::FirtoolOptions::BuildModeDebug,
505  "debug",
506  "Compile with only necessary optimizations"),
507  clEnumValN(firtool::FirtoolOptions::BuildModeRelease,
508  "release", "Compile with optimizations")),
509  llvm::cl::init(firtool::FirtoolOptions::BuildModeDefault)};
510 
511  llvm::cl::opt<bool> disableOptimization{
512  "disable-opt",
513  llvm::cl::desc("Disable optimizations"),
514  };
515 
517  "export-chisel-interface",
518  llvm::cl::desc("Generate a Scala Chisel interface to the top level "
519  "module of the firrtl circuit"),
520  llvm::cl::init(false)};
521 
522  llvm::cl::opt<std::string> chiselInterfaceOutDirectory{
523  "chisel-interface-out-dir",
524  llvm::cl::desc(
525  "The output directory for generated Chisel interface files"),
526  llvm::cl::init("")};
527 
528  llvm::cl::opt<bool> vbToBV{
529  "vb-to-bv",
530  llvm::cl::desc("Transform vectors of bundles to bundles of vectors"),
531  llvm::cl::init(false)};
532 
533  llvm::cl::opt<bool> noDedup{
534  "no-dedup",
535  llvm::cl::desc("Disable deduplication of structurally identical modules"),
536  llvm::cl::init(false)};
537 
539  "grand-central-companion-mode",
540  llvm::cl::desc("Specifies the handling of Grand Central companions"),
541  ::llvm::cl::values(
542  clEnumValN(firrtl::CompanionMode::Bind, "bind",
543  "Lower companion instances to SystemVerilog binds"),
544  clEnumValN(firrtl::CompanionMode::Instantiate, "instantiate",
545  "Instantiate companions in the design"),
546  clEnumValN(firrtl::CompanionMode::Drop, "drop",
547  "Remove companions from the design")),
548  llvm::cl::init(firrtl::CompanionMode::Bind),
549  llvm::cl::Hidden,
550  };
551 
552  llvm::cl::opt<bool> disableAggressiveMergeConnections{
553  "disable-aggressive-merge-connections",
554  llvm::cl::desc(
555  "Disable aggressive merge connections (i.e. merge all field-level "
556  "connections into bulk connections)"),
557  llvm::cl::init(false)};
558 
559  llvm::cl::opt<bool> emitOMIR{
560  "emit-omir", llvm::cl::desc("Emit OMIR annotations to a JSON file"),
561  llvm::cl::init(true)};
562 
563  llvm::cl::opt<std::string> omirOutFile{
564  "output-omir", llvm::cl::desc("File name for the output omir"),
565  llvm::cl::init("")};
566 
567  llvm::cl::opt<bool> lowerMemories{
568  "lower-memories",
569  llvm::cl::desc("Lower memories to have memories with masks as an "
570  "array with one memory per ground type"),
571  llvm::cl::init(false)};
572 
573  llvm::cl::opt<std::string> blackBoxRootPath{
574  "blackbox-path",
575  llvm::cl::desc(
576  "Optional path to use as the root of black box annotations"),
577  llvm::cl::value_desc("path"),
578  llvm::cl::init(""),
579  };
580 
581  llvm::cl::opt<bool> replSeqMem{
582  "repl-seq-mem",
583  llvm::cl::desc("Replace the seq mem for macro replacement and emit "
584  "relevant metadata"),
585  llvm::cl::init(false)};
586 
587  llvm::cl::opt<std::string> replSeqMemFile{
588  "repl-seq-mem-file", llvm::cl::desc("File name for seq mem metadata"),
589  llvm::cl::init("")};
590 
591  llvm::cl::opt<bool> extractTestCode{
592  "extract-test-code", llvm::cl::desc("Run the extract test code pass"),
593  llvm::cl::init(false)};
594 
595  llvm::cl::opt<bool> ignoreReadEnableMem{
596  "ignore-read-enable-mem",
597  llvm::cl::desc("Ignore the read enable signal, instead of "
598  "assigning X on read disable"),
599  llvm::cl::init(false)};
600 
602  llvm::cl::desc(
603  "Disable random initialization code (may break semantics!)"),
604  llvm::cl::values(
605  clEnumValN(firtool::FirtoolOptions::RandomKind::Mem,
606  "disable-mem-randomization",
607  "Disable emission of memory randomization code"),
608  clEnumValN(firtool::FirtoolOptions::RandomKind::Reg,
609  "disable-reg-randomization",
610  "Disable emission of register randomization code"),
612  "disable-all-randomization",
613  "Disable emission of all randomization code")),
614  llvm::cl::init(firtool::FirtoolOptions::RandomKind::None)};
615 
616  llvm::cl::opt<std::string> outputAnnotationFilename{
617  "output-annotation-file",
618  llvm::cl::desc("Optional output annotation file"),
619  llvm::cl::CommaSeparated, llvm::cl::value_desc("filename")};
620 
621  llvm::cl::opt<bool> enableAnnotationWarning{
622  "warn-on-unprocessed-annotations",
623  llvm::cl::desc(
624  "Warn about annotations that were not removed by lower-to-hw"),
625  llvm::cl::init(false)};
626 
627  llvm::cl::opt<bool> addMuxPragmas{
628  "add-mux-pragmas",
629  llvm::cl::desc("Annotate mux pragmas for memory array access"),
630  llvm::cl::init(false)};
631 
633  "verification-flavor",
634  llvm::cl::desc("Specify a verification flavor used in LowerFIRRTLToHW"),
635  llvm::cl::values(
636  clEnumValN(firrtl::VerificationFlavor::None, "none",
637  "Use the flavor specified by the op"),
638  clEnumValN(firrtl::VerificationFlavor::IfElseFatal, "if-else-fatal",
639  "Use Use `if(cond) else $fatal(..)` format"),
640  clEnumValN(firrtl::VerificationFlavor::Immediate, "immediate",
641  "Use immediate verif statements"),
642  clEnumValN(firrtl::VerificationFlavor::SVA, "sva", "Use SVA")),
643  llvm::cl::init(firrtl::VerificationFlavor::None)};
644 
645  llvm::cl::opt<bool> emitSeparateAlwaysBlocks{
646  "emit-separate-always-blocks",
647  llvm::cl::desc(
648  "Prevent always blocks from being merged and emit constructs into "
649  "separate always blocks whenever possible"),
650  llvm::cl::init(false)};
651 
652  llvm::cl::opt<bool> etcDisableInstanceExtraction{
653  "etc-disable-instance-extraction",
654  llvm::cl::desc("Disable extracting instances only that feed test code"),
655  llvm::cl::init(false)};
656 
657  llvm::cl::opt<bool> etcDisableRegisterExtraction{
658  "etc-disable-register-extraction",
659  llvm::cl::desc("Disable extracting registers that only feed test code"),
660  llvm::cl::init(false)};
661 
662  llvm::cl::opt<bool> etcDisableModuleInlining{
663  "etc-disable-module-inlining",
664  llvm::cl::desc("Disable inlining modules that only feed test code"),
665  llvm::cl::init(false)};
666 
667  llvm::cl::opt<bool> addVivadoRAMAddressConflictSynthesisBugWorkaround{
668  "add-vivado-ram-address-conflict-synthesis-bug-workaround",
669  llvm::cl::desc(
670  "Add a vivado specific SV attribute (* ram_style = "
671  "\"distributed\" *) to unpacked array registers as a workaronud "
672  "for a vivado synthesis bug that incorrectly modifies "
673  "address conflict behavivor of combinational memories"),
674  llvm::cl::init(false)};
675 
676  //===----------------------------------------------------------------------===
677  // External Clock Gate Options
678  //===----------------------------------------------------------------------===
679 
680  llvm::cl::opt<std::string> ckgModuleName{
681  "ckg-name", llvm::cl::desc("Clock gate module name"),
682  llvm::cl::init("EICG_wrapper")};
683 
684  llvm::cl::opt<std::string> ckgInputName{
685  "ckg-input", llvm::cl::desc("Clock gate input port name"),
686  llvm::cl::init("in")};
687 
688  llvm::cl::opt<std::string> ckgOutputName{
689  "ckg-output", llvm::cl::desc("Clock gate output port name"),
690  llvm::cl::init("out")};
691 
692  llvm::cl::opt<std::string> ckgEnableName{
693  "ckg-enable", llvm::cl::desc("Clock gate enable port name"),
694  llvm::cl::init("en")};
695 
696  llvm::cl::opt<std::string> ckgTestEnableName{
697  "ckg-test-enable",
698  llvm::cl::desc("Clock gate test enable port name (optional)"),
699  llvm::cl::init("test_en")};
700 
701  llvm::cl::opt<bool> exportModuleHierarchy{
702  "export-module-hierarchy",
703  llvm::cl::desc("Export module and instance hierarchy as JSON"),
704  llvm::cl::init(false)};
705 
706  llvm::cl::opt<bool> stripFirDebugInfo{
707  "strip-fir-debug-info",
708  llvm::cl::desc(
709  "Disable source fir locator information in output Verilog"),
710  llvm::cl::init(true)};
711 
712  llvm::cl::opt<bool> stripDebugInfo{
713  "strip-debug-info",
714  llvm::cl::desc("Disable source locator information in output Verilog"),
715  llvm::cl::init(false)};
716 
717  llvm::cl::opt<bool> fixupEICGWrapper{
718  "fixup-eicg-wrapper",
719  llvm::cl::desc("Lower `EICG_wrapper` modules into clock gate intrinsics"),
720  llvm::cl::init(false)};
721 
722  llvm::cl::opt<bool> addCompanionAssume{
723  "add-companion-assume",
724  llvm::cl::desc("Add companion assumes to assertions"),
725  llvm::cl::init(false)};
726 };
727 } // namespace
728 
729 static llvm::ManagedStatic<FirtoolCmdOptions> clOptions;
730 
731 /// Register a set of useful command-line options that can be used to configure
732 /// various flags within the MLIRContext. These flags are used when constructing
733 /// an MLIR context for initialization.
735  // Make sure that the options struct has been initialized.
736  *clOptions;
737 }
738 
739 // Initialize the firtool options with defaults supplied by the cl::opts above.
741  : outputFilename("-"), disableAnnotationsUnknown(false),
742  disableAnnotationsClassless(false), lowerAnnotationsNoRefTypePorts(false),
743  allowAddingPortsOnPublic(false), probesToSignals(false),
744  preserveAggregate(firrtl::PreserveAggregate::None),
745  preserveMode(firrtl::PreserveValues::None), enableDebugInfo(false),
746  buildMode(BuildModeRelease), disableOptimization(false),
747  exportChiselInterface(false), chiselInterfaceOutDirectory(""),
748  vbToBV(false), noDedup(false), companionMode(firrtl::CompanionMode::Bind),
749  disableAggressiveMergeConnections(false), emitOMIR(true), omirOutFile(""),
750  lowerMemories(false), blackBoxRootPath(""), replSeqMem(false),
751  replSeqMemFile(""), extractTestCode(false), ignoreReadEnableMem(false),
752  disableRandom(RandomKind::None), outputAnnotationFilename(""),
753  enableAnnotationWarning(false), addMuxPragmas(false),
754  verificationFlavor(firrtl::VerificationFlavor::None),
755  emitSeparateAlwaysBlocks(false), etcDisableInstanceExtraction(false),
756  etcDisableRegisterExtraction(false), etcDisableModuleInlining(false),
757  addVivadoRAMAddressConflictSynthesisBugWorkaround(false),
758  ckgModuleName("EICG_wrapper"), ckgInputName("in"), ckgOutputName("out"),
759  ckgEnableName("en"), ckgTestEnableName("test_en"), ckgInstName("ckg"),
760  exportModuleHierarchy(false), stripFirDebugInfo(true),
761  stripDebugInfo(false), fixupEICGWrapper(false),
762  addCompanionAssume(false) {
763  if (!clOptions.isConstructed())
764  return;
765  outputFilename = clOptions->outputFilename;
766  disableAnnotationsUnknown = clOptions->disableAnnotationsUnknown;
767  disableAnnotationsClassless = clOptions->disableAnnotationsClassless;
768  lowerAnnotationsNoRefTypePorts = clOptions->lowerAnnotationsNoRefTypePorts;
769  allowAddingPortsOnPublic = clOptions->allowAddingPortsOnPublic;
770  probesToSignals = clOptions->probesToSignals;
771  preserveAggregate = clOptions->preserveAggregate;
772  preserveMode = clOptions->preserveMode;
773  enableDebugInfo = clOptions->enableDebugInfo;
774  buildMode = clOptions->buildMode;
775  disableOptimization = clOptions->disableOptimization;
776  exportChiselInterface = clOptions->exportChiselInterface;
777  chiselInterfaceOutDirectory = clOptions->chiselInterfaceOutDirectory;
778  vbToBV = clOptions->vbToBV;
779  noDedup = clOptions->noDedup;
780  companionMode = clOptions->companionMode;
782  clOptions->disableAggressiveMergeConnections;
783  emitOMIR = clOptions->emitOMIR;
784  omirOutFile = clOptions->omirOutFile;
785  lowerMemories = clOptions->lowerMemories;
786  blackBoxRootPath = clOptions->blackBoxRootPath;
787  replSeqMem = clOptions->replSeqMem;
788  replSeqMemFile = clOptions->replSeqMemFile;
789  extractTestCode = clOptions->extractTestCode;
790  ignoreReadEnableMem = clOptions->ignoreReadEnableMem;
791  disableRandom = clOptions->disableRandom;
792  outputAnnotationFilename = clOptions->outputAnnotationFilename;
793  enableAnnotationWarning = clOptions->enableAnnotationWarning;
794  addMuxPragmas = clOptions->addMuxPragmas;
795  verificationFlavor = clOptions->verificationFlavor;
796  emitSeparateAlwaysBlocks = clOptions->emitSeparateAlwaysBlocks;
797  etcDisableInstanceExtraction = clOptions->etcDisableInstanceExtraction;
798  etcDisableRegisterExtraction = clOptions->etcDisableRegisterExtraction;
799  etcDisableModuleInlining = clOptions->etcDisableModuleInlining;
801  clOptions->addVivadoRAMAddressConflictSynthesisBugWorkaround;
802  ckgModuleName = clOptions->ckgModuleName;
803  ckgInputName = clOptions->ckgInputName;
804  ckgOutputName = clOptions->ckgOutputName;
805  ckgEnableName = clOptions->ckgEnableName;
806  ckgTestEnableName = clOptions->ckgTestEnableName;
807  exportModuleHierarchy = clOptions->exportModuleHierarchy;
808  stripFirDebugInfo = clOptions->stripFirDebugInfo;
809  stripDebugInfo = clOptions->stripDebugInfo;
810  fixupEICGWrapper = clOptions->fixupEICGWrapper;
811  addCompanionAssume = clOptions->addCompanionAssume;
812 }
static LogicalResult exportChiselInterface(CircuitOp circuit, llvm::raw_ostream &os)
Exports a Chisel interface to the output stream.
static llvm::ManagedStatic< FirtoolCmdOptions > clOptions
Definition: Firtool.cpp:729
Set of options used to control the behavior of the firtool pipeline.
Definition: Firtool.h:30
bool shouldStripDebugInfo() const
Definition: Firtool.h:117
firrtl::PreserveAggregate::PreserveMode getPreserveAggregate() const
Definition: Firtool.h:65
bool shouldAddVivadoRAMAddressConflictSynthesisBugWorkaround() const
Definition: Firtool.h:129
firrtl::PreserveValues::PreserveMode preserveMode
Definition: Firtool.h:373
bool shouldAddCompanionAssume() const
Definition: Firtool.h:134
auto getVerificationFlavor() const
Definition: Firtool.h:124
StringRef getOmirOutputFile() const
Definition: Firtool.h:55
bool isDefaultOutputFilename() const
Definition: Firtool.h:85
StringRef getOutputFilename() const
Definition: Firtool.h:54
bool shouldDisableAggressiveMergeConnections() const
Definition: Firtool.h:120
StringRef getReplaceSequentialMemoriesFile() const
Definition: Firtool.h:60
bool addVivadoRAMAddressConflictSynthesisBugWorkaround
Definition: Firtool.h:400
bool shouldExportChiselInterface() const
Definition: Firtool.h:106
bool shouldExtractTestCode() const
Definition: Firtool.h:132
std::string chiselInterfaceOutDirectory
Definition: Firtool.h:378
bool shouldFixupEICGWrapper() const
Definition: Firtool.h:133
bool shouldConvertProbesToSignals() const
Definition: Firtool.h:98
firrtl::PreserveValues::PreserveMode getPreserveMode() const
Definition: Firtool.h:42
StringRef getBlackBoxRootPath() const
Definition: Firtool.h:56
bool shouldDisableOptimization() const
Definition: Firtool.h:100
firrtl::CompanionMode getCompanionMode() const
Definition: Firtool.h:68
bool shouldDisableClasslessAnnotations() const
Definition: Firtool.h:89
bool shouldReplaceSequentialMemories() const
Definition: Firtool.h:99
bool shouldIgnoreReadEnableMemories() const
Definition: Firtool.h:104
bool isRandomEnabled(RandomKind kind) const
Definition: Firtool.h:38
bool shouldDisableUnknownAnnotations() const
Definition: Firtool.h:86
bool shouldAddMuxPragmas() const
Definition: Firtool.h:128
bool shouldEnableAnnotationWarning() const
Definition: Firtool.h:123
bool shouldEtcDisableInstanceExtraction() const
Definition: Firtool.h:108
bool shouldConvertVecOfBundle() const
Definition: Firtool.h:107
StringRef getOutputAnnotationFilename() const
Definition: Firtool.h:61
bool shouldStripFirDebugInfo() const
Definition: Firtool.h:118
bool shouldEtcDisableRegisterExtraction() const
Definition: Firtool.h:111
std::string outputAnnotationFilename
Definition: Firtool.h:392
firrtl::VerificationFlavor verificationFlavor
Definition: Firtool.h:395
firrtl::PreserveAggregate::PreserveMode preserveAggregate
Definition: Firtool.h:372
bool shouldLowerMemories() const
Definition: Firtool.h:101
bool shouldEtcDisableModuleInlining() const
Definition: Firtool.h:114
bool shouldAllowAddingPortsOnPublic() const
Definition: Firtool.h:95
bool shouldLowerNoRefTypePortAnnotations() const
Definition: Firtool.h:92
bool shouldExportModuleHierarchy() const
Definition: Firtool.h:119
firrtl::CompanionMode companionMode
Definition: Firtool.h:381
seq::ExternalizeClockGateOptions getClockGateOptions() const
Definition: Firtool.h:70
bool shouldEnableDebugInfo() const
Definition: Firtool.h:103
bool shouldEmitSeparateAlwaysBlocks() const
Definition: Firtool.h:125
StringRef getChiselInterfaceOutputDirectory() const
Definition: Firtool.h:57
std::unique_ptr< mlir::Pass > createDedupPass()
Definition: Dedup.cpp:744
@ All
Preserve all aggregate values.
Definition: Passes.h:42
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
Definition: Passes.h:36
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
Definition: Passes.h:39
@ None
Don't preserve aggregate at all.
Definition: Passes.h:33
@ Strip
Strip all names. No name on declaration is preserved.
Definition: Passes.h:50
std::unique_ptr< mlir::Pass > createInferReadWritePass()
std::unique_ptr< mlir::Pass > createCheckCombLoopsPass()
std::unique_ptr< mlir::Pass > createCheckLayers()
std::unique_ptr< mlir::Pass > createCheckRecursiveInstantiation()
std::unique_ptr< mlir::Pass > createFinalizeIRPass()
Definition: FinalizeIR.cpp:46
std::unique_ptr< mlir::Pass > createLowerFIRRTLTypesPass(PreserveAggregate::PreserveMode mode=PreserveAggregate::None, PreserveAggregate::PreserveMode memoryMode=PreserveAggregate::None)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createResolveTracesPass(mlir::StringRef outputAnnotationFilename="")
std::unique_ptr< mlir::Pass > createEmitOMIRPass(mlir::StringRef outputFilename="")
std::unique_ptr< mlir::Pass > createResolvePathsPass()
std::unique_ptr< mlir::Pass > createLowerFIRRTLAnnotationsPass(bool ignoreUnhandledAnnotations=false, bool ignoreClasslessAnnotations=false, bool noRefTypePorts=false, bool allowAddingPortsOnPublic=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createLowerSignaturesPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createVBToBVPass()
Definition: VBToBV.cpp:995
std::unique_ptr< mlir::Pass > createGrandCentralPass(CompanionMode companionMode=CompanionMode::Bind)
std::unique_ptr< mlir::Pass > createLowerDPIPass()
Definition: LowerDPI.cpp:296
std::unique_ptr< mlir::Pass > createLowerIntmodulesPass(bool fixupEICGWrapper=false)
This is the pass constructor.
std::unique_ptr< mlir::Pass > createIMConstPropPass()
std::unique_ptr< mlir::Pass > createBlackBoxReaderPass(std::optional< mlir::StringRef > inputPrefix={})
std::unique_ptr< mlir::Pass > createCreateCompanionAssume()
std::unique_ptr< mlir::Pass > createCreateSiFiveMetadataPass(bool replSeqMem=false, mlir::StringRef replSeqMemFile="")
std::unique_ptr< mlir::Pass > createLayerMergePass()
Definition: LayerMerge.cpp:72
std::unique_ptr< mlir::Pass > createInlinerPass()
std::unique_ptr< mlir::Pass > createVectorizationPass()
std::unique_ptr< mlir::Pass > createLowerMemoryPass()
std::unique_ptr< mlir::Pass > createDropNamesPass(PreserveValues::PreserveMode mode=PreserveValues::None)
Definition: DropName.cpp:100
std::unique_ptr< mlir::Pass > createLowerLayersPass()
std::unique_ptr< mlir::Pass > createIMDeadCodeElimPass()
std::unique_ptr< mlir::Pass > createLintingPass()
Definition: Lint.cpp:78
std::unique_ptr< mlir::Pass > createPassiveWiresPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createExtractInstancesPass()
std::unique_ptr< mlir::Pass > createLayerSinkPass()
Definition: LayerSink.cpp:61
std::unique_ptr< mlir::Pass > createSpecializeLayersPass()
std::unique_ptr< mlir::Pass > createLowerCHIRRTLPass()
std::unique_ptr< mlir::Pass > createInnerSymbolDCEPass()
std::unique_ptr< mlir::Pass > createExpandWhensPass()
std::unique_ptr< mlir::Pass > createLowerXMRPass()
Definition: LowerXMR.cpp:860
std::unique_ptr< mlir::Pass > createLowerIntrinsicsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createInferWidthsPass()
std::unique_ptr< mlir::Pass > createMemToRegOfVecPass(bool replSeqMem=false, bool ignoreReadEnable=false)
std::unique_ptr< mlir::Pass > createLowerOpenAggsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createAssignOutputDirsPass(mlir::StringRef outputDir="")
std::unique_ptr< mlir::Pass > createDropConstPass()
Definition: DropConst.cpp:111
std::unique_ptr< mlir::Pass > createSFCCompatPass()
Definition: SFCCompat.cpp:167
std::unique_ptr< mlir::Pass > createPrefixModulesPass()
std::unique_ptr< mlir::Pass > createInjectDUTHierarchyPass()
std::unique_ptr< mlir::Pass > createRandomizeRegisterInitPass()
std::unique_ptr< mlir::Pass > createLowerClassesPass()
std::unique_ptr< mlir::Pass > createAddSeqMemPortsPass()
std::unique_ptr< mlir::Pass > createRegisterOptimizerPass()
std::unique_ptr< mlir::Pass > createLowerMatchesPass()
std::unique_ptr< mlir::Pass > createProbesToSignalsPass()
This is the pass constructor.
std::unique_ptr< mlir::Pass > createMergeConnectionsPass(bool enableAggressiveMerging=false)
std::unique_ptr< mlir::Pass > createInferResetsPass()
std::unique_ptr< mlir::Pass > createFlattenMemoryPass()
std::unique_ptr< mlir::Pass > createMaterializeDebugInfoPass()
LogicalResult populateHWToBTOR2(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::raw_ostream &os)
Definition: Firtool.cpp:414
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition: Firtool.cpp:396
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:285
LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:244
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition: Firtool.cpp:377
LogicalResult populatePreprocessTransforms(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:27
void registerFirtoolCLOptions()
Register a set of useful command-line options that can be used to configure various flags within the ...
Definition: Firtool.cpp:734
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:406
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition: Firtool.cpp:55
std::unique_ptr< mlir::Pass > createFlattenModulesPass()
std::unique_ptr< mlir::Pass > createVerifyInnerRefNamespacePass()
std::unique_ptr< mlir::Pass > createVerifyObjectFieldsPass()
std::unique_ptr< mlir::Pass > createFreezePathsPass(std::function< StringAttr(Operation *)> getOpNameFallback={})
std::unique_ptr< mlir::Pass > createHWMemSimImplPass(const HWMemSimImplOptions &options={})
std::unique_ptr< mlir::Pass > createExternalizeClockGatePass(const ExternalizeClockGateOptions &options={})
std::unique_ptr< mlir::Pass > createHWExportModuleHierarchyPass()
std::unique_ptr< mlir::Pass > createSVExtractTestCodePass(bool disableInstanceExtraction=false, bool disableRegisterExtraction=false, bool disableModuleInlining=false)
std::unique_ptr< mlir::Pass > createHWLegalizeModulesPass()
std::unique_ptr< mlir::Pass > createPrettifyVerilogPass()
std::unique_ptr< mlir::Pass > createHWCleanupPass(bool mergeAlwaysBlocks=true)
Definition: HWCleanup.cpp:252
std::unique_ptr< mlir::Pass > createVerifyClockedAssertLikePass()
std::unique_ptr< mlir::Pass > createPrepareForFormalPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
std::unique_ptr< mlir::Pass > createExportSplitChiselInterfacePass(mlir::StringRef outputDirectory="./")
std::unique_ptr< mlir::Pass > createExportVerilogPass(std::unique_ptr< llvm::raw_ostream > os)
std::unique_ptr< mlir::Pass > createExportChiselInterfacePass(llvm::raw_ostream &os)
std::unique_ptr< mlir::Pass > createExportSplitVerilogPass(llvm::StringRef directory="./")
std::unique_ptr< mlir::Pass > createConvertHWToBTOR2Pass(llvm::raw_ostream &os)
Definition: HWToBTOR2.cpp:1024
std::unique_ptr< OperationPass< hw::HWModuleOp > > createLowerVerifToSVPass()
Create the Verif to SV conversion pass.
Definition: VerifToSV.cpp:243
std::unique_ptr< mlir::Pass > createLowerSeqToSVPass(const LowerSeqToSVOptions &options={})
Definition: SeqToSV.cpp:812
std::unique_ptr< mlir::Pass > createLowerLTLToCorePass()
Definition: LTLToCore.cpp:168
std::unique_ptr< mlir::Pass > createLowerFIRRTLToHWPass(bool enableAnnotationWarning=false, firrtl::VerificationFlavor assertionFlavor=firrtl::VerificationFlavor::None)
This is the pass constructor.
Definition: LowerToHW.cpp:586
std::unique_ptr< mlir::Pass > createLowerSimToSVPass()
Definition: SimToSV.cpp:370
std::unique_ptr< Pass > createSimpleCanonicalizerPass()
Create a simple canonicalizer pass.
Definition: Passes.cpp:15
std::unique_ptr< mlir::Pass > createStripDebugInfoWithPredPass(const std::function< bool(mlir::Location)> &pred)
Creates a pass to strip debug information from a function.
LogicalResult populatePrepareForExportVerilog(mlir::PassManager &pm, const firtool::FirtoolOptions &opt)
Definition: Firtool.cpp:338