Skip to content

Commit 0684dc4

Browse files
authored
Merge pull request #395 from Xilinx/matthias.emitc_tu_2
emitc.tu: Automatically create block for body
2 parents 26a9787 + ac5f771 commit 0684dc4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ def EmitC_TranslationUnitOp : EmitC_Op<"tu",
8585
let regions = (region SizedRegion<1>:$bodyRegion);
8686

8787
let assemblyFormat = "$id attr-dict-with-keyword $bodyRegion";
88+
let builders = [OpBuilder<(ins CArg<"StringRef">:$id)>];
8889
let extraClassDeclaration = [{
90+
/// Construct a module from the given location with an optional name.
91+
static TranslationUnitOp create(Location loc, StringRef name);
92+
8993
//===------------------------------------------------------------------===//
9094
// OpAsmOpInterface Methods
9195
//===------------------------------------------------------------------===//
@@ -96,6 +100,10 @@ def EmitC_TranslationUnitOp : EmitC_Op<"tu",
96100
return "emitc";
97101
}
98102
}];
103+
104+
// We need to ensure that the body region has a block;
105+
// the auto-generated builders do not guarantee that.
106+
let skipDefaultBuilders = 1;
99107
}
100108

101109
def EmitC_AddOp : EmitC_BinaryOp<"add", [CExpression]> {

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,16 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
12511251
return success();
12521252
}
12531253

1254+
//===----------------------------------------------------------------------===//
1255+
// TranslationUnitOp
1256+
//===----------------------------------------------------------------------===//
1257+
void TranslationUnitOp::build(OpBuilder &builder, OperationState &state,
1258+
StringRef id) {
1259+
state.addRegion()->emplaceBlock();
1260+
state.attributes.push_back(
1261+
builder.getNamedAttr("id", builder.getStringAttr(id)));
1262+
}
1263+
12541264
//===----------------------------------------------------------------------===//
12551265
// TableGen'd op method definitions
12561266
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)