-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a pass which converts struct expressions with Type_Header to head…
…er expressions.
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
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
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,24 @@ | ||
#include "backends/p4tools/common/compiler/convert_struct_expr.h" | ||
|
||
#include "ir/irutils.h" | ||
|
||
namespace P4Tools { | ||
|
||
const IR::Node *ConvertStructExpr::postorder(IR::StructExpression *expr) { | ||
auto structType = expr->type; | ||
if (structType->is<IR::Type_Name>()) { | ||
structType = typeMap->getTypeType(structType, true); | ||
} | ||
if (structType->is<IR::Type_Header>()) { | ||
auto structExpr = expr->to<IR::StructExpression>(); | ||
return new IR::HeaderExpression(structExpr->srcInfo, expr->type, expr->type, | ||
structExpr->components, IR::getBoolLiteral(true)); | ||
} | ||
return expr; | ||
} | ||
|
||
ConvertStructExpr::ConvertStructExpr(const P4::TypeMap *typeMap) : typeMap(typeMap) { | ||
setName("ConvertStructExpr"); | ||
visitDagOnce = false; | ||
} | ||
} // namespace P4Tools |
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,23 @@ | ||
#ifndef BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_STRUCT_EXPR_H_ | ||
#define BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_STRUCT_EXPR_H_ | ||
|
||
#include "frontends/p4/typeMap.h" | ||
#include "ir/ir.h" | ||
#include "ir/node.h" | ||
#include "ir/visitor.h" | ||
|
||
namespace P4Tools { | ||
|
||
class ConvertStructExpr : public Transform { | ||
private: | ||
const P4::TypeMap *typeMap; | ||
|
||
public: | ||
explicit ConvertStructExpr(const P4::TypeMap *typeMap); | ||
|
||
const IR::Node *postorder(IR::StructExpression *expr) override; | ||
}; | ||
|
||
} // namespace P4Tools | ||
|
||
#endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_STRUCT_EXPR_H_ */ |
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