Skip to content

Commit 0da3cb6

Browse files
committed
build driver
1 parent 69ee9b0 commit 0da3cb6

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

mlir/lib/Target/IRDLToCpp/IRDLToCpp.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,6 @@ static LogicalResult generateLib(irdl::DialectOp dialect, raw_ostream &output,
279279
output << "#ifdef " << definitionMacroFlag << "\n#undef "
280280
<< definitionMacroFlag << "\n";
281281

282-
output << llvm::formatv(dialectDefTemplateText, dialectStrings.namespaceOpen,
283-
dialectStrings.namespaceClose,
284-
dialectStrings.dialectCppName,
285-
dialectStrings.namespacePath);
286-
287282
// type header
288283
output << llvm::formatv(
289284
typeHeaderDefTemplateText, dialectStrings.dialectBaseTypeName,
@@ -432,6 +427,14 @@ static void {0}::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &od
432427
output << llvm::formatv(opDefTemplateText, commaSeparatedOpList,
433428
perOpDefinitions);
434429

430+
output << llvm::formatv(dialectDefTemplateText, dialectStrings.namespaceOpen,
431+
dialectStrings.namespaceClose,
432+
dialectStrings.dialectCppName,
433+
dialectStrings.namespacePath,
434+
commaSeparatedOpList,
435+
commaSeparatedTypeList
436+
);
437+
435438
output << "#endif // " << definitionMacroFlag << "\n";
436439
return success();
437440
}

mlir/lib/Target/IRDLToCpp/Templates/DialectDef.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/*
2+
{0}: namespace open
3+
{1}: namespace close
4+
5+
{2}: Dialect Cpp Name
6+
{3}: Namespace path
7+
8+
{4}: Op list
9+
{5}: Type list
10+
*/
11+
112
R"(
213
MLIR_DEFINE_EXPLICIT_TYPE_ID({3}::{2})
314
{0}
@@ -8,5 +19,15 @@ MLIR_DEFINE_EXPLICIT_TYPE_ID({3}::{2})
819
}
920

1021
{2}::~{2}() = default;
22+
23+
24+
void {2}::initialize() {{
25+
addOperations<
26+
{4}
27+
>();
28+
addTypes<
29+
{5}
30+
>();
31+
}
1132
{1}
1233
)"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
{0}: Dialect CppName
3+
4+
{1}: Namespace path
5+
6+
{2}: Includes
7+
*/
8+
9+
R"(
10+
11+
12+
13+
14+
15+
)"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
#include "test_irdl_to_cpp.irdl.mlir.cpp.inc"
3+
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
irdl.dialect @test_irdl_to_cpp {}
1+
irdl.dialect @test_irdl_to_cpp {
2+
irdl.type @foo
3+
4+
irdl.operation @bar {
5+
%0 = irdl.any
6+
irdl.results(res: %0)
7+
}
8+
}

0 commit comments

Comments
 (0)