Skip to content

Commit 8531f1d

Browse files
author
Chris Dodd
authored
Cleanup annotation creation by using default args (#2308)
1 parent 98a34fe commit 8531f1d

10 files changed

+28
-29
lines changed

frontends/p4-14/header_type.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ HeaderTypeMaxLengthCalculator::preorder(IR::Type_StructLike *hdr_type) {
2424
unsigned len = 0;
2525
for (auto field : hdr_type->fields)
2626
len += field->type->width_bits();
27-
max_length = new IR::Annotation("max_length", len, false);
27+
max_length = new IR::Annotation("max_length", len);
2828
if (!annot) annot = hdr_type->annotations->clone();
2929
annot->annotations.push_back(max_length); }
3030
auto *length = hdr_type->getAnnotation("length");
3131
if (!length) {
3232
if (!annot) annot = hdr_type->annotations->clone();
33-
length = new IR::Annotation("length", max_length->expr, false);
33+
length = new IR::Annotation("length", max_length->expr);
3434
annot->annotations.push_back(length); }
3535
if (annot) hdr_type->annotations = annot;
3636
return false;

frontends/p4/createBuiltins.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void CreateBuiltins::postorder(IR::ActionList* actions) {
7171
actions->push_back(
7272
new IR::ActionListElement(
7373
new IR::Annotations(
74-
{new IR::Annotation(IR::Annotation::defaultOnlyAnnotation, {}, false)}),
74+
{new IR::Annotation(IR::Annotation::defaultOnlyAnnotation, {})}),
7575
new IR::MethodCallExpression(
7676
new IR::PathExpression(P4::P4CoreLibrary::instance.noAction.Id(actions->srcInfo)),
7777
new IR::Vector<IR::Type>(), new IR::Vector<IR::Argument>())));

frontends/p4/directCalls.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ const IR::Node* DoInstantiateCalls::postorder(IR::MethodCallExpression* expressi
3434
auto name = refMap->newName(tn->typeName->path->name + "_inst");
3535
LOG3("Inserting instance " << name);
3636
auto annos = new IR::Annotations();
37-
annos->add(new IR::Annotation(
38-
IR::Annotation::nameAnnotation,
39-
{ new IR::StringLiteral(tn->typeName->path->toString()) }, false));
37+
annos->add(new IR::Annotation(IR::Annotation::nameAnnotation, tn->typeName->path->toString()));
4038
auto inst = new IR::Declaration_Instance(
4139
expression->srcInfo, IR::ID(name), annos,
4240
tn->typeName->clone(), new IR::Vector<IR::Argument>());

frontends/p4/fromv1.0/converters.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ const IR::StructField *TypeConverter::postorder(IR::StructField *field) {
464464
auto fieldlen = new IR::Sub(
465465
scale->srcInfo, scale, new IR::Constant(type->width_bits()));
466466
field->annotations = field->annotations->add(
467-
new IR::Annotation("length", { fieldlen }, false));
467+
new IR::Annotation("length", { fieldlen }));
468468
}
469469
}
470470
}

frontends/p4/fromv1.0/converters.h

+2-5
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,7 @@ class InsertCompilerGeneratedStartState: public Transform {
776776
new IR::PathExpression(new IR::Path(p.second->name))));
777777
}
778778
auto instAnnos = new IR::Annotations();
779-
instAnnos->add(new IR::Annotation(
780-
IR::Annotation::nameAnnotation,
781-
{new IR::StringLiteral(IR::ID(".$InstanceType"))}, false));
779+
instAnnos->add(new IR::Annotation(IR::Annotation::nameAnnotation, ".$InstanceType"));
782780
auto instEnum =
783781
new IR::Type_SerEnum(newInstanceType, instAnnos, IR::Type_Bits::get(32), members);
784782
allTypeDecls.push_back(instEnum);
@@ -790,8 +788,7 @@ class InsertCompilerGeneratedStartState: public Transform {
790788
"instance_type")));
791789
auto selects = new IR::SelectExpression(new IR::ListExpression(selExpr), selCases);
792790
auto annos = new IR::Annotations();
793-
annos->add(new IR::Annotation(IR::Annotation::nameAnnotation,
794-
{new IR::StringLiteral(IR::ID(".$start"))}, false));
791+
annos->add(new IR::Annotation(IR::Annotation::nameAnnotation, ".$start"));
795792
auto startState = new IR::ParserState(IR::ParserState::start, annos, selects);
796793
varDecls.push_back(startState);
797794

