diff --git a/libopenfpga/CMakeLists.txt b/libopenfpga/CMakeLists.txt
index ec3299198..92d25522a 100644
--- a/libopenfpga/CMakeLists.txt
+++ b/libopenfpga/CMakeLists.txt
@@ -4,3 +4,4 @@ add_subdirectory(libopenfpgashell)
add_subdirectory(libarchopenfpga)
add_subdirectory(libopenfpgautil)
add_subdirectory(libfabrickey)
+add_subdirectory(libfpgabitstream)
diff --git a/libopenfpga/libfpgabitstream/CMakeLists.txt b/libopenfpga/libfpgabitstream/CMakeLists.txt
new file mode 100644
index 000000000..ce1a37d31
--- /dev/null
+++ b/libopenfpga/libfpgabitstream/CMakeLists.txt
@@ -0,0 +1,35 @@
+cmake_minimum_required(VERSION 3.9)
+
+project("libfpgabitstream")
+
+file(GLOB_RECURSE EXEC_SOURCES test/*.cpp)
+file(GLOB_RECURSE LIB_SOURCES src/*.cpp)
+file(GLOB_RECURSE LIB_HEADERS src/*.h)
+files_to_dirs(LIB_HEADERS LIB_INCLUDE_DIRS)
+
+#Remove test executable from library
+list(REMOVE_ITEM LIB_SOURCES ${EXEC_SOURCES})
+
+#Create the library
+add_library(libfpgabitstream STATIC
+ ${LIB_HEADERS}
+ ${LIB_SOURCES})
+target_include_directories(libfpgabitstream PUBLIC ${LIB_INCLUDE_DIRS})
+set_target_properties(libfpgabitstream PROPERTIES PREFIX "") #Avoid extra 'lib' prefix
+
+#Specify link-time dependancies
+target_link_libraries(libfpgabitstream
+ libopenfpgautil
+ libarchopenfpga
+ libvtrutil
+ libpugixml
+ libpugiutil)
+
+#Create the test executable
+foreach(testsourcefile ${EXEC_SOURCES})
+ # Use a simple string replace, to cut off .cpp.
+ get_filename_component(testname ${testsourcefile} NAME_WE)
+ add_executable(${testname} ${testsourcefile})
+ # Make sure the library is linked to each test executable
+ target_link_libraries(${testname} libfpgabitstream)
+endforeach(testsourcefile ${EXEC_SOURCES})
diff --git a/openfpga/src/fpga_bitstream/arch_bitstream_writer.cpp b/libopenfpga/libfpgabitstream/src/arch_bitstream_writer.cpp
similarity index 70%
rename from openfpga/src/fpga_bitstream/arch_bitstream_writer.cpp
rename to libopenfpga/libfpgabitstream/src/arch_bitstream_writer.cpp
index 6b3afdf4b..ebb0a3129 100644
--- a/openfpga/src/fpga_bitstream/arch_bitstream_writer.cpp
+++ b/libopenfpga/libfpgabitstream/src/arch_bitstream_writer.cpp
@@ -14,7 +14,7 @@
/* Headers from openfpgautil library */
#include "openfpga_digest.h"
-#include "openfpga_naming.h"
+#include "openfpga_reserved_words.h"
#include "bitstream_manager_utils.h"
#include "arch_bitstream_writer.h"
@@ -51,70 +51,86 @@ void write_bitstream_xml_file_head(std::fstream& fp) {
*******************************************************************/
static
void rec_write_block_bitstream_to_xml_file(std::fstream& fp,
- const AtomContext& atom_ctx,
const BitstreamManager& bitstream_manager,
- const ConfigBlockId& block) {
+ const ConfigBlockId& block,
+ const size_t& hierarchy_level) {
valid_file_stream(fp);
+ /* Write the bits of this block */
+ write_tab_to_file(fp, hierarchy_level);
+ fp << "" << std::endl;
+
/* Dive to child blocks if this block has any */
for (const ConfigBlockId& child_block : bitstream_manager.block_children(block)) {
- rec_write_block_bitstream_to_xml_file(fp, atom_ctx, bitstream_manager, child_block);
+ rec_write_block_bitstream_to_xml_file(fp, bitstream_manager, child_block, hierarchy_level + 1);
}
if (0 == bitstream_manager.block_bits(block).size()) {
+ write_tab_to_file(fp, hierarchy_level);
+ fp << "" <" << std::endl;
-
std::vector block_hierarchy = find_bitstream_manager_block_hierarchy(bitstream_manager, block);
/* Output hierarchy of this parent*/
- fp << "\t" << std::endl;
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "" << std::endl;
size_t hierarchy_counter = 0;
for (const ConfigBlockId& temp_block : block_hierarchy) {
- fp << "\t\t" << std::endl;
hierarchy_counter++;
}
- fp << "\t" << std::endl;
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "" << std::endl;
/* Output input/output nets if there are any */
if (false == bitstream_manager.block_input_net_ids(block).empty()) {
- fp << "\t\n";
- fp << "\t\t";
- for (const AtomNetId& net : bitstream_manager.block_input_net_ids(block)) {
- if (false == atom_ctx.nlist.valid_net_id(net)) {
- fp << "\tunmapped";
- } else {
- VTR_ASSERT_SAFE(true == atom_ctx.nlist.valid_net_id(net));
- fp << "\t" << atom_ctx.nlist.net_name(net);
- }
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "\n";
+ size_t path_counter = 0;
+ for (const std::string& net : bitstream_manager.block_input_net_ids(block)) {
+ write_tab_to_file(fp, hierarchy_level + 2);
+ fp << "";
+
+ path_counter++;
}
fp << "\n";
- fp << "\t\n";
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "\n";
}
if (false == bitstream_manager.block_output_net_ids(block).empty()) {
- fp << "\t\n";
- fp << "\t\t";
- for (const AtomNetId& net : bitstream_manager.block_output_net_ids(block)) {
- if (false == atom_ctx.nlist.valid_net_id(net)) {
- fp << "\tunmapped";
- } else {
- VTR_ASSERT_SAFE(true == atom_ctx.nlist.valid_net_id(net));
- fp << "\t" << atom_ctx.nlist.net_name(net);
- }
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "\n";
+ size_t path_counter = 0;
+ for (const std::string& net : bitstream_manager.block_output_net_ids(block)) {
+ write_tab_to_file(fp, hierarchy_level + 2);
+ fp << "";
+
+ path_counter++;
}
fp << "\n";
- fp << "\t\n";
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "\n";
}
/* Output child bits under this block */
size_t bit_counter = 0;
- fp << "\t" << std::endl;
for (const ConfigBitId& child_bit : bitstream_manager.block_bits(block)) {
- fp << "\t\t" << std::endl;
bit_counter++;
}
- fp << "\t" << std::endl;
+ write_tab_to_file(fp, hierarchy_level + 1);
+ fp << "" << std::endl;
+ write_tab_to_file(fp, hierarchy_level);
fp << "" < top_block = find_bitstream_manager_top_blocks(bitstream_manager);
/* Make sure we have only 1 top block and its name matches the top module */
@@ -175,7 +193,7 @@ void write_arch_independent_bitstream_to_xml_file(const BitstreamManager& bitstr
VTR_ASSERT(0 == top_block_name.compare(bitstream_manager.block_name(top_block[0])));
/* Write bitstream, block by block, in a recursive way */
- rec_write_block_bitstream_to_xml_file(fp, atom_ctx, bitstream_manager, top_block[0]);
+ rec_write_block_bitstream_to_xml_file(fp, bitstream_manager, top_block[0], 0);
/* Close file handler */
fp.close();
diff --git a/openfpga/src/fpga_bitstream/arch_bitstream_writer.h b/libopenfpga/libfpgabitstream/src/arch_bitstream_writer.h
similarity index 87%
rename from openfpga/src/fpga_bitstream/arch_bitstream_writer.h
rename to libopenfpga/libfpgabitstream/src/arch_bitstream_writer.h
index 69ee1f5a2..91f9e271d 100644
--- a/openfpga/src/fpga_bitstream/arch_bitstream_writer.h
+++ b/libopenfpga/libfpgabitstream/src/arch_bitstream_writer.h
@@ -5,7 +5,6 @@
* Include header files that are required by function declaration
*******************************************************************/
#include
-#include "vpr_context.h"
#include "bitstream_manager.h"
/********************************************************************
@@ -16,7 +15,7 @@
namespace openfpga {
void write_arch_independent_bitstream_to_xml_file(const BitstreamManager& bitstream_manager,
- const AtomContext& clustering_ctx,
+ const std::string& top_block_name,
const std::string& fname);
} /* end namespace openfpga */
diff --git a/openfpga/src/fpga_bitstream/bitstream_manager.cpp b/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp
similarity index 87%
rename from openfpga/src/fpga_bitstream/bitstream_manager.cpp
rename to libopenfpga/libfpgabitstream/src/bitstream_manager.cpp
index 15946c292..66b4d1f23 100644
--- a/openfpga/src/fpga_bitstream/bitstream_manager.cpp
+++ b/libopenfpga/libfpgabitstream/src/bitstream_manager.cpp
@@ -115,14 +115,14 @@ int BitstreamManager::block_path_id(const ConfigBlockId& block_id) const {
return block_path_ids_[block_id];
}
-std::vector BitstreamManager::block_input_net_ids(const ConfigBlockId& block_id) const {
+std::vector BitstreamManager::block_input_net_ids(const ConfigBlockId& block_id) const {
/* Ensure the input ids are valid */
VTR_ASSERT(true == valid_block_id(block_id));
return block_input_net_ids_[block_id];
}
-std::vector BitstreamManager::block_output_net_ids(const ConfigBlockId& block_id) const {
+std::vector BitstreamManager::block_output_net_ids(const ConfigBlockId& block_id) const {
/* Ensure the input ids are valid */
VTR_ASSERT(true == valid_block_id(block_id));
@@ -143,11 +143,22 @@ ConfigBitId BitstreamManager::add_bit(const bool& bit_value) {
return bit;
}
-ConfigBlockId BitstreamManager::add_block(const std::string& block_name) {
+void BitstreamManager::reserve_blocks(const size_t& num_blocks) {
+ block_ids_.reserve(num_blocks);
+ block_names_.reserve(num_blocks);
+ block_bit_ids_.reserve(num_blocks);
+ block_path_ids_.reserve(num_blocks);
+ block_input_net_ids_.reserve(num_blocks);
+ block_output_net_ids_.reserve(num_blocks);
+ parent_block_ids_.reserve(num_blocks);
+ child_block_ids_.reserve(num_blocks);
+}
+
+ConfigBlockId BitstreamManager::create_block() {
ConfigBlockId block = ConfigBlockId(block_ids_.size());
/* Add a new bit, and allocate associated data structures */
block_ids_.push_back(block);
- block_names_.push_back(block_name);
+ block_names_.emplace_back();
block_bit_ids_.emplace_back();
block_path_ids_.push_back(-2);
block_input_net_ids_.emplace_back();
@@ -158,6 +169,20 @@ ConfigBlockId BitstreamManager::add_block(const std::string& block_name) {
return block;
}
+ConfigBlockId BitstreamManager::add_block(const std::string& block_name) {
+ ConfigBlockId block = create_block();
+ set_block_name(block, block_name);
+
+ return block;
+}
+
+void BitstreamManager::set_block_name(const ConfigBlockId& block_id,
+ const std::string& block_name) {
+ /* Ensure the input ids are valid */
+ VTR_ASSERT(true == valid_block_id(block_id));
+ block_names_[block_id] = block_name;
+}
+
void BitstreamManager::add_child_block(const ConfigBlockId& parent_block, const ConfigBlockId& child_block) {
/* Ensure the input ids are valid */
VTR_ASSERT(true == valid_block_id(parent_block));
@@ -199,7 +224,7 @@ void BitstreamManager::add_path_id_to_block(const ConfigBlockId& block, const in
}
void BitstreamManager::add_input_net_id_to_block(const ConfigBlockId& block,
- const AtomNetId& input_net_id) {
+ const std::string& input_net_id) {
/* Ensure the input ids are valid */
VTR_ASSERT(true == valid_block_id(block));
@@ -208,7 +233,7 @@ void BitstreamManager::add_input_net_id_to_block(const ConfigBlockId& block,
}
void BitstreamManager::add_output_net_id_to_block(const ConfigBlockId& block,
- const AtomNetId& output_net_id) {
+ const std::string& output_net_id) {
/* Ensure the input ids are valid */
VTR_ASSERT(true == valid_block_id(block));
diff --git a/openfpga/src/fpga_bitstream/bitstream_manager.h b/libopenfpga/libfpgabitstream/src/bitstream_manager.h
similarity index 90%
rename from openfpga/src/fpga_bitstream/bitstream_manager.h
rename to libopenfpga/libfpgabitstream/src/bitstream_manager.h
index 0621a214e..71bd63b43 100644
--- a/openfpga/src/fpga_bitstream/bitstream_manager.h
+++ b/libopenfpga/libfpgabitstream/src/bitstream_manager.h
@@ -38,9 +38,6 @@
#include