Skip to content

Commit

Permalink
Moved truncate to v1model; disabled P4 special compilation path
Browse files Browse the repository at this point in the history
  • Loading branch information
mbudiu-vmw committed Dec 2, 2016
1 parent d26dc12 commit 1b03329
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backends/bmv2/jsonconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,9 @@ JsonConverter::convertActionBody(const IR::Vector<IR::StatOrDecl>* body,
params->append(lo);
params->append(hi);
continue;
} else if (ef->method->name == corelib.truncate.name) {
} else if (ef->method->name == v1model.truncate.name) {
BUG_CHECK(mc->arguments->size() == 1, "Expected 1 arguments for %1%", mc);
auto primitive = mkPrimitive(corelib.truncate.name, result);
auto primitive = mkPrimitive(v1model.truncate.name, result);
auto params = mkParameters(primitive);
auto len = conv->convert(mc->arguments->at(0));
params->append(len);
Expand Down
4 changes: 4 additions & 0 deletions backends/bmv2/midend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ limitations under the License.

namespace BMV2 {

#if 0
void MidEnd::setup_for_P4_14(CompilerOptions&) {
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap);
// Inlining is simpler for P4 v1.0/1.1 programs, so we have a
Expand All @@ -65,6 +66,7 @@ void MidEnd::setup_for_P4_14(CompilerOptions&) {
new P4::RemoveAllUnusedDeclarations(&refMap),
});
}
#endif

class EnumOn32Bits : public P4::ChooseEnumRepresentation {
bool convert(const IR::Type_Enum* type) const override {
Expand Down Expand Up @@ -134,10 +136,12 @@ MidEnd::MidEnd(CompilerOptions& options) {
bool isv1 = options.isv1();
setName("MidEnd");
refMap.setIsV1(isv1); // must be done BEFORE creating passes
#if 0
if (isv1)
// TODO: This path should be eventually deprecated
setup_for_P4_14(options);
else
#endif
setup_for_P4_16(options);

// BMv2-specific passes
Expand Down
4 changes: 3 additions & 1 deletion backends/bmv2/midend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,9 @@ limitations under the License.
namespace BMV2 {

class MidEnd : public PassManager {
#if 0
void setup_for_P4_14(CompilerOptions& options);
#endif
void setup_for_P4_16(CompilerOptions& options);
P4::InlineWorkList controlsToInline;
P4::ActionsInlineList actionsToInline;
Expand Down
2 changes: 1 addition & 1 deletion backends/ebpf/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Makefile for the EBPF P4 v1.2 back-end.
# Makefile for the EBPF P4-16 back-end.
# To be included in the main P4C compiler makefile

bin_PROGRAMS += p4c-ebpf
Expand Down
2 changes: 1 addition & 1 deletion backends/p4test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Makefile for a fake backend that is used for testing the P4 v1.2 front-end.
# Makefile for a fake backend that is used for testing the P4-16 front-end.
# To be included in the main P4C compiler makefile

noinst_PROGRAMS += p4test
Expand Down
7 changes: 0 additions & 7 deletions frontends/p4/coreLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ class PacketOut : public Model::Extern_Model {
Model::Elem emit;
};

class Truncate : public Model::Extern_Model {
public:
Truncate() : Extern_Model("truncate"), length_type(IR::Type::Bits::get(32)) {}
const IR::Type* length_type;
};

class P4Exception_Model : public ::Model::Elem {
public:
const StandardExceptions exc;
Expand Down Expand Up @@ -126,7 +120,6 @@ class P4CoreLibrary : public ::Model::Model {

PacketIn packetIn;
PacketOut packetOut;
Truncate truncate;

P4Exception_Model noError;
P4Exception_Model packetTooShort;
Expand Down
4 changes: 2 additions & 2 deletions frontends/p4/fromv1.0/programStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,10 +1225,10 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri
} else if (primitive->name == "truncate") {
OPS_CK(primitive, 1);
auto len = primitive->operands.at(0);
auto methodName = p4lib.truncate.Id();
auto methodName = v1model.truncate.Id();
auto method = new IR::PathExpression(methodName);
auto args = new IR::Vector<IR::Expression>();
auto arg0 = new IR::Cast(len->srcInfo, p4lib.truncate.length_type, conv.convert(len));
auto arg0 = new IR::Cast(len->srcInfo, v1model.truncate.length_type, conv.convert(len));
args->push_back(arg0);
auto mc = new IR::MethodCallExpression(primitive->srcInfo, method,
emptyTypeArguments, args);
Expand Down
7 changes: 7 additions & 0 deletions frontends/p4/fromv1.0/v1model.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ struct Random_Model : public ::Model::Elem {
::Model::Elem modify_field_rng_uniform;
};

class Truncate : public Model::Extern_Model {
public:
Truncate() : Extern_Model("truncate"), length_type(IR::Type::Bits::get(32)) {}
const IR::Type* length_type;
};

struct CounterOrMeter_Model : public ::Model::Extern_Model {
explicit CounterOrMeter_Model(cstring name) : Extern_Model(name),
sizeParam("size"), typeParam("type"),
Expand Down Expand Up @@ -249,6 +255,7 @@ class V1Model : public ::Model::Model {
Control_Model egress;
Control_Model ingress;
Switch_Model sw;
Truncate truncate;
CounterOrMeter_Model counterOrMeter;
Counter_Model counter;
Meter_Model meter;
Expand Down
4 changes: 2 additions & 2 deletions ir/v1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2013-present Barefoot Networks, Inc.
Copyright 2013-present Barefoot Networks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,7 +118,7 @@ unsigned IR::Primitive::inferOperandTypes() const {
return 0;
}

const IR::Type *IR::Primitive::inferOperandType(int operand) const {
const IR::Type *IR::Primitive::inferOperandType(int) const {
if (name == "truncate")
return IR::Type::Bits::get(32);
return IR::Type::Unknown::get();
Expand Down
2 changes: 0 additions & 2 deletions p4include/core.p4
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ extern packet_out {
void emit<T>(in T hdr);
}

extern void truncate(in bit<32> length);

// TODO: remove from this file, convert to built-in
extern void verify(in bool check, in error toSignal);

Expand Down
2 changes: 2 additions & 0 deletions p4include/v1model.p4
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ extern void recirculate<T>(in T data);
extern void clone(in CloneType type, in bit<32> session);
extern void clone3<T>(in CloneType type, in bit<32> session, in T data);

extern void truncate(in bit<32> length);

// The name 'standard_metadata' is reserved

// Architecture.
Expand Down

0 comments on commit 1b03329

Please sign in to comment.