frontends/p4/fromv1.0/programStructure.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ ProgramStructure::convertTable(const IR::V1Table* table, cstring newName,
869869
actionList->push_back(
870870
new IR::ActionListElement(
871871
new IR::Annotations(
872-
{new IR::Annotation(IR::Annotation::defaultOnlyAnnotation, {}, false)}),
872+
{new IR::Annotation(IR::Annotation::defaultOnlyAnnotation, {})}),
873873
new IR::PathExpression(default_action))); }
874874
props->push_back(new IR::Property(IR::ID(IR::TableProperties::actionsPropertyName),
875875
actionList, false));

frontends/p4/hierarchicalNames.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const IR::Node* HierarchicalNames::postorder(IR::Annotation* annotation) {
3434
newName += s + ".";
3535
newName += name;
3636
LOG2("Changing " << name << " to " << newName);
37-
annotation = new IR::Annotation(annotation->name, { new IR::StringLiteral(newName) }, false);
37+
annotation = new IR::Annotation(annotation->name, newName);
3838
return annotation;
3939
}
4040

frontends/parsers/v1/v1parser.ypp

+7-7
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ input: /* epsilon */
270270
| input blackbox_type_declaration
271271
| input blackbox_instantiation
272272
| input PRAGMA pragma_operands NEWLINE
273-
{ driver.addPragma(new IR::Annotation(@2, $2, *$3, false)); }
273+
{ driver.addPragma(new IR::Annotation(@2, $2, *$3)); }
274274
| input error
275275
{ driver.clearPragmas(); }
276276
;
@@ -329,20 +329,20 @@ attributes:
329329

330330
attrib:
331331
SIGNED { $$.signed_ = true; }
332-
| SATURATING { $$.annotations.push_back(new IR::Annotation(@1, IR::ID(@1, $1), {}, false));
332+
| SATURATING { $$.annotations.push_back(new IR::Annotation(@1, IR::ID(@1, $1), {}));
333333
$$.saturating = true; }
334334
;
335335

336336
opt_length: /* epsilon */
337337
| LENGTH ":" expression ";" /* const_expression or name */
338338
{ $<HeaderType>-1.annotations->emplace_back(
339-
IR::Annotation(@1+@4, "length", IR::Vector<IR::Expression>($3), false)); }
339+
IR::Annotation(@1+@4, "length", IR::Vector<IR::Expression>($3))); }
340340
;
341341

342342
opt_max_length: /* epsilon */
343343
| MAX_LENGTH ":" const_expression ";"
344344
{ $<HeaderType>-2.annotations->emplace_back(
345-
IR::Annotation(@1+@4, "max_length", IR::Vector<IR::Expression>($3), false)); }
345+
IR::Annotation(@1+@4, "max_length", IR::Vector<IR::Expression>($3))); }
346346
;
347347

348348
type: BIT { $$ = IR::Type::Bits::get(@1, 1); }
@@ -886,9 +886,9 @@ blackbox_attribute: /* epsilon */ { $$ = new IR::Attribute($<IR::ID>-1); }
886886

887887
blackbox_method: { $$ = new IR::Annotations; }
888888
| blackbox_method READS "{" opt_name_list "}"
889-
{ ($$=$1)->add(new IR::Annotation(@2, $2, driver.makeExpressionList($4), false)); }
889+
{ ($$=$1)->add(new IR::Annotation(@2, $2, driver.makeExpressionList($4))); }
890890
| blackbox_method WRITES "{" opt_name_list "}"
891-
{ ($$=$1)->add(new IR::Annotation(@2, $2, driver.makeExpressionList($4), false)); }
891+
{ ($$=$1)->add(new IR::Annotation(@2, $2, driver.makeExpressionList($4))); }
892892
;
893893

