Skip to content

Commit

Permalink
Merge pull request #689 from os-fpga/yosys-io
Browse files Browse the repository at this point in the history
Fix editor SDC parser
  • Loading branch information
alaindargelas authored Jun 27, 2024
2 parents 6a7831f + b6e0a3c commit a23cf65
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set(VERSION_MAJOR 0)
set(VERSION_MINOR 0)


set(VERSION_PATCH 336)
set(VERSION_PATCH 337)


project(yosys_verific_rs)
Expand Down
55 changes: 31 additions & 24 deletions design_edit/src/rs_design_edit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ const std::vector<std::string> OUT_PORTS = {"O", "O_P", "O_N", "Q", "CLK_OUT", "
struct DesignEditRapidSilicon : public ScriptPass {
DesignEditRapidSilicon()
: ScriptPass("design_edit", "Netlist Editing Tool") {}

~DesignEditRapidSilicon() {
while (pins.size()) {
delete pins.back();
pins.pop_back();
}
}

void help() override {
log("\n");
Expand Down Expand Up @@ -103,7 +110,21 @@ struct DesignEditRapidSilicon : public ScriptPass {

return tokens;
}


pin_data* get_pin(std::string name, bool create_new_if_not_exist = true) {
pin_data* pin = nullptr;
for (auto& p : pins) {
if (p->_name == name) {
pin = p;
break;
}
}
if (pin == nullptr && create_new_if_not_exist) {
pin = new pin_data(name);
pins.push_back(pin);
}
return pin;
}
void processSdcFile(std::istream &input) {
std::string line;
while (std::getline(input, line)) {
Expand All @@ -112,27 +133,22 @@ struct DesignEditRapidSilicon : public ScriptPass {
continue;
if ("set_property" == tokens[0]) {
if (tokens.size() == 4) {
location_map[tokens[3]]._properties[tokens[1]] = tokens[2];
location_map[tokens[3]]._name = tokens[3];
pin_data* pin = get_pin(tokens[3]);
log_assert(pin != nullptr);
pin->_properties[tokens[1]] = tokens[2];
}
} else if ("set_pin_loc" == tokens[0]) {
if (tokens.size() < 3 || tokens.size() > 4) continue;
constrained_pins.insert(tokens[1]);
location_map[tokens[2]]._associated_pin = tokens[1];
location_map[tokens[2]]._name = tokens[2];
pin_data* pin = get_pin(tokens[1]);
log_assert(pin != nullptr);
pin->_location = tokens[2];
if (tokens.size() == 4) {
location_map[tokens[2]]._internal_pin = tokens[3];
pin->_internal_pin = tokens[3];
}
}
}
}

void get_loc_map_by_io() {
for (auto &p : location_map) {
location_map_by_io[p.second._associated_pin] = p.second;
}
}

std::string id(RTLIL::IdString internal_id)
{
const char *str = internal_id.c_str();
Expand Down Expand Up @@ -187,14 +203,6 @@ struct DesignEditRapidSilicon : public ScriptPass {
instance_object["connectivity"][port_name].push_back(s);
}
}
if (location_map_by_io.find(connection) != location_map_by_io.end()) {
instance_object["location"] = location_map_by_io[connection]._name;
for (auto &pr : location_map_by_io[connection]._properties) {
if (!pr.second.empty()) {
instance_object["properties"][pr.first] = pr.second;
}
}
}
}
instances_array.push_back(instance_object);
}
Expand Down Expand Up @@ -1110,9 +1118,8 @@ struct DesignEditRapidSilicon : public ScriptPass {
std::cerr << "Error opening input sdc file: " << sdc_file << std::endl;
}
processSdcFile(input_sdc);
get_loc_map_by_io();
for (auto &p : location_map_by_io) {
extractor->assign_location(p.second._associated_pin, p.second._name, p.second._properties, p.second._internal_pin);
for (auto &p : pins) {
extractor->assign_location(p->_name, p->_location, p->_properties, p->_internal_pin);
}
}

Expand Down
17 changes: 9 additions & 8 deletions design_edit/src/rs_design_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ struct primitives_data_default {
}
};

struct location_data {
std::string _name;
std::string _associated_pin;
std::string _internal_pin;
struct pin_data {
pin_data(const std::string& n) : _name(n) {
log_assert(_name.size());
}
const std::string _name = "";
std::string _location = "";
std::string _internal_pin = "";
std::unordered_map<string, std::string> _properties;
void print(std::ostream &output) {
output << "name: " << _name << std::endl;
output << " pin: " << _associated_pin << std::endl;
output << " pin location: " << _location << std::endl;
output << " internal pin: " << _internal_pin << std::endl;
output << " properties: " << std::endl;
for (auto &pr : _properties) {
Expand All @@ -54,8 +57,7 @@ struct location_data {
};

enum Technologies { GENERIC, GENESIS, GENESIS_2, GENESIS_3 };
std::unordered_map<string, location_data> location_map_by_io;
std::unordered_map<string, location_data> location_map;
std::vector<pin_data*> pins;
std::vector<std::string> wrapper_files;
std::vector<std::string> post_route_wrapper;
std::unordered_set<std::string> clk_outs;
Expand All @@ -72,7 +74,6 @@ std::unordered_set<std::string> common_clks_resets;
std::unordered_set<std::string> orig_inst_conns;
std::unordered_set<std::string> interface_inst_conns;
std::unordered_set<std::string> keep_wires;
std::unordered_set<std::string> constrained_pins;
std::string io_config_json;
std::string sdc_file;
bool sdc_passed = false;
Expand Down

0 comments on commit a23cf65

Please sign in to comment.