File tree Expand file tree Collapse file tree 3 files changed +45
-8
lines changed
include/mlir/Dialect/EmitC/IR Expand file tree Collapse file tree 3 files changed +45
-8
lines changed Original file line number Diff line number Diff line change @@ -126,22 +126,24 @@ def EmitC_IncludeOp
126
126
127
127
```mlir
128
128
// Custom form defining the inclusion of `<myheader>`.
129
- emitc.include "myheader.h" is_standard_include
129
+ emitc.include < "myheader.h">
130
130
131
131
// Generic form of the same operation.
132
132
"emitc.include" (){include = "myheader.h", is_standard_include} : () -> ()
133
133
134
- // Generic form defining the inclusion of `"myheader"`.
134
+ // Custom form defining the inclusion of `"myheader"`.
135
+ emitc.include "myheader.h"
136
+
137
+ // Generic form of the same operation.
135
138
"emitc.include" (){include = "myheader.h"} : () -> ()
136
139
```
137
140
}];
138
141
let arguments = (ins
139
142
Arg<StrAttr, "source file to include">:$include,
140
143
UnitAttr:$is_standard_include
141
144
);
142
- let assemblyFormat = [{
143
- $include attr-dict (`is_standard_include` $is_standard_include^)?
144
- }];
145
+ let printer = [{ return ::print(p, *this); }];
146
+ let parser = [{ return ::parse$cppClass(parser, result); }];
145
147
let verifier = ?;
146
148
}
147
149
Original file line number Diff line number Diff line change @@ -116,6 +116,41 @@ OpFoldResult emitc::ConstantOp::fold(ArrayRef<Attribute> operands) {
116
116
return value ();
117
117
}
118
118
119
+ // ===----------------------------------------------------------------------===//
120
+ // IncludeOp
121
+ // ===----------------------------------------------------------------------===//
122
+
123
+ static void print (OpAsmPrinter &p, IncludeOp &op) {
124
+ bool standardInclude = op.is_standard_include ();
125
+
126
+ p << IncludeOp::getOperationName () << " " ;
127
+ if (standardInclude)
128
+ p << " <" ;
129
+ p << " \" " << op.include () << " \" " ;
130
+ if (standardInclude)
131
+ p << " >" ;
132
+ }
133
+
134
+ static ParseResult parseIncludeOp (OpAsmParser &parser, OperationState &result) {
135
+ bool standardInclude = !parser.parseOptionalLess ();
136
+
137
+ StringAttr include;
138
+ OptionalParseResult includeParseResult =
139
+ parser.parseOptionalAttribute (include, " include" , result.attributes );
140
+ if (!includeParseResult.hasValue ())
141
+ return parser.emitError (parser.getNameLoc ()) << " expected string attribute" ;
142
+
143
+ if (standardInclude && parser.parseOptionalGreater ())
144
+ return parser.emitError (parser.getNameLoc ())
145
+ << " expected trailing '>' for standard include" ;
146
+
147
+ if (standardInclude)
148
+ result.addAttribute (" is_standard_include" ,
149
+ UnitAttr::get (parser.getBuilder ().getContext ()));
150
+
151
+ return success ();
152
+ }
153
+
119
154
// ===----------------------------------------------------------------------===//
120
155
// TableGen'd op method definitions
121
156
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change 1
- // RUN: mlir-opt -verify-diagnostics %s | FileCheck %s
1
+ // RUN: mlir-opt %s | mlir-opt | FileCheck %s
2
2
3
- " emitc.include" (){ include = " test.h" , is_standard_include } : () -> ()
4
- emitc.include " test.h" is_standard_include
3
+ emitc.include < " test.h" >
4
+ emitc.include " test.h"
5
5
6
6
// CHECK-LABEL: func @f(%{{.*}}: i32, %{{.*}}: !emitc.opaque<"int32_t">) {
7
7
func @f (%arg0: i32 , %f: !emitc.opaque <" int32_t" >) {
You can’t perform that action at this time.
0 commit comments