-
Notifications
You must be signed in to change notification settings - Fork 444
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
Shorten the Identifer name, including dots(.) in Member expression #3175
Conversation
backends/dpdk/dpdk.def
Outdated
@@ -1,38 +1,38 @@ | |||
interface IDPDKNode { | |||
virtual std::ostream& toSpec(std::ostream& out) const = 0; | |||
virtual std::ostream& toSpec(std::ostream& out, const ordered_map<cstring, cstring>& origNameMap = {}) const = 0; |
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.
maybe you can make the map accessible through a method of the IDPDKNode class. Could be even a static variable (not beautiful, but simpler).
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.
create static member
ordered_map<cstring, cstring> newNameMap; | ||
ordered_map<cstring, cstring> &origNameMap; | ||
static size_t count; | ||
// Currently Dpdk allows Identifier of 63 char long or less |
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.
this is just a silly restriction, since I suspect the identifiers do not have a runtime representation.
wouldn't it be easier to fix this in the DPDK spec/implementation?
we're no longer in the 1970s when every byte counted.
// including dots(.) for member exp. | ||
// worst case member expression will look like below(for headers) | ||
// 1.30.30 => 63(including dot(.)) | ||
cstring shortenString(cstring str, size_t allowedLength = 60) { |
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.
We already have a class which does this, MinimalNameGenerator.
You should reuse that code.
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.
This runs post codegen and applied on some dpdk specific types too.
e03d7d6
to
9499681
Compare
9499681
to
9b1fd8b
Compare
backends/dpdk/spec.cpp
Outdated
@@ -16,22 +17,39 @@ std::ostream &IR::DpdkAsmProgram::toSpec(std::ostream &out) const { | |||
l->toSpec(out) << std::endl; | |||
} | |||
out << std::endl; | |||
for (auto h : headerType) | |||
for (auto h : headerType) { | |||
if (origNameMap.count(h->name.toString())) |
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.
looks like this could have been also a utility function, but it's a short one.
ir/ir.cpp
Outdated
@@ -34,6 +34,8 @@ const cstring Type_Error::error = "error"; | |||
|
|||
int IR::Declaration::nextId = 0; | |||
int IR::This::nextId = 0; | |||
// used in dpdk backend |
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.
Let's move this to a separate file, dpdk.cpp.
ir/ir.def
Outdated
@@ -613,4 +613,10 @@ class ToplevelBlock : Block, IDeclaration { | |||
validate { BUG_CHECK(node->is<IR::P4Program>(), "%1%: expected a P4Program", node); } | |||
} | |||
|
|||
/// Dpdk specific ir node | |||
interface IDPDKNode { |
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.
This should be in a separate file, dpdk.def.
5ed1815
to
a87ac30
Compare
@@ -275,8 +280,71 @@ cc_binary( | |||
data = [":p4include"], | |||
) | |||
|
|||
# This builds the p4test backend. | |||
# dpdk backend |
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.
perhaps for the bazel build you want to request a review from @smolkaj
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.
I am unable to add @smolkaj to reviewer list. may be due to permission issues. Can you please add him?
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.
That mention is enough, he had been notified. If he doesn't reply in a couple of days I will merge it anyway
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.
Got it, taking a look :)
backends/dpdk/dpdk.def
Outdated
@@ -1,5 +1,6 @@ | |||
interface IDPDKNode { | |||
virtual std::ostream& toSpec(std::ostream& out) const = 0; | |||
static ordered_map<cstring, cstring> origNameMap; |
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.
How about change this to be a static memeber of the ShortenTokenLength class? This feels like an odd place for a static member.
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.
done
…sion to be less than 64 because dpdk does not allow Identifer longer than 63 chars
a87ac30
to
3be4e04
Compare
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.
LGTM for the BUILD file changes
cc_library( | ||
name = "p4c_dpdk_lib", | ||
srcs = glob( | ||
["backends/dpdk/*.cpp", "backends/dpdk/control-plane/*.cpp", "backends/bmv2/common/lower.cpp"], |
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.
Nit: maybe put each file on a separate line for consistency / readability?
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.
Here and below
I will merge this now, but please consider the suggested changes in a future PR. Thank you all. |
to be less than 64 because dpdk does not allow Identifer longer than 63 chars