Skip to content

Commit

Permalink
[FIRRTL][OMIR] Add omir output file option to firtool. NFC. (llvm#2028)
Browse files Browse the repository at this point in the history
This commit adds the option `--output-omir` to specify the output file for OMIR output json.
  • Loading branch information
prithayan authored Oct 22, 2021
1 parent b77f14b commit 47bd2df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions test/firtool/firtool.fir
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
; RUN: firtool %s --format=fir -verilog | FileCheck %s --check-prefix=VERILOG
; RUN: firtool %s --annotation-file %s.anno.json,%s.anno.1.json --mlir --parse-only | FileCheck %s --check-prefix=ANNOTATIONS
; RUN: firtool %s --omir-file %s.omir.anno.json --parse-only | FileCheck %s --check-prefix=OMIR
; RUN: firtool %s --omir-file %s.omir.anno.json --output-omir meta.omir.json --verilog | FileCheck %s --check-prefix=OMIROUT

circuit test_mod : %[[{"a": "a"}]]

Expand All @@ -29,6 +30,18 @@ circuit test_mod : %[[{"a": "a"}]]
; OMIR-SAME: id = "OMID:0",
; OMIR-SAME: info = #loc1}]}


; OMIROUT-LABEL: FILE "meta.omir.json" -----
; OMIROUT: "info": "@[Foo.scala 32:32]",
; OMIROUT-NEXT: "id": "OMID:0",
; OMIROUT-NEXT: "fields": [
; OMIROUT-NEXT: {
; OMIROUT-NEXT: "info": "@[Foo.scala 64:64 Bar.scala 128:128]",
; OMIROUT-NEXT: "name": "stringVal",
; OMIROUT-NEXT: "value": "OMString:hello"
; OMIROUT-NEXT: }


module test_mod :
input clock : Clock
input a: UInt<1>
Expand Down
7 changes: 6 additions & 1 deletion tools/firtool/firtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ static cl::list<std::string>
cl::desc("Optional input object model 2.0 file"),
cl::CommaSeparated, cl::value_desc("filename"));

static cl::opt<std::string>
omirOutFile("output-omir", cl::desc("file name for the output omir"),
cl::init(""));

static cl::opt<std::string> blackBoxRootPath(
"blackbox-path",
cl::desc("Optional path to use as the root of black box annotations"),
Expand Down Expand Up @@ -396,7 +400,8 @@ processBuffer(MLIRContext &context, TimingScope &ts, llvm::SourceMgr &sourceMgr,
replSeqMem, replSeqMemCircuit, replSeqMemFile));

if (emitOMIR)
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createEmitOMIRPass());
pm.nest<firrtl::CircuitOp>().addPass(
firrtl::createEmitOMIRPass(omirOutFile));

// Lower if we are going to verilog or if lowering was specifically requested.
if (lowerToHW || outputFormat == OutputVerilog ||
Expand Down

0 comments on commit 47bd2df

Please sign in to comment.