17 #include "mlir/IR/ImplicitLocOpBuilder.h"
18 #include "mlir/Support/LogicalResult.h"
20 using namespace circt;
21 using namespace firrtl;
27 auto clazz = anno.getAs<StringAttr>(
"class").getValue();
28 auto *context = anno.getContext();
29 ImplicitLocOpBuilder builder(target.
ref.
getOp()->getLoc(), context);
33 if (
auto portTarget = dyn_cast<PortAnnoTarget>(target.
ref)) {
34 auto portNum = portTarget.getImpl().getPortNo();
35 if (
auto module = dyn_cast<FModuleOp>(portTarget.getOp())) {
37 builder.setInsertionPointToStart(module.getBodyBlock());
39 builder.setInsertionPointToEnd(module.getBodyBlock());
43 }
else if (
auto ext = dyn_cast<FExtModuleOp>(portTarget.getOp())) {
47 if (paths.size() > 1) {
48 mlir::emitError(state.
circuit.getLoc())
49 <<
"cannot resolve a unique instance path from the "
50 "external module target "
54 inst = cast<InstanceOp>(paths[0].leaf());
56 inst = cast<InstanceOp>(target.
instances.back());
59 builder.setInsertionPointAfter(inst);
63 return mlir::emitError(state.
circuit.getLoc())
64 <<
"Annotation has invalid target: " << anno;
66 }
else if (
auto opResult = dyn_cast<OpAnnoTarget>(target.
ref)) {
67 if (target.
isOpOfType<WireOp, RegOp, RegResetOp>()) {
68 auto *targetBase = opResult.getOp();
69 builder.setInsertionPointAfter(targetBase);
73 return mlir::emitError(state.
circuit.getLoc())
74 <<
"Annotation targets non-wireable operation: " << anno;
77 return mlir::emitError(state.
circuit.getLoc())
78 <<
"Annotation has invalid target: " << anno;
82 auto pin = anno.getAs<StringAttr>(
"pin");
84 return mlir::emitError(state.
circuit.getLoc())
85 <<
"Annotation does not have an associated pin name: " << anno;
94 return mlir::emitError(state.
circuit.getLoc())
96 <<
" defined for pin " << pin;
constexpr const char * wiringSinkAnnoClass
constexpr const char * wiringSourceAnnoClass
LogicalResult applyWiring(const AnnoPathValue &target, DictionaryAttr anno, ApplyState &state)
Consume SourceAnnotation and SinkAnnotation, storing into state.
Value getValueByFieldID(ImplicitLocOpBuilder builder, Value value, unsigned fieldID)
This gets the value targeted by a field id.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
SmallVector< InstanceOp > instances
Operation * getOp() const
State threaded through functions for resolving and applying annotations.
DenseSet< InstanceOp > wiringProblemInstRefs
DenseMap< StringAttr, LegacyWiringProblem > legacyWiringProblems
InstancePathCache & instancePathCache
ArrayRef< InstancePath > getAbsolutePaths(ModuleOpInterface op)