CIRCT  19.0.0git
Firtool.cpp
Go to the documentation of this file.
1 //===- Firtool.cpp - C Interface to Firtool-lib ---------------------------===//
2 //
3 // Implements a C Interface for Firtool-lib.
4 //
5 //===----------------------------------------------------------------------===//
6 
9 
10 #include "circt/Firtool/Firtool.h"
11 #include "mlir/CAPI/IR.h"
12 #include "mlir/CAPI/Pass.h"
13 #include "mlir/CAPI/Support.h"
14 #include "mlir/CAPI/Utils.h"
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 using namespace circt;
19 
20 DEFINE_C_API_PTR_METHODS(CirctFirtoolFirtoolOptions,
22 
23 //===----------------------------------------------------------------------===//
24 // Option API.
25 //===----------------------------------------------------------------------===//
26 
27 CirctFirtoolFirtoolOptions circtFirtoolOptionsCreateDefault() {
28  auto *options = new firtool::FirtoolOptions();
29  return wrap(options);
30 }
31 
32 void circtFirtoolOptionsDestroy(CirctFirtoolFirtoolOptions options) {
33  delete unwrap(options);
34 }
35 
36 void circtFirtoolOptionsSetOutputFilename(CirctFirtoolFirtoolOptions options,
37  MlirStringRef filename) {
38  unwrap(options)->setOutputFilename(unwrap(filename));
39 }
40 
42  CirctFirtoolFirtoolOptions options, bool disable) {
43  unwrap(options)->setDisableUnknownAnnotations(disable);
44 }
45 
47  CirctFirtoolFirtoolOptions options, bool value) {
48  unwrap(options)->setDisableAnnotationsClassless(value);
49 }
50 
52  CirctFirtoolFirtoolOptions options, bool value) {
53  unwrap(options)->setLowerAnnotationsNoRefTypePorts(value);
54 }
55 
57  CirctFirtoolFirtoolOptions options,
60 
61  switch (value) {
63  converted = firrtl::PreserveAggregate::PreserveMode::None;
64  break;
67  break;
70  break;
73  break;
74  }
75 
76  unwrap(options)->setPreserveAggregate(converted);
77 }
78 
80  CirctFirtoolFirtoolOptions options, CirctFirtoolPreserveValuesMode value) {
82 
83  switch (value) {
86  break;
88  converted = firrtl::PreserveValues::PreserveMode::None;
89  break;
92  break;
95  break;
96  }
97 
98  unwrap(options)->setPreserveValues(converted);
99 }
100 
101 void circtFirtoolOptionsSetEnableDebugInfo(CirctFirtoolFirtoolOptions options,
102  bool value) {
103  unwrap(options)->setEnableDebugInfo(value);
104 }
105 
106 void circtFirtoolOptionsSetBuildMode(CirctFirtoolFirtoolOptions options,
107  CirctFirtoolBuildMode value) {
109 
110  switch (value) {
112  converted = firtool::FirtoolOptions::BuildMode::BuildModeDefault;
113  break;
115  converted = firtool::FirtoolOptions::BuildMode::BuildModeDebug;
116  break;
118  converted = firtool::FirtoolOptions::BuildMode::BuildModeRelease;
119  break;
120  }
121 
122  unwrap(options)->setBuildMode(converted);
123 }
124 
126  CirctFirtoolFirtoolOptions options, bool value) {
127  unwrap(options)->setDisableOptimization(value);
128 }
129 
131  CirctFirtoolFirtoolOptions options, bool value) {
132  unwrap(options)->setExportChiselInterface(value);
133 }
134 
136  CirctFirtoolFirtoolOptions options, MlirStringRef value) {
137  unwrap(options)->setChiselInterfaceOutDirectory(unwrap(value));
138 }
139 
140 void circtFirtoolOptionsSetVbToBv(CirctFirtoolFirtoolOptions options,
141  bool value) {
142  unwrap(options)->setVbToBV(value);
143 }
144 
145 void circtFirtoolOptionsSetNoDedup(CirctFirtoolFirtoolOptions options,
146  bool value) {
147  unwrap(options)->setNoDedup(value);
148 }
149 
150 void circtFirtoolOptionsSetCompanionMode(CirctFirtoolFirtoolOptions options,
152  firrtl::CompanionMode converted;
153 
154  switch (value) {
156  converted = firrtl::CompanionMode::Bind;
157  break;
160  break;
162  converted = firrtl::CompanionMode::Drop;
163  break;
164  }
165 
166  unwrap(options)->setCompanionMode(converted);
167 }
168 
170  CirctFirtoolFirtoolOptions options, bool value) {
171  unwrap(options)->setDisableAggressiveMergeConnections(value);
172 }
173 
175  CirctFirtoolFirtoolOptions options, bool value) {
176  unwrap(options)->setDisableHoistingHWPassthrough(value);
177 }
178 
179 void circtFirtoolOptionsSetEmitOmir(CirctFirtoolFirtoolOptions options,
180  bool value) {
181  unwrap(options)->setEmitOMIR(value);
182 }
183 
184 void circtFirtoolOptionsSetOmirOutFile(CirctFirtoolFirtoolOptions options,
185  MlirStringRef value) {
186  unwrap(options)->setOmirOutFile(unwrap(value));
187 }
188 
189 void circtFirtoolOptionsSetLowerMemories(CirctFirtoolFirtoolOptions options,
190  bool value) {
191  unwrap(options)->setLowerMemories(value);
192 }
193 
194 void circtFirtoolOptionsSetBlackBoxRootPath(CirctFirtoolFirtoolOptions options,
195  MlirStringRef value) {
196  unwrap(options)->setBlackBoxRootPath(unwrap(value));
197 }
198 
199 void circtFirtoolOptionsSetReplSeqMem(CirctFirtoolFirtoolOptions options,
200  bool value) {
201  unwrap(options)->setReplSeqMem(value);
202 }
203 
204 void circtFirtoolOptionsSetReplSeqMemFile(CirctFirtoolFirtoolOptions options,
205  MlirStringRef value) {
206  unwrap(options)->setReplSeqMemFile(unwrap(value));
207 }
208 
209 void circtFirtoolOptionsSetExtractTestCode(CirctFirtoolFirtoolOptions options,
210  bool value) {
211  unwrap(options)->setExtractTestCode(value);
212 }
213 
215  CirctFirtoolFirtoolOptions options, bool value) {
216  unwrap(options)->setIgnoreReadEnableMem(value);
217 }
218 
219 void circtFirtoolOptionsSetDisableRandom(CirctFirtoolFirtoolOptions options,
220  CirctFirtoolRandomKind value) {
222 
223  switch (value) {
226  break;
229  break;
232  break;
235  break;
236  }
237 
238  unwrap(options)->setDisableRandom(converted);
239 }
240 
242  CirctFirtoolFirtoolOptions options, MlirStringRef value) {
243  unwrap(options)->setOutputAnnotationFilename(unwrap(value));
244 }
245 
247  CirctFirtoolFirtoolOptions options, bool value) {
248  unwrap(options)->setEnableAnnotationWarning(value);
249 }
250 
251 void circtFirtoolOptionsSetAddMuxPragmas(CirctFirtoolFirtoolOptions options,
252  bool value) {
253  unwrap(options)->setAddMuxPragmas(value);
254 }
255 
257  CirctFirtoolFirtoolOptions options, bool value) {
258  unwrap(options)->setEmitChiselAssertsAsSVA(value);
259 }
260 
262  CirctFirtoolFirtoolOptions options, bool value) {
263  unwrap(options)->setEmitSeparateAlwaysBlocks(value);
264 }
265 
267  CirctFirtoolFirtoolOptions options, bool value) {
268  unwrap(options)->setEtcDisableInstanceExtraction(value);
269 }
270 
272  CirctFirtoolFirtoolOptions options, bool value) {
273  unwrap(options)->setEtcDisableRegisterExtraction(value);
274 }
275 
277  CirctFirtoolFirtoolOptions options, bool value) {
278  unwrap(options)->setEtcDisableModuleInlining(value);
279 }
280 
282  CirctFirtoolFirtoolOptions options, bool value) {
283  unwrap(options)->setAddVivadoRAMAddressConflictSynthesisBugWorkaround(value);
284 }
285 
286 void circtFirtoolOptionsSetCkgModuleName(CirctFirtoolFirtoolOptions options,
287  MlirStringRef value) {
288  unwrap(options)->setCkgModuleName(unwrap(value));
289 }
290 
291 void circtFirtoolOptionsSetCkgInputName(CirctFirtoolFirtoolOptions options,
292  MlirStringRef value) {
293  unwrap(options)->setCkgInputName(unwrap(value));
294 }
295 
296 void circtFirtoolOptionsSetCkgOutputName(CirctFirtoolFirtoolOptions options,
297  MlirStringRef value) {
298  unwrap(options)->setCkgOutputName(unwrap(value));
299 }
300 
301 void circtFirtoolOptionsSetCkgEnableName(CirctFirtoolFirtoolOptions options,
302  MlirStringRef value) {
303  unwrap(options)->setCkgEnableName(unwrap(value));
304 }
305 
306 void circtFirtoolOptionsSetCkgTestEnableName(CirctFirtoolFirtoolOptions options,
307  MlirStringRef value) {
308  unwrap(options)->setCkgTestEnableName(unwrap(value));
309 }
310 
312  CirctFirtoolFirtoolOptions options, bool value) {
313  unwrap(options)->setExportModuleHierarchy(value);
314 }
315 
316 void circtFirtoolOptionsSetStripFirDebugInfo(CirctFirtoolFirtoolOptions options,
317  bool value) {
318  unwrap(options)->setStripFirDebugInfo(value);
319 }
320 
321 void circtFirtoolOptionsSetStripDebugInfo(CirctFirtoolFirtoolOptions options,
322  bool value) {
323  unwrap(options)->setStripDebugInfo(value);
324 }
325 
326 //===----------------------------------------------------------------------===//
327 // Populate API.
328 //===----------------------------------------------------------------------===//
329 
330 MlirLogicalResult
332  CirctFirtoolFirtoolOptions options) {
333  return wrap(
335 }
336 
337 MlirLogicalResult
339  CirctFirtoolFirtoolOptions options,
340  MlirStringRef inputFilename) {
341  return wrap(firtool::populateCHIRRTLToLowFIRRTL(*unwrap(pm), *unwrap(options),
342  unwrap(inputFilename)));
343 }
344 
345 MlirLogicalResult
347  CirctFirtoolFirtoolOptions options) {
348  return wrap(firtool::populateLowFIRRTLToHW(*unwrap(pm), *unwrap(options)));
349 }
350 
351 MlirLogicalResult
352 circtFirtoolPopulateHWToSV(MlirPassManager pm,
353  CirctFirtoolFirtoolOptions options) {
354  return wrap(firtool::populateHWToSV(*unwrap(pm), *unwrap(options)));
355 }
356 
357 MlirLogicalResult
359  CirctFirtoolFirtoolOptions options,
360  MlirStringCallback callback, void *userData) {
361  auto stream =
362  std::make_unique<mlir::detail::CallbackOstream>(callback, userData);
363  return wrap(firtool::populateExportVerilog(*unwrap(pm), *unwrap(options),
364  std::move(stream)));
365 }
366 
367 MlirLogicalResult
369  CirctFirtoolFirtoolOptions options,
370  MlirStringRef directory) {
371  return wrap(firtool::populateExportSplitVerilog(*unwrap(pm), *unwrap(options),
372  unwrap(directory)));
373 }
374 
375 MlirLogicalResult
377  CirctFirtoolFirtoolOptions options) {
378  return wrap(firtool::populateFinalizeIR(*unwrap(pm), *unwrap(options)));
379 }
void circtFirtoolOptionsSetDisableAggressiveMergeConnections(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:169
void circtFirtoolOptionsSetStripDebugInfo(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:321
void circtFirtoolOptionsSetEmitSeparateAlwaysBlocks(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:261
void circtFirtoolOptionsSetEmitOmir(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:179
void circtFirtoolOptionsSetDisableUnknownAnnotations(CirctFirtoolFirtoolOptions options, bool disable)
Definition: Firtool.cpp:41
void circtFirtoolOptionsSetExportModuleHierarchy(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:311
void circtFirtoolOptionsSetEmitChiselAssertsAsSVA(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:256
void circtFirtoolOptionsSetCkgOutputName(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:296
void circtFirtoolOptionsSetCkgTestEnableName(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:306
void circtFirtoolOptionsSetCkgEnableName(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:301
void circtFirtoolOptionsSetPreserveAggregate(CirctFirtoolFirtoolOptions options, CirctFirtoolPreserveAggregateMode value)
Definition: Firtool.cpp:56
void circtFirtoolOptionsSetDisableOptimization(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:125
void circtFirtoolOptionsSetLowerAnnotationsNoRefTypePorts(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:51
void circtFirtoolOptionsSetIgnoreReadEnableMem(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:214
void circtFirtoolOptionsSetOutputFilename(CirctFirtoolFirtoolOptions options, MlirStringRef filename)
Definition: Firtool.cpp:36
void circtFirtoolOptionsSetReplSeqMemFile(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:204
MlirLogicalResult circtFirtoolPopulateCHIRRTLToLowFIRRTL(MlirPassManager pm, CirctFirtoolFirtoolOptions options, MlirStringRef inputFilename)
Definition: Firtool.cpp:338
void circtFirtoolOptionsSetDisableAnnotationsClassless(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:46
void circtFirtoolOptionsDestroy(CirctFirtoolFirtoolOptions options)
Definition: Firtool.cpp:32
void circtFirtoolOptionsSetVbToBv(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:140
void circtFirtoolOptionsSetOutputAnnotationFilename(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:241
void circtFirtoolOptionsSetNoDedup(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:145
void circtFirtoolOptionsSetBlackBoxRootPath(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:194
void circtFirtoolOptionsSetOmirOutFile(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:184
void circtFirtoolOptionsSetCkgModuleName(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:286
void circtFirtoolOptionsSetDisableRandom(CirctFirtoolFirtoolOptions options, CirctFirtoolRandomKind value)
Definition: Firtool.cpp:219
MlirLogicalResult circtFirtoolPopulateFinalizeIR(MlirPassManager pm, CirctFirtoolFirtoolOptions options)
Definition: Firtool.cpp:376
void circtFirtoolOptionsSetEtcDisableInstanceExtraction(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:266
void circtFirtoolOptionsSetEnableAnnotationWarning(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:246
void circtFirtoolOptionsSetReplSeqMem(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:199
void circtFirtoolOptionsSetEnableDebugInfo(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:101
void circtFirtoolOptionsSetExportChiselInterface(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:130
void circtFirtoolOptionsSetCkgInputName(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:291
void circtFirtoolOptionsSetBuildMode(CirctFirtoolFirtoolOptions options, CirctFirtoolBuildMode value)
Definition: Firtool.cpp:106
MlirLogicalResult circtFirtoolPopulateHWToSV(MlirPassManager pm, CirctFirtoolFirtoolOptions options)
Definition: Firtool.cpp:352
void circtFirtoolOptionsSetDisableHoistingHWPassthrough(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:174
void circtFirtoolOptionsSetLowerMemories(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:189
void circtFirtoolOptionsSetEtcDisableModuleInlining(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:276
void circtFirtoolOptionsSetAddVivadoRAMAddressConflictSynthesisBugWorkaround(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:281
MlirLogicalResult circtFirtoolPopulateExportVerilog(MlirPassManager pm, CirctFirtoolFirtoolOptions options, MlirStringCallback callback, void *userData)
Definition: Firtool.cpp:358
MlirLogicalResult circtFirtoolPopulateLowFIRRTLToHW(MlirPassManager pm, CirctFirtoolFirtoolOptions options)
Definition: Firtool.cpp:346
void circtFirtoolOptionsSetExtractTestCode(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:209
void circtFirtoolOptionsSetChiselInterfaceOutDirectory(CirctFirtoolFirtoolOptions options, MlirStringRef value)
Definition: Firtool.cpp:135
void circtFirtoolOptionsSetStripFirDebugInfo(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:316
DEFINE_C_API_PTR_METHODS(CirctFirtoolFirtoolOptions, circt::firtool::FirtoolOptions) CirctFirtoolFirtoolOptions circtFirtoolOptionsCreateDefault()
Definition: Firtool.cpp:20
void circtFirtoolOptionsSetAddMuxPragmas(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:251
void circtFirtoolOptionsSetCompanionMode(CirctFirtoolFirtoolOptions options, CirctFirtoolCompanionMode value)
Definition: Firtool.cpp:150
void circtFirtoolOptionsSetEtcDisableRegisterExtraction(CirctFirtoolFirtoolOptions options, bool value)
Definition: Firtool.cpp:271
MlirLogicalResult circtFirtoolPopulatePreprocessTransforms(MlirPassManager pm, CirctFirtoolFirtoolOptions options)
Definition: Firtool.cpp:331
MlirLogicalResult circtFirtoolPopulateExportSplitVerilog(MlirPassManager pm, CirctFirtoolFirtoolOptions options, MlirStringRef directory)
Definition: Firtool.cpp:368
void circtFirtoolOptionsSetPreserveValues(CirctFirtoolFirtoolOptions options, CirctFirtoolPreserveValuesMode value)
Definition: Firtool.cpp:79
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
Definition: OM.cpp:96
CirctFirtoolCompanionMode
Definition: Firtool.h:42
@ CIRCT_FIRTOOL_COMPANION_MODE_BIND
Definition: Firtool.h:43
@ CIRCT_FIRTOOL_COMPANION_MODE_DROP
Definition: Firtool.h:45
@ CIRCT_FIRTOOL_COMPANION_MODE_INSTANTIATE
Definition: Firtool.h:44
CirctFirtoolRandomKind
Definition: Firtool.h:56
@ CIRCT_FIRTOOL_RANDOM_KIND_MEM
Definition: Firtool.h:58
@ CIRCT_FIRTOOL_RANDOM_KIND_NONE
Definition: Firtool.h:57
@ CIRCT_FIRTOOL_RANDOM_KIND_REG
Definition: Firtool.h:59
@ CIRCT_FIRTOOL_RANDOM_KIND_ALL
Definition: Firtool.h:60
MLIR_CAPI_EXPORTED CirctFirtoolFirtoolOptions circtFirtoolOptionsCreateDefault(void)
CirctFirtoolPreserveAggregateMode
Definition: Firtool.h:26
@ CIRCT_FIRTOOL_PRESERVE_AGGREGATE_MODE_NONE
Definition: Firtool.h:27
@ CIRCT_FIRTOOL_PRESERVE_AGGREGATE_MODE_ALL
Definition: Firtool.h:30
@ CIRCT_FIRTOOL_PRESERVE_AGGREGATE_MODE_VEC
Definition: Firtool.h:29
@ CIRCT_FIRTOOL_PRESERVE_AGGREGATE_MODE_ONE_DIM_VEC
Definition: Firtool.h:28
CirctFirtoolBuildMode
Definition: Firtool.h:49
@ CIRCT_FIRTOOL_BUILD_MODE_RELEASE
Definition: Firtool.h:52
@ CIRCT_FIRTOOL_BUILD_MODE_DEBUG
Definition: Firtool.h:51
@ CIRCT_FIRTOOL_BUILD_MODE_DEFAULT
Definition: Firtool.h:50
CirctFirtoolPreserveValuesMode
Definition: Firtool.h:34
@ CIRCT_FIRTOOL_PRESERVE_VALUES_MODE_STRIP
Definition: Firtool.h:35
@ CIRCT_FIRTOOL_PRESERVE_VALUES_MODE_ALL
Definition: Firtool.h:38
@ CIRCT_FIRTOOL_PRESERVE_VALUES_MODE_NAMED
Definition: Firtool.h:37
@ CIRCT_FIRTOOL_PRESERVE_VALUES_MODE_NONE
Definition: Firtool.h:36
Set of options used to control the behavior of the firtool pipeline.
Definition: Firtool.h:29
@ All
Preserve all aggregate values.
Definition: Passes.h:51
@ OneDimVec
Preserve only 1d vectors of ground type (e.g. UInt<2>[3]).
Definition: Passes.h:45
@ Vec
Preserve only vectors (e.g. UInt<2>[3][3]).
Definition: Passes.h:48
@ Strip
Strip all names. No name on declaration is preserved.
Definition: Passes.h:155
LogicalResult populateExportSplitVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, llvm::StringRef directory)
Definition: Firtool.cpp:364
LogicalResult populateHWToSV(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:263
LogicalResult populateLowFIRRTLToHW(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:230
LogicalResult populateExportVerilog(mlir::PassManager &pm, const FirtoolOptions &opt, std::unique_ptr< llvm::raw_ostream > os)
Definition: Firtool.cpp:345
LogicalResult populatePreprocessTransforms(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:26
LogicalResult populateFinalizeIR(mlir::PassManager &pm, const FirtoolOptions &opt)
Definition: Firtool.cpp:374
LogicalResult populateCHIRRTLToLowFIRRTL(mlir::PassManager &pm, const FirtoolOptions &opt, StringRef inputFilename)
Definition: Firtool.cpp:45
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21