54 op->walk<WalkOrder::PreOrder>([&](Operation *op) {
55 if (
auto moduleOp = dyn_cast<hw::HWModuleOp>(op)) {
56 LLVM_DEBUG(llvm::dbgs()
57 <<
"Collect DI for module " << moduleOp.getNameAttr() <<
"\n");
58 auto &
module = getOrCreateModule(moduleOp.getNameAttr());
61 return WalkResult::skip();
64 if (
auto moduleOp = dyn_cast<hw::HWModuleExternOp>(op)) {
65 LLVM_DEBUG(llvm::dbgs() <<
"Collect DI for extern module "
66 << moduleOp.getNameAttr() <<
"\n");
67 auto &
module = getOrCreateModule(moduleOp.getNameAttr());
69 module.isExtern = true;
72 for (
auto &port : moduleOp.getPortList()) {
74 var->name = port.name;
76 module.variables.push_back(var);
79 return WalkResult::skip();
82 return WalkResult::advance();
94 bool hasVariables =
false;
95 bool hasInstances =
false;
96 moduleOp.walk([&](Operation *op) {
97 if (isa<debug::VariableOp>(op))
99 if (
auto scopeOp = dyn_cast<debug::ScopeOp>(op)) {
101 node->isInline =
true;
102 node->name = scopeOp.getModuleNameAttr();
104 scopes.insert({scopeOp, node});
112 auto getScope = [&](Value scopeValue) ->
DIModule & {
114 if (
auto scopeOp = scopeValue.getDefiningOp<debug::ScopeOp>())
115 return *scopes.lookup(scopeOp);
122 auto inputValues = moduleOp.getBody().getArguments();
123 auto outputValues = moduleOp.getBodyBlock()->getTerminator()->getOperands();
124 for (
auto &port : moduleOp.getPortList()) {
125 auto value = port.isOutput() ? outputValues[port.argNum]
126 : inputValues[port.argNum];
128 var->name = port.name;
131 module.variables.push_back(var);
136 moduleOp->walk([&](Operation *op) {
137 if (
auto varOp = dyn_cast<debug::VariableOp>(op)) {
139 var->name = varOp.getNameAttr();
140 var->loc = varOp.getLoc();
141 var->value = varOp.getValue();
142 getScope(varOp.getScope()).variables.push_back(var);
146 if (
auto scopeOp = dyn_cast<debug::ScopeOp>(op)) {
148 instance->name = scopeOp.getInstanceNameAttr();
149 instance->op = scopeOp;
150 instance->module = scopes.lookup(scopeOp);
151 getScope(scopeOp.getScope()).instances.push_back(instance);
156 if (
auto instOp = dyn_cast<hw::InstanceOp>(op)) {
160 instance->name = instOp.getInstanceNameAttr();
161 instance->op = instOp;
162 instance->module = &childModule;
163 module.instances.push_back(instance);
173 if (
auto wireOp = dyn_cast<hw::WireOp>(op)) {
175 var->name = wireOp.getNameAttr();
176 var->loc = wireOp.getLoc();
178 module.variables.push_back(var);