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

Separate Parser and Post-parser code C code #4138

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions backends/tc/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ bool Backend::process() {
}

bool Backend::ebpfCodeGen(P4::ReferenceMap *refMapEBPF, P4::TypeMap *typeMapEBPF) {
if (options.cFile.isNullOrEmpty()) return true;
target = new EBPF::KernelSamplesTarget(options.emitTraceMessages);
ebpfOption.xdp2tcMode = options.xdp2tcMode;
ebpfOption.exe_name = options.exe_name;
Expand Down Expand Up @@ -122,15 +121,48 @@ void Backend::serialize() const {
outstream->flush();
}
}
auto progName = options.file;
auto filename = progName.findlast('/');
if (filename) progName = filename;
progName = progName.exceptLast(3);
progName = progName.trim("/\t\n\r");
cstring parserFile = progName + "_parser.c";
cstring postParserFile = progName + "_post_parser.c";
cstring headerFile = progName + "_parser.h";
if (!options.cFile.isNullOrEmpty()) {
auto cstream = openFile(options.cFile, false);
if (cstream == nullptr) return;
if (ebpf_program == nullptr) return;
EBPF::CodeBuilder c(target);
ebpf_program->emit(&c);
*cstream << c.toString();
cstream->flush();
if (options.cFile.get(options.cFile.size() - 1) != '/') {
options.cFile = options.cFile + '/';
}
parserFile = options.cFile + parserFile;
postParserFile = options.cFile + postParserFile;
headerFile = options.cFile + headerFile;
}
auto cstream = openFile(postParserFile, false);
auto pstream = openFile(parserFile, false);
auto hstream = openFile(headerFile, false);
if (cstream == nullptr) {
::error("Unable to open File %1%", postParserFile);
return;
}
if (pstream == nullptr) {
::error("Unable to open File %1%", parserFile);
return;
}
if (hstream == nullptr) {
::error("Unable to open File %1%", headerFile);
return;
}
if (ebpf_program == nullptr) return;
EBPF::CodeBuilder c(target), p(target), h(target);
ebpf_program->emit(&c);
ebpf_program->emitParser(&p);
ebpf_program->emitHeader(&h);
*cstream << c.toString();
*pstream << p.toString();
*hstream << h.toString();
cstream->flush();
pstream->flush();
hstream->flush();
}

bool Backend::serializeIntrospectionJson(std::ostream &out) const {
Expand Down
Loading
Loading