From 4449f619478bc62defb62e10ae56ee9d0f8144a2 Mon Sep 17 00:00:00 2001 From: fruffy Date: Fri, 13 Dec 2024 15:34:17 +0100 Subject: [PATCH] Revert custom lib usage. Signed-off-by: fruffy --- backends/tofino/bf-p4c/CMakeLists.txt | 2 + frontends/common/constantParsing.h | 46 +++++++++++++++++- ir/CMakeLists.txt | 40 ++++++++++----- ir/inode.h | 3 +- ir/unpacker_table.h | 18 ------- ir/unparsed_constant.h | 70 --------------------------- tools/ir-generator/irclass.cpp | 4 +- 7 files changed, 80 insertions(+), 103 deletions(-) delete mode 100644 ir/unpacker_table.h delete mode 100644 ir/unparsed_constant.h diff --git a/backends/tofino/bf-p4c/CMakeLists.txt b/backends/tofino/bf-p4c/CMakeLists.txt index 01c3565346a..18a5e56c272 100644 --- a/backends/tofino/bf-p4c/CMakeLists.txt +++ b/backends/tofino/bf-p4c/CMakeLists.txt @@ -102,6 +102,8 @@ set (BF_P4C_SPEC_SRCS add_library(tofinospecs STATIC ${BF_P4C_SPEC_SRCS}) target_link_libraries(tofinospecs PUBLIC p4ctoolkit) +# We depend on the gen-tree-macro.h file, which is generated. +add_dependencies(tofinospecs genIR) set (BF_P4C_MIDEND_SRCS midend/annotate_with_in_hash.cpp diff --git a/frontends/common/constantParsing.h b/frontends/common/constantParsing.h index 37a4a4bfdf7..b2d4c5376ff 100644 --- a/frontends/common/constantParsing.h +++ b/frontends/common/constantParsing.h @@ -17,7 +17,7 @@ limitations under the License. #ifndef FRONTENDS_COMMON_CONSTANTPARSING_H_ #define FRONTENDS_COMMON_CONSTANTPARSING_H_ -#include "ir/unparsed_constant.h" +#include "lib/cstring.h" namespace P4::IR { class Constant; @@ -29,6 +29,50 @@ class SourceInfo; namespace P4 { +/** + * An unparsed numeric constant. We produce these as token values during + * lexing. The parser is responsible for actually interpreting the raw text as a + * numeric value and transforming it into an IR::Constant using parseConstant(). + * + * To illustrate how a numeric constant is represented using this struct, + * here is a breakdown of '16w0x12': + * + * ___ + * / ___ + * | / + * | bitwidth (if @hasWidth) | 16 + * | \___ + * | + * | ___ + * | / + * | separator (if @hasWidth) | w + * | \___ + * @text | + * | ___ + * | / + * | ignored prefix of length @skip | 0x + * | \___ + * | + * | ___ + * | / + * | numeric value in base @base | w + * | \___ + * \___ + * + * Simple numeric constants like '5' are specified by setting @hasWidth to + * false and providing a @skip length of 0. + */ +struct UnparsedConstant { + cstring text; /// Raw P4 text which was recognized as a numeric constant. + unsigned skip; /// An ignored prefix of the numeric constant (e.g. '0x'). + unsigned base; /// The base in which the constant is expressed. + bool hasWidth; /// If true, a bitwidth and separator are present. +}; + +std::ostream &operator<<(std::ostream &out, const UnparsedConstant &constant); + +bool operator<(const UnparsedConstant &a, const UnparsedConstant &b); + /** * Parses an UnparsedConstant @constant into an IR::Constant object, with * location information taken from @srcInfo. If parsing fails, an IR::Constant diff --git a/ir/CMakeLists.txt b/ir/CMakeLists.txt index 31e31892372..242f6d104c9 100644 --- a/ir/CMakeLists.txt +++ b/ir/CMakeLists.txt @@ -12,18 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -set (IR_LIB_SRCS - bitrange.cpp - json_parser.cpp -) - -add_library (ir_lib STATIC ${IR_LIB_SRCS}) -target_link_libraries(ir_lib PRIVATE p4ctoolkit absl::flat_hash_map ${LIBGC_LIBRARIES}) - - set (IR_SRCS annotations.cpp base.cpp + bitrange.cpp dbprint.cpp dbprint-expression.cpp dbprint-stmt.cpp @@ -33,8 +25,9 @@ set (IR_SRCS expression.cpp ir.cpp irutils.cpp - node.cpp + json_parser.cpp loop-visitor.cpp + node.cpp pass_manager.cpp pass_utils.cpp type.cpp @@ -42,6 +35,31 @@ set (IR_SRCS write_context.cpp ) +set (IR_HDRS + annotations.h + configuration.h + dbprint.h + dump.h + id.h + indexed_vector.h + ir-inline.h + ir-tree-macros.h + ir.h + ir-traversal.h + ir-traversal-internal.h + irutils.h + json_generator.h + json_loader.h + json_parser.h + namemap.h + node.h + nodemap.h + pass_manager.h + pass_utils.h + vector.h + visitor.h +) + set (BASE_IR_DEF_FILES ${CMAKE_CURRENT_SOURCE_DIR}/base.def ${CMAKE_CURRENT_SOURCE_DIR}/type.def @@ -52,7 +70,7 @@ set (BASE_IR_DEF_FILES set (IR_DEF_FILES ${IR_DEF_FILES} ${BASE_IR_DEF_FILES} PARENT_SCOPE) add_library (ir STATIC ${IR_SRCS}) -target_link_libraries(ir PUBLIC ir_lib PRIVATE absl::flat_hash_map ${LIBGC_LIBRARIES}) +target_link_libraries(ir PRIVATE absl::flat_hash_map ${LIBGC_LIBRARIES}) add_dependencies(ir genIR) diff --git a/ir/inode.h b/ir/inode.h index 6f39d1a062a..fd9da360c1a 100644 --- a/ir/inode.h +++ b/ir/inode.h @@ -17,6 +17,7 @@ limitations under the License. #ifndef IR_INODE_H_ #define IR_INODE_H_ +#include "ir/gen-tree-macro.h" #include "lib/castable.h" #include "lib/cstring.h" #include "lib/exceptions.h" @@ -69,7 +70,7 @@ class INode : public Util::IHasSourceInfo, public IHasDbPrint, public ICastable return result; } - DECLARE_TYPEINFO(INode); + DECLARE_TYPEINFO_WITH_TYPEID(INode, NodeKind::INode); }; } // namespace P4::IR diff --git a/ir/unpacker_table.h b/ir/unpacker_table.h deleted file mode 100644 index 1c88aea176b..00000000000 --- a/ir/unpacker_table.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef IR_UNPACKER_TABLE_H_ -#define IR_UNPACKER_TABLE_H_ - -#include "ir/inode.h" -#include "lib/cstring.h" - -namespace P4 { -class JSONLoader; - -using NodeFactoryFn = IR::INode *(*)(JSONLoader &); -namespace IR { -extern std::map unpacker_table; - -} // namespace IR - -} // namespace P4 - -#endif /* IR_UNPACKER_TABLE_H_ */ diff --git a/ir/unparsed_constant.h b/ir/unparsed_constant.h deleted file mode 100644 index b5adaf871d1..00000000000 --- a/ir/unparsed_constant.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -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. -*/ - -#ifndef IR_UNPARSED_CONSTANT_H_ -#define IR_UNPARSED_CONSTANT_H_ - -#include "lib/cstring.h" - -namespace P4 { - -/** - * An unparsed numeric constant. We produce these as token values during - * lexing. The parser is responsible for actually interpreting the raw text as a - * numeric value and transforming it into an IR::Constant using parseConstant(). - * - * To illustrate how a numeric constant is represented using this struct, - * here is a breakdown of '16w0x12': - * - * ___ - * / ___ - * | / - * | bitwidth (if @hasWidth) | 16 - * | \___ - * | - * | ___ - * | / - * | separator (if @hasWidth) | w - * | \___ - * @text | - * | ___ - * | / - * | ignored prefix of length @skip | 0x - * | \___ - * | - * | ___ - * | / - * | numeric value in base @base | w - * | \___ - * \___ - * - * Simple numeric constants like '5' are specified by setting @hasWidth to - * false and providing a @skip length of 0. - */ -struct UnparsedConstant { - cstring text; /// Raw P4 text which was recognized as a numeric constant. - unsigned skip; /// An ignored prefix of the numeric constant (e.g. '0x'). - unsigned base; /// The base in which the constant is expressed. - bool hasWidth; /// If true, a bitwidth and separator are present. -}; - -std::ostream &operator<<(std::ostream &out, const UnparsedConstant &constant); - -bool operator<(const UnparsedConstant &a, const UnparsedConstant &b); - -} // namespace P4 - -#endif /* IR_UNPARSED_CONSTANT_H_ */ diff --git a/tools/ir-generator/irclass.cpp b/tools/ir-generator/irclass.cpp index 59e1449facd..013ca5d48dd 100644 --- a/tools/ir-generator/irclass.cpp +++ b/tools/ir-generator/irclass.cpp @@ -131,16 +131,16 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i << "#include \"ir/namemap.h\" // IWYU pragma: keep\n" << "#include \"ir/node.h\" // IWYU pragma: keep\n" << "#include \"ir/nodemap.h\" // IWYU pragma: keep\n" - << "#include \"ir/unpacker_table.h\" // IWYU pragma: keep\n" << "#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::INode*(*)(JSONLoader&);\n" + << "using NodeFactoryFn = IR::Node*(*)(JSONLoader&);\n" << std::endl << "namespace IR {\n" + << "extern std::map unpacker_table;\n" << "using namespace P4::literals;\n" << "}\n";