From 1b03329e051dd6238883901df6bae60f6131b18b Mon Sep 17 00:00:00 2001 From: mbudiu-vmw Date: Fri, 2 Dec 2016 09:34:21 -0800 Subject: [PATCH] Moved truncate to v1model; disabled P4 special compilation path --- backends/bmv2/jsonconverter.cpp | 4 ++-- backends/bmv2/midend.cpp | 4 ++++ backends/bmv2/midend.h | 4 +++- backends/ebpf/Makefile.am | 2 +- backends/p4test/Makefile.am | 2 +- frontends/p4/coreLibrary.h | 7 ------- frontends/p4/fromv1.0/programStructure.cpp | 4 ++-- frontends/p4/fromv1.0/v1model.h | 7 +++++++ ir/v1.cpp | 4 ++-- p4include/core.p4 | 2 -- p4include/v1model.p4 | 2 ++ 11 files changed, 24 insertions(+), 18 deletions(-) diff --git a/backends/bmv2/jsonconverter.cpp b/backends/bmv2/jsonconverter.cpp index 8b5181cdfe9..7a26503cd14 100644 --- a/backends/bmv2/jsonconverter.cpp +++ b/backends/bmv2/jsonconverter.cpp @@ -975,9 +975,9 @@ JsonConverter::convertActionBody(const IR::Vector* 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); diff --git a/backends/bmv2/midend.cpp b/backends/bmv2/midend.cpp index 4d8fe08a352..a40ffff9b9a 100644 --- a/backends/bmv2/midend.cpp +++ b/backends/bmv2/midend.cpp @@ -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 @@ -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 { @@ -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 diff --git a/backends/bmv2/midend.h b/backends/bmv2/midend.h index 69dc7333fbb..897b2fcf3ac 100644 --- a/backends/bmv2/midend.h +++ b/backends/bmv2/midend.h @@ -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. @@ -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; diff --git a/backends/ebpf/Makefile.am b/backends/ebpf/Makefile.am index 16132dd9991..f01358ca5e2 100644 --- a/backends/ebpf/Makefile.am +++ b/backends/ebpf/Makefile.am @@ -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 diff --git a/backends/p4test/Makefile.am b/backends/p4test/Makefile.am index c74b52419f5..20ecb4c66a4 100644 --- a/backends/p4test/Makefile.am +++ b/backends/p4test/Makefile.am @@ -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 diff --git a/frontends/p4/coreLibrary.h b/frontends/p4/coreLibrary.h index 6f6a3edc9db..3a04533eb39 100644 --- a/frontends/p4/coreLibrary.h +++ b/frontends/p4/coreLibrary.h @@ -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; @@ -126,7 +120,6 @@ class P4CoreLibrary : public ::Model::Model { PacketIn packetIn; PacketOut packetOut; - Truncate truncate; P4Exception_Model noError; P4Exception_Model packetTooShort; diff --git a/frontends/p4/fromv1.0/programStructure.cpp b/frontends/p4/fromv1.0/programStructure.cpp index daee68807cb..68c6acefc4c 100644 --- a/frontends/p4/fromv1.0/programStructure.cpp +++ b/frontends/p4/fromv1.0/programStructure.cpp @@ -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(); - 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); diff --git a/frontends/p4/fromv1.0/v1model.h b/frontends/p4/fromv1.0/v1model.h index 665bdae3a99..04261f0529a 100644 --- a/frontends/p4/fromv1.0/v1model.h +++ b/frontends/p4/fromv1.0/v1model.h @@ -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"), @@ -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; diff --git a/ir/v1.cpp b/ir/v1.cpp index 70f30746126..bc348a43e52 100644 --- a/ir/v1.cpp +++ b/ir/v1.cpp @@ -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. @@ -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(); diff --git a/p4include/core.p4 b/p4include/core.p4 index 287059ae332..26d23359da0 100644 --- a/p4include/core.p4 +++ b/p4include/core.p4 @@ -48,8 +48,6 @@ extern packet_out { void emit(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); diff --git a/p4include/v1model.p4 b/p4include/v1model.p4 index 6a0d71c4cd3..fd51421b442 100644 --- a/p4include/v1model.p4 +++ b/p4include/v1model.p4 @@ -112,6 +112,8 @@ extern void recirculate(in T data); extern void clone(in CloneType type, in bit<32> session); extern void clone3(in CloneType type, in bit<32> session, in T data); +extern void truncate(in bit<32> length); + // The name 'standard_metadata' is reserved // Architecture.