-
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
Fix support for verify() and error type to fully support verify() in PSA/eBPF backend #3250
Changes from all commits
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 |
---|---|---|
|
@@ -27,6 +27,38 @@ limitations under the License. | |
|
||
namespace EBPF { | ||
|
||
class PSAErrorCodesGen : public Inspector { | ||
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. We have a midend pass called convertErrors that could perhaps be used to do this. 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. I use this class only to iterate over error codes and emit them into C code. Similarly is done for filter architecture. I've prepared a PR in my fork which shows difference with this midend pass, especially this commit. In my opinion there is no profits from using 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. Sounds fine, it's a small amount of code. |
||
CodeBuilder* builder; | ||
|
||
public: | ||
explicit PSAErrorCodesGen(CodeBuilder* builder) : builder(builder) {} | ||
|
||
bool preorder(const IR::Type_Error* errors) override { | ||
int id = -1; | ||
for (auto decl : errors->members) { | ||
++id; | ||
if (decl->srcInfo.isValid()) { | ||
auto sourceFile = decl->srcInfo.getSourceFile(); | ||
// all the error codes are located in core.p4 file, they are defined in psa.h | ||
if (sourceFile.endsWith("p4include/core.p4")) | ||
continue; | ||
} | ||
|
||
builder->emitIndent(); | ||
builder->appendFormat("static const ParserError_t %s = %d", decl->name.name, id); | ||
builder->endOfStatement(true); | ||
|
||
// type ParserError_t is u8, which can have values from 0 to 255 | ||
if (id > 255) { | ||
::error(ErrorType::ERR_OVERLIMIT, | ||
"%1%: Reached maximum number of possible errors", decl); | ||
} | ||
} | ||
builder->newline(); | ||
return false; | ||
} | ||
}; | ||
|
||
// =====================PSAEbpfGenerator============================= | ||
void PSAEbpfGenerator::emitPSAIncludes(CodeBuilder *builder) const { | ||
builder->appendLine("#include <stdbool.h>"); | ||
|
@@ -89,6 +121,9 @@ void PSAEbpfGenerator::emitInternalStructures(CodeBuilder *builder) const { | |
|
||
/* Generate headers and structs in p4 prog */ | ||
void PSAEbpfGenerator::emitTypes(CodeBuilder *builder) const { | ||
PSAErrorCodesGen errorGen(builder); | ||
ingress->program->apply(errorGen); | ||
|
||
for (auto type : ebpfTypes) { | ||
type->emit(builder); | ||
} | ||
|
@@ -447,6 +482,8 @@ const PSAEbpfGenerator * ConvertToEbpfPSA::build(const IR::ToplevelBlock *tlb) { | |
|
||
const IR::Node *ConvertToEbpfPSA::preorder(IR::ToplevelBlock *tlb) { | ||
ebpf_psa_arch = build(tlb); | ||
ebpf_psa_arch->ingress->program = tlb->getProgram(); | ||
ebpf_psa_arch->egress->program = tlb->getProgram(); | ||
return tlb; | ||
} | ||
|
||
|
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.
If you use the error elimination pass (see below) this code may need to change.