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

Make the Tofino spec files independent of the generated IR. #5063

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fruffy
Copy link
Collaborator

@fruffy fruffy commented Dec 13, 2024

This makes it possible to depend on these files without pulling in the entire compiler. The advantages of this separation is a mid end that does not depend on the Tofino back end and the ability of other tools (primarily P4Testgen) to link into certain Tofino files.

@fruffy fruffy added the tofino Topics related to the Tofino switch and back end. label Dec 13, 2024
@fruffy fruffy force-pushed the fruffy/tofino_specs branch 2 times, most recently from e1813de to 8aae242 Compare December 13, 2024 19:04
ir/inode.h Outdated
return result;
}

DECLARE_TYPEINFO(INode);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@asl I have a question on the RTTI macros. I am trying to factor out some classes to avoid pulling in the entire IR code. Unfortunately, for IDeclaration and INode macros like DECLARE_TYPEINFO_WITH_TYPEID(INode, NodeKind::INode); require pulling in ir/ir-tree-macros.h which is generated.

Is there a way to avoid this while still being correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, the typeid's should be unique. It is part of gen-tree-macro.h. The location is a bit weird, but it was emitted there exactly in order not to pull the whole IR header. It could be even split into separate .h file if gen-tree-macro.h is undesired.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, gen-tree-macro depends on the generator which is a little unpleasant. Although the code there is less complex than what is being put into ir-generated.h.
You effectively run into #5013.

Maybe there is a way to depend on gen-tree or just the rtti enum.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, one way to do this is to split enum into "static" and "generated" parts. Static would be for all classes not autogenerated (INode, IDeclaration, Vector), etc. and everything else will be outside the scope.

<< "#include \"ir/vector.h\" // IWYU pragma: keep\n"
<< "#include \"lib/ordered_map.h\" // IWYU pragma: keep\n"
<< std::endl
<< "namespace P4 {\n"
<< std::endl
<< "class JSONLoader;\n"
<< "using NodeFactoryFn = IR::Node*(*)(JSONLoader&);\n"
<< "using NodeFactoryFn = IR::INode*(*)(JSONLoader&);\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks a bit weird. After all, interface is a property of the object, there is no way to "materialize" pure interface w/o underlying object. But factory produces definite objects, not abstract interfaces, so should be Node here...

@fruffy fruffy force-pushed the fruffy/tofino_specs branch 2 times, most recently from cb4309d to 71eb3a4 Compare December 15, 2024 11:01
Signed-off-by: fruffy <fruffy@nyu.edu>
Signed-off-by: fruffy <fruffy@nyu.edu>
@fruffy fruffy force-pushed the fruffy/tofino_specs branch from 71eb3a4 to 4449f61 Compare December 15, 2024 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tofino Topics related to the Tofino switch and back end.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants