Skip to content

Commit

Permalink
Test with nested lists
Browse files Browse the repository at this point in the history
Signed-off-by: Mihai Budiu <[email protected]>
  • Loading branch information
Mihai Budiu committed Nov 18, 2022
1 parent fabd91c commit 15c5504
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 24 deletions.
15 changes: 0 additions & 15 deletions frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,21 +1021,6 @@ TypeInference::checkExternConstructor(const IR::Node* errorPosition,
if (!functionType->is<IR::Type_Method>())
BUG("Unexpected type for function %1%", functionType);

LOG2("Constructor type before specialization " << methodType << " with " << tvs);
TypeVariableSubstitutionVisitor substVisitor(tvs);
substVisitor.setCalledBy(this);
auto specMethodType = methodType->apply(substVisitor);
LOG2("Constructor type after specialization " << specMethodType);
learn(specMethodType, this);
auto canon = getType(specMethodType);
if (canon == nullptr)
return nullptr;

auto functionType = specMethodType->to<IR::Type_MethodBase>();
BUG_CHECK(functionType != nullptr, "Method type is %1%", specMethodType);
if (!functionType->is<IR::Type_Method>())
BUG("Unexpected type for function %1%", functionType);

ConstantTypeSubstitution cts(tvs, refMap, typeMap, this);
// Arguments may need to be cast, e.g., list expression to a
// header type.
Expand Down
23 changes: 23 additions & 0 deletions testdata/p4_16_samples/list8.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <core.p4>

extern E {
E(list<list<bit<32>>> data);
void run();
}

control c() {
E(
(list<list<bit<32>>>)
{
(list<bit<32>>){10, 6, 3},
(list<bit<32>>){5, 2}
}) e;
apply {
e.run();
}
}

control C();
package top(C _c);

top(c()) main;
2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/list-first.p4
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern E {

control c() {
E((list<bit<32>>){32w2,32w3,32w4}) e;
bit<32> list;
apply {
e.run();
}
Expand All @@ -15,4 +16,3 @@ control c() {
control C();
package top(C _c);
top(c()) main;

1 change: 0 additions & 1 deletion testdata/p4_16_samples_outputs/list-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ control c() {
control C();
package top(C _c);
top(c()) main;

11 changes: 5 additions & 6 deletions testdata/p4_16_samples_outputs/list-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ extern E {

control c() {
@name("c.e") E((list<bit<32>>){32w2,32w3,32w4}) e_0;
@hidden action list11() {
@hidden action list12() {
e_0.run();
}
@hidden table tbl_list11 {
@hidden table tbl_list12 {
actions = {
list11();
list12();
}
const default_action = list11();
const default_action = list12();
}
apply {
tbl_list11.apply();
tbl_list12.apply();
}
}

control C();
package top(C _c);
top(c()) main;

2 changes: 1 addition & 1 deletion testdata/p4_16_samples_outputs/list.p4
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern E {

control c() {
E((list<bit<32>>){ 2, 3, 4 }) e;
bit<32> list;
apply {
e.run();
}
Expand All @@ -15,4 +16,3 @@ control c() {
control C();
package top(C _c);
top(c()) main;

17 changes: 17 additions & 0 deletions testdata/p4_16_samples_outputs/list8-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <core.p4>

extern E {
E(list<list<bit<32>>> data);
void run();
}

control c() {
E((list<list<bit<32>>>){(list<bit<32>>){32w10,32w6,32w3},(list<bit<32>>){32w5,32w2}}) e;
apply {
e.run();
}
}

control C();
package top(C _c);
top(c()) main;
17 changes: 17 additions & 0 deletions testdata/p4_16_samples_outputs/list8-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <core.p4>

extern E {
E(list<list<bit<32>>> data);
void run();
}

control c() {
@name("c.e") E((list<list<bit<32>>>){(list<bit<32>>){32w10,32w6,32w3},(list<bit<32>>){32w5,32w2}}) e_0;
apply {
e_0.run();
}
}

control C();
package top(C _c);
top(c()) main;
26 changes: 26 additions & 0 deletions testdata/p4_16_samples_outputs/list8-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <core.p4>

extern E {
E(list<list<bit<32>>> data);
void run();
}

control c() {
@name("c.e") E((list<list<bit<32>>>){(list<bit<32>>){32w10,32w6,32w3},(list<bit<32>>){32w5,32w2}}) e_0;
@hidden action list8l16() {
e_0.run();
}
@hidden table tbl_list8l16 {
actions = {
list8l16();
}
const default_action = list8l16();
}
apply {
tbl_list8l16.apply();
}
}

control C();
package top(C _c);
top(c()) main;
17 changes: 17 additions & 0 deletions testdata/p4_16_samples_outputs/list8.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <core.p4>

extern E {
E(list<list<bit<32>>> data);
void run();
}

control c() {
E((list<list<bit<32>>>){ (list<bit<32>>){ 10, 6, 3 }, (list<bit<32>>){ 5, 2 } }) e;
apply {
e.run();
}
}

control C();
package top(C _c);
top(c()) main;
Empty file.

0 comments on commit 15c5504

Please sign in to comment.