Skip to content

Commit e2931e1

Browse files
authored
actionSynthesis propagate source info (#1773)
- propagate source info from statements to newly created actions and tables; allows later passes to generate errors/warnings referring to the code that the tables were created from rather than just a meaningless name like tbl_act_14 - ResolveReferences -- avoid spurious errors for names with no SourceInfo
1 parent 11e9a87 commit e2931e1

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

frontends/common/resolveReferences/resolveReferences.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ResolutionContext::resolve(IR::ID name, P4::ResolutionType type, bool forwardOK)
5555
BUG("Unexpected enumeration value %1%", static_cast<int>(type));
5656
}
5757

58-
if (!forwardOK) {
58+
if (!forwardOK && name.srcInfo.isValid()) {
5959
std::function<bool(const IR::IDeclaration*)> locationFilter =
6060
[name](const IR::IDeclaration* d) {
6161
Util::SourceInfo nsi = name.srcInfo;
@@ -96,7 +96,7 @@ ResolutionContext::resolve(IR::ID name, P4::ResolutionType type, bool forwardOK)
9696
BUG("Unexpected enumeration value %1%", static_cast<int>(type));
9797
}
9898

99-
if (!forwardOK) {
99+
if (!forwardOK && name.srcInfo.isValid()) {
100100
Util::SourceInfo nsi = name.srcInfo;
101101
Util::SourceInfo dsi = decl->getNode()->srcInfo;
102102
bool before = dsi <= nsi;

midend/actionSynthesis.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statem
7373

7474
auto annos = new IR::Annotations();
7575
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}));
76-
auto tbl = new IR::P4Table(tblName, annos, props);
76+
auto tbl = new IR::P4Table(statement->srcInfo, tblName, annos, props);
7777
tables.push_back(tbl);
7878

7979
// Table invocation statement
@@ -138,6 +138,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) {
138138
left->push_back(action);
139139
actbody = new IR::BlockStatement; }
140140
actbody->push_back(c);
141+
actbody->srcInfo += c->srcInfo;
141142
continue; }
142143
} else if (c->is<IR::MethodCallStatement>()) {
143144
if (mustMove(c->to<IR::MethodCallStatement>())) {
@@ -147,6 +148,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) {
147148
left->push_back(action);
148149
actbody = new IR::BlockStatement; }
149150
actbody->push_back(c);
151+
actbody->srcInfo += c->srcInfo;
150152
continue;
151153
}
152154
} else {
@@ -190,8 +192,8 @@ const IR::Statement* DoSynthesizeActions::createAction(const IR::Statement* toAd
190192
auto action = new IR::P4Action(name, annos, new IR::ParameterList(), body);
191193
actions.push_back(action);
192194
auto actpath = new IR::PathExpression(name);
193-
auto repl = new IR::MethodCallExpression(actpath);
194-
auto result = new IR::MethodCallStatement(repl->srcInfo, repl);
195+
auto repl = new IR::MethodCallExpression(toAdd->srcInfo, actpath);
196+
auto result = new IR::MethodCallStatement(toAdd->srcInfo, repl);
195197
return result;
196198
}
197199

0 commit comments

Comments
 (0)