auto generate capnp no compile error
This commit is contained in:
parent
03ccfa1b6c
commit
f0a52bec18
|
@ -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}
|
||||
)
|
|
@ -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);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
#include "mmap_file.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "vtr_error.h"
|
||||
#include "vtr_util.h"
|
||||
#ifndef _WIN32
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
|
||||
#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<const ::capnp::word> 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<const ::capnp::word*>(data_.begin()),
|
||||
size_ / sizeof(::capnp::word));
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef MMAP_FILE_H_
|
||||
#define MMAP_FILE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#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<const ::capnp::word> getData() const;
|
||||
|
||||
private:
|
||||
size_t size_;
|
||||
kj::Array<const kj::byte> data_;
|
||||
};
|
||||
|
||||
#endif /* MMAP_FILE_H_ */
|
|
@ -1,23 +0,0 @@
|
|||
#include "serdes_utils.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
#ifndef SERDES_UTILS_H_
|
||||
#define SERDES_UTILS_H_
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#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<uint64_t>::max();
|
||||
return opts;
|
||||
}
|
||||
|
||||
#endif /* SERDES_UTILS_H_ */
|
|
@ -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<vtr::Point<size_t>> read_bin_unique_instance_coords(
|
||||
const uniqueblockcap::UniqueBlockPacked::Reader& unique_block) {
|
||||
const ucap::Uniqueblockpacked::Reader& unique_block) {
|
||||
std::vector<vtr::Point<size_t>> 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<vtr::Point<size_t>> read_bin_unique_instance_coords(
|
|||
|
||||
/*read the unique block coordinate from a bin file */
|
||||
vtr::Point<size_t> 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<uniqueblockcap::UniqueBlocks>();
|
||||
if (root.hasAtomInfo()) {
|
||||
auto block_list = root.getAtomInfo();
|
||||
auto root = reader.getRoot<ucap::UniqueBlocks>();
|
||||
if (root.hasAtominfos()) {
|
||||
auto block_list = root.getAtominfos();
|
||||
for (auto unique_block : block_list) {
|
||||
uniqueblockcap::BlockType type;
|
||||
ucap::Blocktype type;
|
||||
vtr::Point<size_t> block_coordinate = read_bin_unique_block_coord(
|
||||
unique_block, type); /*get block coordinate and type*/
|
||||
std::vector<vtr::Point<size_t>> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,11 +37,10 @@ int read_xml_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
|||
bool verbose_output);
|
||||
|
||||
std::vector<vtr::Point<size_t>> read_bin_unique_instance_coords(
|
||||
const uniqueblockcap::UniqueBlockPacked::Reader& unique_block);
|
||||
const ucap::Uniqueblockpacked::Reader& unique_block);
|
||||
|
||||
vtr::Point<size_t> 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);
|
||||
|
|
|
@ -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<vtr::Point<size_t>>& instance_map,
|
||||
const vtr::Point<size_t>& 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<vtr::Point<size_t>>& 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<uniqueblockcap::UniqueBlocks>();
|
||||
auto unique_blocks = builder.initRoot<ucap::UniqueBlocks>();
|
||||
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<vtr::Point<size_t>> 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;
|
||||
|
|
|
@ -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<vtr::Point<size_t>>& instance_map,
|
||||
const vtr::Point<size_t>& unique_block_coord,
|
||||
const uniqueblockcap::BlockType type,
|
||||
uniqueblockcap::UniqueBlockPacked::Builder& root);
|
||||
const ucap::Blocktype type,
|
||||
ucap::Uniqueblockpacked::Builder& root);
|
||||
} // namespace openfpga
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue