-
Notifications
You must be signed in to change notification settings - Fork 446
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
parser graph generation support for graphs backend #969
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
098e404
parser graph generation support for graphs backend
c3m3gyanesh f2a7618
cpplint fix- tab2whitespace
c3m3gyanesh 3f84ad8
header guard style fix
c3m3gyanesh c9975c6
create graph base class, using rectangles in graphs
c3m3gyanesh 3b75ee2
main func and Graph methods are separed to different files:p4c-graphs…
c3m3gyanesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
main func and Graph methods are separed to different files:p4c-graphs…
….cpp,graphs.cpp
- Loading branch information
commit 3b75ee2b531bd5e6b474f42a2931da0dae20e419
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ set (GRAPHS_SRCS | |
graphs.cpp | ||
controls.cpp | ||
parser.cpp | ||
p4c-graphs.cpp | ||
) | ||
|
||
set (GRAPHS_HDRS | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
Copyright 2013-present Barefoot Networks, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "ir/ir.h" | ||
#include "lib/log.h" | ||
#include "lib/error.h" | ||
#include "lib/exceptions.h" | ||
#include "lib/gc.h" | ||
#include "lib/crash.h" | ||
#include "lib/nullstream.h" | ||
#include "frontends/common/parseInput.h" | ||
#include "frontends/p4/evaluator/evaluator.h" | ||
#include "frontends/p4/frontend.h" | ||
|
||
#include "graphs.h" | ||
|
||
namespace graphs { | ||
|
||
class MidEnd : public PassManager { | ||
public: | ||
P4::ReferenceMap refMap; | ||
P4::TypeMap typeMap; | ||
IR::ToplevelBlock *toplevel = nullptr; | ||
|
||
explicit MidEnd(CompilerOptions& options); | ||
IR::ToplevelBlock* process(const IR::P4Program *&program) { | ||
program = program->apply(*this); | ||
return toplevel; | ||
} | ||
}; | ||
|
||
MidEnd::MidEnd(CompilerOptions& options) { | ||
bool isv1 = options.langVersion == CompilerOptions::FrontendVersion::P4_14; | ||
refMap.setIsV1(isv1); | ||
auto evaluator = new P4::EvaluatorPass(&refMap, &typeMap); | ||
setName("MidEnd"); | ||
|
||
addPasses({ | ||
evaluator, | ||
new VisitFunctor([this, evaluator]() { toplevel = evaluator->getToplevelBlock(); }), | ||
}); | ||
} | ||
|
||
class Options : public CompilerOptions { | ||
public: | ||
cstring graphsDir{"."}; | ||
Options() { | ||
registerOption("--graphs-dir", "dir", | ||
[this](const char* arg) { graphsDir = arg; return true; }, | ||
"Use this directory to dump graphs in dot format " | ||
"(default is current working directory)\n"); | ||
} | ||
}; | ||
|
||
} // namespace graphs | ||
|
||
int main(int argc, char *const argv[]) { | ||
setup_gc_logging(); | ||
setup_signals(); | ||
|
||
graphs::Options options; | ||
options.langVersion = CompilerOptions::FrontendVersion::P4_16; | ||
options.compilerVersion = "0.0.5"; | ||
|
||
if (options.process(argc, argv) != nullptr) | ||
options.setInputFile(); | ||
if (::errorCount() > 0) | ||
return 1; | ||
|
||
auto hook = options.getDebugHook(); | ||
|
||
auto program = P4::parseP4File(options); | ||
if (program == nullptr || ::errorCount() > 0) | ||
return 1; | ||
|
||
try { | ||
P4::FrontEnd fe; | ||
fe.addDebugHook(hook); | ||
program = fe.run(options, program); | ||
} catch (const Util::P4CExceptionBase &bug) { | ||
std::cerr << bug.what() << std::endl; | ||
return 1; | ||
} | ||
if (program == nullptr || ::errorCount() > 0) | ||
return 1; | ||
|
||
graphs::MidEnd midEnd(options); | ||
midEnd.addDebugHook(hook); | ||
const IR::ToplevelBlock *top = nullptr; | ||
try { | ||
top = midEnd.process(program); | ||
if (options.dumpJsonFile) | ||
JSONGenerator(*openFile(options.dumpJsonFile, true)) << program << std::endl; | ||
} catch (const Util::P4CExceptionBase &bug) { | ||
std::cerr << bug.what() << std::endl; | ||
return 1; | ||
} | ||
if (::errorCount() > 0) | ||
return 1; | ||
|
||
LOG1("Generating graphs under " << options.graphsDir); | ||
LOG1("Generating control graphs"); | ||
graphs::ControlGraphs cgen(&midEnd.refMap, &midEnd.typeMap, options.graphsDir); | ||
top->getMain()->apply(cgen); | ||
|
||
LOG1("Generating parser graphs"); | ||
graphs::ParserGraphs pgen(&midEnd.refMap, &midEnd.typeMap, options.graphsDir); | ||
top->getMain()->apply(pgen); | ||
|
||
return ::errorCount() > 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 personally think that the
main
function for the backend and theGraph
methods implementation belong in 2 different files; apart from that it looks ok.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.
created a new file "p4c-graphs.cpp" to accommodate
main
funcion.