Skip to content

Commit

Permalink
Revert custom lib usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Dec 13, 2024
1 parent 16925b6 commit cb4309d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 103 deletions.
2 changes: 2 additions & 0 deletions backends/tofino/bf-p4c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 45 additions & 1 deletion frontends/common/constantParsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
40 changes: 29 additions & 11 deletions ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,15 +25,41 @@ 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
visitor.cpp
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
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ir/inode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions ir/unpacker_table.h

This file was deleted.

70 changes: 0 additions & 70 deletions ir/unparsed_constant.h

This file was deleted.

4 changes: 2 additions & 2 deletions tools/ir-generator/irclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cstring, NodeFactoryFn> unpacker_table;\n"
<< "using namespace P4::literals;\n"
<< "}\n";

Expand Down

0 comments on commit cb4309d

Please sign in to comment.