-
Notifications
You must be signed in to change notification settings - Fork 466
[Generator] Add an explicit modifier to the IR generator. #5208
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
base: main
Are you sure you want to change the base?
Changes from all commits
1d45672
fdea5f2
8eaa5d0
79d63cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <tna.p4> | ||
|
||
header foo_t { | ||
varbit<32> foo; | ||
} | ||
struct headers { | ||
foo_t foo; | ||
} | ||
struct ingress_metadata_t {} | ||
struct egress_headers_t {} | ||
struct egress_metadata_t {} | ||
|
||
|
||
parser ig_prs( | ||
packet_in pkt, | ||
out headers hdr, | ||
out ingress_metadata_t ig_md, | ||
out ingress_intrinsic_metadata_t ig_intr_md) | ||
{ | ||
state start { | ||
transition foo; | ||
} | ||
|
||
state foo { | ||
pkt.extract(hdr.foo, (bit<32>)8); | ||
transition accept; | ||
} | ||
} | ||
|
||
control ig_ctl( | ||
inout headers hdr, inout ingress_metadata_t ig_md, | ||
in ingress_intrinsic_metadata_t ig_intr_md, | ||
in ingress_intrinsic_metadata_from_parser_t ig_prsr_md, | ||
inout ingress_intrinsic_metadata_for_deparser_t ig_dprsr_md, | ||
inout ingress_intrinsic_metadata_for_tm_t ig_tm_md) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
control ig_dprs( | ||
packet_out pkt, | ||
inout headers hdr, | ||
in ingress_metadata_t ig_md, | ||
in ingress_intrinsic_metadata_for_deparser_t ig_dprsr_md) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
parser eg_prs( | ||
packet_in pkt, | ||
out egress_headers_t eg_hdr, out egress_metadata_t eg_md, | ||
out egress_intrinsic_metadata_t eg_intr_md) | ||
{ | ||
state start { | ||
transition accept; | ||
} | ||
} | ||
|
||
control eg_ctl( | ||
inout egress_headers_t eg_hdr, inout egress_metadata_t eg_md, | ||
in egress_intrinsic_metadata_t eg_intr_md, | ||
in egress_intrinsic_metadata_from_parser_t eg_prsr_md, | ||
inout egress_intrinsic_metadata_for_deparser_t eg_dprsr_md, | ||
inout egress_intrinsic_metadata_for_output_port_t eg_oport_md) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
control eg_dprs( | ||
packet_out pkt, | ||
inout egress_headers_t eg_hdr, in egress_metadata_t eg_md, | ||
in egress_intrinsic_metadata_for_deparser_t eg_dprsr_md) | ||
{ | ||
apply { | ||
} | ||
} | ||
|
||
Pipeline( | ||
ig_prs(), ig_ctl(), ig_dprs(), | ||
eg_prs(), eg_ctl(), eg_dprs()) pipe; | ||
|
||
Switch(pipe) main; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,7 +242,7 @@ class Annotation { | |
inline Annotation(Util::SourceInfo si, ID n, | ||
std::initializer_list<const Expression *> a, bool structured = false) | ||
: Node(si), name(n), body(a), structured(structured) {} | ||
inline Annotation(Util::SourceInfo si, ID n, | ||
inline explicit Annotation(Util::SourceInfo si, ID n, | ||
const Expression *a, bool structured = false) | ||
: Node(si), name(n), body(), structured(structured) { | ||
body.emplace<ExpressionAnnotation>(a); | ||
|
@@ -252,7 +252,7 @@ class Annotation { | |
inline Annotation(Util::SourceInfo si, ID n, const IndexedVector<NamedExpression> &kv, | ||
bool structured = false) | ||
: Node(si), name(n), body(kv), structured(structured) {} | ||
inline Annotation(ID n, const Expression *a, bool structured = false) | ||
inline explicit Annotation(ID n, const Expression *a, bool structured = false) | ||
: name(n), body(), structured(structured) { | ||
body.emplace<ExpressionAnnotation>(a); | ||
} | ||
|
@@ -445,6 +445,12 @@ interface IAnnotated { | |
inline void addOrReplaceAnnotation(Annotation ann) { | ||
Annotations::addOrReplace(getAnnotations(), ann); | ||
} | ||
#emit | ||
// FIXME: We shouldn't need this delete. | ||
// Ideally, we only accept references to expressions. | ||
void addOrReplaceAnnotation(cstring name, std::nullptr_t expr, bool structured = false) = delete; | ||
void addAnnotation(cstring name, std::nullptr_t expr, bool structured = false) = delete; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While calling these with an explicit
or perhaps add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deleting this overload works because the compiler will throw an error that the call is ambiguous. It is not pretty, but doesn't break the interface. Probably the right approach is to make everything pass-by-reference. |
||
#end | ||
} | ||
|
||
interface IInstance { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like the
explicit
does anything useful here -- it just disallows things likewhich doesn't seem too useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I started out with this approach and then realized the Expression constructor must be made explicit. Figured it is still useful to add this modifier to the generator.
I haven't made the necessary changes to the generator yet to support this. There is still a bit of work to do.