From f0a52bec18adf9c5a689765a858d3e5da48a1bf1 Mon Sep 17 00:00:00 2001 From: Lin Date: Wed, 9 Oct 2024 14:15:39 +0800 Subject: [PATCH] auto generate capnp no compile error --- libs/libopenfpgacapnproto/CMakeLists.txt | 36 +---------------- .../gen/unique_blocks_uxsdcxx.capnp | 38 ++++++++++++++++++ libs/libopenfpgacapnproto/mmap_file.cpp | 39 ------------------- libs/libopenfpgacapnproto/mmap_file.h | 20 ---------- libs/libopenfpgacapnproto/serdes_utils.cpp | 23 ----------- libs/libopenfpgacapnproto/serdes_utils.h | 21 ---------- .../src/annotation/read_unique_blocks.cpp | 28 ++++++------- openfpga/src/annotation/read_unique_blocks.h | 5 +-- .../src/annotation/write_unique_blocks.cpp | 27 ++++++------- openfpga/src/annotation/write_unique_blocks.h | 4 +- 10 files changed, 71 insertions(+), 170 deletions(-) delete mode 100644 libs/libopenfpgacapnproto/mmap_file.cpp delete mode 100644 libs/libopenfpgacapnproto/mmap_file.h delete mode 100644 libs/libopenfpgacapnproto/serdes_utils.cpp delete mode 100644 libs/libopenfpgacapnproto/serdes_utils.h diff --git a/libs/libopenfpgacapnproto/CMakeLists.txt b/libs/libopenfpgacapnproto/CMakeLists.txt index da04f7ecd..c81ab82f3 100644 --- a/libs/libopenfpgacapnproto/CMakeLists.txt +++ b/libs/libopenfpgacapnproto/CMakeLists.txt @@ -17,9 +17,6 @@ if(NOT MSCV) endif() # Create generated headers from capnp schema files -# -# Each schema used should appear here. - set(CAPNP_DEFS gen/unique_blocks_uxsdcxx.capnp ) @@ -30,42 +27,13 @@ capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS -find_program(WGET wget REQUIRED) -find_package(ZLIB REQUIRED) - -# Add Java schema -set(JAVA_SCHEMA ${CMAKE_CURRENT_BINARY_DIR}/schema/capnp/java.capnp) -add_custom_command( - OUTPUT ${JAVA_SCHEMA} - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/schema/capnp/ - COMMAND ${WGET} - https://raw.githubusercontent.com/capnproto/capnproto-java/master/compiler/src/main/schema/capnp/java.capnp - -O ${JAVA_SCHEMA} -) - -add_custom_target( - get_java_capnp_schema_openfpga - DEPENDS ${JAVA_SCHEMA} -) - -set(CAPNPC_IMPORT_DIRS) -list(APPEND CAPNPC_IMPORT_DIRS ${CMAKE_CURRENT_BINARY_DIR}/schema) - - -install(FILES ${CAPNP_DEFS} DESTINATION ${CMAKE_INSTALL_DATADIR}/openfpga) - add_library(libopenfpgacapnproto STATIC ${CAPNP_SRCS} ${IC_SRCS} - mmap_file.h - mmap_file.cpp - serdes_utils.h - serdes_utils.cpp ) add_dependencies(libopenfpgacapnproto - get_java_capnp_schema_openfpga generate_unique_block_capnp ) @@ -77,7 +45,7 @@ target_include_directories(libopenfpgacapnproto PUBLIC ) target_link_libraries(libopenfpgacapnproto libopenfpgautil - CapnProto::capnp + libvtrcapnproto ) @@ -93,7 +61,7 @@ add_custom_target( unique_blocks_capnproto_generate/unique_blocks_uxsdcxx_capnp.h unique_blocks_capnproto_generate/unique_blocks_uxsdcxx_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/gen - COMMAND ${CMAKE_COMMAND} -E copy unique_blocks_capnproto_generate/unique_blocks_uxsdcxx.capnp ${CMAKE_CURRENT_SOURCE_DIR}/../libopenfpgacapnproto/gen + COMMAND ${CMAKE_COMMAND} -E copy unique_blocks_capnproto_generate/unique_blocks_uxsdcxx.capnp ${CMAKE_CURRENT_SOURCE_DIR}/gen DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen/unique_blocks.xsd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) \ No newline at end of file diff --git a/libs/libopenfpgacapnproto/gen/unique_blocks_uxsdcxx.capnp b/libs/libopenfpgacapnproto/gen/unique_blocks_uxsdcxx.capnp index e69de29bb..9c370820f 100644 --- a/libs/libopenfpgacapnproto/gen/unique_blocks_uxsdcxx.capnp +++ b/libs/libopenfpgacapnproto/gen/unique_blocks_uxsdcxx.capnp @@ -0,0 +1,38 @@ +# This file is generated by uxsdcap 0.1.0. +# https://github.com/duck2/uxsdcxx +# Modify only if your build process doesn't involve regenerating this file. +# +# Cmdline: uxsdcxx/uxsdcap.py /home/jrlin/add_feature/bin_format/OpenFPGA/libs/libopenfpgacapnproto/gen/unique_blocks.xsd unique_blocks_capnproto_generate/unique_blocks_uxsdcxx.h unique_blocks_capnproto_generate/unique_blocks_uxsdcxx_capnp.h unique_blocks_capnproto_generate/unique_blocks_uxsdcxx_interface.h /home/jrlin/add_feature/bin_format/OpenFPGA/libs/libopenfpgacapnproto/gen +# Input file: /home/jrlin/add_feature/bin_format/OpenFPGA/libs/libopenfpgacapnproto/gen/unique_blocks.xsd +# md5sum of input file: 6fd16e8f6b3530e875f67cea3044e719 + +@0xf133a161f333ac8a; +using Cxx = import "/capnp/c++.capnp"; +$Cxx.namespace("ucap"); + +enum Blocktype { + uxsdInvalid @0; + cbx @1; + cby @2; + sb @3; +} + +struct Blockinfo { + type @0 :Blocktype; + x @1 :UInt32; + y @2 :UInt32; +} + +struct Instanceinfo { + x @0 :UInt32; + y @1 :UInt32; +} + +struct Uniqueblockpacked { + blockinfo @0 :Blockinfo; + instances @1 :List(Instanceinfo); +} + +struct UniqueBlocks { + atominfos @0 :List(Uniqueblockpacked); +} diff --git a/libs/libopenfpgacapnproto/mmap_file.cpp b/libs/libopenfpgacapnproto/mmap_file.cpp deleted file mode 100644 index caa697ef7..000000000 --- a/libs/libopenfpgacapnproto/mmap_file.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "mmap_file.h" - -#include -#include - -#include "vtr_error.h" -#include "vtr_util.h" -#ifndef _WIN32 -#include -#endif -#include - -#include "kj/filesystem.h" - -MmapFile::MmapFile(const std::string& file) : size_(0) { - try { - auto fs = kj::newDiskFilesystem(); - auto path = fs->getCurrentPath().evalNative(file); - - const auto& dir = fs->getRoot(); - auto stat = dir.lstat(path); - auto f = dir.openFile(path); - size_ = stat.size; - data_ = f->mmap(0, stat.size); - } catch (kj::Exception& e) { - throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine()); - } -} - -const kj::ArrayPtr MmapFile::getData() const { - if ((size_ % sizeof(::capnp::word)) != 0) { - throw vtr::VtrError( - vtr::string_fmt("size_ %d is not a multiple of capnp::word", size_), - __FILE__, __LINE__); - } - - return kj::arrayPtr(reinterpret_cast(data_.begin()), - size_ / sizeof(::capnp::word)); -} diff --git a/libs/libopenfpgacapnproto/mmap_file.h b/libs/libopenfpgacapnproto/mmap_file.h deleted file mode 100644 index 4b3d0ff25..000000000 --- a/libs/libopenfpgacapnproto/mmap_file.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MMAP_FILE_H_ -#define MMAP_FILE_H_ - -#include - -#include "capnp/message.h" -#include "kj/array.h" - -// Platform independent mmap, useful for reading large capnp's. -class MmapFile { - public: - explicit MmapFile(const std::string& file); - const kj::ArrayPtr getData() const; - - private: - size_t size_; - kj::Array data_; -}; - -#endif /* MMAP_FILE_H_ */ diff --git a/libs/libopenfpgacapnproto/serdes_utils.cpp b/libs/libopenfpgacapnproto/serdes_utils.cpp deleted file mode 100644 index 88d84a455..000000000 --- a/libs/libopenfpgacapnproto/serdes_utils.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "serdes_utils.h" - -#include -#include - -#include "kj/filesystem.h" -#include "vtr_error.h" - -void writeMessageToFile(const std::string& file, - ::capnp::MessageBuilder* builder) { - try { - auto fs = kj::newDiskFilesystem(); - auto path = fs->getCurrentPath().evalNative(file); - - const auto& dir = fs->getRoot(); - auto f = dir.openFile(path, kj::WriteMode::CREATE | kj::WriteMode::MODIFY); - f->truncate(0); - auto f_app = kj::newFileAppender(std::move(f)); - capnp::writeMessage(*f_app, *builder); - } catch (kj::Exception& e) { - throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine()); - } -} diff --git a/libs/libopenfpgacapnproto/serdes_utils.h b/libs/libopenfpgacapnproto/serdes_utils.h deleted file mode 100644 index 0c961d314..000000000 --- a/libs/libopenfpgacapnproto/serdes_utils.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SERDES_UTILS_H_ -#define SERDES_UTILS_H_ - -#include -#include - -#include "capnp/serialize.h" - -// Platform indepedent way to file message to a file on disk. -void writeMessageToFile(const std::string& file, - ::capnp::MessageBuilder* builder); - -inline ::capnp::ReaderOptions default_large_capnp_opts() { - ::capnp::ReaderOptions opts = ::capnp::ReaderOptions(); - - /* Remove traversal limit */ - opts.traversalLimitInWords = std::numeric_limits::max(); - return opts; -} - -#endif /* SERDES_UTILS_H_ */ diff --git a/openfpga/src/annotation/read_unique_blocks.cpp b/openfpga/src/annotation/read_unique_blocks.cpp index 8e390279e..b8a0bef09 100644 --- a/openfpga/src/annotation/read_unique_blocks.cpp +++ b/openfpga/src/annotation/read_unique_blocks.cpp @@ -162,10 +162,10 @@ int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, /*read the instances' coordinate of a unique block from a bin file*/ std::vector> read_bin_unique_instance_coords( - const uniqueblockcap::UniqueBlockPacked::Reader& unique_block) { + const ucap::Uniqueblockpacked::Reader& unique_block) { std::vector> instance_coords; - if (unique_block.hasInstanceList()) { - auto instance_list = unique_block.getInstanceList(); + if (unique_block.hasInstances()) { + auto instance_list = unique_block.getInstances(); for (auto instance : instance_list) { int instance_x = instance.getX(); int instance_y = instance.getY(); @@ -178,9 +178,8 @@ std::vector> read_bin_unique_instance_coords( /*read the unique block coordinate from a bin file */ vtr::Point read_bin_unique_block_coord( - const uniqueblockcap::UniqueBlockPacked::Reader& unique_block, - uniqueblockcap::BlockType& type) { - auto block_info = unique_block.getBlockInfo(); + const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type) { + auto block_info = unique_block.getBlockinfo(); int block_x = block_info.getX(); int block_y = block_info.getY(); type = block_info.getType(); @@ -196,11 +195,11 @@ int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, device_rr_gsb.reserve_unique_modules(); MmapFile f(file_name); ::capnp::FlatArrayMessageReader reader(f.getData()); - auto root = reader.getRoot(); - if (root.hasAtomInfo()) { - auto block_list = root.getAtomInfo(); + auto root = reader.getRoot(); + if (root.hasAtominfos()) { + auto block_list = root.getAtominfos(); for (auto unique_block : block_list) { - uniqueblockcap::BlockType type; + ucap::Blocktype type; vtr::Point block_coordinate = read_bin_unique_block_coord( unique_block, type); /*get block coordinate and type*/ std::vector> instance_coords = @@ -208,15 +207,18 @@ int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, unique_block); /* get a list of instance coordinates*/ /* get block coordinate and instance coordinate, try to setup * device_rr_gsb */ - if (type == uniqueblockcap::BlockType::SB) { + if (type == ucap::Blocktype::SB) { device_rr_gsb.preload_unique_sb_module(block_coordinate, instance_coords); - } else if (type == uniqueblockcap::BlockType::CBY) { + } else if (type == ucap::Blocktype::CBY) { device_rr_gsb.preload_unique_cby_module(block_coordinate, instance_coords); - } else if (type == uniqueblockcap::BlockType::CBX) { + } else if (type == ucap::Blocktype::CBX) { device_rr_gsb.preload_unique_cbx_module(block_coordinate, instance_coords); + } else if (type == ucap::Blocktype::UXSD_INVALID) { + VTR_LOG_ERROR("Invalid block type!"); + return CMD_EXEC_FATAL_ERROR; } } } diff --git a/openfpga/src/annotation/read_unique_blocks.h b/openfpga/src/annotation/read_unique_blocks.h index 84f81502b..a65c54ac3 100644 --- a/openfpga/src/annotation/read_unique_blocks.h +++ b/openfpga/src/annotation/read_unique_blocks.h @@ -37,11 +37,10 @@ int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, bool verbose_output); std::vector> read_bin_unique_instance_coords( - const uniqueblockcap::UniqueBlockPacked::Reader& unique_block); + const ucap::Uniqueblockpacked::Reader& unique_block); vtr::Point read_bin_unique_block_coord( - const uniqueblockcap::UniqueBlockPacked::Reader& unique_block, - uniqueblockcap::BlockType& type); + const ucap::Uniqueblockpacked::Reader& unique_block, ucap::Blocktype& type); int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name, bool verbose_output); diff --git a/openfpga/src/annotation/write_unique_blocks.cpp b/openfpga/src/annotation/write_unique_blocks.cpp index 0ea960ffc..d4e9e1555 100644 --- a/openfpga/src/annotation/write_unique_blocks.cpp +++ b/openfpga/src/annotation/write_unique_blocks.cpp @@ -189,14 +189,14 @@ int write_xml_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, * instances' info)into capnp builder */ int write_bin_atom_block(const std::vector>& instance_map, const vtr::Point& unique_block_coord, - const uniqueblockcap::BlockType type, - uniqueblockcap::UniqueBlockPacked::Builder& root) { - auto block_info = root.initBlockInfo(); + const ucap::Blocktype type, + ucap::Uniqueblockpacked::Builder& root) { + auto block_info = root.initBlockinfo(); block_info.setX(unique_block_coord.x()); block_info.setY(unique_block_coord.y()); block_info.setType(type); if (instance_map.size() > 0) { - auto instance_list = root.initInstanceList(instance_map.size()); + auto instance_list = root.initInstances(instance_map.size()); for (size_t instance_id = 0; instance_id < instance_map.size(); instance_id++) { auto instance = instance_list[instance_id]; @@ -211,11 +211,11 @@ int write_bin_atom_block(const std::vector>& instance_map, int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, bool verbose_output) { ::capnp::MallocMessageBuilder builder; - auto unique_blocks = builder.initRoot(); + auto unique_blocks = builder.initRoot(); int num_unique_blocks = device_rr_gsb.get_num_sb_unique_module() + device_rr_gsb.get_num_cb_unique_module(CHANX) + device_rr_gsb.get_num_cb_unique_module(CHANY); - auto block_list = unique_blocks.initAtomInfo(num_unique_blocks); + auto block_list = unique_blocks.initAtominfos(num_unique_blocks); /*write switch blocks into bin file */ for (size_t id = 0; id < device_rr_gsb.get_num_sb_unique_module(); ++id) { @@ -223,9 +223,8 @@ int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, const std::vector> instance_map = device_rr_gsb.get_sb_unique_block_instance_coord(unique_block_coord); auto unique_block = block_list[id]; - int status_code = - write_bin_atom_block(instance_map, unique_block_coord, - uniqueblockcap::BlockType::SB, unique_block); + int status_code = write_bin_atom_block(instance_map, unique_block_coord, + ucap::Blocktype::SB, unique_block); if (status_code != 0) { VTR_LOG_ERROR("write sb unique blocks into bin file failed!"); return CMD_EXEC_FATAL_ERROR; @@ -241,9 +240,8 @@ int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, device_rr_gsb.get_cbx_unique_block_instance_coord(unique_block_coord); int block_id = id + device_rr_gsb.get_num_sb_unique_module(); auto unique_block = block_list[block_id]; - int status_code = - write_bin_atom_block(instance_map, unique_block_coord, - uniqueblockcap::BlockType::CBX, unique_block); + int status_code = write_bin_atom_block(instance_map, unique_block_coord, + ucap::Blocktype::CBX, unique_block); if (status_code != 0) { VTR_LOG_ERROR("write cbx unique blocks into bin file failed!"); return CMD_EXEC_FATAL_ERROR; @@ -260,9 +258,8 @@ int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, int block_id = id + device_rr_gsb.get_num_sb_unique_module() + device_rr_gsb.get_num_cb_unique_module(CHANX); auto unique_block = block_list[block_id]; - int status_code = - write_bin_atom_block(instance_map, unique_block_coord, - uniqueblockcap::BlockType::CBY, unique_block); + int status_code = write_bin_atom_block(instance_map, unique_block_coord, + ucap::Blocktype::CBY, unique_block); if (status_code != 0) { VTR_LOG_ERROR("write cby unique blocks into bin file failed!"); return CMD_EXEC_FATAL_ERROR; diff --git a/openfpga/src/annotation/write_unique_blocks.h b/openfpga/src/annotation/write_unique_blocks.h index 6b56c67ff..d6f69e021 100644 --- a/openfpga/src/annotation/write_unique_blocks.h +++ b/openfpga/src/annotation/write_unique_blocks.h @@ -37,7 +37,7 @@ int write_bin_unique_blocks(const DeviceRRGSB& device_rr_gsb, const char* fname, bool verbose_output); int write_bin_atom_block(const std::vector>& instance_map, const vtr::Point& unique_block_coord, - const uniqueblockcap::BlockType type, - uniqueblockcap::UniqueBlockPacked::Builder& root); + const ucap::Blocktype type, + ucap::Uniqueblockpacked::Builder& root); } // namespace openfpga #endif