read bin format mod (with bug)
This commit is contained in:
parent
59f1e4adc9
commit
ed381692a7
|
@ -1,39 +1,39 @@
|
|||
#include "mmap_file.h"
|
||||
#include "vtr_error.h"
|
||||
#include "vtr_util.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "vtr_error.h"
|
||||
#include "vtr_util.h"
|
||||
#ifndef _WIN32
|
||||
#include <sys/mman.h>
|
||||
#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);
|
||||
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 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__);
|
||||
}
|
||||
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));
|
||||
return kj::arrayPtr(reinterpret_cast<const ::capnp::word*>(data_.begin()),
|
||||
size_ / sizeof(::capnp::word));
|
||||
}
|
||||
|
|
|
@ -2,18 +2,19 @@
|
|||
#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;
|
||||
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_;
|
||||
private:
|
||||
size_t size_;
|
||||
kj::Array<const kj::byte> data_;
|
||||
};
|
||||
|
||||
#endif /* MMAP_FILE_H_ */
|
||||
|
|
|
@ -3,20 +3,21 @@
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "vtr_error.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);
|
||||
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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@
|
|||
|
||||
#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);
|
||||
::capnp::MessageBuilder* builder);
|
||||
|
||||
inline ::capnp::ReaderOptions default_large_capnp_opts() {
|
||||
::capnp::ReaderOptions opts = ::capnp::ReaderOptions();
|
||||
::capnp::ReaderOptions opts = ::capnp::ReaderOptions();
|
||||
|
||||
/* Remove traversal limit */
|
||||
opts.traversalLimitInWords = std::numeric_limits<uint64_t>::max();
|
||||
return opts;
|
||||
/* Remove traversal limit */
|
||||
opts.traversalLimitInWords = std::numeric_limits<uint64_t>::max();
|
||||
return opts;
|
||||
}
|
||||
|
||||
#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];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ DeviceRRGSB::get_cbx_unique_block_instance_coord(
|
|||
cbx_unique_module_id_[location_x][location_y];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ DeviceRRGSB::get_cby_unique_block_instance_coord(
|
|||
cby_unique_module_id_[location_x][location_y];
|
||||
if (unique_module_id_instance == unique_module_id) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,21 +197,10 @@ int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
|||
if (root.hasAtomInfo()) {
|
||||
auto block_list = root.getAtomInfo();
|
||||
for (auto unqiue_block : block_list) {
|
||||
auto block_info = unique_block.getBlockInfo();
|
||||
std::string type = block_info.getType().Cstr();
|
||||
int block_x = block_info.getX();
|
||||
int block_y = block_info.getY();
|
||||
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);
|
||||
}
|
||||
}
|
||||
vtr::Point<size_t> block_coordinate =
|
||||
read_bin_unique_block_coord(unique_block);
|
||||
std::vector<vtr::Point<size_t>> instance_coords =
|
||||
read_bin_unique_instance_coords(unique_block);
|
||||
/* get block coordinate and instance coordinate, try to setup
|
||||
* device_rr_gsb */
|
||||
if (type == "sb") {
|
||||
|
|
|
@ -43,7 +43,7 @@ vtr::Point<size_t> read_bin_unique_block_coord(
|
|||
const uniqueblockcap::BlockInfo::Reader& unique_block);
|
||||
|
||||
int read_bin_unique_blocks(DeviceRRGSB& device_rr_gsb, const char* file_name,
|
||||
bool verbose_output)
|
||||
bool verbose_output);
|
||||
} // namespace openfpga
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,8 +56,7 @@ int write_xml_atom_block(std::fstream& fp,
|
|||
write_xml_attribute(fp, "y", instance_info.y());
|
||||
|
||||
fp << "/>"
|
||||
<< "\n";
|
||||
|
||||
<< "\n";
|
||||
}
|
||||
openfpga::write_tab_to_file(fp, 1);
|
||||
fp << "</block>"
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
#include "report_reference.h"
|
||||
#include "vtr_log.h"
|
||||
#include "vtr_time.h"
|
||||
#include "write_unique_blocks.h"
|
||||
#include "write_xml_fabric_pin_physical_location.h"
|
||||
#include "write_xml_module_name_map.h"
|
||||
#include "write_unique_blocks.h"
|
||||
|
||||
/* begin namespace openfpga */
|
||||
namespace openfpga {
|
||||
|
|
Loading…
Reference in New Issue