CIRCT 20.0.0git
Loading...
Searching...
No Matches
EmitOps.cpp
Go to the documentation of this file.
1//===- EmitOps.cpp - Implement the Emit operations ------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements `sim` dialect ops.
10//
11//===----------------------------------------------------------------------===//
12
15
16using namespace mlir;
17using namespace circt;
18using namespace emit;
19
20//===----------------------------------------------------------------------===//
21// FileOp
22//===----------------------------------------------------------------------===//
23
24void FileOp::build(OpBuilder &builder, OperationState &result,
25 StringRef fileName, StringRef symName,
26 llvm::function_ref<void()> bodyCtor) {
27 MLIRContext *context = builder.getContext();
28 OpBuilder::InsertionGuard guard(builder);
29
30 auto &props = result.getOrAddProperties<Properties>();
31 props.sym_name = StringAttr::get(context, symName);
32 props.file_name = StringAttr::get(context, fileName);
33
34 builder.createBlock(result.addRegion());
35 if (bodyCtor)
36 bodyCtor();
37}
38
39void FileOp::build(OpBuilder &builder, OperationState &result,
40 StringAttr fileName, llvm::function_ref<void()> bodyCtor) {
41 OpBuilder::InsertionGuard guard(builder);
42
43 auto &props = result.getOrAddProperties<Properties>();
44 props.file_name = fileName;
45
46 builder.createBlock(result.addRegion());
47 if (bodyCtor)
48 bodyCtor();
49}
50
51//===----------------------------------------------------------------------===//
52// FragmentOp
53//===----------------------------------------------------------------------===//
54
55void FragmentOp::build(OpBuilder &builder, OperationState &result,
56 StringAttr symName,
57 llvm::function_ref<void()> bodyCtor) {
58 OpBuilder::InsertionGuard guard(builder);
59
60 auto &props = result.getOrAddProperties<Properties>();
61 props.sym_name = symName;
62
63 builder.createBlock(result.addRegion());
64 if (bodyCtor)
65 bodyCtor();
66}
67
68//===----------------------------------------------------------------------===//
69// RefOp
70//===----------------------------------------------------------------------===//
71
72LogicalResult RefOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
73 auto target = getTargetAttr();
74 auto *op = symbolTable.lookupNearestSymbolFrom(getOperation(), target);
75 if (!op)
76 return emitError("invalid symbol reference: ") << target;
77 if (!isa<emit::Emittable>(op))
78 return emitError("does not target an emittable op: ") << target;
79 return success();
80}
81
82//===----------------------------------------------------------------------===//
83// FileListOp
84//===----------------------------------------------------------------------===//
85
86LogicalResult FileListOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
87 for (auto sym : getFiles()) {
88 Operation *op = symbolTable.lookupNearestSymbolFrom(
89 getOperation(), cast<FlatSymbolRefAttr>(sym));
90 if (!op)
91 return emitError("invalid symbol reference: ") << sym;
92
93 if (!isa<emit::FileOp>(op))
94 return emitError("referenced operation is not a file: ") << sym;
95 }
96 return success();
97}
98
99//===----------------------------------------------------------------------===//
100// TableGen generated logic.
101//===----------------------------------------------------------------------===//
102
103// Provide the autogenerated implementation guts for the Op classes.
104#define GET_OP_CLASSES
105#include "circt/Dialect/Emit/Emit.cpp.inc"
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition emit.py:1