| #include <ot/liberty/celllib.hpp> |
|
|
| namespace ot { |
|
|
| |
| void Celllib::_uncomment(std::vector<char>& buffer) { |
| |
| auto fsize = buffer.size() > 0 ? buffer.size() - 1 : 0; |
|
|
| |
| for(size_t i=0; i<fsize; ++i) { |
|
|
| |
| if(buffer[i] == '/' && buffer[i+1] == '*') { |
| buffer[i] = buffer[i+1] = ' '; |
| for(i=i+2; i<fsize; buffer[i++]=' ') { |
| if(buffer[i] == '*' && buffer[i+1] == '/') { |
| buffer[i] = buffer[i+1] = ' '; |
| i = i+1; |
| break; |
| } |
| } |
| } |
| |
| |
| if(buffer[i] == '/' && buffer[i+1] == '/') { |
| buffer[i] = buffer[i+1] = ' '; |
| for(i=i+2; i<fsize; ++i) { |
| if(buffer[i] == '\n' || buffer[i] == '\r') { |
| break; |
| } |
| else buffer[i] = ' '; |
| } |
| } |
| |
| |
| if(buffer[i] == '#') { |
| buffer[i] = ' '; |
| for(i=i+1; i<fsize; ++i) { |
| if(buffer[i] == '\n' || buffer[i] == '\r') { |
| break; |
| } |
| else buffer[i] = ' '; |
| } |
| } |
| } |
| } |
|
|
| |
| void Celllib::_tokenize(const std::vector<char>& buf, std::vector<std::string_view>& tokens) { |
|
|
| static std::string_view dels = "(),:;/#[]{}*\"\\"; |
|
|
| |
| const char* beg = buf.data(); |
| const char* end = buf.data() + buf.size(); |
|
|
| |
| const char *token {nullptr}; |
| size_t len {0}; |
|
|
| tokens.clear(); |
|
|
| for(const char* itr = beg; itr != end && *itr != 0; ++itr) { |
| |
| |
| bool is_del = (dels.find(*itr) != std::string_view::npos); |
|
|
| if(std::isspace(*itr) || is_del) { |
| if(len > 0) { |
| tokens.push_back({token, len}); |
| token = nullptr; |
| len = 0; |
| } |
| |
| if(*itr == '(' || *itr == ')' || *itr == '{' || *itr == '}') { |
| tokens.push_back({itr, 1}); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| } |
| else { |
| if(len == 0) { |
| token = itr; |
| } |
| ++len; |
| } |
| } |
|
|
| if(len > 0) { |
| tokens.push_back({token, len}); |
| } |
| } |
|
|
| |
|
|
| |
| std::string to_string(DelayModel m) { |
| switch(m) { |
| case DelayModel::GENERIC_CMOS: |
| return "generic_cmos"; |
| break; |
|
|
| case DelayModel::TABLE_LOOKUP: |
| return "table_lookup"; |
| break; |
|
|
| case DelayModel::CMOS2: |
| return "cmos2"; |
| break; |
|
|
| case DelayModel::PIECEWISE_CMOS: |
| return "piecewise_cmos"; |
| break; |
|
|
| case DelayModel::DCM: |
| return "dcm"; |
| break; |
|
|
| case DelayModel::POLYNOMIAL: |
| return "polynomial"; |
| break; |
|
|
| default: |
| return "undefined"; |
| break; |
| } |
| } |
|
|
| |
| const LutTemplate* Celllib::lut_template(const std::string& name) const { |
| if(auto itr = lut_templates.find(name); itr == lut_templates.end()) { |
| return nullptr; |
| } |
| else { |
| return &(itr->second); |
| } |
| } |
|
|
| |
| LutTemplate* Celllib::lut_template(const std::string& name) { |
| if(auto itr = lut_templates.find(name); itr == lut_templates.end()) { |
| return nullptr; |
| } |
| else { |
| return &(itr->second); |
| } |
| } |
|
|
| |
| const Cell* Celllib::cell(const std::string& name) const { |
| if(auto itr = cells.find(name); itr == cells.end()) { |
| return nullptr; |
| } |
| else { |
| return &(itr->second); |
| } |
| } |
|
|
| |
| Cell* Celllib::cell(const std::string& name) { |
| if(auto itr = cells.find(name); itr == cells.end()) { |
| return nullptr; |
| } |
| else { |
| return &(itr->second); |
| } |
| } |
|
|
| |
| std::optional<float> Celllib::_extract_operating_conditions(token_iterator& itr, const token_iterator end) { |
|
|
| std::optional<float> voltage; |
| std::string operating_condition_name; |
|
|
| if(itr=on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& name) mutable { operating_condition_name = name; }); itr == end) { |
| OT_LOGF("can't find lut template name"); |
| } |
| |
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find lut template group brace '{'"); |
| } |
|
|
| |
|
|
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| |
| if(*itr == "voltage") { |
|
|
| if(++itr == end) { |
| OT_LOGF("volate error in operating_conditions template ", operating_condition_name); |
| } |
|
|
| voltage = std::strtof(std::string(*itr).c_str(), nullptr); |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
| |
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find operating_conditions template group brace '}'"); |
| } |
|
|
| return voltage; |
| } |
|
|
| |
| LutTemplate Celllib::_extract_lut_template(token_iterator& itr, const token_iterator end) { |
|
|
| LutTemplate lt; |
|
|
| if(itr=on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& name) mutable { lt.name = name; }); itr == end) { |
| OT_LOGF("can't find lut template name"); |
| } |
| |
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find lut template group brace '{'"); |
| } |
|
|
| |
|
|
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| |
| if(*itr == "variable_1") { |
|
|
| if(++itr == end) { |
| OT_LOGF("variable_1 error in lut template ", lt.name); |
| } |
|
|
| if(auto vitr = lut_vars.find(*itr); vitr != lut_vars.end()) { |
| lt.variable1 = vitr->second; |
| } |
| else { |
| OT_LOGW("unexpected lut template variable ", *itr); |
| } |
| } |
| |
| else if(*itr == "variable_2") { |
|
|
| if(++itr == end) { |
| OT_LOGF("variable_2 error in lut template ", lt.name); |
| } |
|
|
| if(auto vitr = lut_vars.find(*itr); vitr != lut_vars.end()) { |
| lt.variable2 = vitr->second; |
| } |
| else { |
| OT_LOGW("unexpected lut template variable ", *itr); |
| } |
| } |
| |
| else if(*itr == "index_1") { |
| itr = on_next_parentheses(itr, end, [&] (auto& str) { |
| lt.indices1.push_back(std::strtof(str.data(), nullptr)); |
| }); |
| } |
| |
| else if(*itr == "index_2") { |
| itr = on_next_parentheses(itr, end, [&] (auto& str) { |
| lt.indices2.push_back(std::strtof(str.data(), nullptr)); |
| }); |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
| |
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find lut template group brace '}'"); |
| } |
|
|
| return lt; |
| } |
|
|
| |
| Lut Celllib::_extract_lut(token_iterator& itr, const token_iterator end) { |
| |
| Lut lut; |
| |
| if(itr=on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& name) mutable { lut.name = name; }); itr == end) { |
| OT_LOGF("can't find lut template name"); |
| } |
| |
| |
| lut.lut_template = lut_template(lut.name); |
| |
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("group brace '{' error in lut ", lut.name); |
| } |
|
|
| int stack = 1; |
|
|
| size_t size1 = 1; |
| size_t size2 = 1; |
|
|
| while(stack && ++itr != end) { |
|
|
| if(*itr == "index_1") { |
| itr = on_next_parentheses(itr, end, [&] (auto& v) mutable { |
| lut.indices1.push_back(std::strtof(v.data(), nullptr)); |
| }); |
|
|
| if(lut.indices1.size() == 0) { |
| OT_LOGF("syntax error in ", lut.name, " index_1"); |
| } |
|
|
| size1 = lut.indices1.size(); |
| } |
| else if(*itr == "index_2") { |
| itr = on_next_parentheses(itr, end, [&] (auto& v) mutable { |
| lut.indices2.push_back(std::strtof(v.data(), nullptr)); |
| }); |
|
|
| if(lut.indices2.size() == 0) { |
| OT_LOGF("syntax error in ", lut.name, " index_2"); |
| } |
| |
| size2 = lut.indices2.size(); |
| } |
| else if(*itr == "values") { |
|
|
| if(lut.indices1.empty()) { |
| if(size1 != 1) { |
| OT_LOGF("empty indices1 in non-scalar lut ", lut.name); |
| } |
| lut.indices1.resize(size1); |
| } |
|
|
| if(lut.indices2.empty()){ |
| if(size2 != 1) { |
| OT_LOGF("empty indices2 in non-scalar lut ", lut.name); |
| } |
| lut.indices2.resize(size2); |
| } |
|
|
| lut.table.resize(size1*size2); |
|
|
| int id {0}; |
| itr = on_next_parentheses(itr, end, [&] (auto& v) mutable { |
| lut.table[id++] = std::strtof(v.data(), nullptr); |
| }); |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
|
|
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("group brace '}' error in lut ", lut.name); |
| } |
|
|
| return lut; |
| } |
|
|
| |
| InternalPower Celllib::_extract_internal_power(token_iterator& itr, const token_iterator end) { |
|
|
| InternalPower power; |
|
|
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find group brace '{' in timing"); |
| } |
|
|
| int stack = 1; |
|
|
| while(stack && ++itr != end) { |
|
|
| if (*itr == "rise_power") { |
| power.rise_power = _extract_lut(itr, end); |
| } |
| else if (*itr == "fall_power") { |
| power.fall_power = _extract_lut(itr, end); |
| } |
| else if (*itr == "related_pin") { |
|
|
| if(++itr == end) { |
| OT_LOGF("syntax error in related_pin"); |
| } |
|
|
| power.related_pin = *itr; |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
|
|
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find group brace '}' in internal_power"); |
| } |
|
|
| return power; |
| } |
|
|
| |
| Timing Celllib::_extract_timing(token_iterator& itr, const token_iterator end) { |
|
|
| Timing timing; |
|
|
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find group brace '{' in timing"); |
| } |
| |
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| if (*itr == "cell_fall") { |
| timing.cell_fall = _extract_lut(itr, end); |
| } |
| else if (*itr == "cell_rise") { |
| timing.cell_rise = _extract_lut(itr, end); |
| } |
| else if (*itr == "fall_transition") { |
| timing.fall_transition = _extract_lut(itr, end); |
| } |
| else if (*itr == "rise_transition") { |
| timing.rise_transition = _extract_lut(itr, end); |
| } |
| else if (*itr == "rise_constraint") { |
| timing.rise_constraint = _extract_lut(itr, end); |
| } |
| else if(*itr == "fall_constraint") { |
| timing.fall_constraint = _extract_lut(itr, end); |
| } |
| else if(*itr == "timing_sense") { |
|
|
| OT_LOGF_IF(++itr == end, "syntex error in timing_sense"); |
|
|
| if(*itr == "negative_unate") { |
| timing.sense = TimingSense::NEGATIVE_UNATE; |
| } |
| else if(*itr == "positive_unate") { |
| timing.sense = TimingSense::POSITIVE_UNATE; |
| } |
| else if(*itr == "non_unate") { |
| timing.sense = TimingSense::NON_UNATE; |
| } |
| else { |
| OT_LOGF("unexpected timing sense ", *itr); |
| } |
| } |
| else if(*itr == "timing_type") { |
| |
| if(++itr == end) { |
| OT_LOGF("syntax error in timing_type"); |
| } |
|
|
| if(auto titr = timing_types.find(*itr); titr != timing_types.end()) { |
| timing.type = titr->second; |
| } |
| else { |
| OT_LOGW("unexpected timing type ", *itr); |
| } |
| } |
| else if (*itr == "related_pin") { |
| |
| if(++itr == end) { |
| OT_LOGF("syntax error in related_pin"); |
| } |
|
|
| timing.related_pin = *itr; |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
|
|
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find group brace '}' in timing"); |
| } |
|
|
| return timing; |
| } |
|
|
| |
| Cellpin Celllib::_extract_cellpin(token_iterator& itr, const token_iterator end) { |
|
|
| Cellpin cellpin; |
| |
| if(itr=on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& name) mutable { cellpin.name = name; }); itr == end) { |
| OT_LOGF("can't find cellpin name"); |
| } |
| |
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find group brace '{' in cellpin ", cellpin.name); |
| } |
|
|
| |
|
|
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| if(*itr == "direction") { |
|
|
| if(++itr == end) { |
| OT_LOGF("can't get the direction in cellpin ", cellpin.name); |
| } |
|
|
| if(auto ditr = cellpin_directions.find(*itr); ditr != cellpin_directions.end()) { |
| cellpin.direction = ditr->second; |
| } |
| else { |
| OT_LOGW("unexpected cellpin direction ", *itr); |
| } |
| } |
| else if(*itr == "capacitance") { |
| OT_LOGF_IF(++itr == end, "can't get the capacitance in cellpin ", cellpin.name); |
| cellpin.capacitance = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "max_capacitance") { |
| OT_LOGF_IF(++itr == end, "can't get the max_capacitance in cellpin ", cellpin.name); |
| cellpin.max_capacitance = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "min_capacitance") { |
| OT_LOGF_IF(++itr == end, "can't get the min_capacitance in cellpin ", cellpin.name); |
| cellpin.min_capacitance = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "max_transition") { |
| OT_LOGF_IF(++itr == end, "can't get the max_transition in cellpin ", cellpin.name); |
| cellpin.max_transition = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "min_transition") { |
| OT_LOGF_IF(++itr == end, "can't get the min_transition in cellpin ", cellpin.name); |
| cellpin.min_transition = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "fall_capacitance") { |
| OT_LOGF_IF(++itr == end, "can't get fall_capacitance in cellpin ", cellpin.name); |
| cellpin.fall_capacitance = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "rise_capacitance") { |
| OT_LOGF_IF(++itr == end, "can't get rise_capacitance in cellpin ", cellpin.name); |
| cellpin.rise_capacitance = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "fanout_load") { |
| OT_LOGF_IF(++itr == end, "can't get fanout_load in cellpin ", cellpin.name); |
| cellpin.fanout_load = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "max_fanout") { |
| OT_LOGF_IF(++itr == end, "can't get max_fanout in cellpin ", cellpin.name); |
| cellpin.max_fanout = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "min_fanout") { |
| OT_LOGF_IF(++itr == end, "can't get min_fanout in cellpin ", cellpin.name); |
| cellpin.min_fanout = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "clock") { |
| OT_LOGF_IF(++itr == end, "can't get the clock status in cellpin ", cellpin.name); |
| cellpin.is_clock = (*itr == "true") ? true : false; |
| } |
| else if(*itr == "original_pin") { |
| OT_LOGF_IF(++itr == end, "can't get the original pin in cellpin ", cellpin.name); |
| cellpin.original_pin = *itr; |
| } |
| else if(*itr == "internal_power") { |
| auto ipower = _extract_internal_power(itr, end); |
| bool found = false; |
| for(auto &t:cellpin.timings) { |
| if (t.related_pin != ipower.related_pin) |
| continue; |
|
|
| t.internal_power = ipower; |
| found = true; |
| break; |
| } |
| if (!found) { |
| Timing t; |
| t.related_pin = ipower.related_pin; |
| t.internal_power = ipower; |
| cellpin.timings.emplace_back(t); |
| } |
| } |
| else if(*itr == "timing") { |
| auto ti = _extract_timing(itr, end); |
| bool found = false; |
| for(auto &t:cellpin.timings) { |
| if (t.related_pin != ti.related_pin) |
| continue; |
| auto ipower_copy = t.internal_power; |
| t = ti; |
| t.internal_power = ipower_copy; |
| found = true; |
| break; |
| } |
| if (!found) { |
| cellpin.timings.push_back(ti); |
| } |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
| |
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find group brace '}' in cellpin ", cellpin.name); |
| } |
|
|
| return cellpin; |
| } |
|
|
| |
| Cell Celllib::_extract_cell(token_iterator& itr, const token_iterator end) { |
| |
| Cell cell; |
| |
| if(itr=on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& name) mutable { cell.name = name; }); itr==end) { |
| OT_LOGF("can't find cell name"); |
| } |
|
|
| |
| if(itr = std::find(itr, end, "{"); itr == end) { |
| OT_LOGF("can't find group brace '{' in cell ", cell.name); |
| } |
|
|
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| if(*itr == "cell_leakage_power") { |
| OT_LOGF_IF(++itr == end, "can't get leakage power in cell ", cell.name); |
| cell.leakage_power = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "cell_footprint") { |
| OT_LOGF_IF(++itr == end, "can't get footprint in cell ", cell.name); |
| cell.cell_footprint = *itr; |
| } |
| else if(*itr == "area") { |
| OT_LOGF_IF(++itr == end, "can't get area in cell ", cell.name); |
| cell.area = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "pin") { |
| auto pin = _extract_cellpin(itr, end); |
| cell.cellpins[pin.name] = std::move(pin); |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| |
| } |
| } |
|
|
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find group brace '}' in cell ", cell.name); |
| } |
|
|
| return cell; |
| } |
|
|
| |
| void Celllib::read(const std::filesystem::path& path) { |
| |
| std::ifstream ifs(path, std::ios::ate); |
| |
| |
| OT_LOGF_IF(!ifs, "failed to open celllib ", path); |
|
|
| size_t fsize = ifs.tellg(); |
| ifs.seekg(0, std::ios::beg); |
| std::vector<char> buffer(fsize + 1); |
| ifs.read(buffer.data(), fsize); |
| buffer[fsize] = 0; |
|
|
| |
| std::vector<std::string_view> tokens; |
| tokens.reserve(buffer.size() / sizeof(std::string)); |
|
|
| _uncomment(buffer); |
| _tokenize (buffer, tokens); |
|
|
| |
| auto itr = tokens.begin(); |
| auto end = tokens.end(); |
|
|
| |
| if(itr = std::find(itr, end, "library"); itr == end) { |
| OT_LOGF("can't find keyword ", std::quoted("library")); |
| } |
|
|
| if(itr = on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& str) mutable { name = str; }); itr == end) { |
| OT_LOGF("can't find library name"); |
| } |
|
|
| |
| if(itr = std::find(itr, tokens.end(), "{"); itr == tokens.end()) { |
| OT_LOGF("can't find library group symbol '{'"); |
| } |
|
|
| int stack = 1; |
| |
| while(stack && ++itr != end) { |
| |
| if(*itr == "lu_table_template") { |
| auto lut = _extract_lut_template(itr, end); |
| lut_templates[lut.name] = lut; |
| } |
| else if(*itr == "power_lut_template") { |
| auto lut = _extract_lut_template(itr, end); |
| lut_templates[lut.name] = lut; |
| } |
| else if(*itr == "delay_model") { |
| OT_LOGF_IF(++itr == end, "syntax error in delay_model"); |
| if(auto ditr = delay_models.find(*itr); ditr != delay_models.end()) { |
| delay_model = ditr->second; |
| } |
| else { |
| OT_LOGW("unexpected delay model ", *itr); |
| } |
| } |
| else if(*itr == "default_cell_leakage_power") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_cell_leakage_power"); |
| default_cell_leakage_power = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_inout_pin_cap") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_inout_pin_cap"); |
| default_inout_pin_cap = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_input_pin_cap") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_input_pin_cap"); |
| default_input_pin_cap = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_output_pin_cap") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_output_pin_cap"); |
| default_output_pin_cap = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_fanout_load") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_fanout_load"); |
| default_fanout_load = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_max_fanout") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_max_fanout"); |
| default_max_fanout = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "default_max_transition") { |
| OT_LOGF_IF(++itr == end, "syntax error in default_max_transition"); |
| default_max_transition = std::strtof(itr->data(), nullptr); |
| } |
| else if(*itr == "operating_conditions") { |
| OT_LOGF_IF(++itr == end, "syntax error in operating_conditions"); |
| voltage = _extract_operating_conditions(itr, end); |
| |
| }else if(*itr == "time_unit") { |
| OT_LOGF_IF(++itr == end, "time_unit syntax error"); |
| time_unit = make_time_unit(*itr); |
| } |
| else if(*itr == "voltage_unit") { |
| OT_LOGF_IF(++itr == end, "voltage_unit syntax error"); |
| voltage_unit = make_voltage_unit(*itr); |
| } |
| else if(*itr == "current_unit") { |
| OT_LOGF_IF(++itr == end, "current_unit syntax error"); |
| current_unit = make_current_unit(*itr); |
| } |
| else if(*itr == "pulling_resistance_unit") { |
| OT_LOGF_IF(++itr == end, "pulling_resistance_unit syntax error"); |
| resistance_unit = make_resistance_unit(*itr); |
| } |
| else if(*itr == "leakage_power_unit") { |
| OT_LOGF_IF(++itr == end, "leakage_power_unit syntax error"); |
| power_unit = make_power_unit(*itr); |
| } |
| else if(*itr == "capacitive_load_unit") { |
| std::string unit; |
| if(itr = on_next_parentheses( |
| itr, |
| end, |
| [&] (auto& str) mutable { unit += str; }); itr == end) { |
| OT_LOGF("capacitive_load_unit syntax error"); |
| } |
| capacitance_unit = make_capacitance_unit(unit); |
| } |
| else if(*itr == "cell") { |
| auto cell = _extract_cell(itr, end); |
| cells[cell.name] = std::move(cell); |
| } |
| else if(*itr == "}") { |
| stack--; |
| } |
| else if(*itr == "{") { |
| stack++; |
| } |
| else { |
| } |
| } |
|
|
| if(stack != 0 || *itr != "}") { |
| OT_LOGF("can't find library group brace '}'"); |
| } |
|
|
| _apply_default_values(); |
| } |
| |
| |
| void Celllib::_apply_default_values() { |
|
|
| for(auto& ckvp : cells) { |
| |
| auto& cell = ckvp.second; |
| |
| |
| if(!cell.leakage_power) { |
| cell.leakage_power = default_cell_leakage_power; |
| } |
|
|
| for(auto& pkvp : cell.cellpins) { |
|
|
| auto& cpin = pkvp.second; |
|
|
| |
| if(!cpin.direction) { |
| OT_LOGW("cellpin ", cell.name, '/', cpin.name, " has no direction defined"); |
| continue; |
| } |
|
|
| switch(*cpin.direction) { |
|
|
| case CellpinDirection::INPUT: |
| if(!cpin.capacitance) { |
| cpin.capacitance = default_input_pin_cap; |
| } |
|
|
| if(!cpin.fanout_load) { |
| cpin.fanout_load = default_fanout_load; |
| } |
| break; |
|
|
| case CellpinDirection::OUTPUT: |
| if(!cpin.capacitance) { |
| cpin.capacitance = default_output_pin_cap; |
| } |
|
|
| if(!cpin.max_fanout) { |
| cpin.max_fanout = default_max_fanout; |
| } |
|
|
| if(!cpin.max_transition) { |
| cpin.max_transition = default_max_transition; |
| } |
| break; |
|
|
| case CellpinDirection::INOUT: |
| if(!cpin.capacitance) { |
| cpin.capacitance = default_inout_pin_cap; |
| } |
| break; |
|
|
| case CellpinDirection::INTERNAL: |
| break; |
| } |
| |
| } |
| } |
| } |
|
|
| |
| |
| void Celllib::scale_time(float s) { |
| |
| if(default_max_transition) { |
| default_max_transition = *default_max_transition * s; |
| } |
|
|
| for(auto& c : cells) { |
| c.second.scale_time(s); |
| } |
| } |
|
|
| |
| void Celllib::scale_capacitance(float s) { |
| |
| if(default_inout_pin_cap) { |
| default_inout_pin_cap = *default_inout_pin_cap * s; |
| } |
| |
| if(default_input_pin_cap) { |
| default_input_pin_cap = *default_input_pin_cap * s; |
| } |
| |
| if(default_output_pin_cap) { |
| default_output_pin_cap = *default_output_pin_cap * s; |
| } |
| |
| for(auto& c : cells) { |
| c.second.scale_capacitance(s); |
| } |
| } |
|
|
| |
| void Celllib::scale_voltage(float s) { |
| |
| } |
|
|
| |
| void Celllib::scale_current(float s) { |
|
|
| |
| } |
|
|
| |
| void Celllib::scale_resistance(float s) { |
| |
| } |
|
|
| |
| void Celllib::scale_power(float s) { |
| |
| } |
|
|
| |
| std::ostream& operator << (std::ostream& os, const Celllib& c) { |
|
|
| |
| os << "/* Generated by OpenTimer " << " */\n"; |
| |
| |
| os << "library (\"" << c.name << "\") {\n\n"; |
|
|
| |
| if(c.delay_model) { |
| os << "delay_model : " << to_string(*(c.delay_model)) << ";\n"; |
| } |
|
|
| |
| if(auto u = c.time_unit; u) { |
| os << "time_unit : \"" << u->value() << "s\"\n"; |
| } |
|
|
| if(auto u = c.voltage_unit; u) { |
| os << "voltage_unit : \"" << u->value() << "V\"\n"; |
| } |
| |
| if(auto u = c.current_unit; u) { |
| os << "current_unit : \"" << u->value() << "A\"\n"; |
| } |
| |
| if(auto u = c.resistance_unit; u) { |
| os << "pulling_resistance_unit : \"" << u->value() << "ohm\"\n"; |
| } |
|
|
| if(auto u = c.power_unit; u) { |
| os << "leakage_power_unit : \"" << u->value() << "W\"\n"; |
| } |
|
|
| if(auto u = c.capacitance_unit; u) { |
| os << "capacitive_load_unit (" << u->value() << ",F)\"\n"; |
| } |
| |
| |
| if(c.default_cell_leakage_power) { |
| os << *c.default_cell_leakage_power << '\n'; |
| } |
|
|
| if(c.default_inout_pin_cap) { |
| os << *c.default_inout_pin_cap << '\n'; |
| } |
|
|
| if(c.default_input_pin_cap) { |
| os << *c.default_input_pin_cap << '\n'; |
| } |
|
|
| if(c.default_output_pin_cap) { |
| os << *c.default_fanout_load << '\n'; |
| } |
| |
| if(c.default_max_fanout) { |
| os << *c.default_max_fanout << '\n'; |
| } |
| |
| if(c.default_max_transition) { |
| os << *c.default_max_transition << '\n'; |
| } |
|
|
| |
| for(const auto& kvp : c.lut_templates) { |
| os << kvp.second << '\n'; |
| } |
|
|
| |
| for(const auto& kvp : c.cells) { |
| os << kvp.second << '\n'; |
| } |
|
|
| |
| os << "}\n"; |
|
|
| return os; |
| } |
|
|
|
|
|
|
| }; |
|
|
|
|
|
|
|
|
|
|
|
|