Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ def EmitC_GetFieldOp
let arguments = (ins FlatSymbolRefAttr:$field_name);
let results = (outs EmitCType:$result);
let assemblyFormat = "$field_name `:` type($result) attr-dict";
let hasVerifier = 1;
}

#endif // MLIR_DIALECT_EMITC_IR_EMITC
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 @@ -1398,6 +1398,7 @@ void FileOp::build(OpBuilder &builder, OperationState &state, StringRef id) {
//===----------------------------------------------------------------------===//
// FieldOp
//===----------------------------------------------------------------------===//

static void printEmitCFieldOpTypeAndInitialValue(OpAsmPrinter &p, FieldOp op,
TypeAttr type,
Attribute initialValue) {
Expand Down Expand Up @@ -1455,6 +1456,15 @@ LogicalResult FieldOp::verify() {
//===----------------------------------------------------------------------===//
// GetFieldOp
//===----------------------------------------------------------------------===//

LogicalResult GetFieldOp::verify() {
auto parentClassOp = getOperation()->getParentOfType<emitc::ClassOp>();
if (!parentClassOp.getOperation())
return emitOpError(" must be nested within an emitc.class operation");

return success();
}

LogicalResult GetFieldOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
mlir::FlatSymbolRefAttr fieldNameAttr = getFieldNameAttr();
FieldOp fieldOp =
Expand Down
32 changes: 32 additions & 0 deletions mlir/test/Dialect/EmitC/invalid_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,35 @@ func.func @test_verbatim(%arg0 : !emitc.ptr<i32>, %arg1 : i32) {
emitc.verbatim "{a} " args %arg0, %arg1 : !emitc.ptr<i32>, i32
return
}

// -----

// expected-error @+1 {{'emitc.field' op field must be nested within an emitc.class operation}}
emitc.field @testField : !emitc.array<1xf32>

// -----

// expected-error @+1 {{'emitc.get_field' op must be nested within an emitc.class operation}}
%1 = emitc.get_field @testField : !emitc.array<1xf32>

// -----

emitc.func @testMethod() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
// expected-error @+1 {{'emitc.get_field' op must be nested within an emitc.class operation}}
%1 = get_field @testField : !emitc.array<1xf32>
%2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}

// -----

emitc.class @testClass {
emitc.func @testMethod() {
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
// expected-error @+1 {{'emitc.get_field' op field '@testField' not found in the class}}
%1 = get_field @testField : !emitc.array<1xf32>
%2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
return
}
}