Skip to content

Commit

Permalink
Extractor 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chungshien-chai committed Dec 11, 2024
1 parent 31a0719 commit bc0f44e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 17 deletions.
109 changes: 95 additions & 14 deletions src/Configuration/ModelConfig/ModelConfig_IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,15 @@ void ModelConfig_IO::assign_no_location_instance() {
CFG_ASSERT(instance.contains("__validation_msg__"));
CFG_ASSERT(instance["__validation__"].is_boolean());
CFG_ASSERT(instance["__validation_msg__"].is_string());
if (instance["__validation__"] && (instance["module"] == "BOOT_CLOCK" ||
instance["module"] == "FCLK_BUF")) {
if (instance["__validation__"] &&
(instance["module"] == "BOOT_CLOCK" ||
instance["module"] == "FCLK_BUF" ||
instance["module"] == "SOC_FPGA_INTF_AHB_M" ||
instance["module"] == "SOC_FPGA_INTF_AHB_S" ||
instance["module"] == "SOC_FPGA_INTF_DMA" ||
instance["module"] == "SOC_FPGA_INTF_IRQ" ||
instance["module"] == "SOC_FPGA_INTF_JTAG" ||
instance["module"] == "SOC_FPGA_TEMPERATURE")) {
POST_DEBUG_MSG(1, "Instance: %s",
((std::string)(instance["name"])).c_str());
CFG_ASSERT(((std::string)(instance["location"])).size() == 0);
Expand Down Expand Up @@ -840,6 +847,12 @@ void ModelConfig_IO::assign_no_location_instance_child_location(
CFG_ASSERT(instance["__validation_msg__"].is_string());
if (instance["__validation__"] && instance["module"] != "BOOT_CLOCK" &&
instance["module"] != "FCLK_BUF" &&
instance["module"] != "SOC_FPGA_INTF_AHB_M" &&
instance["module"] != "SOC_FPGA_INTF_AHB_S" &&
instance["module"] != "SOC_FPGA_INTF_DMA" &&
instance["module"] != "SOC_FPGA_INTF_IRQ" &&
instance["module"] != "SOC_FPGA_INTF_JTAG" &&
instance["module"] != "SOC_FPGA_TEMPERATURE" &&
instance["linked_object"] == linked_object) {
CFG_ASSERT(((std::string)(instance["location"])).size() == 0);
instance["location"] =
Expand Down Expand Up @@ -1037,7 +1050,7 @@ nlohmann::json ModelConfig_IO::prepare_routing_json() {
if (src_pin_info.type == "BOOT_CLOCK") {
routing["source"] =
CFG_print("%s->osc", src_pin_info.model_name.c_str());
} else if (src_pin_info.type == "FABRIC_CLKBUF") {
} else if (src_pin_info.type == "FCLK_BUF") {
CFG_ASSERT(
instance["parameters"].contains("ROUTE_FROM_FABRIC_CLK"));
std::string fclk_buf_source =
Expand Down Expand Up @@ -1986,9 +1999,9 @@ void ModelConfig_IO::write_json(const std::string& file, bool status,
std::ofstream json(file.c_str());
size_t index = 0;
json << "{\n";
json << " \"status\": " << (status ? "true" : "false") << ",\n";
json << " \"feature\": \"" << feature.c_str() << "\",\n";
json << " \"messages\": [\n";
json << " \"status\": " << (status ? "true" : "false") << ",\n";
json << " \"feature\": \"" << feature.c_str() << "\",\n";
json << " \"messages\": [\n";
for (auto& msg : messages) {
CFG_ASSERT(msg.is_string());
if (index) {
Expand Down Expand Up @@ -2021,6 +2034,16 @@ void ModelConfig_IO::write_json(const std::string& file, bool status,
json.close();
}

/*
To write space
*/
void ModelConfig_IO::write_json_space(std::ofstream& json, uint32_t space) {
while (space) {
json << " ";
space--;
}
}

/*
To write single instance into JSON
*/
Expand Down Expand Up @@ -2079,7 +2102,7 @@ void ModelConfig_IO::write_json_instance(nlohmann::json& instance,
json << "\n";
json << " },\n";
json << " \"connectivity\": {\n";
write_json_map(instance["connectivity"], json);
write_json_connectivity(instance["connectivity"], json);
json << " },\n";
json << " \"parameters\": {\n";
write_json_map(instance["parameters"], json);
Expand Down Expand Up @@ -2161,10 +2184,7 @@ void ModelConfig_IO::write_json_instance(nlohmann::json& instance,
void ModelConfig_IO::write_json_object(const std::string& key,
const std::string& value,
std::ofstream& json, uint32_t space) {
while (space) {
json << " ";
space--;
}
write_json_space(json, space);
json << "\"";
write_json_data(key, json);
json << "\"";
Expand Down Expand Up @@ -2209,9 +2229,7 @@ void ModelConfig_IO::write_json_array(std::vector<std::string> array,
if (index) {
json << ",\n";
}
for (uint8_t i = 0; i < space; i++) {
json << " ";
}
write_json_space(json, space);
json << "\"";
write_json_data(iter, json);
json << "\"";
Expand All @@ -2237,4 +2255,67 @@ void ModelConfig_IO::write_json_data(const std::string& str,
}
}

/*
To write connectivity into JSON
*/
void ModelConfig_IO::write_json_connectivity(nlohmann::json& connectivity,
std::ofstream& json,
uint32_t space) {
CFG_ASSERT(connectivity.is_object())
size_t index = 0;
for (auto& iter : connectivity.items()) {
if (index) {
json << ",\n";
}
write_json_space(json, space);
json << "\"";
write_json_data(std::string(iter.key()), json);
json << "\" : [\n";
write_json_connectivity_nets(iter.value(), json);
write_json_space(json, space);
json << "]";
index++;
}
if (index) {
json << "\n";
}
}

/*
To write connectivity nets into JSON
*/
void ModelConfig_IO::write_json_connectivity_nets(nlohmann::json& nets,
std::ofstream& json,
uint32_t space) {
json.flush();
CFG_ASSERT(nets.is_array());
std::map<std::string, std::string> dummy;
size_t index = 0;
for (auto& net : nets) {
CFG_ASSERT(net.is_object());
CFG_ASSERT(net.contains("net"));
CFG_ASSERT(net.contains("DriveSink"));
if (index) {
json << ",\n";
}
std::vector<std::string> dss =
get_json_string_list(net["DriveSink"], dummy);
write_json_space(json, space);
json << "{\n";
write_json_object("net", std::string(net["net"]), json, space + 1);
json << ",\n";
write_json_space(json, space + 1);
json << "\"DriveSink\" : [\n";
write_json_array(dss, json, space + 2);
write_json_space(json, space + 1);
json << "]\n";
write_json_space(json, space);
json << "}";
index++;
}
if (index) {
json << "\n";
}
}

} // namespace FOEDAG
12 changes: 9 additions & 3 deletions src/Configuration/ModelConfig/ModelConfig_IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ struct PIN_INFO {
ab_io(in5),
ab_name(in6),
model_name(in7) {
CFG_ASSERT(((type == "BOOT_CLOCK" || type == "FABRIC_CLKBUF") &&
ab_name.size() == 0) ||
ab_name.size() == 1);
CFG_ASSERT(
((type == "BOOT_CLOCK" || type == "FCLK_BUF") && ab_name.size() == 0) ||
ab_name.size() == 1);
}
const std::string type = "";
const uint32_t bank = 0;
Expand Down Expand Up @@ -211,6 +211,7 @@ class ModelConfig_IO {
Helper to write JSON
*/
void write_json(const std::string& file);
static void write_json_space(std::ofstream& json, uint32_t space);
static void write_json_instance(nlohmann::json& instance,
std::ofstream& json);
static void write_json_object(const std::string& key,
Expand All @@ -221,6 +222,11 @@ class ModelConfig_IO {
static void write_json_array(std::vector<std::string> array,
std::ofstream& json, uint32_t space = 4);
static void write_json_data(const std::string& str, std::ofstream& json);
static void write_json_connectivity(nlohmann::json& map, std::ofstream& json,
uint32_t space = 4);
static void write_json_connectivity_nets(nlohmann::json& map,
std::ofstream& json,
uint32_t space = 5);

protected:
bool m_status = true;
Expand Down

0 comments on commit bc0f44e

Please sign in to comment.