Skip to content

Commit ced52d2

Browse files
author
mbudiu-vmw
committed
Fixes in type-checking; parameter removal for actions
1 parent 76cc8da commit ced52d2

File tree

528 files changed

+4683
-4099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

528 files changed

+4683
-4099
lines changed

backends/bmv2/jsonconverter.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,12 @@ JsonConverter::convertTable(const CFG::TableNode* node, Util::JsonArray* counter
11421142

11431143
std::map<cstring, cstring> useActionName;
11441144
for (auto a : *al->actionList) {
1145-
if (a->arguments != nullptr && a->arguments->size() > 0)
1146-
::error("%1%: Actions in action list with arguments not supported", a);
1147-
auto decl = refMap->getDeclaration(a->name->path, true);
1145+
if (a->expression->is<IR::MethodCallExpression>()) {
1146+
auto mce = a->expression->to<IR::MethodCallExpression>();
1147+
if (mce->arguments->size() > 0)
1148+
::error("%1%: Actions in action list with arguments not supported", a);
1149+
}
1150+
auto decl = refMap->getDeclaration(a->getPath(), true);
11481151
BUG_CHECK(decl->is<IR::P4Action>(), "%1%: should be an action name", a);
11491152
auto action = decl->to<IR::P4Action>();
11501153
unsigned id = get(structure.ids, action);
@@ -1203,7 +1206,7 @@ JsonConverter::convertTable(const CFG::TableNode* node, Util::JsonArray* counter
12031206
// the nextLabel.
12041207
if (!hitMiss) {
12051208
for (auto a : *al->actionList) {
1206-
cstring name = a->name->path->name;
1209+
cstring name = a->getName().name;
12071210
cstring label = ::get(useActionName, name);
12081211
if (labelsDone.find(label) == labelsDone.end())
12091212
next_tables->emplace(label, nextLabel);

backends/ebpf/ebpfTable.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void EBPFTable::emitValueType(CodeBuilder* builder) {
109109
builder->blockStart();
110110

111111
for (auto a : *actionList->actionList) {
112-
auto adecl = program->refMap->getDeclaration(a->name->path, true);
112+
auto adecl = program->refMap->getDeclaration(a->getPath(), true);
113113
auto action = adecl->getNode()->to<IR::P4Action>();
114114
cstring name = nameFromAnnotation(action->annotations, action->name);
115115
builder->emitIndent();
@@ -135,7 +135,7 @@ void EBPFTable::emitValueType(CodeBuilder* builder) {
135135
builder->blockStart();
136136

137137
for (auto a : *actionList->actionList) {
138-
auto adecl = program->refMap->getDeclaration(a->name->path, true);
138+
auto adecl = program->refMap->getDeclaration(a->getPath(), true);
139139
auto action = adecl->getNode()->to<IR::P4Action>();
140140
cstring name = nameFromAnnotation(action->annotations, action->name);
141141
emitActionArguments(builder, action, name);
@@ -236,7 +236,7 @@ void EBPFTable::runAction(CodeBuilder* builder, cstring valueName) {
236236
builder->blockStart();
237237

238238
for (auto a : *actionList->actionList) {
239-
auto adecl = program->refMap->getDeclaration(a->name->path, true);
239+
auto adecl = program->refMap->getDeclaration(a->getPath(), true);
240240
auto action = adecl->getNode()->to<IR::P4Action>();
241241
builder->emitIndent();
242242
cstring name = nameFromAnnotation(action->annotations, action->name);

backends/v12test/midend.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ IR::ToplevelBlock* MidEnd::process(CompilerOptions& options, const IR::P4Program
8989
new P4::UniqueParameters(&refMap, isv1),
9090
new P4::TypeChecking(&refMap, &typeMap, isv1),
9191
new P4::SimplifyControlFlow(&refMap, &typeMap),
92-
new P4::TypeChecking(&refMap, &typeMap, isv1),
93-
new P4::RemoveTableParameters(&refMap, &typeMap),
92+
new P4::RemoveParameters(&refMap, &typeMap, isv1),
9493
// Exit statements are transformed into control-flow
9594
new P4::TypeChecking(&refMap, &typeMap, isv1),
9695
new P4::RemoveExits(&refMap, &typeMap),

backends/v12test/run-v12-sample.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env python
2-
# Copyright 2013-present Barefoot Networks, Inc.
3-
#
2+
# Copyright 2013-present Barefoot Networks, Inc.
3+
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
66
# You may obtain a copy of the License at
7-
#
7+
#
88
# http://www.apache.org/licenses/LICENSE-2.0
99
#
1010
# Unless required by applicable law or agreed to in writing, software
@@ -175,7 +175,7 @@ def process_file(options, argv):
175175
if options.verbose:
176176
print("Writing temporary files into ", tmpdir)
177177
ppfile = tmpdir + "/" + basename # after parsing
178-
referenceOutputs = "FrontEnd_11,FrontEnd_12,MidEnd_28_Evaluator"
178+
referenceOutputs = "FrontEnd_11,FrontEnd_12,MidEnd_27_Evaluator"
179179
stderr = tmpdir + "/" + basename + "-stderr"
180180

181181
if not os.path.isfile(options.p4filename):
@@ -210,7 +210,7 @@ def process_file(options, argv):
210210
newName = file_name(tmpdir, base, "-frontend", ext)
211211
os.rename(midFile, newName)
212212
lastFile = newName
213-
endFile = file_name(tmpdir, base, "-MidEnd_28_Evaluator", ext)
213+
endFile = file_name(tmpdir, base, "-MidEnd_27_Evaluator", ext)
214214
if os.path.isfile(endFile):
215215
newName = file_name(tmpdir, base, "-midend", ext)
216216
os.rename(endFile, newName)

frontends/Makefile.am

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Copyright 2013-present Barefoot Networks, Inc.
2-
#
1+
# Copyright 2013-present Barefoot Networks, Inc.
2+
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
55
# You may obtain a copy of the License at
6-
#
6+
#
77
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software

frontends/common/typeMap.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
namespace P4 {
55

6-
const IR::Type_InfInt* TypeMap::canonInfInt = new IR::Type_InfInt();
7-
86
void TypeMap::dbprint(std::ostream& out) const {
97
out << "TypeMap for " << dbp(program);
108
for (auto it : typeMap)

frontends/common/typeMap.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -49,8 +49,6 @@ class TypeMap final : public ProgramMap {
4949
// checks some preconditions before setting the type
5050
void checkPrecondition(const IR::Node* element, const IR::Type* type) const;
5151

52-
static const IR::Type_InfInt* canonInfInt;
53-
5452
friend class TypeInference;
5553
friend class ConstantTypeSubstitution;
5654

@@ -72,8 +70,6 @@ class TypeMap final : public ProgramMap {
7270
// The following are only used by TypeInference
7371
void setLeftValue(const IR::Expression* expression);
7472
void setCompileTimeConstant(const IR::Expression* expression);
75-
const IR::Type_InfInt* canonicalInfInt() const
76-
{ return TypeMap::canonInfInt; }
7773
};
7874
} // namespace P4
7975

frontends/p4/cloner.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "cloner.h"
2+
3+
namespace P4 {
4+
5+
const IR::Node* DeepCloner::postorder(IR::Declaration_Variable* decl) {
6+
return new IR::Declaration_Variable(decl->srcInfo, decl->name, decl->annotations,
7+
decl->type, decl->initializer); }
8+
9+
const IR::Node* DeepCloner::postorder(IR::Declaration_Instance* decl) {
10+
return new IR::Declaration_Instance(decl->srcInfo, decl->name, decl->type,
11+
decl->annotations, decl->initializer); }
12+
13+
const IR::Node* DeepCloner::postorder(IR::ParserState* decl) {
14+
return new IR::ParserState(decl->srcInfo, decl->name, decl->annotations,
15+
decl->components, decl->selectExpression); }
16+
17+
const IR::Node* DeepCloner::postorder(IR::P4Parser* decl) {
18+
return new IR::P4Parser(decl->srcInfo, decl->name, decl->type, decl->constructorParams,
19+
decl->stateful, decl->states); }
20+
21+
const IR::Node* DeepCloner::postorder(IR::P4Control* decl) {
22+
return new IR::P4Control(decl->srcInfo, decl->name, decl->type,
23+
decl->constructorParams, decl->stateful, decl->body); }
24+
25+
const IR::Node* DeepCloner::postorder(IR::P4Action* decl) {}
26+
27+
const IR::Node* DeepCloner::postorder(IR::ActionListElement* decl) {}
28+
29+
const IR::Node* DeepCloner::postorder(IR::TableProperty* decl) {}
30+
31+
const IR::Node* DeepCloner::postorder(IR::P4Table* decl) {}
32+
33+
const IR::Node* DeepCloner::postorder(IR::Function* decl) {}
34+
35+
const IR::Node* DeepCloner::postorder(IR::Parameter* decl) {}
36+
37+
} // namespace P4

frontends/p4/cloner.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -27,10 +27,12 @@ namespace P4 {
2727
class Cloner : public Transform {
2828
public:
2929
Cloner() { setName("Cloner"); }
30-
const IR::Node* clone(const IR::Node* node)
31-
{ return node->apply(*this); }
3230
const IR::Node* postorder(IR::PathExpression* path) override
3331
{ return new IR::PathExpression(path->path->clone()); }
32+
33+
template<typename T>
34+
const T* clone(const IR::Node* node)
35+
{ return node->apply(*this)->to<T>(); }
3436
};
3537

3638
} // namespace P4

frontends/p4/createBuiltins.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,28 @@ void CreateBuiltins::postorder(IR::P4Parser* parser) {
1818
newStates->push_back(rj);
1919
parser->states = newStates;
2020
}
21+
22+
void CreateBuiltins::postorder(IR::ActionListElement* element) {
23+
// convert path expressions to method calls
24+
// actions = { a; b; }
25+
// becomes
26+
// action = { a(); b(); }
27+
if (element->expression->is<IR::PathExpression>())
28+
element->expression = new IR::MethodCallExpression(
29+
element->expression->srcInfo, element->expression,
30+
new IR::Vector<IR::Type>(), new IR::Vector<IR::Expression>());
31+
}
32+
33+
void CreateBuiltins::postorder(IR::ExpressionValue* expression) {
34+
// convert a default_action = a; into
35+
// default_action = a();
36+
auto prop = findContext<IR::TableProperty>();
37+
if (prop != nullptr &&
38+
prop->name == IR::TableProperties::defaultActionPropertyName &&
39+
expression->expression->is<IR::PathExpression>())
40+
expression->expression = new IR::MethodCallExpression(
41+
expression->expression->srcInfo, expression->expression,
42+
new IR::Vector<IR::Type>(), new IR::Vector<IR::Expression>());
43+
}
44+
2145
} // namespace P4

frontends/p4/createBuiltins.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2013-present Barefoot Networks, Inc.
2+
Copyright 2013-present Barefoot Networks, Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ class CreateBuiltins final : public Modifier {
2525
using Modifier::postorder;
2626
CreateBuiltins() { setName("CreateBuiltins"); }
2727
void postorder(IR::P4Parser* parser) override;
28+
void postorder(IR::ActionListElement* element) override;
29+
void postorder(IR::ExpressionValue* property) override;
2830
};
2931
} // namespace P4
3032

frontends/p4/fromv1.0/programStructure.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,11 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName,
588588
newname = actions.get(action);
589589
}
590590
auto ale = new IR::ActionListElement(a.srcInfo, IR::Annotations::empty,
591-
new IR::PathExpression(newname), nullptr);
591+
new IR::PathExpression(newname));
592592
actVect->push_back(ale);
593593
}
594594
auto nop = new IR::ActionListElement(Util::SourceInfo(), IR::Annotations::empty,
595-
new IR::PathExpression(p4lib.noAction.Id()), nullptr);
595+
new IR::PathExpression(p4lib.noAction.Id()));
596596
actVect->push_back(nop);
597597
propvec->push_back(new IR::TableProperty(Util::SourceInfo(),
598598
IR::ID(IR::TableProperties::actionsPropertyName),

frontends/p4/p4-parse.ypp

+5-3
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,12 @@ actionList
758758

759759
actionRef
760760
: optAnnotations name { auto expr = new IR::PathExpression(*$2);
761-
$$ = new IR::ActionListElement(@2, $1, expr, nullptr);}
761+
$$ = new IR::ActionListElement(@2, $1, expr);}
762762
| optAnnotations name '(' argumentList ')'
763-
{ auto expr = new IR::PathExpression(*$2);
764-
$$ = new IR::ActionListElement(@2, $1, expr, $4); }
763+
{ auto method = new IR::PathExpression(*$2);
764+
auto mce = new IR::MethodCallExpression(
765+
@2+@4, method, new IR::Vector<IR::Type>(), $4);
766+
$$ = new IR::ActionListElement(@2, $1, mce); }
765767
;
766768

767769
/************************* ACTION ********************************/

frontends/p4/toP4/toP4.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1048,14 +1048,7 @@ bool ToP4::preorder(const IR::ExpressionValue* v) {
10481048
bool ToP4::preorder(const IR::ActionListElement* ale) {
10491049
dump(3);
10501050
visit(ale->annotations);
1051-
visit(ale->name);
1052-
if (ale->arguments != nullptr) {
1053-
builder.append("(");
1054-
setVecSep(", ");
1055-
visit(ale->arguments);
1056-
doneVec();
1057-
builder.append(")");
1058-
}
1051+
visit(ale->expression);
10591052
return false;
10601053
}
10611054

0 commit comments

Comments
 (0)