Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement IAnnotated where possible #2035

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backends/graphs/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef _BACKENDS_GRAPHS_PARSERS_H_
#define _BACKENDS_GRAPHS_PARSERS_H_

#include "frontends/common/resolveReferences/referenceMap.h"
#include "ir/ir.h"
#include "lib/cstring.h"
#include "lib/nullstream.h"
Expand Down
30 changes: 20 additions & 10 deletions ir/v1.def
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ class Type_AnyTable : Type_Base {
dbprint { out << "table"; }
}

abstract HeaderOrMetadata {
abstract HeaderOrMetadata : IAnnotated {
ID type_name;
ID name;
Annotations annotations;
NullOK Type_StructLike type = nullptr;

Annotations getAnnotations() const override { return annotations; }
HeaderOrMetadata(ID n, Type_StructLike t)
: type_name(t->name), name(n), annotations(Annotations::empty), type(t) {}
dbprint { out << type_name << ' ' << name; }
Expand Down Expand Up @@ -215,23 +216,25 @@ class Primitive : Operation {
precedence = DBPrint::Prec_Postfix;
}

class FieldList {
class FieldList : IAnnotated {
optional ID name;
bool payload = false;
optional Annotations annotations = Annotations::empty;
inline Vector<Expression> fields = {};
Annotations getAnnotations() const override { return annotations; }
}

class FieldListCalculation {
class FieldListCalculation : IAnnotated {
optional ID name;
NullOK NameList input = nullptr;
NullOK FieldList input_fields = nullptr;
NullOK NameList algorithm = nullptr;
int output_width = 0;
optional Annotations annotations = Annotations::empty;
Annotations getAnnotations() const override { return annotations; }
}

class CalculatedField {
class CalculatedField : IAnnotated {
optional NullOK Expression field;
class update_or_verify {
Util::SourceInfo srcInfo;
Expand All @@ -246,15 +249,17 @@ class CalculatedField {
}
safe_vector<update_or_verify> specs = {};
Annotations annotations;
Annotations getAnnotations() const override { return annotations; }
visit_children {
v.visit(field, "field");
for (auto &s : specs) v.visit(s.cond, s.name.name);
v.visit(annotations, "annotations"); }
}

class ParserValueSet {
class ParserValueSet : IAnnotated {
ID name;
optional Annotations annotations = Annotations::empty;
Annotations getAnnotations() const override { return annotations; }
dbprint { out << node_type_name() << " " << name; }
toString { return node_type_name() + " " + name; }
}
Expand All @@ -264,7 +269,7 @@ class CaseEntry {
optional ID action;
}

class V1Parser {
class V1Parser :IAnnotated {
optional ID name;
inline Vector<Expression> stmts = {};
NullOK Vector<Expression> select = nullptr;
Expand All @@ -273,17 +278,19 @@ class V1Parser {
ID parse_error = {};
bool drop = false;
Annotations annotations;
Annotations getAnnotations() const override { return annotations; }
toString { return node_type_name() + " " + name; }
}

class ParserException {}

abstract Attached : IInstance {
abstract Attached : IInstance, IAnnotated {
optional ID name;
optional Annotations annotations = Annotations::empty;
cstring Name() const override { return name; }
virtual const char *kind() const = 0;
Type getType() const override { return Type_Unknown::get(); }
Annotations getAnnotations() const override { return annotations; }
virtual bool indexed() const { return false; }
Attached *clone_rename(const char *ext) const {
Attached *rv = clone();
Expand Down Expand Up @@ -355,12 +362,13 @@ class ActionArg : Expression {
}

// Represents a P4 v1.0 action
class ActionFunction {
class ActionFunction : IAnnotated {
optional ID name;
inline Vector<Primitive> action = {};
safe_vector<ActionArg> args = {};
optional Annotations annotations = Annotations::empty;

Annotations getAnnotations() const override { return annotations; }
ActionArg arg(cstring n) const {
for (auto a : args)
if (a->name == n)
Expand Down Expand Up @@ -395,7 +403,7 @@ class ActionSelector : Attached {
const char *kind() const override { return "action_selector"; }
}

class V1Table : IInstance {
class V1Table : IInstance, IAnnotated {
optional ID name;
NullOK Vector<Expression> reads = 0;
safe_vector<ID> reads_types = {};
Expand All @@ -411,19 +419,21 @@ class V1Table : IInstance {
optional Annotations annotations = Annotations::empty;

void addProperty(Property prop) { properties.push_back(prop); }
Annotations getAnnotations() const override { return annotations; }
toString { return node_type_name() + " " + name; }
cstring Name() const override { return name; }
Type getType() const override { return Type_AnyTable::get(); }
}

class V1Control {
class V1Control : IAnnotated {
ID name;
Vector<Expression> code;
Annotations annotations;

V1Control(ID n) : name(n), code(new Vector<Expression>()) {}
V1Control(Util::SourceInfo si, ID n) : Node(si), name(n), code(new Vector<Expression>()) {}
#apply
Annotations getAnnotations() const override { return annotations; }
toString { return node_type_name() + " " + name; }
}

Expand Down