-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramStructure.cpp
More file actions
66 lines (54 loc) · 2.15 KB
/
programStructure.cpp
File metadata and controls
66 lines (54 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2019 Seungbin Song
*/
#include "programStructure.h"
namespace PSDN {
void ProgramStructureBuilder::postorder(const IR::ParameterList *paramList) {
bool inAction = findContext<IR::P4Action>() != nullptr;
unsigned index = 0;
for (auto p : *paramList->getEnumerator()) {
structure->actionParamMap.emplace(p, index);
if (!inAction)
structure->nonActionParams.emplace(p);
index++;
}
}
void ProgramStructureBuilder::postorder(const IR::P4Action *action) {
LOG2("discovered action " << action);
auto control = findContext<IR::P4Control>();
structure->actionMap.emplace(action, control);
}
void ProgramStructureBuilder::postorder(const IR::Declaration_Variable *decl) {
structure->variables.push_back(decl);
}
void ProgramStructureBuilder::postorder(const IR::Type_Error *errors) {
auto &map = structure->errorCodeMap;
for (auto m : *errors->getDeclarations()) {
BUG_CHECK(map.find(m) == map.end(), "Duplicate error");
map[m] = map.size();
}
}
void ProgramStructureBuilder::postorder(const IR::Declaration_MatchKind* kind) {
for (auto member : kind->members) {
structure->matchKinds.insert(member->name);
}
}
/**
* Find parser, pipe, and deparser
*/
bool ProgramStructureBuilder::preorder(const IR::PackageBlock* package) {
if (package->type->name != "SimpleSumeSwitch") {
::warning(ErrorType::WARN_INVALID, "%1%: the type name of main package should be"
"SimpleSumeSwitch; are you using a different architecture?", package->type->name);
}
auto parser = package->getParameterValue(SUME_PARSER_PAR_NAME);
auto pipe = package->getParameterValue(SUME_PIPE_PAR_NAME);
auto deparser = package->getParameterValue(SUME_DEPARSER_PAR_NAME);
structure->parser = parser->to<IR::ParserBlock>()->container;
structure->pipe = pipe->to<IR::ControlBlock>()->container;
structure->deparser = deparser->to<IR::ControlBlock>()->container;
structure->pipelineControls.emplace(structure->pipe->name);
structure->nonPipelineControls.emplace(structure->deparser->name);
return false;
}
}; // namespace PSDN