Skip to content

Commit

Permalink
Merge pull request #395 from Xilinx/matthias.emitc_tu_2
Browse files Browse the repository at this point in the history
emitc.tu: Automatically create block for body
  • Loading branch information
mgehre-amd authored Nov 7, 2024
2 parents 26a9787 + ac5f771 commit 0684dc4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===------------------------------------------------------------------===//
Expand All @@ -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]> {
Expand Down
10 changes: 10 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 0684dc4

Please sign in to comment.