-
Notifications
You must be signed in to change notification settings - Fork 4
IRDL-to-C++ #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IRDL-to-C++ #15
Changes from 1 commit
a2ce564
05494f3
523d6c3
c47260e
d0acddb
1a4d588
e9304cb
d659648
34e63be
0635ef8
720014f
b79a624
8268794
2b64b15
5d76555
3a84a4e
73b8330
689342d
695d725
8d30c73
835bba9
c0e7a59
6979ab2
9c62446
6464238
02ed6d8
3280596
044929d
782c066
05674b2
cc78177
3d02834
61d5fdf
f1cf168
be50ada
f4e14bf
62cae9c
6bb05ea
34deb76
a4380fe
2e12bad
4f844e7
8f1d1dd
86d1d4e
a58e2d1
bb7e559
5c3a997
69d6c1f
0967a6f
127cc84
896ea58
6e574a4
bae8e1f
b6c9c76
435a542
8c1f018
0240129
319feac
6db8490
6179131
989aadf
d4f0f43
5530474
0f1277d
0fa3ba7
760bf4f
123bf5f
16fdb4f
6e98c8c
23a341e
683dcb8
eb37abe
189d5da
fd1c4c3
6bd3543
50304b0
34813d9
23d4756
a21fb74
53d7b1d
5ff1752
7239841
3c9812e
bbca78f
1bdec97
204eb70
52c2e45
3f15b66
7dc7c15
51a03ed
7549f42
cd7104e
9502d1b
a2f72ed
8e31e71
fe09550
3e3b02f
9d10305
7c093ed
710ef17
21cbc8a
d045eb1
01cb390
0cf3c43
6087854
396278e
76141f8
b878e0d
6e91fb1
961613b
dc8f2f0
f5bfa9b
26c5de5
7dc72a0
b2bb0f9
7b4d2a0
a2d717d
75d62ee
fe30cde
5efd1ae
524ef16
99f1f0e
afd3133
9f5a670
6520b21
7b2fc48
c6be456
441b967
1590ef3
e100f54
795e889
35c15e4
672e926
df03f7e
cd60ee9
eb341f0
1d411f2
77a3f81
faa4505
1695e8b
ea3c225
a8be7a7
26fe803
b208016
e9dbf31
d5802c3
bb03cdc
0c7853d
7e09a00
dddcbc2
ccffa1d
89909d8
f0ff2be
4b97c6e
c8f29e3
84f06b8
871b0a3
15c9f27
75dbda4
48056a7
b5663d0
e03b1b8
92cebab
ef2531b
8323335
08a50bd
407df06
c180d0c
d71dcfa
0918361
3bc174b
2faa45c
6d1d937
a8433b8
a6ca703
0804ca8
af2a957
a9b2998
7cfdd74
294643e
4b4699a
8d374f1
8f9549c
3f3b19d
69f2ff3
aa452b6
1e48418
2849b12
e089d48
1f3b6d8
24c782e
4788d5f
47b9837
13c3df9
64e8935
252bd80
0ef8ef6
3ac2b5c
f3d9dff
346a72f
e373f7a
fb99a85
4675f22
6bbaef1
adaf170
dcef154
7d71a35
7ff0cf6
2f3bc37
abf1bfb
f093d7e
1cc9e6e
fb14c83
1ecc291
4eb91b9
448d0ec
c192d53
1e8e662
d4d8a0f
b77e36d
13d7c60
3793cc1
7407165
2b43657
964aedb
9662a60
b754e40
7687261
b65760b
9d3ea92
0e80be8
068868d
a438b23
e933948
fe32806
d89084c
3910a2c
63adf07
953302e
f64f4f5
e3e949c
1593bf4
bc0c4db
9a440f8
c0506a1
49c39ef
f755e66
028f2dd
47914c6
2a4a43e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ static std::string snakeToCamel(llvm::StringRef in, bool capitalize = false) { | |
| } | ||
|
|
||
| static std::string snakeToPascal(llvm::StringRef in) { | ||
| return snakeToCamel(in, /*capitalize=*/true); | ||
| return snakeToCamel(in, /*capitalize=*/true); | ||
| } | ||
|
|
||
| static std::string typeToCppName(irdl::TypeOp type) { | ||
|
|
@@ -490,61 +490,81 @@ static LogicalResult verifySupported(irdl::DialectOp dialect) { | |
| return success(); | ||
| } | ||
|
|
||
| LogicalResult irdl::translateIRDLDialectToCpp(irdl::DialectOp dialect, | ||
| raw_ostream &output) { | ||
| LogicalResult | ||
| irdl::translateIRDLDialectToCpp(llvm::ArrayRef<irdl::DialectOp> dialects, | ||
| raw_ostream &output) { | ||
| static const auto typeDefTempl = detail::Template( | ||
| #include "Templates/TypeDef.txt" | ||
| ); | ||
|
|
||
| StringRef dialectName = dialect.getSymName(); | ||
| llvm::LogicalResult result = success(); | ||
|
|
||
| // TODO: deal with no more constraints than the verifier allows. | ||
| if (dialectName.size() < 1) | ||
| return dialect->emitError("dialect name must be more than one character"); | ||
| if (!llvm::isAlpha(dialectName[0])) | ||
| return dialect->emitError("dialect name must start with a letter"); | ||
| if (!llvm::all_of(dialectName, | ||
| [](char c) { return llvm::isAlnum(c) || c == '_'; })) | ||
| return dialect->emitError( | ||
| "dialect name must only contain letters, numbers or underscores"); | ||
| for (auto dialect : dialects) { | ||
| StringRef dialectName = dialect.getSymName(); | ||
|
|
||
| if (failed(verifySupported(dialect))) | ||
| return failure(); | ||
|
|
||
| llvm::SmallVector<llvm::SmallString<8>> namespaceAbsolutePath{{"mlir"}, | ||
| dialectName}; | ||
| std::string namespaceOpen; | ||
| std::string namespaceClose; | ||
| std::string namespacePath; | ||
| llvm::raw_string_ostream namespaceOpenStream(namespaceOpen); | ||
| llvm::raw_string_ostream namespaceCloseStream(namespaceClose); | ||
| llvm::raw_string_ostream namespacePathStream(namespacePath); | ||
| for (auto &pathElement : namespaceAbsolutePath) { | ||
| namespaceOpenStream << "namespace " << pathElement << " {\n"; | ||
| namespaceCloseStream << "} // namespace " << pathElement << "\n"; | ||
| namespacePathStream << "::" << pathElement; | ||
| } | ||
|
|
||
| std::string cppShortName = snakeToPascal(dialectName); | ||
| std::string dialectBaseTypeName = llvm::formatv("{0}Type", cppShortName); | ||
| std::string cppName = llvm::formatv("{0}Dialect", cppShortName); | ||
|
|
||
| DialectStrings dialectStrings; | ||
| dialectStrings.dialectName = dialectName; | ||
| dialectStrings.dialectBaseTypeName = dialectBaseTypeName; | ||
| dialectStrings.dialectCppName = cppName; | ||
| dialectStrings.dialectCppShortName = cppShortName; | ||
| dialectStrings.namespaceOpen = namespaceOpen; | ||
| dialectStrings.namespaceClose = namespaceClose; | ||
| dialectStrings.namespacePath = namespacePath; | ||
| // TODO: deal with no more constraints than the verifier allows. | ||
|
||
| if (dialectName.size() < 1) { | ||
| result = | ||
| dialect->emitError("dialect name must be more than one character"); | ||
| continue; | ||
| } | ||
| if (!llvm::isAlpha(dialectName[0])) { | ||
| result = dialect->emitError("dialect name must start with a letter"); | ||
| continue; | ||
| } | ||
| if (!llvm::all_of(dialectName, | ||
| [](char c) { return llvm::isAlnum(c) || c == '_'; })) { | ||
| result = dialect->emitError( | ||
| "dialect name must only contain letters, numbers or underscores"); | ||
| continue; | ||
| } | ||
|
|
||
| output << headerTemplateText; | ||
| if (failed(verifySupported(dialect))) | ||
| result = failure(); | ||
|
|
||
| llvm::SmallVector<llvm::SmallString<8>> namespaceAbsolutePath{{"mlir"}, | ||
| dialectName}; | ||
| std::string namespaceOpen; | ||
| std::string namespaceClose; | ||
| std::string namespacePath; | ||
| llvm::raw_string_ostream namespaceOpenStream(namespaceOpen); | ||
| llvm::raw_string_ostream namespaceCloseStream(namespaceClose); | ||
| llvm::raw_string_ostream namespacePathStream(namespacePath); | ||
| for (auto &pathElement : namespaceAbsolutePath) { | ||
| namespaceOpenStream << "namespace " << pathElement << " {\n"; | ||
| namespaceCloseStream << "} // namespace " << pathElement << "\n"; | ||
| namespacePathStream << "::" << pathElement; | ||
| } | ||
|
|
||
| if (failed(generateInclude(dialect, output, dialectStrings))) | ||
| return failure(); | ||
| std::string cppShortName = snakeToPascal(dialectName); | ||
| std::string dialectBaseTypeName = llvm::formatv("{0}Type", cppShortName); | ||
| std::string cppName = llvm::formatv("{0}Dialect", cppShortName); | ||
|
|
||
| DialectStrings dialectStrings; | ||
| dialectStrings.dialectName = dialectName; | ||
| dialectStrings.dialectBaseTypeName = dialectBaseTypeName; | ||
| dialectStrings.dialectCppName = cppName; | ||
| dialectStrings.dialectCppShortName = cppShortName; | ||
| dialectStrings.namespaceOpen = namespaceOpen; | ||
| dialectStrings.namespaceClose = namespaceClose; | ||
| dialectStrings.namespacePath = namespacePath; | ||
|
|
||
| output << headerTemplateText; | ||
|
|
||
| if (failed(generateInclude(dialect, output, dialectStrings))) { | ||
| dialect->emitError("Error in Dialect " + dialectName + | ||
| " while generating headers"); | ||
| result = failure(); | ||
| continue; | ||
| } | ||
|
|
||
| if (failed(generateLib(dialect, output, dialectStrings))) | ||
| return failure(); | ||
| if (failed(generateLib(dialect, output, dialectStrings))) { | ||
| dialect->emitError("Error in Dialect " + dialectName + | ||
| " while generating library"); | ||
| result = failure(); | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| return success(); | ||
| return result; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that all the macro guards that are available?