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

Add support for parser value_set to eBPF backend #3235

Merged
merged 4 commits into from
Apr 22, 2022
Merged

Conversation

tatry
Copy link
Contributor

@tatry tatry commented Apr 21, 2022

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]

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);
Copy link
Contributor

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.

// 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>()) {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use getTypeType

}

void EBPFValueSet::emitTypes(CodeBuilder* builder) {
if (pvs->elementType->is<IR::Type_Name>()) {
Copy link
Contributor

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.

builder->endOfStatement(true);
};

if (pvs->elementType->is<IR::Type_Bits>()) {
Copy link
Contributor

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.


// init other bigger fields
for (unsigned int i = 0; i < fieldNames.size(); i++) {
if (fieldNames.at(i).second->is<IR::Type_Bits>()) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

tatry and others added 2 commits April 22, 2022 08:18
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]>
@tatry
Copy link
Contributor Author

tatry commented Apr 22, 2022

@mbudiu-vmw I think I addressed all the comments, thank you for your review.

@mihaibudiu mihaibudiu merged commit 0e19ec1 into p4lang:main Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants