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

parser graph generation support for graphs backend #969

Merged
merged 5 commits into from
Oct 30, 2017
Merged

parser graph generation support for graphs backend #969

merged 5 commits into from
Oct 30, 2017

Conversation

c3m3gyanesh
Copy link
Contributor

Generates a graph representation of top-level parser block as a dot file.
Added an example of parser graph for reference.

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

Rectangles with small padding take up much less space on the page. I would recommend using rectangles for the graph nodes that occur most frequently.

@@ -67,6 +67,18 @@ class EdgeSwitch : public EdgeTypeIface {
const IR::Expression *labelExpr;
};

class EdgeSelect : public EdgeTypeIface {
Copy link
Member

Choose a reason for hiding this comment

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

This is not used in this file, so I'm not sure why it is defined here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be removed. Remnant code from my initial experimentation with code.

@@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef _BACKENDS_GRAPHS_CONTROLS_H_
Copy link
Member

Choose a reason for hiding this comment

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

it's a little confusing to call this file graphs.h, given that none of the classes it prototypes are implemented in graphs.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the common header file for both control.cpp and parser.cpp.
If you have any other suggestion for names, i would appreciate that.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe graph_generators.h if you want to have a single header file for both control and parser

Copy link
Contributor

@ChrisDodd ChrisDodd Oct 13, 2017

Choose a reason for hiding this comment

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

If you refactor ParserGraphs and ControlGraphs into a single Graphs (abstract) base class with ParserGraphs and ControlGraphs as (simpler) subclasses, then I think this organization does make a fair amount of sense.

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 tried to refactor the classes and created a Graphs base class.

// properties. See
// https://stackoverflow.com/questions/29312444/how-to-write-graphviz-subgraphs-with-boostwrite-graphviz
// for more information.
using GraphvizAttributes = std::map<cstring, cstring>;
Copy link
Member

Choose a reason for hiding this comment

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

it seems you pasted a lot of code from ControlGraphs here, and that these 2 classes would benefit from inheriting from a common base class

bool preorder(const IR::P4Parser *pars) override;
bool preorder(const IR::ParserState *state) override;

void writeGraphToFile(const Graph &g, const cstring &name);
Copy link
Member

Choose a reason for hiding this comment

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

as underlined in my comment above, duplicating this method in ControlGraphs and ParserGraphs looks like a bad design

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the code duplication is minimized.

parents.clear();

if (state->selectExpression->is<IR::PathExpression>()) {
parents = {{v, new EdgeSwitch(new IR::DefaultExpression())}};
Copy link
Member

Choose a reason for hiding this comment

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

these edge classes are not visible from this file; this will break non-unified builds

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 don't understand what you said? I am pretty new to c++
Can you give little more details, plz. ?

Copy link
Member

Choose a reason for hiding this comment

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

Well there is no EdgeSwitch declaration visible from this file. It is in controls.cpp. I believe that this is only compiling because we use a unified-build by default, which merges all the source files in this directory before compiling them. Some people build this code in a non-unified way, it which case it would fail. You should try compiling without a unified build (run cmake with UNIFIED_COMPILATION_ENABLED set to false). It really should be a regression for this repo IMO but it's not.

@mihaibudiu
Copy link
Contributor

@sethfowler @cc10512 @ChrisDodd : there are several builds that fail due to some errors that should not happen, including this one. Is the Travis setup for testing wrong?

@cc10512
Copy link
Contributor

cc10512 commented Oct 16, 2017

@mbudiu-vmw agreed. It is likely the -march=native that breaks it when running in a VM.

@c3m3gyanesh
Copy link
Contributor Author

@mbudiu-vmw I updated the graphs to use rectangle. Please take a look at the example graph which is part of the commit and let me know your thoughts.

@@ -55,6 +55,116 @@ MidEnd::MidEnd(CompilerOptions& options) {
});
}

class Graphs::GraphAttributeSetter {
Copy link
Member

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 the Graph methods implementation belong in 2 different files; apart from that it looks ok.

Copy link
Contributor Author

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.

@c3m3gyanesh
Copy link
Contributor Author

Is there something else remain to be done from my side for this pull request to be merged? I would appreciate any input here to understand the pull/merge process.
Thank you.

@antoninbas antoninbas merged commit 4ab8482 into p4lang:master Oct 30, 2017
@c3m3gyanesh c3m3gyanesh deleted the parser-graph branch October 31, 2017 08:59
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.

5 participants