read bin format mod (with bug)
This commit is contained in:
parent
59f1e4adc9
commit
ed381692a7
|
@ -1,39 +1,39 @@
|
||||||
#include "mmap_file.h"
|
#include "mmap_file.h"
|
||||||
#include "vtr_error.h"
|
|
||||||
#include "vtr_util.h"
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "vtr_error.h"
|
||||||
|
#include "vtr_util.h"
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "kj/filesystem.h"
|
#include "kj/filesystem.h"
|
||||||
|
|
||||||
MmapFile::MmapFile(const std::string& file)
|
MmapFile::MmapFile(const std::string& file) : size_(0) {
|
||||||
: size_(0) {
|
try {
|
||||||
try {
|
auto fs = kj::newDiskFilesystem();
|
||||||
auto fs = kj::newDiskFilesystem();
|
auto path = fs->getCurrentPath().evalNative(file);
|
||||||
auto path = fs->getCurrentPath().evalNative(file);
|
|
||||||
|
|
||||||
const auto& dir = fs->getRoot();
|
const auto& dir = fs->getRoot();
|
||||||
auto stat = dir.lstat(path);
|
auto stat = dir.lstat(path);
|
||||||
auto f = dir.openFile(path);
|
auto f = dir.openFile(path);
|
||||||
size_ = stat.size;
|
size_ = stat.size;
|
||||||
data_ = f->mmap(0, stat.size);
|
data_ = f->mmap(0, stat.size);
|
||||||
} catch (kj::Exception& e) {
|
} catch (kj::Exception& e) {
|
||||||
throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine());
|
throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const kj::ArrayPtr<const ::capnp::word> MmapFile::getData() const {
|
const kj::ArrayPtr<const ::capnp::word> MmapFile::getData() const {
|
||||||
if ((size_ % sizeof(::capnp::word)) != 0) {
|
if ((size_ % sizeof(::capnp::word)) != 0) {
|
||||||
throw vtr::VtrError(
|
throw vtr::VtrError(
|
||||||
vtr::string_fmt("size_ %d is not a multiple of capnp::word", size_),
|
vtr::string_fmt("size_ %d is not a multiple of capnp::word", size_),
|
||||||
__FILE__, __LINE__);
|
__FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
return kj::arrayPtr(reinterpret_cast<const ::capnp::word*>(data_.begin()),
|
return kj::arrayPtr(reinterpret_cast<const ::capnp::word*>(data_.begin()),
|
||||||
size_ / sizeof(::capnp::word));
|
size_ / sizeof(::capnp::word));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,18 +2,19 @@
|
||||||
#define MMAP_FILE_H_
|
#define MMAP_FILE_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "capnp/message.h"
|
#include "capnp/message.h"
|
||||||
#include "kj/array.h"
|
#include "kj/array.h"
|
||||||
|
|
||||||
// Platform independent mmap, useful for reading large capnp's.
|
// Platform independent mmap, useful for reading large capnp's.
|
||||||
class MmapFile {
|
class MmapFile {
|
||||||
public:
|
public:
|
||||||
explicit MmapFile(const std::string& file);
|
explicit MmapFile(const std::string& file);
|
||||||
const kj::ArrayPtr<const ::capnp::word> getData() const;
|
const kj::ArrayPtr<const ::capnp::word> getData() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t size_;
|
size_t size_;
|
||||||
kj::Array<const kj::byte> data_;
|
kj::Array<const kj::byte> data_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MMAP_FILE_H_ */
|
#endif /* MMAP_FILE_H_ */
|
||||||
|
|
|
@ -3,20 +3,21 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "vtr_error.h"
|
|
||||||
#include "kj/filesystem.h"
|
#include "kj/filesystem.h"
|
||||||
|
#include "vtr_error.h"
|
||||||
|
|
||||||
void writeMessageToFile(const std::string& file, ::capnp::MessageBuilder* builder) {
|
void writeMessageToFile(const std::string& file,
|
||||||
try {
|
::capnp::MessageBuilder* builder) {
|
||||||
auto fs = kj::newDiskFilesystem();
|
try {
|
||||||
auto path = fs->getCurrentPath().evalNative(file);
|
auto fs = kj::newDiskFilesystem();
|
||||||
|
auto path = fs->getCurrentPath().evalNative(file);
|
||||||
|
|
||||||
const auto& dir = fs->getRoot();
|
const auto& dir = fs->getRoot();
|
||||||
auto f = dir.openFile(path, kj::WriteMode::CREATE | kj::WriteMode::MODIFY);
|
auto f = dir.openFile(path, kj::WriteMode::CREATE | kj::WriteMode::MODIFY);
|
||||||
f->truncate(0);
|
f->truncate(0);
|
||||||
auto f_app = kj::newFileAppender(std::move(f));
|
auto f_app = kj::newFileAppender(std::move(f));
|
||||||
capnp::writeMessage(*f_app, *builder);
|
capnp::writeMessage(*f_app, *builder);
|
||||||
} catch (kj::Exception& e) {
|
} catch (kj::Exception& e) {
|
||||||
throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine());
|
throw vtr::VtrError(e.getDescription().cStr(), e.getFile(), e.getLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,19 @@
|
||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "capnp/serialize.h"
|
#include "capnp/serialize.h"
|
||||||
|
|
||||||
// Platform indepedent way to file message to a file on disk.
|
// Platform indepedent way to file message to a file on disk.
|
||||||
void writeMessageToFile(const std::string& file,
|
void writeMessageToFile(const std::string& file,
|
||||||
::capnp::MessageBuilder* builder);
|
::capnp::MessageBuilder* builder);
|
||||||
|
|
||||||
inline ::capnp::ReaderOptions default_large_capnp_opts() {
|
inline ::capnp::ReaderOptions default_large_capnp_opts() {
|
||||||
::capnp::ReaderOptions opts = ::capnp::ReaderOptions();
|
::capnp::ReaderOptions opts = ::capnp::ReaderOptions();
|
||||||
|
|
||||||
/* Remove traversal limit */
|
/* Remove traversal limit */
|
||||||
opts.traversalLimitInWords = std::numeric_limits<uint64_t>::max();
|
opts.traversalLimitInWords = std::numeric_limits<uint64_t>::max();
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SERDES_UTILS_H_ */
|
#endif /* SERDES_UTILS_H_ */
|
||||||
|
|
|
@ -116,7 +116,7 @@ std::vector<vtr::Point<size_t>> DeviceRRGSB::get_sb_unique_block_instance_coord(
|
||||||
sb_unique_module_id_[location_x][location_y];
|
sb_unique_module_id_[location_x][location_y];
|
||||||
if (unique_module_id_instance == unique_module_id) {
|
if (unique_module_id_instance == unique_module_id) {
|
||||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||||
if (instance_coord != unique_block_coord){
|
if (instance_coord != unique_block_coord) {
|
||||||
instance_map.push_back(instance_coord);
|
instance_map.push_back(instance_coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ DeviceRRGSB::get_cbx_unique_block_instance_coord(
|
||||||
cbx_unique_module_id_[location_x][location_y];
|
cbx_unique_module_id_[location_x][location_y];
|
||||||
if (unique_module_id_instance == unique_module_id) {
|
if (unique_module_id_instance == unique_module_id) {
|
||||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||||
if (instance_coord != unique_block_coord){
|
if (instance_coord != unique_block_coord) {
|
||||||
instance_map.push_back(instance_coord);
|
instance_map.push_back(instance_coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ DeviceRRGSB::get_cby_unique_block_instance_coord(
|
||||||
cby_unique_module_id_[location_x][location_y];
|
cby_unique_module_id_[location_x][location_y];
|
||||||
if (unique_module_id_instance == unique_module_id) {
|
if (unique_module_id_instance == unique_module_id) {
|
||||||
vtr::Point<size_t> instance_coord(location_x, location_y);
|
vtr::Point<size_t> instance_coord(location_x, location_y);
|
||||||
if (instance_coord != unique_block_coord){
|
if (instance_coord != unique_block_coord) {
|
||||||
instance_map.push_back(instance_coord);
|
instance_map.push_back(instance_coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,21 +197,10 @@ int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
||||||
if (root.hasAtomInfo()) {
|
if (root.hasAtomInfo()) {
|
||||||
auto block_list = root.getAtomInfo();
|
auto block_list = root.getAtomInfo();
|
||||||
for (auto unqiue_block : block_list) {
|
for (auto unqiue_block : block_list) {
|
||||||
auto block_info = unique_block.getBlockInfo();
|
vtr::Point<size_t> block_coordinate =
|
||||||
std::string type = block_info.getType().Cstr();
|
read_bin_unique_block_coord(unique_block);
|
||||||
int block_x = block_info.getX();
|
std::vector<vtr::Point<size_t>> instance_coords =
|
||||||
int block_y = block_info.getY();
|
read_bin_unique_instance_coords(unique_block);
|
||||||
vtr::Point<size_t> block_coordinate(block_x, block_y);
|
|
||||||
if (unique_block.hasInstanceList()) {
|
|
||||||
auto instance_list = unique_block.getInstanceList();
|
|
||||||
std::vector<vtr::Point<size_t>> instance_coords;
|
|
||||||
for (auto instance : instance_list) {
|
|
||||||
int instance_x = instance.getX();
|
|
||||||
int instance_y = instance.getY();
|
|
||||||
vtr::Point<size_t> instance_coordinate(instance_x, instance_y);
|
|
||||||
instance_coords.push_back(instance_coordinate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* get block coordinate and instance coordinate, try to setup
|
/* get block coordinate and instance coordinate, try to setup
|
||||||
* device_rr_gsb */
|
* device_rr_gsb */
|
||||||
if (type == "sb") {
|
if (type == "sb") {
|
||||||
|
|
|
@ -43,7 +43,7 @@ vtr::Point<size_t> read_bin_unique_block_coord(
|
||||||
const uniqueblockcap::BlockInfo::Reader& unique_block);
|
const uniqueblockcap::BlockInfo::Reader& unique_block);
|
||||||
|
|
||||||
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
||||||
bool verbose_output)
|
bool verbose_output);
|
||||||
} // namespace openfpga
|
} // namespace openfpga
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -56,8 +56,7 @@ int write_xml_atom_block(std::fstream& fp,
|
||||||
write_xml_attribute(fp, "y", instance_info.y());
|
write_xml_attribute(fp, "y", instance_info.y());
|
||||||
|
|
||||||
fp << "/>"
|
fp << "/>"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
openfpga::write_tab_to_file(fp, 1);
|
openfpga::write_tab_to_file(fp, 1);
|
||||||
fp << "</block>"
|
fp << "</block>"
|
||||||
|
|
|
@ -25,9 +25,9 @@
|
||||||
#include "report_reference.h"
|
#include "report_reference.h"
|
||||||
#include "vtr_log.h"
|
#include "vtr_log.h"
|
||||||
#include "vtr_time.h"
|
#include "vtr_time.h"
|
||||||
|
#include "write_unique_blocks.h"
|
||||||
#include "write_xml_fabric_pin_physical_location.h"
|
#include "write_xml_fabric_pin_physical_location.h"
|
||||||
#include "write_xml_module_name_map.h"
|
#include "write_xml_module_name_map.h"
|
||||||
#include "write_unique_blocks.h"
|
|
||||||
|
|
||||||
/* begin namespace openfpga */
|
/* begin namespace openfpga */
|
||||||
namespace openfpga {
|
namespace openfpga {
|
||||||
|
|
Loading…
Reference in New Issue