894894
opt_argument_list:
@@ -905,7 +905,7 @@ argument:
905905
inout type name
906906
{ $$ = new IR::Parameter(@3, $3, $1, $2); }
907907
| OPTIONAL argument
908-
{ ($$ = $2)->annotations = $2->annotations->add(new IR::Annotation(@1, $1, {}, false)); }
908+
{ ($$ = $2)->annotations = $2->annotations->add(new IR::Annotation(@1, $1, {})); }
909909
;
910910

911911
inout: IN { $$ = IR::Direction::In; } | OUT { $$ = IR::Direction::Out; } ;

ir/base.def

+10-6
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,23 @@ class Annotation {
240240

241241
// The remaining constructors are for compiler-generated annotations.
242242
Annotation(Util::SourceInfo si, ID n,
243-
const std::initializer_list<const Expression *> &a, bool structured)
243+
const std::initializer_list<const Expression *> &a, bool structured = false)
244244
: Node(si), name(n), needsParsing(false), expr(a), structured(structured) {}
245-
Annotation(Util::SourceInfo si, ID n, const IR::Vector<Expression> &a, bool structured)
245+
Annotation(Util::SourceInfo si, ID n, const IR::Vector<Expression> &a, bool structured = false)
246246
: Node(si), name(n), needsParsing(false), expr(a), structured(structured) {}
247-
Annotation(Util::SourceInfo si, ID n, const IndexedVector<NamedExpression> &kv, bool structured)
247+
Annotation(Util::SourceInfo si, ID n, const IndexedVector<NamedExpression> &kv,
248+
bool structured = false)
248249
: Node(si), name(n), needsParsing(false), kv(kv), structured(structured) {}
249-
Annotation(ID n, const std::initializer_list<const Expression *> &a, bool structured)
250+
Annotation(ID n, const std::initializer_list<const Expression *> &a, bool structured = false)
250251
: name(n), needsParsing(false), expr(a), structured(structured) {}
251-
Annotation(ID n, const IR::Vector<Expression> &a, bool structured)
252+
Annotation(ID n, const IR::Vector<Expression> &a, bool structured = false)
252253
: name(n), needsParsing(false), expr(a), structured(structured) {}
253-
Annotation(ID n, intmax_t v, bool structured)
254+
Annotation(ID n, intmax_t v, bool structured = false)
254255
: name(n), needsParsing(false), structured(structured) {
255256
expr.push_back(new Constant(v)); }
257+
Annotation(ID n, cstring v, bool structured = false)
258+
: name(n), needsParsing(false), structured(structured) {
259+
expr.push_back(new StringLiteral(v)); }
256260

257261
static const cstring nameAnnotation; /// Indicates the control-plane name.
258262
static const cstring tableOnlyAnnotation; /// Action cannot be a default_action.

midend/actionSynthesis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statem
7272
cstring tblName = IR::ID(refMap->newName(cstring("tbl_") + ac->action->name.name), nullptr);
7373

7474
auto annos = new IR::Annotations();
75-
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}, false));
75+
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}));
7676
auto tbl = new IR::P4Table(statement->srcInfo, tblName, annos, props);
7777
tables.push_back(tbl);
7878

@@ -202,7 +202,7 @@ const IR::Statement* DoSynthesizeActions::createAction(const IR::Statement* toAd
202202
LOG3("Adding new action " << name << body);
203203

204204
auto annos = new IR::Annotations();
205-
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}, false));
205+
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation, {}));
206206
auto action = new IR::P4Action(name, annos, new IR::ParameterList(), body);
207207
actions.push_back(action);
208208
auto actpath = new IR::PathExpression(name);

0 commit comments

Comments
 (0)