diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td index 3f290f68b85dc8..ab71bb680e1509 100644 --- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td +++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td @@ -85,7 +85,11 @@ def EmitC_TranslationUnitOp : EmitC_Op<"tu", let regions = (region SizedRegion<1>:$bodyRegion); let assemblyFormat = "$id attr-dict-with-keyword $bodyRegion"; + let builders = [OpBuilder<(ins CArg<"StringRef">:$id)>]; let extraClassDeclaration = [{ + /// Construct a module from the given location with an optional name. + static TranslationUnitOp create(Location loc, StringRef name); + //===------------------------------------------------------------------===// // OpAsmOpInterface Methods //===------------------------------------------------------------------===// @@ -96,6 +100,10 @@ def EmitC_TranslationUnitOp : EmitC_Op<"tu", return "emitc"; } }]; + + // We need to ensure that the body region has a block; + // the auto-generated builders do not guarantee that. + let skipDefaultBuilders = 1; } def EmitC_AddOp : EmitC_BinaryOp<"add", [CExpression]> { diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index ee44f524c91428..c2fb835c2ebc34 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -1251,6 +1251,16 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) { return success(); } +//===----------------------------------------------------------------------===// +// TranslationUnitOp +//===----------------------------------------------------------------------===// +void TranslationUnitOp::build(OpBuilder &builder, OperationState &state, + StringRef id) { + state.addRegion()->emplaceBlock(); + state.attributes.push_back( + builder.getNamedAttr("id", builder.getStringAttr(id))); +} + //===----------------------------------------------------------------------===// // TableGen'd op method definitions //===----------------------------------------------------------------------===//