-
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
Add support for parser value_set to eBPF backend #3235
Conversation
explicit EBPFParser(const EBPFProgram* program, const IR::ParserBlock* block, | ||
const P4::TypeMap* typeMap); | ||
virtual void emitDeclaration(CodeBuilder* builder, const IR::Declaration* decl); | ||
void emit(CodeBuilder* builder); | ||
virtual bool build(); | ||
|
||
virtual void emitTypes(CodeBuilder* builder) { (void) builder; } | ||
virtual void emitValueSetInstances(CodeBuilder* builder) { (void) builder; } | ||
virtual void emitTypes(CodeBuilder* builder); |
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.
So this works with the standard ebpf backend too. Thank you.
backends/ebpf/ebpfTable.cpp
Outdated
// validate type | ||
if (pvs->elementType->is<IR::Type_Bits>() || pvs->elementType->is<IR::Type_Tuple>()) { | ||
// no restrictions | ||
} else if (pvs->elementType->is<IR::Type_Name>()) { |
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.
In general you can do typeMap->getType(pvs->elementType, true)
.
This should cover all cases, including nested typedefs, etc.
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.
getType
returns instance of IR::Type_Type
. This is intended behavior?
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.
Use getTypeType
backends/ebpf/ebpfTable.cpp
Outdated
} | ||
|
||
void EBPFValueSet::emitTypes(CodeBuilder* builder) { | ||
if (pvs->elementType->is<IR::Type_Name>()) { |
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.
Same here, use the typeMap.
backends/ebpf/ebpfTable.cpp
Outdated
builder->endOfStatement(true); | ||
}; | ||
|
||
if (pvs->elementType->is<IR::Type_Bits>()) { |
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 as well it is safest to use the type from the typeMap.
backends/ebpf/ebpfTable.cpp
Outdated
|
||
// init other bigger fields | ||
for (unsigned int i = 0; i < fieldNames.size(); i++) { | ||
if (fieldNames.at(i).second->is<IR::Type_Bits>()) { |
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.
why do a separate loop? Can't this case be handled in the above loop?
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've changed the way that key is initialized, so now it is one loop.
This PR adds the support for parser value_set to eBPF backend. Co-authored-by: Tomasz Osiński <[email protected]> Co-authored-by: Mateusz Kossakowski <[email protected]>
@mbudiu-vmw I think I addressed all the comments, thank you for your review. |
This PR adds the support for parser value_set to eBPF backend.
Co-authored-by: Tomasz Osiński [email protected]
Co-authored-by: Mateusz Kossakowski [email protected]