Repository navigation
Expand file tree
/
Copy pathprogramStructure.h
More file actions
82 lines (60 loc) · 2.33 KB
/
Copy pathprogramStructure.h
File metadata and controls
82 lines (60 loc) · 2.33 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Copyright 2019 Seungbin Song
*/
#ifndef PSDN_PROGRAM_STRUCTURE_H
#define PSDN_PROGRAM_STRUCTURE_H
#include "frontends/common/model.h"
#include "ir/ir.h"
#include "directMeterMap.h"
#include "resourceMap.h"
#define SUME_SWITCH_TYPE_NAME "SimpleSumeSwitch"
#define SUME_PARSER_PAR_NAME "p"
#define SUME_PIPE_PAR_NAME "map"
#define SUME_DEPARSER_PAR_NAME "d"
namespace PSDN {
// Represent compile-time information about a P4 program
class ProgramStructure {
public:
// Map each action to parent control
ordered_map<const IR::P4Action*, const IR::P4Control*> actionMap;
// Map each parameter of an action to its positional index
ordered_map<const IR::Parameter*, unsigned> actionParamMap;
// Parameters of controls or parsers
ordered_set<const IR::Parameter*> nonActionParams;
// local variables
std::vector<const IR::Declaration_Variable*> variables;
// error codes
ordered_map<const IR::IDeclaration*, unsigned int> errorCodeMap;
// All the direct meters
DirectMeterMap directMeterMap;
// All the direct counters
ordered_map<cstring, const IR::P4Table*> directCounterMap;
// All match kinds
std::set<cstring> matchKinds;
// map IR node to compile-time allocated resource blocks.
ResourceMap resourceMap;
// We place scalar user metadata fields (i.e., bit<>, bool)
// in the scalarsName metadata object, so we may need to rename
// these fields. This map holds the new names.
std::map<const IR::StructField*, cstring> userMetadataMap;
const IR::P4Parser* parser;
const IR::P4Control* pipe;
const IR::P4Control* deparser;
std::set<cstring> nonPipelineControls;
std::set<cstring> pipelineControls;
ProgramStructure() {}
};
class ProgramStructureBuilder : public Inspector {
ProgramStructure* structure;
public:
explicit ProgramStructureBuilder(ProgramStructure* structure) :
structure(structure) { CHECK_NULL(structure); }
void postorder(const IR::ParameterList *paramList) override;
void postorder(const IR::P4Action *action) override;
void postorder(const IR::Declaration_Variable *decl) override;
void postorder(const IR::Type_Error *errors) override;
void postorder(const IR::Declaration_MatchKind* kind) override;
bool preorder(const IR::PackageBlock* main) override;
};
}; //namespace PSDN
#endif