From 25f400934ec06024c67065af44f887423dd7d355 Mon Sep 17 00:00:00 2001 From: Chris Dodd Date: Fri, 7 Apr 2017 17:21:24 -0700 Subject: [PATCH] cleanup -- remove unnecessary default args to constructors --- backends/bmv2/jsonconverter.cpp | 13 +- backends/bmv2/lower.cpp | 8 +- backends/ebpf/ebpfType.cpp | 2 +- frontends/common/constantFolding.cpp | 5 +- frontends/p4-14/p4-14-parse.ypp | 2 +- frontends/p4/createBuiltins.cpp | 8 +- frontends/p4/fromv1.0/converters.cpp | 35 +- frontends/p4/fromv1.0/programStructure.cpp | 401 +++++++++------------ frontends/p4/moveDeclarations.cpp | 3 +- frontends/p4/p4-parse.ypp | 26 +- frontends/p4/parserControlFlow.cpp | 16 +- frontends/p4/resetHeaders.cpp | 7 +- frontends/p4/sideEffects.cpp | 58 ++- frontends/p4/specialize.cpp | 4 +- frontends/p4/typeChecking/typeChecker.cpp | 32 +- frontends/p4/uniqueNames.cpp | 2 +- ir/expression.def | 6 +- ir/ir.cpp | 23 +- ir/ir.def | 51 +-- ir/type.cpp | 18 +- ir/type.def | 8 +- ir/v1.def | 12 +- midend/actionSynthesis.cpp | 37 +- midend/actionsInlining.cpp | 11 +- midend/copyStructures.cpp | 10 +- midend/eliminateTuples.cpp | 8 +- midend/expandLookahead.cpp | 18 +- midend/inlining.cpp | 24 +- midend/localizeActions.cpp | 6 +- midend/moveConstructors.cpp | 12 +- midend/nestedStructs.cpp | 4 +- midend/nestedStructs.h | 2 +- midend/noMatch.cpp | 7 +- midend/predication.cpp | 29 +- midend/removeParameters.cpp | 3 +- midend/removeReturns.cpp | 55 ++- midend/removeSelectBooleans.cpp | 4 +- midend/simplifyKey.cpp | 4 +- midend/simplifySelectList.cpp | 2 +- midend/tableHit.cpp | 6 +- tools/ir-generator/ir-generator.ypp | 5 +- 41 files changed, 409 insertions(+), 578 deletions(-) diff --git a/backends/bmv2/jsonconverter.cpp b/backends/bmv2/jsonconverter.cpp index 4fc5a8867e7..7d7bae66c40 100644 --- a/backends/bmv2/jsonconverter.cpp +++ b/backends/bmv2/jsonconverter.cpp @@ -39,7 +39,7 @@ class ArithmeticFixup : public Transform { const IR::Expression* fix(const IR::Expression* expr, const IR::Type_Bits* type) { unsigned width = type->size; if (!type->isSigned) { - auto mask = new IR::Constant(Util::SourceInfo(), type, Util::mask(width), 16); + auto mask = new IR::Constant(type, Util::mask(width), 16); typeMap->setType(mask, type); auto result = new IR::BAnd(expr->srcInfo, expr, mask); typeMap->setType(result, type); @@ -817,12 +817,12 @@ cstring JsonConverter::createCalculation(cstring algo, const IR::Expression* fie auto type = typeMap->getType(fields, true); BUG_CHECK(type->is(), "%1%: expected a struct", fields); for (auto f : *type->to()->fields) { - auto e = new IR::Member(Util::SourceInfo(), fields, f->name); + auto e = new IR::Member(fields, f->name); auto ftype = typeMap->getType(f); typeMap->setType(e, ftype); vec->push_back(e); } - fields = new IR::ListExpression(Util::SourceInfo(), vec); + fields = new IR::ListExpression(vec); typeMap->setType(fields, type); } auto jright = conv->convert(fields); @@ -982,8 +982,7 @@ JsonConverter::convertActionBody(const IR::Vector* body, if (ef->method->name == v1model.clone.name) { BUG_CHECK(mc->arguments->size() == 2, "Expected 2 arguments for %1%", mc); cstring name = refMap->newName("fl"); - auto emptylist = new IR::ListExpression( - Util::SourceInfo(), new IR::Vector()); + auto emptylist = new IR::ListExpression(new IR::Vector()); id = createFieldList(emptylist, "field_lists", name, fieldLists); } else { BUG_CHECK(mc->arguments->size() == 3, "Expected 3 arguments for %1%", mc); @@ -1129,7 +1128,7 @@ void JsonConverter::addToFieldList(const IR::Expression* expr, Util::JsonArray* // recursively add all fields auto st = type->to(); for (auto f : *st->fields) { - auto member = new IR::Member(Util::SourceInfo(), expr, f->name); + auto member = new IR::Member(expr, f->name); typeMap->setType(member, typeMap->getType(f, true)); addToFieldList(member, fl); } @@ -2695,7 +2694,7 @@ Util::IJson* JsonConverter::convertParserStatement(const IR::StatOrDecl* stat) { } else if (minst->is()) { auto bi = minst->to(); if (bi->name == IR::Type_Header::setValid || bi->name == IR::Type_Header::setInvalid) { - auto mem = new IR::Member(Util::SourceInfo(), bi->appliedTo, "$valid$"); + auto mem = new IR::Member(bi->appliedTo, "$valid$"); typeMap->setType(mem, IR::Type_Void::get()); auto jexpr = conv->convert(mem, true, false); result->emplace("op", "set"); diff --git a/backends/bmv2/lower.cpp b/backends/bmv2/lower.cpp index b2d04b414e7..e3cf2f9c591 100644 --- a/backends/bmv2/lower.cpp +++ b/backends/bmv2/lower.cpp @@ -401,12 +401,10 @@ const IR::PathExpression* RemoveComplexExpressions::createTemporary(const IR::Expression* expression) { auto type = typeMap->getType(expression, true); auto name = refMap->newName("tmp"); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), IR::ID(name), - IR::Annotations::empty, type->getP4Type(), nullptr); + auto decl = new IR::Declaration_Variable(IR::ID(name), type->getP4Type()); newDecls.push_back(decl); typeMap->setType(decl, type); - auto assign = new IR::AssignmentStatement( - Util::SourceInfo(), new IR::PathExpression(name), expression); + auto assign = new IR::AssignmentStatement(new IR::PathExpression(name), expression); assignments.push_back(assign); return new IR::PathExpression(name); } @@ -488,7 +486,7 @@ RemoveComplexExpressions::postorder(IR::Statement* statement) { return statement; auto vec = new IR::IndexedVector(assignments); vec->push_back(statement); - auto block = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, vec); + auto block = new IR::BlockStatement(vec); assignments.clear(); return block; } diff --git a/backends/ebpf/ebpfType.cpp b/backends/ebpf/ebpfType.cpp index b2f82d06fc1..df8bb316349 100644 --- a/backends/ebpf/ebpfType.cpp +++ b/backends/ebpf/ebpfType.cpp @@ -34,7 +34,7 @@ EBPFType* EBPFTypeFactory::create(const IR::Type* type) { auto canon = typeMap->getTypeType(type, true); result = create(canon); auto path = new IR::Path(type->to()->name); - result = new EBPFTypeName(new IR::Type_Name(Util::SourceInfo(), path), result); + result = new EBPFTypeName(new IR::Type_Name(path), result); } else if (type->is()) { auto canon = typeMap->getTypeType(type, true); result = create(canon); diff --git a/frontends/common/constantFolding.cpp b/frontends/common/constantFolding.cpp index 3978c34b6ec..5c89809a981 100644 --- a/frontends/common/constantFolding.cpp +++ b/frontends/common/constantFolding.cpp @@ -524,7 +524,7 @@ const IR::Node* DoConstantFolding::postorder(IR::Concat* e) { return e; } - auto resultType = IR::Type_Bits::get(Util::SourceInfo(), lt->size + rt->size, lt->isSigned); + auto resultType = IR::Type_Bits::get(lt->size + rt->size, lt->isSigned); mpz_class value = Util::shift_left(left->value, static_cast(rt->size)) + right->value; auto result = new IR::Constant(e->srcInfo, resultType, value, left->base); setConstant(e, result); @@ -785,8 +785,7 @@ const IR::Node* DoConstantFolding::postorder(IR::SelectExpression* expression) { changes = true; finished = true; if (someUnknown) { - auto newc = new IR::SelectCase( - c->srcInfo, new IR::DefaultExpression(Util::SourceInfo()), c->state); + auto newc = new IR::SelectCase(c->srcInfo, new IR::DefaultExpression(), c->state); cases.push_back(newc); } else { // This is the result. diff --git a/frontends/p4-14/p4-14-parse.ypp b/frontends/p4-14/p4-14-parse.ypp index 68e68dba946..d3e68f45f26 100644 --- a/frontends/p4-14/p4-14-parse.ypp +++ b/frontends/p4-14/p4-14-parse.ypp @@ -638,7 +638,7 @@ table_body: /* epsilon */ { $$ = new IR::V1Table(getPragmas()); } $$->default_action_args = $6; } | table_body IDENTIFIER ':' expression ';' { auto exp = new IR::ExpressionValue(@4, $4); - auto prop = new IR::Property(@2, IR::ID(@2, $2), IR::Annotations::empty, exp, false); + auto prop = new IR::Property(@2, IR::ID(@2, $2), exp, false); $1->addProperty(prop); $$ = $1; } | table_body error ';' { $$=$1; } diff --git a/frontends/p4/createBuiltins.cpp b/frontends/p4/createBuiltins.cpp index 03df6ccdef1..bc6ba4eff9e 100644 --- a/frontends/p4/createBuiltins.cpp +++ b/frontends/p4/createBuiltins.cpp @@ -20,14 +20,10 @@ limitations under the License. namespace P4 { void CreateBuiltins::postorder(IR::P4Parser* parser) { auto newStates = new IR::IndexedVector(*parser->states); - IR::ParserState* ac = new IR::ParserState(Util::SourceInfo(), - IR::ParserState::accept, - IR::Annotations::empty, + IR::ParserState* ac = new IR::ParserState(IR::ParserState::accept, new IR::IndexedVector(), nullptr); - IR::ParserState* rj = new IR::ParserState(Util::SourceInfo(), - IR::ParserState::reject, - IR::Annotations::empty, + IR::ParserState* rj = new IR::ParserState(IR::ParserState::reject, new IR::IndexedVector(), nullptr); newStates->push_back(ac); diff --git a/frontends/p4/fromv1.0/converters.cpp b/frontends/p4/fromv1.0/converters.cpp index 772f8c09a1f..fde94eb71f0 100644 --- a/frontends/p4/fromv1.0/converters.cpp +++ b/frontends/p4/fromv1.0/converters.cpp @@ -48,8 +48,7 @@ const IR::Node* ExpressionConverter::postorder(IR::Mask* expression) { return exp; if (value != range.value) return new IR::BAnd(expression->srcInfo, exp, cst); - return new IR::Slice(Util::SourceInfo(), exp, - new IR::Constant(range.highIndex), new IR::Constant(range.lowIndex)); + return new IR::Slice(exp, new IR::Constant(range.highIndex), new IR::Constant(range.lowIndex)); } const IR::Node* ExpressionConverter::postorder(IR::Constant* expression) { @@ -95,13 +94,11 @@ const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) { } const IR::Expression* method = new IR::Member( - Util::SourceInfo(), structure->paramReference(structure->parserPacketIn), P4::P4CoreLibrary::instance.packetIn.lookahead.Id()); auto typeargs = new IR::Vector(); typeargs->push_back(IR::Type_Bits::get(aval + bval)); - auto lookahead = new IR::MethodCallExpression( - Util::SourceInfo(), method, typeargs, new IR::Vector()); + auto lookahead = new IR::MethodCallExpression(method, typeargs); auto result = new IR::Slice(primitive->srcInfo, lookahead, new IR::Constant(bval - 1), new IR::Constant(0)); @@ -112,7 +109,7 @@ const IR::Node* ExpressionConverter::postorder(IR::Primitive* primitive) { auto base = primitive->operands.at(0); auto method = new IR::Member(primitive->srcInfo, base, IR::ID(IR::Type_Header::isValid)); auto result = new IR::MethodCallExpression(primitive->srcInfo, IR::Type::Boolean::get(), - method, new IR::Vector(), new IR::Vector()); + method); return result; } BUG("Unexpected primitive %1%", primitive); @@ -145,7 +142,7 @@ const IR::Node* ExpressionConverter::postorder(IR::ConcreteHeaderRef* nhr) { else ref = structure->conversionContext.userMetadata->clone(); } - auto result = new IR::Member(Util::SourceInfo(), ref, nhr->ref->name); + auto result = new IR::Member(ref, nhr->ref->name); result->type = nhr->type; return result; } @@ -178,11 +175,8 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) { auto table = structure->tables.get(apply->name); auto newname = structure->tables.get(table); auto tbl = new IR::PathExpression(newname); - auto method = new IR::Member(Util::SourceInfo(), tbl, - IR::ID(IR::IApply::applyMethodName)); - auto call = new IR::MethodCallExpression(apply->srcInfo, method, - structure->emptyTypeArguments, - new IR::Vector()); + auto method = new IR::Member(tbl, IR::ID(IR::IApply::applyMethodName)); + auto call = new IR::MethodCallExpression(apply->srcInfo, method); if (apply->actions.size() == 0) { auto stat = new IR::MethodCallStatement(apply->srcInfo, call); prune(); @@ -210,9 +204,9 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) { if (!otherLabels) { StatementConverter conv(structure, renameMap); - auto hitcase = hit ? conv.convert(hit) : new IR::EmptyStatement(Util::SourceInfo()); + auto hitcase = hit ? conv.convert(hit) : new IR::EmptyStatement(); auto misscase = miss ? conv.convert(miss) : nullptr; - auto check = new IR::Member(Util::SourceInfo(), call, IR::Type_Table::hit); + auto check = new IR::Member(call, IR::Type_Table::hit); auto ifstat = new IR::IfStatement(apply->srcInfo, check, hitcase, misscase); prune(); return ifstat; @@ -230,7 +224,7 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) { stat = conv.convert(a.second); } const IR::Expression* destination; if (a.first == "default") { - destination = new IR::DefaultExpression(Util::SourceInfo()); + destination = new IR::DefaultExpression(); } else { cstring act_name = a.first; cstring full_name = table->name + '.' + act_name; @@ -239,7 +233,7 @@ const IR::Node* StatementConverter::preorder(IR::Apply* apply) { destination = new IR::PathExpression(IR::ID(act_name)); } auto swcase = new IR::SwitchCase(a.second->srcInfo, destination, stat); cases.insert(insert_at, swcase); } - auto check = new IR::Member(Util::SourceInfo(), call, IR::Type_Table::action_run); + auto check = new IR::Member(call, IR::Type_Table::action_run); auto sw = new IR::SwitchStatement(apply->srcInfo, check, std::move(cases)); prune(); return sw; @@ -252,13 +246,12 @@ const IR::Node* StatementConverter::preorder(IR::Primitive* primitive) { if (control != nullptr) { auto instanceName = get(renameMap, control->name); auto ctrl = new IR::PathExpression(IR::ID(instanceName)); - auto method = new IR::Member(Util::SourceInfo(), ctrl, IR::ID(IR::IApply::applyMethodName)); + auto method = new IR::Member(ctrl, IR::ID(IR::IApply::applyMethodName)); auto args = new IR::Vector(); args->push_back(structure->conversionContext.header->clone()); args->push_back(structure->conversionContext.userMetadata->clone()); args->push_back(structure->conversionContext.standardMetadata->clone()); - auto call = new IR::MethodCallExpression(primitive->srcInfo, method, - structure->emptyTypeArguments, args); + auto call = new IR::MethodCallExpression(primitive->srcInfo, method, args); auto stat = new IR::MethodCallStatement(primitive->srcInfo, call); return stat; } @@ -273,7 +266,7 @@ const IR::Node* StatementConverter::preorder(IR::If* cond) { BUG_CHECK(pred != nullptr, "Expected to get an expression when converting %1%", cond->pred); const IR::Statement* t, *f; if (cond->ifTrue == nullptr) - t = new IR::EmptyStatement(Util::SourceInfo()); + t = new IR::EmptyStatement(); else t = conv.convert(cond->ifTrue); @@ -293,7 +286,7 @@ const IR::Statement* StatementConverter::convert(const IR::Vectorpush_back(s); } - auto result = new IR::BlockStatement(toConvert->srcInfo, IR::Annotations::empty, stats); + auto result = new IR::BlockStatement(toConvert->srcInfo, stats); return result; } diff --git a/frontends/p4/fromv1.0/programStructure.cpp b/frontends/p4/fromv1.0/programStructure.cpp index ba98e6d3508..c4fbd793f48 100644 --- a/frontends/p4/fromv1.0/programStructure.cpp +++ b/frontends/p4/fromv1.0/programStructure.cpp @@ -54,8 +54,7 @@ const IR::Annotations* ProgramStructure::addNameAnnotation(cstring name, const IR::Annotations* annos) { if (annos == nullptr) annos = IR::Annotations::empty; - return annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), name)); + return annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, new IR::StringLiteral(name)); } cstring ProgramStructure::makeUniqueName(cstring base) { @@ -189,8 +188,7 @@ void ProgramStructure::createStructures() { auto field = new IR::StructField(id.srcInfo, id, annos, tn); fields->push_back(field); } - auto metadata = new IR::Type_Struct(Util::SourceInfo(), v1model.metadataType.Id(), - IR::Annotations::empty, fields); + auto metadata = new IR::Type_Struct(v1model.metadataType.Id(), fields); declarations->push_back(metadata); fields = new IR::IndexedVector(); @@ -220,8 +218,7 @@ void ProgramStructure::createStructures() { fields->push_back(field); } - auto headers = new IR::Type_Struct(Util::SourceInfo(), IR::ID(v1model.headersType.name), - IR::Annotations::empty, fields); + auto headers = new IR::Type_Struct(IR::ID(v1model.headersType.name), fields); declarations->push_back(headers); } @@ -304,11 +301,9 @@ const IR::Statement* ProgramStructure::convertParserStatement(const IR::Expressi this->latest = conv.convert(dest); conv.replaceNextWithLast = false; const IR::Expression* method = new IR::Member( - Util::SourceInfo(), paramReference(parserPacketIn), p4lib.packetIn.extract.Id()); - auto mce = new IR::MethodCallExpression(expr->srcInfo, method, - emptyTypeArguments, args); + auto mce = new IR::MethodCallExpression(expr->srcInfo, method, args); auto result = new IR::MethodCallStatement(expr->srcInfo, mce); return result; } else if (primitive->name == "set_metadata") { @@ -421,34 +416,33 @@ const IR::ParserState* ProgramStructure::convertParser(const IR::V1Parser* parse void ProgramStructure::createParser() { auto paramList = new IR::IndexedVector(); auto pinpath = new IR::Path(p4lib.packetIn.Id()); - auto pintype = new IR::Type_Name(Util::SourceInfo(), pinpath); - parserPacketIn = new IR::Parameter(Util::SourceInfo(), v1model.parser.packetParam.Id(), - IR::Annotations::empty, IR::Direction::None, pintype); + auto pintype = new IR::Type_Name(pinpath); + parserPacketIn = new IR::Parameter(v1model.parser.packetParam.Id(), + IR::Direction::None, pintype); paramList->push_back(parserPacketIn); auto headpath = new IR::Path(v1model.headersType.Id()); - auto headtype = new IR::Type_Name(Util::SourceInfo(), headpath); - parserHeadersOut = new IR::Parameter(Util::SourceInfo(), v1model.parser.headersParam.Id(), - IR::Annotations::empty, IR::Direction::Out, headtype); + auto headtype = new IR::Type_Name(headpath); + parserHeadersOut = new IR::Parameter(v1model.parser.headersParam.Id(), + IR::Direction::Out, headtype); paramList->push_back(parserHeadersOut); conversionContext.header = paramReference(parserHeadersOut); auto metapath = new IR::Path(v1model.metadataType.Id()); - auto metatype = new IR::Type_Name(Util::SourceInfo(), metapath); - auto meta = new IR::Parameter(Util::SourceInfo(), v1model.parser.metadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, metatype); + auto metatype = new IR::Type_Name(metapath); + auto meta = new IR::Parameter(v1model.parser.metadataParam.Id(), + IR::Direction::InOut, metatype); paramList->push_back(meta); conversionContext.userMetadata = paramReference(meta); auto stdMetaPath = new IR::Path(v1model.standardMetadataType.Id()); - auto stdMetaType = new IR::Type_Name(Util::SourceInfo(), stdMetaPath); - auto stdmeta = new IR::Parameter(Util::SourceInfo(), v1model.ingress.standardMetadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, stdMetaType); + auto stdMetaType = new IR::Type_Name(stdMetaPath); + auto stdmeta = new IR::Parameter(v1model.ingress.standardMetadataParam.Id(), + IR::Direction::InOut, stdMetaType); paramList->push_back(stdmeta); conversionContext.standardMetadata = paramReference(stdmeta); - auto type = new IR::Type_Parser(Util::SourceInfo(), v1model.parser.Id(), - IR::Annotations::empty, new IR::TypeParameters(), + auto type = new IR::Type_Parser(v1model.parser.Id(), new IR::TypeParameters(), new IR::ParameterList(paramList)); auto stateful = new IR::IndexedVector(); auto states = new IR::IndexedVector(); @@ -459,8 +453,7 @@ void ProgramStructure::createParser() { if (states->empty()) ::error("No parsers specified"); - auto result = new IR::P4Parser(Util::SourceInfo(), v1model.parser.Id(), type, - new IR::ParameterList(), stateful, states); + auto result = new IR::P4Parser(v1model.parser.Id(), type, stateful, states); declarations->push_back(result); conversionContext.clear(); } @@ -506,7 +499,7 @@ class HeaderRepresentation { if (expression->is()) { cstring name = expression->to()->ref->name; if (header.find(name) == header.end()) - header[name] = new IR::Member(Util::SourceInfo(), hdrsParam, name); + header[name] = new IR::Member(hdrsParam, name); return header[name]; } else if (expression->is()) { auto hsir = expression->to(); @@ -520,7 +513,7 @@ class HeaderRepresentation { if (stackElement[hdr].find(index) != stackElement[hdr].end()) return stackElement[hdr][index]; } - auto ai = new IR::ArrayIndex(Util::SourceInfo(), hdr, hsir->index_); + auto ai = new IR::ArrayIndex(hdr, hsir->index_); stackElement[hdr][index] = ai; return ai; } @@ -528,7 +521,7 @@ class HeaderRepresentation { } const IR::Expression* getFakeHeader(cstring state) { if (fakeHeader.find(state) == fakeHeader.end()) - fakeHeader[state] = new IR::StringLiteral(Util::SourceInfo(), state); + fakeHeader[state] = new IR::StringLiteral(state); return fakeHeader[state]; } }; @@ -536,9 +529,9 @@ class HeaderRepresentation { void ProgramStructure::createDeparser() { auto headpath = new IR::Path(v1model.headersType.Id()); - auto headtype = new IR::Type_Name(Util::SourceInfo(), headpath); - auto headers = new IR::Parameter(Util::SourceInfo(), v1model.deparser.headersParam.Id(), - IR::Annotations::empty, IR::Direction::In, headtype); + auto headtype = new IR::Type_Name(headpath); + auto headers = new IR::Parameter(v1model.deparser.headersParam.Id(), + IR::Direction::In, headtype); auto hdrsParam = paramReference(headers); HeaderRepresentation hr(hdrsParam); @@ -587,16 +580,14 @@ void ProgramStructure::createDeparser() { auto params = new IR::IndexedVector(); auto poutpath = new IR::Path(p4lib.packetOut.Id()); - auto pouttype = new IR::Type_Name(Util::SourceInfo(), poutpath); - auto packetOut = new IR::Parameter(Util::SourceInfo(), v1model.deparser.packetParam.Id(), - IR::Annotations::empty, IR::Direction::None, pouttype); + auto pouttype = new IR::Type_Name(poutpath); + auto packetOut = new IR::Parameter(v1model.deparser.packetParam.Id(), + IR::Direction::None, pouttype); params->push_back(packetOut); params->push_back(headers); conversionContext.header = paramReference(headers); - auto type = new IR::Type_Control(Util::SourceInfo(), v1model.deparser.Id(), - IR::Annotations::empty, - new IR::TypeParameters(), new IR::ParameterList(params)); + auto type = new IR::Type_Control(v1model.deparser.Id(), new IR::ParameterList(params)); auto stateful = new IR::IndexedVector(); auto components = new IR::IndexedVector(); @@ -610,17 +601,14 @@ void ProgramStructure::createDeparser() { auto args = new IR::Vector(); args->push_back(exp); const IR::Expression* method = new IR::Member( - Util::SourceInfo(), paramReference(packetOut), p4lib.packetOut.emit.Id()); - auto mce = new IR::MethodCallExpression(Util::SourceInfo(), method, - emptyTypeArguments, args); - auto stat = new IR::MethodCallStatement(Util::SourceInfo(), mce); + auto mce = new IR::MethodCallExpression(method, args); + auto stat = new IR::MethodCallStatement(mce); components->push_back(stat); } - auto body = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, components); - deparser = new IR::P4Control(Util::SourceInfo(), v1model.deparser.Id(), type, - new IR::ParameterList(), stateful, body); + auto body = new IR::BlockStatement(components); + deparser = new IR::P4Control(v1model.deparser.Id(), type, stateful, body); declarations->push_back(deparser); } @@ -631,7 +619,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, ExpressionConverter conv(this); auto propvec = new IR::IndexedVector(*table->properties.properties); auto actVect = new IR::IndexedVector(); - auto actionList = new IR::ActionList(Util::SourceInfo(), actVect); + auto actionList = new IR::ActionList(actVect); cstring profile = table->action_profile.name; const IR::ActionProfile* action_profile = nullptr; @@ -662,8 +650,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, } else { newname = actions.get(action); } - auto ale = new IR::ActionListElement(a.srcInfo, IR::Annotations::empty, - new IR::PathExpression(newname)); + auto ale = new IR::ActionListElement(a.srcInfo, new IR::PathExpression(newname)); actVect->push_back(ale); } if (!table->default_action) { @@ -676,14 +663,12 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, new IR::ActionListElement( new IR::Annotations({new IR::Annotation("default_only", {})}), new IR::PathExpression(table->default_action))); } - propvec->push_back(new IR::Property(Util::SourceInfo(), - IR::ID(IR::TableProperties::actionsPropertyName), - IR::Annotations::empty, + propvec->push_back(new IR::Property(IR::ID(IR::TableProperties::actionsPropertyName), actionList, false)); if (table->reads != nullptr) { auto keyVec = new IR::Vector(); - auto key = new IR::Key(Util::SourceInfo(), keyVec); + auto key = new IR::Key(keyVec); for (size_t i=0; i < table->reads->size(); i++) { auto e = table->reads->at(i); auto rt = table->reads_types.at(i); @@ -692,8 +677,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, auto ce = conv.convert(e); // TODO: this should use a translation routine. Now it relies on the fact that // the spelling is the same - auto keyComp = new IR::KeyElement(Util::SourceInfo(), IR::Annotations::empty, - ce, new IR::PathExpression(rt)); + auto keyComp = new IR::KeyElement(ce, new IR::PathExpression(rt)); keyVec->push_back(keyComp); } @@ -706,8 +690,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, if (fl != nullptr) { for (auto f : fl->fields) { auto ce = conv.convert(f); - auto keyComp = new IR::KeyElement( - Util::SourceInfo(), IR::Annotations::empty, ce, + auto keyComp = new IR::KeyElement(ce, new IR::PathExpression(v1model.selectorMatchType.Id())); keyVec->push_back(keyComp); } @@ -715,28 +698,23 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, } } - propvec->push_back(new IR::Property(Util::SourceInfo(), - IR::ID(IR::TableProperties::keyPropertyName), - IR::Annotations::empty, - key, false)); + propvec->push_back(new IR::Property(IR::ID(IR::TableProperties::keyPropertyName), + key, false)); } if (table->size != 0) { - auto prop = new IR::Property( - Util::SourceInfo(), IR::ID("size"), IR::Annotations::empty, - new IR::ExpressionValue(Util::SourceInfo(), new IR::Constant(table->size)), false); + auto prop = new IR::Property(IR::ID("size"), + new IR::ExpressionValue(new IR::Constant(table->size)), false); propvec->push_back(prop); } if (table->min_size != 0) { - auto prop = new IR::Property( - Util::SourceInfo(), IR::ID("min_size"), IR::Annotations::empty, - new IR::ExpressionValue(Util::SourceInfo(), new IR::Constant(table->min_size)), false); + auto prop = new IR::Property(IR::ID("min_size"), + new IR::ExpressionValue(new IR::Constant(table->min_size)), false); propvec->push_back(prop); } if (table->max_size != 0) { - auto prop = new IR::Property( - Util::SourceInfo(), IR::ID("max_size"), IR::Annotations::empty, - new IR::ExpressionValue(Util::SourceInfo(), new IR::Constant(table->max_size)), false); + auto prop = new IR::Property(IR::ID("max_size"), + new IR::ExpressionValue(new IR::Constant(table->max_size)), false); propvec->push_back(prop); } @@ -746,11 +724,10 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, : p4lib.noAction.Id()); auto args = table->default_action_args != nullptr ? table->default_action_args : new IR::Vector(); - auto methodCall = new IR::MethodCallExpression(Util::SourceInfo(), act, - emptyTypeArguments, args); + auto methodCall = new IR::MethodCallExpression(act, args); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(IR::TableProperties::defaultActionPropertyName), - IR::Annotations::empty, new IR::ExpressionValue(Util::SourceInfo(), methodCall), + IR::ID(IR::TableProperties::defaultActionPropertyName), + new IR::ExpressionValue(methodCall), /* isConstant = */ hasExplicitDefaultAction); propvec->push_back(prop); } @@ -767,15 +744,15 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, args->push_back(size); auto width = new IR::Constant(v1model.action_selector.widthType, flc->output_width); args->push_back(width); - auto constructor = new IR::ConstructorCallExpression(Util::SourceInfo(), type, args); - auto propvalue = new IR::ExpressionValue(Util::SourceInfo(), constructor); + auto constructor = new IR::ConstructorCallExpression(type, args); + auto propvalue = new IR::ExpressionValue(constructor); auto annos = addNameAnnotation(action_profile->name); if (action_selector->mode) annos = annos->addAnnotation("mode", new IR::StringLiteral(action_selector->mode)); if (action_selector->type) annos = annos->addAnnotation("type", new IR::StringLiteral(action_selector->type)); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(v1model.tableAttributes.tableImplementation.Id()), + IR::ID(v1model.tableAttributes.tableImplementation.Id()), annos, propvalue, false); propvec->push_back(prop); } else if (action_profile != nullptr) { @@ -783,11 +760,11 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, auto type = new IR::Type_Name(new IR::Path(v1model.action_profile.Id())); auto args = new IR::Vector(); args->push_back(size); - auto constructor = new IR::ConstructorCallExpression(Util::SourceInfo(), type, args); - auto propvalue = new IR::ExpressionValue(Util::SourceInfo(), constructor); + auto constructor = new IR::ConstructorCallExpression(type, args); + auto propvalue = new IR::ExpressionValue(constructor); auto annos = addNameAnnotation(action_profile->name); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(v1model.tableAttributes.tableImplementation.Id()), + IR::ID(v1model.tableAttributes.tableImplementation.Id()), annos, propvalue, false); propvec->push_back(prop); } @@ -798,25 +775,24 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName, auto type = new IR::Type_Name(new IR::Path(v1model.directCounter.Id())); auto args = new IR::Vector(); args->push_back(kindarg); - auto constructor = new IR::ConstructorCallExpression(Util::SourceInfo(), type, args); - auto propvalue = new IR::ExpressionValue(Util::SourceInfo(), constructor); + auto constructor = new IR::ConstructorCallExpression(type, args); + auto propvalue = new IR::ExpressionValue(constructor); auto annos = addNameAnnotation(ctr); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(v1model.tableAttributes.directCounter.Id()), + IR::ID(v1model.tableAttributes.directCounter.Id()), annos, propvalue, false); propvec->push_back(prop); } if (mtr != nullptr) { auto meter = new IR::PathExpression(mtr->name); - auto propvalue = new IR::ExpressionValue(Util::SourceInfo(), meter); + auto propvalue = new IR::ExpressionValue(meter); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(v1model.tableAttributes.directMeter.Id()), - IR::Annotations::empty, propvalue, false); + IR::ID(v1model.tableAttributes.directMeter.Id()), propvalue, false); propvec->push_back(prop); } - auto props = new IR::TableProperties(Util::SourceInfo(), propvec); + auto props = new IR::TableProperties(propvec); auto annos = addNameAnnotation(table->name, table->annotations); auto result = new IR::P4Table(table->srcInfo, newName, annos, props); return result; @@ -841,7 +817,7 @@ const IR::Expression* ProgramStructure::convertHashAlgorithm(IR::ID algorithm) { result = algorithm; } auto pe = new IR::TypeNameExpression(v1model.algorithm.Id()); - auto mem = new IR::Member(Util::SourceInfo(), pe, result); + auto mem = new IR::Member(pe, result); return mem; } @@ -876,11 +852,10 @@ const IR::Statement* ProgramStructure::sliceAssign( auto type = left->type; if (!sameBitsType(mask->type, left->type)) - mask = new IR::Cast(Util::SourceInfo(), type, mask); + mask = new IR::Cast(type, mask); if (!sameBitsType(right->type, left->type)) - right = new IR::Cast(Util::SourceInfo(), type, right); - auto op1 = new IR::BAnd(left->srcInfo, left, - new IR::Cmpl(Util::SourceInfo(), mask)); + right = new IR::Cast(type, right); + auto op1 = new IR::BAnd(left->srcInfo, left, new IR::Cmpl(mask)); auto op2 = new IR::BAnd(right->srcInfo, right, mask); auto result = new IR::BOr(mask->srcInfo, op1, op2); return new IR::AssignmentStatement(srcInfo, left, result); @@ -917,8 +892,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto args = new IR::Vector(); for (unsigned i = 1; i < primitive->operands.size(); ++i) args->push_back(conv.convert(primitive->operands.at(i))); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(primitive->srcInfo, mc); } else if (primitive->name == "modify_field") { if (primitive->operands.size() == 2) { @@ -994,11 +968,11 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto right = conv.convert(primitive->operands.at(1)); IR::Expression* op = nullptr; if (primitive->name == "bit_not") - op = new IR::Cmpl(Util::SourceInfo(), right); + op = new IR::Cmpl(right); auto result = new IR::AssignmentStatement(primitive->srcInfo, dest, op); return result; } else if (primitive->name == "no_op") { - return new IR::EmptyStatement(Util::SourceInfo()); + return new IR::EmptyStatement(); } else if (primitive->name == "add_to_field" || primitive->name == "subtract_from_field") { OPS_CK(primitive, 2); auto left = conv.convert(primitive->operands.at(0)); @@ -1014,18 +988,16 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri } else if (primitive->name == "remove_header") { OPS_CK(primitive, 1); auto hdr = conv.convert(primitive->operands.at(0)); - auto method = new IR::Member(Util::SourceInfo(), hdr, IR::ID(IR::Type_Header::setInvalid)); + auto method = new IR::Member(hdr, IR::ID(IR::Type_Header::setInvalid)); auto args = new IR::Vector(); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "add_header") { OPS_CK(primitive, 1); auto hdr = conv.convert(primitive->operands.at(0)); - auto method = new IR::Member(Util::SourceInfo(), hdr, IR::ID(IR::Type_Header::setValid)); + auto method = new IR::Member(hdr, IR::ID(IR::Type_Header::setValid)); auto args = new IR::Vector(); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "copy_header") { OPS_CK(primitive, 2); @@ -1034,9 +1006,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri return new IR::AssignmentStatement(primitive->srcInfo, left, right); } else if (primitive->name == "drop" || primitive->name == "mark_for_drop") { auto method = new IR::PathExpression(v1model.drop.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, - new IR::Vector()); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "push" || primitive->name == "pop") { OPS_CK(primitive, 2); @@ -1044,11 +1014,10 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto count = conv.convert(primitive->operands.at(1)); auto methodName = primitive->name == "push" ? IR::Type_Stack::push_front : IR::Type_Stack::pop_front; - auto method = new IR::Member(Util::SourceInfo(), hdr, IR::ID(methodName)); + auto method = new IR::Member(hdr, IR::ID(methodName)); auto args = new IR::Vector(); args->push_back(count); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "count") { OPS_CK(primitive, 2); @@ -1064,13 +1033,12 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto newname = counters.get(counter); auto counterref = new IR::PathExpression(newname); auto methodName = v1model.counter.increment.Id(); - auto method = new IR::Member(Util::SourceInfo(), counterref, methodName); + auto method = new IR::Member(counterref, methodName); auto args = new IR::Vector(); - auto arg = new IR::Cast(Util::SourceInfo(), v1model.counter.index_type, + auto arg = new IR::Cast(v1model.counter.index_type, conv.convert(primitive->operands.at(1))); args->push_back(arg); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "modify_field_from_rng") { BUG_CHECK(primitive->operands.size() == 2 || primitive->operands.size() == 3, @@ -1082,9 +1050,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri mask = conv.convert(primitive->operands.at(2)); cstring tmpvar = makeUniqueName("tmp"); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), tmpvar, - IR::Annotations::empty, - v1model.random.resultType, nullptr); + auto decl = new IR::Declaration_Variable(tmpvar, v1model.random.resultType, nullptr); auto args = new IR::Vector(); args->push_back(new IR::PathExpression(tmpvar)); args->push_back(new IR::Constant(primitive->operands.at(1)->srcInfo, @@ -1093,8 +1059,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri args->push_back(new IR::Cast(primitive->operands.at(1)->srcInfo, v1model.random.resultType, new IR::Sub(new IR::Shl(one, logRange), one))); auto random = new IR::PathExpression(v1model.random.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, args); auto call = new IR::MethodCallStatement(primitive->srcInfo, mc); auto components = new IR::IndexedVector(); const IR::Statement* assign; @@ -1102,13 +1067,12 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri assign = sliceAssign(primitive->srcInfo, field, new IR::PathExpression(IR::ID(tmpvar)), mask); } else { - assign = new IR::AssignmentStatement(Util::SourceInfo(), field, - new IR::PathExpression(tmpvar)); + assign = new IR::AssignmentStatement(field, new IR::PathExpression(tmpvar)); } components->push_back(decl); components->push_back(call); components->push_back(assign); - auto block = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, components); + auto block = new IR::BlockStatement(components); return block; } else if (primitive->name == "modify_field_rng_uniform") { BUG_CHECK(primitive->operands.size() == 3, "Expected 3 operands for %1%", primitive); @@ -1122,8 +1086,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri args->push_back(new IR::Cast(primitive->operands.at(1)->srcInfo, v1model.random.resultType, hi)); auto random = new IR::PathExpression(v1model.random.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, args); auto call = new IR::MethodCallStatement(primitive->srcInfo, mc); return call; } else if (primitive->name == "recirculate") { @@ -1134,8 +1097,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto args = new IR::Vector(); args->push_back(right); auto path = new IR::PathExpression(v1model.recirculate.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, path, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, path, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "clone_egress_pkt_to_egress" || primitive->name == "clone_ingress_pkt_to_egress" || @@ -1150,9 +1112,8 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto args = new IR::Vector(); auto enumref = new IR::TypeNameExpression( - Util::SourceInfo(), new IR::Type_Name(new IR::Path(v1model.clone.cloneType.Id()))); - auto kindarg = new IR::Member(Util::SourceInfo(), enumref, kind.Id()); + auto kindarg = new IR::Member(enumref, kind.Id()); args->push_back(kindarg); args->push_back(new IR::Cast(primitive->operands.at(0)->srcInfo, v1model.clone.sessionType, session)); @@ -1164,8 +1125,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto id = primitive->operands.size() == 2 ? v1model.clone.clone3.Id() : v1model.clone.Id(); auto clone = new IR::PathExpression(id); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, clone, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, clone, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "resubmit") { OPS_CK(primitive, 1); @@ -1174,8 +1134,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri if (list != nullptr) args->push_back(list); auto resubmit = new IR::PathExpression(v1model.resubmit.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, resubmit, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, resubmit, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "execute_meter") { OPS_CK(primitive, 3); @@ -1193,15 +1152,14 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto newname = meters.get(meter); auto meterref = new IR::PathExpression(newname); auto methodName = v1model.meter.executeMeter.Id(); - auto method = new IR::Member(Util::SourceInfo(), meterref, methodName); + auto method = new IR::Member(meterref, methodName); auto args = new IR::Vector(); - auto arg = new IR::Cast(Util::SourceInfo(), v1model.meter.index_type, + auto arg = new IR::Cast(v1model.meter.index_type, conv.convert(primitive->operands.at(1))); args->push_back(arg); auto dest = conv.convert(primitive->operands.at(2)); args->push_back(dest); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(primitive->srcInfo, mc); } else if (primitive->name == "modify_field_with_hash_based_offset") { OPS_CK(primitive, 4); @@ -1224,13 +1182,11 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto algorithm = convertHashAlgorithm(flc->algorithm); args->push_back(dest); args->push_back(algorithm); - args->push_back(new IR::Cast(Util::SourceInfo(), ttype, base)); + args->push_back(new IR::Cast(ttype, base)); args->push_back(list); - args->push_back(new IR::Cast(Util::SourceInfo(), - IR::Type_Bits::get(2 * flc->output_width), max)); + args->push_back(new IR::Cast(IR::Type_Bits::get(2 * flc->output_width), max)); auto hash = new IR::PathExpression(v1model.hash.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, hash, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, hash, args); auto result = new IR::MethodCallStatement(primitive->srcInfo, mc); return result; } else if (primitive->name == "modify_field_conditionally") { @@ -1254,11 +1210,10 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri if (list != nullptr) args->push_back(list); auto typeArgs = new IR::Vector(); - auto typeName = new IR::Type_Name(Util::SourceInfo(), new IR::Path(type->name)); + auto typeName = new IR::Type_Name(new IR::Path(type->name)); typeArgs->push_back(typeName); auto random = new IR::PathExpression(v1model.digest_receiver.Id()); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, - typeArgs, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, random, typeArgs, args); auto result = new IR::MethodCallStatement(mc->srcInfo, mc); return result; } else if (primitive->name == "register_read") { @@ -1276,14 +1231,13 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto newname = registers.get(reg); auto registerref = new IR::PathExpression(newname); auto methodName = v1model.registers.read.Id(); - auto method = new IR::Member(Util::SourceInfo(), registerref, methodName); + auto method = new IR::Member(registerref, methodName); auto args = new IR::Vector(); - auto arg = new IR::Cast(Util::SourceInfo(), v1model.registers.index_type, + auto arg = new IR::Cast(v1model.registers.index_type, conv.convert(primitive->operands.at(2))); args->push_back(left); args->push_back(arg); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "register_write") { OPS_CK(primitive, 3); @@ -1304,7 +1258,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto newname = registers.get(reg); auto registerref = new IR::PathExpression(newname); auto methodName = v1model.registers.write.Id(); - auto method = new IR::Member(Util::SourceInfo(), registerref, methodName); + auto method = new IR::Member(registerref, methodName); auto args = new IR::Vector(); auto arg0 = new IR::Cast(primitive->operands.at(1)->srcInfo, v1model.registers.index_type, conv.convert(primitive->operands.at(1))); @@ -1312,8 +1266,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri conv.convert(primitive->operands.at(2))); args->push_back(arg0); args->push_back(arg1); - auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "truncate") { OPS_CK(primitive, 1); @@ -1323,8 +1276,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto args = new IR::Vector(); 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); + auto mc = new IR::MethodCallExpression(primitive->srcInfo, method, args); return new IR::MethodCallStatement(mc->srcInfo, mc); } else if (primitive->name == "exit") { OPS_CK(primitive, 0); @@ -1349,8 +1301,7 @@ const IR::Statement* ProgramStructure::convertPrimitive(const IR::Primitive* pri auto e = conv.convert(a); args->push_back(e); } - auto call = new IR::MethodCallExpression(primitive->srcInfo, act, - emptyTypeArguments, args); + auto call = new IR::MethodCallExpression(primitive->srcInfo, act, args); auto stat = new IR::MethodCallStatement(primitive->srcInfo, call); return stat; } @@ -1381,8 +1332,7 @@ ProgramStructure::convertAction(const IR::ActionFunction* action, cstring newNam auto path = new IR::Path(type->to()->name); type = new IR::Type_Name(path); } - auto param = new IR::Parameter(p->srcInfo, p->name, IR::Annotations::empty, - direction, type); + auto param = new IR::Parameter(p->srcInfo, p->name, direction, type); LOG2(" " << p << " is " << direction << " " << param); params->push_back(param); } @@ -1392,12 +1342,12 @@ ProgramStructure::convertAction(const IR::ActionFunction* action, cstring newNam auto decl = get(meterMap, meterToAccess); CHECK_NULL(decl); auto extObj = new IR::PathExpression(decl->name); - auto method = new IR::Member(Util::SourceInfo(), extObj, v1model.directMeter.read.Id()); + auto method = new IR::Member(extObj, v1model.directMeter.read.Id()); auto args = new IR::Vector(); auto arg = conv.convert(meterToAccess->result); if (arg != nullptr) args->push_back(arg); - auto mc = new IR::MethodCallExpression(method, emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(method, args); auto stat = new IR::MethodCallStatement(mc->srcInfo, mc); body->push_back(stat); } @@ -1408,7 +1358,7 @@ ProgramStructure::convertAction(const IR::ActionFunction* action, cstring newNam auto extObj = new IR::PathExpression(decl->name); auto method = new IR::Member(extObj, v1model.directCounter.count.Id()); auto args = new IR::Vector(); - auto mc = new IR::MethodCallExpression(method, emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(method, args); auto stat = new IR::MethodCallStatement(mc->srcInfo, mc); body->push_back(stat); } @@ -1422,7 +1372,7 @@ ProgramStructure::convertAction(const IR::ActionFunction* action, cstring newNam auto annos = addNameAnnotation(cstring(".") + action->name, action->annotations); auto result = new IR::P4Action( action->srcInfo, newName, annos, new IR::ParameterList(params), - new IR::BlockStatement(body->srcInfo, IR::Annotations::empty, body)); + new IR::BlockStatement(body->srcInfo, body)); return result; } @@ -1430,30 +1380,28 @@ const IR::Type_Control* ProgramStructure::controlType(IR::ID name) { auto params = new IR::IndexedVector(); auto headpath = new IR::Path(v1model.headersType.Id()); - auto headtype = new IR::Type_Name(Util::SourceInfo(), headpath); + auto headtype = new IR::Type_Name(headpath); // we can use ingress, since all control blocks have the same signature - auto headers = new IR::Parameter(Util::SourceInfo(), v1model.ingress.headersParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, headtype); + auto headers = new IR::Parameter(v1model.ingress.headersParam.Id(), + IR::Direction::InOut, headtype); params->push_back(headers); conversionContext.header = paramReference(headers); auto metapath = new IR::Path(v1model.metadataType.Id()); - auto metatype = new IR::Type_Name(Util::SourceInfo(), metapath); - auto meta = new IR::Parameter(Util::SourceInfo(), v1model.ingress.metadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, metatype); + auto metatype = new IR::Type_Name(metapath); + auto meta = new IR::Parameter(v1model.ingress.metadataParam.Id(), + IR::Direction::InOut, metatype); params->push_back(meta); conversionContext.userMetadata = paramReference(meta); auto stdMetaPath = new IR::Path(v1model.standardMetadataType.Id()); - auto stdMetaType = new IR::Type_Name(Util::SourceInfo(), stdMetaPath); - auto stdmeta = new IR::Parameter(Util::SourceInfo(), v1model.ingress.standardMetadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, stdMetaType); + auto stdMetaType = new IR::Type_Name(stdMetaPath); + auto stdmeta = new IR::Parameter(v1model.ingress.standardMetadataParam.Id(), + IR::Direction::InOut, stdMetaType); params->push_back(stdmeta); conversionContext.standardMetadata = paramReference(stdmeta); - auto type = new IR::Type_Control(Util::SourceInfo(), name, - IR::Annotations::empty, new IR::TypeParameters(), - new IR::ParameterList(params)); + auto type = new IR::Type_Control(name, new IR::TypeParameters(), new IR::ParameterList(params)); return type; } @@ -1480,9 +1428,8 @@ const IR::Expression* ProgramStructure::counterType(const IR::CounterOrMeter* cm else BUG("%1%: unsupported", cm); } - auto enumref = new IR::TypeNameExpression(Util::SourceInfo(), - new IR::Type_Name(new IR::Path(enumName))); - return new IR::Member(Util::SourceInfo(), enumref, kind); + auto enumref = new IR::TypeNameExpression(new IR::Type_Name(new IR::Path(enumName))); + return new IR::Member(enumref, kind); } const IR::Declaration_Instance* @@ -1500,12 +1447,11 @@ ProgramStructure::convert(const IR::Register* reg, cstring newName) { auto type = new IR::Type_Name(typepath); auto typeargs = new IR::Vector(); typeargs->push_back(regElementType); - auto spectype = new IR::Type_Specialized(Util::SourceInfo(), type, typeargs); + auto spectype = new IR::Type_Specialized(type, typeargs); auto args = new IR::Vector(); args->push_back(new IR::Constant(v1model.registers.size_type, reg->instance_count)); auto annos = addNameAnnotation(reg->name, reg->annotations); - auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), newName, annos, spectype, args, nullptr); + auto decl = new IR::Declaration_Instance(newName, annos, spectype, args, nullptr); return decl; } @@ -1531,7 +1477,7 @@ ProgramStructure::convert(const IR::CounterOrMeter* cm, cstring newName) { annos = annos->addAnnotation("max_width", new IR::Constant(c->max_width)); } auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), newName, annos, type, args, nullptr); + newName, annos, type, args, nullptr); return decl; } @@ -1562,13 +1508,12 @@ ProgramStructure::convertDirectMeter(const IR::Meter* m, cstring newName) { auto type = new IR::Type_Name(typepath); auto vec = new IR::Vector(); vec->push_back(outputType); - auto specType = new IR::Type_Specialized(Util::SourceInfo(), type, vec); + auto specType = new IR::Type_Specialized(type, vec); auto args = new IR::Vector(); auto kindarg = counterType(m); args->push_back(kindarg); auto annos = addNameAnnotation(m->name, m->annotations); - auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), newName, annos, specType, args, nullptr); + auto decl = new IR::Declaration_Instance(newName, annos, specType, args, nullptr); return decl; } @@ -1583,8 +1528,7 @@ ProgramStructure::convertDirectCounter(const IR::Counter* c, cstring newName) { auto kindarg = counterType(c); args->push_back(kindarg); auto annos = addNameAnnotation(c->name, c->annotations); - auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), newName, annos, type, args, nullptr); + auto decl = new IR::Declaration_Instance(newName, annos, type, args, nullptr); return decl; } @@ -1726,8 +1670,7 @@ ProgramStructure::convertControl(const IR::V1Control* control, cstring newName) auto typepath = new IR::Path(IR::ID(newname)); auto type = new IR::Type_Name(typepath); auto annos = addNameAnnotation(cc); - auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), IR::ID(iname), annos, type, + auto decl = new IR::Declaration_Instance(IR::ID(iname), annos, type, new IR::Vector(), nullptr); stateful->push_back(decl); } @@ -1740,9 +1683,8 @@ ProgramStructure::convertControl(const IR::V1Control* control, cstring newName) components->push_back(s); } - auto body = new IR::BlockStatement(Util::SourceInfo(), control->annotations, components); - auto result = new IR::P4Control(Util::SourceInfo(), name, type, - new IR::ParameterList(), stateful, body); + auto body = new IR::BlockStatement(control->annotations, components); + auto result = new IR::P4Control(name, type, stateful, body); conversionContext.clear(); return result; } @@ -1774,10 +1716,8 @@ void ProgramStructure::createControls() { auto type = controlType(name); auto stateful = new IR::IndexedVector(); auto components = new IR::IndexedVector(); - auto body = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, components); - auto egressControl = new IR::P4Control(Util::SourceInfo(), name, type, - new IR::ParameterList(), - stateful, body); + auto body = new IR::BlockStatement(components); + auto egressControl = new IR::P4Control(name, type, stateful, body); declarations->push_back(egressControl); } } @@ -1792,42 +1732,35 @@ void ProgramStructure::createMain() { auto parserPath = new IR::Path(v1model.parser.Id()); auto parserType = new IR::Type_Name(parserPath); - auto parserConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), parserType, emptyArgs); + auto parserConstruct = new IR::ConstructorCallExpression(parserType, emptyArgs); args->push_back(parserConstruct); auto verifyPath = new IR::Path(verifyChecksums->name); auto verifyType = new IR::Type_Name(verifyPath); - auto verifyConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), verifyType, emptyArgs); + auto verifyConstruct = new IR::ConstructorCallExpression(verifyType, emptyArgs); args->push_back(verifyConstruct); auto ingressPath = new IR::Path(ingressReference); auto ingressType = new IR::Type_Name(ingressPath); - auto ingressConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), ingressType, emptyArgs); + auto ingressConstruct = new IR::ConstructorCallExpression(ingressType, emptyArgs); args->push_back(ingressConstruct); auto egressPath = new IR::Path(v1model.egress.Id()); auto egressType = new IR::Type_Name(egressPath); - auto egressConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), egressType, emptyArgs); + auto egressConstruct = new IR::ConstructorCallExpression(egressType, emptyArgs); args->push_back(egressConstruct); auto updatePath = new IR::Path(updateChecksums->name); auto updateType = new IR::Type_Name(updatePath); - auto updateConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), updateType, emptyArgs); + auto updateConstruct = new IR::ConstructorCallExpression(updateType, emptyArgs); args->push_back(updateConstruct); auto deparserPath = new IR::Path(deparser->name); auto deparserType = new IR::Type_Name(deparserPath); - auto deparserConstruct = new IR::ConstructorCallExpression( - Util::SourceInfo(), deparserType, emptyArgs); + auto deparserConstruct = new IR::ConstructorCallExpression(deparserType, emptyArgs); args->push_back(deparserConstruct); - auto result = new IR::Declaration_Instance(Util::SourceInfo(), name, IR::Annotations::empty, - type, args, nullptr); + auto result = new IR::Declaration_Instance(name, type, args, nullptr); declarations->push_back(result); } @@ -1886,23 +1819,22 @@ void ProgramStructure::createChecksumVerifications() { // verify auto params = new IR::IndexedVector(); auto headpath = new IR::Path(v1model.headersType.Id()); - auto headtype = new IR::Type_Name(Util::SourceInfo(), headpath); - auto headers = new IR::Parameter(Util::SourceInfo(), v1model.verify.headersParam.Id(), - IR::Annotations::empty, IR::Direction::In, headtype); + auto headtype = new IR::Type_Name(headpath); + auto headers = new IR::Parameter(v1model.verify.headersParam.Id(), + IR::Direction::In, headtype); params->push_back(headers); conversionContext.header = paramReference(headers); auto metapath = new IR::Path(v1model.metadataType.Id()); - auto metatype = new IR::Type_Name(Util::SourceInfo(), metapath); - auto meta = new IR::Parameter(Util::SourceInfo(), v1model.parser.metadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, metatype); + auto metatype = new IR::Type_Name(metapath); + auto meta = new IR::Parameter(v1model.parser.metadataParam.Id(), + IR::Direction::InOut, metatype); params->push_back(meta); conversionContext.userMetadata = paramReference(meta); conversionContext.standardMetadata = nullptr; - auto type = new IR::Type_Control(Util::SourceInfo(), v1model.verify.Id(), - IR::Annotations::empty, + auto type = new IR::Type_Control(v1model.verify.Id(), new IR::TypeParameters(), new IR::ParameterList(params)); std::map map; @@ -1941,30 +1873,26 @@ void ProgramStructure::createChecksumVerifications() { auto le = conv.convert(fl); auto extObj = new IR::PathExpression(inst->name); // The only method we currently know about is v1model.ck16.get - auto method = new IR::Member(Util::SourceInfo(), extObj, v1model.ck16.get.Id()); + auto method = new IR::Member(extObj, v1model.ck16.get.Id()); auto args = new IR::Vector(); args->push_back(le); - auto mc = new IR::MethodCallExpression(Util::SourceInfo(), method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(method, args); const IR::Expression* cond = new IR::Equ(uov.srcInfo, dest, mc); if (uov.cond != nullptr) { auto cond2 = conv.convert(uov.cond); // cond2 is evaluated first - cond = new IR::LAnd(Util::SourceInfo(), cond2, cond); + cond = new IR::LAnd(cond2, cond); } auto dropmethod = new IR::PathExpression(v1model.drop.Id()); - auto dropmc = new IR::MethodCallExpression(Util::SourceInfo(), dropmethod, - emptyTypeArguments, - new IR::Vector()); + auto dropmc = new IR::MethodCallExpression(dropmethod); auto drop = new IR::MethodCallStatement(mc->srcInfo, dropmc); - auto ifstate = new IR::IfStatement(Util::SourceInfo(), cond, drop, nullptr); + auto ifstate = new IR::IfStatement(cond, drop, nullptr); components->push_back(ifstate); LOG1("Converted " << flc); } } - auto body = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, components); - verifyChecksums = new IR::P4Control(Util::SourceInfo(), v1model.verify.Id(), type, - new IR::ParameterList(), stateful, body); + auto body = new IR::BlockStatement(components); + verifyChecksums = new IR::P4Control(v1model.verify.Id(), type, stateful, body); declarations->push_back(verifyChecksums); conversionContext.clear(); } @@ -1973,23 +1901,22 @@ void ProgramStructure::createChecksumUpdates() { ExpressionConverter conv(this); auto params = new IR::IndexedVector(); auto headpath = new IR::Path(v1model.headersType.Id()); - auto headtype = new IR::Type_Name(Util::SourceInfo(), headpath); - auto headers = new IR::Parameter(Util::SourceInfo(), v1model.update.headersParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, headtype); + auto headtype = new IR::Type_Name(headpath); + auto headers = new IR::Parameter(v1model.update.headersParam.Id(), + IR::Direction::InOut, headtype); params->push_back(headers); conversionContext.header = paramReference(headers); auto metapath = new IR::Path(v1model.metadataType.Id()); - auto metatype = new IR::Type_Name(Util::SourceInfo(), metapath); - auto meta = new IR::Parameter(Util::SourceInfo(), v1model.parser.metadataParam.Id(), - IR::Annotations::empty, IR::Direction::InOut, metatype); + auto metatype = new IR::Type_Name(metapath); + auto meta = new IR::Parameter(v1model.parser.metadataParam.Id(), + IR::Direction::InOut, metatype); params->push_back(meta); conversionContext.userMetadata = paramReference(meta); conversionContext.standardMetadata = nullptr; - auto type = new IR::Type_Control(Util::SourceInfo(), v1model.update.Id(), - IR::Annotations::empty, + auto type = new IR::Type_Control(v1model.update.Id(), new IR::TypeParameters(), new IR::ParameterList(params)); auto stateful = new IR::IndexedVector(); @@ -2029,23 +1956,21 @@ void ProgramStructure::createChecksumUpdates() { auto extObj = new IR::PathExpression(inst->name); // The only method we currently know about is v1model.ck16.get - auto method = new IR::Member(Util::SourceInfo(), extObj, v1model.ck16.get.Id()); + auto method = new IR::Member(extObj, v1model.ck16.get.Id()); auto args = new IR::Vector(); args->push_back(le); - auto mc = new IR::MethodCallExpression(Util::SourceInfo(), method, - emptyTypeArguments, args); + auto mc = new IR::MethodCallExpression(method, args); const IR::Statement* set = new IR::AssignmentStatement(flc->srcInfo, dest, mc); if (uov.cond != nullptr) { auto cond = conv.convert(uov.cond); - set = new IR::IfStatement(Util::SourceInfo(), cond, set, nullptr); + set = new IR::IfStatement(cond, set, nullptr); } components->push_back(set); LOG1("Converted " << flc); } } - auto body = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, components); - updateChecksums = new IR::P4Control(Util::SourceInfo(), v1model.update.Id(), type, - new IR::ParameterList(), stateful, body); + auto body = new IR::BlockStatement(components); + updateChecksums = new IR::P4Control(v1model.update.Id(), type, stateful, body); declarations->push_back(updateChecksums); conversionContext.clear(); } diff --git a/frontends/p4/moveDeclarations.cpp b/frontends/p4/moveDeclarations.cpp index 1b05eaeec8c..b65d0524578 100644 --- a/frontends/p4/moveDeclarations.cpp +++ b/frontends/p4/moveDeclarations.cpp @@ -128,8 +128,7 @@ const IR::Node* MoveInitializers::postorder(IR::P4Control* control) { if (toMove->empty()) return control; toMove->append(*control->body->components); - auto newBody = new IR::BlockStatement( - Util::SourceInfo(), control->body->annotations, toMove); + auto newBody = new IR::BlockStatement(control->body->annotations, toMove); control->body = newBody; toMove = new IR::IndexedVector(); return control; diff --git a/frontends/p4/p4-parse.ypp b/frontends/p4/p4-parse.ypp index 5a2c70ab46a..0120657fbaa 100644 --- a/frontends/p4/p4-parse.ypp +++ b/frontends/p4/p4-parse.ypp @@ -322,11 +322,10 @@ packageTypeDeclaration instantiation : annotations typeRef '(' argumentList ')' name ';' { $$ = new IR::Declaration_Instance(@6, *$6, new IR::Annotations(*$1), - $2, $4, nullptr); + $2, $4); structure.declareObject(*$6); } | typeRef '(' argumentList ')' name ';' - { $$ = new IR::Declaration_Instance(@5, *$5, IR::Annotations::empty, - $1, $3, nullptr); + { $$ = new IR::Declaration_Instance(@5, *$5, $1, $3); structure.declareObject(*$5); } /* experimental */ | annotations typeRef '(' argumentList ')' name '=' objInitializer ';' @@ -335,8 +334,7 @@ instantiation structure.declareObject(*$6); } /* experimental */ | typeRef '(' argumentList ')' name '=' objInitializer ';' - { $$ = new IR::Declaration_Instance(@5, *$5, IR::Annotations::empty, - $1, $3, $7); + { $$ = new IR::Declaration_Instance(@5, *$5, $1, $3, $7); structure.declareObject(*$5); } ; @@ -344,7 +342,7 @@ instantiation objInitializer : '{' { structure.pushNamespace(@1, false); } objDeclarations '}' { structure.pop(); - $$ = new IR::BlockStatement(@1+@4, IR::Annotations::empty, $3); } + $$ = new IR::BlockStatement(@1+@4, $3); } ; objDeclarations @@ -677,11 +675,11 @@ typedefDeclaration : annotations TYPEDEF typeRef name { structure.declareType(*$4); $$ = new IR::Type_Typedef(@4, *$4, new IR::Annotations(*$1), $3); } | TYPEDEF typeRef name { structure.declareType(*$3); - $$ = new IR::Type_Typedef(@3, *$3, IR::Annotations::empty, $2); } + $$ = new IR::Type_Typedef(@3, *$3, $2); } | annotations TYPEDEF derivedTypeDeclaration name { structure.declareType(*$4); $$ = new IR::Type_Typedef(@4, *$4, new IR::Annotations(*$1), $3); } | TYPEDEF derivedTypeDeclaration name { structure.declareType(*$3); - $$ = new IR::Type_Typedef(@3, *$3, IR::Annotations::empty, $2); } + $$ = new IR::Type_Typedef(@3, *$3, $2); } ; /*************************** STATEMENTS *************************/ @@ -784,11 +782,11 @@ tableProperty : KEY '=' '{' keyElementList '}' { auto v = new IR::Key(@4, $4); auto id = IR::ID(@1, "key"); $$ = new IR::Property( - @1 + @5, id, IR::Annotations::empty, v, false); } + @1 + @5, id, v, false); } | ACTIONS '=' '{' actionList '}' { auto v = new IR::ActionList(@4, $4); auto id = IR::ID(@1, "actions"); $$ = new IR::Property( - @1 + @5, id, IR::Annotations::empty, v, false); } + @1 + @5, id, v, false); } | optAnnotations optCONST ENTRIES '=' '{' entriesList '}' { auto l = new IR::EntriesList(@3, $6); auto id = IR::ID(@3+@7, "entries"); @@ -830,9 +828,8 @@ entry : keysetExpression ':' actionBinding optAnnotations ';' { assert($3->is()); - if ($1->is()) - $$ = new IR::Entry(@1+@4, $4, - $1->to(), $3); + if (auto l = $1->to()) + $$ = new IR::Entry(@1+@4, $4, l, $3); else { // if not a tuple, make it a list of 1 auto le = new IR::Vector(); le->push_back($1); @@ -871,8 +868,7 @@ variableDeclaration $$ = new IR::Declaration_Variable(@1+@4, *$3, ann, $2, $4); structure.declareObject(*$3); } | typeRef name optInitializer ';' - { $$ = new IR::Declaration_Variable( - @1+@4, *$2, IR::Annotations::empty, $1, $3); + { $$ = new IR::Declaration_Variable(@1+@4, *$2, $1, $3); structure.declareObject(*$2); } ; diff --git a/frontends/p4/parserControlFlow.cpp b/frontends/p4/parserControlFlow.cpp index f17d6b2d249..af7bbed350e 100644 --- a/frontends/p4/parserControlFlow.cpp +++ b/frontends/p4/parserControlFlow.cpp @@ -84,8 +84,7 @@ const IR::Node* DoRemoveParserControlFlow::postorder(IR::ParserState* state) { cstring trueName = refMap->newName(state->name.name + "_true"); auto trueComponents = new IR::IndexedVector(); trueComponents->push_back(ifstat->ifTrue); - auto trueState = new IR::ParserState( - Util::SourceInfo(), trueName, IR::Annotations::empty, trueComponents, + auto trueState = new IR::ParserState(trueName, trueComponents, new IR::PathExpression(IR::ID(joinName, nullptr))); states->push_back(trueState); @@ -95,8 +94,7 @@ const IR::Node* DoRemoveParserControlFlow::postorder(IR::ParserState* state) { falseName = refMap->newName(state->name.name + "_false"); auto falseComponents = new IR::IndexedVector(); falseComponents->push_back(ifstat->ifFalse); - auto falseState = new IR::ParserState( - Util::SourceInfo(), falseName, IR::Annotations::empty, falseComponents, + auto falseState = new IR::ParserState(falseName, falseComponents, new IR::PathExpression(IR::ID(joinName, nullptr))); states->push_back(falseState); } @@ -104,22 +102,20 @@ const IR::Node* DoRemoveParserControlFlow::postorder(IR::ParserState* state) { // left-over auto vec = new IR::Vector(); vec->push_back(ifstat->condition); - auto trueCase = new IR::SelectCase( - Util::SourceInfo(), new IR::BoolLiteral(true), + auto trueCase = new IR::SelectCase(new IR::BoolLiteral(true), new IR::PathExpression(IR::ID(trueName, nullptr))); auto falseCase = new IR::SelectCase( - Util::SourceInfo(), new IR::BoolLiteral(false), + new IR::BoolLiteral(false), new IR::PathExpression(IR::ID(falseName, nullptr))); auto cases = new IR::Vector(); cases->push_back(trueCase); cases->push_back(falseCase); currentState->selectExpression = new IR::SelectExpression( - Util::SourceInfo(), new IR::ListExpression(vec), std::move(*cases)); + new IR::ListExpression(vec), std::move(*cases)); currentState->components = currentComponents; currentComponents = new IR::IndexedVector(); - currentState = new IR::ParserState( - Util::SourceInfo(), joinName, IR::Annotations::empty, + currentState = new IR::ParserState(joinName, currentComponents, origSelect); // may be overriten } else { currentComponents->push_back(c); diff --git a/frontends/p4/resetHeaders.cpp b/frontends/p4/resetHeaders.cpp index 5865b84e17d..212c27faba3 100644 --- a/frontends/p4/resetHeaders.cpp +++ b/frontends/p4/resetHeaders.cpp @@ -24,14 +24,13 @@ void DoResetHeaders::generateResets(const TypeMap* typeMap, const IR::Type* type auto sl = type->to(); for (auto f : *sl->fields) { auto ftype = typeMap->getType(f, true); - auto member = new IR::Member(Util::SourceInfo(), expr, f->name); + auto member = new IR::Member(expr, f->name); generateResets(typeMap, ftype, member, resets); } } else if (type->is()) { auto method = new IR::Member(expr->srcInfo, expr, IR::Type_Header::setInvalid); auto args = new IR::Vector(); - auto mc = new IR::MethodCallExpression(expr->srcInfo, method, - new IR::Vector(), args); + auto mc = new IR::MethodCallExpression(expr->srcInfo, method, args); auto stat = new IR::MethodCallStatement(mc->srcInfo, mc); resets->push_back(stat); } else if (type->is()) { @@ -42,7 +41,7 @@ void DoResetHeaders::generateResets(const TypeMap* typeMap, const IR::Type* type } for (unsigned i = 0; i < tstack->getSize(); i++) { auto index = new IR::Constant(i); - auto elem = new IR::ArrayIndex(Util::SourceInfo(), expr, index); + auto elem = new IR::ArrayIndex(expr, index); generateResets(typeMap, tstack->elementType, elem, resets); } } diff --git a/frontends/p4/sideEffects.cpp b/frontends/p4/sideEffects.cpp index f7dfbfca43c..07ae4145d0c 100644 --- a/frontends/p4/sideEffects.cpp +++ b/frontends/p4/sideEffects.cpp @@ -45,8 +45,7 @@ struct EvaluationOrder { cstring createTemporary(const IR::Type* type) { auto tmp = refMap->newName("tmp"); - auto decl = new IR::Declaration_Variable( - Util::SourceInfo(), IR::ID(tmp, nullptr), IR::Annotations::empty, type, nullptr); + auto decl = new IR::Declaration_Variable(IR::ID(tmp, nullptr), type); temporaries->push_back(decl); return tmp; } @@ -54,7 +53,7 @@ struct EvaluationOrder { const IR::Expression* addAssignment( cstring varName, const IR::Expression* expression) { auto left = new IR::PathExpression(IR::ID(varName, nullptr)); - auto stat = new IR::AssignmentStatement(Util::SourceInfo(), left, expression); + auto stat = new IR::AssignmentStatement(left, expression); statements->push_back(stat); auto result = left->clone(); return result; @@ -140,7 +139,7 @@ class DismantleExpression : public Transform { BUG_CHECK(type->is(), "%1%: not boolean", type); auto tmp = result->createTemporary(type); auto path = new IR::PathExpression(IR::ID(tmp, nullptr)); - auto stat = new IR::AssignmentStatement(Util::SourceInfo(), path, result->final); + auto stat = new IR::AssignmentStatement(path, result->final); result->statements->push_back(stat); result->final = path->clone(); typeMap->setType(result->final, type); @@ -219,10 +218,10 @@ class DismantleExpression : public Transform { // tmp = simplify(e2); bool land = expression->is(); - auto constant = new IR::BoolLiteral(Util::SourceInfo(), !land); + auto constant = new IR::BoolLiteral(!land); auto tmp = result->createTemporary(type); auto ifTrue = new IR::AssignmentStatement( - Util::SourceInfo(), new IR::PathExpression(IR::ID(tmp, nullptr)), constant); + new IR::PathExpression(IR::ID(tmp, nullptr)), constant); auto ifFalse = new IR::IndexedVector(); auto save = result->statements; @@ -231,12 +230,11 @@ class DismantleExpression : public Transform { auto path = result->addAssignment(tmp, result->final); result->statements = save; if (land) { - cond = new IR::LNot(Util::SourceInfo(), cond); + cond = new IR::LNot(cond); typeMap->setType(cond, type); } - auto block = new IR::BlockStatement(Util::SourceInfo(), - IR::Annotations::empty, ifFalse); - auto ifStatement = new IR::IfStatement(Util::SourceInfo(), cond, ifTrue, block); + auto block = new IR::BlockStatement(ifFalse); + auto ifStatement = new IR::IfStatement(cond, ifTrue, block); result->statements->push_back(ifStatement); result->final = path->clone(); } @@ -267,9 +265,7 @@ class DismantleExpression : public Transform { result->statements = save; auto ifStatement = new IR::IfStatement( - Util::SourceInfo(), e0, - new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, ifTrue), - new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, ifFalse)); + e0, new IR::BlockStatement(ifTrue), new IR::BlockStatement(ifFalse)); result->statements->push_back(ifStatement); result->final = path->clone(); typeMap->setType(result->final, type); @@ -405,14 +401,11 @@ class DismantleExpression : public Transform { // declare temporary variable auto tmp = refMap->newName("tmp"); argValue = new IR::PathExpression(IR::ID(tmp, nullptr)); - auto decl = new IR::Declaration_Variable( - Util::SourceInfo(), IR::ID(tmp, nullptr), - IR::Annotations::empty, paramtype, nullptr); + auto decl = new IR::Declaration_Variable(IR::ID(tmp, nullptr), paramtype); result->temporaries->push_back(decl); if (p->direction != IR::Direction::Out) { auto clone = argValue->clone(); - auto stat = new IR::AssignmentStatement( - Util::SourceInfo(), clone, newarg); + auto stat = new IR::AssignmentStatement(clone, newarg); LOG3(clone << " = " << newarg); result->statements->push_back(stat); typeMap->setType(clone, paramtype); @@ -423,7 +416,7 @@ class DismantleExpression : public Transform { } if (leftValue && useTemp) { auto assign = new IR::AssignmentStatement( - Util::SourceInfo(), cloner.clone(newarg), + cloner.clone(newarg), cloner.clone(argValue)); copyBack->push_back(assign); LOG3("Will copy out value " << dbp(assign)); @@ -455,13 +448,10 @@ class DismantleExpression : public Transform { !tbl_apply && // not a table.apply call !resultNotUsed) { // result of call is not used auto tmp = refMap->newName("tmp"); - auto decl = new IR::Declaration_Variable( - Util::SourceInfo(), IR::ID(tmp, nullptr), IR::Annotations::empty, - type, nullptr); + auto decl = new IR::Declaration_Variable(IR::ID(tmp, nullptr), type); result->temporaries->push_back(decl); auto left = new IR::PathExpression(IR::ID(tmp, nullptr)); - auto stat = new IR::AssignmentStatement( - Util::SourceInfo(), left, simplified); + auto stat = new IR::AssignmentStatement(left, simplified); result->statements->push_back(stat); result->final = left->clone(); typeMap->setType(result->final, type); @@ -507,8 +497,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::Function* function) { locals->push_back(a); for (auto s : *function->body->components) locals->push_back(s); - function->body = new IR::BlockStatement( - function->body->srcInfo, IR::Annotations::empty, locals); + function->body = new IR::BlockStatement(function->body->srcInfo, locals); toInsert.clear(); return function; } @@ -541,7 +530,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::P4Action* action) { locals->push_back(a); for (auto s : *action->body->components) locals->push_back(s); - action->body = new IR::BlockStatement(action->body->srcInfo, IR::Annotations::empty, locals); + action->body = new IR::BlockStatement(action->body->srcInfo, locals); toInsert.clear(); return action; } @@ -572,8 +561,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::AssignmentStatement* statem auto right = parts->final; CHECK_NULL(right); parts->statements->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, parts->statements); + auto block = new IR::BlockStatement(parts->statements); return block; } @@ -584,8 +572,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::MethodCallStatement* statem if (parts->simple()) return statement; toInsert.append(*parts->temporaries); - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, parts->statements); + auto block = new IR::BlockStatement(parts->statements); return block; } @@ -600,8 +587,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::ReturnStatement* statement) toInsert.append(*parts->temporaries); auto expr = parts->final; parts->statements->push_back(new IR::ReturnStatement(statement->srcInfo, expr)); - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, parts->statements); + auto block = new IR::BlockStatement(parts->statements); return block; } @@ -615,8 +601,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::IfStatement* statement) { auto expr = parts->final; parts->statements->push_back(new IR::IfStatement(statement->srcInfo, expr, statement->ifTrue, statement->ifFalse)); - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, parts->statements); + auto block = new IR::BlockStatement(parts->statements); return block; } @@ -630,8 +615,7 @@ const IR::Node* DoSimplifyExpressions::postorder(IR::SwitchStatement* statement) auto expr = parts->final; parts->statements->push_back( new IR::SwitchStatement(statement->srcInfo, expr, std::move(statement->cases))); - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, parts->statements); + auto block = new IR::BlockStatement(parts->statements); return block; } diff --git a/frontends/p4/specialize.cpp b/frontends/p4/specialize.cpp index 333ab639a24..8614ae0bfcb 100644 --- a/frontends/p4/specialize.cpp +++ b/frontends/p4/specialize.cpp @@ -66,8 +66,8 @@ const IR::Expression* SpecializationMap::convertArgument( auto cce = arg->to(); cstring nName = refMap->newName("inst"); auto decl = new IR::Declaration_Instance( - Util::SourceInfo(), IR::ID(nName, nullptr), IR::Annotations::empty, - cce->constructedType, cce->arguments, nullptr); + IR::ID(nName, nullptr), + cce->constructedType, cce->arguments); spec->declarations->push_back(decl); auto path = new IR::PathExpression(IR::ID(nName, nullptr)); return path; diff --git a/frontends/p4/typeChecking/typeChecker.cpp b/frontends/p4/typeChecking/typeChecker.cpp index 2e4f2fd51bb..6d9b2b9b198 100644 --- a/frontends/p4/typeChecking/typeChecker.cpp +++ b/frontends/p4/typeChecking/typeChecker.cpp @@ -540,7 +540,7 @@ const IR::Node* TypeInference::postorder(IR::Declaration_MatchKind* decl) { const IR::Node* TypeInference::postorder(IR::P4Table* table) { if (done()) return table; - auto type = new IR::Type_Table(Util::SourceInfo(), table); + auto type = new IR::Type_Table(table); setType(getOriginal(), type); setType(table, type); return table; @@ -551,8 +551,7 @@ const IR::Node* TypeInference::postorder(IR::P4Action* action) { auto pl = canonicalizeParameters(action->parameters); if (pl == nullptr) return action; - auto type = new IR::Type_Action(Util::SourceInfo(), new IR::TypeParameters(), - nullptr, pl); + auto type = new IR::Type_Action(new IR::TypeParameters(), nullptr, pl); bool foundDirectionless = false; for (auto p : *action->parameters->parameters) { @@ -882,7 +881,7 @@ TypeInference::containerInstantiation( auto argInfo = new IR::ArgumentInfo(arg->srcInfo, arg, true, argType); args->push_back(argInfo); } - auto rettype = new IR::Type_Var(Util::SourceInfo(), IR::ID(refMap->newName("R"), nullptr)); + auto rettype = new IR::Type_Var(IR::ID(refMap->newName("R"))); // There are never type arguments at this point; if they exist, they have been folded // into the constructor by type specialization. auto callType = new IR::Type_MethodCall(node->srcInfo, @@ -1298,8 +1297,7 @@ const IR::Node* TypeInference::postorder(IR::Concat* expression) { } auto bl = ltype->to(); auto br = rtype->to(); - const IR::Type* resultType = IR::Type_Bits::get(Util::SourceInfo(), - bl->size + br->size, bl->isSigned); + const IR::Type* resultType = IR::Type_Bits::get(bl->size + br->size, bl->isSigned); resultType = canonicalize(resultType); if (resultType != nullptr) { setType(getOriginal(), resultType); @@ -1328,7 +1326,7 @@ const IR::Node* TypeInference::postorder(IR::Key* key) { } vec->push_back(kt); } - auto keyTuple = new IR::Type_Tuple(Util::SourceInfo(), vec); + auto keyTuple = new IR::Type_Tuple(vec); LOG2("Setting key type to " << dbp(keyTuple)); setType(key, keyTuple); // installing also for the original because we cannot tell which one will survive in the ir @@ -2111,9 +2109,7 @@ const IR::Node* TypeInference::postorder(IR::Member* expression) { if (type->is()) { if (member == IR::Type_Header::isValid) { // Built-in method - auto type = new IR::Type_Method( - Util::SourceInfo(), new IR::TypeParameters(), - IR::Type_Boolean::get(), new IR::ParameterList()); + auto type = new IR::Type_Method(IR::Type_Boolean::get(), new IR::ParameterList()); auto ctype = canonicalize(type); if (ctype == nullptr) return expression; @@ -2126,9 +2122,8 @@ const IR::Node* TypeInference::postorder(IR::Member* expression) { ::error("%1%: must be applied to a left-value", expression); // Built-in method auto params = new IR::IndexedVector(); - auto type = new IR::Type_Method( - Util::SourceInfo(), new IR::TypeParameters(), IR::Type_Void::get(), - new IR::ParameterList(Util::SourceInfo(), params)); + auto type = new IR::Type_Method(IR::Type_Void::get(), + new IR::ParameterList(params)); auto ctype = canonicalize(type); if (ctype == nullptr) return expression; @@ -2212,14 +2207,11 @@ const IR::Node* TypeInference::postorder(IR::Member* expression) { if (!isLeftValue(expression->expr)) ::error("%1%: must be applied to a left-value", expression); auto params = new IR::IndexedVector(); - auto param = new IR::Parameter(Util::SourceInfo(), IR::ID("count", nullptr), - IR::Annotations::empty, IR::Direction::In, + auto param = new IR::Parameter(IR::ID("count", nullptr), IR::Direction::In, new IR::Type_InfInt()); setType(param, param->type); params->push_back(param); - auto type = new IR::Type_Method(Util::SourceInfo(), new IR::TypeParameters(), - IR::Type_Void::get(), - new IR::ParameterList(Util::SourceInfo(), params)); + auto type = new IR::Type_Method(IR::Type_Void::get(), new IR::ParameterList(params)); auto canon = canonicalize(type); if (canon == nullptr) return expression; @@ -2312,7 +2304,7 @@ TypeInference::actionCall(bool inActionList, } if (it != arguments->end()) typeError("%1% Too many arguments for action", *it); - auto pl = new IR::ParameterList(Util::SourceInfo(), params); + auto pl = new IR::ParameterList(params); auto resultType = new IR::Type_Action(baseType->srcInfo, baseType->typeParameters, nullptr, pl); setType(getOriginal(), resultType); @@ -2354,7 +2346,7 @@ const IR::Node* TypeInference::postorder(IR::MethodCallExpression* expression) { } else { // We build a type for the callExpression and unify it with the method expression // Allocate a fresh variable for the return type; it will be hopefully bound in the process. - auto rettype = new IR::Type_Var(Util::SourceInfo(), IR::ID(refMap->newName("R"), nullptr)); + auto rettype = new IR::Type_Var(IR::ID(refMap->newName("R"), nullptr)); auto args = new IR::Vector(); for (auto arg : *expression->arguments) { auto argType = getType(arg); diff --git a/frontends/p4/uniqueNames.cpp b/frontends/p4/uniqueNames.cpp index 23de8afa533..4b8f86e1c4f 100644 --- a/frontends/p4/uniqueNames.cpp +++ b/frontends/p4/uniqueNames.cpp @@ -52,7 +52,7 @@ addNameAnnotation(cstring name, const IR::Annotations* annos) { if (annos == nullptr) annos = IR::Annotations::empty; return annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), name)); + new IR::StringLiteral(name)); } UniqueNames::UniqueNames(ReferenceMap* refMap) : renameMap(new RenameMap) { diff --git a/ir/expression.def b/ir/expression.def index 5770e733ec2..32a902cd244 100644 --- a/ir/expression.def +++ b/ir/expression.def @@ -311,9 +311,9 @@ class SelectExpression : Expression { } class MethodCallExpression : Expression { - Expression method; - Vector typeArguments; - Vector arguments; + Expression method; + optional Vector typeArguments = new Vector; + optional Vector arguments = new Vector; toString{ return method->toString(); } validate{ typeArguments->check_null(); arguments->check_null(); } } diff --git a/ir/ir.cpp b/ir/ir.cpp index 1c699952c39..24aafa144f5 100644 --- a/ir/ir.cpp +++ b/ir/ir.cpp @@ -35,15 +35,15 @@ int IR::Declaration::nextId = 0; int IR::This::nextId = 0; const Type_Method* P4Control::getConstructorMethodType() const { - return new Type_Method(Util::SourceInfo(), getTypeParameters(), type, constructorParams); + return new Type_Method(getTypeParameters(), type, constructorParams); } const Type_Method* P4Parser::getConstructorMethodType() const { - return new Type_Method(Util::SourceInfo(), getTypeParameters(), type, constructorParams); + return new Type_Method(getTypeParameters(), type, constructorParams); } const Type_Method* Type_Package::getConstructorMethodType() const { - return new Type_Method(Util::SourceInfo(), getTypeParameters(), this, constructorParams); + return new Type_Method(getTypeParameters(), this, constructorParams); } Util::Enumerator* IGeneralNamespace::getDeclsByName(cstring name) const { @@ -115,12 +115,12 @@ const Method* Type_Extern::lookupMethod(cstring name, int paramCount) const { const Type_Method* Type_Parser::getApplyMethodType() const { - return new Type_Method(Util::SourceInfo(), new IR::TypeParameters(), nullptr, applyParams); + return new Type_Method(applyParams); } const Type_Method* Type_Control::getApplyMethodType() const { - return new Type_Method(Util::SourceInfo(), new IR::TypeParameters(), nullptr, applyParams); + return new Type_Method(applyParams); } const IR::Path* ActionListElement::getPath() const { @@ -145,17 +145,12 @@ P4Table::getApplyMethodType() const { actions); auto alv = actions->value->to(); auto fields = new IR::IndexedVector(); - auto hit = new IR::StructField(Util::SourceInfo(), IR::Type_Table::hit, - IR::Annotations::empty, IR::Type_Boolean::get()); + auto hit = new IR::StructField(IR::Type_Table::hit, IR::Type_Boolean::get()); fields->push_back(hit); - auto label = new IR::StructField(Util::SourceInfo(), IR::Type_Table::action_run, - IR::Annotations::empty, - new IR::Type_ActionEnum(Util::SourceInfo(), alv)); + auto label = new IR::StructField(IR::Type_Table::action_run, new IR::Type_ActionEnum(alv)); fields->push_back(label); - auto rettype = new IR::Type_Struct(Util::SourceInfo(), ID(name), - IR::Annotations::empty, fields); - auto applyMethod = new IR::Type_Method(Util::SourceInfo(), new TypeParameters(), - rettype, new IR::ParameterList()); + auto rettype = new IR::Type_Struct(ID(name), fields); + auto applyMethod = new IR::Type_Method(rettype, new IR::ParameterList()); return applyMethod; } diff --git a/ir/ir.def b/ir/ir.def index 4f4c0047d1c..4314db07635 100644 --- a/ir/ir.def +++ b/ir/ir.def @@ -36,8 +36,8 @@ */ class ParserState : ISimpleNamespace, Declaration, IAnnotated { - Annotations annotations; - IndexedVector components; + optional Annotations annotations = Annotations::empty; + IndexedVector components; // selectExpression can be a SelectExpression, or a PathExpression representing a state NullOK Expression selectExpression; @@ -62,8 +62,8 @@ class ParserState : ISimpleNamespace, Declaration, IAnnotated { // A parser that contains all states (unlike the P4 v1.0 parser, which is really just a state) class P4Parser : Type_Declaration, ISimpleNamespace, IApply, IContainer { - Type_Parser type; - ParameterList constructorParams; + Type_Parser type; + optional ParameterList constructorParams = new ParameterList; IndexedVector parserLocals; IndexedVector states; @@ -91,8 +91,8 @@ class P4Parser : Type_Declaration, ISimpleNamespace, IApply, IContainer { } class P4Control : Type_Declaration, ISimpleNamespace, IApply, IContainer { - Type_Control type; - ParameterList constructorParams; + Type_Control type; + optional ParameterList constructorParams = new ParameterList; IndexedVector controlLocals; BlockStatement body; @@ -114,9 +114,9 @@ class P4Control : Type_Declaration, ISimpleNamespace, IApply, IContainer { } class P4Action : Declaration, ISimpleNamespace, IAnnotated { - Annotations annotations; - ParameterList parameters; - BlockStatement body; + optional Annotations annotations = Annotations::empty; + ParameterList parameters; + BlockStatement body; Util::Enumerator* getDeclarations() const override; IDeclaration getDeclByName(cstring name) const override; Annotations getAnnotations() const override { return annotations; } @@ -158,8 +158,8 @@ class ExpressionListValue : PropertyValue { // An element in a table actions list class ActionListElement : IAnnotated, IDeclaration { - Annotations annotations; - Expression expression; // This can be a PathExpression or a MethodCallExpression + optional Annotations annotations = Annotations::empty; + Expression expression; // This can be a PathExpression or a MethodCallExpression dbprint { out << annotations << expression; } ID getName() const override { return getPath()->name; } Path getPath() const; @@ -180,9 +180,9 @@ class ActionList : PropertyValue { } class KeyElement { - Annotations annotations; - Expression expression; - PathExpression matchType; + optional Annotations annotations = Annotations::empty; + Expression expression; + PathExpression matchType; const IR::Node *transform_visit(Transform &v) { // call this from Transform::preorder(KeyElement) if the transform might split @@ -212,7 +212,8 @@ class Key : PropertyValue { /// Pre-defined entry in a table class Entry : IAnnotated { - Annotations annotations; /// annotations are optional (supported annotations: @priority(value)) + /// annotations are optional (supported annotations: @priority(value)) + optional Annotations annotations = Annotations::empty; ListExpression keys; /// must be a tuple expression Expression action; /// typically a MethodCallExpression. /// The action must be defined in action list @@ -258,8 +259,8 @@ class TableProperties : ISimpleNamespace { } class P4Table : Declaration, IAnnotated, IApply { - Annotations annotations; - TableProperties properties; + optional Annotations annotations = Annotations::empty; + TableProperties properties; Annotations getAnnotations() const override { return annotations; } Type_Method getApplyMethodType() const override; @@ -307,9 +308,9 @@ class P4Table : Declaration, IAnnotated, IApply { } class Declaration_Variable : Declaration, IAnnotated { - Annotations annotations; - Type type; - NullOK Expression initializer; + optional Annotations annotations = Annotations::empty; + Type type; + optional NullOK Expression initializer = nullptr; Annotations getAnnotations() const override { return annotations; } dbprint { @@ -318,9 +319,9 @@ class Declaration_Variable : Declaration, IAnnotated { } class Declaration_Constant : Declaration, IAnnotated { - Annotations annotations; - Type type; - Expression initializer; + optional Annotations annotations = Annotations::empty; + Type type; + Expression initializer; Annotations getAnnotations() const override { return annotations; } toString { return Declaration::toString(); } @@ -396,8 +397,8 @@ class IfStatement : Statement { } class BlockStatement : Statement, ISimpleNamespace { - Annotations annotations; - IndexedVector components; + optional Annotations annotations = Annotations::empty; + IndexedVector components; IDeclaration getDeclByName(cstring name) const override { return components->getDeclaration(name); } Util::Enumerator* getDeclarations() const override { diff --git a/ir/type.cpp b/ir/type.cpp index 36f5f2125c7..2b6af8d464e 100644 --- a/ir/type.cpp +++ b/ir/type.cpp @@ -47,28 +47,28 @@ const Type_Bits* Type_Bits::get(int width, bool isSigned) { map = new std::map(); auto &result = (*map)[width]; if (!result) - result = new Type_Bits(Util::SourceInfo(), width, isSigned); + result = new Type_Bits(width, isSigned); return result; } const Type::Unknown *Type::Unknown::get() { static const Type::Unknown *singleton = nullptr; if (!singleton) - singleton = (new Type::Unknown(Util::SourceInfo())); + singleton = (new Type::Unknown()); return singleton; } const Type::Boolean *Type::Boolean::get() { static const Type::Boolean *singleton = nullptr; if (!singleton) - singleton = (new Type::Boolean(Util::SourceInfo())); + singleton = (new Type::Boolean()); return singleton; } const Type_String *Type_String::get() { static const Type_String *singleton = nullptr; if (!singleton) - singleton = (new Type_String(Util::SourceInfo())); + singleton = (new Type_String()); return singleton; } @@ -85,34 +85,34 @@ const Type::Varbits *Type::Varbits::get(Util::SourceInfo si, int sz) { } const Type::Varbits *Type::Varbits::get() { - return new Type::Varbits(Util::SourceInfo(), 0); + return new Type::Varbits(0); } const Type_Dontcare *Type_Dontcare::get() { static const Type_Dontcare *singleton; if (!singleton) - singleton = (new Type_Dontcare(Util::SourceInfo())); + singleton = (new Type_Dontcare()); return singleton; } const Type_State *Type_State::get() { static const Type_State *singleton; if (!singleton) - singleton = (new Type_State(Util::SourceInfo())); + singleton = (new Type_State()); return singleton; } const Type_Void *Type_Void::get() { static const Type_Void *singleton; if (!singleton) - singleton = (new Type_Void(Util::SourceInfo())); + singleton = (new Type_Void()); return singleton; } const Type_MatchKind *Type_MatchKind::get() { static const Type_MatchKind *singleton; if (!singleton) - singleton = (new Type_MatchKind(Util::SourceInfo())); + singleton = (new Type_MatchKind()); return singleton; } diff --git a/ir/type.def b/ir/type.def index 2abe29ca48e..fb664774741 100644 --- a/ir/type.def +++ b/ir/type.def @@ -283,8 +283,8 @@ class Type_Tuple : Type { /// The type of an architectural block. /// Abstract base for Type_Control, Type_Parser and Type_Package abstract Type_ArchBlock : Type_Declaration, IMayBeGenericType, IAnnotated { - Annotations annotations; - TypeParameters typeParameters; + optional Annotations annotations = Annotations::empty; + optional TypeParameters typeParameters = new TypeParameters; Annotations getAnnotations() const override { return annotations; } TypeParameters getTypeParameters() const override { return typeParameters; } } @@ -472,8 +472,8 @@ class Method : Declaration { } class Type_Typedef : Type_Declaration, IAnnotated { - Annotations annotations; - Type type; + optional Annotations annotations = Annotations::empty; + Type type; Annotations getAnnotations() const override { return annotations; } #nodbprint } diff --git a/ir/v1.def b/ir/v1.def index 29cd2a5a3e7..0c938911516 100644 --- a/ir/v1.def +++ b/ir/v1.def @@ -223,12 +223,12 @@ class FieldList { } class FieldListCalculation { - optional ID name; - NullOK NameList input = nullptr; - NullOK FieldList input_fields = nullptr; - ID algorithm = {}; - int output_width = 0; - Annotations annotations; + optional ID name; + NullOK NameList input = nullptr; + NullOK FieldList input_fields = nullptr; + ID algorithm = {}; + int output_width = 0; + optional Annotations annotations = Annotations::empty; } class CalculatedField { diff --git a/midend/actionSynthesis.cpp b/midend/actionSynthesis.cpp index 098edeeda83..5ea243101fc 100644 --- a/midend/actionSynthesis.cpp +++ b/midend/actionSynthesis.cpp @@ -47,15 +47,14 @@ const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statem auto actionPath = new IR::PathExpression(IR::ID(mc->srcInfo, ac->action->name)); auto call = new IR::MethodCallExpression(mc->srcInfo, actionPath, new IR::Vector(), directionArgs); - auto actinst = new IR::ActionListElement(statement->srcInfo, IR::Annotations::empty, call); + auto actinst = new IR::ActionListElement(statement->srcInfo, call); auto actions = new IR::IndexedVector(); actions->push_back(actinst); // Action list property - auto actlist = new IR::ActionList(Util::SourceInfo(), actions); + auto actlist = new IR::ActionList(actions); auto prop = new IR::Property( - Util::SourceInfo(), IR::ID(IR::TableProperties::actionsPropertyName, nullptr), - IR::Annotations::empty, actlist, false); + actlist, false); // default action property auto otherArgs = new IR::Vector(); for (; it != action->parameters->parameters->end(); ++it) { @@ -64,24 +63,24 @@ const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statem } BUG_CHECK(arg == mc->arguments->end(), "%1%: mismatched arguments", mc); auto amce = new IR::MethodCallExpression(mc->srcInfo, mc->method, mc->typeArguments, otherArgs); - auto defactval = new IR::ExpressionValue(Util::SourceInfo(), amce); + auto defactval = new IR::ExpressionValue(amce); auto defprop = new IR::Property( - Util::SourceInfo(), IR::ID(IR::TableProperties::defaultActionPropertyName, nullptr), - IR::Annotations::empty, defactval, true); + IR::ID(IR::TableProperties::defaultActionPropertyName, nullptr), + defactval, true); // List of table properties auto nm = new IR::IndexedVector(); nm->push_back(prop); nm->push_back(defprop); - auto props = new IR::TableProperties(Util::SourceInfo(), nm); + auto props = new IR::TableProperties(nm); // Synthesize a new table cstring tblName = IR::ID(refMap->newName(cstring("tbl_") + ac->action->name.name), nullptr); - auto tbl = new IR::P4Table(Util::SourceInfo(), tblName, IR::Annotations::empty, props); + auto tbl = new IR::P4Table(tblName, props); tables.push_back(tbl); // Table invocation statement auto tblpath = new IR::PathExpression(tblName); - auto method = new IR::Member(Util::SourceInfo(), tblpath, IR::IApply::applyMethodName); + auto method = new IR::Member(tblpath, IR::IApply::applyMethodName); auto mce = new IR::MethodCallExpression( statement->srcInfo, method, new IR::Vector(), new IR::Vector()); @@ -164,8 +163,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) { } if (!actbody->empty()) { - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, actbody); + auto block = new IR::BlockStatement(actbody); auto action = createAction(block); left->push_back(action); actbody = new IR::IndexedVector(); @@ -173,8 +171,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) { left->push_back(c); } if (!actbody->empty()) { - auto block = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, actbody); + auto block = new IR::BlockStatement(actbody); auto action = createAction(block); left->push_back(action); } @@ -183,7 +180,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) { // Since we have only one 'changes' per P4Control, this may // be conservatively creating a new block when it hasn't changed. // But the result should be correct. - auto result = new IR::BlockStatement(Util::SourceInfo(), statement->annotations, left); + auto result = new IR::BlockStatement(statement->annotations, left); return result; } return statement; @@ -198,16 +195,12 @@ const IR::Statement* DoSynthesizeActions::createAction(const IR::Statement* toAd } else { auto b = new IR::IndexedVector(); b->push_back(toAdd); - body = new IR::BlockStatement(toAdd->srcInfo, IR::Annotations::empty, b); + body = new IR::BlockStatement(toAdd->srcInfo, b); } - auto action = new IR::P4Action(Util::SourceInfo(), name, - IR::Annotations::empty, - new IR::ParameterList(), body); + auto action = new IR::P4Action(name, new IR::ParameterList(), body); actions.push_back(action); auto actpath = new IR::PathExpression(name); - auto repl = new IR::MethodCallExpression(Util::SourceInfo(), actpath, - new IR::Vector(), - new IR::Vector()); + auto repl = new IR::MethodCallExpression(actpath); auto result = new IR::MethodCallStatement(repl->srcInfo, repl); return result; } diff --git a/midend/actionsInlining.cpp b/midend/actionsInlining.cpp index 739a387cdc1..fea428bce0e 100644 --- a/midend/actionsInlining.cpp +++ b/midend/actionsInlining.cpp @@ -157,9 +157,8 @@ const IR::Node* ActionsInliner::preorder(IR::MethodCallStatement* statement) { cstring newName = refMap->newName(param->name); paramRename.emplace(param, newName); if (param->direction == IR::Direction::In || param->direction == IR::Direction::InOut) { - auto vardecl = new IR::Declaration_Variable(Util::SourceInfo(), newName, - param->annotations, param->type, - initializer); + auto vardecl = new IR::Declaration_Variable(newName, param->annotations, + param->type, initializer); body->push_back(vardecl); subst.add(param, new IR::PathExpression(newName)); } else if (param->direction == IR::Direction::None) { @@ -168,8 +167,8 @@ const IR::Node* ActionsInliner::preorder(IR::MethodCallStatement* statement) { subst.add(param, initializer); } else if (param->direction == IR::Direction::Out) { // uninitialized variable - auto vardecl = new IR::Declaration_Variable(Util::SourceInfo(), newName, - param->annotations, param->type, nullptr); + auto vardecl = new IR::Declaration_Variable(newName, + param->annotations, param->type); subst.add(param, new IR::PathExpression(newName)); body->push_back(vardecl); } @@ -192,7 +191,7 @@ const IR::Node* ActionsInliner::preorder(IR::MethodCallStatement* statement) { if (param->direction == IR::Direction::InOut || param->direction == IR::Direction::Out) { cstring newName = ::get(paramRename, param); auto right = new IR::PathExpression(newName); - auto copyout = new IR::AssignmentStatement(Util::SourceInfo(), left, right); + auto copyout = new IR::AssignmentStatement(left, right); body->push_back(copyout); } ++it; diff --git a/midend/copyStructures.cpp b/midend/copyStructures.cpp index 57703b07258..7e3a207c77f 100644 --- a/midend/copyStructures.cpp +++ b/midend/copyStructures.cpp @@ -28,7 +28,7 @@ const IR::Node* DoCopyStructures::postorder(IR::AssignmentStatement* statement) unsigned index = 0; for (auto f : *strct->fields) { auto right = list->components->at(index); - auto left = new IR::Member(Util::SourceInfo(), statement->left, f->name); + auto left = new IR::Member(statement->left, f->name); retval->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); index++; } @@ -43,8 +43,8 @@ const IR::Node* DoCopyStructures::postorder(IR::AssignmentStatement* statement) statement->right->is(), "%1%: Unexpected operation when eliminating struct copying", statement->right); - auto right = new IR::Member(Util::SourceInfo(), statement->right, f->name); - auto left = new IR::Member(Util::SourceInfo(), statement->left, f->name); + auto right = new IR::Member(statement->right, f->name); + auto left = new IR::Member(statement->left, f->name); retval->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); } } @@ -58,8 +58,8 @@ const IR::Node* DoCopyStructures::postorder(IR::AssignmentStatement* statement) statement->right->is(), "%1%: Unexpected operation when eliminating struct copying", statement->right); - auto right = new IR::ArrayIndex(Util::SourceInfo(), statement->right, index); - auto left = new IR::ArrayIndex(Util::SourceInfo(), statement->left, index->clone()); + auto right = new IR::ArrayIndex(statement->right, index); + auto left = new IR::ArrayIndex(statement->left, index->clone()); retval->push_back(new IR::AssignmentStatement(statement->srcInfo, left, right)); } return retval; diff --git a/midend/eliminateTuples.cpp b/midend/eliminateTuples.cpp index 6953a2e06ff..d7664fe7ed7 100644 --- a/midend/eliminateTuples.cpp +++ b/midend/eliminateTuples.cpp @@ -15,8 +15,7 @@ const IR::Type* ReplacementMap::convertType(const IR::Type* type) { auto cftype = convertType(ftype); if (cftype != ftype) changes = true; - auto field = new IR::StructField(Util::SourceInfo(), f->name, - f->annotations, cftype->getP4Type()); + auto field = new IR::StructField(f->name, f->annotations, cftype->getP4Type()); fields->push_back(field); } if (changes) { @@ -33,11 +32,10 @@ const IR::Type* ReplacementMap::convertType(const IR::Type* type) { for (auto t : *type->to()->components) { auto ftype = convertType(t); auto fname = ng->newName("field"); - auto field = new IR::StructField(Util::SourceInfo(), IR::ID(fname), - IR::Annotations::empty, ftype->getP4Type()); + auto field = new IR::StructField(IR::ID(fname), ftype->getP4Type()); fields->push_back(field); } - auto result = new IR::Type_Struct(Util::SourceInfo(), name, IR::Annotations::empty, fields); + auto result = new IR::Type_Struct(name, fields); LOG1("Converted " << dbp(type) << " to " << dbp(result)); replacement.emplace(type, result); return result; diff --git a/midend/expandLookahead.cpp b/midend/expandLookahead.cpp index ae17bb2e0cb..9d2f6902a52 100644 --- a/midend/expandLookahead.cpp +++ b/midend/expandLookahead.cpp @@ -28,14 +28,12 @@ void DoExpandLookahead::expandSetValid(const IR::Expression* base, const IR::Typ auto t = typeMap->getTypeType(f->type, true); if (t == nullptr) return; - auto mem = new IR::Member(Util::SourceInfo(), base, f->name); + auto mem = new IR::Member(base, f->name); expandSetValid(mem, t, output); } } else if (type->is()) { - auto setValid = new IR::Member(Util::SourceInfo(), base, IR::Type_Header::setValid); - auto mc = new IR::MethodCallExpression( - Util::SourceInfo(), setValid, new IR::Vector(), - new IR::Vector()); + auto setValid = new IR::Member(base, IR::Type_Header::setValid); + auto mc = new IR::MethodCallExpression(setValid); output->push_back(new IR::MethodCallStatement(mc)); } } @@ -52,12 +50,11 @@ const IR::Expression* DoExpandLookahead::expand( auto e = expand(base, t, offset); vec->push_back(e); } - return new IR::ListExpression(Util::SourceInfo(), vec); + return new IR::ListExpression(vec); } else if (type->is() || type->is()) { unsigned size = type->width_bits(); BUG_CHECK(size > 0, "%1%: unexpected size %2%", type, size); - auto expression = new IR::Slice( - Util::SourceInfo(), base->clone(), *offset + size - 1, *offset); + auto expression = new IR::Slice(base->clone(), *offset + size - 1, *offset); *offset += size; return expression; } else { @@ -96,8 +93,7 @@ const IR::Node* DoExpandLookahead::postorder(IR::AssignmentStatement* statement) auto bittype = IR::Type_Bits::get(width); auto name = refMap->newName("tmp"); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), IR::ID(name), - IR::Annotations::empty, bittype, nullptr); + auto decl = new IR::Declaration_Variable(IR::ID(name), bittype, nullptr); newDecls.push_back(decl); auto vec = new IR::IndexedVector(); @@ -116,7 +112,7 @@ const IR::Node* DoExpandLookahead::postorder(IR::AssignmentStatement* statement) auto assignment = new IR::AssignmentStatement(statement->srcInfo, statement->left, init); vec->push_back(assignment); - auto result = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, vec); + auto result = new IR::BlockStatement(vec); return result; } diff --git a/midend/inlining.cpp b/midend/inlining.cpp index 88a781843b4..097f2011774 100644 --- a/midend/inlining.cpp +++ b/midend/inlining.cpp @@ -217,7 +217,7 @@ setNameAnnotation(cstring name, const IR::Annotations* annos) { if (annos == nullptr) annos = IR::Annotations::empty; return annos->addOrReplace(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), name)); + new IR::StringLiteral(name)); } @@ -540,9 +540,8 @@ const IR::Node* GeneralInliner::preorder(IR::P4Control* caller) { auto path = new IR::PathExpression(newName); substs->paramSubst.add(param, path); LOG1("Replacing " << param->name << " with " << newName); - auto vardecl = new IR::Declaration_Variable(Util::SourceInfo(), newName, - param->annotations, param->type, - nullptr); + auto vardecl = new IR::Declaration_Variable(newName, + param->annotations, param->type); locals->push_back(vardecl); } } @@ -592,7 +591,7 @@ const IR::Node* GeneralInliner::preorder(IR::MethodCallStatement* statement) { auto arg = mcd.substitution.lookup(param); if ((param->direction == IR::Direction::In || param->direction == IR::Direction::InOut) && initializer != arg) { - auto stat = new IR::AssignmentStatement(Util::SourceInfo(), initializer, arg); + auto stat = new IR::AssignmentStatement(initializer, arg); body->push_back(stat); } else if (param->direction == IR::Direction::Out) { auto paramType = typeMap->getType(param, true); @@ -611,8 +610,7 @@ const IR::Node* GeneralInliner::preorder(IR::MethodCallStatement* statement) { auto left = mcd.substitution.lookup(param); auto initializer = substs->paramSubst.lookupByName(param->name); if (initializer != left) { - auto copyout = new IR::AssignmentStatement( - Util::SourceInfo(), left, initializer->clone()); + auto copyout = new IR::AssignmentStatement(left, initializer->clone()); body->push_back(copyout); } } @@ -734,7 +732,7 @@ const IR::Node* GeneralInliner::preorder(IR::ParserState* state) { LOG1("Looking for " << param->name); if (param->direction == IR::Direction::In || param->direction == IR::Direction::InOut) { auto expr = substs->paramSubst.lookupByName(param->name); - auto stat = new IR::AssignmentStatement(Util::SourceInfo(), expr, initializer); + auto stat = new IR::AssignmentStatement(expr, initializer); current->push_back(stat); } else if (param->direction == IR::Direction::Out) { auto expr = substs->paramSubst.lookupByName(param->name); @@ -768,7 +766,6 @@ const IR::Node* GeneralInliner::preorder(IR::ParserState* state) { // Prepare next state annotations = IR::Annotations::empty; - srcInfo = Util::SourceInfo(); name = IR::ID(nextState, nullptr); current = new IR::IndexedVector(); @@ -779,7 +776,7 @@ const IR::Node* GeneralInliner::preorder(IR::ParserState* state) { if (param->direction == IR::Direction::InOut || param->direction == IR::Direction::Out) { auto expr = substs->paramSubst.lookupByName(param->name); - auto copyout = new IR::AssignmentStatement(Util::SourceInfo(), left, expr->clone()); + auto copyout = new IR::AssignmentStatement(left, expr->clone()); current->push_back(copyout); } ++it; @@ -788,7 +785,7 @@ const IR::Node* GeneralInliner::preorder(IR::ParserState* state) { if (!states->empty()) { // Create final state - auto newState = new IR::ParserState(srcInfo, name, annotations, + auto newState = new IR::ParserState(name, annotations, current, state->selectExpression); states->push_back(newState); LOG1("Replacing with " << states->size() << " states"); @@ -844,9 +841,8 @@ const IR::Node* GeneralInliner::preorder(IR::P4Parser* caller) { auto path = new IR::PathExpression(newName); substs->paramSubst.add(param, path); LOG1("Replacing " << param->name << " with " << newName); - auto vardecl = new IR::Declaration_Variable(Util::SourceInfo(), newName, - param->annotations, param->type, - nullptr); + auto vardecl = new IR::Declaration_Variable(newName, + param->annotations, param->type); locals->push_back(vardecl); } diff --git a/midend/localizeActions.cpp b/midend/localizeActions.cpp index 3e88e155b31..1788c3b9b9b 100644 --- a/midend/localizeActions.cpp +++ b/midend/localizeActions.cpp @@ -43,7 +43,7 @@ const IR::Node* TagGlobalActions::preorder(IR::P4Action* action) { annos = IR::Annotations::empty; cstring name = cstring(".") + action->name; annos = annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), name)); + new IR::StringLiteral(name)); action->annotations = annos; } prune(); @@ -77,7 +77,7 @@ bool FindGlobalActionUses::preorder(const IR::PathExpression* path) { if (annos == nullptr) annos = IR::Annotations::empty; annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), action->name)); + new IR::StringLiteral(action->name)); auto replacement = new IR::P4Action(action->srcInfo, IR::ID(action->name.srcInfo, newName), annos, params, replBody); repl->addReplacement(action, control, replacement); @@ -165,7 +165,7 @@ bool FindRepeatedActionUses::preorder(const IR::PathExpression* expression) { if (annos == nullptr) annos = IR::Annotations::empty; annos->addAnnotationIfNew(IR::Annotation::nameAnnotation, - new IR::StringLiteral(Util::SourceInfo(), action->name)); + new IR::StringLiteral(action->name)); replacement = new IR::P4Action(action->srcInfo, IR::ID(action->name.srcInfo, newName), annos, params, replBody); repl->createReplacement(action, actionUser, replacement); diff --git a/midend/moveConstructors.cpp b/midend/moveConstructors.cpp index 262af7e9db7..40535c6cdd2 100644 --- a/midend/moveConstructors.cpp +++ b/midend/moveConstructors.cpp @@ -87,8 +87,7 @@ class MoveConstructorsImpl : public Transform { for (auto e : cmap.tmpName) { auto cce = e.first; auto decl = new IR::Declaration_Instance( - cce->srcInfo, e.second, IR::Annotations::empty, - cce->constructedType, cce->arguments, nullptr); + cce->srcInfo, e.second, cce->constructedType, cce->arguments); result->push_back(decl); changes = true; } @@ -108,8 +107,7 @@ class MoveConstructorsImpl : public Transform { for (auto e : cmap.tmpName) { auto cce = e.first; auto decl = new IR::Declaration_Instance( - cce->srcInfo, e.second, IR::Annotations::empty, cce->constructedType, - cce->arguments, nullptr); + cce->srcInfo, e.second, cce->constructedType, cce->arguments); newDecls->push_back(decl); } newDecls->append(*parser->parserLocals); @@ -128,8 +126,7 @@ class MoveConstructorsImpl : public Transform { for (auto e : cmap.tmpName) { auto cce = e.first; auto inst = new IR::Declaration_Instance( - cce->srcInfo, e.second, IR::Annotations::empty, cce->constructedType, - cce->arguments, nullptr); + cce->srcInfo, e.second, cce->constructedType, cce->arguments); newDecls->push_back(inst); changes = true; } @@ -156,8 +153,7 @@ class MoveConstructorsImpl : public Transform { for (auto e : cmap.tmpName) { auto cce = e.first; auto decl = new IR::Declaration_Instance( - cce->srcInfo, e.second, IR::Annotations::empty, cce->constructedType, - cce->arguments, nullptr); + cce->srcInfo, e.second, cce->constructedType, cce->arguments); newDecls->push_back(decl); } newDecls->append(*control->controlLocals); diff --git a/midend/nestedStructs.cpp b/midend/nestedStructs.cpp index 9da0f23ce02..0444b0c0bca 100644 --- a/midend/nestedStructs.cpp +++ b/midend/nestedStructs.cpp @@ -32,9 +32,7 @@ void ComplexValues::explode(cstring prefix, const IR::Type_Struct* type, cstring newName = refMap->newName(fname); auto comp = new FinalName(newName); map->members.emplace(f->name.name, comp); - auto clone = new IR::Declaration_Variable( - Util::SourceInfo(), IR::ID(newName), IR::Annotations::empty, - ftype->getP4Type(), nullptr); + auto clone = new IR::Declaration_Variable(IR::ID(newName), ftype->getP4Type()); LOG3("Created " << clone); result->push_back(clone); } diff --git a/midend/nestedStructs.h b/midend/nestedStructs.h index 63fef79f45e..cd63cd78075 100644 --- a/midend/nestedStructs.h +++ b/midend/nestedStructs.h @@ -66,7 +66,7 @@ class ComplexValues final { auto e = m.second->convertToExpression(); vec->push_back(e); } - return new IR::ListExpression(Util::SourceInfo(), vec); + return new IR::ListExpression(vec); } Component* get(cstring name) override { return ::get(members, name); } diff --git a/midend/noMatch.cpp b/midend/noMatch.cpp index 1c24c27a312..915b20c1f11 100644 --- a/midend/noMatch.cpp +++ b/midend/noMatch.cpp @@ -40,15 +40,12 @@ const IR::Node* DoHandleNoMatch::preorder(IR::P4Parser* parser) { auto args = new IR::Vector(); args->push_back(new IR::BoolLiteral(false)); args->push_back(new IR::Member( - Util::SourceInfo(), new IR::TypeNameExpression(IR::Type_Error::error), lib.noMatch.Id())); auto verify = new IR::MethodCallExpression( - Util::SourceInfo(), new IR::PathExpression(IR::ID(IR::ParserState::verify)), - new IR::Vector(), args); + new IR::PathExpression(IR::ID(IR::ParserState::verify)), args); vec->push_back(new IR::MethodCallStatement(verify)); - noMatch = new IR::ParserState(Util::SourceInfo(), IR::ID(name), - IR::Annotations::empty, vec, + noMatch = new IR::ParserState(IR::ID(name), vec, new IR::PathExpression(IR::ID(IR::ParserState::reject))); auto comp = new IR::IndexedVector(*parser->states); comp->push_back(noMatch); diff --git a/midend/predication.cpp b/midend/predication.cpp index 7f7a98dc7bf..75e4e17abf3 100644 --- a/midend/predication.cpp +++ b/midend/predication.cpp @@ -21,7 +21,7 @@ namespace P4 { const IR::Node* Predication::postorder(IR::AssignmentStatement* statement) { if (!inside_action || ifNestingLevel == 0) return statement; - auto right = new IR::Mux(Util::SourceInfo(), predicate(), statement->right, statement->left); + auto right = new IR::Mux(predicate(), statement->right, statement->left); statement->right = right; return statement; } @@ -33,9 +33,7 @@ const IR::Node* Predication::preorder(IR::IfStatement* statement) { ++ifNestingLevel; auto vec = new IR::IndexedVector(); cstring conditionName = generator->newName("cond"); - auto condDecl = new IR::Declaration_Variable( - Util::SourceInfo(), conditionName, IR::Annotations::empty, - IR::Type::Boolean::get(), nullptr); + auto condDecl = new IR::Declaration_Variable(conditionName, IR::Type::Boolean::get()); vec->push_back(condDecl); auto condition = new IR::PathExpression(IR::ID(conditionName)); @@ -46,51 +44,48 @@ const IR::Node* Predication::preorder(IR::IfStatement* statement) { // a new name for the new predicate cstring newPredName = generator->newName("pred"); predicateName.push_back(newPredName); - auto decl = new IR::Declaration_Variable( - Util::SourceInfo(), newPredName, IR::Annotations::empty, - IR::Type::Boolean::get(), nullptr); + auto decl = new IR::Declaration_Variable(newPredName, IR::Type::Boolean::get()); blockVec->push_back(decl); // This evaluates the if condition. // We are careful not to evaluate any conditional more times // than in the original program, since the evaluation may have side-effects. - auto trueCond = new IR::AssignmentStatement(Util::SourceInfo(), condition->clone(), - statement->condition); + auto trueCond = new IR::AssignmentStatement(condition->clone(), statement->condition); blockVec->push_back(trueCond); const IR::Expression* pred; if (previousPredicate == nullptr) { pred = condition->clone(); } else { - pred = new IR::LAnd(Util::SourceInfo(), previousPredicate, condition->clone()); + pred = new IR::LAnd(previousPredicate, condition->clone()); } - auto truePred = new IR::AssignmentStatement(Util::SourceInfo(), predicate(), pred); + auto truePred = new IR::AssignmentStatement(predicate(), pred); blockVec->push_back(truePred); visit(statement->ifTrue); blockVec->push_back(statement->ifTrue); if (statement->ifFalse != nullptr) { - auto neg = new IR::LNot(Util::SourceInfo(), condition->clone()); - auto falseCond = new IR::AssignmentStatement(Util::SourceInfo(), condition->clone(), neg); + auto neg = new IR::LNot(condition->clone()); + auto falseCond = new IR::AssignmentStatement(condition->clone(), neg); blockVec->push_back(falseCond); if (previousPredicate == nullptr) { pred = condition->clone(); } else { - pred = new IR::LAnd(Util::SourceInfo(), previousPredicate->clone(), condition->clone()); + pred = new IR::LAnd(previousPredicate->clone(), condition->clone()); } - auto falsePred = new IR::AssignmentStatement(Util::SourceInfo(), predicate(), pred); + auto falsePred = new IR::AssignmentStatement(predicate(), pred); blockVec->push_back(falsePred); visit(statement->ifFalse); blockVec->push_back(statement->ifFalse); } - auto block = new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, blockVec); + auto block = new IR::BlockStatement(blockVec); vec->push_back(block); predicateName.pop_back(); --ifNestingLevel; prune(); - return new IR::BlockStatement(Util::SourceInfo(), IR::Annotations::empty, vec); + return new IR::BlockStatement(vec); } const IR::Node* Predication::preorder(IR::P4Action* action) { diff --git a/midend/removeParameters.cpp b/midend/removeParameters.cpp index 182437bdffa..eb67f50d4f2 100644 --- a/midend/removeParameters.cpp +++ b/midend/removeParameters.cpp @@ -124,8 +124,7 @@ const IR::Node* DoRemoveActionParameters::postorder(IR::P4Action* action) { initializers->append(*postamble); action->parameters = new IR::ParameterList(action->parameters->srcInfo, leftParams); - action->body = new IR::BlockStatement( - action->body->srcInfo, IR::Annotations::empty, initializers); + action->body = new IR::BlockStatement(action->body->srcInfo, initializers); LOG1("To replace " << dbp(action)); result->push_back(action); return result; diff --git a/midend/removeReturns.cpp b/midend/removeReturns.cpp index dbf0f9a1d2b..b9e239c1cc2 100644 --- a/midend/removeReturns.cpp +++ b/midend/removeReturns.cpp @@ -54,9 +54,8 @@ const IR::Node* DoRemoveReturns::preorder(IR::P4Action* action) { LOG3("Processing " << dbp(action)); cstring var = refMap->newName(variableName); returnVar = IR::ID(var, nullptr); - auto f = new IR::BoolLiteral(Util::SourceInfo(), false); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), returnVar, - IR::Annotations::empty, IR::Type_Boolean::get(), f); + auto f = new IR::BoolLiteral(false); + auto decl = new IR::Declaration_Variable(returnVar, IR::Type_Boolean::get(), f); BUG_CHECK(stack.empty(), "Non-empty stack"); push(); visit(action->body); @@ -86,9 +85,8 @@ const IR::Node* DoRemoveReturns::preorder(IR::P4Control* control) { cstring var = refMap->newName(variableName); returnVar = IR::ID(var, nullptr); - auto f = new IR::BoolLiteral(Util::SourceInfo(), false); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), returnVar, - IR::Annotations::empty, IR::Type_Boolean::get(), f); + auto f = new IR::BoolLiteral(false); + auto decl = new IR::Declaration_Variable(returnVar, IR::Type_Boolean::get(), f); BUG_CHECK(stack.empty(), "Non-empty stack"); push(); visit(control->body); @@ -109,7 +107,7 @@ const IR::Node* DoRemoveReturns::preorder(IR::ReturnStatement* statement) { set(Returns::Yes); auto left = new IR::PathExpression(returnVar); return new IR::AssignmentStatement(statement->srcInfo, left, - new IR::BoolLiteral(Util::SourceInfo(), true)); + new IR::BoolLiteral(true)); return statement; } @@ -134,10 +132,9 @@ const IR::Node* DoRemoveReturns::preorder(IR::BlockStatement* statement) { } else if (r == Returns::Maybe) { auto newBody = new IR::IndexedVector(); auto path = new IR::PathExpression(returnVar); - auto condition = new IR::LNot(Util::SourceInfo(), path); - auto newBlock = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, newBody); - auto ifstat = new IR::IfStatement(Util::SourceInfo(), condition, newBlock, nullptr); + auto condition = new IR::LNot(path); + auto newBlock = new IR::BlockStatement(newBody); + auto ifstat = new IR::IfStatement(condition, newBlock, nullptr); body->push_back(ifstat); currentBody = newBody; ret = r; @@ -153,7 +150,7 @@ const IR::Node* DoRemoveReturns::preorder(IR::IfStatement* statement) { push(); visit(statement->ifTrue); if (statement->ifTrue == nullptr) - statement->ifTrue = new IR::EmptyStatement(Util::SourceInfo()); + statement->ifTrue = new IR::EmptyStatement(); auto rt = hasReturned(); auto rf = Returns::No; pop(); @@ -228,7 +225,7 @@ const IR::Node* DoRemoveExits::preorder(IR::ExitStatement* statement) { set(Returns::Yes); auto left = new IR::PathExpression(returnVar); return new IR::AssignmentStatement(statement->srcInfo, left, - new IR::BoolLiteral(Util::SourceInfo(), true)); + new IR::BoolLiteral(true)); } const IR::Node* DoRemoveExits::preorder(IR::P4Table* table) { @@ -276,17 +273,14 @@ const IR::Node* DoRemoveExits::preorder(IR::P4Control* control) { push(); visit(control->body); auto stateful = new IR::IndexedVector(); - auto decl = new IR::Declaration_Variable(Util::SourceInfo(), returnVar, - IR::Annotations::empty, - IR::Type_Boolean::get(), nullptr); + auto decl = new IR::Declaration_Variable(returnVar, IR::Type_Boolean::get(), nullptr); stateful->push_back(decl); stateful->append(*control->controlLocals); control->controlLocals = stateful; auto newbody = new IR::IndexedVector(); auto left = new IR::PathExpression(returnVar); - auto init = new IR::AssignmentStatement(Util::SourceInfo(), left, - new IR::BoolLiteral(Util::SourceInfo(), false)); + auto init = new IR::AssignmentStatement(left, new IR::BoolLiteral(false)); newbody->push_back(init); newbody->append(*control->body->components); control->body = new IR::BlockStatement( @@ -314,10 +308,9 @@ const IR::Node* DoRemoveExits::preorder(IR::BlockStatement* statement) { } else if (r == Returns::Maybe) { auto newBody = new IR::IndexedVector(); auto path = new IR::PathExpression(returnVar); - auto condition = new IR::LNot(Util::SourceInfo(), path); - auto newBlock = new IR::BlockStatement( - Util::SourceInfo(), IR::Annotations::empty, newBody); - auto ifstat = new IR::IfStatement(Util::SourceInfo(), condition, newBlock, nullptr); + auto condition = new IR::LNot(path); + auto newBlock = new IR::BlockStatement(newBody); + auto ifstat = new IR::IfStatement(condition, newBlock, nullptr); body->push_back(ifstat); currentBody = newBody; ret = r; @@ -341,11 +334,11 @@ const IR::Node* DoRemoveExits::preorder(IR::IfStatement* statement) { visit(statement->ifTrue); if (statement->ifTrue == nullptr) - statement->ifTrue = new IR::EmptyStatement(Util::SourceInfo()); + statement->ifTrue = new IR::EmptyStatement(); if (ce.callsExit) { auto path = new IR::PathExpression(returnVar); - auto condition = new IR::LNot(Util::SourceInfo(), path); - auto newif = new IR::IfStatement(Util::SourceInfo(), condition, statement->ifTrue, nullptr); + auto condition = new IR::LNot(path); + auto newif = new IR::IfStatement(condition, statement->ifTrue, nullptr); statement->ifTrue = newif; } auto rt = hasReturned(); @@ -356,9 +349,8 @@ const IR::Node* DoRemoveExits::preorder(IR::IfStatement* statement) { visit(statement->ifFalse); if (ce.callsExit && statement->ifFalse != nullptr) { auto path = new IR::PathExpression(returnVar); - auto condition = new IR::LNot(Util::SourceInfo(), path); - auto newif = new IR::IfStatement(Util::SourceInfo(), condition, - statement->ifFalse, nullptr); + auto condition = new IR::LNot(path); + auto newif = new IR::IfStatement(condition, statement->ifFalse, nullptr); statement->ifFalse = newif; } rf = hasReturned(); @@ -395,12 +387,11 @@ const IR::Node* DoRemoveExits::preorder(IR::SwitchStatement* statement) { IR::Statement* stat = nullptr; if (c->statement != nullptr) { auto path = new IR::PathExpression(returnVar); - auto condition = new IR::LNot(Util::SourceInfo(), path); - auto newif = new IR::IfStatement(Util::SourceInfo(), condition, - c->statement, nullptr); + auto condition = new IR::LNot(path); + auto newif = new IR::IfStatement(condition, c->statement, nullptr); auto vec = new IR::IndexedVector(); vec->push_back(newif); - stat = new IR::BlockStatement(newif->srcInfo, IR::Annotations::empty, vec); + stat = new IR::BlockStatement(newif->srcInfo, vec); } auto swcase = new IR::SwitchCase(c->srcInfo, c->label, stat); cases->push_back(swcase); diff --git a/midend/removeSelectBooleans.cpp b/midend/removeSelectBooleans.cpp index d59996b9449..ae20c930aff 100644 --- a/midend/removeSelectBooleans.cpp +++ b/midend/removeSelectBooleans.cpp @@ -29,7 +29,7 @@ DoRemoveSelectBooleans::addToplevelCasts(const IR::Expression* expression) { auto type = typeMap->getType(e, true); if (type->is()) { changes = true; - auto cast = new IR::Cast(Util::SourceInfo(), IR::Type_Bits::get(1), e); + auto cast = new IR::Cast(IR::Type_Bits::get(1), e); vec->push_back(cast); } else { vec->push_back(e); @@ -41,7 +41,7 @@ DoRemoveSelectBooleans::addToplevelCasts(const IR::Expression* expression) { } else { auto type = typeMap->getType(expression, true); if (type->is()) - expression = new IR::Cast(Util::SourceInfo(), IR::Type_Bits::get(1), expression); + expression = new IR::Cast(IR::Type_Bits::get(1), expression); return expression; } } diff --git a/midend/simplifyKey.cpp b/midend/simplifyKey.cpp index b61186deda0..c52486334df 100644 --- a/midend/simplifyKey.cpp +++ b/midend/simplifyKey.cpp @@ -61,9 +61,7 @@ const IR::Node* DoSimplifyKey::postorder(IR::KeyElement* element) { auto tmp = refMap->newName("key"); auto type = typeMap->getType(element->expression, true); - auto decl = new IR::Declaration_Variable( - Util::SourceInfo(), tmp, IR::Annotations::empty, - type, nullptr); + auto decl = new IR::Declaration_Variable(tmp, type, nullptr); insertions->declarations.push_back(decl); auto left = new IR::PathExpression(tmp); auto right = element->expression; diff --git a/midend/simplifySelectList.cpp b/midend/simplifySelectList.cpp index 03fb97498cc..acb40962ce1 100644 --- a/midend/simplifySelectList.cpp +++ b/midend/simplifySelectList.cpp @@ -24,7 +24,7 @@ void SubstituteStructures::explode( if (type->is()) { auto st = type->to(); for (auto f : *st->fields) { - auto e = new IR::Member(Util::SourceInfo(), expression, f->name); + auto e = new IR::Member(expression, f->name); auto t = typeMap->getTypeType(f->type, true); explode(e, t, output); } diff --git a/midend/tableHit.cpp b/midend/tableHit.cpp index 02e00327f0e..560ec044207 100644 --- a/midend/tableHit.cpp +++ b/midend/tableHit.cpp @@ -25,11 +25,11 @@ const IR::Node* DoTableHit::postorder(IR::AssignmentStatement* statement) { return statement; auto tstat = new IR::AssignmentStatement( - Util::SourceInfo(), statement->left->clone(), new IR::BoolLiteral(true)); + statement->left->clone(), new IR::BoolLiteral(true)); auto fstat = new IR::AssignmentStatement( - Util::SourceInfo(), statement->left->clone(), new IR::BoolLiteral(false)); + statement->left->clone(), new IR::BoolLiteral(false)); auto ifStatement = new IR::IfStatement( - Util::SourceInfo(), statement->right, tstat, fstat); + statement->right, tstat, fstat); return ifStatement; } diff --git a/tools/ir-generator/ir-generator.ypp b/tools/ir-generator/ir-generator.ypp index 6d66a462077..775cf9dcc42 100644 --- a/tools/ir-generator/ir-generator.ypp +++ b/tools/ir-generator/ir-generator.ypp @@ -345,7 +345,10 @@ expression | NEW name { $$ = "new " + $2; } ; -name: IDENTIFIER | name DBLCOL IDENTIFIER { $$ = $1 + "::" + $3; } +name: IDENTIFIER + | name DBLCOL IDENTIFIER { $$ = $1 + "::" + $3; } + | name '<' name '>' { $$ = $1 + "<" + $3 + ">"; } + ; /*****************************************************************************/