diff --git a/examples/multi_corner.tcl b/examples/multi_corner.tcl index 4900d867..fa5fab18 100644 --- a/examples/multi_corner.tcl +++ b/examples/multi_corner.tcl @@ -17,4 +17,3 @@ define_scene ff -liberty NangateOpenCellLibrary_fast report_checks -path_delay min_max # report typical scene report_checks -scene tt - diff --git a/graph/Graph.cc b/graph/Graph.cc index 2fe4d934..9e0b189d 100644 --- a/graph/Graph.cc +++ b/graph/Graph.cc @@ -1236,6 +1236,8 @@ Edge::to_string(const StaState *sta) const string str = from(graph)->to_string(sta); str += " -> "; str += to(graph)->to_string(sta); + str += " "; + str += role()->to_string(); FuncExpr *when = arc_set_->cond(); if (when) { str += " "; diff --git a/graph/Graph.i b/graph/Graph.i index ed9ad710..b6f3c3c5 100644 --- a/graph/Graph.i +++ b/graph/Graph.i @@ -171,6 +171,7 @@ path_iterator(const RiseFall *rf, } // Vertex methods %extend Edge { +std::string to_string() { return self->to_string(Sta::sta()); }; Vertex *from() { return self->from(Sta::sta()->graph()); } Vertex *to() { return self->to(Sta::sta()->graph()); } Pin *from_pin() { return self->from(Sta::sta()->graph())->pin(); } diff --git a/include/sta/Liberty.hh b/include/sta/Liberty.hh index 68d43bb3..02769b84 100644 --- a/include/sta/Liberty.hh +++ b/include/sta/Liberty.hh @@ -253,7 +253,7 @@ public: float wire_delay) const; // Check for supported axis variables. // Return true if axes are supported. - static bool checkSlewDegradationAxes(const TablePtr &table); + static bool checkSlewDegradationAxes(const TableModel *table_model); float defaultInputPinCap() const { return default_input_pin_cap_; } void setDefaultInputPinCap(float cap); @@ -1051,7 +1051,7 @@ public: void setScale(ScaleFactorType type, ScaleFactorPvt pvt, float scale); - void print(); + void report(Report *report); protected: std::string name_; diff --git a/include/sta/TableModel.hh b/include/sta/TableModel.hh index 1d08d751..1e88faf6 100644 --- a/include/sta/TableModel.hh +++ b/include/sta/TableModel.hh @@ -49,6 +49,7 @@ using FloatTable = std::vector; // Sequence of 1D tables (order 1). using Table1Seq = std::vector; using Waveform = Table; +using TableModelsEarlyLate = std::array; TableAxisVariable stringTableAxisVariable(const char *variable); @@ -63,11 +64,14 @@ class GateTableModel : public GateTimingModel public: GateTableModel(LibertyCell *cell, TableModel *delay_model, - TableModel *delay_sigma_models[EarlyLate::index_count], + TableModelsEarlyLate delay_sigma_models, TableModel *slew_model, - TableModel *slew_sigma_models[EarlyLate::index_count], + TableModelsEarlyLate slew_sigma_models, ReceiverModelPtr receiver_model, OutputWaveforms *output_waveforms); + GateTableModel(LibertyCell *cell, + TableModel *delay_model, + TableModel *slew_model); ~GateTableModel() override; void gateDelay(const Pvt *pvt, float in_slew, @@ -100,7 +104,7 @@ public: OutputWaveforms *outputWaveforms() const { return output_waveforms_.get(); } // Check the axes before making the model. // Return true if the model axes are supported. - static bool checkAxes(const TablePtr &table); + static bool checkAxes(const TableModel *table); protected: void maxCapSlew(float in_slew, @@ -135,9 +139,9 @@ protected: static bool checkAxis(const TableAxis *axis); std::unique_ptr delay_model_; - std::array, EarlyLate::index_count> delay_sigma_models_; + TableModelsEarlyLate delay_sigma_models_; std::unique_ptr slew_model_; - std::array, EarlyLate::index_count> slew_sigma_models_; + TableModelsEarlyLate slew_sigma_models_; ReceiverModelPtr receiver_model_; std::unique_ptr output_waveforms_; }; @@ -147,7 +151,9 @@ class CheckTableModel : public CheckTimingModel public: CheckTableModel(LibertyCell *cell, TableModel *model, - TableModel *sigma_models[EarlyLate::index_count]); + TableModelsEarlyLate sigma_models); + CheckTableModel(LibertyCell *cell, + TableModel *model); ~CheckTableModel() override; ArcDelay checkDelay(const Pvt *pvt, float from_slew, @@ -166,7 +172,7 @@ public: // Check the axes before making the model. // Return true if the model axes are supported. - static bool checkAxes(const TablePtr table); + static bool checkAxes(const TableModel *table); protected: void setIsScaled(bool is_scaled) override; @@ -197,7 +203,7 @@ protected: static bool checkAxis(const TableAxis *axis); std::unique_ptr model_; - std::array, EarlyLate::index_count> sigma_models_; + TableModelsEarlyLate sigma_models_; }; class TableAxis @@ -254,6 +260,8 @@ public: const TableAxis *axis2() const { return axis2_.get(); } const TableAxis *axis3() const { return axis3_.get(); } const TableAxisPtr axis1ptr() const { return axis1_; } + const TableAxisPtr axis2ptr() const { return axis2_; } + const TableAxisPtr axis3ptr() const { return axis3_; } void setIsScaled(bool is_scaled); float value(size_t axis_idx1, @@ -409,7 +417,7 @@ public: void setCapacitanceModel(TableModel table_model, size_t segment, const RiseFall *rf); - static bool checkAxes(TablePtr table); + static bool checkAxes(const TableModel *table); private: std::vector capacitance_models_; diff --git a/include/sta/TimingArc.hh b/include/sta/TimingArc.hh index 347e37f1..63c04d49 100644 --- a/include/sta/TimingArc.hh +++ b/include/sta/TimingArc.hh @@ -99,7 +99,7 @@ class TimingArcAttrs public: TimingArcAttrs(); TimingArcAttrs(TimingSense sense); - virtual ~TimingArcAttrs(); + ~TimingArcAttrs(); TimingType timingType() const { return timing_type_; } void setTimingType(TimingType type); TimingSense timingSense() const { return timing_sense_; } @@ -145,7 +145,8 @@ class TimingArcSet friend class LibertyCell; public: - virtual ~TimingArcSet(); + ~TimingArcSet(); + std::string to_string(); LibertyCell *libertyCell() const; LibertyPort *from() const { return from_; } LibertyPort *to() const { return to_; } @@ -249,7 +250,7 @@ public: TimingArcSet *set() const { return set_; } TimingSense sense() const; // Index in TimingArcSet. - unsigned index() const { return index_; } + size_t index() const { return index_; } TimingModel *model() const { return model_; } GateTimingModel *gateModel(const Scene *scene, const MinMax *min_max) const; @@ -270,7 +271,7 @@ public: protected: TimingModel *model(const Scene *scene, const MinMax *min_max) const; - void setIndex(unsigned index); + void setIndex(size_t index); void addScaledModel(const OperatingConditions *op_cond, TimingModel *scaled_model); diff --git a/include/sta/TokenParser.hh b/include/sta/TokenParser.hh index a339a6a8..27db37f9 100644 --- a/include/sta/TokenParser.hh +++ b/include/sta/TokenParser.hh @@ -24,8 +24,13 @@ #pragma once +#include +#include + namespace sta { +using StdStringSeq = std::vector; + // Iterate over the tokens in str separated by character sep. // Similar in functionality to strtok, but does not leave the string // side-effected. This is preferable to using strtok because it leaves @@ -49,4 +54,9 @@ private: bool first_; }; +// Parse delimiter separated tokens and skipp spaces. +StdStringSeq +parseTokens(const std::string &s, + const char delimiter); + } // namespace diff --git a/include/sta/Transition.hh b/include/sta/Transition.hh index 39190c6c..3f3e03c6 100644 --- a/include/sta/Transition.hh +++ b/include/sta/Transition.hh @@ -48,6 +48,7 @@ public: static const RiseFall *fall() { return &fall_; } static int riseIndex() { return rise_.sdf_triple_index_; } static int fallIndex() { return fall_.sdf_triple_index_; } + const std::string &to_string_long() const { return name_; } const std::string &to_string() const { return short_name_; } const char *name() const { return name_.c_str(); } const char *shortName() const { return short_name_.c_str(); } diff --git a/liberty/LibExprReader.cc b/liberty/LibExprReader.cc index c9bc84bc..dfb2d679 100644 --- a/liberty/LibExprReader.cc +++ b/liberty/LibExprReader.cc @@ -37,7 +37,7 @@ namespace sta { FuncExpr * parseFuncExpr(const char *func, - LibertyCell *cell, + const LibertyCell *cell, const char *error_msg, Report *report) { @@ -56,7 +56,7 @@ parseFuncExpr(const char *func, } LibExprReader::LibExprReader(const char *func, - LibertyCell *cell, + const LibertyCell *cell, const char *error_msg, Report *report) : func_(func), @@ -69,7 +69,7 @@ LibExprReader::LibExprReader(const char *func, // defined in LibertyReader.cc LibertyPort * -libertyReaderFindPort(LibertyCell *cell, +libertyReaderFindPort(const LibertyCell *cell, const char *port_name); FuncExpr * diff --git a/liberty/LibExprReader.hh b/liberty/LibExprReader.hh index 79d6d35f..fa36aaa3 100644 --- a/liberty/LibExprReader.hh +++ b/liberty/LibExprReader.hh @@ -32,7 +32,7 @@ class LibertyCell; FuncExpr * parseFuncExpr(const char *func, - LibertyCell *cell, + const LibertyCell *cell, const char *error_msg, Report *report); diff --git a/liberty/LibExprReaderPvt.hh b/liberty/LibExprReaderPvt.hh index 4532b2e8..06a65ea2 100644 --- a/liberty/LibExprReaderPvt.hh +++ b/liberty/LibExprReaderPvt.hh @@ -35,7 +35,7 @@ class LibExprReader { public: LibExprReader(const char *func, - LibertyCell *cell, + const LibertyCell *cell, const char *error_msg, Report *report); FuncExpr *makeFuncExprPort(const char *port_name); @@ -55,7 +55,7 @@ public: private: const char *func_; - LibertyCell *cell_; + const LibertyCell *cell_; const char *error_msg_; Report *report_; FuncExpr *result_; diff --git a/liberty/Liberty.cc b/liberty/Liberty.cc index d83d06b7..5df31143 100644 --- a/liberty/Liberty.cc +++ b/liberty/Liberty.cc @@ -111,8 +111,6 @@ LibertyLibrary::LibertyLibrary(const char *name, LibertyLibrary::~LibertyLibrary() { - delete scale_factors_; - for (auto rf_index : RiseFall::rangeIndex()) { TableModel *model = wire_slew_degradation_tbls_[rf_index]; delete model; @@ -271,14 +269,14 @@ LibertyLibrary::setScaleFactors(ScaleFactors *scales) ScaleFactors * LibertyLibrary::makeScaleFactors(const char *name) { - auto [it, inserted] = scale_factors_map_.emplace(std::string(name), name); + auto [it, inserted] = scale_factors_map_.emplace(name, name); return &it->second; } ScaleFactors * LibertyLibrary::findScaleFactors(const char *name) { - return findKeyValuePtr(scale_factors_map_, std::string(name)); + return findKeyValuePtr(scale_factors_map_, name); } float @@ -400,20 +398,20 @@ LibertyLibrary::degradeWireSlew(const TableModel *model, // Check for supported axis variables. // Return true if axes are supported. bool -LibertyLibrary::checkSlewDegradationAxes(const TablePtr &table) +LibertyLibrary::checkSlewDegradationAxes(const TableModel *table_model) { - switch (table->order()) { + switch (table_model->order()) { case 0: return true; case 1: { - const TableAxis *axis1 = table->axis1(); + const TableAxis *axis1 = table_model->axis1(); TableAxisVariable var1 = axis1->variable(); return var1 == TableAxisVariable::output_pin_transition || var1 == TableAxisVariable::connect_delay; } case 2: { - const TableAxis *axis1 = table->axis1(); - const TableAxis *axis2 = table->axis2(); + const TableAxis *axis1 = table_model->axis1(); + const TableAxis *axis2 = table_model->axis2(); TableAxisVariable var1 = axis1->variable(); TableAxisVariable var2 = axis2->variable(); return (var1 == TableAxisVariable::output_pin_transition @@ -1269,8 +1267,7 @@ LibertyCell::makeInternalPower(LibertyPort *port, const std::shared_ptr &when, InternalPowerModels &models) { - internal_powers_.emplace_back(port, related_port, related_pg_pin, - when, models); + internal_powers_.emplace_back(port, related_port, related_pg_pin, when, models); port_internal_powers_[port].push_back(internal_powers_.size() - 1); } @@ -1485,6 +1482,10 @@ LibertyCell::makeSequential(int size, port_to_seq_map_[sequentials_.back().output()] = idx; port_to_seq_map_[sequentials_.back().outputInv()] = idx; } + delete clk; + delete data; + delete clear; + delete preset; } Sequential * @@ -3087,7 +3088,8 @@ OperatingConditions::setWireloadTree(WireloadTree tree) static EnumNameMap scale_factor_type_map = {{ScaleFactorType::pin_cap, "pin_cap"}, - {ScaleFactorType::wire_cap, "wire_res"}, + {ScaleFactorType::wire_cap, "wire_cap"}, + {ScaleFactorType::wire_res, "wire_res"}, {ScaleFactorType::min_period, "min_period"}, {ScaleFactorType::cell, "cell"}, {ScaleFactorType::hold, "hold"}, @@ -3124,7 +3126,9 @@ scaleFactorTypeRiseFallSuffix(ScaleFactorType type) || type == ScaleFactorType::recovery || type == ScaleFactorType::removal || type == ScaleFactorType::nochange - || type == ScaleFactorType::skew; + || type == ScaleFactorType::skew + || type == ScaleFactorType::leakage_power + || type == ScaleFactorType::internal_power; } bool @@ -3144,7 +3148,8 @@ scaleFactorTypeLowHighSuffix(ScaleFactorType type) EnumNameMap scale_factor_pvt_names = {{ScaleFactorPvt::process, "process"}, {ScaleFactorPvt::volt, "volt"}, - {ScaleFactorPvt::temp, "temp"} + {ScaleFactorPvt::temp, "temp"}, + {ScaleFactorPvt::unknown, "unknown"} }; ScaleFactorPvt @@ -3214,31 +3219,32 @@ ScaleFactors::scale(ScaleFactorType type, } void -ScaleFactors::print() +ScaleFactors::report(Report *report) { - printf("%10s", " "); + std::string line = " "; for (int pvt_index = 0; pvt_index < scale_factor_pvt_count; pvt_index++) { ScaleFactorPvt pvt = (ScaleFactorPvt) pvt_index; - printf("%10s", scaleFactorPvtName(pvt)); + stringAppend(line, "%10s", scaleFactorPvtName(pvt)); } - printf("\n"); + report->reportLineString(line); + for (int type_index = 0; type_index < scale_factor_type_count; type_index++) { ScaleFactorType type = (ScaleFactorType) type_index; - printf("%10s ", scaleFactorTypeName(type)); + stringPrint(line, "%10s ", scaleFactorTypeName(type)); for (int pvt_index = 0; pvt_index < scale_factor_pvt_count; pvt_index++) { if (scaleFactorTypeRiseFallSuffix(type) || scaleFactorTypeRiseFallPrefix(type) || scaleFactorTypeLowHighSuffix(type)) { - printf(" %.3f,%.3f", - scales_[type_index][pvt_index][RiseFall::riseIndex()], - scales_[type_index][pvt_index][RiseFall::fallIndex()]); + stringAppend(line, " %.3f,%.3f", + scales_[type_index][pvt_index][RiseFall::riseIndex()], + scales_[type_index][pvt_index][RiseFall::fallIndex()]); } else { - printf(" %.3f", - scales_[type_index][pvt_index][0]); + stringAppend(line, " %.3f", + scales_[type_index][pvt_index][0]); } } - printf("\n"); + report->reportLineString(line); } } diff --git a/liberty/Liberty.i b/liberty/Liberty.i index 96223170..2257b2eb 100644 --- a/liberty/Liberty.i +++ b/liberty/Liberty.i @@ -363,6 +363,7 @@ scan_signal_type() %extend TimingArcSet { LibertyPort *from() { return self->from(); } LibertyPort *to() { return self->to(); } +std::string to_string() { return self->to_string(); } const TimingRole *role() { return self->role(); } const char *sdf_cond() { return self->sdfCond().c_str(); } diff --git a/liberty/Liberty.tcl b/liberty/Liberty.tcl index 672e876f..fd75a8bf 100644 --- a/liberty/Liberty.tcl +++ b/liberty/Liberty.tcl @@ -74,6 +74,11 @@ proc report_lib_cell_ { cell scene } { if { $filename != "" } { report_line "File $filename" } + report_lib_ports $cell $scene + report_timing_arcs $cell +} + +proc report_lib_ports { cell scene } { set iter [$cell liberty_port_iterator] while {[$iter has_next]} { set port [$iter next] @@ -115,5 +120,16 @@ proc report_lib_port { port scene } { report_line " ${indent}$port_name [liberty_port_direction $port]$enable$func[port_capacitance_str $port $scene $sta_report_default_digits]" } +proc report_timing_arcs { cell } { + set timing_arcs [$cell timing_arc_sets] + if { [llength $timing_arcs] > 0 } { + puts "" + puts "Timing arcs" + foreach timing_arc $timing_arcs { + puts [$timing_arc to_string] + } + } +} + # sta namespace end } diff --git a/liberty/LibertyBuilder.cc b/liberty/LibertyBuilder.cc index b20d8c62..988c32e9 100644 --- a/liberty/LibertyBuilder.cc +++ b/liberty/LibertyBuilder.cc @@ -35,14 +35,11 @@ namespace sta { -using std::string; - -void -LibertyBuilder::init(Debug *debug, - Report *report) +LibertyBuilder::LibertyBuilder(Debug *debug, + Report *report) : + debug_(debug), + report_(report) { - debug_ = debug; - report_ = report; } LibertyCell * @@ -105,7 +102,7 @@ LibertyBuilder::makeBusPortBit(ConcreteLibrary *library, const char *bus_name, int bit_index) { - string bit_name; + std::string bit_name; stringPrint(bit_name, "%s%c%d%c", bus_name, library->busBrktLeft(), @@ -189,6 +186,7 @@ LibertyBuilder::makeTimingArcs(LibertyCell *cell, case TimingType::combinational: if (seq && seq->isLatch() + && seq->data() && seq->data()->hasPort(from_port)) // Latch D->Q timing arcs. return makeLatchDtoQArcs(cell, from_port, to_port, @@ -307,8 +305,9 @@ LibertyBuilder::makeCombinationalArcs(LibertyCell *cell, { FuncExpr *func = to_port->function(); FuncExpr *enable = to_port->tristateEnable(); - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, - TimingRole::combinational(), attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, nullptr, + TimingRole::combinational(), + attrs); TimingSense sense = attrs->timingSense(); if (sense == TimingSense::unknown) { // Timing sense not specified - find it from function. @@ -388,8 +387,9 @@ LibertyBuilder::makeLatchDtoQArcs(LibertyCell *cell, TimingSense sense, TimingArcAttrsPtr attrs) { - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, - TimingRole::latchDtoQ(), attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, nullptr, + TimingRole::latchDtoQ(), + attrs); TimingModel *model; const RiseFall *to_rf = RiseFall::rise(); model = attrs->model(to_rf); @@ -456,8 +456,8 @@ LibertyBuilder::makeFromTransitionArcs(LibertyCell *cell, const TimingRole *role, TimingArcAttrsPtr attrs) { - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, - related_out, role, attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, + related_out, role, attrs); for (auto to_rf : RiseFall::range()) { TimingModel *model = attrs->model(to_rf); if (model) @@ -476,8 +476,8 @@ LibertyBuilder::makePresetClrArcs(LibertyCell *cell, TimingArcSet *arc_set = nullptr; TimingModel *model = attrs->model(to_rf); if (model) { - arc_set = makeTimingArcSet(cell, from_port, to_port, - TimingRole::regSetClr(), attrs); + arc_set = cell->makeTimingArcSet(from_port, to_port, nullptr, + TimingRole::regSetClr(), attrs); const RiseFall *opp_rf = to_rf->opposite(); switch (attrs->timingSense()) { case TimingSense::positive_unate: @@ -509,8 +509,9 @@ LibertyBuilder::makeTristateEnableArcs(LibertyCell *cell, bool to_fall, TimingArcAttrsPtr attrs) { - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, - TimingRole::tristateEnable(), attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, nullptr, + TimingRole::tristateEnable(), + attrs); FuncExpr *tristate_enable = to_port->tristateEnable(); TimingSense sense = attrs->timingSense(); if (sense == TimingSense::unknown && tristate_enable) @@ -579,9 +580,9 @@ LibertyBuilder::makeTristateDisableArcs(LibertyCell *cell, bool to_fall, TimingArcAttrsPtr attrs) { - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, - TimingRole::tristateDisable(), - attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, nullptr, + TimingRole::tristateDisable(), + attrs); TimingSense sense = attrs->timingSense(); FuncExpr *tristate_enable = to_port->tristateEnable(); if (sense == TimingSense::unknown && tristate_enable) @@ -648,7 +649,8 @@ LibertyBuilder::makeClockTreePathArcs(LibertyCell *cell, const TimingRole *role, TimingArcAttrsPtr attrs) { - TimingArcSet *arc_set = makeTimingArcSet(cell, nullptr, to_port, role, attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(nullptr, to_port, nullptr, + role, attrs); for (const RiseFall *to_rf : RiseFall::range()) { TimingModel *model = attrs->model(to_rf); if (model) { @@ -683,8 +685,8 @@ LibertyBuilder::makeMinPulseWidthArcs(LibertyCell *cell, { if (from_port == nullptr) from_port = to_port; - TimingArcSet *arc_set = makeTimingArcSet(cell, from_port, to_port, related_out, - role, attrs); + TimingArcSet *arc_set = cell->makeTimingArcSet(from_port, to_port, related_out, + role, attrs); for (const RiseFall *from_rf : RiseFall::range()) { TimingModel *model = attrs->model(from_rf); if (model) @@ -695,27 +697,6 @@ LibertyBuilder::makeMinPulseWidthArcs(LibertyCell *cell, //////////////////////////////////////////////////////////////// -TimingArcSet * -LibertyBuilder::makeTimingArcSet(LibertyCell *cell, - LibertyPort *from, - LibertyPort *to, - const TimingRole *role, - TimingArcAttrsPtr attrs) -{ - return cell->makeTimingArcSet(from, to, nullptr, role, attrs); -} - -TimingArcSet * -LibertyBuilder::makeTimingArcSet(LibertyCell *cell, - LibertyPort *from, - LibertyPort *to, - LibertyPort *related_out, - const TimingRole *role, - TimingArcAttrsPtr attrs) -{ - return cell->makeTimingArcSet(from, to, related_out, role, attrs); -} - TimingArc * LibertyBuilder::makeTimingArc(TimingArcSet *set, const RiseFall *from_rf, diff --git a/liberty/LibertyBuilder.hh b/liberty/LibertyBuilder.hh index dacbbb41..06538687 100644 --- a/liberty/LibertyBuilder.hh +++ b/liberty/LibertyBuilder.hh @@ -38,23 +38,21 @@ class Report; class LibertyBuilder { public: - LibertyBuilder() {} - virtual ~LibertyBuilder() {} - void init(Debug *debug, - Report *report); - virtual LibertyCell *makeCell(LibertyLibrary *library, - const char *name, - const char *filename); - virtual LibertyPort *makePort(LibertyCell *cell, - const char *name); - virtual LibertyPort *makeBusPort(LibertyCell *cell, - const char *bus_name, - int from_index, - int to_index, - BusDcl *bus_dcl); - virtual LibertyPort *makeBundlePort(LibertyCell *cell, - const char *name, - ConcretePortSeq *members); + LibertyBuilder(Debug *debug, + Report *report); + LibertyCell *makeCell(LibertyLibrary *library, + const char *name, + const char *filename); + LibertyPort *makePort(LibertyCell *cell, + const char *name); + LibertyPort *makeBusPort(LibertyCell *cell, + const char *bus_name, + int from_index, + int to_index, + BusDcl *bus_dcl); + LibertyPort *makeBundlePort(LibertyCell *cell, + const char *name, + ConcretePortSeq *members); // Build timing arc sets and their arcs given a type and sense. // Port functions and cell latches are also used by this builder // to get the correct roles. @@ -100,29 +98,18 @@ protected: int from_index, int to_index); // Bus port bit (internal to makeBusPortBits). - virtual LibertyPort *makePort(LibertyCell *cell, - const char *bit_name, - int bit_index); + LibertyPort *makePort(LibertyCell *cell, + const char *bit_name, + int bit_index); void makeBusPortBit(ConcreteLibrary *library, LibertyCell *cell, ConcretePort *bus_port, const char *bus_name, int index); - virtual TimingArcSet *makeTimingArcSet(LibertyCell *cell, - LibertyPort *from, - LibertyPort *to, - const TimingRole *role, - TimingArcAttrsPtr attrs); - virtual TimingArcSet *makeTimingArcSet(LibertyCell *cell, - LibertyPort *from, - LibertyPort *to, - LibertyPort *related_out, - const TimingRole *role, - TimingArcAttrsPtr attrs); - virtual TimingArc *makeTimingArc(TimingArcSet *set, - const Transition *from_rf, - const Transition *to_rf, - TimingModel *model); + TimingArc *makeTimingArc(TimingArcSet *set, + const Transition *from_rf, + const Transition *to_rf, + TimingModel *model); TimingArc *makeTimingArc(TimingArcSet *set, const RiseFall *from_rf, const RiseFall *to_rf, diff --git a/liberty/LibertyExt.cc b/liberty/LibertyExt.cc index d45a7420..32c10b5e 100644 --- a/liberty/LibertyExt.cc +++ b/liberty/LibertyExt.cc @@ -42,8 +42,8 @@ using sta::Report; using sta::Debug; using sta::Network; using sta::LibertyReader; -using sta::LibertyAttr; using sta::LibertyGroup; +using sta::LibertySimpleAttr; using sta::TimingGroup; using sta::LibertyCell; using sta::LibertyPort; @@ -164,13 +164,6 @@ class BigcoLibertyBuilder : public LibertyBuilder public: virtual LibertyCell *makeCell(LibertyLibrary *library, const char *name, const char *filename); - -protected: - virtual TimingArcSet *makeTimingArcSet(LibertyCell *cell, LibertyPort *from, - LibertyPort *to, - LibertyPort *related_out, - const TimingRole *role, - TimingArcAttrsPtr attrs) override; }; LibertyCell * @@ -182,16 +175,6 @@ BigcoLibertyBuilder::makeCell(LibertyLibrary *library, const char *name, return cell; } -TimingArcSet * -BigcoLibertyBuilder::makeTimingArcSet(LibertyCell *cell, LibertyPort *from, - LibertyPort *to, - LibertyPort *related_out, - const TimingRole *role, - TimingArcAttrsPtr attrs) -{ - return cell->makeTimingArcSet(from, to, related_out, role, attrs); -} - //////////////////////////////////////////////////////////////// // Liberty reader to parse Bigco attributes. @@ -201,22 +184,18 @@ public: BigcoLibertyReader(LibertyBuilder *builder); protected: - virtual void visitAttr1(LibertyAttr *attr); - virtual void visitAttr2(LibertyAttr *attr); - virtual void beginLibrary(LibertyGroup *group); + virtual void visitAttr1(const LibertySimpleAttr *attr); + virtual void visitAttr2(const LibertySimpleAttr *attr); + virtual void beginLibrary(const LibertyGroup *group, + const LibertyGroup *library_group); virtual TimingGroup *makeTimingGroup(int line); - virtual void beginCell(LibertyGroup *group); + virtual void beginCell(const LibertyGroup *group, + const LibertyGroup *library_group); }; BigcoLibertyReader::BigcoLibertyReader(LibertyBuilder *builder) : LibertyReader(builder) { - // Define a visitor for the "thingy" attribute. - // Note that the function descriptor passed to defineAttrVisitor - // must be defined by the LibertyVisitor class, so a number of - // extra visitor functions are pre-defined for extensions. - defineAttrVisitor("thingy", &LibertyReader::visitAttr1); - defineAttrVisitor("frob", &LibertyReader::visitAttr2); } bool @@ -228,12 +207,13 @@ libertyCellRequired(const char *) // Prune cells from liberty file based on libertyCellRequired predicate. void -BigcoLibertyReader::beginCell(LibertyGroup *group) +BigcoLibertyReader::beginCell(const LibertyGroup *group, + const LibertyGroup *library_group) { const char *name = group->firstName(); if (name && libertyCellRequired(name)) - LibertyReader::beginCell(group); + LibertyReader::beginCell(group, library_group); } TimingGroup * @@ -244,15 +224,16 @@ BigcoLibertyReader::makeTimingGroup(int line) // Called at the beginning of a library group. void -BigcoLibertyReader::beginLibrary(LibertyGroup *group) +BigcoLibertyReader::beginLibrary(const LibertyGroup *group, + const LibertyGroup *library_group) { - LibertyReader::beginLibrary(group); + LibertyReader::beginLibrary(group, library_group); // Do Bigco stuff here. printf("Bigco was here.\n"); } void -BigcoLibertyReader::visitAttr1(LibertyAttr *attr) +BigcoLibertyReader::visitAttr1(const LibertySimpleAttr *attr) { const char *thingy = getAttrString(attr); if (thingy) { @@ -263,7 +244,7 @@ BigcoLibertyReader::visitAttr1(LibertyAttr *attr) } void -BigcoLibertyReader::visitAttr2(LibertyAttr *attr) +BigcoLibertyReader::visitAttr2(const LibertySimpleAttr *attr) { const char *frob = getAttrString(attr); if (frob) { diff --git a/liberty/LibertyLex.ll b/liberty/LibertyLex.ll index 6df7d07b..22edd696 100644 --- a/liberty/LibertyLex.ll +++ b/liberty/LibertyLex.ll @@ -87,14 +87,14 @@ EOL \r?\n {FLOAT}{TOKEN_END} { /* Push back the TOKEN_END character. */ yyless(yyleng - 1); - yylval->emplace(strtod(yytext, nullptr)); + yylval->emplace(strtof(yytext, nullptr)); return token::FLOAT; } {ALPHA}({ALPHA}|_|{DIGIT})*{TOKEN_END} { /* Push back the TOKEN_END character. */ yyless(yyleng - 1); - yylval->emplace(yytext); + yylval->emplace(yytext, yyleng); return token::KEYWORD; } @@ -107,7 +107,7 @@ EOL \r?\n {TOKEN}{TOKEN_END} { /* Push back the TOKEN_END character. */ yyless(yyleng - 1); - yylval->emplace(yytext); + yylval->emplace(yytext, yyleng); return token::STRING; } @@ -141,7 +141,7 @@ EOL \r?\n {EOL} { error("unterminated string constant"); BEGIN(INITIAL); - yylval->emplace(token_); + yylval->emplace(token_); return token::STRING; } diff --git a/liberty/LibertyParse.yy b/liberty/LibertyParse.yy index 7423c4fe..a3d4b715 100644 --- a/liberty/LibertyParse.yy +++ b/liberty/LibertyParse.yy @@ -52,7 +52,7 @@ sta::LibertyParse::error(const location_type &loc, %require "3.2" %skeleton "lalr1.cc" -%debug +//%debug %define api.namespace {sta} %locations %define api.location.file "LibertyLocation.hh" @@ -72,7 +72,7 @@ sta::LibertyParse::error(const location_type &loc, %left '^' %left '!' -%type statement complex_attr simple_attr variable group file +%type statement complex_attr simple_attr variable group file %type attr_values %type attr_value %type string expr expr_term expr_term1 volt_expr @@ -158,11 +158,11 @@ string: attr_value: FLOAT - { $$ = reader->makeFloatAttrValue($1); } + { $$ = reader->makeAttrValueFloat($1); } | expr - { $$ = reader->makeStringAttrValue(std::move($1)); } + { $$ = reader->makeAttrValueString(std::move($1)); } | volt_expr - { $$ = reader->makeStringAttrValue(std::move($1)); } + { $$ = reader->makeAttrValueString(std::move($1)); } ; /* Voltage expressions are ignored. */ diff --git a/liberty/LibertyParser.cc b/liberty/LibertyParser.cc index 9cf52702..4660aa42 100644 --- a/liberty/LibertyParser.cc +++ b/liberty/LibertyParser.cc @@ -70,21 +70,23 @@ LibertyParser::setFilename(const string &filename) filename_ = filename; } -LibertyStmt * -LibertyParser::makeDefine(LibertyAttrValueSeq *values, +LibertyDefine * +LibertyParser::makeDefine(const LibertyAttrValueSeq *values, int line) { LibertyDefine *define = nullptr; if (values->size() == 3) { - std::string define_name = (*values)[0]->stringValue(); + const std::string &define_name = (*values)[0]->stringValue(); const std::string &group_type_name = (*values)[1]->stringValue(); const std::string &value_type_name = (*values)[2]->stringValue(); - LibertyAttrType value_type = attrValueType(value_type_name.c_str()); - LibertyGroupType group_type = groupType(group_type_name.c_str()); - define = new LibertyDefine(std::move(define_name), group_type, - value_type, line); + LibertyAttrType value_type = attrValueType(value_type_name); + LibertyGroupType group_type = groupType(group_type_name); + define = new LibertyDefine(std::move(define_name), group_type, value_type, line); LibertyGroup *group = this->group(); - group->addStmt(define); + group->addDefine(define); + for (auto value : *values) + delete value; + delete values; } else report_->fileWarn(24, filename_.c_str(), line, @@ -96,42 +98,47 @@ LibertyParser::makeDefine(LibertyAttrValueSeq *values, // used to define valid attribute types. Beyond "string" these are // guesses. LibertyAttrType -LibertyParser::attrValueType(const char *value_type_name) +LibertyParser::attrValueType(const std::string &value_type_name) { - if (stringEq(value_type_name, "string")) + if (value_type_name == "string") return LibertyAttrType::attr_string; - else if (stringEq(value_type_name, "integer")) + else if (value_type_name == "integer") return LibertyAttrType::attr_int; - else if (stringEq(value_type_name, "float")) + else if (value_type_name == "float") return LibertyAttrType::attr_double; - else if (stringEq(value_type_name, "boolean")) + else if (value_type_name == "boolean") return LibertyAttrType::attr_boolean; else return LibertyAttrType::attr_unknown; } LibertyGroupType -LibertyParser::groupType(const char *group_type_name) +LibertyParser::groupType(const std::string &group_type_name) { - if (stringEq(group_type_name, "library")) + if (group_type_name == "library") return LibertyGroupType::library; - else if (stringEq(group_type_name, "cell")) + else if (group_type_name == "cell") return LibertyGroupType::cell; - else if (stringEq(group_type_name, "pin")) + else if (group_type_name == "pin") return LibertyGroupType::pin; - else if (stringEq(group_type_name, "timing")) + else if (group_type_name == "timing") return LibertyGroupType::timing; else return LibertyGroupType::unknown; } void -LibertyParser::groupBegin(std::string type, +LibertyParser::groupBegin(const std::string type, LibertyAttrValueSeq *params, int line) { - LibertyGroup *group = new LibertyGroup(std::move(type), params, line); - group_visitor_->begin(group); + LibertyGroup *group = + new LibertyGroup(std::move(type), + params ? std::move(*params) : LibertyAttrValueSeq(), + line); + delete params; + LibertyGroup *parent_group = group_stack_.empty() ? nullptr : group_stack_.back(); + group_visitor_->begin(group, parent_group); group_stack_.push_back(group); } @@ -139,20 +146,13 @@ LibertyGroup * LibertyParser::groupEnd() { LibertyGroup *group = this->group(); - group_visitor_->end(group); group_stack_.pop_back(); LibertyGroup *parent = group_stack_.empty() ? nullptr : group_stack_.back(); - if (parent && group_visitor_->save(group)) { - parent->addStmt(group); - return group; - } - else if (group_visitor_->save(group)) - return group; - else { - delete group; - return nullptr; - } + if (parent) + parent->addSubgroup(group); + group_visitor_->end(group, parent); + return group; } LibertyGroup * @@ -167,240 +167,65 @@ LibertyParser::deleteGroups() deleteContents(group_stack_); } -LibertyStmt * -LibertyParser::makeSimpleAttr(std::string name, - LibertyAttrValue *value, +LibertySimpleAttr * +LibertyParser::makeSimpleAttr(const std::string name, + const LibertyAttrValue *value, int line) { - LibertyAttr *attr = new LibertySimpleAttr(std::move(name), value, line); - group_visitor_->visitAttr(attr); + LibertySimpleAttr *attr = new LibertySimpleAttr(std::move(name), + std::move(*value), line); + delete value; LibertyGroup *group = this->group(); - if (group && group_visitor_->save(attr)) { - group->addStmt(attr); - return attr; - } - else { - delete attr; - return nullptr; - } + group->addAttr(attr); + group_visitor_->visitAttr(attr); + return attr; } -LibertyStmt * -LibertyParser::makeComplexAttr(std::string name, - LibertyAttrValueSeq *values, +LibertyComplexAttr * +LibertyParser::makeComplexAttr(const std::string name, + const LibertyAttrValueSeq *values, int line) { // Defines have the same syntax as complex attributes. // Detect and convert them. if (name == "define") { - LibertyStmt *define = makeDefine(values, line); - deleteContents(values); - delete values; - return define; + makeDefine(values, line); + return nullptr; // Define is not a complex attr; already added to group } else { - LibertyAttr *attr = new LibertyComplexAttr(std::move(name), values, line); + LibertyComplexAttr *attr = new LibertyComplexAttr(std::move(name), + std::move(*values), + line); + delete values; + LibertyGroup *group = this->group(); + group->addAttr(attr); group_visitor_->visitAttr(attr); - if (group_visitor_->save(attr)) { - LibertyGroup *group = this->group(); - group->addStmt(attr); - return attr; - } - delete attr; - return nullptr; + return attr; } } -LibertyStmt * -LibertyParser::makeVariable(std::string var, +LibertyVariable * +LibertyParser::makeVariable(const std::string var, float value, int line) { LibertyVariable *variable = new LibertyVariable(std::move(var), value, line); + LibertyGroup *group = this->group(); + group->addVariable(variable); group_visitor_->visitVariable(variable); - if (group_visitor_->save(variable)) - return variable; - else { - delete variable; - return nullptr; - } + return variable; } LibertyAttrValue * -LibertyParser::makeStringAttrValue(std::string value) +LibertyParser::makeAttrValueString(std::string value) { - return new LibertyStringAttrValue(std::move(value)); + return new LibertyAttrValue(std::move(value)); } LibertyAttrValue * -LibertyParser::makeFloatAttrValue(float value) -{ - return new LibertyFloatAttrValue(value); -} - -const std::string & -LibertyFloatAttrValue::stringValue() const -{ - criticalError(1127, "LibertyStringAttrValue called for float value"); - static std::string null; - return null; -} - -//////////////////////////////////////////////////////////////// - -LibertyStmt::LibertyStmt(int line) : - line_(line) -{ -} - -LibertyGroup::LibertyGroup(std::string type, - LibertyAttrValueSeq *params, - int line) : - LibertyStmt(line), - type_(std::move(type)), - params_(params), - stmts_(nullptr) -{ -} - -void -LibertyGroup::addStmt(LibertyStmt *stmt) -{ - if (stmts_ == nullptr) - stmts_ = new LibertyStmtSeq; - stmts_->push_back(stmt); -} - -LibertyGroup::~LibertyGroup() -{ - if (params_) { - deleteContents(params_); - delete params_; - } - if (stmts_) { - deleteContents(stmts_); - delete stmts_; - } -} - -const char * -LibertyGroup::firstName() -{ - if (params_ && params_->size() > 0) { - LibertyAttrValue *value = (*params_)[0]; - if (value->isString()) - return value->stringValue().c_str(); - } - return nullptr; -} - -const char * -LibertyGroup::secondName() -{ - if (params_ && params_->size() > 1) { - LibertyAttrValue *value = (*params_)[1]; - if (value->isString()) - return value->stringValue().c_str(); - } - return nullptr; -} - -//////////////////////////////////////////////////////////////// - -LibertyAttr::LibertyAttr(std::string name, - int line) : - LibertyStmt(line), - name_(std::move(name)) -{ -} - -LibertySimpleAttr::LibertySimpleAttr(std::string name, - LibertyAttrValue *value, - int line) : - LibertyAttr(std::move(name), line), - value_(value) -{ -} - -LibertySimpleAttr::~LibertySimpleAttr() -{ - delete value_; -} - -LibertyAttrValueSeq * -LibertySimpleAttr::values() const -{ - criticalError(1125, "valueIterator called for LibertySimpleAttribute"); - return nullptr; -} - -//////////////////////////////////////////////////////////////// - -LibertyComplexAttr::LibertyComplexAttr(std::string name, - LibertyAttrValueSeq *values, - int line) : - LibertyAttr(std::move(name), line), - values_(values) -{ -} - -LibertyComplexAttr::~LibertyComplexAttr() -{ - if (values_) { - deleteContents(values_); - delete values_; - } -} - -LibertyAttrValue * -LibertyComplexAttr::firstValue() -{ - if (values_ && values_->size() > 0) - return (*values_)[0]; - else - return nullptr; -} - -LibertyStringAttrValue::LibertyStringAttrValue(std::string value) : - LibertyAttrValue(), - value_(std::move(value)) -{ -} - -float -LibertyStringAttrValue::floatValue() const -{ - criticalError(1126, "LibertyStringAttrValue called for float value"); - return 0.0; -} - -LibertyFloatAttrValue::LibertyFloatAttrValue(float value) : - value_(value) -{ -} - -//////////////////////////////////////////////////////////////// - -LibertyDefine::LibertyDefine(std::string name, - LibertyGroupType group_type, - LibertyAttrType value_type, - int line) : - LibertyStmt(line), - name_(std::move(name)), - group_type_(group_type), - value_type_(value_type) -{ -} - -//////////////////////////////////////////////////////////////// - -LibertyVariable::LibertyVariable(std::string var, - float value, - int line) : - LibertyStmt(line), - var_(std::move(var)), - value_(value) +LibertyParser::makeAttrValueFloat(float value) { + return new LibertyAttrValue(value); } //////////////////////////////////////////////////////////////// @@ -425,13 +250,13 @@ LibertyScanner::includeBegin() error("nested include_file's are not supported"); else { // include_file(filename); - std::regex include_regexp("include_file *\\( *([^)]+) *\\) *;?"); + static const std::regex include_regexp("include_file *\\( *([^)]+) *\\) *;?"); std::cmatch matches; if (std::regex_match(yytext, matches, include_regexp)) { string filename = matches[1].str(); gzstream::igzstream *stream = new gzstream::igzstream(filename.c_str()); if (stream->is_open()) { - yypush_buffer_state(yy_create_buffer(stream, 256)); + yypush_buffer_state(yy_create_buffer(stream, 16384)); filename_prev_ = filename_; stream_prev_ = stream_; @@ -471,4 +296,323 @@ LibertyScanner::error(const char *msg) report_->fileError(1866, filename_.c_str(), lineno(), "%s", msg); } +//////////////////////////////////////////////////////////////// + +LibertyGroup::LibertyGroup(std::string type, + LibertyAttrValueSeq params, + int line) : + type_(std::move(type)), + params_(std::move(params)), + line_(line) +{ +} + +LibertyGroup::~LibertyGroup() +{ + clear(); +} + +void +LibertyGroup::clear() +{ + deleteContents(params_); + deleteContents(simple_attr_map_); + for (auto &attr : complex_attr_map_) + deleteContents(attr.second); + complex_attr_map_.clear(); + deleteContents(subgroups_); + subgroup_map_.clear(); + deleteContents(define_map_); + deleteContents(variables_); +} + +void +LibertyGroup::addSubgroup(LibertyGroup *subgroup) +{ + subgroups_.push_back(subgroup); + subgroup_map_[subgroup->type()].push_back(subgroup); +} + +void +LibertyGroup::deleteSubgroup(const LibertyGroup *subgroup) +{ + if (subgroup == subgroups_.back()) { + subgroups_.pop_back(); + subgroup_map_[subgroup->type()].pop_back(); + delete subgroup; + } + else + criticalError(1128, "LibertyAttrValue::floatValue() called on string"); +} + +void +LibertyGroup::addDefine(LibertyDefine *define) +{ + const string &define_name = define->name(); + LibertyDefine *prev_define = findKey(define_map_, define_name); + if (prev_define) { + define_map_.erase(define_name); + delete prev_define; + } + define_map_[define_name] = define; +} + +void +LibertyGroup::addAttr(LibertySimpleAttr *attr) +{ + // Only keep the most recent simple attribute value. + const auto &itr = simple_attr_map_.find(attr->name()); + if (itr != simple_attr_map_.end()) + delete itr->second; + simple_attr_map_[attr->name()] = attr; +} + +void +LibertyGroup::addAttr(LibertyComplexAttr *attr) +{ + complex_attr_map_[attr->name()].push_back(attr); +} + +void +LibertyGroup::addVariable(LibertyVariable *var) +{ + variables_.push_back(var); +} + +const char * +LibertyGroup::firstName() const +{ + if (params_.size() >= 1) { + LibertyAttrValue *value = params_[0]; + if (value->isString()) + return value->stringValue().c_str(); + } + return nullptr; +} + +const char * +LibertyGroup::secondName() const +{ + LibertyAttrValue *value = params_[1]; + if (value->isString()) + return value->stringValue().c_str(); + else + return nullptr; +} + +const LibertyGroupSeq & +LibertyGroup::findSubgroups(const std::string type) const +{ + return findKeyValue(subgroup_map_, type); +} + +const LibertyGroup * +LibertyGroup::findSubgroup(const std::string type) const +{ + const LibertyGroupSeq &groups = findKeyValue(subgroup_map_, type); + if (groups.size() >= 1) + return groups[0]; + else + return nullptr; +} + +const LibertySimpleAttr * +LibertyGroup::findSimpleAttr(const std::string attr_name) const +{ + return findKeyValue(simple_attr_map_, attr_name); +} + +const LibertyComplexAttrSeq & +LibertyGroup::findComplexAttrs(const std::string attr_name) const +{ + return findKeyValue(complex_attr_map_, attr_name); +} + +const LibertyComplexAttr * +LibertyGroup::findComplexAttr(const std::string attr_name) const +{ + const LibertyComplexAttrSeq &attrs = findKeyValue(complex_attr_map_, attr_name); + if (attrs.size() >= 1) + return attrs[0]; + else + return nullptr; +} + +const std::string * +LibertyGroup::findAttrString(const std::string attr_name) const +{ + const LibertySimpleAttr *attr = findSimpleAttr(attr_name); + if (attr) + return &attr->value().stringValue(); + else + return nullptr; +} + +void +LibertyGroup::findAttrFloat(const std::string attr_name, + // Return values. + float &value, + bool &exists) const +{ + const LibertySimpleAttr *attr = findSimpleAttr(attr_name); + if (attr) { + const LibertyAttrValue &attr_value = attr->value(); + if (attr_value.isFloat()) { + value = attr_value.floatValue(); + exists = true; + return; + } + else { + // Possibly quoted string float. + const std::string &float_str = attr_value.stringValue(); + char *end = nullptr; + value = std::strtof(float_str.c_str(), &end); + if (end) { + exists = true; + return; + } + } + } + exists = false; +} + +void +LibertyGroup::findAttrInt(const std::string attr_name, + // Return values. + int &value, + bool &exists) const +{ + const LibertySimpleAttr *attr = findSimpleAttr(attr_name); + if (attr) { + const LibertyAttrValue &attr_value = attr->value(); + if (attr_value.isFloat()) { + value = static_cast(attr_value.floatValue()); + exists = true; + return; + } + } + exists = false; +} + +//////////////////////////////////////////////////////////////// + +LibertySimpleAttr::LibertySimpleAttr(const std::string name, + const LibertyAttrValue value, + int line) : + name_(std::move(name)), + line_(line), + value_(std::move(value)) +{ +} + +const std::string * +LibertySimpleAttr::stringValue() const +{ + return &value().stringValue(); +} + +//////////////////////////////////////////////////////////////// + +LibertyComplexAttr::LibertyComplexAttr(std::string name, + const LibertyAttrValueSeq values, + int line) : + name_(std::move(name)), + values_(std::move(values)), + line_(line) +{ +} + +LibertyComplexAttr::~LibertyComplexAttr() +{ + deleteContents(values_); +} + +const LibertyAttrValue * +LibertyComplexAttr::firstValue() const +{ + if (values_.size() > 0) + return values_[0]; + else + return nullptr; +} + +//////////////////////////////////////////////////////////////// + +LibertyAttrValue::LibertyAttrValue(std::string value) : + string_value_(std::move(value)) +{ +} + +LibertyAttrValue::LibertyAttrValue(float value) : + float_value_(value) +{ +} + +bool +LibertyAttrValue::isFloat() const +{ + return string_value_.empty(); +} + +bool +LibertyAttrValue::isString() const +{ + return !string_value_.empty(); +} + +float +LibertyAttrValue::floatValue() const +{ + if (!string_value_.empty()) + criticalError(1127, "LibertyAttrValue::floatValue() called on string"); + return float_value_; +} + +void +LibertyAttrValue::floatValue(// Return values. + float &value, + bool &valid) const +{ + valid = false; + if (string_value_.empty()) { + value = float_value_; + valid = true; + } + else { + // Some floats are enclosed in quotes. + char *end; + value = strtof(string_value_.c_str(), &end); + if ((*end == '\0' + || isspace(*end)) + // strtof support INF as a valid float. + && string_value_ != "inf") { + valid = true; + } + } +} + +//////////////////////////////////////////////////////////////// + +LibertyDefine::LibertyDefine(std::string name, + LibertyGroupType group_type, + LibertyAttrType value_type, + int line) : + name_(std::move(name)), + group_type_(group_type), + value_type_(value_type), + line_(line) +{ +} + +//////////////////////////////////////////////////////////////// + +LibertyVariable::LibertyVariable(std::string var, + float value, + int line) : + var_(std::move(var)), + value_(value), + line_(line) +{ +} + } // namespace diff --git a/liberty/LibertyParser.hh b/liberty/LibertyParser.hh index e27d859a..2f533c36 100644 --- a/liberty/LibertyParser.hh +++ b/liberty/LibertyParser.hh @@ -34,20 +34,22 @@ namespace sta { class Report; class LibertyGroupVisitor; -class LibertyStmt; class LibertyGroup; -class LibertyAttr; class LibertyDefine; +class LibertySimpleAttr; +class LibertyComplexAttr; class LibertyAttrValue; class LibertyVariable; class LibertyScanner; -using LibertyStmtSeq = std::vector; using LibertyGroupSeq = std::vector; -using LibertyAttrSeq = std::vector; -using LibertyAttrMap = std::map; +using LibertySubGroupMap = std::map; +using LibertySimpleAttrMap = std::map; +using LibertyComplexAttrSeq = std::vector; +using LibertyComplexAttrMap = std::map; using LibertyDefineMap = std::map; using LibertyAttrValueSeq = std::vector; +using LibertyVariableSeq = std::vector; using LibertyVariableMap = std::map; using LibertyGroupVisitorMap = std::map; @@ -65,27 +67,27 @@ public: const std::string &filename() const { return filename_; } void setFilename(const std::string &filename); Report *report() const { return report_; } - LibertyStmt *makeDefine(LibertyAttrValueSeq *values, - int line); - LibertyAttrType attrValueType(const char *value_type_name); - LibertyGroupType groupType(const char *group_type_name); - void groupBegin(std::string type, + LibertyDefine *makeDefine(const LibertyAttrValueSeq *values, + int line); + LibertyAttrType attrValueType(const std::string &value_type_name); + LibertyGroupType groupType(const std::string &group_type_name); + void groupBegin(const std::string type, LibertyAttrValueSeq *params, int line); LibertyGroup *groupEnd(); LibertyGroup *group(); void deleteGroups(); - LibertyStmt *makeSimpleAttr(std::string name, - LibertyAttrValue *value, - int line); - LibertyStmt *makeComplexAttr(std::string name, - LibertyAttrValueSeq *values, - int line); - LibertyAttrValue *makeStringAttrValue(std::string value); - LibertyAttrValue *makeFloatAttrValue(float value); - LibertyStmt *makeVariable(std::string var, - float value, - int line); + LibertySimpleAttr *makeSimpleAttr(const std::string name, + const LibertyAttrValue *value, + int line); + LibertyComplexAttr *makeComplexAttr(const std::string name, + const LibertyAttrValueSeq *values, + int line); + LibertyAttrValue *makeAttrValueString(const std::string value); + LibertyAttrValue *makeAttrValueFloat(float value); + LibertyVariable *makeVariable(const std::string var, + float value, + int line); private: std::string filename_; @@ -94,178 +96,171 @@ private: LibertyGroupSeq group_stack_; }; -// Abstract base class for liberty statements. -class LibertyStmt -{ -public: - LibertyStmt(int line); - virtual ~LibertyStmt() {} - int line() const { return line_; } - virtual bool isGroup() const { return false; } - virtual bool isAttribute() const { return false; } - virtual bool isSimpleAttr() const { return false; } - virtual bool isComplexAttr() const { return false; } - virtual bool isDefine() const { return false; } - virtual bool isVariable() const { return false; } - -protected: - int line_; -}; - -// Groups are a type keyword with a set of parameters and statements -// enclosed in brackets. -// type([param1][, param2]...) { stmts.. } -class LibertyGroup : public LibertyStmt -{ -public: - LibertyGroup(std::string type, - LibertyAttrValueSeq *params, - int line); - virtual ~LibertyGroup(); - virtual bool isGroup() const { return true; } - const std::string &type() const { return type_; } - LibertyAttrValueSeq *params() const { return params_; } - // First param as a string. - const char *firstName(); - // Second param as a string. - const char *secondName(); - void addStmt(LibertyStmt *stmt); - LibertyStmtSeq *stmts() const { return stmts_; } - -protected: - void parseNames(LibertyAttrValueSeq *values); - - std::string type_; - LibertyAttrValueSeq *params_; - LibertyStmtSeq *stmts_; -}; - -// Abstract base class for attributes. -class LibertyAttr : public LibertyStmt -{ -public: - LibertyAttr(std::string name, - int line); - const std::string &name() const { return name_; } - virtual LibertyAttrValueSeq *values() const = 0; - virtual LibertyAttrValue *firstValue() = 0; - -protected: - std::string name_; -}; - -// Abstract base class for simple attributes. -// name : value; -class LibertySimpleAttr : public LibertyAttr -{ -public: - LibertySimpleAttr(std::string name, - LibertyAttrValue *value, - int line); - virtual ~LibertySimpleAttr(); - bool isSimpleAttr() const override { return true; }; - LibertyAttrValue *firstValue() override { return value_; }; - LibertyAttrValueSeq *values() const override; - -private: - LibertyAttrValue *value_; -}; - -// Complex attributes have multiple values. -// name(attr_value1[, attr_value2]...); -class LibertyComplexAttr : public LibertyAttr -{ -public: - LibertyComplexAttr(std::string name, - LibertyAttrValueSeq *values, - int line); - virtual ~LibertyComplexAttr(); - bool isComplexAttr() const override { return true; }; - LibertyAttrValue *firstValue() override ; - LibertyAttrValueSeq *values() const override { return values_; } - -private: - LibertyAttrValueSeq *values_; -}; - // Attribute values are a string or float. class LibertyAttrValue { public: LibertyAttrValue() {} - virtual ~LibertyAttrValue() {} - virtual bool isString() const = 0; - virtual bool isFloat() const = 0; - virtual float floatValue() const = 0; - virtual const std::string &stringValue() const = 0; -}; - -class LibertyStringAttrValue : public LibertyAttrValue -{ -public: - LibertyStringAttrValue(std::string value); - virtual ~LibertyStringAttrValue() {} - bool isFloat() const override { return false; } - bool isString() const override { return true; } - float floatValue() const override ; - const std::string &stringValue() const override { return value_; } + LibertyAttrValue(float value); + LibertyAttrValue(std::string value); + bool isString() const; + bool isFloat() const; + float floatValue() const; + void floatValue(// Return values. + float &value, + bool &valid) const; + const std::string &stringValue() const { return string_value_; } private: - std::string value_; + float float_value_; + std::string string_value_; }; -class LibertyFloatAttrValue : public LibertyAttrValue +// Groups are a type keyword with a set of parameters and statements +// enclosed in brackets. +// type([param1][, param2]...) { stmts.. } +class LibertyGroup { public: - LibertyFloatAttrValue(float value); - virtual ~LibertyFloatAttrValue() {} - bool isString() const override { return false; } - bool isFloat() const override { return true; } - float floatValue() const override { return value_; } - const std::string &stringValue() const override; + LibertyGroup(const std::string type, + const LibertyAttrValueSeq params, + int line); + ~LibertyGroup(); + void clear(); + const std::string &type() const { return type_; } + const LibertyAttrValueSeq ¶ms() const { return params_; } + // First param as a string. + const char *firstName() const; + // Second param as a string. + const char *secondName() const; + int line() const { return line_; } + + const LibertyGroupSeq &findSubgroups(const std::string type) const; + const LibertyGroup *findSubgroup(const std::string type) const; + const LibertySimpleAttr *findSimpleAttr(const std::string attr_name) const; + const LibertyComplexAttrSeq &findComplexAttrs(const std::string attr_name) const; + const LibertyComplexAttr *findComplexAttr(const std::string attr_name) const; + const std::string *findAttrString(const std::string attr_name) const; + void findAttrFloat(const std::string attr_name, + // Return values. + float &value, + bool &exists) const; + void findAttrInt(const std::string attr_name, + // Return values. + int &value, + bool &exists) const; + + const LibertyGroupSeq &subgroups() const { return subgroups_; } + const LibertyDefineMap &defineMap() const { return define_map_; } + + void addSubgroup(LibertyGroup *subgroup); + void deleteSubgroup(const LibertyGroup *subgroup); + void addAttr(LibertySimpleAttr *attr); + void addAttr(LibertyComplexAttr *attr); + void addDefine(LibertyDefine *define); + void addVariable(LibertyVariable *var); + +protected: + std::string type_; + LibertyAttrValueSeq params_; + int line_; + + LibertySimpleAttrMap simple_attr_map_; + LibertyComplexAttrMap complex_attr_map_; + LibertyGroupSeq subgroups_; + LibertySubGroupMap subgroup_map_; + LibertyDefineMap define_map_; + LibertyVariableSeq variables_; +}; + +class LibertyGroupLineLess +{ +public: + bool + operator()(const LibertyGroup *group1, + const LibertyGroup *group2) const { + return group1->line() < group2->line(); + } +}; + +// Simple attributes: name : value; +class LibertySimpleAttr +{ +public: + LibertySimpleAttr(const std::string name, + const LibertyAttrValue value, + int line); + const std::string &name() const { return name_; } + const LibertyAttrValue &value() const { return value_; }; + const std::string *stringValue() const; + int line() const { return line_; } private: - float value_; + std::string name_; + int line_; + LibertyAttrValue value_; +}; + +// Complex attributes have multiple values. +// name(attr_value1[, attr_value2]...); +class LibertyComplexAttr +{ +public: + LibertyComplexAttr(const std::string name, + const LibertyAttrValueSeq values, + int line); + ~LibertyComplexAttr(); + const std::string &name() const { return name_; } + const LibertyAttrValue *firstValue() const; + const LibertyAttrValueSeq &values() const { return values_; } + int line() const { return line_; } + +private: + std::string name_; + LibertyAttrValueSeq values_; + int line_; }; // Define statements define new simple attributes. // define(attribute_name, group_name, attribute_type); // attribute_type is string|integer|float. -class LibertyDefine : public LibertyStmt +class LibertyDefine { public: LibertyDefine(std::string name, LibertyGroupType group_type, LibertyAttrType value_type, int line); - virtual bool isDefine() const { return true; } const std::string &name() const { return name_; } LibertyGroupType groupType() const { return group_type_; } LibertyAttrType valueType() const { return value_type_; } + int line() const { return line_; } private: std::string name_; LibertyGroupType group_type_; LibertyAttrType value_type_; + int line_; }; // The Liberty User Guide Version 2003.12 fails to document variables. // var = value; // The only example I have only uses float values, so I am assuming // that is all that is supported (which is probably wrong). -class LibertyVariable : public LibertyStmt +class LibertyVariable { public: LibertyVariable(std::string var, float value, int line); - bool isVariable() const override { return true; } + int line() const { return line_; } const std::string &variable() const { return var_; } float value() const { return value_; } private: std::string var_; float value_; + int line_; }; class LibertyGroupVisitor @@ -273,14 +268,13 @@ class LibertyGroupVisitor public: LibertyGroupVisitor() {} virtual ~LibertyGroupVisitor() {} - virtual void begin(LibertyGroup *group) = 0; - virtual void end(LibertyGroup *group) = 0; - virtual void visitAttr(LibertyAttr *attr) = 0; + virtual void begin(const LibertyGroup *group, + LibertyGroup *parent_group) = 0; + virtual void end(const LibertyGroup *group, + LibertyGroup *parent_group) = 0; + virtual void visitAttr(const LibertySimpleAttr *attr) = 0; + virtual void visitAttr(const LibertyComplexAttr *attr) = 0; virtual void visitVariable(LibertyVariable *variable) = 0; - // Predicates to save parse structure after visits. - virtual bool save(LibertyGroup *group) = 0; - virtual bool save(LibertyAttr *attr) = 0; - virtual bool save(LibertyVariable *variable) = 0; }; void diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index edcde894..974ab7ec 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include "ContainerHelpers.hh" @@ -55,9 +56,6 @@ extern int LibertyParse_debug; namespace sta { -using std::make_shared; -using std::string; - static void scaleFloats(FloatSeq &floats, float scale); @@ -74,76 +72,19 @@ readLibertyFile(const char *filename, LibertyReader::LibertyReader(const char *filename, bool infer_latches, Network *network) : - LibertyGroupVisitor() + LibertyGroupVisitor(), + filename_(filename), + infer_latches_(infer_latches), + report_(network->report()), + debug_(network->debug()), + network_(network), + builder_(debug_, report_), + library_(nullptr), + first_cell_(true) { - init(filename, infer_latches, network); defineVisitors(); } -void -LibertyReader::init(const char *filename, - bool infer_latches, - Network *network) -{ - filename_ = filename; - infer_latches_ = infer_latches; - report_ = network->report(); - debug_ = network->debug(); - network_ = network; - var_map_ = nullptr; - library_ = nullptr; - wireload_ = nullptr; - wireload_selection_ = nullptr; - default_wireload_ = nullptr; - default_wireload_selection_ = nullptr; - scale_factors_ = nullptr; - save_scale_factors_ = nullptr; - tbl_template_ = nullptr; - cell_ = nullptr; - save_cell_ = nullptr; - scaled_cell_owner_ = nullptr; - test_cell_ = nullptr; - ocv_derate_name_ = nullptr; - op_cond_ = nullptr; - ports_ = nullptr; - port_group_ = nullptr; - saved_ports_ = nullptr; - saved_port_group_ = nullptr; - in_bus_ = false; - in_bundle_ = false; - in_ccsn_ = false; - in_ecsm_waveform_ = false; - sequential_ = nullptr; - statetable_ = nullptr; - timing_ = nullptr; - internal_power_ = nullptr; - leakage_power_ = nullptr; - table_ = nullptr; - rf_ = nullptr; - index_ = 0; - table_model_scale_ = 1.0; - mode_def_ = nullptr; - mode_value_ = nullptr; - ocv_derate_ = nullptr; - pg_port_ = nullptr; - default_operating_condition_ = nullptr; - receiver_model_ = nullptr; - - builder_.init(debug_, report_); - - for (auto rf_index : RiseFall::rangeIndex()) { - have_input_threshold_[rf_index] = false; - have_output_threshold_[rf_index] = false; - have_slew_lower_threshold_[rf_index] = false; - have_slew_upper_threshold_[rf_index] = false; - } -} - -LibertyReader::~LibertyReader() -{ - delete var_map_; -} - LibertyLibrary * LibertyReader::readLibertyFile(const char *filename) { @@ -157,498 +98,179 @@ LibertyReader::defineGroupVisitor(const char *type, LibraryGroupVisitor begin_visitor, LibraryGroupVisitor end_visitor) { - group_begin_map_[type] = begin_visitor; - group_end_map_[type] = end_visitor; -} - -void -LibertyReader::defineAttrVisitor(const char *attr_name, - LibraryAttrVisitor visitor) -{ - attr_visitor_map_[attr_name] = visitor; + if (begin_visitor) + group_begin_map_[type] = begin_visitor; + if (end_visitor) + group_end_map_[type] = end_visitor; } void LibertyReader::defineVisitors() { - // Library defineGroupVisitor("library", &LibertyReader::beginLibrary, &LibertyReader::endLibrary); - defineAttrVisitor("time_unit", &LibertyReader::visitTimeUnit); - defineAttrVisitor("pulling_resistance_unit", - &LibertyReader::visitPullingResistanceUnit); - defineAttrVisitor("resistance_unit", &LibertyReader::visitResistanceUnit); - defineAttrVisitor("capacitive_load_unit", - &LibertyReader::visitCapacitiveLoadUnit); - defineAttrVisitor("voltage_unit", &LibertyReader::visitVoltageUnit); - defineAttrVisitor("current_unit", &LibertyReader::visitCurrentUnit); - defineAttrVisitor("leakage_power_unit", &LibertyReader::visitPowerUnit); - defineAttrVisitor("distance_unit", &LibertyReader::visitDistanceUnit); - defineAttrVisitor("delay_model", &LibertyReader::visitDelayModel); - defineAttrVisitor("bus_naming_style", &LibertyReader::visitBusStyle); - defineAttrVisitor("voltage_map", &LibertyReader::visitVoltageMap); - defineAttrVisitor("nom_temperature", &LibertyReader::visitNomTemp); - defineAttrVisitor("nom_voltage", &LibertyReader::visitNomVolt); - defineAttrVisitor("nom_process", &LibertyReader::visitNomProc); - defineAttrVisitor("default_inout_pin_cap", - &LibertyReader::visitDefaultInoutPinCap); - defineAttrVisitor("default_input_pin_cap", - &LibertyReader::visitDefaultInputPinCap); - defineAttrVisitor("default_output_pin_cap", - &LibertyReader::visitDefaultOutputPinCap); - defineAttrVisitor("default_max_transition", - &LibertyReader::visitDefaultMaxTransition); - defineAttrVisitor("default_max_fanout", - &LibertyReader::visitDefaultMaxFanout); - defineAttrVisitor("default_intrinsic_rise", - &LibertyReader::visitDefaultIntrinsicRise); - defineAttrVisitor("default_intrinsic_fall", - &LibertyReader::visitDefaultIntrinsicFall); - defineAttrVisitor("default_inout_pin_rise_res", - &LibertyReader::visitDefaultInoutPinRiseRes); - defineAttrVisitor("default_inout_pin_fall_res", - &LibertyReader::visitDefaultInoutPinFallRes); - defineAttrVisitor("default_output_pin_rise_res", - &LibertyReader::visitDefaultOutputPinRiseRes); - defineAttrVisitor("default_output_pin_fall_res", - &LibertyReader::visitDefaultOutputPinFallRes); - defineAttrVisitor("default_fanout_load", - &LibertyReader::visitDefaultFanoutLoad); - defineAttrVisitor("default_wire_load", - &LibertyReader::visitDefaultWireLoad); - defineAttrVisitor("default_wire_load_mode", - &LibertyReader::visitDefaultWireLoadMode); - defineAttrVisitor("default_wire_load_selection", - &LibertyReader::visitDefaultWireLoadSelection); - defineAttrVisitor("default_operating_conditions", - &LibertyReader::visitDefaultOperatingConditions); - defineAttrVisitor("input_threshold_pct_fall", - &LibertyReader::visitInputThresholdPctFall); - defineAttrVisitor("input_threshold_pct_rise", - &LibertyReader::visitInputThresholdPctRise); - defineAttrVisitor("output_threshold_pct_fall", - &LibertyReader::visitOutputThresholdPctFall); - defineAttrVisitor("output_threshold_pct_rise", - &LibertyReader::visitOutputThresholdPctRise); - defineAttrVisitor("slew_lower_threshold_pct_fall", - &LibertyReader::visitSlewLowerThresholdPctFall); - defineAttrVisitor("slew_lower_threshold_pct_rise", - &LibertyReader::visitSlewLowerThresholdPctRise); - defineAttrVisitor("slew_upper_threshold_pct_fall", - &LibertyReader::visitSlewUpperThresholdPctFall); - defineAttrVisitor("slew_upper_threshold_pct_rise", - &LibertyReader::visitSlewUpperThresholdPctRise); - defineAttrVisitor("slew_derate_from_library", - &LibertyReader::visitSlewDerateFromLibrary); - - defineGroupVisitor("lu_table_template", - &LibertyReader::beginTableTemplateDelay, - &LibertyReader::endTableTemplate); - defineGroupVisitor("output_current_template", - &LibertyReader::beginTableTemplateOutputCurrent, - &LibertyReader::endTableTemplate); - defineAttrVisitor("variable_1", &LibertyReader::visitVariable1); - defineAttrVisitor("variable_2", &LibertyReader::visitVariable2); - defineAttrVisitor("variable_3", &LibertyReader::visitVariable3); - defineAttrVisitor("index_1", &LibertyReader::visitIndex1); - defineAttrVisitor("index_2", &LibertyReader::visitIndex2); - defineAttrVisitor("index_3", &LibertyReader::visitIndex3); - - defineGroupVisitor("technology", - &LibertyReader::beginTechnology, - &LibertyReader::endTechnology); - defineGroupVisitor("rise_transition_degradation", - &LibertyReader::beginRiseTransitionDegredation, - &LibertyReader::endRiseFallTransitionDegredation); - defineGroupVisitor("fall_transition_degradation", - &LibertyReader::beginFallTransitionDegredation, - &LibertyReader::endRiseFallTransitionDegredation); - - defineGroupVisitor("type", &LibertyReader::beginType, - &LibertyReader::endType); - defineAttrVisitor("bit_from", &LibertyReader::visitBitFrom); - defineAttrVisitor("bit_to", &LibertyReader::visitBitTo); - - defineGroupVisitor("scaling_factors", &LibertyReader::beginScalingFactors, - &LibertyReader::endScalingFactors); - defineScalingFactorVisitors(); - - defineGroupVisitor("operating_conditions", &LibertyReader::beginOpCond, - &LibertyReader::endOpCond); - defineAttrVisitor("process", &LibertyReader::visitProc); - defineAttrVisitor("voltage", &LibertyReader::visitVolt); - defineAttrVisitor("temperature", &LibertyReader::visitTemp); - defineAttrVisitor("tree_type", &LibertyReader::visitTreeType); - - defineGroupVisitor("wire_load", &LibertyReader::beginWireload, - &LibertyReader::endWireload); - defineAttrVisitor("resistance", &LibertyReader::visitResistance); - defineAttrVisitor("slope", &LibertyReader::visitSlope); - defineAttrVisitor("fanout_length", &LibertyReader::visitFanoutLength); - - defineGroupVisitor("wire_load_selection", - &LibertyReader::beginWireloadSelection, - &LibertyReader::endWireloadSelection); - defineAttrVisitor("wire_load_from_area", - &LibertyReader::visitWireloadFromArea); - - // Cells - defineGroupVisitor("cell", &LibertyReader::beginCell, - &LibertyReader::endCell); - defineGroupVisitor("scaled_cell", &LibertyReader::beginScaledCell, - &LibertyReader::endScaledCell); - defineAttrVisitor("clock_gating_integrated_cell", - &LibertyReader::visitClockGatingIntegratedCell); - defineAttrVisitor("area", &LibertyReader::visitArea); - defineAttrVisitor("dont_use", &LibertyReader::visitDontUse); - defineAttrVisitor("is_macro_cell", &LibertyReader::visitIsMacro); - defineAttrVisitor("is_memory", &LibertyReader::visitIsMemory); - defineAttrVisitor("pad_cell", &LibertyReader::visitIsPadCell); - defineAttrVisitor("is_pad", &LibertyReader::visitIsPad); - defineAttrVisitor("is_clock_cell", &LibertyReader::visitIsClockCell); - defineAttrVisitor("is_level_shifter", &LibertyReader::visitIsLevelShifter); - defineAttrVisitor("level_shifter_type", &LibertyReader::visitLevelShifterType); - defineAttrVisitor("is_isolation_cell", &LibertyReader::visitIsIsolationCell); - defineAttrVisitor("always_on", &LibertyReader::visitAlwaysOn); - defineAttrVisitor("switch_cell_type", &LibertyReader::visitSwitchCellType); - defineAttrVisitor("interface_timing", &LibertyReader::visitInterfaceTiming); - defineAttrVisitor("scaling_factors", &LibertyReader::visitScalingFactors); - defineAttrVisitor("cell_footprint", &LibertyReader::visitCellFootprint); - defineAttrVisitor("user_function_class", - &LibertyReader::visitCellUserFunctionClass); - - // Pins - defineGroupVisitor("pin", &LibertyReader::beginPin,&LibertyReader::endPin); - defineGroupVisitor("bus", &LibertyReader::beginBus,&LibertyReader::endBus); - defineGroupVisitor("bundle", &LibertyReader::beginBundle, - &LibertyReader::endBundle); - defineAttrVisitor("direction", &LibertyReader::visitDirection); - defineAttrVisitor("clock", &LibertyReader::visitClock); - defineAttrVisitor("bus_type", &LibertyReader::visitBusType); - defineAttrVisitor("members", &LibertyReader::visitMembers); - defineAttrVisitor("function", &LibertyReader::visitFunction); - defineAttrVisitor("three_state", &LibertyReader::visitThreeState); - defineAttrVisitor("capacitance", &LibertyReader::visitCapacitance); - defineAttrVisitor("rise_capacitance", &LibertyReader::visitRiseCap); - defineAttrVisitor("fall_capacitance", &LibertyReader::visitFallCap); - defineAttrVisitor("rise_capacitance_range", - &LibertyReader::visitRiseCapRange); - defineAttrVisitor("fall_capacitance_range", - &LibertyReader::visitFallCapRange); - defineAttrVisitor("fanout_load", &LibertyReader::visitFanoutLoad); - defineAttrVisitor("max_fanout", &LibertyReader::visitMaxFanout); - defineAttrVisitor("min_fanout", &LibertyReader::visitMinFanout); - defineAttrVisitor("max_transition", &LibertyReader::visitMaxTransition); - defineAttrVisitor("min_transition", &LibertyReader::visitMinTransition); - defineAttrVisitor("max_capacitance", &LibertyReader::visitMaxCapacitance); - defineAttrVisitor("min_capacitance", &LibertyReader::visitMinCapacitance); - defineAttrVisitor("min_period", &LibertyReader::visitMinPeriod); - defineAttrVisitor("min_pulse_width_low", - &LibertyReader::visitMinPulseWidthLow); - defineAttrVisitor("min_pulse_width_high", - &LibertyReader::visitMinPulseWidthHigh); - defineAttrVisitor("pulse_clock", - &LibertyReader::visitPulseClock); - defineAttrVisitor("clock_gate_clock_pin", - &LibertyReader::visitClockGateClockPin); - defineAttrVisitor("clock_gate_enable_pin", - &LibertyReader::visitClockGateEnablePin); - defineAttrVisitor("clock_gate_out_pin", - &LibertyReader::visitClockGateOutPin); - defineAttrVisitor("is_pll_feedback_pin", - &LibertyReader::visitIsPllFeedbackPin); - defineAttrVisitor("signal_type", &LibertyReader::visitSignalType); - - defineAttrVisitor("isolation_cell_data_pin", - &LibertyReader::visitIsolationCellDataPin); - defineAttrVisitor("isolation_cell_enable_pin", - &LibertyReader::visitIsolationCellEnablePin); - defineAttrVisitor("level_shifter_data_pin", - &LibertyReader::visitLevelShifterDataPin); - defineAttrVisitor("switch_pin", &LibertyReader::visitSwitchPin); - - // Memory - defineGroupVisitor("memory", &LibertyReader::beginMemory, - &LibertyReader::endMemory); - - // Register/latch - defineGroupVisitor("ff", &LibertyReader::beginFF, &LibertyReader::endFF); - defineGroupVisitor("ff_bank", &LibertyReader::beginFFBank, - &LibertyReader::endFFBank); - defineGroupVisitor("latch", &LibertyReader::beginLatch, - &LibertyReader::endLatch); - defineGroupVisitor("latch_bank", &LibertyReader::beginLatchBank, - &LibertyReader::endLatchBank); - defineAttrVisitor("clocked_on", &LibertyReader::visitClockedOn); - defineAttrVisitor("enable", &LibertyReader::visitClockedOn); - defineAttrVisitor("data_in", &LibertyReader::visitDataIn); - defineAttrVisitor("next_state", &LibertyReader::visitDataIn); - defineAttrVisitor("clear", &LibertyReader::visitClear); - defineAttrVisitor("preset", &LibertyReader::visitPreset); - defineAttrVisitor("clear_preset_var1", &LibertyReader::visitClrPresetVar1); - defineAttrVisitor("clear_preset_var2", &LibertyReader::visitClrPresetVar2); - - // Statetable - defineGroupVisitor("statetable", &LibertyReader::beginStatetable, - &LibertyReader::endStatetable); - defineAttrVisitor("table", &LibertyReader::visitTable); - - defineGroupVisitor("timing", &LibertyReader::beginTiming, - &LibertyReader::endTiming); - defineAttrVisitor("related_pin", &LibertyReader::visitRelatedPin); - defineAttrVisitor("related_bus_pins", &LibertyReader::visitRelatedBusPins); - defineAttrVisitor("related_output_pin", - &LibertyReader::visitRelatedOutputPin); - defineAttrVisitor("timing_type", &LibertyReader::visitTimingType); - defineAttrVisitor("timing_sense", &LibertyReader::visitTimingSense); - defineAttrVisitor("sdf_cond_start", &LibertyReader::visitSdfCondStart); - defineAttrVisitor("sdf_cond_end", &LibertyReader::visitSdfCondEnd); - defineAttrVisitor("mode", &LibertyReader::visitMode); - defineAttrVisitor("intrinsic_rise", &LibertyReader::visitIntrinsicRise); - defineAttrVisitor("intrinsic_fall", &LibertyReader::visitIntrinsicFall); - defineAttrVisitor("rise_resistance", &LibertyReader::visitRiseResistance); - defineAttrVisitor("fall_resistance", &LibertyReader::visitFallResistance); - defineGroupVisitor("cell_rise", &LibertyReader::beginCellRise, - &LibertyReader::endCellRiseFall); - defineGroupVisitor("cell_fall", &LibertyReader::beginCellFall, - &LibertyReader::endCellRiseFall); - defineGroupVisitor("rise_transition", &LibertyReader::beginRiseTransition, - &LibertyReader::endRiseFallTransition); - defineGroupVisitor("fall_transition", &LibertyReader::beginFallTransition, - &LibertyReader::endRiseFallTransition); - defineGroupVisitor("rise_constraint", &LibertyReader::beginRiseConstraint, - &LibertyReader::endRiseFallConstraint); - defineGroupVisitor("fall_constraint", &LibertyReader::beginFallConstraint, - &LibertyReader::endRiseFallConstraint); - defineAttrVisitor("value", &LibertyReader::visitValue); - defineAttrVisitor("values", &LibertyReader::visitValues); - - defineGroupVisitor("lut", &LibertyReader::beginLut,&LibertyReader::endLut); - - defineGroupVisitor("test_cell", &LibertyReader::beginTestCell, - &LibertyReader::endTestCell); - - defineGroupVisitor("mode_definition", &LibertyReader::beginModeDef, - &LibertyReader::endModeDef); - defineGroupVisitor("mode_value", &LibertyReader::beginModeValue, - &LibertyReader::endModeValue); - defineAttrVisitor("when", &LibertyReader::visitWhen); - defineAttrVisitor("sdf_cond", &LibertyReader::visitSdfCond); - - // Power attributes. - defineGroupVisitor("power_lut_template", - &LibertyReader::beginTableTemplatePower, - &LibertyReader::endTableTemplate); - defineGroupVisitor("leakage_power", &LibertyReader::beginLeakagePower, - &LibertyReader::endLeakagePower); - defineGroupVisitor("internal_power", &LibertyReader::beginInternalPower, - &LibertyReader::endInternalPower); - // power group for both rise/fall - defineGroupVisitor("power", &LibertyReader::beginRisePower, - &LibertyReader::endPower); - defineGroupVisitor("fall_power", &LibertyReader::beginFallPower, - &LibertyReader::endRiseFallPower); - defineGroupVisitor("rise_power", &LibertyReader::beginRisePower, - &LibertyReader::endRiseFallPower); - defineAttrVisitor("related_ground_pin",&LibertyReader::visitRelatedGroundPin); - defineAttrVisitor("related_power_pin", &LibertyReader::visitRelatedPowerPin); - defineAttrVisitor("related_pg_pin", &LibertyReader::visitRelatedPgPin); - - // AOCV attributes. - defineAttrVisitor("ocv_arc_depth", &LibertyReader::visitOcvArcDepth); - defineAttrVisitor("default_ocv_derate_group", - &LibertyReader::visitDefaultOcvDerateGroup); - defineAttrVisitor("ocv_derate_group", &LibertyReader::visitOcvDerateGroup); - defineGroupVisitor("ocv_table_template", - &LibertyReader::beginTableTemplateOcv, - &LibertyReader::endTableTemplate); - defineGroupVisitor("ocv_derate", - &LibertyReader::beginOcvDerate, - &LibertyReader::endOcvDerate); - defineGroupVisitor("ocv_derate_factors", - &LibertyReader::beginOcvDerateFactors, - &LibertyReader::endOcvDerateFactors); - defineAttrVisitor("rf_type", &LibertyReader::visitRfType); - defineAttrVisitor("derate_type", &LibertyReader::visitDerateType); - defineAttrVisitor("path_type", &LibertyReader::visitPathType); - - // POCV attributes. - defineGroupVisitor("ocv_sigma_cell_rise", &LibertyReader::beginOcvSigmaCellRise, - &LibertyReader::endOcvSigmaCell); - defineGroupVisitor("ocv_sigma_cell_fall", &LibertyReader::beginOcvSigmaCellFall, - &LibertyReader::endOcvSigmaCell); - defineGroupVisitor("ocv_sigma_rise_transition", - &LibertyReader::beginOcvSigmaRiseTransition, - &LibertyReader::endOcvSigmaTransition); - defineGroupVisitor("ocv_sigma_fall_transition", - &LibertyReader::beginOcvSigmaFallTransition, - &LibertyReader::endOcvSigmaTransition); - defineGroupVisitor("ocv_sigma_rise_constraint", - &LibertyReader::beginOcvSigmaRiseConstraint, - &LibertyReader::endOcvSigmaConstraint); - defineGroupVisitor("ocv_sigma_fall_constraint", - &LibertyReader::beginOcvSigmaFallConstraint, - &LibertyReader::endOcvSigmaConstraint); - defineAttrVisitor("sigma_type", &LibertyReader::visitSigmaType); - defineAttrVisitor("cell_leakage_power", &LibertyReader::visitCellLeakagePower); - - defineGroupVisitor("pg_pin", &LibertyReader::beginPgPin, - &LibertyReader::endPgPin); - defineAttrVisitor("pg_type", &LibertyReader::visitPgType); - defineAttrVisitor("voltage_name", &LibertyReader::visitVoltageName); - - // ccs receiver capacitance - defineGroupVisitor("receiver_capacitance", - &LibertyReader::beginReceiverCapacitance, - &LibertyReader::endReceiverCapacitance); - - defineGroupVisitor("receiver_capacitance_rise", - &LibertyReader::beginReceiverCapacitance1Rise, - &LibertyReader::endReceiverCapacitanceRiseFall); - defineGroupVisitor("receiver_capacitance_fall", - &LibertyReader::beginReceiverCapacitance1Fall, - &LibertyReader::endReceiverCapacitanceRiseFall); - defineAttrVisitor("segment", &LibertyReader::visitSegement); - - defineGroupVisitor("receiver_capacitance1_rise", - &LibertyReader::beginReceiverCapacitance1Rise, - &LibertyReader::endReceiverCapacitanceRiseFall); - defineGroupVisitor("receiver_capacitance1_fall", - &LibertyReader::beginReceiverCapacitance1Fall, - &LibertyReader::endReceiverCapacitanceRiseFall); - defineGroupVisitor("receiver_capacitance2_rise", - &LibertyReader::beginReceiverCapacitance2Rise, - &LibertyReader::endReceiverCapacitanceRiseFall); - defineGroupVisitor("receiver_capacitance2_fall", - &LibertyReader::beginReceiverCapacitance2Fall, - &LibertyReader::endReceiverCapacitanceRiseFall); - // ccs - defineGroupVisitor("output_current_rise", - &LibertyReader::beginOutputCurrentRise, - &LibertyReader::endOutputCurrentRiseFall); - defineGroupVisitor("output_current_fall", - &LibertyReader::beginOutputCurrentFall, - &LibertyReader::endOutputCurrentRiseFall); - defineGroupVisitor("vector", &LibertyReader::beginVector, &LibertyReader::endVector); - defineAttrVisitor("reference_time", &LibertyReader::visitReferenceTime); - defineGroupVisitor("normalized_driver_waveform", - &LibertyReader::beginNormalizedDriverWaveform, - &LibertyReader::endNormalizedDriverWaveform); - defineAttrVisitor("driver_waveform_name", &LibertyReader::visitDriverWaveformName); - defineAttrVisitor("driver_waveform_rise", &LibertyReader::visitDriverWaveformRise); - defineAttrVisitor("driver_waveform_fall", &LibertyReader::visitDriverWaveformFall); - - // ccsn (not implemented, this is needed to properly ignore ccsn groups) - defineGroupVisitor("ccsn_first_stage", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("ccsn_last_stage", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("output_voltage_rise", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("output_voltage_fall", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("propagated_noise_low", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("propagated_noise_high", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("input_ccb", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - defineGroupVisitor("output_ccb", &LibertyReader::beginCcsn, - &LibertyReader::endCcsn); - - defineGroupVisitor("ecsm_waveform", &LibertyReader::beginEcsmWaveform, - &LibertyReader::endEcsmWaveform); - defineGroupVisitor("ecsm_waveform_set", &LibertyReader::beginEcsmWaveform, - &LibertyReader::endEcsmWaveform); - defineGroupVisitor("ecsm_capacitance", &LibertyReader::beginEcsmWaveform, - &LibertyReader::endEcsmWaveform); + defineGroupVisitor("cell", nullptr, &LibertyReader::endCell); + defineGroupVisitor("scaled_cell", nullptr, &LibertyReader::endScaledCell); } void -LibertyReader::defineScalingFactorVisitors() +LibertyReader::visitAttr(const LibertySimpleAttr *) { - for (int type_index = 0; type_index < scale_factor_type_count; type_index++) { - ScaleFactorType type = static_cast(type_index); - const char *type_name = scaleFactorTypeName(type); - for (int pvt_index = 0; pvt_index < scale_factor_pvt_count; pvt_index++) { - ScaleFactorPvt pvt = static_cast(pvt_index); - const char *pvt_name = scaleFactorPvtName(pvt); - if (scaleFactorTypeRiseFallSuffix(type)) { - for (auto tr : RiseFall::range()) { - const char *tr_name = (tr == RiseFall::rise()) ? "rise":"fall"; - string attr_name; - stringPrint(attr_name, "k_%s_%s_%s", - pvt_name, - type_name, - tr_name); - defineAttrVisitor(attr_name.c_str() ,&LibertyReader::visitScaleFactorSuffix); - } - } - else if (scaleFactorTypeRiseFallPrefix(type)) { - for (auto tr : RiseFall::range()) { - const char *tr_name = (tr == RiseFall::rise()) ? "rise":"fall"; - string attr_name; - stringPrint(attr_name, "k_%s_%s_%s", - pvt_name, - tr_name, - type_name); - defineAttrVisitor(attr_name.c_str(),&LibertyReader::visitScaleFactorPrefix); - } - } - else if (scaleFactorTypeLowHighSuffix(type)) { - for (auto tr : RiseFall::range()) { - const char *tr_name = (tr == RiseFall::rise()) ? "high":"low"; - string attr_name; - stringPrint(attr_name, "k_%s_%s_%s", - pvt_name, - type_name, - tr_name); - defineAttrVisitor(attr_name.c_str(),&LibertyReader::visitScaleFactorHiLow); - } - } - else { - string attr_name; - stringPrint(attr_name, "k_%s_%s", - pvt_name, - type_name); - defineAttrVisitor(attr_name.c_str(),&LibertyReader::visitScaleFactor); - } - } - } } void -LibertyReader::visitAttr(LibertyAttr *attr) +LibertyReader::visitAttr(const LibertyComplexAttr *) { - LibraryAttrVisitor *visitor = findKeyValuePtr(attr_visitor_map_, attr->name()); - if (visitor) - (this->**visitor)(attr); } void -LibertyReader::begin(LibertyGroup *group) +LibertyReader::begin(const LibertyGroup *group, + LibertyGroup *parent_group) { LibraryGroupVisitor *visitor = findKeyValuePtr(group_begin_map_, group->type()); if (visitor) - (this->**visitor)(group); + (this->**visitor)(group, parent_group); } void -LibertyReader::end(LibertyGroup *group) +LibertyReader::end(const LibertyGroup *group, + LibertyGroup *parent_group) { LibraryGroupVisitor *visitor = findKeyValuePtr(group_end_map_, group->type()); if (visitor) - (this->**visitor)(group); + (this->**visitor)(group, parent_group); } void -LibertyReader::beginLibrary(LibertyGroup *group) +LibertyReader::beginLibrary(const LibertyGroup *library_group, + LibertyGroup *) { - const char *name = group->firstName(); + makeLibrary(library_group); +} + +void +LibertyReader::endLibrary(const LibertyGroup *group, + LibertyGroup *) +{ + // If a library hasno cells endCell is not called. + if (first_cell_) + readLibraryAttributes(group); + delete group; +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::endCell(const LibertyGroup *cell_group, + LibertyGroup *library_group) +{ + // Read library groups defined since the last cell was read. + // Normally they are all defined by the first cell, but there + // are libraries that define table templates and bus tyupes + // between cells. + if (first_cell_) + readLibraryAttributes(library_group); + else { + readTableTemplates(library_group); + readBusTypes(nullptr, library_group); + } + + const char *name = cell_group->firstName(); + if (name) { + debugPrint(debug_, "liberty", 1, "cell %s", name); + LibertyCell *cell = builder_.makeCell(library_, name, filename_); + readCell(cell, cell_group); + } + else + libWarn(1193, cell_group, "cell missing name."); + library_group->clear(); + first_cell_ = false; +} + +void +LibertyReader::endScaledCell(const LibertyGroup *scaled_cell_group, + LibertyGroup *library_group) +{ + readLibraryAttributes(library_group); + readScaledCell(scaled_cell_group); + library_group->deleteSubgroup(scaled_cell_group); +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::readLibraryAttributes(const LibertyGroup *library_group) +{ + readTechnology(library_group); + readLibraryUnits(library_group); + readThresholds(library_group); + readDelayModel(library_group); + readBusStyle(library_group); + readBusTypes(nullptr, library_group); + readTableTemplates(library_group); + readVoltateMaps(library_group); + readWireloads(library_group); + readWireloadSelection(library_group); + readDefaultWireLoad(library_group); + readDefaultWireLoadMode(library_group); + readDefaultWireLoadSelection(library_group); + readOperatingConds(library_group); + readScaleFactors(library_group); + readOcvDerateFactors(nullptr, library_group); + readDefaultOcvDerateGroup(library_group); + readGroupAttrFloat("ocv_arc_depth", library_group, + [this](float v) { library_->setOcvArcDepth(v); }); + readNormalizedDriverWaveform(library_group); + readSlewDegradations(library_group); + + readLibAttrFloat(library_group, "nom_temperature", + &LibertyLibrary::setNominalTemperature, 1.0F); + readLibAttrFloat(library_group, "nom_voltage", &LibertyLibrary::setNominalVoltage, + volt_scale_); + readLibAttrFloat(library_group, "nom_process", + &LibertyLibrary::setNominalProcess, 1.0F); + readLibAttrFloat(library_group, "default_inout_pin_cap", + &LibertyLibrary::setDefaultBidirectPinCap, cap_scale_); + readLibAttrFloat(library_group, "default_input_pin_cap", + &LibertyLibrary::setDefaultInputPinCap, cap_scale_); + readLibAttrFloat(library_group, "default_output_pin_cap", + &LibertyLibrary::setDefaultOutputPinCap, cap_scale_); + readLibAttrFloatWarnZero(library_group, "default_max_transition", + &LibertyLibrary::setDefaultMaxSlew, time_scale_); + readLibAttrFloatWarnZero(library_group, "default_max_fanout", + &LibertyLibrary::setDefaultMaxFanout, 1.0F); + readLibAttrFloat(library_group, "default_intrinsic_rise", + &LibertyLibrary::setDefaultIntrinsic, RiseFall::rise(), + time_scale_); + readLibAttrFloat(library_group, "default_intrinsic_fall", + &LibertyLibrary::setDefaultIntrinsic, RiseFall::fall(), + time_scale_); + readLibAttrFloat(library_group, "default_inout_pin_rise_res", + &LibertyLibrary::setDefaultBidirectPinRes, RiseFall::rise(), + res_scale_); + readLibAttrFloat(library_group, "default_inout_pin_fall_res", + &LibertyLibrary::setDefaultBidirectPinRes, RiseFall::fall(), + res_scale_); + readLibAttrFloat(library_group, "default_output_pin_rise_res", + &LibertyLibrary::setDefaultOutputPinRes, RiseFall::rise(), + res_scale_); + readLibAttrFloat(library_group, "default_output_pin_fall_res", + &LibertyLibrary::setDefaultOutputPinRes, RiseFall::fall(), + res_scale_); + readLibAttrFloatWarnZero(library_group, "default_fanout_load", + &LibertyLibrary::setDefaultFanoutLoad, 1.0F); + readLibAttrFloat(library_group, "slew_derate_from_library", + &LibertyLibrary::setSlewDerateFromLibrary, 1.0F); +} + +void +LibertyReader::makeLibrary(const LibertyGroup *libary_group) +{ + const char *name = libary_group->firstName(); if (name) { LibertyLibrary *library = network_->findLiberty(name); if (library) - libWarn(1140, group, "library %s already exists.", name); + libWarn(1140, libary_group, "library %s already exists.", name); // Make a new library even if a library with the same name exists. // Both libraries may be accessed by min/max analysis points. library_ = network_->makeLibertyLibrary(name, filename_); @@ -664,8 +286,6 @@ LibertyReader::beginLibrary(LibertyGroup *group) current_scale_ = 1E-3F; // Default is 1; power_scale_ = 1; - // Default is fJ. - setEnergyScale(); // Default is 1 micron. distance_scale_ = 1e-6; @@ -677,802 +297,326 @@ LibertyReader::beginLibrary(LibertyGroup *group) library_->units()->distanceUnit()->setScale(distance_scale_); library_->setDelayModelType(DelayModelType::cmos_linear); - scale_factors_ = new ScaleFactors(""); - library_->setScaleFactors(scale_factors_); } else - libError(1141, group, "library missing name."); + libError(1141, libary_group, "library missing name."); } -// Energy scale is derived. -void -LibertyReader::setEnergyScale() +// Energy scale is derived from other units. +float +LibertyReader::energyScale() { - energy_scale_ = volt_scale_ * volt_scale_ * cap_scale_; + return volt_scale_ * volt_scale_ * cap_scale_; } void -LibertyReader::endLibrary(LibertyGroup *group) +LibertyReader::readTechnology(const LibertyGroup *library_group) { - endLibraryAttrs(group); -} - -void -LibertyReader::endLibraryAttrs(LibertyGroup *group) -{ - // These attributes reference named groups in the library so - // wait until the end of the library to resolve them. - if (default_wireload_) { - const Wireload *wireload = library_->findWireload(default_wireload_); - if (wireload) - library_->setDefaultWireload(wireload); - else - libWarn(1142, group, "default_wire_load %s not found.", default_wireload_); - stringDelete(default_wireload_); - default_wireload_ = nullptr; - } - - if (default_wireload_selection_) { - const WireloadSelection *selection = - library_->findWireloadSelection(default_wireload_selection_); - if (selection) - library_->setDefaultWireloadSelection(selection); - else - libWarn(1143, group, "default_wire_selection %s not found.", - default_wireload_selection_); - stringDelete(default_wireload_selection_); - default_wireload_selection_ = nullptr; - } - - if (default_operating_condition_) { - OperatingConditions *op_cond = - library_->findOperatingConditions(default_operating_condition_); - if (op_cond) - library_->setDefaultOperatingConditions(op_cond); - else - libWarn(1144, group, "default_operating_condition %s not found.", - default_operating_condition_); - stringDelete(default_operating_condition_); - default_operating_condition_ = nullptr; - } - - bool missing_threshold = false; - for (auto rf : RiseFall::range()) { - int rf_index = rf->index(); - if (!have_input_threshold_[rf_index]) { - libWarn(1145, group, "input_threshold_pct_%s not found.", rf->name()); - missing_threshold = true; - } - if (!have_output_threshold_[rf_index]) { - libWarn(1146, group, "output_threshold_pct_%s not found.", rf->name()); - missing_threshold = true; - } - if (!have_slew_lower_threshold_[rf_index]) { - libWarn(1147, group, "slew_lower_threshold_pct_%s not found.", rf->name()); - missing_threshold = true; - } - if (!have_slew_upper_threshold_[rf_index]) { - libWarn(1148, group, "slew_upper_threshold_pct_%s not found.", rf->name()); - missing_threshold = true; + const LibertyComplexAttr *tech_attr = library_group->findComplexAttr("technology"); + if (tech_attr) { + const LibertyAttrValue *tech_value = tech_attr->firstValue(); + if (tech_value) { + const std::string &tech = tech_value->stringValue(); + if (tech == "fpga") + library_->setDelayModelType(DelayModelType::cmos_linear); } } - if (missing_threshold) - libError(1149, group, "Library %s is missing one or more thresholds.", - library_->name()); } void -LibertyReader::visitTimeUnit(LibertyAttr *attr) +LibertyReader::readLibraryUnits(const LibertyGroup *library_group) { - if (library_) - parseUnits(attr, "s", time_scale_, library_->units()->timeUnit()); -} + readUnit("time_unit", "s", time_scale_, library_->units()->timeUnit(), library_group); + readUnit("pulling_resistance_unit", "ohm", res_scale_, + library_->units()->resistanceUnit(), library_group); + readUnit("voltage_unit", "V", volt_scale_, library_->units()->voltageUnit(), + library_group); + readUnit("current_unit", "A", current_scale_, library_->units()->currentUnit(), + library_group); + readUnit("leakage_power_unit", "W", power_scale_, library_->units()->powerUnit(), + library_group); + readUnit("distance_unit", "m", distance_scale_, library_->units()->distanceUnit(), + library_group); -void -LibertyReader::visitPullingResistanceUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "ohm", res_scale_, - library_->units()->resistanceUnit()); -} - -void -LibertyReader::visitResistanceUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "ohm", res_scale_, library_->units()->resistanceUnit()); -} - -void -LibertyReader::visitCurrentUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "A", current_scale_, library_->units()->currentUnit()); -} - -void -LibertyReader::visitVoltageUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "V", volt_scale_, library_->units()->voltageUnit()); - setEnergyScale(); -} - -void -LibertyReader::visitPowerUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "W", power_scale_, library_->units()->powerUnit()); -} - -void -LibertyReader::visitDistanceUnit(LibertyAttr *attr) -{ - if (library_) - parseUnits(attr, "m", distance_scale_, library_->units()->distanceUnit()); -} - -void -LibertyReader::parseUnits(LibertyAttr *attr, - const char *unit_suffix, - float &scale_var, - Unit *unit) -{ - const char *units = getAttrString(attr); - if (units) { - // Unit format is . - // Find the multiplier digits. - string units1 = units; - size_t mult_end = units1.find_first_not_of("0123456789"); - float mult = 1.0F; - string scale_suffix; - if (mult_end != units1.npos) { - string unit_mult = units1.substr(0, mult_end); - scale_suffix = units1.substr(mult_end); - if (unit_mult == "1") - mult = 1.0F; - else if (unit_mult == "10") - mult = 10.0F; - else if (unit_mult == "100") - mult = 100.0F; - else - libWarn(1150, attr, "unknown unit multiplier %s.", unit_mult.c_str()); - } - else - scale_suffix = units; - - float scale_mult = 1.0F; - if (scale_suffix.size() == strlen(unit_suffix) + 1) { - string suffix = scale_suffix.substr(1); - if (stringEqual(suffix.c_str(), unit_suffix)) { - char scale_char = tolower(scale_suffix[0]); - if (scale_char == 'k') - scale_mult = 1E+3F; - else if (scale_char == 'm') - scale_mult = 1E-3F; - else if (scale_char == 'u') - scale_mult = 1E-6F; - else if (scale_char == 'n') - scale_mult = 1E-9F; - else if (scale_char == 'p') - scale_mult = 1E-12F; - else if (scale_char == 'f') - scale_mult = 1E-15F; - else - libWarn(1151, attr, "unknown unit scale %c.", scale_char); + const LibertyComplexAttr *cap_attr = + library_group->findComplexAttr("capacitive_load_unit"); + if (cap_attr) { + const LibertyAttrValueSeq &values = cap_attr->values(); + if (values.size() == 2) { + LibertyAttrValue *value = values[0]; + bool valid = false; + float scale; + if (value->isFloat()) { + scale = value->floatValue(); + valid = true; } - else - libWarn(1152, attr, "unknown unit suffix %s.", suffix.c_str()); - } - else if (!stringEqual(scale_suffix.c_str(), unit_suffix)) - libWarn(1153, attr, "unknown unit suffix %s.", scale_suffix.c_str()); - scale_var = scale_mult * mult; - unit->setScale(scale_var); - } -} - -void -LibertyReader::visitCapacitiveLoadUnit(LibertyAttr *attr) -{ - if (library_) { - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *values = attr->values(); - if (values->size() == 2) { - LibertyAttrValue *value = (*values)[0]; - bool valid = false; - float scale; - if (value->isFloat()) { - scale = value->floatValue(); + else if (value->isString()) { + try { + scale = std::stof(value->stringValue()); valid = true; } - else if (value->isString()) { - try { - scale = std::stof(value->stringValue()); - valid = true; - } - catch (...) { - valid = false; - } + catch (...) { + valid = false; } + } - if (valid) { - value = (*values)[1]; - if (value->isString()) { - const std::string suffix = value->stringValue(); - if (stringEqual(suffix.c_str(), "ff")) - cap_scale_ = scale * 1E-15F; - else if (stringEqual(suffix.c_str(), "pf")) - cap_scale_ = scale * 1E-12F; - else - libWarn(1154, attr, "capacitive_load_units are not ff or pf."); - } - else - libWarn(1155, attr, "capacitive_load_units are not a string."); - } - else - libWarn(1157, attr, "capacitive_load_units scale is not a float."); - } - else if (values->size() == 1) - libWarn(1156, attr, "capacitive_load_units missing suffix."); - else - libWarn(1158, attr, "capacitive_load_units missing scale and suffix."); - } - else - libWarn(1159, attr, "capacitive_load_unit missing values suffix."); - library_->units()->capacitanceUnit()->setScale(cap_scale_); - setEnergyScale(); - } -} - -void -LibertyReader::visitDelayModel(LibertyAttr *attr) -{ - if (library_) { - const char *type_name = getAttrString(attr); - if (type_name) { - if (stringEq(type_name, "table_lookup")) - library_->setDelayModelType(DelayModelType::table); - else if (stringEq(type_name, "generic_cmos")) - library_->setDelayModelType(DelayModelType::cmos_linear); - else if (stringEq(type_name, "piecewise_cmos")) { - library_->setDelayModelType(DelayModelType::cmos_pwl); - libWarn(1160, attr, "delay_model %s not supported.", type_name); - } - else if (stringEq(type_name, "cmos2")) { - library_->setDelayModelType(DelayModelType::cmos2); - libWarn(1161, attr, "delay_model %s not supported.", type_name); - } - else if (stringEq(type_name, "polynomial")) { - library_->setDelayModelType(DelayModelType::polynomial); - libWarn(1162, attr, "delay_model %s not supported.", type_name); - } - // Evil IBM garbage. - else if (stringEq(type_name, "dcm")) { - library_->setDelayModelType(DelayModelType::dcm); - libWarn(1163, attr, "delay_model %s not supported..", type_name); - } - else - libWarn(1164, attr, "unknown delay_model %s.", type_name); - } - } -} - -void -LibertyReader::visitBusStyle(LibertyAttr *attr) -{ - if (library_) { - const char *bus_style = getAttrString(attr); - // Assume bus style is of the form "%s[%d]". - if (bus_style - && strlen(bus_style) == 6 - && bus_style[0] == '%' - && bus_style[1] == 's' - && bus_style[3] == '%' - && bus_style[4] == 'd') - library_->setBusBrkts(bus_style[2], bus_style[5]); - else - libWarn(1165, attr, "unknown bus_naming_style format."); - } -} - -void -LibertyReader::visitVoltageMap(LibertyAttr *attr) -{ - if (library_) { - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *values = attr->values(); - if (values->size() >= 1) { - LibertyAttrValue *value = (*values)[0]; + if (valid) { + value = values[1]; if (value->isString()) { - const std::string &supply_name = value->stringValue(); - if (values->size() == 2) { - value = (*values)[1]; - bool valid = false; - float voltage; - if (value->isFloat()) { - voltage = value->floatValue(); - valid = true; - } - else if (value->isString()) { - try { - voltage = std::stof(value->stringValue()); - valid = true; - } - catch (...) { - valid = false; - } - } - - if (valid) - library_->addSupplyVoltage(supply_name.c_str(), voltage); - else - libWarn(1166, attr, "voltage_map voltage is not a float."); - } + const std::string suffix = value->stringValue(); + if (stringEqual(suffix.c_str(), "ff")) + cap_scale_ = scale * 1E-15F; + else if (stringEqual(suffix.c_str(), "pf")) + cap_scale_ = scale * 1E-12F; else - libWarn(1167, attr, "voltage_map missing voltage."); + libWarn(1154, cap_attr, "capacitive_load_units are not ff or pf."); } else - libWarn(1168, attr, "voltage_map supply name is not a string."); + libWarn(1155, cap_attr, "capacitive_load_units are not a string."); } else - libWarn(1169, attr, "voltage_map missing supply name and voltage."); + libWarn(1157, cap_attr, "capacitive_load_units scale is not a float."); + } + else if (values.size() == 1) + libWarn(1156, cap_attr, "capacitive_load_units missing suffix."); + else + libWarn(1158, cap_attr, "capacitive_load_units missing scale and suffix."); + library_->units()->capacitanceUnit()->setScale(cap_scale_); + } +} + +void +LibertyReader::readUnit(const char *unit_attr_name, + const char *unit_suffix, + float &scale_var, + Unit *unit, + const LibertyGroup *library_group) +{ + const LibertySimpleAttr *unit_attr = library_group->findSimpleAttr(unit_attr_name); + if (unit_attr) { + const std::string *units = unit_attr->stringValue(); + if (units) { + // Unit format is . + // Find the multiplier digits. + std::string units1 = *units; + size_t mult_end = units1.find_first_not_of("0123456789"); + float mult = 1.0F; + std::string scale_suffix; + if (mult_end != units1.npos) { + std::string unit_mult = units1.substr(0, mult_end); + scale_suffix = units1.substr(mult_end); + if (unit_mult == "1") + mult = 1.0F; + else if (unit_mult == "10") + mult = 10.0F; + else if (unit_mult == "100") + mult = 100.0F; + else + libWarn(1150, unit_attr, "unknown unit multiplier %s.", unit_mult.c_str()); + } + else + scale_suffix = *units; + + float scale_mult = 1.0F; + if (scale_suffix.size() == strlen(unit_suffix) + 1) { + std::string suffix = scale_suffix.substr(1); + if (stringEqual(suffix.c_str(), unit_suffix)) { + char scale_char = tolower(scale_suffix[0]); + if (scale_char == 'k') + scale_mult = 1E+3F; + else if (scale_char == 'm') + scale_mult = 1E-3F; + else if (scale_char == 'u') + scale_mult = 1E-6F; + else if (scale_char == 'n') + scale_mult = 1E-9F; + else if (scale_char == 'p') + scale_mult = 1E-12F; + else if (scale_char == 'f') + scale_mult = 1E-15F; + else + libWarn(1151, unit_attr, "unknown unit scale %c.", scale_char); + } + else + libWarn(1152, unit_attr, "unknown unit suffix %s.", suffix.c_str()); + } + else if (!stringEqual(scale_suffix.c_str(), unit_suffix)) + libWarn(1153, unit_attr, "unknown unit suffix %s.", scale_suffix.c_str()); + scale_var = scale_mult * mult; + unit->setScale(scale_var); + } + } +} + +void +LibertyReader::readDelayModel(const LibertyGroup *library_group) +{ + const std::string *type_name = library_group->findAttrString("delay_model"); + if (type_name) { + if (*type_name == "table_lookup") + library_->setDelayModelType(DelayModelType::table); + else if (*type_name == "generic_cmos") + library_->setDelayModelType(DelayModelType::cmos_linear); + else if (*type_name == "piecewise_cmos") { + library_->setDelayModelType(DelayModelType::cmos_pwl); + libWarn(1160, library_group, "delay_model %s not supported.", type_name->c_str()); + } + else if (*type_name == "cmos2") { + library_->setDelayModelType(DelayModelType::cmos2); + libWarn(1161, library_group, "delay_model %s not supported.", type_name->c_str()); + } + else if (*type_name == "polynomial") { + library_->setDelayModelType(DelayModelType::polynomial); + libWarn(1162, library_group, "delay_model %s not supported.", type_name->c_str()); + } + // Evil IBM garbage. + else if (*type_name == "dcm") { + library_->setDelayModelType(DelayModelType::dcm); + libWarn(1163, library_group, "delay_model %s not supported..", type_name->c_str()); } else - libWarn(1170, attr, "voltage_map missing values suffix."); + libWarn(1164, library_group, "unknown delay_model %s.", type_name->c_str()); } } void -LibertyReader::visitNomTemp(LibertyAttr *attr) +LibertyReader::readBusStyle(const LibertyGroup *library_group) { - if (library_) { - float value; - bool valid; - getAttrFloat(attr, value, valid); - if (valid) - library_->setNominalTemperature(value); + const std::string *bus_style = library_group->findAttrString("bus_naming_style"); + if (bus_style) { + // Assume bus style is of the form "%s[%d]". + if (bus_style->size() == 6 + && (*bus_style)[0] == '%' + && (*bus_style)[1] == 's' + && (*bus_style)[3] == '%' + && (*bus_style)[4] == 'd') + library_->setBusBrkts((*bus_style)[2], (*bus_style)[5]); + else + libWarn(1165, library_group, "unknown bus_naming_style format."); } } void -LibertyReader::visitNomProc(LibertyAttr *attr) +LibertyReader::readBusTypes(LibertyCell *cell, + const LibertyGroup *group) { - if (library_) { - float value; - bool valid; - getAttrFloat(attr, value, valid); - if (valid) - library_->setNominalProcess(value); - } -} - -void -LibertyReader::visitNomVolt(LibertyAttr *attr) -{ - if (library_) { - float value; - bool valid; - getAttrFloat(attr, value, valid); - if (valid) - library_->setNominalVoltage(value); - } -} - -void -LibertyReader::visitDefaultInoutPinCap(LibertyAttr *attr) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultBidirectPinCap(value * cap_scale_); - } -} - -void -LibertyReader::visitDefaultInputPinCap(LibertyAttr *attr) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultInputPinCap(value * cap_scale_); - } -} - -void -LibertyReader::visitDefaultOutputPinCap(LibertyAttr *attr) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultOutputPinCap(value * cap_scale_); - } -} - -void -LibertyReader::visitDefaultMaxTransition(LibertyAttr *attr) -{ - if (library_){ - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - if (value == 0.0) - libWarn(1171, attr, "default_max_transition is 0.0."); - library_->setDefaultMaxSlew(value * time_scale_); + for (const LibertyGroup *type_group : group->findSubgroups("type")) { + const char *name = type_group->firstName(); + if (name) { + int from, to; + bool from_exists, to_exists; + type_group->findAttrInt("bit_from", from, from_exists); + type_group->findAttrInt("bit_to", to, to_exists); + if (from_exists && to_exists) { + if (cell) + cell->makeBusDcl(name, from, to); + else + library_->makeBusDcl(name, from, to); + } + else if (!from_exists) + libWarn(1179, type_group, "bus type missing bit_from."); + else if (!to_exists) + libWarn(1180, type_group, "bus type missing bit_to."); } } } void -LibertyReader::visitDefaultMaxFanout(LibertyAttr *attr) +LibertyReader::readThresholds(const LibertyGroup *library_group) { - if (library_){ - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - if (value == 0.0) - libWarn(1172, attr, "default_max_fanout is 0.0."); - library_->setDefaultMaxFanout(value); - } + for (const RiseFall *rf : RiseFall::range()) { + std::string suffix = rf->to_string_long(); + readLibAttrFloat(library_group, ("input_threshold_pct_" + suffix).c_str(), + &LibertyLibrary::setInputThreshold, rf, 0.01F); + if (library_->inputThreshold(rf) == 0.0) + libWarn(1145, library_group, "input_threshold_pct_%s not found.", rf->name()); + + readLibAttrFloat(library_group, ("output_threshold_pct_" + suffix).c_str(), + &LibertyLibrary::setOutputThreshold, rf, 0.01F); + if (library_->outputThreshold(rf) == 0.0) + libWarn(1146, library_group, "output_threshold_pct_%s not found.", rf->name()); + + readLibAttrFloat(library_group, ("slew_lower_threshold_pct_" + suffix).c_str(), + &LibertyLibrary::setSlewLowerThreshold, rf, 0.01F); + if (library_->slewLowerThreshold(rf) == 0.0) + libWarn(1147, library_group, "slew_lower_threshold_pct_%s not found.", rf->name()); + + readLibAttrFloat(library_group, ("slew_upper_threshold_pct_" + suffix).c_str(), + &LibertyLibrary::setSlewUpperThreshold, rf, 0.01F); + if (library_->slewUpperThreshold(rf) == 0.0) + libWarn(1148, library_group, "slew_upper_threshold_pct_%s not found.", rf->name()); } } void -LibertyReader::visitDefaultIntrinsicRise(LibertyAttr *attr) +LibertyReader::readTableTemplates(const LibertyGroup *library_group) { - visitDefaultIntrinsic(attr, RiseFall::rise()); + readTableTemplates(library_group, "lu_table_template", TableTemplateType::delay); + readTableTemplates(library_group, "output_current_template", + TableTemplateType::output_current); + readTableTemplates(library_group, "power_lut_template", TableTemplateType::power); + readTableTemplates(library_group, "ocv_table_template", TableTemplateType::ocv); } void -LibertyReader::visitDefaultIntrinsicFall(LibertyAttr *attr) -{ - visitDefaultIntrinsic(attr, RiseFall::fall()); -} - -void -LibertyReader::visitDefaultIntrinsic(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultIntrinsic(rf, value * time_scale_); - } -} - -void -LibertyReader::visitDefaultInoutPinRiseRes(LibertyAttr *attr) -{ - visitDefaultInoutPinRes(attr, RiseFall::rise()); -} - -void -LibertyReader::visitDefaultInoutPinFallRes(LibertyAttr *attr) -{ - visitDefaultInoutPinRes(attr, RiseFall::fall()); -} - -void -LibertyReader::visitDefaultInoutPinRes(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultBidirectPinRes(rf, value * res_scale_); - } -} - -void -LibertyReader::visitDefaultOutputPinRiseRes(LibertyAttr *attr) -{ - visitDefaultOutputPinRes(attr, RiseFall::rise()); -} - -void -LibertyReader::visitDefaultOutputPinFallRes(LibertyAttr *attr) -{ - visitDefaultOutputPinRes(attr, RiseFall::fall()); -} - -void -LibertyReader::visitDefaultOutputPinRes(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setDefaultOutputPinRes(rf, value * res_scale_); - } -} - -void -LibertyReader::visitDefaultFanoutLoad(LibertyAttr *attr) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - if (value == 0.0) - libWarn(1173, attr, "default_fanout_load is 0.0."); - library_->setDefaultFanoutLoad(value); - } - } -} - -void -LibertyReader::visitDefaultWireLoad(LibertyAttr *attr) -{ - if (library_) { - const char *value = getAttrString(attr); - if (value) { - stringDelete(default_wireload_); - default_wireload_ = stringCopy(value); - } - } -} - -void -LibertyReader::visitDefaultWireLoadMode(LibertyAttr *attr) -{ - if (library_) { - const char *wire_load_mode = getAttrString(attr); - if (wire_load_mode) { - WireloadMode mode = stringWireloadMode(wire_load_mode); - if (mode != WireloadMode::unknown) - library_->setDefaultWireloadMode(mode); - else - libWarn(1174, attr, "default_wire_load_mode %s not found.", - wire_load_mode); - } - } -} - -void -LibertyReader::visitDefaultWireLoadSelection(LibertyAttr *attr) -{ - if (library_) { - const char *value = getAttrString(attr); - if (value) { - stringDelete(default_wireload_selection_); - default_wireload_selection_ = stringCopy(value); - } - } -} - -void -LibertyReader::visitDefaultOperatingConditions(LibertyAttr *attr) -{ - if (library_) { - const char *value = getAttrString(attr); - if (value) { - stringDelete(default_operating_condition_); - default_operating_condition_ = stringCopy(value); - } - } -} - -void -LibertyReader::visitInputThresholdPctFall(LibertyAttr *attr) -{ - visitInputThresholdPct(attr, RiseFall::fall()); -} - -void -LibertyReader::visitInputThresholdPctRise(LibertyAttr *attr) -{ - visitInputThresholdPct(attr, RiseFall::rise()); -} - -void -LibertyReader::visitInputThresholdPct(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setInputThreshold(rf, value / 100.0F); - } - have_input_threshold_[rf->index()] = true; -} - -void -LibertyReader::visitOutputThresholdPctFall(LibertyAttr *attr) -{ - visitOutputThresholdPct(attr, RiseFall::fall()); -} - -void -LibertyReader::visitOutputThresholdPctRise(LibertyAttr *attr) -{ - visitOutputThresholdPct(attr, RiseFall::rise()); -} - -void -LibertyReader::visitOutputThresholdPct(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setOutputThreshold(rf, value / 100.0F); - } - have_output_threshold_[rf->index()] = true; -} - -void -LibertyReader::visitSlewLowerThresholdPctFall(LibertyAttr *attr) -{ - visitSlewLowerThresholdPct(attr, RiseFall::fall()); -} - -void -LibertyReader::visitSlewLowerThresholdPctRise(LibertyAttr *attr) -{ - visitSlewLowerThresholdPct(attr, RiseFall::rise()); -} - -void -LibertyReader::visitSlewLowerThresholdPct(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setSlewLowerThreshold(rf, value / 100.0F); - } - have_slew_lower_threshold_[rf->index()] = true; -} - -void -LibertyReader::visitSlewUpperThresholdPctFall(LibertyAttr *attr) -{ - visitSlewUpperThresholdPct(attr, RiseFall::fall()); -} - -void -LibertyReader::visitSlewUpperThresholdPctRise(LibertyAttr *attr) -{ - visitSlewUpperThresholdPct(attr, RiseFall::rise()); -} - -void -LibertyReader::visitSlewUpperThresholdPct(LibertyAttr *attr, - const RiseFall *rf) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setSlewUpperThreshold(rf, value / 100.0F); - } - have_slew_upper_threshold_[rf->index()] = true; -} - -void -LibertyReader::visitSlewDerateFromLibrary(LibertyAttr *attr) -{ - if (library_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - library_->setSlewDerateFromLibrary(value); - } -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginTechnology(LibertyGroup *group) -{ - if (library_) { - const char *tech = group->firstName(); - if (stringEq(tech, "fpga")) - library_->setDelayModelType(DelayModelType::cmos_linear); - } -} - -void -LibertyReader::endTechnology(LibertyGroup *) -{ -} - -void -LibertyReader::beginTableTemplateDelay(LibertyGroup *group) -{ - beginTableTemplate(group, TableTemplateType::delay); -} - -void -LibertyReader::beginTableTemplateOutputCurrent(LibertyGroup *group) -{ - beginTableTemplate(group, TableTemplateType::output_current); -} - -void -LibertyReader::beginTableTemplate(LibertyGroup *group, +LibertyReader::readTableTemplates(const LibertyGroup *library_group, + const char *group_name, TableTemplateType type) { - if (library_) { - const char *name = group->firstName(); + for (const LibertyGroup *template_group : library_group->findSubgroups(group_name)) { + const char *name = template_group->firstName(); if (name) { - tbl_template_ = library_->makeTableTemplate(name, type); + TableTemplate *tbl_template = library_->makeTableTemplate(name, type); + TableAxisPtr axis1 = makeTableTemplateAxis(template_group, 1); + if (axis1) + tbl_template->setAxis1(axis1); + TableAxisPtr axis2 = makeTableTemplateAxis(template_group, 2); + if (axis2) + tbl_template->setAxis2(axis2); + TableAxisPtr axis3 = makeTableTemplateAxis(template_group, 3); + if (axis3) + tbl_template->setAxis3(axis3); } else - libWarn(1175, group, "table template missing name."); - axis_var_[0] = axis_var_[1] = axis_var_[2] = TableAxisVariable::unknown; - clearAxisValues(); - } -} - -void -LibertyReader::clearAxisValues() -{ - axis_values_[0].clear(); - axis_values_[1].clear(); - axis_values_[2].clear(); -} - -void -LibertyReader::endTableTemplate(LibertyGroup *group) -{ - if (tbl_template_) { - TableAxisPtr axis1 = makeAxis(0, group); - if (axis1) - tbl_template_->setAxis1(axis1); - TableAxisPtr axis2 = makeAxis(1, group); - if (axis2) - tbl_template_->setAxis2(axis2); - TableAxisPtr axis3 = makeAxis(2, group); - if (axis3) - tbl_template_->setAxis3(axis3); - tbl_template_ = nullptr; - axis_var_[0] = axis_var_[1] = axis_var_[2] = TableAxisVariable::unknown; + libWarn(1175, template_group, "table template missing name."); } } TableAxisPtr -LibertyReader::makeAxis(int index, - LibertyGroup *group) +LibertyReader::makeTableTemplateAxis(const LibertyGroup *template_group, + int axis_index) { - TableAxisVariable axis_var = axis_var_[index]; - if (axis_var != TableAxisVariable::unknown) { - FloatSeq values; - if (!axis_values_[index].empty()) { + std::string var_attr_name = "variable_" + std::to_string(axis_index); + const std::string *var_name = template_group->findAttrString(var_attr_name); + if (var_name) { + TableAxisVariable axis_var = stringTableAxisVariable(var_name->c_str()); + if (axis_var == TableAxisVariable::unknown) + libWarn(1297, template_group, "axis type %s not supported.", var_name->c_str()); + else { + std::string index_attr_name = "index_" + std::to_string(axis_index); + const LibertyComplexAttr *index_attr = + template_group->findComplexAttr(index_attr_name); + FloatSeq axis_values; + if (index_attr) { + axis_values = readFloatSeq(index_attr, 1.0F); + if (!axis_values.empty()) { + float prev = axis_values[0]; + for (size_t i = 1; i < axis_values.size(); i++) { + float value = axis_values[i]; + if (value <= prev) { + libWarn(1178, template_group, "non-increasing table index values."); + break; + } + prev = value; + } + } + } const Units *units = library_->units(); float scale = tableVariableUnit(axis_var, units)->scale(); - values = std::move(axis_values_[index]); - scaleFloats(values, scale); + scaleFloats(axis_values, scale); + return make_shared(axis_var, std::move(axis_values)); } - return make_shared(axis_var, std::move(values)); } - else if (!axis_values_[index].empty()) { - libWarn(1176, group, "missing variable_%d attribute.", index + 1); - axis_values_[index].clear(); - } - // No warning for missing index_xx attributes because they are not required. return nullptr; } @@ -1486,695 +630,2163 @@ scaleFloats(FloatSeq &floats, } void -LibertyReader::visitVariable1(LibertyAttr *attr) +LibertyReader::readVoltateMaps(const LibertyGroup *library_group) { - visitVariable(0, attr); -} - -void -LibertyReader::visitVariable2(LibertyAttr *attr) -{ - visitVariable(1, attr); -} - -void -LibertyReader::visitVariable3(LibertyAttr *attr) -{ - visitVariable(2, attr); -} - -void -LibertyReader::visitVariable(int index, - LibertyAttr *attr) -{ - if (tbl_template_) { - const char *type = getAttrString(attr); - TableAxisVariable var = stringTableAxisVariable(type); - if (var == TableAxisVariable::unknown) - libWarn(1297, attr, "axis type %s not supported.", type); - else - axis_var_[index] = var; + for (const LibertyComplexAttr *volt_attr : + library_group->findComplexAttrs("voltage_map")) { + const LibertyAttrValueSeq &values = volt_attr->values(); + if (values.size() == 2) { + const std::string &volt_name = values[0]->stringValue(); + float volt; + bool valid; + values[1]->floatValue(volt, valid); + if (valid) + library_->addSupplyVoltage(volt_name.c_str(), volt); + else + libWarn(1166, volt_attr, "voltage_map voltage is not a float."); + } } } void -LibertyReader::visitIndex1(LibertyAttr *attr) +LibertyReader::readOperatingConds(const LibertyGroup *library_group) { - visitIndex(0, attr); + for (const LibertyGroup *opcond_group : + library_group->findSubgroups("operating_conditions")) { + const char *name = opcond_group->firstName(); + if (name) { + OperatingConditions *op_cond = library_->makeOperatingConditions(name); + float value; + bool exists; + opcond_group->findAttrFloat("process", value, exists); + if (exists) + op_cond->setProcess(value); + opcond_group->findAttrFloat("temperature", value, exists); + if (exists) + op_cond->setTemperature(value); + opcond_group->findAttrFloat("voltage", value, exists); + if (exists) + op_cond->setVoltage(value); + const std::string *tree_type = opcond_group->findAttrString("tree_type"); + if (tree_type) { + WireloadTree wireload_tree = stringWireloadTree(tree_type->c_str()); + op_cond->setWireloadTree(wireload_tree); + } + } + } + + const std::string *default_op_cond = + library_group->findAttrString("default_operating_conditions"); + if (default_op_cond) { + OperatingConditions *op_cond = + library_->findOperatingConditions(default_op_cond->c_str()); + if (op_cond) + library_->setDefaultOperatingConditions(op_cond); + else + libWarn(1144, library_group, "default_operating_condition %s not found.", + default_op_cond->c_str()); + } } void -LibertyReader::visitIndex2(LibertyAttr *attr) +LibertyReader::readScaleFactors(const LibertyGroup *library_group) { - visitIndex(1, attr); + // Top level scale factors. + ScaleFactors *scale_factors = library_->makeScaleFactors(""); + library_->setScaleFactors(scale_factors); + readScaleFactors(library_group, scale_factors); + + // Named scale factors. + for (const LibertyGroup *scale_group : library_group->findSubgroups("scaling_factors")){ + const char *name = scale_group->firstName(); + if (name) { + ScaleFactors *scale_factors = library_->makeScaleFactors(name); + readScaleFactors(scale_group, scale_factors); + } + } } void -LibertyReader::visitIndex3(LibertyAttr *attr) +LibertyReader::readScaleFactors(const LibertyGroup *scale_group, + ScaleFactors *scale_factors) { - visitIndex(2, attr); + // Skip unknown type. + for (int type_index = 0; type_index < scale_factor_type_count - 1; type_index++) { + ScaleFactorType type = static_cast(type_index); + const char *type_name = scaleFactorTypeName(type); + // Skip unknown pvt. + for (int pvt_index = 0; pvt_index < scale_factor_pvt_count - 1; pvt_index++) { + ScaleFactorPvt pvt = static_cast(pvt_index); + const std::string pvt_name = scaleFactorPvtName(pvt); + std::string attr_name; + for (const RiseFall *rf : RiseFall::range()) { + if (scaleFactorTypeRiseFallSuffix(type)) { + const std::string rf_name = (rf == RiseFall::rise()) ? "rise" : "fall"; + attr_name = "k_" + pvt_name + "_" + type_name + "_" + rf_name; + } + else if (scaleFactorTypeRiseFallPrefix(type)) { + const char *rf_name = (rf == RiseFall::rise()) ? "rise" : "fall"; + attr_name = "k_" + pvt_name + "_" + rf_name + "_" + type_name; + } + else if (scaleFactorTypeLowHighSuffix(type)) { + const char *rf_name = (rf == RiseFall::rise()) ? "high":"low"; + attr_name = "k_" + pvt_name + "_" + type_name + "_" + rf_name; + } + else + attr_name = "k_" + pvt_name + "_" + type_name; + float value; + bool exists; + scale_group->findAttrFloat(attr_name, value, exists); + if (exists) + scale_factors->setScale(type, pvt, rf, value); + } + } + } } void -LibertyReader::visitIndex(int index, - LibertyAttr *attr) +LibertyReader::readWireloads(const LibertyGroup *library_group) { - if (tbl_template_ - // Ignore index_* in ecsm_waveform groups. - && !in_ecsm_waveform_) { - FloatSeq axis_values = readFloatSeq(attr, 1.0F); + for (const LibertyGroup *wl_group : library_group->findSubgroups("wire_load")) { + const char *name = wl_group->firstName(); + if (name) { + Wireload *wireload = library_->makeWireload(name); + float value; + bool exists; + wl_group->findAttrFloat("resistance", value, exists); + if (exists) + wireload->setResistance(value * res_scale_); + + wl_group->findAttrFloat("capacitance", value, exists); + if (exists) + wireload->setCapacitance(value * cap_scale_); + + wl_group->findAttrFloat("slope", value, exists); + if (exists) + wireload->setSlope(value); + + for (const LibertyComplexAttr *fanout_attr : + wl_group->findComplexAttrs("fanout_length")) { + float fanout, length; + bool exists; + getAttrFloat2(fanout_attr, fanout, length, exists); + if (exists) + wireload->addFanoutLength(fanout, length); + else + libWarn(1185, fanout_attr, "fanout_length is missing length and fanout."); + } + } + else + libWarn(1184, wl_group, "wire_load missing name."); + } +} + +void +LibertyReader::readWireloadSelection(const LibertyGroup *library_group) +{ + const LibertyGroup *sel_group = library_group->findSubgroup("wire_load_selection"); + if (sel_group) { + const char *name = sel_group->firstName(); + if (name == nullptr) + name = ""; + WireloadSelection *wireload_selection = library_->makeWireloadSelection(name); + for (const LibertyComplexAttr *area_attr : + sel_group->findComplexAttrs("wire_load_from_area")) { + const LibertyAttrValueSeq &values = area_attr->values(); + if (values.size() == 3) { + LibertyAttrValue *value = values[0]; + if (value->isFloat()) { + float min_area = value->floatValue(); + value = values[1]; + if (value->isFloat()) { + float max_area = value->floatValue(); + value = values[2]; + if (value->isString()) { + const std::string &wireload_name = value->stringValue(); + const Wireload *wireload = + library_->findWireload(wireload_name.c_str()); + if (wireload) + wireload_selection->addWireloadFromArea(min_area, max_area, + wireload); + else + libWarn(1187, area_attr, "wireload %s not found.", wireload_name.c_str()); + } + else + libWarn(1188, area_attr, + "wire_load_from_area wireload name not a string."); + } + else + libWarn(1189, area_attr, "wire_load_from_area min not a float."); + } + else + libWarn(1190, area_attr, "wire_load_from_area max not a float."); + } + else + libWarn(1191, area_attr, "wire_load_from_area missing parameters."); + } + } +} + +void +LibertyReader::readDefaultWireLoad(const LibertyGroup *library_group) +{ + const std::string *wireload_name = library_group->findAttrString("default_wire_load"); + if (wireload_name) { + const Wireload *wireload = library_->findWireload(wireload_name->c_str()); + if (wireload) + library_->setDefaultWireload(wireload); + else + libWarn(1142, library_group, "default_wire_load %s not found.", + wireload_name->c_str()); + } +} + +void +LibertyReader::readDefaultWireLoadMode(const LibertyGroup *library_group) +{ + const std::string *wire_load_mode = + library_group->findAttrString("default_wire_load_mode"); + if (wire_load_mode) { + WireloadMode mode = stringWireloadMode(wire_load_mode->c_str()); + if (mode != WireloadMode::unknown) + library_->setDefaultWireloadMode(mode); + else + libWarn(1174, library_group, "default_wire_load_mode %s not found.", + wire_load_mode->c_str()); + } +} + +void +LibertyReader::readDefaultWireLoadSelection(const LibertyGroup *library_group) +{ + const std::string *selection_name = + library_group->findAttrString("default_wire_load_selection"); + if (selection_name) { + const WireloadSelection *selection = + library_->findWireloadSelection(selection_name->c_str()); + if (selection) + library_->setDefaultWireloadSelection(selection); + else + libWarn(1143, library_group, "default_wire_selection %s not found.", + selection_name->c_str()); + } +} + +void +LibertyReader::readModeDefs(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + for (const LibertyGroup *mode_group : cell_group->findSubgroups("mode_definition")) { + const char *name = mode_group->firstName(); + if (name) { + ModeDef *mode_def = cell->makeModeDef(name); + for (const LibertyGroup *value_group : mode_group->findSubgroups("mode_value")) { + const char *value_name = value_group->firstName(); + if (value_name) { + ModeValueDef *mode_value = mode_def->defineValue(value_name, nullptr, nullptr); + const std::string *sdf_cond = value_group->findAttrString("sdf_cond"); + if (sdf_cond) + mode_value->setSdfCond(sdf_cond->c_str()); + const std::string *when = value_group->findAttrString("when"); + if (when) { + // line + FuncExpr *when_expr = parseFunc(when->c_str(), "when", cell, + value_group->line()); + mode_value->setCond(when_expr); + } + } + else + libWarn(1264, value_group, "mode value missing name."); + } + } + else + libWarn(1263, mode_group, "mode definition missing name."); + } +} + +void +LibertyReader::readSlewDegradations(const LibertyGroup *library_group) +{ + for (const RiseFall *rf : RiseFall::range()) { + const std::string group_name = rf->to_string_long() + "_transition_degradation"; + const LibertyGroup *degradation_group = + library_group->findSubgroup(group_name.c_str()); + if (degradation_group) { + TableModel *table_model = readTableModel(degradation_group, rf, + TableTemplateType::delay, + time_scale_, + ScaleFactorType::transition); + if (LibertyLibrary::checkSlewDegradationAxes(table_model)) + library_->setWireSlewDegradationTable(table_model, rf); + else + libWarn(1254, degradation_group, "unsupported model axis."); + } + } +} + +void +LibertyReader::readLibAttrFloat(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(float value), + float scale) +{ + float value; + bool exists; + library_group->findAttrFloat(attr_name, value, exists); + if (exists) + (library_->*set_func)(value * scale); +} + +void +LibertyReader::readLibAttrFloat(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(const RiseFall *rf, + float value), + const RiseFall *rf, + float scale) +{ + float value; + bool exists; + library_group->findAttrFloat(attr_name, value, exists); + if (exists) + (library_->*set_func)(rf, value * scale); +} + +void +LibertyReader::readLibAttrFloatWarnZero(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(float value), + float scale) +{ + float value; + bool exists; + library_group->findAttrFloat(attr_name, value, exists); + if (exists) { + if (value == 0.0F) { + const LibertySimpleAttr *attr = library_group->findSimpleAttr(attr_name); + if (attr) + libWarn(1171, attr, "%s is 0.0.", attr_name); + else + libWarn(1172, library_group, "%s is 0.0.", attr_name); + } + (library_->*set_func)(value * scale); + } +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::readCell(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + readBusTypes(cell, cell_group); + // Make ports first because they are referenced by functions, timing arcs, etc. + LibertyPortGroupMap port_group_map = makeCellPorts(cell, cell_group); + + // Make ff/latch output ports. + makeSequentials(cell, cell_group); + + readCellAttributes(cell, cell_group); + + // Set port directions before making timing arcs etc. + for (auto const &[port_group, ports] : port_group_map) + readPortDir(ports, port_group); + + for (auto const &[port_group, ports] : port_group_map) { + readPortAttributes(cell, ports, port_group); + makePortFuncs(cell, ports, port_group); + makeTimingArcs(cell, ports, port_group); + readInternalPowerGroups(cell, ports, port_group); + } + + readTestCell(cell, cell_group); + + cell->finish(infer_latches_, report_, debug_); +} + +void +LibertyReader::readScaledCell(const LibertyGroup *scaled_cell_group) +{ + const char *name = scaled_cell_group->firstName(); + if (name) { + LibertyCell *owner = library_->findLibertyCell(name); + if (owner) { + const char *op_cond_name = scaled_cell_group->secondName(); + if (op_cond_name) { + OperatingConditions *op_cond = library_->findOperatingConditions(op_cond_name); + if (op_cond) { + debugPrint(debug_, "liberty", 1, "scaled cell %s %s", + name, op_cond_name); + LibertyCell *scaled_cell = library_->makeScaledCell(name, filename_); + readCell(scaled_cell, scaled_cell_group); + checkScaledCell(scaled_cell, owner, scaled_cell_group, op_cond_name); + // Add scaled cell AFTER ports and timing arcs are defined. + owner->addScaledCell(op_cond, scaled_cell); + } + else + libWarn(1202, scaled_cell_group, "operating conditions %s not found.", + op_cond_name); + } + else + libWarn(1203, scaled_cell_group, "scaled_cell missing operating condition."); + } + else + libWarn(1204, scaled_cell_group, "scaled_cell cell %s has not been defined.", name); + } + else + libWarn(1205, scaled_cell_group, "scaled_cell missing name."); +} + +// Minimal check that is not very specific about where the discrepancies are. +void +LibertyReader::checkScaledCell(LibertyCell *scaled_cell, + LibertyCell *owner, + const LibertyGroup *scaled_cell_group, + const char *op_cond_name) +{ + if (equivCellPorts(scaled_cell, owner)) { + if (!equivCellPorts(scaled_cell, owner)) + libWarn(1206, scaled_cell_group, "scaled_cell %s, %s ports do not match cell ports", + scaled_cell->name(), + op_cond_name); + if (!equivCellFuncs(scaled_cell, owner)) + libWarn(1206, scaled_cell_group, + "scaled_cell %s, %s port functions do not match cell port functions.", + scaled_cell->name(), + op_cond_name); + } + else + libWarn(1207, scaled_cell_group, "scaled_cell ports do not match cell ports."); + if (!equivCellTimingArcSets(scaled_cell, owner)) + libWarn(1208, scaled_cell_group, + "scaled_cell %s, %s timing does not match cell timing.", + scaled_cell->name(), + op_cond_name); +} + +LibertyPortGroupMap +LibertyReader::makeCellPorts(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + LibertyPortGroupMap port_group_map; + for (const LibertyGroup *subgroup : cell_group->subgroups()) { + const std::string &type = subgroup->type(); + if (type == "pin") + makePinPort(cell, subgroup, port_group_map); + else if (type == "bus") + makeBusPort(cell, subgroup, port_group_map); + else if (type == "bundle") + makeBundlePort(cell, subgroup, port_group_map); + else if (type == "pg_pin") + makePgPinPort(cell, subgroup); + } + return port_group_map; +} + +void +LibertyReader::makePinPort(LibertyCell *cell, + const LibertyGroup *pin_group, + LibertyPortGroupMap &port_group_map) +{ + for (const LibertyAttrValue *port_value : pin_group->params()) { + const std::string &port_name = port_value->stringValue(); + LibertyPort *port = makePort(cell, port_name.c_str()); + port_group_map[pin_group].push_back(port); + } +} + +void +LibertyReader::makeBusPort(LibertyCell *cell, + const LibertyGroup *bus_group, + LibertyPortGroupMap &port_group_map) +{ + for (const LibertyAttrValue *port_value : bus_group->params()) { + const std::string &port_name = port_value->stringValue(); + const LibertySimpleAttr *bus_type_attr = bus_group->findSimpleAttr("bus_type"); + if (bus_type_attr) { + const std::string *bus_type = bus_type_attr->stringValue(); + if (bus_type) { + // Look for bus dcl local to cell first. + BusDcl *bus_dcl = cell->findBusDcl(bus_type->c_str()); + if (bus_dcl == nullptr) + bus_dcl = library_->findBusDcl(bus_type->c_str()); + if (bus_dcl) { + debugPrint(debug_, "liberty", 1, " bus %s", port_name.c_str()); + LibertyPort *bus_port = makeBusPort(cell, port_name.c_str(), + bus_dcl->from(), bus_dcl->to(), + bus_dcl); + port_group_map[bus_group].push_back(bus_port); + // Make ports for pin groups inside the bus group. + makeBusPinPorts(cell, bus_group, port_group_map); + } + else + libWarn(1235, bus_type_attr, "bus_type %s not found.", bus_type->c_str()); + } + } + else + libWarn(1236, bus_type_attr, "bus_type not found."); + } +} + +void +LibertyReader::makeBusPinPorts(LibertyCell *cell, + const LibertyGroup *bus_group, + LibertyPortGroupMap &port_group_map) +{ + for (const LibertyGroup *pin_group : bus_group->findSubgroups("pin")) { + for (const LibertyAttrValue *param : pin_group->params()) { + if (param->isString()) { + const std::string pin_name = param->stringValue(); + debugPrint(debug_, "liberty", 1, " bus pin port %s", pin_name.c_str()); + // Expand foo[3:0] port names. + PortNameBitIterator name_iter(cell, pin_name.c_str(), this, pin_group->line()); + while (name_iter.hasNext()) { + LibertyPort *pin_port = name_iter.next(); + if (pin_port) { + port_group_map[pin_group].push_back(pin_port); + } + else + libWarn(1232, pin_group, "pin %s not found.", pin_name.c_str()); + } + } + else + libWarn(1233, pin_group, "pin name is not a string."); + } + } +} + +void +LibertyReader::makeBundlePort(LibertyCell *cell, + const LibertyGroup *bundle_group, + LibertyPortGroupMap &port_group_map) +{ + const std::string &bundle_name = bundle_group->firstName(); + debugPrint(debug_, "liberty", 1, " bundle %s", bundle_name.c_str()); + + const LibertyComplexAttr *member_attr = bundle_group->findComplexAttr("members"); + ConcretePortSeq *members = new ConcretePortSeq; + for (const LibertyAttrValue *member_value : member_attr->values()) { + if (member_value->isString()) { + const char *member_name = member_value->stringValue().c_str(); + LibertyPort *member = cell->findLibertyPort(member_name); + if (member == nullptr) + member = makePort(cell, member_name); + members->push_back(member); + } + } + LibertyPort *bundle_port = builder_.makeBundlePort(cell, bundle_name.c_str(), + members); + port_group_map[bundle_group].push_back(bundle_port); + // Make ports for pin groups inside the bundle group. + makeBundlePinPorts(cell, bundle_group, port_group_map); +} + +void +LibertyReader::makeBundlePinPorts(LibertyCell *cell, + const LibertyGroup *bundle_group, + LibertyPortGroupMap &port_group_map) +{ + for (const LibertyGroup *pin_group : bundle_group->findSubgroups("pin")) { + for (LibertyAttrValue *param : pin_group->params()) { + if (param->isString()) { + const std::string pin_name = param->stringValue(); + debugPrint(debug_, "liberty", 1, " bundle pin port %s", pin_name.c_str()); + LibertyPort *pin_port = cell->findLibertyPort(pin_name.c_str()); + if (pin_port == nullptr) + pin_port = makePort(cell, pin_name.c_str()); + port_group_map[pin_group].push_back(pin_port); + } + else + libWarn(1234, pin_group, "pin name is not a string."); + } + } +} + +void +LibertyReader::makePgPinPort(LibertyCell *cell, + const LibertyGroup *pg_pin_group) +{ + const std::string &port_name = pg_pin_group->firstName(); + LibertyPort *pg_port = makePort(cell, port_name.c_str()); + + const std::string *type_name = pg_pin_group->findAttrString("pg_type"); + if (type_name) { + PwrGndType type = findPwrGndType(type_name->c_str()); + PortDirection *dir = PortDirection::unknown(); + switch (type) { + case PwrGndType::primary_ground: + case PwrGndType::backup_ground: + case PwrGndType::internal_ground: + dir = PortDirection::ground(); + break; + case PwrGndType::primary_power: + case PwrGndType::backup_power: + case PwrGndType::internal_power: + dir = PortDirection::power(); + break; + case PwrGndType::none: + libError(1291, pg_pin_group, "unknown pg_type."); + break; + default: + break; + } + pg_port->setPwrGndType(type); + pg_port->setDirection(dir); + } + + const std::string *voltate_name = pg_pin_group->findAttrString("voltage_name"); + if (voltate_name) + pg_port->setVoltageName(voltate_name->c_str()); +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::readPortAttributes(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + readCapacitance(ports, port_group); + readMinPulseWidth(cell, ports, port_group); + readPortAttrFloat("min_period", &LibertyPort::setMinPeriod, ports, + port_group, time_scale_); + readPortAttrBool("clock", &LibertyPort::setIsClock, ports, port_group); + readPortAttrFloat("fanout_load", &LibertyPort::setFanoutLoad, ports, + port_group, 1.0F); + readPortAttrFloatMinMax("max_fanout", &LibertyPort::setFanoutLimit, ports, + port_group, MinMax::max(), 1.0F); + readPortAttrFloatMinMax("min_fanout", &LibertyPort::setFanoutLimit, ports, + port_group, MinMax::min(), 1.0F); + readPulseClock(ports, port_group); + readPortAttrBool("clock_gate_clock_pin", &LibertyPort::setIsClockGateClock, + ports, port_group); + readPortAttrBool("clock_gate_enable_pin", &LibertyPort::setIsClockGateEnable, + ports, port_group); + readPortAttrBool("clock_gate_out_pin", &LibertyPort::setIsClockGateOut, + ports, port_group); + readPortAttrBool("is_pll_feedback_pin", &LibertyPort::setIsPllFeedback, + ports, port_group); + readSignalType(cell, ports, port_group); + readPortAttrBool("isolation_cell_data_pin", + &LibertyPort::setIsolationCellData, ports, port_group); + readPortAttrBool("isolation_cell_enable_pin", + &LibertyPort::setIsolationCellEnable, ports, port_group); + readPortAttrBool("level_shifter_data_pin", + &LibertyPort::setLevelShifterData, ports, port_group); + readPortAttrBool("switch_pin", &LibertyPort::setIsSwitch, ports, port_group); + readPortAttrString("related_ground_pin", &LibertyPort::setRelatedGroundPin, + ports, port_group); + readPortAttrString("related_power_pin", &LibertyPort::setRelatedPowerPin, + ports, port_group); + readDriverWaveform(ports, port_group); +} + +void +LibertyReader::readDriverWaveform(const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + for (const RiseFall *rf : RiseFall::range()) { + const char *attr_name = rf == RiseFall::rise() + ? "driver_waveform_rise" : "driver_waveform_fall"; + const std::string *name = port_group->findAttrString(attr_name); + if (name) { + DriverWaveform *waveform = library_->findDriverWaveform(name->c_str()); + if (waveform) { + for (LibertyPort *port : ports) + port->setDriverWaveform(waveform, rf); + } + } + } +} + +void +LibertyReader::readPortAttrString(const char *attr_name, + void (LibertyPort::*set_func)(const char *value), + const LibertyPortSeq &ports, + const LibertyGroup *group) +{ + const std::string *value = group->findAttrString(attr_name); + if (value) { + for (LibertyPort *port : ports) + (port->*set_func)(value->c_str()); + } +} + +void +LibertyReader::readPortAttrFloat(const char *attr_name, + void (LibertyPort::*set_func)(float value), + const LibertyPortSeq &ports, + const LibertyGroup *group, + float scale) +{ + float value; + bool exists; + group->findAttrFloat(attr_name, value, exists); + if (exists) { + for (LibertyPort *port : ports) + (port->*set_func)(value * scale); + } +} + +void +LibertyReader::readPortAttrBool(const char *attr_name, + void (LibertyPort::*set_func)(bool value), + const LibertyPortSeq &ports, + const LibertyGroup *group) +{ + const LibertySimpleAttr *attr = group->findSimpleAttr(attr_name); + if (attr) { + const LibertyAttrValue &attr_value = attr->value(); + if (attr_value.isString()) { + const std::string &value = attr_value.stringValue(); + if (stringEqual(value.c_str(), "true")) { + for (LibertyPort *port : ports) + (port->*set_func)(true); + } + else if (stringEqual(value.c_str(), "false")) { + for (LibertyPort *port : ports) + (port->*set_func)(false); + } + else + libWarn(1238, attr, "%s attribute is not boolean.", attr_name); + } + else + libWarn(1239, attr, "%s attribute is not boolean.", attr_name); + } +} + +void +LibertyReader::readPortAttrFloatMinMax(const char *attr_name, + void (LibertyPort::*set_func)(float value, + const MinMax *min_max), + const LibertyPortSeq &ports, + const LibertyGroup *group, + const MinMax *min_max, + float scale) +{ + float value; + bool exists; + group->findAttrFloat(attr_name, value, exists); + if (exists) { + for (LibertyPort *port : ports) + (port->*set_func)(value * scale, min_max); + } +} + +void +LibertyReader::readPulseClock(const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + const std::string *pulse_clk = port_group->findAttrString("pulse_clock"); + if (pulse_clk) { + const RiseFall *trigger = nullptr; + const RiseFall *sense = nullptr; + if (*pulse_clk == "rise_triggered_high_pulse") { + trigger = RiseFall::rise(); + sense = RiseFall::rise(); + } + else if (*pulse_clk == "rise_triggered_low_pulse") { + trigger = RiseFall::rise(); + sense = RiseFall::fall(); + } + else if (*pulse_clk == "fall_triggered_high_pulse") { + trigger = RiseFall::fall(); + sense = RiseFall::rise(); + } + else if (*pulse_clk == "fall_triggered_low_pulse") { + trigger = RiseFall::fall(); + sense = RiseFall::fall(); + } + else + libWarn(1242, port_group, "pulse_latch unknown pulse type."); + if (trigger) { + for (LibertyPort *port : ports) + port->setPulseClk(trigger, sense); + } + } +} + +void +LibertyReader::readSignalType(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + if (!dynamic_cast(cell)) + return; + const std::string *type = port_group->findAttrString("signal_type"); + if (!type) + return; + ScanSignalType signal_type = ScanSignalType::none; + if (*type == "test_scan_enable") + signal_type = ScanSignalType::enable; + else if (*type == "test_scan_enable_inverted") + signal_type = ScanSignalType::enable_inverted; + else if (*type == "test_scan_clock") + signal_type = ScanSignalType::clock; + else if (*type == "test_scan_clock_a") + signal_type = ScanSignalType::clock_a; + else if (*type == "test_scan_clock_b") + signal_type = ScanSignalType::clock_b; + else if (*type == "test_scan_in") + signal_type = ScanSignalType::input; + else if (*type == "test_scan_in_inverted") + signal_type = ScanSignalType::input_inverted; + else if (*type == "test_scan_out") + signal_type = ScanSignalType::output; + else if (*type == "test_scan_out_inverted") + signal_type = ScanSignalType::output_inverted; + else { + libWarn(1299, port_group, "unknown signal_type %s.", type->c_str()); + return; + } + for (LibertyPort *port : ports) + port->setScanSignalType(signal_type); +} + +void +LibertyReader::readPortDir(const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + const LibertySimpleAttr *dir_attr = port_group->findSimpleAttr("direction"); + // Note missing direction attribute is not an error because a bus group + // can have pin groups for the bus bits that have direcitons. + if (dir_attr) { + const std::string *dir = dir_attr->stringValue(); + if (dir) { + PortDirection *port_dir = PortDirection::unknown(); + if (*dir == "input") + port_dir = PortDirection::input(); + else if (*dir == "output") + port_dir = PortDirection::output(); + else if (*dir == "inout") + port_dir = PortDirection::bidirect(); + else if (*dir == "internal") + port_dir = PortDirection::internal(); + else + libWarn(1240, dir_attr, "unknown port direction."); + for (LibertyPort *port : ports) + port->setDirection(port_dir); + } + } +} + +void +LibertyReader::readCapacitance(const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + // capacitance + readPortAttrFloat("capacitance", &LibertyPort::setCapacitance, ports, + port_group, cap_scale_); + + for (LibertyPort *port : ports) { + // rise/fall_capacitance + for (const RiseFall *rf : RiseFall::range()) { + std::string attr_name = rf->to_string_long() + "_capacitance"; + float cap; + bool exists; + port_group->findAttrFloat(attr_name, cap, exists); + if (exists) { + for (const MinMax *min_max : MinMax::range()) + port->setCapacitance(rf, min_max, cap * cap_scale_); + } + + // rise/fall_capacitance_range(min_cap, max_cap); + attr_name = rf->to_string_long() + "_capacitance_range"; + const LibertyComplexAttrSeq &range_attrs = port_group->findComplexAttrs(attr_name); + if (!range_attrs.empty()) { + const LibertyComplexAttr *attr = range_attrs[0]; + const LibertyAttrValueSeq &values = attr->values(); + if (values.size() == 2) { + float cap_min = values[0]->floatValue(); + float cap_max = values[1]->floatValue(); + port->setCapacitance(rf, MinMax::min(), cap_min * cap_scale_); + port->setCapacitance(rf, MinMax::max(), cap_max * cap_scale_); + } + } + } + if (!(port->isBus() || port->isBundle())) + setPortCapDefault(port); + + for (const MinMax *min_max : MinMax::range()) { + // min/max_capacitance + std::string attr_name = min_max->to_string() + "_capacitance"; + float limit; + bool exists; + port_group->findAttrFloat(attr_name, limit, exists); + if (exists) + port->setCapacitanceLimit(limit * cap_scale_, min_max); + + // min/max_transition + attr_name = min_max->to_string() + "_transition"; + port_group->findAttrFloat(attr_name, limit, exists); + if (exists) + port->setSlewLimit(limit * time_scale_, min_max); + } + + // Default capacitance. + if (port->isBus() || port->isBundle()) { + // Do not clobber member port capacitances by setting the capacitance + // on a bus or bundle. + LibertyPortMemberIterator member_iter(port); + while (member_iter.hasNext()) { + LibertyPort *member = member_iter.next(); + setPortCapDefault(member); + } + } + else + setPortCapDefault(port); + } +} + +void +LibertyReader::setPortCapDefault(LibertyPort *port) +{ + for (const MinMax *min_max : MinMax::range()) { + for (const RiseFall *rf : RiseFall::range()) { + float cap; + bool exists; + port->capacitance(rf, min_max, cap, exists); + if (!exists) + port->setCapacitance(rf, min_max, defaultCap(port)); + } + } +} + +void +LibertyReader::readMinPulseWidth(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + for (LibertyPort *port : ports) { + TimingArcAttrsPtr timing_attrs = nullptr; + for (const RiseFall *rf : RiseFall::range()) { + const char *mpw_attr_name = rf == RiseFall::rise() + ? "min_pulse_width_high" + : "min_pulse_width_low"; + float mpw; + bool exists; + port_group->findAttrFloat(mpw_attr_name, mpw, exists); + if (exists) { + mpw *= time_scale_; + port->setMinPulseWidth(rf, mpw); + + // Make timing arcs for the port min_pulse_width_low/high attributes. + // This is redundant but makes sdf annotation consistent. + if (timing_attrs == nullptr) { + timing_attrs = std::make_shared(); + timing_attrs->setTimingType(TimingType::min_pulse_width); + } + TimingModel *check_model = + makeScalarCheckModel(cell, mpw, ScaleFactorType::min_pulse_width, rf); + timing_attrs->setModel(rf, check_model); + } + } + if (timing_attrs) + builder_.makeTimingArcs(cell, port, port, nullptr, timing_attrs, + port_group->line()); + } +} + +void +LibertyReader::makePortFuncs(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + const LibertySimpleAttr *func_attr = port_group->findSimpleAttr("function"); + if (func_attr) { + const std::string *func = func_attr->stringValue(); + if (func) { + FuncExpr *func_expr = parseFunc(func->c_str(), "function", cell, func_attr->line()); + for (LibertyPort *port : ports) { + port->setFunction(func_expr); + if (func_expr->checkSize(port)) { + libWarn(1195, func_attr->line(), + "port %s function size does not match port size.", + port->name()); + } + } + } + } + + const LibertySimpleAttr *tri_attr = port_group->findSimpleAttr("three_state"); + if (tri_attr) { + const std::string *tri_disable = tri_attr->stringValue(); + if (tri_disable) { + FuncExpr *tri_disable_expr = parseFunc(tri_disable->c_str(), + "three_state", cell, + tri_attr->line()); + FuncExpr *tri_enable_expr = tri_disable_expr->invert(); + for (LibertyPort *port : ports) { + port->setTristateEnable(tri_enable_expr); + if (port->direction() == PortDirection::output()) + port->setDirection(PortDirection::tristate()); + } + } + } +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::makeSequentials(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + makeSequentials(cell, cell_group, true, "ff", "clocked_on", "next_state"); + makeSequentials(cell, cell_group, true, "ff_bank", "clocked_on", "next_state"); + makeSequentials(cell, cell_group, false, "latch", "enable", "data_in"); + makeSequentials(cell, cell_group, false, "latch_bank", "enable", "data_in"); + + const LibertyGroup *lut_group = cell_group->findSubgroup("lut");; + if (lut_group) { + LibertyPort *out_port = nullptr; + LibertyPort *out_port_inv = nullptr; + size_t size; + makeSeqPorts(cell, lut_group, out_port, out_port_inv, size); + } +} + +void +LibertyReader::makeSequentials(LibertyCell *cell, + const LibertyGroup *cell_group, + bool is_register, + const char *seq_group_name, + const char *clk_attr_name, + const char *data_attr_name) +{ + for (const LibertyGroup *seq_group : cell_group->findSubgroups(seq_group_name)) { + LibertyPort *out_port = nullptr; + LibertyPort *out_port_inv = nullptr; + size_t size; + makeSeqPorts(cell, seq_group, out_port, out_port_inv, size); + FuncExpr *clk_expr = makeSeqFunc(cell, seq_group, clk_attr_name, size); + FuncExpr *data_expr = makeSeqFunc(cell, seq_group, data_attr_name, size); + FuncExpr *clr_expr = makeSeqFunc(cell, seq_group, "clear", size); + FuncExpr *preset_expr = makeSeqFunc(cell, seq_group, "preset", size); + + LogicValue clr_preset_var1 = LogicValue::unknown; + const LibertySimpleAttr *var1 = seq_group->findSimpleAttr("clear_preset_var1"); + if (var1) + clr_preset_var1 = getAttrLogicValue(var1); + + LogicValue clr_preset_var2 = LogicValue::unknown; + const LibertySimpleAttr *var2 = seq_group->findSimpleAttr("clear_preset_var2"); + if (var2) + clr_preset_var2 = getAttrLogicValue(var2); + + cell->makeSequential(size, is_register, clk_expr, data_expr, clr_expr, + preset_expr, clr_preset_var1, clr_preset_var2, + out_port, out_port_inv); + } +} + +FuncExpr * +LibertyReader::makeSeqFunc(LibertyCell *cell, + const LibertyGroup *seq_group, + const char *attr_name, + int size) +{ + FuncExpr *expr = nullptr; + const std::string *attr = seq_group->findAttrString(attr_name); + if (attr) { + expr = parseFunc(attr->c_str(), attr_name, cell, seq_group->line()); + if (expr && expr->checkSize(size)) { + libWarn(1196, seq_group, "%s %s bus width mismatch.", + seq_group->type().c_str(), attr_name); + delete expr; + expr = nullptr; + } + } + return expr; +} + +void +LibertyReader::makeSeqPorts(LibertyCell *cell, + const LibertyGroup *seq_group, + // Return values. + LibertyPort *&out_port, + LibertyPort *&out_port_inv, + size_t &size) +{ + const char *out_name, *out_inv_name; + bool has_size; + seqPortNames(seq_group, out_name, out_inv_name, has_size, size); + if (out_name) { + if (has_size) + out_port = makeBusPort(cell, out_name, size - 1, 0, nullptr); + else + out_port = makePort(cell, out_name); + out_port->setDirection(PortDirection::internal()); + } + if (out_inv_name) { + if (has_size) + out_port_inv = makeBusPort(cell, out_inv_name, size - 1, 0, nullptr); + else + out_port_inv = makePort(cell, out_inv_name); + out_port_inv->setDirection(PortDirection::internal()); + } +} + +void +LibertyReader::seqPortNames(const LibertyGroup *group, + const char *&out_name, + const char *&out_inv_name, + bool &has_size, + size_t &size) +{ + out_name = nullptr; + out_inv_name = nullptr; + if (group->params().size() == 1) { + // out_port + out_name = group->firstName(); + size = 1; + has_size = false; + } + if (group->params().size() == 2) { + // out_port, out_port_inv + out_name = group->firstName(); + out_inv_name = group->secondName(); + size = 1; + has_size = false; + } + else if (group->params().size() == 3) { + LibertyAttrValue *third_value = group->params()[2]; + if (third_value->isFloat()) { + // out_port, out_port_inv, bus_size + out_name = group->firstName(); + out_inv_name = group->secondName(); + size = static_cast(third_value->floatValue()); + has_size = true; + } + else { + // in_port (ignored), out_port, out_port_inv + out_name = group->secondName(); + out_inv_name = third_value->stringValue().c_str(); + has_size = true; + size = 1; + } + } +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::readCellAttributes(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + readCellAttrFloat("area", &LibertyCell::setArea, cell, cell_group, 1.0); + readCellAttrString("cell_footprint", &LibertyCell::setFootprint, cell, cell_group); + readCellAttrBool("dont_use", &LibertyCell::setDontUse, cell, cell_group); + readCellAttrBool("is_macro_cell", &LibertyCell::setIsMacro, cell, cell_group); + readCellAttrBool("is_pad", &LibertyCell::setIsPad, cell, cell_group); + readCellAttrBool("is_level_shifter", &LibertyCell::setIsLevelShifter, cell, cell_group); + readCellAttrBool("is_clock_cell", &LibertyCell::setIsClockCell, cell, cell_group); + readCellAttrBool("is_isolation_cell", &LibertyCell::setIsIsolationCell,cell,cell_group); + readCellAttrBool("always_on", &LibertyCell::setAlwaysOn,cell,cell_group); + readCellAttrBool("interface_timing", &LibertyCell::setInterfaceTiming,cell,cell_group); + readCellAttrFloat("cell_leakage_power", &LibertyCell::setLeakagePower, cell, + cell_group, power_scale_); + + readCellAttrBool("is_memory", &LibertyCell::setIsMemory, cell, cell_group); + if (cell_group->findSubgroup("memory")) + cell->setIsMemory(true); + + readCellAttrBool("pad_cell", &LibertyCell::setIsPad, cell, cell_group); + readLevelShifterType(cell, cell_group); + readSwitchCellType(cell, cell_group); + readCellAttrString("user_function_class", &LibertyCell::setUserFunctionClass, + cell, cell_group); + + readOcvDerateFactors(cell, cell_group); + readCellOcvDerateGroup(cell, cell_group); + readGroupAttrFloat("ocv_arc_depth", cell_group, + [cell](float v) { cell->setOcvArcDepth(v); }); + + const std::string *clock_gate_type = + cell_group->findAttrString("clock_gating_integrated_cell"); + if (clock_gate_type) { + if (stringBeginEqual(clock_gate_type->c_str(), "latch_posedge")) + cell->setClockGateType(ClockGateType::latch_posedge); + else if (stringBeginEqual(clock_gate_type->c_str(), "latch_negedge")) + cell->setClockGateType(ClockGateType::latch_negedge); + else + cell->setClockGateType(ClockGateType::other); + } + + readScaleFactors(cell, cell_group); + readLeagageGrouops(cell, cell_group); + readStatetable(cell, cell_group); + readModeDefs(cell, cell_group); +} + +void +LibertyReader::readScaleFactors(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + const std::string *scale_factors_name = cell_group->findAttrString("scaling_factors"); + if (scale_factors_name) { + ScaleFactors *scale_factors = library_->findScaleFactors(scale_factors_name->c_str()); + if (scale_factors) + cell->setScaleFactors(scale_factors); + else + libWarn(1230, cell_group, "scaling_factors %s not found.", + scale_factors_name->c_str()); + } +} + +void +LibertyReader::readCellAttrString(const char *attr_name, + void (LibertyCell::*set_func)(const char *value), + LibertyCell *cell, + const LibertyGroup *group) +{ + const std::string *value = group->findAttrString(attr_name); + if (value) + (cell->*set_func)(value->c_str()); +} + +void +LibertyReader::readCellAttrFloat(const char *attr_name, + void (LibertyCell::*set_func)(float value), + LibertyCell *cell, + const LibertyGroup *group, + float scale) +{ + float value; + bool exists; + group->findAttrFloat(attr_name, value, exists); + if (exists) + (cell->*set_func)(value * scale); +} + +void +LibertyReader::readCellAttrBool(const char *attr_name, + void (LibertyCell::*set_func)(bool value), + LibertyCell *cell, + const LibertyGroup *group) +{ + const LibertySimpleAttr *attr = group->findSimpleAttr(attr_name); + if (attr) { + const LibertyAttrValue &attr_value = attr->value(); + if (attr_value.isString()) { + const std::string &value = attr_value.stringValue(); + if (stringEqual(value.c_str(), "true")) + (cell->*set_func)(true); + else if (stringEqual(value.c_str(), "false")) + (cell->*set_func)(false); + else + libWarn(1279, attr, "%s attribute is not boolean.", attr_name); + } + else + libWarn(1280, attr, "%s attribute is not boolean.", attr_name); + } +} + +//////////////////////////////////////////////////////////////// + +void +LibertyReader::makeTimingArcs(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + for (const LibertyGroup *timing_group : port_group->findSubgroups("timing")) { + TimingArcAttrsPtr timing_attrs = std::make_shared(); + readTimingArcAttrs(cell, timing_group, timing_attrs); + makeTimingModels(cell, timing_group, timing_attrs); + + LibertyPort *related_output_port = findLibertyPort(cell, timing_group, + "related_output_pin"); + StdStringSeq related_port_names = findAttributStrings(timing_group, "related_pin"); + StdStringSeq related_bus_names=findAttributStrings(timing_group,"related_bus_pins"); + TimingType timing_type = timing_attrs->timingType(); + + for (LibertyPort *to_port : ports) { + if (timing_type == TimingType::combinational && + to_port->direction()->isInput()) + libWarn(1209, timing_group, "combinational timing to an input port."); + + if (related_port_names.size() || related_bus_names.size()) { + for (const std::string &from_port_name : related_port_names) { + debugPrint(debug_, "liberty", 2, " timing %s -> %s", + from_port_name.c_str(), to_port->name()); + makeTimingArcs(cell, from_port_name, to_port, related_output_port, true, + timing_attrs, timing_group->line()); + } + for (const std::string &from_port_name : related_bus_names) { + debugPrint(debug_, "liberty", 2, " timing %s -> %s", + from_port_name.c_str(), to_port->name()); + makeTimingArcs(cell, from_port_name, to_port, related_output_port, false, + timing_attrs, timing_group->line()); + } + } + else if (!(timing_type == TimingType::min_pulse_width + || timing_type == TimingType::minimum_period + || timing_type == TimingType::min_clock_tree_path + || timing_type == TimingType::max_clock_tree_path)) + libWarn(1243, timing_group, "timing group missing related_pin/related_bus_pin."); + else + makeTimingArcs(cell, to_port, related_output_port, + timing_attrs, timing_group->line()); + } + } +} + +void +LibertyReader::readTimingArcAttrs(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + readTimingSense(timing_group, timing_attrs); + readTimingType(timing_group, timing_attrs); + readTimingWhen(cell, timing_group, timing_attrs); + readTimingMode(timing_group, timing_attrs); + readGroupAttrFloat("ocv_arc_depth", timing_group, + [timing_attrs](float v) { timing_attrs->setOcvArcDepth(v); }); +} + +void +LibertyReader::readGroupAttrFloat(const char *attr_name, + const LibertyGroup *group, + const std::function &set_func, + float scale) +{ + float value; + bool exists; + group->findAttrFloat(attr_name, value, exists); + if (exists) + set_func(value * scale); +} + +void +LibertyReader::readTimingSense(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + const LibertySimpleAttr *sense_attr = timing_group->findSimpleAttr("timing_sense"); + if (sense_attr) { + const std::string *sense_name = sense_attr->stringValue(); + if (sense_name) { + if (*sense_name == "non_unate") + timing_attrs->setTimingSense(TimingSense::non_unate); + else if (*sense_name == "positive_unate") + timing_attrs->setTimingSense(TimingSense::positive_unate); + else if (*sense_name == "negative_unate") + timing_attrs->setTimingSense(TimingSense::negative_unate); + else + libWarn(1245, timing_group, "unknown timing_sense %s.", sense_name->c_str()); + } + } +} + +void +LibertyReader::readTimingType(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + TimingType type = TimingType::combinational; + const LibertySimpleAttr *type_attr = timing_group->findSimpleAttr("timing_type"); + if (type_attr) { + const std::string *type_name = type_attr->stringValue(); + if (type_name) { + type = findTimingType(type_name->c_str()); + if (type == TimingType::unknown) { + libWarn(1244, type_attr, "unknown timing_type %s.", type_name->c_str()); + type = TimingType::combinational; + } + } + } + timing_attrs->setTimingType(type); +} + +void +LibertyReader::readTimingWhen(const LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + const LibertySimpleAttr *when_attr = timing_group->findSimpleAttr("when"); + if (when_attr) { + const std::string *when = when_attr->stringValue(); + if (when) { + FuncExpr *when_expr = parseFunc(when->c_str(), "when", cell, when_attr->line()); + timing_attrs->setCond(when_expr); + } + } + + const LibertySimpleAttr *cond_attr = timing_group->findSimpleAttr("sdf_cond"); + if (cond_attr) { + const std::string *cond = cond_attr->stringValue(); + if (cond) + timing_attrs->setSdfCond(cond->c_str()); + } + cond_attr = timing_group->findSimpleAttr("sdf_cond_start"); + if (cond_attr) { + const std::string *cond = cond_attr->stringValue(); + if (cond) + timing_attrs->setSdfCondStart(cond->c_str()); + } + cond_attr = timing_group->findSimpleAttr("sdf_cond_end"); + if (cond_attr) { + const std::string *cond = cond_attr->stringValue(); + if (cond) + timing_attrs->setSdfCondEnd(cond->c_str()); + } +} + +void +LibertyReader::readTimingMode(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + const LibertyComplexAttrSeq &mode_attrs = timing_group->findComplexAttrs("mode"); + if (!mode_attrs.empty()) { + const LibertyComplexAttr *mode_attr = mode_attrs[0]; + const LibertyAttrValueSeq &mode_values = mode_attr->values(); + if (mode_values.size() == 2) { + LibertyAttrValue *value = mode_values[0]; + if (value->isString()) + timing_attrs->setModeName(value->stringValue()); + else + libWarn(1248, mode_attr, "mode name is not a string."); + + value = mode_values[1]; + if (value->isString()) + timing_attrs->setModeValue(value->stringValue()); + else + libWarn(1246, mode_attr, "mode value is not a string."); + } + else + libWarn(1249, mode_attr, "mode requirees 2 values."); + } +} + +void +LibertyReader::makeTimingModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + switch (cell->libertyLibrary()->delayModelType()) { + case DelayModelType::cmos_linear: + makeLinearModels(cell, timing_group, timing_attrs); + break; + case DelayModelType::table: + makeTableModels(cell, timing_group, timing_attrs); + break; + case DelayModelType::cmos_pwl: + case DelayModelType::cmos2: + case DelayModelType::polynomial: + case DelayModelType::dcm: + break; + } +} + +void +LibertyReader::makeLinearModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + LibertyLibrary *library = cell->libertyLibrary(); + for (const RiseFall *rf : RiseFall::range()) { + std::string intr_attr_name = "intrinsic_" + rf->to_string_long(); + float intr = 0.0; + bool intr_exists; + timing_group->findAttrFloat(intr_attr_name, intr, intr_exists); + if (intr_exists) + intr *= time_scale_; + else + library->defaultIntrinsic(rf, intr, intr_exists); + TimingModel *model = nullptr; + if (intr_exists) { + if (timingTypeIsCheck(timing_attrs->timingType())) + model = new CheckLinearModel(cell, intr); + else { + std::string res_attr_name = rf->to_string_long() + "_resistance"; + float res = 0.0; + bool res_exists; + timing_group->findAttrFloat(res_attr_name, res, res_exists); + if (res_exists) + res *= res_scale_; + else + library->defaultPinResistance(rf, PortDirection::output(), + res, res_exists); + model = new GateLinearModel(cell, intr, res); + } + timing_attrs->setModel(rf, model); + } + } +} + +void +LibertyReader::makeTableModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs) +{ + for (const RiseFall *rf : RiseFall::range()) { + std::string delay_attr_name = "cell_" + rf->to_string_long(); + TableModel *delay = readGateTableModel(timing_group, delay_attr_name.c_str(), rf, + TableTemplateType::delay, time_scale_, + ScaleFactorType::cell); + std::string transition_attr_name = rf->to_string_long() + "_transition"; + TableModel *transition = readGateTableModel(timing_group, + transition_attr_name.c_str(), + rf, TableTemplateType::delay, + time_scale_, + ScaleFactorType::transition); + if (delay || transition) { + std::string delay_sigma_attr_name = "ocv_sigma_cell_" + rf->to_string_long(); + TableModelsEarlyLate delay_sigmas = + readEarlyLateTableModels(timing_group, + delay_sigma_attr_name.c_str(), + rf, TableTemplateType::delay, + time_scale_, + ScaleFactorType::unknown); + + std::string slew_sigma_attr_name = "ocv_sigma_" + rf->to_string_long() + + "_transition"; + TableModelsEarlyLate slew_sigmas = + readEarlyLateTableModels(timing_group, + slew_sigma_attr_name.c_str(), + rf, TableTemplateType::delay, + time_scale_, + ScaleFactorType::unknown); + + ReceiverModelPtr receiver_model = readReceiverCapacitance(timing_group, rf); + OutputWaveforms *output_waveforms = readOutputWaveforms(timing_group, rf); + + timing_attrs->setModel(rf, new GateTableModel(cell, delay, + std::move(delay_sigmas), + transition, + std::move(slew_sigmas), + receiver_model, + output_waveforms)); + TimingType timing_type = timing_attrs->timingType(); + if (isGateTimingType(timing_type)) { + if (transition == nullptr) + libWarn(1210, timing_group, "missing %s_transition.", rf->name()); + if (delay == nullptr) + libWarn(1211, timing_group, "missing cell_%s.", rf->name()); + } + } + + std::string constraint_attr_name = rf->to_string_long() + "_constraint"; + ScaleFactorType scale_factor_type = + timingTypeScaleFactorType(timing_attrs->timingType()); + TableModel *constraint = readCheckTableModel(timing_group, + constraint_attr_name.c_str(), + rf, TableTemplateType::delay, + time_scale_, scale_factor_type); + if (constraint) { + std::string constraint_sigma_attr_name = "ocv_sigma_" + rf->to_string_long() + + "_constraint"; + TableModelsEarlyLate constraint_sigmas = + readEarlyLateTableModels(timing_group, + constraint_sigma_attr_name.c_str(), + rf, TableTemplateType::delay, + time_scale_, + ScaleFactorType::unknown); + timing_attrs->setModel(rf, new CheckTableModel(cell, constraint, + std::move(constraint_sigmas))); + } + } +} + +bool +LibertyReader::isGateTimingType(TimingType timing_type) +{ + return timing_type == TimingType::clear + || timing_type == TimingType::combinational + || timing_type == TimingType::combinational_fall + || timing_type == TimingType::combinational_rise + || timing_type == TimingType::falling_edge + || timing_type == TimingType::preset + || timing_type == TimingType::rising_edge + || timing_type == TimingType::three_state_disable + || timing_type == TimingType::three_state_disable_rise + || timing_type == TimingType::three_state_disable_fall + || timing_type == TimingType::three_state_enable + || timing_type == TimingType::three_state_enable_fall + || timing_type == TimingType::three_state_enable_rise; +} + +TableModel * +LibertyReader::readGateTableModel(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type) +{ + const LibertyGroup *table_group = timing_group->findSubgroup(table_group_name); + if (table_group) { + TableModel *model = readTableModel(table_group, rf, template_type, scale, + scale_factor_type); + if (model && !GateTableModel::checkAxes(model)) + libWarn(1251, table_group, "unsupported model axis."); + return model; + } + return nullptr; +} + +TableModel * +LibertyReader::readCheckTableModel(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type) +{ + const LibertyGroup *table_group = timing_group->findSubgroup(table_group_name); + if (table_group) { + TableModel *model = readTableModel(table_group, rf, template_type, scale, + scale_factor_type); + if (model && !CheckTableModel::checkAxes(model)) + libWarn(1252, table_group, "unsupported model axis."); + return model; + } + return nullptr; +} + +TableModelsEarlyLate +LibertyReader::readEarlyLateTableModels(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type) +{ + TableModelsEarlyLate models{}; + for (const LibertyGroup *table_group : timing_group->findSubgroups(table_group_name)) { + TableModel *model = readTableModel(table_group, rf, template_type, scale, + scale_factor_type); + const std::string *early_late = table_group->findAttrString("sigma_type"); + if (early_late == nullptr + || *early_late == "early_and_late") { + models[EarlyLate::early()->index()] = model; + models[EarlyLate::late()->index()] = model; + } + else if (*early_late == "early") + models[EarlyLate::early()->index()] = model; + else if (*early_late == "late") + models[EarlyLate::late()->index()] = model; + + //if (model && !GateTableModel::checkAxes(model)) + // libWarn(1182, table_group, "unsupported model axis."); + } + return models; +} + +ReceiverModelPtr +LibertyReader::readReceiverCapacitance(const LibertyGroup *timing_group, + const RiseFall *rf) +{ + ReceiverModelPtr receiver_model = nullptr; + readReceiverCapacitance(timing_group, "receiver_capacitance", 0, rf, + receiver_model); + readReceiverCapacitance(timing_group, "receiver_capacitance1", 0, rf, + receiver_model); + readReceiverCapacitance(timing_group, "receiver_capacitance2", 1, rf, + receiver_model); + return receiver_model; +} + +void +LibertyReader::readReceiverCapacitance(const LibertyGroup *timing_group, + const char *cap_group_name, + int index, + const RiseFall *rf, + ReceiverModelPtr &receiver_model) +{ + std::string cap_group_name1 = cap_group_name; + cap_group_name1 += "_" + rf->to_string_long(); + const LibertyGroup *cap_group = timing_group->findSubgroup(cap_group_name1); + if (cap_group) { + const LibertySimpleAttr *segment_attr = cap_group->findSimpleAttr("segment"); + if (segment_attr) { + // For receiver_capacitance groups with mulitiple segments this + // overrides the index passed in beginReceiverCapacitance1Rise/Fall. + int segment; + bool exists; + getAttrInt(segment_attr, segment, exists); + if (exists) + index = segment; + } + TableModel *model = readTableModel(cap_group, rf, TableTemplateType::delay, + cap_scale_, ScaleFactorType::pin_cap); + if (ReceiverModel::checkAxes(model)) { + if (receiver_model == nullptr) + receiver_model = std::make_shared(); + receiver_model->setCapacitanceModel(std::move(*model), index, rf); + } + else + libWarn(1219, cap_group, "unsupported model axis."); + delete model; + } +} + +OutputWaveforms * +LibertyReader::readOutputWaveforms(const LibertyGroup *timing_group, + const RiseFall *rf) +{ + const std::string current_group_name = "output_current_" + rf->to_string_long(); + const LibertyGroup *current_group = timing_group->findSubgroup(current_group_name); + if (current_group) { + OutputWaveformSeq output_currents; + for (const LibertyGroup *vector_group : current_group->findSubgroups("vector")) { + float ref_time; + bool ref_time_exists; + vector_group->findAttrFloat("reference_time", ref_time, ref_time_exists); + if (ref_time_exists) { + ref_time *= time_scale_; + TableModel *table = readTableModel(vector_group, rf, + TableTemplateType::output_current, + current_scale_, ScaleFactorType::unknown); + if (table) { + TableTemplate *tbl_template = table->tblTemplate(); + const TableAxis *slew_axis, *cap_axis; + // Canonicalize axis order. + if (tbl_template->axis1()->variable()==TableAxisVariable::input_net_transition){ + slew_axis = table->axis1(); + cap_axis = table->axis2(); + } + else { + slew_axis = table->axis2(); + cap_axis = table->axis1(); + } + + if (slew_axis->size() == 1 && cap_axis->size() == 1) { + // Convert 1x1xN Table (order 3) to 1D Table. + float slew = slew_axis->axisValue(0); + float cap = cap_axis->axisValue(0); + TablePtr table_ptr = table->table(); + FloatTable *values3 = table_ptr->values3(); + FloatSeq row = std::move((*values3)[0]); + values3->erase(values3->begin()); + Table *table1 = new Table(std::move(row), table->table()->axis3ptr()); + output_currents.emplace_back(slew, cap, table1, ref_time); + } + else + libWarn(1223, vector_group, + "vector index_1 and index_2 must have exactly one value."); + } + delete table; + } + else + libWarn(1224, vector_group, "vector reference_time not found."); + } + if (!output_currents.empty()) + return makeOutputWaveforms(current_group, output_currents, rf); + } + return nullptr; +} + +OutputWaveforms * +LibertyReader::makeOutputWaveforms(const LibertyGroup *current_group, + OutputWaveformSeq &output_currents, + const RiseFall *rf) +{ + std::set slew_set, cap_set; + FloatSeq slew_values; + FloatSeq cap_values; + for (const OutputWaveform &waveform : output_currents) { + float slew = waveform.slew(); + // Filter duplilcate slews and capacitances. + if (!slew_set.contains(slew)) { + slew_set.insert(slew); + slew_values.push_back(slew); + } + float cap = waveform.cap(); + if (!cap_set.contains(cap)) { + cap_set.insert(cap); + cap_values.push_back(cap); + } + } + sort(slew_values, std::less()); + sort(cap_values, std::less()); + size_t slew_size = slew_values.size(); + size_t cap_size = cap_values.size(); + TableAxisPtr slew_axis = + make_shared(TableAxisVariable::input_net_transition, + std::move(slew_values)); + TableAxisPtr cap_axis = + make_shared(TableAxisVariable::total_output_net_capacitance, + std::move(cap_values)); + FloatSeq ref_times(slew_size); + Table1Seq current_waveforms(slew_size * cap_size); + for (OutputWaveform &waveform : output_currents) { + size_t slew_index, cap_index; + bool slew_exists, cap_exists; + slew_axis->findAxisIndex(waveform.slew(), slew_index, slew_exists); + cap_axis->findAxisIndex(waveform.cap(), cap_index, cap_exists); + if (slew_exists && cap_exists) { + size_t index = slew_index * cap_axis->size() + cap_index; + current_waveforms[index] = waveform.releaseCurrents(); + ref_times[slew_index] = waveform.referenceTime(); + } + else + libWarn(1221, current_group, "output current waveform %.2e %.2e not found.", + waveform.slew(), + waveform.cap()); + } + Table ref_time_tbl(std::move(ref_times), slew_axis); + OutputWaveforms *output_current = new OutputWaveforms(slew_axis, cap_axis, rf, + current_waveforms, + std::move(ref_time_tbl)); + return output_current; +} + +TableModel * +LibertyReader::readTableModel(const LibertyGroup *table_group, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type) +{ + const char *template_name = table_group->firstName(); + if (library_ && template_name) { + TableTemplate *tbl_template = library_->findTableTemplate(template_name, + template_type); + if (tbl_template) { + TablePtr table = readTableModel(table_group, tbl_template, scale); + if (table) { + TableModel *table_model = new TableModel(table, tbl_template, + scale_factor_type, rf); + return table_model; + } + } + else + libWarn(1253, table_group, "table template %s not found.", template_name); + } + return nullptr; +} + +TablePtr +LibertyReader::readTableModel(const LibertyGroup *table_group, + const TableTemplate *tbl_template, + float scale) +{ + const LibertyComplexAttr *values_attr = table_group->findComplexAttr("values"); + if (values_attr) { + TableAxisPtr axis1 = makeTableAxis(table_group, "index_1", tbl_template->axis1ptr()); + TableAxisPtr axis2 = makeTableAxis(table_group, "index_2", tbl_template->axis2ptr()); + TableAxisPtr axis3 = makeTableAxis(table_group, "index_3", tbl_template->axis3ptr()); + if (axis1 && axis2 && axis3) { + // 3D table + FloatTable float_table = makeFloatTable(values_attr, table_group, + axis1->size() * axis2->size(), + axis3->size(), scale); + return make_shared(std::move(float_table), axis1, axis2, axis3); + } + else if (axis1 && axis2) { + FloatTable float_table = makeFloatTable(values_attr, table_group, + axis1->size(), axis2->size(), scale); + return make_shared
(std::move(float_table), axis1, axis2); + } + else if (axis1) { + FloatTable table = makeFloatTable(values_attr, table_group, 1, + axis1->size(), scale); + return make_shared
(std::move(table[0]), axis1); + } + else if (axis1 == nullptr && axis2 == nullptr && axis3 == nullptr) { + FloatTable table = makeFloatTable(values_attr, table_group, 1, 1, scale); + float value = table[0][0]; + return std::make_shared
(value); + } + } + else + libWarn(1257, table_group, "%s is missing values.", table_group->type().c_str()); + return nullptr; +} + +TableAxisPtr +LibertyReader::makeTableAxis(const LibertyGroup *table_group, + const char *index_attr_name, + TableAxisPtr template_axis) +{ + const LibertyComplexAttr *index_attr = table_group->findComplexAttr(index_attr_name); + if (index_attr) { + FloatSeq axis_values = readFloatSeq(index_attr, 1.0F); if (axis_values.empty()) - libWarn(1177, attr, "missing table index values."); + libWarn(1177, index_attr, "missing table index values."); else { // Check monotonicity of the values. float prev = axis_values[0]; for (size_t i = 1; i < axis_values.size(); i++) { float value = axis_values[i]; if (value <= prev) - libWarn(1178, attr, "non-increasing table index values."); + libWarn(1173, index_attr, "non-increasing table index values."); prev = value; } - axis_values_[index] = std::move(axis_values); + + TableAxisVariable axis_var = template_axis->variable(); + const Units *units = library_->units(); + float scale = tableVariableUnit(axis_var, units)->scale(); + scaleFloats(axis_values, scale); + return make_shared(axis_var, std::move(axis_values)); } } + return template_axis; } //////////////////////////////////////////////////////////////// void -LibertyReader::beginType(LibertyGroup *) +LibertyReader::makeTimingArcs(LibertyCell *cell, + const std::string &from_port_name, + LibertyPort *to_port, + LibertyPort *related_out_port, + bool one_to_one, + TimingArcAttrsPtr timing_attrs, + int timing_line) { - type_bit_from_exists_ = false; - type_bit_to_exists_ = false; -} - -void -LibertyReader::endType(LibertyGroup *group) -{ - const char *name = group->firstName(); - if (name) { - if (type_bit_from_exists_ && type_bit_to_exists_) { - if (cell_) - cell_->makeBusDcl(name, type_bit_from_, type_bit_to_); - else if (library_) - library_->makeBusDcl(name, type_bit_from_, type_bit_to_); + PortNameBitIterator from_port_iter(cell, from_port_name.c_str(), this, timing_line); + if (from_port_iter.size() == 1 && !to_port->hasMembers()) { + // one -> one + if (from_port_iter.hasNext()) { + LibertyPort *from_port = from_port_iter.next(); + if (from_port->direction()->isOutput()) + libWarn(1212, timing_line, "timing group from output port."); + builder_.makeTimingArcs(cell, from_port, to_port, related_out_port, + timing_attrs, timing_line); + } + } + else if (from_port_iter.size() > 1 && !to_port->hasMembers()) { + // bus -> one + while (from_port_iter.hasNext()) { + LibertyPort *from_port = from_port_iter.next(); + if (from_port->direction()->isOutput()) + libWarn(1213, timing_line, "timing group from output port."); + builder_.makeTimingArcs(cell, from_port, to_port, related_out_port, + timing_attrs, timing_line); + } + } + else if (from_port_iter.size() == 1 && to_port->hasMembers()) { + // one -> bus + if (from_port_iter.hasNext()) { + LibertyPort *from_port = from_port_iter.next(); + if (from_port->direction()->isOutput()) + libWarn(1214, timing_line, "timing group from output port."); + LibertyPortMemberIterator bit_iter(to_port); + while (bit_iter.hasNext()) { + LibertyPort *to_port_bit = bit_iter.next(); + builder_.makeTimingArcs(cell, from_port, to_port_bit, related_out_port, + timing_attrs, timing_line); + } + } + } + else { + // bus -> bus + if (one_to_one) { + int from_size = from_port_iter.size(); + int to_size = to_port->size(); + LibertyPortMemberIterator to_port_iter(to_port); + // warn about different sizes + if (from_size != to_size) + libWarn(1216, timing_line, + "timing port %s and related port %s are different sizes.", + from_port_name.c_str(), + to_port->name()); + // align to/from iterators for one-to-one mapping + while (from_size > to_size) { + from_size--; + from_port_iter.next(); + } + while (to_size > from_size) { + to_size--; + to_port_iter.next(); + } + // make timing arcs + while (from_port_iter.hasNext() && to_port_iter.hasNext()) { + LibertyPort *from_port_bit = from_port_iter.next(); + LibertyPort *to_port_bit = to_port_iter.next(); + if (from_port_bit->direction()->isOutput()) + libWarn(1215, timing_line, "timing group from output port."); + builder_.makeTimingArcs(cell, from_port_bit, to_port_bit, + related_out_port, timing_attrs, + timing_line); + } } else { - if (!type_bit_from_exists_) - libWarn(1179, group, "bus type %s missing bit_from.", name); - if (!type_bit_to_exists_) - libWarn(1180, group, "bus type %s missing bit_to.", name); - } - } - else - libWarn(1181, group, "type missing name."); -} - -void -LibertyReader::visitBitFrom(LibertyAttr *attr) -{ - getAttrInt(attr, type_bit_from_, type_bit_from_exists_); -} - -void -LibertyReader::visitBitTo(LibertyAttr *attr) -{ - getAttrInt(attr, type_bit_to_, type_bit_to_exists_); -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginScalingFactors(LibertyGroup *group) -{ - const char *name = group->firstName(); - if (name) { - save_scale_factors_ = scale_factors_; - scale_factors_ = library_->makeScaleFactors(name); - } - else - libWarn(1182, group, "scaling_factors do not have a name."); -} - -void -LibertyReader::endScalingFactors(LibertyGroup *) -{ - scale_factors_ = save_scale_factors_; -} - -void -LibertyReader::visitScaleFactorSuffix(LibertyAttr *attr) -{ - if (scale_factors_) { - ScaleFactorPvt pvt = ScaleFactorPvt::unknown; - ScaleFactorType type = ScaleFactorType::unknown; - const RiseFall *rf = nullptr; - // Parse the attribute name. - TokenParser parser(attr->name().c_str(), "_"); - if (parser.hasNext()) - parser.next(); - if (parser.hasNext()) { - const char *pvt_name = parser.next(); - pvt = findScaleFactorPvt(pvt_name); - } - if (parser.hasNext()) { - const char *type_name = parser.next(); - type = findScaleFactorType(type_name); - } - if (parser.hasNext()) { - const char *tr_name = parser.next(); - if (stringEq(tr_name, "rise")) - rf = RiseFall::rise(); - else if (stringEq(tr_name, "fall")) - rf = RiseFall::fall(); - } - if (pvt != ScaleFactorPvt::unknown - && type != ScaleFactorType::unknown - && rf) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - scale_factors_->setScale(type, pvt, rf, value); - } - } -} - -void -LibertyReader::visitScaleFactorPrefix(LibertyAttr *attr) -{ - if (scale_factors_) { - ScaleFactorPvt pvt = ScaleFactorPvt::unknown; - ScaleFactorType type = ScaleFactorType::unknown; - const RiseFall *rf = nullptr; - // Parse the attribute name. - TokenParser parser(attr->name().c_str(), "_"); - if (parser.hasNext()) - parser.next(); - if (parser.hasNext()) { - const char *pvt_name = parser.next(); - pvt = findScaleFactorPvt(pvt_name); - } - if (parser.hasNext()) { - const char *tr_name = parser.next(); - if (stringEq(tr_name, "rise")) - rf = RiseFall::rise(); - else if (stringEq(tr_name, "fall")) - rf = RiseFall::fall(); - } - if (parser.hasNext()) { - const char *type_name = parser.next(); - type = findScaleFactorType(type_name); - } - if (pvt != ScaleFactorPvt::unknown - && type != ScaleFactorType::unknown - && rf) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - scale_factors_->setScale(type, pvt, rf, value); - } - } -} - -void -LibertyReader::visitScaleFactorHiLow(LibertyAttr *attr) -{ - if (scale_factors_) { - ScaleFactorPvt pvt = ScaleFactorPvt::unknown; - ScaleFactorType type = ScaleFactorType::unknown; - const RiseFall *rf = nullptr; - const char *pvt_name = nullptr; - const char *type_name = nullptr; - const char *tr_name = nullptr; - // Parse the attribute name. - TokenParser parser(attr->name().c_str(), "_"); - if (parser.hasNext()) - parser.next(); - if (parser.hasNext()) { - pvt_name = parser.next(); - pvt = findScaleFactorPvt(pvt_name); - } - if (parser.hasNext()) { - type_name = parser.next(); - type = findScaleFactorType(type_name); - } - if (parser.hasNext()) { - tr_name = parser.next(); - if (stringEq(tr_name, "high")) - rf = RiseFall::rise(); - else if (stringEq(tr_name, "low")) - rf = RiseFall::fall(); - } - if (pvt != ScaleFactorPvt::unknown - && type != ScaleFactorType::unknown - && rf) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - scale_factors_->setScale(type, pvt, rf, value); - } - } -} - -void -LibertyReader::visitScaleFactor(LibertyAttr *attr) -{ - if (scale_factors_) { - ScaleFactorPvt pvt = ScaleFactorPvt::unknown; - ScaleFactorType type = ScaleFactorType::unknown; - const char *pvt_name = nullptr; - const char *type_name = nullptr; - // Parse the attribute name. - TokenParser parser(attr->name().c_str(), " "); - if (parser.hasNext()) - parser.next(); - if (parser.hasNext()) { - pvt_name = parser.next(); - pvt = findScaleFactorPvt(pvt_name); - } - if (parser.hasNext()) { - type_name = parser.next(); - type = findScaleFactorType(type_name); - } - if (pvt != ScaleFactorPvt::unknown - && type != ScaleFactorType::unknown) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - scale_factors_->setScale(type, pvt, value); - } - } -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginOpCond(LibertyGroup *group) -{ - if (library_) { - const char *name = group->firstName(); - if (name) - op_cond_ = library_->makeOperatingConditions(name); - else - libWarn(1183, group, "operating_conditions missing name."); - } -} - -void -LibertyReader::visitProc(LibertyAttr *attr) -{ - if (op_cond_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - op_cond_->setProcess(value); - } -} - -void -LibertyReader::visitVolt(LibertyAttr *attr) -{ - if (op_cond_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - op_cond_->setVoltage(value * volt_scale_); - } -} - -void -LibertyReader::visitTemp(LibertyAttr *attr) -{ - if (op_cond_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - op_cond_->setTemperature(value); - } -} - -void -LibertyReader::visitTreeType(LibertyAttr *attr) -{ - if (op_cond_) { - const char *tree_type = getAttrString(attr); - if (tree_type) { - WireloadTree wire_load_tree = stringWireloadTree(tree_type); - op_cond_->setWireloadTree(wire_load_tree); - } - } -} - -void -LibertyReader::endOpCond(LibertyGroup *) -{ - op_cond_ = nullptr; -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginWireload(LibertyGroup *group) -{ - if (library_) { - const char *name = group->firstName(); - if (name) - wireload_ = library_->makeWireload(name); - } - else - libWarn(1184, group, "wire_load missing name."); -} - -void -LibertyReader::endWireload(LibertyGroup *) -{ - wireload_ = nullptr; -} - -void -LibertyReader::visitResistance(LibertyAttr *attr) -{ - if (wireload_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - wireload_->setResistance(value * res_scale_); - } -} - -void -LibertyReader::visitSlope(LibertyAttr *attr) -{ - if (wireload_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - wireload_->setSlope(value); - } -} - -void -LibertyReader::visitFanoutLength(LibertyAttr *attr) -{ - if (wireload_) { - float fanout, length; - bool exists; - getAttrFloat2(attr, fanout, length, exists); - if (exists) - wireload_->addFanoutLength(fanout, length); - else - libWarn(1185, attr, "fanout_length is missing length and fanout."); - } -} - -void -LibertyReader::beginWireloadSelection(LibertyGroup *group) -{ - if (library_) { - const char *name = group->firstName(); - if (name) - wireload_selection_ = library_->makeWireloadSelection(name); - } - else - libWarn(1186, group, "wire_load_selection missing name."); -} - -void -LibertyReader::endWireloadSelection(LibertyGroup *) -{ - wireload_selection_ = nullptr; -} - -void -LibertyReader::visitWireloadFromArea(LibertyAttr *attr) -{ - if (wireload_selection_) { - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *values = attr->values(); - if (values->size() == 3) { - LibertyAttrValue *value = (*values)[0]; - if (value->isFloat()) { - float min_area = value->floatValue(); - value = (*values)[1]; - if (value->isFloat()) { - float max_area = value->floatValue(); - - value = (*values)[2]; - if (value->isString()) { - const std::string &wireload_name = value->stringValue(); - const Wireload *wireload = - library_->findWireload(wireload_name.c_str()); - if (wireload) - wireload_selection_->addWireloadFromArea(min_area, max_area, - wireload); - else - libWarn(1187, attr, "wireload %s not found.", wireload_name.c_str()); - } - else - libWarn(1188, attr, - "wire_load_from_area wireload name not a string."); - } - else - libWarn(1189, attr, "wire_load_from_area min not a float."); + // cross product + while (from_port_iter.hasNext()) { + LibertyPort *from_port_bit = from_port_iter.next(); + LibertyPortMemberIterator to_port_iter(to_port); + while (to_port_iter.hasNext()) { + LibertyPort *to_port_bit = to_port_iter.next(); + builder_.makeTimingArcs(cell, from_port_bit, to_port_bit, + related_out_port, timing_attrs, + timing_line); } - else - libWarn(1190, attr, "wire_load_from_area max not a float."); } - else - libWarn(1191, attr, "wire_load_from_area missing parameters."); } - else - libWarn(1192, attr, "wire_load_from_area missing parameters."); } } +void +LibertyReader::makeTimingArcs(LibertyCell *cell, + LibertyPort *to_port, + LibertyPort *related_out_port, + TimingArcAttrsPtr timing_attrs, + int timing_line) +{ + if (to_port->hasMembers()) { + LibertyPortMemberIterator bit_iter(to_port); + while (bit_iter.hasNext()) { + LibertyPort *to_port_bit = bit_iter.next(); + builder_.makeTimingArcs(cell, nullptr, to_port_bit, + related_out_port, timing_attrs, + timing_line); + } + } + else + builder_.makeTimingArcs(cell, nullptr, to_port, + related_out_port, timing_attrs, + timing_line); +} + //////////////////////////////////////////////////////////////// void -LibertyReader::beginCell(LibertyGroup *group) +LibertyReader::readLeagageGrouops(LibertyCell *cell, + const LibertyGroup *cell_group) { - const char *name = group->firstName(); - if (name) { - debugPrint(debug_, "liberty", 1, "cell %s", name); - if (library_) { - cell_ = builder_.makeCell(library_, name, filename_); - in_bus_ = false; - in_bundle_ = false; - } - } - else - libWarn(1193, group, "cell missing name."); -} - -void -LibertyReader::endCell(LibertyGroup *group) -{ - if (cell_) { - // Sequentials and leakage powers reference expressions outside of port definitions - // so they do not require LibertyFunc's. - makeCellSequentials(); - makeStatetable(); - // Parse functions defined inside of port groups that reference other ports - // and replace the references with the parsed expressions. - parseCellFuncs(); - makeLeakagePowers(); - finishPortGroups(); - - if (ocv_derate_name_) { - OcvDerate *derate = cell_->findOcvDerate(ocv_derate_name_); - if (derate == nullptr) - derate = library_->findOcvDerate(ocv_derate_name_); - if (derate) - cell_->setOcvDerate(derate); - else - libWarn(1194, group, "cell %s ocv_derate_group %s not found.", - cell_->name(), ocv_derate_name_); - stringDelete(ocv_derate_name_); - ocv_derate_name_ = nullptr; - } - cell_->finish(infer_latches_, report_, debug_); - cell_ = nullptr; - } -} - -void -LibertyReader::finishPortGroups() -{ - for (PortGroup *port_group : cell_port_groups_) { - int line = port_group->line(); - for (LibertyPort *port : *port_group->ports()) { - checkPort(port, line); - makeMinPulseWidthArcs(port, line); - } - makeTimingArcs(port_group); - makeInternalPowers(port_group); - delete port_group; - } - cell_port_groups_.clear(); -} - -void -LibertyReader::checkPort(LibertyPort *port, - int line) -{ - FuncExpr *func_expr = port->function(); - if (func_expr) { - if (func_expr->checkSize(port)) { - libWarn(1195, line, "port %s function size does not match port size.", - port->name()); - } - } - if (port->tristateEnable() - && port->direction() == PortDirection::output()) - port->setDirection(PortDirection::tristate()); -} - -// Make timing arcs for the port min_pulse_width_low/high attributes. -// This is redundant but makes sdf annotation consistent. -void -LibertyReader::makeMinPulseWidthArcs(LibertyPort *port, - int line) -{ - TimingArcAttrsPtr attrs = nullptr; - for (auto hi_low : RiseFall::range()) { - float min_width; + for (const LibertyGroup *leak_group : cell_group->findSubgroups("leakage_power")) { + FuncExpr *when = readFuncExpr(cell, leak_group, "when"); + float power; bool exists; - port->minPulseWidth(hi_low, min_width, exists); + leak_group->findAttrFloat("value", power, exists); if (exists) { - if (attrs == nullptr) { - attrs = make_shared(); - attrs->setTimingType(TimingType::min_pulse_width); + LibertyPort *related_pg_port = findLibertyPort(cell, leak_group, "related_pg_pin"); + cell->makeLeakagePower(related_pg_port, when, power * power_scale_); + } + else + libWarn(1307, leak_group, "leakage_power missing value."); + } +} + +void +LibertyReader::readInternalPowerGroups(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group) +{ + for (LibertyPort *port : ports) { + for (const LibertyGroup *ipwr_group : port_group->findSubgroups("internal_power")) { + LibertyPortSeq related_ports = findLibertyPorts(cell, ipwr_group, "related_pin"); + LibertyPort *related_pg_port = findLibertyPort(cell, ipwr_group, "related_pg_pin"); + std::shared_ptr when; + FuncExpr *when1 = readFuncExpr(cell, ipwr_group, "when"); + if (when1) + when = std::shared_ptr(when1); + InternalPowerModels models; + // rise/fall_power group + for (const RiseFall *rf : RiseFall::range()) { + std::string pwr_attr_name = rf->to_string_long() + "_power"; + const LibertyGroup *pwr_group = ipwr_group->findSubgroup(pwr_attr_name); + if (pwr_group) { + TableModel *model = readTableModel(pwr_group, rf, TableTemplateType::power, + energyScale(), + ScaleFactorType::internal_power); + models[rf->index()] = std::make_shared(model); + } + } + // power group (rise/fall power are the same) + const LibertyGroup *pwr_group = ipwr_group->findSubgroup("power"); + if (pwr_group) { + TableModel *model = readTableModel(pwr_group, RiseFall::rise(), + TableTemplateType::power, + energyScale(), + ScaleFactorType::internal_power); + auto pwr_model = std::make_shared(model); + for (const RiseFall *rf : RiseFall::range()) + models[rf->index()] = pwr_model; + } + if (related_ports.empty()) + cell->makeInternalPower(port, nullptr, related_pg_port, when, models); + else { + for (LibertyPort *related_port : related_ports) + cell->makeInternalPower(port, related_port, related_pg_port, when, models); } - // rise/fall_constraint model is on the leading edge of the pulse. - const RiseFall *model_rf = hi_low; - TimingModel *check_model = - makeScalarCheckModel(min_width, ScaleFactorType::min_pulse_width, model_rf); - attrs->setModel(model_rf, check_model); } } - if (attrs) - builder_.makeTimingArcs(cell_, port, port, nullptr, attrs, line); } +//////////////////////////////////////////////////////////////// + +FuncExpr * +LibertyReader::readFuncExpr(LibertyCell *cell, + const LibertyGroup *group, + const char *attr_name) +{ + const std::string *attr = group->findAttrString(attr_name); + if (attr) + return parseFunc(attr->c_str(), attr_name, cell, group->line()); + else + return nullptr; +} + +LibertyPort * +LibertyReader::findLibertyPort(LibertyCell *cell, + const LibertyGroup *group, + const char *port_name_attr) +{ + const LibertySimpleAttr *attr = group->findSimpleAttr(port_name_attr); + if (attr) { + const std::string *port_name = attr->stringValue(); + if (port_name) { + LibertyPort *port = cell->findLibertyPort(port_name->c_str()); + if (port) + return port; + else + libWarn(1290, attr, "port %s not found.", port_name->c_str()); + } + } + return nullptr; +} + +StdStringSeq +LibertyReader::findAttributStrings(const LibertyGroup *group, + const char *name_attr) +{ + const LibertySimpleAttr *attr = group->findSimpleAttr(name_attr); + if (attr) { + const std::string *strings = attr->stringValue(); + if (strings) { + return parseTokens(*strings, ' '); + } + } + return StdStringSeq(); +} + +LibertyPortSeq +LibertyReader::findLibertyPorts(LibertyCell *cell, + const LibertyGroup *group, + const char *port_name_attr) +{ + LibertyPortSeq ports; + StdStringSeq port_names = findAttributStrings(group, port_name_attr); + for (const std::string &port_name : port_names) { + LibertyPort *port = findPort(cell, port_name.c_str()); + if (port) + ports.push_back(port); + else + libWarn(1306, group, "port %s not found.", port_name.c_str()); + } + return ports; +} + +//////////////////////////////////////////////////////////////// + TimingModel * -LibertyReader::makeScalarCheckModel(float value, +LibertyReader::makeScalarCheckModel(LibertyCell *cell, + float value, ScaleFactorType scale_factor_type, const RiseFall *rf) { - TablePtr table = make_shared
(value); + TablePtr table = std::make_shared
(value); TableTemplate *tbl_template = library_->findTableTemplate("scalar", TableTemplateType::delay); TableModel *table_model = new TableModel(table, tbl_template, scale_factor_type, rf); - CheckTableModel *check_model = new CheckTableModel(cell_, table_model, nullptr); + TableModelsEarlyLate sigmas{}; + CheckTableModel *check_model = new CheckTableModel(cell, table_model, + std::move(sigmas)); return check_model; } -void -LibertyReader::makeTimingArcs(PortGroup *port_group) -{ - for (TimingGroup *timing : port_group->timingGroups()) { - timing->makeTimingModels(cell_, this); - - for (LibertyPort *port : *port_group->ports()) - makeTimingArcs(port, timing); - } -} - -void -LibertyReader::makeInternalPowers(PortGroup *port_group) -{ - for (InternalPowerGroup *power_group : port_group->internalPowerGroups()) { - for (LibertyPort *port : *port_group->ports()) - makeInternalPowers(port, power_group); - } -} - -void -LibertyReader::makeCellSequentials() -{ - for (SequentialGroup *seq : cell_sequentials_) { - makeCellSequential(seq); - delete seq; - } - cell_sequentials_.clear(); -} - -void -LibertyReader::makeCellSequential(SequentialGroup *seq) -{ - int line = seq->line(); - int size = seq->size(); - bool is_register = seq->isRegister(); - bool is_bank = seq->isBank(); - const char *type = is_register - ? (is_bank ? "ff_bank" : "ff") - : (is_bank ? "latch_bank" : "latch"); - const char *clk = seq->clock(); - FuncExpr *clk_expr = nullptr; - if (clk) { - const char *clk_attr = is_register ? "clocked_on" : "enable"; - clk_expr = parseFunc(clk, clk_attr, line); - if (clk_expr && clk_expr->checkSize(size)) { - libWarn(1196, line, "%s %s bus width mismatch.", type, clk_attr); - delete clk_expr; - clk_expr = nullptr; - } - } - const char *data = seq->data(); - FuncExpr *data_expr = nullptr; - if (data) { - const char *data_attr = is_register ? "next_state" : "data_in"; - data_expr = parseFunc(data, data_attr, line); - if (data_expr && data_expr->checkSize(size)) { - libWarn(1197, line, "%s %s bus width mismatch.", type, data_attr); - delete data_expr; - data_expr = nullptr; - } - } - const char *clr = seq->clear(); - FuncExpr *clr_expr = nullptr; - if (clr) { - clr_expr = parseFunc(clr, "clear", line); - if (clr_expr && clr_expr->checkSize(size)) { - libWarn(1198, line, "%s %s bus width mismatch.", type, "clear"); - delete clr_expr; - clr_expr = nullptr; - } - } - const char *preset = seq->preset(); - FuncExpr *preset_expr = nullptr; - if (preset) { - preset_expr = parseFunc(preset, "preset", line); - if (preset_expr && preset_expr->checkSize(size)) { - libWarn(1199, line, "%s %s bus width mismatch.", type, "preset"); - delete preset_expr; - preset_expr = nullptr; - } - } - cell_->makeSequential(size, is_register, clk_expr, data_expr, clr_expr, - preset_expr, seq->clrPresetVar1(), - seq->clrPresetVar2(), - seq->outPort(), seq->outInvPort()); - if (!is_register) - checkLatchEnableSense(clk_expr, line); - - // The expressions used in the sequentials are copied by bitSubExpr. - delete clk_expr; - delete data_expr; - delete clr_expr; - delete preset_expr; -} - void LibertyReader::checkLatchEnableSense(FuncExpr *enable_func, int line) @@ -2202,1029 +2814,194 @@ LibertyReader::checkLatchEnableSense(FuncExpr *enable_func, //////////////////////////////////////////////////////////////// void -LibertyReader::makeStatetable() +LibertyReader::readNormalizedDriverWaveform(const LibertyGroup *library_group) { - if (statetable_) { - LibertyPortSeq input_ports; - for (const string &input : statetable_->inputPorts()) { - LibertyPort *port = cell_->findLibertyPort(input.c_str()); - if (port) - input_ports.push_back(port); - else - libWarn(1298, statetable_->line(), "statetable input port %s not found.", - input.c_str()); + for (const LibertyGroup *waveform_group : + library_group->findSubgroups("normalized_driver_waveform")) { + const char *template_name = waveform_group->firstName(); + if (template_name) { + TableTemplate *tbl_template = library_->findTableTemplate(template_name, + TableTemplateType::delay); + if (!tbl_template) { + libWarn(1256, waveform_group, "table template %s not found.", template_name); + continue; + } + TablePtr table = readTableModel(waveform_group, tbl_template, time_scale_); + if (!table) + continue; + if (table->axis1()->variable() != TableAxisVariable::input_net_transition) { + libWarn(1265, waveform_group, + "normalized_driver_waveform variable_1 must be input_net_transition"); + continue; + } + if (table->axis2()->variable() != TableAxisVariable::normalized_voltage) { + libWarn(1225, waveform_group, + "normalized_driver_waveform variable_2 must be normalized_voltage"); + continue; + } + std::string driver_waveform_name; + const std::string *name_attr = waveform_group->findAttrString("driver_waveform_name"); + if (name_attr) + driver_waveform_name = *name_attr; + library_->makeDriverWaveform(driver_waveform_name, table); } - LibertyPortSeq internal_ports; - for (const string &internal : statetable_->internalPorts()) { - LibertyPort *port = cell_->findLibertyPort(internal.c_str()); - if (port == nullptr) - port = makePort(cell_, internal.c_str()); - internal_ports.push_back(port); - } - cell_->makeStatetable(input_ports, internal_ports, statetable_->table()); - delete statetable_; - statetable_ = nullptr; + else + libWarn(1227, waveform_group, "normalized_driver_waveform missing template."); } } //////////////////////////////////////////////////////////////// void -LibertyReader::makeLeakagePowers() +LibertyReader::readLevelShifterType(LibertyCell *cell, + const LibertyGroup *cell_group) { - for (LeakagePowerGroup *power_group : leakage_powers_) { - LibertyPort *related_pg_pin = - cell_->findLibertyPort(power_group->relatedPgPin().c_str()); - cell_->makeLeakagePower(related_pg_pin, power_group->when(), power_group->power()); - delete power_group; + const std::string *level_shifter_type = cell_group->findAttrString("level_shifter_type"); + if (level_shifter_type) { + if (*level_shifter_type == "HL") + cell->setLevelShifterType(LevelShifterType::HL); + else if (*level_shifter_type == "LH") + cell->setLevelShifterType(LevelShifterType::LH); + else if (*level_shifter_type == "HL_LH") + cell->setLevelShifterType(LevelShifterType::HL_LH); + else + libWarn(1228, cell_group, "level_shifter_type must be HL, LH, or HL_LH"); } - leakage_powers_.clear(); -} - -// Record a reference to a function that will be parsed at the end of -// the cell definition when all of the ports are defined. -void -LibertyReader::makeLibertyFunc(const char *expr, - LibertySetFunc set_func, - bool invert, - const char *attr_name, - LibertyStmt *stmt) -{ - LibertyFunc *func = new LibertyFunc(expr, set_func, - invert, attr_name, stmt->line()); - cell_funcs_.push_back(func); } void -LibertyReader::parseCellFuncs() +LibertyReader::readSwitchCellType(LibertyCell *cell, + const LibertyGroup *cell_group) { - for (LibertyFunc *func : cell_funcs_) { - FuncExpr *expr = parseFunc(func->expr(), func->attrName(), func->line()); - if (func->invert() && expr) - expr = expr->invert(); - if (expr) - func->setFunc()(expr); - delete func; + const std::string *switch_cell_type = cell_group->findAttrString("switch_cell_type"); + if (switch_cell_type) { + if (*switch_cell_type == "coarse_grain") + cell->setSwitchCellType(SwitchCellType::coarse_grain); + else if (*switch_cell_type == "fine_grain") + cell->setSwitchCellType(SwitchCellType::fine_grain); + else + libWarn(1229, cell_group, "switch_cell_type must be coarse_grain or fine_grain"); } - cell_funcs_.clear(); } void -LibertyReader::beginScaledCell(LibertyGroup *group) +LibertyReader::readCellOcvDerateGroup(LibertyCell *cell, + const LibertyGroup *cell_group) { - const char *name = group->firstName(); - if (name) { - scaled_cell_owner_ = library_->findLibertyCell(name); - if (scaled_cell_owner_) { - const char *op_cond_name = group->secondName(); - if (op_cond_name) { - op_cond_ = library_->findOperatingConditions(op_cond_name); - if (op_cond_) { - debugPrint(debug_, "liberty", 1, "scaled cell %s %s", - name, op_cond_name); - cell_ = library_->makeScaledCell(name, filename_); + const std::string *derate_name = cell_group->findAttrString("ocv_derate_group"); + if (derate_name) { + OcvDerate *derate = cell->findOcvDerate(derate_name->c_str()); + if (derate == nullptr) + derate = library_->findOcvDerate(derate_name->c_str()); + if (derate) + cell->setOcvDerate(derate); + else + libWarn(1237, cell_group, "OCV derate group named %s not found.", + derate_name->c_str()); + } +} + +void +LibertyReader::readStatetable(LibertyCell *cell, + const LibertyGroup *cell_group) +{ + for (const LibertyGroup *statetable_group : cell_group->findSubgroups("statetable")) { + const char *input_ports_arg = statetable_group->firstName(); + const char *internal_ports_arg = statetable_group->params().size() >= 2 + ? statetable_group->secondName() : nullptr; + StdStringSeq input_ports; + if (input_ports_arg) + input_ports = parseTokens(input_ports_arg, ' '); + StdStringSeq internal_ports; + if (internal_ports_arg) + internal_ports = parseTokens(internal_ports_arg, ' '); + + const LibertySimpleAttr *table_attr = statetable_group->findSimpleAttr("table"); + if (table_attr) { + const std::string *table_str = table_attr->stringValue(); + StdStringSeq table_rows = parseTokens(table_str->c_str(), ','); + size_t input_count = input_ports.size(); + size_t internal_count = internal_ports.size(); + StatetableRows table; + for (const std::string &row : table_rows) { + const StdStringSeq row_groups = parseTokens(row, ':'); + if (row_groups.size() != 3) { + libWarn(1300, table_attr, "table row must have 3 groups separated by ':'."); + break; } + StdStringSeq inputs = parseTokens(row_groups[0], ' '); + if (inputs.size() != input_count) { + libWarn(1301,table_attr,"table row has %zu input values but %zu are required.", + inputs.size(), input_count); + break; + } + StdStringSeq currents = parseTokens(row_groups[1], ' '); + if (currents.size() != internal_count) { + libWarn(1302,table_attr, + "table row has %zu current values but %zu are required.", + currents.size(), internal_count); + break; + } + StdStringSeq nexts = parseTokens(row_groups[2], ' '); + if (nexts.size() != internal_count) { + libWarn(1303, table_attr, "table row has %zu next values but %zu are required.", + nexts.size(), internal_count); + break; + } + + StateInputValues input_values = parseStateInputValues(inputs, table_attr); + StateInternalValues current_values=parseStateInternalValues(currents,table_attr); + StateInternalValues next_values = parseStateInternalValues(nexts, table_attr); + table.emplace_back(input_values, current_values, next_values); + } + + LibertyPortSeq input_port_ptrs; + for (const std::string &input : input_ports) { + LibertyPort *port = cell->findLibertyPort(input.c_str()); + if (port) + input_port_ptrs.push_back(port); else - libWarn(1202, group, "operating conditions %s not found.", op_cond_name); + libWarn(1298, statetable_group, "statetable input port %s not found.", + input.c_str()); } - else - libWarn(1203, group, "scaled_cell missing operating condition."); - } - else - libWarn(1204, group, "scaled_cell cell %s has not been defined.", name); - } - else - libWarn(1205, group, "scaled_cell missing name."); -} - -void -LibertyReader::endScaledCell(LibertyGroup *group) -{ - if (cell_) { - makeCellSequentials(); - parseCellFuncs(); - finishPortGroups(); - cell_->finish(infer_latches_, report_, debug_); - checkScaledCell(group); - // Add scaled cell AFTER ports and timing arcs are defined. - scaled_cell_owner_->addScaledCell(op_cond_, cell_); - cell_ = nullptr; - scaled_cell_owner_ = nullptr; - op_cond_ = nullptr; - } -} - -// Minimal check that is not very specific about where the discrepancies are. -void -LibertyReader::checkScaledCell(LibertyGroup *group) -{ - if (equivCellPorts(cell_, scaled_cell_owner_)) { - if (!equivCellPorts(cell_, scaled_cell_owner_)) - libWarn(1206, group, "scaled_cell %s, %s ports do not match cell ports", - cell_->name(), - op_cond_->name()); - if (!equivCellFuncs(cell_, scaled_cell_owner_)) - libWarn(1206, group, - "scaled_cell %s, %s port functions do not match cell port functions.", - cell_->name(), - op_cond_->name()); - } - else - libWarn(1207, group, "scaled_cell ports do not match cell ports."); - if (!equivCellTimingArcSets(cell_, scaled_cell_owner_)) - libWarn(1208, group, "scaled_cell %s, %s timing does not match cell timing.", - cell_->name(), - op_cond_->name()); -} - -void -LibertyReader::makeTimingArcs(LibertyPort *to_port, - TimingGroup *timing) -{ - LibertyPort *related_out_port = nullptr; - const char *related_out_port_name = timing->relatedOutputPortName(); - if (related_out_port_name) - related_out_port = findPort(related_out_port_name); - int line = timing->line(); - PortDirection *to_port_dir = to_port->direction(); - // Checks should be more comprehensive (timing checks on inputs, etc). - TimingType type = timing->attrs()->timingType(); - if (type == TimingType::combinational && - to_port_dir->isInput()) - libWarn(1209, line, "combinational timing to an input port."); - if (timing->relatedPortNames()) { - for (const char *from_port_name : *timing->relatedPortNames()) { - PortNameBitIterator from_port_iter(cell_, from_port_name, this, line); - if (from_port_iter.hasNext()) { - debugPrint(debug_, "liberty", 2, " timing %s -> %s", - from_port_name, to_port->name()); - makeTimingArcs(from_port_name, from_port_iter, to_port, - related_out_port, timing); + LibertyPortSeq internal_port_ptrs; + for (const std::string &internal : internal_ports) { + LibertyPort *port = cell->findLibertyPort(internal.c_str()); + if (port == nullptr) + port = makePort(cell, internal.c_str()); + internal_port_ptrs.push_back(port); } + cell->makeStatetable(input_port_ptrs, internal_port_ptrs, table); } } - else - makeTimingArcs(to_port, related_out_port, timing); -} - -void -TimingGroup::makeTimingModels(LibertyCell *cell, - LibertyReader *visitor) -{ - switch (cell->libertyLibrary()->delayModelType()) { - case DelayModelType::cmos_linear: - makeLinearModels(cell); - break; - case DelayModelType::table: - makeTableModels(cell, visitor); - break; - case DelayModelType::cmos_pwl: - case DelayModelType::cmos2: - case DelayModelType::polynomial: - case DelayModelType::dcm: - break; - } } void -TimingGroup::makeLinearModels(LibertyCell *cell) +LibertyReader::readTestCell(LibertyCell *cell, + const LibertyGroup *cell_group) { - LibertyLibrary *library = cell->libertyLibrary(); - for (auto rf : RiseFall::range()) { - int rf_index = rf->index(); - float intr = intrinsic_[rf_index]; - bool intr_exists = intrinsic_exists_[rf_index]; - if (!intr_exists) - library->defaultIntrinsic(rf, intr, intr_exists); - TimingModel *model = nullptr; - if (timingTypeIsCheck(attrs_->timingType())) { - if (intr_exists) - model = new CheckLinearModel(cell, intr); - } + const LibertyGroup *test_cell_group = cell_group->findSubgroup("test_cell"); + if (test_cell_group) { + if (cell->testCell()) + libWarn(1262, test_cell_group, "cell %s test_cell redefinition.", cell->name()); else { - float res = resistance_[rf_index]; - bool res_exists = resistance_exists_[rf_index]; - if (!res_exists) - library->defaultPinResistance(rf, PortDirection::output(), - res, res_exists); - if (!res_exists) - res = 0.0F; - if (intr_exists) - model = new GateLinearModel(cell, intr, res); - } - attrs_->setModel(rf, model); - } -} - -void -TimingGroup::makeTableModels(LibertyCell *cell, - LibertyReader *reader) -{ - for (const RiseFall *rf : RiseFall::range()) { - int rf_index = rf->index(); - TableModel *delay = cell_[rf_index]; - TableModel *transition = transition_[rf_index]; - TableModel *constraint = constraint_[rf_index]; - if (delay || transition) { - attrs_->setModel(rf, new GateTableModel(cell, delay, delay_sigma_[rf_index], - transition, - slew_sigma_[rf_index], - receiver_model_, - output_waveforms_[rf_index])); - TimingType timing_type = attrs_->timingType(); - if (timing_type == TimingType::clear - || timing_type == TimingType::combinational - || timing_type == TimingType::combinational_fall - || timing_type == TimingType::combinational_rise - || timing_type == TimingType::falling_edge - || timing_type == TimingType::preset - || timing_type == TimingType::rising_edge - || timing_type == TimingType::three_state_disable - || timing_type == TimingType::three_state_disable_rise - || timing_type == TimingType::three_state_disable_fall - || timing_type == TimingType::three_state_enable - || timing_type == TimingType::three_state_enable_fall - || timing_type == TimingType::three_state_enable_rise) { - if (transition == nullptr) - reader->libWarn(1210, line_, "missing %s_transition.", rf->name()); - if (delay == nullptr) - reader->libWarn(1211, line_, "missing cell_%s.", rf->name()); - } - } - else if (constraint) - attrs_->setModel(rf, new CheckTableModel(cell, constraint, - constraint_sigma_[rf_index])); - cell_[rf_index] = nullptr; - transition_[rf_index] = nullptr; - constraint_[rf_index] = nullptr; - } -} - -void -LibertyReader::makeTimingArcs(const char *from_port_name, - PortNameBitIterator &from_port_iter, - LibertyPort *to_port, - LibertyPort *related_out_port, - TimingGroup *timing) -{ - if (from_port_iter.size() == 1 && !to_port->hasMembers()) { - // one -> one - if (from_port_iter.hasNext()) { - LibertyPort *from_port = from_port_iter.next(); - if (from_port->direction()->isOutput()) - libWarn(1212, timing->line(), "timing group from output port."); - builder_.makeTimingArcs(cell_, from_port, to_port, related_out_port, - timing->attrs(), timing->line()); - } - } - else if (from_port_iter.size() > 1 && !to_port->hasMembers()) { - // bus -> one - while (from_port_iter.hasNext()) { - LibertyPort *from_port = from_port_iter.next(); - if (from_port->direction()->isOutput()) - libWarn(1213, timing->line(), "timing group from output port."); - builder_.makeTimingArcs(cell_, from_port, to_port, related_out_port, - timing->attrs(), timing->line()); - } - } - else if (from_port_iter.size() == 1 && to_port->hasMembers()) { - // one -> bus - if (from_port_iter.hasNext()) { - LibertyPort *from_port = from_port_iter.next(); - if (from_port->direction()->isOutput()) - libWarn(1214, timing->line(), "timing group from output port."); - LibertyPortMemberIterator bit_iter(to_port); - while (bit_iter.hasNext()) { - LibertyPort *to_port_bit = bit_iter.next(); - builder_.makeTimingArcs(cell_, from_port, to_port_bit, related_out_port, - timing->attrs(), timing->line()); - } - } - } - else { - // bus -> bus - if (timing->isOneToOne()) { - int from_size = from_port_iter.size(); - int to_size = to_port->size(); - LibertyPortMemberIterator to_port_iter(to_port); - // warn about different sizes - if (from_size != to_size) - libWarn(1216, timing->line(), - "timing port %s and related port %s are different sizes.", - from_port_name, - to_port->name()); - // align to/from iterators for one-to-one mapping - while (from_size > to_size) { - from_size--; - from_port_iter.next(); - } - while (to_size > from_size) { - to_size--; - to_port_iter.next(); - } - // make timing arcs - while (from_port_iter.hasNext() && to_port_iter.hasNext()) { - LibertyPort *from_port_bit = from_port_iter.next(); - LibertyPort *to_port_bit = to_port_iter.next(); - if (from_port_bit->direction()->isOutput()) - libWarn(1215, timing->line(), "timing group from output port."); - builder_.makeTimingArcs(cell_, from_port_bit, to_port_bit, - related_out_port, timing->attrs(), - timing->line()); - } - } - else { - while (from_port_iter.hasNext()) { - LibertyPort *from_port_bit = from_port_iter.next(); - if (from_port_bit->direction()->isOutput()) - libWarn(1217, timing->line(), "timing group from output port."); - LibertyPortMemberIterator to_iter(to_port); - while (to_iter.hasNext()) { - LibertyPort *to_port_bit = to_iter.next(); - builder_.makeTimingArcs(cell_, from_port_bit, to_port_bit, - related_out_port, timing->attrs(), - timing->line()); - } - } - } - } -} - -void -LibertyReader::makeTimingArcs(LibertyPort *to_port, - LibertyPort *related_out_port, - TimingGroup *timing) -{ - if (to_port->hasMembers()) { - LibertyPortMemberIterator bit_iter(to_port); - while (bit_iter.hasNext()) { - LibertyPort *to_port_bit = bit_iter.next(); - builder_.makeTimingArcs(cell_, nullptr, to_port_bit, - related_out_port, timing->attrs(), - timing->line()); - } - } - else - builder_.makeTimingArcs(cell_, nullptr, to_port, - related_out_port, timing->attrs(), - timing->line()); -} - -//////////////////////////////////////////////////////////////// - -// Group that encloses receiver_capacitance1/2 etc groups. -void -LibertyReader::beginReceiverCapacitance(LibertyGroup *) -{ - receiver_model_ = make_shared(); -} - -void -LibertyReader::endReceiverCapacitance(LibertyGroup *) -{ - if (ports_) { - for (LibertyPort *port : *ports_) - port->setReceiverModel(receiver_model_); - } - receiver_model_ = nullptr; -} - -// For receiver_capacitance groups with mulitiple segments this -// overrides the index passed in beginReceiverCapacitance1Rise/Fall. -void -LibertyReader::visitSegement(LibertyAttr *attr) -{ - if (receiver_model_) { - int segment; - bool exists; - getAttrInt(attr, segment, exists); - if (exists) - index_ = segment; - } -} - -void -LibertyReader::beginReceiverCapacitance1Rise(LibertyGroup *group) -{ - beginReceiverCapacitance(group, 0, RiseFall::rise()); -} - -void -LibertyReader::beginReceiverCapacitance1Fall(LibertyGroup *group) -{ - beginReceiverCapacitance(group, 0, RiseFall::fall()); -} - -void -LibertyReader::beginReceiverCapacitance2Rise(LibertyGroup *group) -{ - beginReceiverCapacitance(group, 1, RiseFall::rise()); -} - -void -LibertyReader::beginReceiverCapacitance2Fall(LibertyGroup *group) -{ - beginReceiverCapacitance(group, 1, RiseFall::fall()); -} - -void -LibertyReader::beginReceiverCapacitance(LibertyGroup *group, - int index, - const RiseFall *rf) -{ - if (timing_ || ports_) { - beginTableModel(group, TableTemplateType::delay, rf, 1.0, - ScaleFactorType::pin_cap); - index_ = index; - } - else - libWarn(1218, group, "receiver_capacitance group not in timing or pin group."); -} - -void -LibertyReader::endReceiverCapacitanceRiseFall(LibertyGroup *group) -{ - if (table_) { - if (ReceiverModel::checkAxes(table_)) { - if (receiver_model_ == nullptr) { - receiver_model_ = make_shared(); - if (timing_) - timing_->setReceiverModel(receiver_model_); - } - receiver_model_->setCapacitanceModel(TableModel(table_, tbl_template_, - scale_factor_type_, rf_), - index_, rf_); - } - else - libWarn(1219, group, "unsupported model axis."); - endTableModel(); - } -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginOutputCurrentRise(LibertyGroup *group) -{ - beginOutputCurrent(RiseFall::rise(), group); -} - -void -LibertyReader::beginOutputCurrentFall(LibertyGroup *group) -{ - beginOutputCurrent(RiseFall::fall(), group); -} - -void -LibertyReader::beginOutputCurrent(const RiseFall *rf, - LibertyGroup *group) -{ - if (timing_) { - rf_ = rf; - output_currents_.clear(); - } - else - libWarn(1220, group, "output_current_%s group not in timing group.", - rf->name()); -} - -void -LibertyReader::endOutputCurrentRiseFall(LibertyGroup *group) -{ - if (timing_) { - std::set slew_set, cap_set; - FloatSeq slew_values; - FloatSeq cap_values; - for (OutputWaveform *waveform : output_currents_) { - float slew = waveform->slew(); - if (!slew_set.contains(slew)) { - slew_set.insert(slew); - slew_values.push_back(slew); - } - float cap = waveform->cap(); - if (!cap_set.contains(cap)) { - cap_set.insert(cap); - cap_values.push_back(cap); - } - } - sort(slew_values, std::less()); - sort(cap_values, std::less()); - size_t slew_size = slew_values.size(); - size_t cap_size = cap_values.size(); - TableAxisPtr slew_axis=make_shared(TableAxisVariable::input_net_transition, - std::move(slew_values)); - TableAxisPtr cap_axis = - make_shared(TableAxisVariable::total_output_net_capacitance, - std::move(cap_values)); - FloatSeq ref_times(slew_size); - Table1Seq current_waveforms(slew_size * cap_size); - for (OutputWaveform *waveform : output_currents_) { - size_t slew_index, cap_index; - bool slew_exists, cap_exists; - slew_axis->findAxisIndex(waveform->slew(), slew_index, slew_exists); - cap_axis->findAxisIndex(waveform->cap(), cap_index, cap_exists); - if (slew_exists && cap_exists) { - size_t index = slew_index * cap_axis->size() + cap_index; - current_waveforms[index] = waveform->stealCurrents(); - ref_times[slew_index] = waveform->referenceTime(); - } - else - libWarn(1221, group, "output current waveform %.2e %.2e not found.", - waveform->slew(), - waveform->cap()); - } - Table ref_time_tbl(std::move(ref_times), slew_axis); - OutputWaveforms *output_current = new OutputWaveforms(slew_axis, cap_axis, rf_, - current_waveforms, - std::move(ref_time_tbl)); - timing_->setOutputWaveforms(rf_, output_current); - deleteContents(output_currents_); - } -} - -void -LibertyReader::beginVector(LibertyGroup *group) -{ - if (timing_ && !in_ccsn_) { - beginTable(group, TableTemplateType::output_current, current_scale_); - scale_factor_type_ = ScaleFactorType::unknown; - reference_time_exists_ = false; - if (tbl_template_ && !OutputWaveforms::checkAxes(tbl_template_)) - libWarn(1222, group, "unsupported model axis."); - } -} - -void -LibertyReader::visitReferenceTime(LibertyAttr *attr) -{ - getAttrFloat(attr, reference_time_, reference_time_exists_); - if (reference_time_exists_) - reference_time_ *= time_scale_; -} - -void -LibertyReader::endVector(LibertyGroup *group) -{ - if (timing_ && tbl_template_) { - TableAxisPtr slew_axis, cap_axis; - // Canonicalize axis order. - if (tbl_template_->axis1()->variable() == TableAxisVariable::input_net_transition) { - slew_axis = axis_[0]; - cap_axis = axis_[1]; - } - else { - slew_axis = axis_[1]; - cap_axis = axis_[0]; - } - - if (slew_axis->size() == 1 && cap_axis->size() == 1) { - // Convert 1x1xN Table (order 3) to 1D Table. - float slew = slew_axis->axisValue(0); - float cap = cap_axis->axisValue(0); - Table *table_ptr = table_.get(); - FloatTable *values3 = table_ptr->values3(); - FloatSeq row = std::move((*values3)[0]); - values3->erase(values3->begin()); - Table *table1 = new Table(std::move(row), axis_[2]); - OutputWaveform *waveform = new OutputWaveform(slew, cap, table1, reference_time_); - output_currents_.push_back(waveform); - } - else - libWarn(1223,group->line(), "vector index_1 and index_2 must have exactly one value."); - if (!reference_time_exists_) - libWarn(1224, group->line(), "vector reference_time not found."); - reference_time_exists_ = false; - tbl_template_ = nullptr; - } -} - -/////////////////////////////////////////////////////////////// - -void -LibertyReader::beginNormalizedDriverWaveform(LibertyGroup *group) -{ - beginTable(group, TableTemplateType::delay, time_scale_); - driver_waveform_name_.clear(); -} - -void -LibertyReader::visitDriverWaveformName(LibertyAttr *attr) -{ - driver_waveform_name_ = getAttrString(attr); -} - -void -LibertyReader::endNormalizedDriverWaveform(LibertyGroup *group) -{ - if (table_) { - if (table_->axis1()->variable() == TableAxisVariable::input_net_transition) { - if (table_->axis2()->variable() == TableAxisVariable::normalized_voltage) { - // Null driver_waveform_name_ means it is the default unnamed waveform. - library_->makeDriverWaveform(driver_waveform_name_, table_); - - } - else - libWarn(1225, group, "normalized_driver_waveform variable_2 must be normalized_voltage"); - } - else - libWarn(1226, group, "normalized_driver_waveform variable_1 must be input_net_transition"); - } - endTableModel(); -} - -void -LibertyReader::visitDriverWaveformRise(LibertyAttr *attr) -{ - visitDriverWaveformRiseFall(attr, RiseFall::rise()); -} - -void -LibertyReader::visitDriverWaveformFall(LibertyAttr *attr) -{ - visitDriverWaveformRiseFall(attr, RiseFall::fall()); -} - -void -LibertyReader::visitDriverWaveformRiseFall(LibertyAttr *attr, - const RiseFall *rf) -{ - if (ports_) { - const char *driver_waveform_name = getAttrString(attr); - DriverWaveform *driver_waveform = library_->findDriverWaveform(driver_waveform_name); - if (driver_waveform) { - for (LibertyPort *port : *ports_) - port->setDriverWaveform(driver_waveform, rf); - } - } -} - -/////////////////////////////////////////////////////////////// - -void -LibertyReader::makeInternalPowers(LibertyPort *port, - InternalPowerGroup *power_group) -{ - int line = power_group->line(); - const std::string &related_pg_pin_name = power_group->relatedPgPin(); - LibertyPort *related_pg_pin = cell_->findLibertyPort(related_pg_pin_name.c_str()); - - StringSeq *related_port_names = power_group->relatedPortNames(); - if (related_port_names) { - for (const char *related_port_name : *related_port_names) { - PortNameBitIterator related_port_iter(cell_, related_port_name, this, line); - if (related_port_iter.hasNext()) { - debugPrint(debug_, "liberty", 2, " power %s -> %s", - related_port_name, port->name()); - makeInternalPowers(port, related_port_name, related_port_iter, - related_pg_pin, power_group); - } - } - } - else { - if (port->hasMembers()) { - LibertyPortMemberIterator bit_iter(port); - while (bit_iter.hasNext()) { - LibertyPort *port_bit = bit_iter.next(); - cell_->makeInternalPower(port_bit, nullptr, related_pg_pin, - power_group->when(), power_group->models()); - } - } - else - cell_->makeInternalPower(port, nullptr, related_pg_pin, power_group->when(), - power_group->models()); - } -} - -void -LibertyReader::makeInternalPowers(LibertyPort *port, - const char *related_port_name, - PortNameBitIterator &related_port_iter, - LibertyPort *related_pg_pin, - InternalPowerGroup *power_group) -{ - const auto &when = power_group->when(); - InternalPowerModels &models = power_group->models(); - if (related_port_iter.size() == 1 && !port->hasMembers()) { - // one -> one - if (related_port_iter.hasNext()) { - LibertyPort *related_port = related_port_iter.next(); - cell_->makeInternalPower(port, related_port, related_pg_pin, when, models); - } - } - else if (related_port_iter.size() > 1 && !port->hasMembers()) { - // bus -> one - while (related_port_iter.hasNext()) { - LibertyPort *related_port = related_port_iter.next(); - cell_->makeInternalPower(port, related_port, related_pg_pin, when, models); - } - } - else if (related_port_iter.size() == 1 && port->hasMembers()) { - // one -> bus - if (related_port_iter.hasNext()) { - LibertyPort *related_port = related_port_iter.next(); - LibertyPortMemberIterator bit_iter(port); - while (bit_iter.hasNext()) { - LibertyPort *port_bit = bit_iter.next(); - cell_->makeInternalPower(port_bit, related_port, related_pg_pin, when, models); - } - } - } - else { - // bus -> bus - if (power_group->isOneToOne()) { - if (static_cast(related_port_iter.size()) == port->size()) { - LibertyPortMemberIterator to_iter(port); - while (related_port_iter.hasNext() && to_iter.hasNext()) { - LibertyPort *related_port_bit = related_port_iter.next(); - LibertyPort *port_bit = to_iter.next(); - cell_->makeInternalPower(port_bit, related_port_bit, related_pg_pin, - when, models); - } - } - else - libWarn(1227, power_group->line(), - "internal_power port %s and related port %s are different sizes.", - related_port_name, - port->name()); - } - else { - while (related_port_iter.hasNext()) { - LibertyPort *related_port_bit = related_port_iter.next(); - LibertyPortMemberIterator to_iter(port); - while (to_iter.hasNext()) { - LibertyPort *port_bit = to_iter.next(); - cell_->makeInternalPower(port_bit, related_port_bit, related_pg_pin, - when, models); - } - } + std::string test_cell_name = std::string(cell->name()) + "/test_cell"; + TestCell *test_cell = new TestCell(cell->libertyLibrary(), + std::move(test_cell_name), + cell->filename()); + cell->setTestCell(test_cell); + readCell(test_cell, test_cell_group); } } } //////////////////////////////////////////////////////////////// -void -LibertyReader::visitArea(LibertyAttr *attr) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - cell_->setArea(value); - } - if (wireload_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - wireload_->setArea(value); - } -} - -void -LibertyReader::visitDontUse(LibertyAttr *attr) -{ - if (cell_) { - bool dont_use, exists; - getAttrBool(attr, dont_use, exists); - if (exists) - cell_->setDontUse(dont_use); - } -} - -void -LibertyReader::visitIsMacro(LibertyAttr *attr) -{ - if (cell_) { - bool is_macro, exists; - getAttrBool(attr, is_macro, exists); - if (exists) - cell_->setIsMacro(is_macro); - } -} - -void -LibertyReader::visitIsMemory(LibertyAttr *attr) -{ - if (cell_) { - bool is_memory, exists; - getAttrBool(attr, is_memory, exists); - if (exists) - cell_->setIsMemory(is_memory); - } -} - -void -LibertyReader::visitIsPadCell(LibertyAttr *attr) -{ - if (cell_) { - bool pad_cell, exists; - getAttrBool(attr, pad_cell, exists); - if (exists) - cell_->setIsPad(pad_cell); - } -} - -void -LibertyReader::visitIsClockCell(LibertyAttr *attr) -{ - if (cell_) { - bool is_clock_cell, exists; - getAttrBool(attr, is_clock_cell, exists); - if (exists) - cell_->setIsClockCell(is_clock_cell); - } -} - -void -LibertyReader::visitIsLevelShifter(LibertyAttr *attr) -{ - if (cell_) { - bool is_level_shifter, exists; - getAttrBool(attr, is_level_shifter, exists); - if (exists) - cell_->setIsLevelShifter(is_level_shifter); - } -} - -void -LibertyReader::visitLevelShifterType(LibertyAttr *attr) -{ - if (cell_) { - const char *level_shifter_type = getAttrString(attr); - if (stringEq(level_shifter_type, "HL")) - cell_->setLevelShifterType(LevelShifterType::HL); - else if (stringEq(level_shifter_type, "LH")) - cell_->setLevelShifterType(LevelShifterType::LH); - else if (stringEq(level_shifter_type, "HL_LH")) - cell_->setLevelShifterType(LevelShifterType::HL_LH); - else - libWarn(1228, attr, "level_shifter_type must be HL, LH, or HL_LH"); - } -} - -void -LibertyReader::visitIsIsolationCell(LibertyAttr *attr) -{ - if (cell_) { - bool is_isolation_cell, exists; - getAttrBool(attr, is_isolation_cell, exists); - if (exists) - cell_->setIsIsolationCell(is_isolation_cell); - } -} - -void -LibertyReader::visitAlwaysOn(LibertyAttr *attr) -{ - if (cell_) { - bool always_on, exists; - getAttrBool(attr, always_on, exists); - if (exists) - cell_->setAlwaysOn(always_on); - } -} - -void -LibertyReader::visitSwitchCellType(LibertyAttr *attr) -{ - if (cell_) { - const char *switch_cell_type = getAttrString(attr); - if (stringEq(switch_cell_type, "coarse_grain")) - cell_->setSwitchCellType(SwitchCellType::coarse_grain); - else if (stringEq(switch_cell_type, "fine_grain")) - cell_->setSwitchCellType(SwitchCellType::fine_grain); - else - libWarn(1229, attr, "switch_cell_type must be coarse_grain or fine_grain"); - } -} - -void -LibertyReader::visitInterfaceTiming(LibertyAttr *attr) -{ - if (cell_) { - bool value, exists; - getAttrBool(attr, value, exists); - if (exists) - cell_->setInterfaceTiming(value); - } -} - -void -LibertyReader::visitScalingFactors(LibertyAttr *attr) -{ - if (cell_) { - const char *scale_factors_name = getAttrString(attr); - ScaleFactors *scales = library_->findScaleFactors(scale_factors_name); - if (scales) - cell_->setScaleFactors(scales); - else - libWarn(1230, attr, "scaling_factors %s not found.", scale_factors_name); - } -} - -void -LibertyReader::visitClockGatingIntegratedCell(LibertyAttr *attr) -{ - if (cell_) { - const char *clock_gate_type = getAttrString(attr); - if (clock_gate_type) { - if (stringBeginEqual(clock_gate_type, "latch_posedge")) - cell_->setClockGateType(ClockGateType::latch_posedge); - else if (stringBeginEqual(clock_gate_type, "latch_negedge")) - cell_->setClockGateType(ClockGateType::latch_negedge); - else - cell_->setClockGateType(ClockGateType::other); - } - } -} - -void -LibertyReader::visitCellFootprint(LibertyAttr *attr) -{ - if (cell_) { - const char *footprint = getAttrString(attr); - if (footprint) - cell_->setFootprint(footprint); - } -} - -void -LibertyReader::visitCellUserFunctionClass(LibertyAttr *attr) -{ - if (cell_) { - const char *user_function_class = getAttrString(attr); - if (user_function_class) - cell_->setUserFunctionClass(user_function_class); - } -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginPin(LibertyGroup *group) -{ - if (cell_) { - if (in_bus_) { - saved_ports_ = ports_; - saved_port_group_ = port_group_; - ports_ = new LibertyPortSeq; - for (LibertyAttrValue *param : *group->params()) { - if (param->isString()) { - const std::string &port_name = param->stringValue(); - debugPrint(debug_, "liberty", 1, " port %s", port_name.c_str()); - PortNameBitIterator port_iter(cell_, port_name.c_str(), this, group->line()); - while (port_iter.hasNext()) { - LibertyPort *port = port_iter.next(); - ports_->push_back(port); - } - } - else - libWarn(1231, group, "pin name is not a string."); - } - } - else if (in_bundle_) { - saved_ports_ = ports_; - saved_port_group_ = port_group_; - ports_ = new LibertyPortSeq; - for (LibertyAttrValue *param : *group->params()) { - if (param->isString()) { - const char *name = param->stringValue().c_str(); - debugPrint(debug_, "liberty", 1, " port %s", name); - LibertyPort *port = findPort(name); - if (port == nullptr) - port = makePort(cell_, name); - ports_->push_back(port); - } - else - libWarn(1232, group, "pin name is not a string."); - } - } - else { - ports_ = new LibertyPortSeq; - // Multiple port names can share group def. - for (LibertyAttrValue *param : *group->params()) { - if (param->isString()) { - const char *name = param->stringValue().c_str(); - debugPrint(debug_, "liberty", 1, " port %s", name); - LibertyPort *port = makePort(cell_, name); - ports_->push_back(port); - } - else - libWarn(1233, group, "pin name is not a string."); - } - } - port_group_ = new PortGroup(ports_, group->line()); - cell_port_groups_.push_back(port_group_); - } -} - LibertyPort * LibertyReader::makePort(LibertyCell *cell, const char *port_name) { - string sta_name = portLibertyToSta(port_name); + std::string sta_name = portLibertyToSta(port_name); return builder_.makePort(cell, sta_name.c_str()); } @@ -3235,189 +3012,13 @@ LibertyReader::makeBusPort(LibertyCell *cell, int to_index, BusDcl *bus_dcl) { - string sta_name = portLibertyToSta(bus_name); + std::string sta_name = portLibertyToSta(bus_name); return builder_.makeBusPort(cell, bus_name, from_index, to_index, bus_dcl); } -void -LibertyReader::endPin(LibertyGroup *) -{ - if (cell_) { - endPorts(); - if (in_bus_ || in_bundle_) { - ports_ = saved_ports_; - port_group_ = saved_port_group_; - } - } -} - -void -LibertyReader::endPorts() -{ - // Capacitances default based on direction so wait until the end - // of the pin group to set them. - if (ports_) { - for (LibertyPort *port : *ports_) { - if (in_bus_ || in_bundle_) { - // Do not clobber member port capacitances by setting the capacitance - // on a bus or bundle. - LibertyPortMemberIterator member_iter(port); - while (member_iter.hasNext()) { - LibertyPort *member = member_iter.next(); - setPortCapDefault(member); - } - } - else - setPortCapDefault(port); - } - ports_ = nullptr; - port_group_ = nullptr; - } -} - -void -LibertyReader::setPortCapDefault(LibertyPort *port) -{ - for (auto min_max : MinMax::range()) { - for (auto tr : RiseFall::range()) { - float cap; - bool exists; - port->capacitance(tr, min_max, cap, exists); - if (!exists) - port->setCapacitance(tr, min_max, defaultCap(port)); - } - } -} - -void -LibertyReader::beginBus(LibertyGroup *group) -{ - if (cell_) { - beginBusOrBundle(group); - in_bus_ = true; - } -} - -void -LibertyReader::endBus(LibertyGroup *group) -{ - if (cell_) { - if (ports_->empty()) - libWarn(1234, group, "bus %s bus_type not found.", group->firstName()); - endBusOrBundle(); - in_bus_ = false; - } -} - -void -LibertyReader::beginBusOrBundle(LibertyGroup *group) -{ - // Multiple port names can share group def. - for (LibertyAttrValue *param : *group->params()) { - if (param->isString()) { - const string &name = param->stringValue(); - bus_names_.push_back(stringCopy(name.c_str())); - } - } - ports_ = new LibertyPortSeq; - port_group_ = new PortGroup(ports_, group->line()); - cell_port_groups_.push_back(port_group_); -} - -void -LibertyReader::endBusOrBundle() -{ - endPorts(); - deleteContents(&bus_names_); - bus_names_.clear(); - ports_ = nullptr; - port_group_ = nullptr; -} - -// Bus port are not made until the bus_type is specified. -void -LibertyReader::visitBusType(LibertyAttr *attr) -{ - if (cell_) { - const char *bus_type = getAttrString(attr); - if (bus_type) { - // Look for bus dcl local to cell first. - BusDcl *bus_dcl = cell_->findBusDcl(bus_type); - if (bus_dcl == nullptr) - bus_dcl = library_->findBusDcl(bus_type); - if (bus_dcl) { - for (const char *name : bus_names_) { - debugPrint(debug_, "liberty", 1, " bus %s", name); - LibertyPort *port = makeBusPort(cell_, name, bus_dcl->from(), - bus_dcl->to(), bus_dcl); - ports_->push_back(port); - } - } - else - libWarn(1235, attr, "bus_type %s not found.", bus_type); - } - else - libWarn(1236, attr, "bus_type is not a string."); - } -} - -void -LibertyReader::beginBundle(LibertyGroup *group) -{ - if (cell_) { - beginBusOrBundle(group); - in_bundle_ = true; - } -} - -void -LibertyReader::endBundle(LibertyGroup *group) -{ - if (cell_) { - if (ports_ && ports_->empty()) - libWarn(1237, group, "bundle %s member not found.", group->firstName()); - endBusOrBundle(); - in_bundle_ = false; - } -} - -void -LibertyReader::visitMembers(LibertyAttr *attr) -{ - if (cell_) { - if (attr->isComplexAttr()) { - for (const char *name : bus_names_) { - debugPrint(debug_, "liberty", 1, " bundle %s", name); - ConcretePortSeq *members = new ConcretePortSeq; - for (LibertyAttrValue *value : *attr->values()) { - if (value->isString()) { - const char *port_name = value->stringValue().c_str(); - LibertyPort *port = findPort(port_name); - if (port == nullptr) - port = makePort(cell_, port_name); - members->push_back(port); - } - else - libWarn(1238, attr, "member is not a string."); - } - LibertyPort *port = builder_.makeBundlePort(cell_, name, members); - ports_->push_back(port); - } - } - else - libWarn(1239, attr,"members attribute is missing values."); - } -} - -LibertyPort * -LibertyReader::findPort(const char *port_name) -{ - return findPort(cell_, port_name); -} - // Also used by LibExprParser::makeFuncExprPort. LibertyPort * -libertyReaderFindPort(LibertyCell *cell, +libertyReaderFindPort(const LibertyCell *cell, const char *port_name) { LibertyPort *port = cell->findLibertyPort(port_name); @@ -3427,7 +3028,7 @@ libertyReaderFindPort(LibertyCell *cell, char brkt_right = library->busBrktRight(); const char escape = '\\'; // Pins at top level with bus names have escaped brackets. - string escaped_port_name = escapeChars(port_name, brkt_left, brkt_right, escape); + std::string escaped_port_name = escapeChars(port_name, brkt_left, brkt_right, escape); port = cell->findLibertyPort(escaped_port_name.c_str()); } return port; @@ -3440,193 +3041,6 @@ LibertyReader::findPort(LibertyCell *cell, return libertyReaderFindPort(cell, port_name); } -void -LibertyReader::visitDirection(LibertyAttr *attr) -{ - if (ports_) { - const char *dir = getAttrString(attr); - if (dir) { - PortDirection *port_dir = PortDirection::unknown(); - if (stringEq(dir, "input")) - port_dir = PortDirection::input(); - else if (stringEq(dir, "output")) - port_dir = PortDirection::output(); - else if (stringEq(dir, "inout")) - port_dir = PortDirection::bidirect(); - else if (stringEq(dir, "internal")) - port_dir = PortDirection::internal(); - else - libWarn(1240, attr, "unknown port direction."); - - for (LibertyPort *port : *ports_) { - // Tristate enable function sets direction to tristate; don't - // clobber it. - if (!port->direction()->isTristate()) - port->setDirection(port_dir); - } - } - } -} - -void -LibertyReader::visitFunction(LibertyAttr *attr) -{ - if (ports_) { - const char *func = getAttrString(attr); - if (func) { - for (LibertyPort *port : *ports_) - makeLibertyFunc(func, - [port] (FuncExpr *expr) { port->setFunction(expr); }, - false, "function", attr); - } - } -} - -void -LibertyReader::visitThreeState(LibertyAttr *attr) -{ - if (ports_) { - const char *three_state = getAttrString(attr); - if (three_state) { - for (LibertyPort *port : *ports_) - makeLibertyFunc(three_state, - [port] (FuncExpr *expr) { port->setTristateEnable(expr); }, - true, "three_state", attr); - } - } -} - -void -LibertyReader::visitPorts(std::function func) -{ - for (LibertyPort *port : *ports_) { - func(port); - LibertyPortMemberIterator member_iter(port); - while (member_iter.hasNext()) { - LibertyPort *member = member_iter.next(); - func(member); - } - } -} - -void -LibertyReader::visitClock(LibertyAttr *attr) -{ - if (ports_) { - bool is_clk, exists; - getAttrBool(attr, is_clk, exists); - if (exists) { - for (LibertyPort *port : *ports_) - port->setIsClock(is_clk); - } - } -} - -void -LibertyReader::visitIsPad(LibertyAttr *attr) -{ - if (ports_) { - bool is_pad, exists; - getAttrBool(attr, is_pad, exists); - if (exists) { - for (LibertyPort *port : *ports_) - port->setIsPad(is_pad); - } - } -} - -void -LibertyReader::visitCapacitance(LibertyAttr *attr) -{ - if (ports_) { - float cap; - bool exists; - getAttrFloat(attr, cap, exists); - if (exists) { - cap *= cap_scale_; - for (LibertyPort *port : *ports_) - port->setCapacitance(cap); - } - } - if (wireload_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - wireload_->setCapacitance(value * cap_scale_); - } -} - -void -LibertyReader::visitRiseCap(LibertyAttr *attr) -{ - if (ports_) { - float cap; - bool exists; - getAttrFloat(attr, cap, exists); - if (exists) { - cap *= cap_scale_; - for (LibertyPort *port : *ports_) { - port->setCapacitance(RiseFall::rise(), MinMax::min(), cap); - port->setCapacitance(RiseFall::rise(), MinMax::max(), cap); - } - } - } -} - -void -LibertyReader::visitFallCap(LibertyAttr *attr) -{ - if (ports_) { - float cap; - bool exists; - getAttrFloat(attr, cap, exists); - if (exists) { - cap *= cap_scale_; - for (LibertyPort *port : *ports_) { - port->setCapacitance(RiseFall::fall(), MinMax::min(), cap); - port->setCapacitance(RiseFall::fall(), MinMax::max(), cap); - } - } - } -} - -void -LibertyReader::visitRiseCapRange(LibertyAttr *attr) -{ - if (ports_) { - bool exists; - float min, max; - getAttrFloat2(attr, min, max, exists); - if (exists) { - min *= cap_scale_; - max *= cap_scale_; - for (LibertyPort *port : *ports_) { - port->setCapacitance(RiseFall::rise(), MinMax::min(), min); - port->setCapacitance(RiseFall::rise(), MinMax::max(), max); - } - } - } -} - -void -LibertyReader::visitFallCapRange(LibertyAttr *attr) -{ - if (ports_) { - bool exists; - float min, max; - getAttrFloat2(attr, min, max, exists); - if (exists) { - min *= cap_scale_; - max *= cap_scale_; - for (LibertyPort *port : *ports_) { - port->setCapacitance(RiseFall::fall(), MinMax::min(), min); - port->setCapacitance(RiseFall::fall(), MinMax::max(), max); - } - } - } -} - float LibertyReader::defaultCap(LibertyPort *port) { @@ -3642,535 +3056,8 @@ LibertyReader::defaultCap(LibertyPort *port) return cap; } -void -LibertyReader::visitFanoutLoad(LibertyAttr *attr) -{ - if (ports_) { - float fanout; - bool exists; - getAttrFloat(attr, fanout, exists); - if (exists) { - visitPorts([&] (LibertyPort *port) { - port->setFanoutLoad(fanout); - }); - } - } -} - -void -LibertyReader::visitMaxFanout(LibertyAttr *attr) -{ - visitFanout(attr, MinMax::max()); -} - -void -LibertyReader::visitMinFanout(LibertyAttr *attr) -{ - visitFanout(attr, MinMax::min()); -} - -void -LibertyReader::visitFanout(LibertyAttr *attr, - const MinMax *min_max) -{ - if (ports_) { - float fanout; - bool exists; - getAttrFloat(attr, fanout, exists); - if (exists) { - visitPorts([&] (LibertyPort *port) { - port->setFanoutLimit(fanout, min_max); - }); - } - } -} - -void -LibertyReader::visitMaxTransition(LibertyAttr *attr) -{ - visitMinMaxTransition(attr, MinMax::max()); -} - -void -LibertyReader::visitMinTransition(LibertyAttr *attr) -{ - visitMinMaxTransition(attr, MinMax::min()); -} - -void -LibertyReader::visitMinMaxTransition(LibertyAttr *attr, - const MinMax *min_max) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - if (min_max == MinMax::max() && value == 0.0) - libWarn(1241, attr, "max_transition is 0.0."); - value *= time_scale_; - visitPorts([&] (LibertyPort *port) { - port->setSlewLimit(value, min_max); - }); - } - } -} - -void -LibertyReader::visitMaxCapacitance(LibertyAttr *attr) -{ - visitMinMaxCapacitance(attr, MinMax::max()); -} - -void -LibertyReader::visitMinCapacitance(LibertyAttr *attr) -{ - visitMinMaxCapacitance(attr, MinMax::min()); -} - -void -LibertyReader::visitMinMaxCapacitance(LibertyAttr *attr, - const MinMax *min_max) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - value *= cap_scale_; - visitPorts([&] (LibertyPort *port) { - port->setCapacitanceLimit(value, min_max); - }); - } - } -} - -void -LibertyReader::visitMinPeriod(LibertyAttr *attr) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - for (LibertyPort *port : *ports_) - port->setMinPeriod(value * time_scale_); - } - } -} - -void -LibertyReader::visitMinPulseWidthLow(LibertyAttr *attr) -{ - visitMinPulseWidth(attr, RiseFall::fall()); -} - -void -LibertyReader::visitMinPulseWidthHigh(LibertyAttr *attr) -{ - visitMinPulseWidth(attr, RiseFall::rise()); -} - -void -LibertyReader::visitMinPulseWidth(LibertyAttr *attr, - const RiseFall *rf) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - value *= time_scale_; - for (LibertyPort *port : *ports_) - port->setMinPulseWidth(rf, value); - } - } -} - -void -LibertyReader::visitPulseClock(LibertyAttr *attr) -{ - if (cell_) { - const char *pulse_clk = getAttrString(attr); - if (pulse_clk) { - const RiseFall *trigger = nullptr; - const RiseFall *sense = nullptr; - if (stringEq(pulse_clk, "rise_triggered_high_pulse")) { - trigger = RiseFall::rise(); - sense = RiseFall::rise(); - } - else if (stringEq(pulse_clk, "rise_triggered_low_pulse")) { - trigger = RiseFall::rise(); - sense = RiseFall::fall(); - } - else if (stringEq(pulse_clk, "fall_triggered_high_pulse")) { - trigger = RiseFall::fall(); - sense = RiseFall::rise(); - } - else if (stringEq(pulse_clk, "fall_triggered_low_pulse")) { - trigger = RiseFall::fall(); - sense = RiseFall::fall(); - } - else - libWarn(1242,attr, "pulse_latch unknown pulse type."); - if (trigger) { - for (LibertyPort *port : *ports_) - port->setPulseClk(trigger, sense); - } - } - } -} - -void -LibertyReader::visitClockGateClockPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsClockGateClock); -} - -void -LibertyReader::visitClockGateEnablePin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsClockGateEnable); -} - -void -LibertyReader::visitClockGateOutPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsClockGateOut); -} - -void -LibertyReader::visitIsPllFeedbackPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsPllFeedback); -} - -void -LibertyReader::visitSignalType(LibertyAttr *attr) -{ - if (test_cell_ && ports_) { - const char *type = getAttrString(attr); - if (type) { - ScanSignalType signal_type = ScanSignalType::none; - if (stringEq(type, "test_scan_enable")) - signal_type = ScanSignalType::enable; - else if (stringEq(type, "test_scan_enable_inverted")) - signal_type = ScanSignalType::enable_inverted; - else if (stringEq(type, "test_scan_clock")) - signal_type = ScanSignalType::clock; - else if (stringEq(type, "test_scan_clock_a")) - signal_type = ScanSignalType::clock_a; - else if (stringEq(type, "test_scan_clock_b")) - signal_type = ScanSignalType::clock_b; - else if (stringEq(type, "test_scan_in")) - signal_type = ScanSignalType::input; - else if (stringEq(type, "test_scan_in_inverted")) - signal_type = ScanSignalType::input_inverted; - else if (stringEq(type, "test_scan_out")) - signal_type = ScanSignalType::output; - else if (stringEq(type, "test_scan_out_inverted")) - signal_type = ScanSignalType::output_inverted; - else { - libWarn(1299, attr, "unknown signal_type %s.", type); - return; - } - for (LibertyPort *port : *ports_) - port->setScanSignalType(signal_type); - } - } -} - -void -LibertyReader::visitIsolationCellDataPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsolationCellData); -} - -void -LibertyReader::visitIsolationCellEnablePin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsolationCellEnable); -} - -void -LibertyReader::visitLevelShifterDataPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setLevelShifterData); -} - -void -LibertyReader::visitSwitchPin(LibertyAttr *attr) -{ - visitPortBoolAttr(attr, &LibertyPort::setIsSwitch); -} - -void -LibertyReader::visitPortBoolAttr(LibertyAttr *attr, - LibertyPortBoolSetter setter) -{ - if (cell_) { - bool value, exists; - getAttrBool(attr, value, exists); - if (exists) { - for (LibertyPort *port : *ports_) - (port->*setter)(value); - } - } -} - //////////////////////////////////////////////////////////////// -void -LibertyReader::beginMemory(LibertyGroup *) -{ - if (cell_) { - cell_->setIsMemory(true); - } -} - -void -LibertyReader::endMemory(LibertyGroup *) -{ -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginFF(LibertyGroup *group) -{ - beginSequential(group, true, false); -} - -void -LibertyReader::endFF(LibertyGroup *) -{ - sequential_ = nullptr; -} - -void -LibertyReader::beginFFBank(LibertyGroup *group) -{ - beginSequential(group, true, true); -} - -void -LibertyReader::endFFBank(LibertyGroup *) -{ - sequential_ = nullptr; -} - -void -LibertyReader::beginLatch(LibertyGroup *group) -{ - beginSequential(group, false, false); -} - -void -LibertyReader::endLatch(LibertyGroup *) -{ - sequential_ = nullptr; -} - -void -LibertyReader::beginLatchBank(LibertyGroup *group) -{ - beginSequential(group, false, true); -} - -void -LibertyReader::endLatchBank(LibertyGroup *) -{ - sequential_ = nullptr; -} - -void -LibertyReader::beginSequential(LibertyGroup *group, - bool is_register, - bool is_bank) -{ - if (cell_) { - // Define ff/latch state variables as internal ports. - const char *out_name, *out_inv_name; - int size; - bool has_size; - seqPortNames(group, out_name, out_inv_name, has_size, size); - LibertyPort *out_port = nullptr; - LibertyPort *out_port_inv = nullptr; - if (out_name) { - if (has_size) - out_port = makeBusPort(cell_, out_name, size - 1, 0, nullptr); - else - out_port = makePort(cell_, out_name); - out_port->setDirection(PortDirection::internal()); - } - if (out_inv_name) { - if (has_size) - out_port_inv = makeBusPort(cell_, out_inv_name, size - 1, 0, nullptr); - else - out_port_inv = makePort(cell_, out_inv_name); - out_port_inv->setDirection(PortDirection::internal()); - } - sequential_ = new SequentialGroup(is_register, is_bank, - out_port, out_port_inv, size, - group->line()); - cell_sequentials_.push_back(sequential_); - } -} - -void -LibertyReader::seqPortNames(LibertyGroup *group, - const char *&out_name, - const char *&out_inv_name, - bool &has_size, - int &size) -{ - out_name = nullptr; - out_inv_name = nullptr; - size = 1; - has_size = false; - if (group->params()->size() == 2) { - // out_port, out_port_inv - out_name = group->firstName(); - out_inv_name = group->secondName(); - } - else if (group->params()->size() == 3) { - LibertyAttrValue *third_value = (*group->params())[2]; - if (third_value->isFloat()) { - // out_port, out_port_inv, bus_size - out_name = group->firstName(); - out_inv_name = group->secondName(); - size = static_cast(third_value->floatValue()); - has_size = true; - } - else { - // in_port (ignored), out_port, out_port_inv - out_name = group->secondName(); - out_inv_name = third_value->stringValue().c_str(); - } - } -} - -void -LibertyReader::visitClockedOn(LibertyAttr *attr) -{ - if (sequential_) { - const char *func = getAttrString(attr); - if (func) - sequential_->setClock(stringCopy(func)); - } -} - -void -LibertyReader::visitDataIn(LibertyAttr *attr) -{ - if (sequential_) { - const char *func = getAttrString(attr); - if (func) - sequential_->setData(stringCopy(func)); - } -} - -void -LibertyReader::visitClear(LibertyAttr *attr) -{ - if (sequential_) { - const char *func = getAttrString(attr); - if (func) - sequential_->setClear(stringCopy(func)); - } -} - -void -LibertyReader::visitPreset(LibertyAttr *attr) -{ - if (sequential_) { - const char *func = getAttrString(attr); - if (func) - sequential_->setPreset(stringCopy(func)); - } -} - -void -LibertyReader::visitClrPresetVar1(LibertyAttr *attr) -{ - if (sequential_) { - LogicValue var = getAttrLogicValue(attr); - sequential_->setClrPresetVar1(var); - } -} - -void -LibertyReader::visitClrPresetVar2(LibertyAttr *attr) -{ - if (sequential_) { - LogicValue var = getAttrLogicValue(attr); - sequential_->setClrPresetVar2(var); - } -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginStatetable(LibertyGroup *group) -{ - if (cell_) { - const char *input_ports_arg = group->firstName(); - StdStringSeq input_ports; - if (input_ports_arg) - input_ports = parseTokenList(input_ports_arg, ' '); - - const char *internal_ports_arg = group->secondName(); - StdStringSeq internal_ports; - if (internal_ports_arg) - internal_ports = parseTokenList(internal_ports_arg, ' '); - statetable_ = new StatetableGroup(input_ports, internal_ports, group->line()); - } -} - -void -LibertyReader::visitTable(LibertyAttr *attr) -{ - if (statetable_) { - const char *table_str = getAttrString(attr); - StdStringSeq table_rows = parseTokenList(table_str, ','); - size_t input_count = statetable_->inputPorts().size(); - size_t internal_count = statetable_->internalPorts().size(); - for (string row : table_rows) { - StdStringSeq row_groups = parseTokenList(row.c_str(), ':'); - if (row_groups.size() != 3) { - libWarn(1300, attr, "table row must have 3 groups separated by ':'."); - break; - } - StdStringSeq inputs = parseTokenList(row_groups[0].c_str(), ' '); - if (inputs.size() != input_count) { - libWarn(1301, attr, "table row has %zu input values but %zu are required.", - inputs.size(), - input_count); - break; - } - StdStringSeq currents = parseTokenList(row_groups[1].c_str(), ' '); - if (currents.size() != internal_count) { - libWarn(1302, attr, "table row has %zu current values but %zu are required.", - currents.size(), - internal_count); - break; - } - StdStringSeq nexts = parseTokenList(row_groups[2].c_str(), ' '); - if (nexts.size() != internal_count) { - libWarn(1303, attr, "table row has %zu next values but %zu are required.", - nexts.size(), - internal_count); - break; - } - - StateInputValues input_values = parseStateInputValues(inputs, attr); - StateInternalValues current_values=parseStateInternalValues(currents,attr); - StateInternalValues next_values = parseStateInternalValues(nexts, attr); - statetable_->addRow(input_values, current_values, next_values); - } - } -} - static EnumNameMap state_input_value_name_map = {{StateInputValue::low, "L"}, {StateInputValue::high, "H"}, @@ -4195,10 +3082,10 @@ static EnumNameMap state_internal_value_name_map = StateInputValues LibertyReader::parseStateInputValues(StdStringSeq &inputs, - LibertyAttr *attr) + const LibertySimpleAttr *attr) { StateInputValues input_values; - for (string input : inputs) { + for (std::string input : inputs) { bool exists; StateInputValue value; state_input_value_name_map.find(input.c_str(), value, exists); @@ -4214,10 +3101,10 @@ LibertyReader::parseStateInputValues(StdStringSeq &inputs, StateInternalValues LibertyReader::parseStateInternalValues(StdStringSeq &states, - LibertyAttr *attr) + const LibertySimpleAttr *attr) { StateInternalValues state_values; - for (string state : states) { + for (std::string state : states) { bool exists; StateInternalValue value; state_internal_value_name_map.find(state.c_str(), value, exists); @@ -4231,530 +3118,30 @@ LibertyReader::parseStateInternalValues(StdStringSeq &states, return state_values; } -void -LibertyReader::endStatetable(LibertyGroup *) -{ -} - //////////////////////////////////////////////////////////////// -void -LibertyReader::beginTiming(LibertyGroup *group) -{ - if (port_group_) { - timing_ = new TimingGroup(group->line()); - port_group_->addTimingGroup(timing_); - } -} - -void -LibertyReader::endTiming(LibertyGroup *group) -{ - if (timing_) { - // Set scale factor type in constraint tables. - for (auto rf : RiseFall::range()) { - TableModel *model = timing_->constraint(rf); - if (model) { - ScaleFactorType type=timingTypeScaleFactorType(timing_->attrs()->timingType()); - model->setScaleFactorType(type); - } - } - TimingType timing_type = timing_->attrs()->timingType(); - if (timing_->relatedPortNames() == nullptr - && !(timing_type == TimingType::min_pulse_width - || timing_type == TimingType::minimum_period - || timing_type == TimingType::min_clock_tree_path - || timing_type == TimingType::max_clock_tree_path)) - libWarn(1243, group, "timing group missing related_pin/related_bus_pin."); - } - timing_ = nullptr; - receiver_model_ = nullptr; -} - -void -LibertyReader::visitRelatedPin(LibertyAttr *attr) -{ - if (timing_) - visitRelatedPin(attr, timing_); - if (internal_power_) - visitRelatedPin(attr, internal_power_); -} - -void -LibertyReader::visitRelatedPin(LibertyAttr *attr, - RelatedPortGroup *group) -{ - const char *port_names = getAttrString(attr); - if (port_names) { - group->setRelatedPortNames(parseNameList(port_names)); - group->setIsOneToOne(true); - } -} - -StringSeq * -LibertyReader::parseNameList(const char *name_list) -{ - StringSeq *names = new StringSeq; - // Parse space separated list of names. - TokenParser parser(name_list, " "); - while (parser.hasNext()) { - char *token = parser.next(); - // Skip extra spaces. - if (token[0] != '\0') { - const char *name = token; - names->push_back(stringCopy(name)); - } - } - return names; -} - -StdStringSeq -LibertyReader::parseTokenList(const char *token_str, - const char separator) -{ - StdStringSeq tokens; - // Parse space separated list of names. - char separators[2] = {separator, '\0'}; - TokenParser parser(token_str, separators); - while (parser.hasNext()) { - char *token = parser.next(); - // Skip extra spaces. - if (token[0] != '\0') { - tokens.push_back(token); - } - } - return tokens; -} - -void -LibertyReader::visitRelatedBusPins(LibertyAttr *attr) -{ - if (timing_) - visitRelatedBusPins(attr, timing_); - if (internal_power_) - visitRelatedBusPins(attr, internal_power_); -} - -void -LibertyReader::visitRelatedBusPins(LibertyAttr *attr, - RelatedPortGroup *group) -{ - const char *port_names = getAttrString(attr); - if (port_names) { - group->setRelatedPortNames(parseNameList(port_names)); - group->setIsOneToOne(false); - } -} - -void -LibertyReader::visitRelatedOutputPin(LibertyAttr *attr) -{ - if (timing_) { - const char *pin_name = getAttrString(attr); - if (pin_name) - timing_->setRelatedOutputPortName(pin_name); - } -} - -void -LibertyReader::visitTimingType(LibertyAttr *attr) -{ - if (timing_) { - const char *type_name = getAttrString(attr); - if (type_name) { - TimingType type = findTimingType(type_name); - if (type == TimingType::unknown) - libWarn(1244, attr, "unknown timing_type %s.", type_name); - else - timing_->attrs()->setTimingType(type); - } - } -} - -void -LibertyReader::visitTimingSense(LibertyAttr *attr) -{ - if (timing_) { - const char *sense_name = getAttrString(attr); - if (sense_name) { - if (stringEq(sense_name, "non_unate")) - timing_->attrs()->setTimingSense(TimingSense::non_unate); - else if (stringEq(sense_name, "positive_unate")) - timing_->attrs()->setTimingSense(TimingSense::positive_unate); - else if (stringEq(sense_name, "negative_unate")) - timing_->attrs()->setTimingSense(TimingSense::negative_unate); - else - libWarn(1245, attr, "unknown timing_sense %s.", sense_name); - } - } -} - -void -LibertyReader::visitSdfCondStart(LibertyAttr *attr) -{ - if (timing_) { - const char *cond = getAttrString(attr); - if (cond) - timing_->attrs()->setSdfCondStart(cond); - } -} - -void -LibertyReader::visitSdfCondEnd(LibertyAttr *attr) -{ - if (timing_) { - const char *cond = getAttrString(attr); - if (cond) - timing_->attrs()->setSdfCondEnd(cond); - } -} - -void -LibertyReader::visitMode(LibertyAttr *attr) -{ - if (timing_) { - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *values = attr->values(); - if (values->size() == 2) { - LibertyAttrValue *value = (*values)[0]; - if (value->isString()) - timing_->attrs()->setModeName(value->stringValue()); - else - libWarn(1248, attr, "mode name is not a string."); - - value = (*values)[1]; - if (value->isString()) - timing_->attrs()->setModeValue(value->stringValue()); - else - libWarn(1246, attr, "mode value is not a string."); - } - else - libWarn(1249, attr, "mode requirees 2 values."); - } - else - libWarn(1250, attr, "mode missing mode name and value."); - } -} - -void -LibertyReader::visitIntrinsicRise(LibertyAttr *attr) -{ - visitIntrinsic(attr, RiseFall::rise()); -} - -void -LibertyReader::visitIntrinsicFall(LibertyAttr *attr) -{ - visitIntrinsic(attr, RiseFall::fall()); -} - -void -LibertyReader::visitIntrinsic(LibertyAttr *attr, - const RiseFall *rf) -{ - if (timing_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - timing_->setIntrinsic(rf, value * time_scale_); - } -} - -void -LibertyReader::visitRiseResistance(LibertyAttr *attr) -{ - visitRiseFallResistance(attr, RiseFall::rise()); -} - -void -LibertyReader::visitFallResistance(LibertyAttr *attr) -{ - visitRiseFallResistance(attr, RiseFall::fall()); -} - -void -LibertyReader::visitRiseFallResistance(LibertyAttr *attr, - const RiseFall *rf) -{ - if (timing_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - timing_->setResistance(rf, value * res_scale_); - } -} - -void -LibertyReader::beginCellRise(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::cell); -} - -void -LibertyReader::beginCellFall(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::cell); -} - -void -LibertyReader::endCellRiseFall(LibertyGroup *group) -{ - if (table_) { - if (GateTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - timing_->setCell(rf_, table_model); - } - else - libWarn(1251, group, "unsupported model axis."); - } - endTableModel(); -} - -void -LibertyReader::beginRiseTransition(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::transition); -} - -void -LibertyReader::beginFallTransition(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::transition); -} - -void -LibertyReader::endRiseFallTransition(LibertyGroup *group) -{ - if (table_) { - if (GateTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - timing_->setTransition(rf_, table_model); - } - else - libWarn(1252, group, "unsupported model axis."); - } - endTableModel(); -} - -void -LibertyReader::beginRiseConstraint(LibertyGroup *group) -{ - // Scale factor depends on timing_type, which may follow this stmt. - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::unknown); -} - -void -LibertyReader::beginFallConstraint(LibertyGroup *group) -{ - // Scale factor depends on timing_type, which may follow this stmt. - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::unknown); -} - -void -LibertyReader::endRiseFallConstraint(LibertyGroup *group) -{ - if (table_) { - if (CheckTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - timing_->setConstraint(rf_, table_model); - } - else - libWarn(1253, group, "unsupported model axis."); - } - endTableModel(); -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginRiseTransitionDegredation(LibertyGroup *group) -{ - if (library_) - beginTableModel(group, TableTemplateType::delay, - RiseFall::rise(), time_scale_, - ScaleFactorType::transition); -} - -void -LibertyReader::beginFallTransitionDegredation(LibertyGroup *group) -{ - if (library_) - beginTableModel(group, TableTemplateType::delay, - RiseFall::fall(), time_scale_, - ScaleFactorType::transition); -} - -void -LibertyReader::endRiseFallTransitionDegredation(LibertyGroup *group) -{ - if (table_) { - if (LibertyLibrary::checkSlewDegradationAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - library_->setWireSlewDegradationTable(table_model, rf_); - } - else - libWarn(1254, group, "unsupported model axis."); - } - endTableModel(); -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginTimingTableModel(LibertyGroup *group, - const RiseFall *rf, - ScaleFactorType scale_factor_type) -{ - if (timing_) - beginTableModel(group, TableTemplateType::delay, rf, - time_scale_, scale_factor_type); - else - libWarn(1255, group, "%s group not in timing group.", group->type().c_str()); -} - -void -LibertyReader::beginTableModel(LibertyGroup *group, - TableTemplateType type, - const RiseFall *rf, - float scale, - ScaleFactorType scale_factor_type) -{ - beginTable(group, type, scale); - rf_ = rf; - scale_factor_type_ = scale_factor_type; - sigma_type_ = EarlyLateAll::all(); -} - -void -LibertyReader::endTableModel() -{ - endTable(); - scale_factor_type_ = ScaleFactorType::unknown; - sigma_type_ = nullptr; - index_ = 0; -} - -void -LibertyReader::beginTable(LibertyGroup *group, - TableTemplateType type, - float scale) -{ - const char *template_name = group->firstName(); - if (library_ && template_name) { - tbl_template_ = library_->findTableTemplate(template_name, type); - if (tbl_template_) { - axis_[0] = tbl_template_->axis1ptr(); - axis_[1] = tbl_template_->axis2ptr(); - axis_[2] = tbl_template_->axis3ptr(); - } - else { - libWarn(1256, group, "table template %s not found.", template_name); - axis_[0] = nullptr; - axis_[1] = nullptr; - axis_[2] = nullptr; - } - clearAxisValues(); - table_ = nullptr; - table_model_scale_ = scale; - } -} - -void -LibertyReader::endTable() -{ - table_ = nullptr; - tbl_template_ = nullptr; - axis_[0] = nullptr; - axis_[1] = nullptr; - axis_[2] = nullptr; -} - -void -LibertyReader::visitValue(LibertyAttr *attr) -{ - if (leakage_power_) { - float value; - bool valid; - getAttrFloat(attr, value, valid); - if (valid) - leakage_power_->setPower(value * power_scale_); - } -} - -void -LibertyReader::visitValues(LibertyAttr *attr) -{ - if (tbl_template_ - // Ignore values in ecsm_waveform groups. - && !in_ecsm_waveform_) - makeTable(attr, table_model_scale_); -} - -void -LibertyReader::makeTable(LibertyAttr *attr, - float scale) -{ - if (attr->isComplexAttr()) { - makeTableAxis(0, attr); - makeTableAxis(1, attr); - makeTableAxis(2, attr); - if (axis_[0] && axis_[1] && axis_[2]) { - // 3D table - // Column index1*size(index2) + index2 - // Row index3 - table_ = make_shared
(makeFloatTable(attr, - axis_[0]->size() * axis_[1]->size(), - axis_[2]->size(), scale), - axis_[0], axis_[1], axis_[2]); - } - else if (axis_[0] && axis_[1]) { - // 2D table - // Row variable1/axis[0] - // Column variable2/axis[1] - table_ = make_shared
(makeFloatTable(attr, axis_[0]->size(), - axis_[1]->size(), scale), - axis_[0], axis_[1]); - } - else if (axis_[0]) { - // 1D table - FloatTable table = makeFloatTable(attr, 1, axis_[0]->size(), scale); - table_ = make_shared
(std::move(table[0]), axis_[0]); - } - else if (axis_[0] == nullptr && axis_[1] == nullptr && axis_[2] == nullptr) { - // scalar - FloatTable table = makeFloatTable(attr, 1, 1, scale); - float value = table[0][0]; - table_ = make_shared
(value); - } - } - else - libWarn(1257, attr, "%s is missing values.", attr->name().c_str()); -} - FloatTable -LibertyReader::makeFloatTable(LibertyAttr *attr, +LibertyReader::makeFloatTable(const LibertyComplexAttr *values_attr, + const LibertyGroup *table_group, size_t rows, size_t cols, float scale) { FloatTable table; table.reserve(rows); - for (LibertyAttrValue *value : *attr->values()) { + for (const LibertyAttrValue *value : values_attr->values()) { FloatSeq row; + row.reserve(cols); if (value->isString()) - row = parseStringFloatList(value->stringValue(), scale, attr); + row = parseStringFloatList(value->stringValue(), scale, values_attr); else if (value->isFloat()) row.push_back(value->floatValue() * scale); else - libWarn(1258, attr, "%s is not a list of floats.", attr->name().c_str()); + libWarn(1258, values_attr, "%s is not a list of floats.", + values_attr->name().c_str()); if (row.size() != cols) { - libWarn(1259, attr, "table row has %zu columns but axis has %zu.", + libWarn(1259, values_attr, "%s row has %zu columns but axis has %zu.", + table_group->type().c_str(), row.size(), cols); for (size_t c = row.size(); c < cols; c++) @@ -4763,9 +3150,14 @@ LibertyReader::makeFloatTable(LibertyAttr *attr, table.push_back(std::move(row)); } if (table.size() != rows) { - libWarn(1260, attr, "table has %zu rows but axis has %zu.", - table.size(), - rows); + if (rows == 0) + libWarn(1260, values_attr, "%s missing axis values.", + table_group->type().c_str()); + else + libWarn(1261, values_attr, "%s has %zu rows but axis has %zu.", + table_group->type().c_str(), + table.size(), + rows); for (size_t r = table.size(); r < rows; r++) { FloatSeq row(cols, 0.0); table.push_back(std::move(row)); @@ -4774,254 +3166,55 @@ LibertyReader::makeFloatTable(LibertyAttr *attr, return table; } -void -LibertyReader::makeTableAxis(int index, - LibertyAttr *attr) -{ - if (axis_[index] && !axis_values_[index].empty()) { - TableAxisVariable var = axis_[index]->variable(); - const Units *units = library_->units(); - float scale = tableVariableUnit(var, units)->scale(); - FloatSeq values = std::move(axis_values_[index]); - scaleFloats(values, scale); - axis_[index] = make_shared(var, std::move(values)); - } - else if (axis_[index] && axis_[index]->values().empty()) { - libWarn(1344, attr, "Table axis and template missing values."); - axis_[index] = nullptr; - axis_values_[index].clear(); - } -} - -//////////////////////////////////////////////////////////////// - -// Define lut output variables as internal ports. -// I can't find any documentation for this group. -void -LibertyReader::beginLut(LibertyGroup *group) -{ - if (cell_) { - for (LibertyAttrValue *param : *group->params()) { - if (param->isString()) { - const std::string &names = param->stringValue(); - // Parse space separated list of related port names. - TokenParser parser(names.c_str(), " "); - while (parser.hasNext()) { - char *name = parser.next(); - if (name[0] != '\0') { - LibertyPort *port = makePort(cell_, name); - port->setDirection(PortDirection::internal()); - } - } - } - else - libWarn(1261, group, "lut output is not a string."); - } - } -} - -void -LibertyReader::endLut(LibertyGroup *) -{ -} - //////////////////////////////////////////////////////////////// void -LibertyReader::beginTestCell(LibertyGroup *group) -{ - if (cell_ && cell_->testCell()) - libWarn(1262, group, "cell %s test_cell redefinition.", cell_->name()); - else { - string name = cell_->name(); - name += "/test_cell"; - test_cell_ = new TestCell(cell_->libertyLibrary(), std::move(name), - cell_->filename()); - cell_->setTestCell(test_cell_); - - // Do a recursive parse of cell into the test_cell because it has - // pins, buses, bundles, and sequentials just like a cell. - save_cell_ = cell_; - save_cell_port_groups_ = std::move(cell_port_groups_); - save_statetable_ = statetable_; - statetable_ = nullptr; - save_cell_sequentials_ = std::move(cell_sequentials_); - save_cell_funcs_ = std::move(cell_funcs_); - cell_ = test_cell_; - } -} - -void -LibertyReader::endTestCell(LibertyGroup *) -{ - makeCellSequentials(); - makeStatetable(); - parseCellFuncs(); - finishPortGroups(); - - // Restore reader state to enclosing cell. - cell_port_groups_ = std::move(save_cell_port_groups_); - statetable_ = save_statetable_; - cell_sequentials_ = std::move(save_cell_sequentials_); - cell_funcs_= std::move(save_cell_funcs_); - cell_ = save_cell_; - - test_cell_ = nullptr; - save_statetable_ = nullptr; -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginModeDef(LibertyGroup *group) -{ - const char *name = group->firstName(); - if (name) - mode_def_ = cell_->makeModeDef(name); - else - libWarn(1263, group, "mode definition missing name."); -} - -void -LibertyReader::endModeDef(LibertyGroup *) -{ - mode_def_ = nullptr; -} - -void -LibertyReader::beginModeValue(LibertyGroup *group) -{ - if (mode_def_) { - const char *name = group->firstName(); - if (name) - mode_value_ = mode_def_->defineValue(name, nullptr, nullptr); - else - libWarn(1264, group, "mode value missing name."); - } -} - -void - LibertyReader::endModeValue(LibertyGroup *) -{ - mode_value_ = nullptr; -} - -void -LibertyReader::visitWhen(LibertyAttr *attr) -{ - if (tbl_template_) - libWarn(1265, attr, "when attribute inside table model."); - if (mode_value_) { - const char *func = getAttrString(attr); - if (func) { - ModeValueDef *mode_value = mode_value_; - makeLibertyFunc(func, - [mode_value] (FuncExpr *expr) {mode_value->setCond(expr);}, - false, "when", attr); - } - } - if (timing_ && !in_ccsn_) { - const char *func = getAttrString(attr); - if (func) { - TimingArcAttrs *attrs = timing_->attrs().get(); - makeLibertyFunc(func, - [attrs] (FuncExpr *expr) { attrs->setCond(expr);}, - false, "when", attr); - } - } - if (internal_power_) { - const char *func = getAttrString(attr); - if (func) { - InternalPowerGroup *internal_pwr = internal_power_; - makeLibertyFunc(func, - [internal_pwr] (FuncExpr *expr) { - internal_pwr->setWhen(std::shared_ptr(expr)); - }, - false, "when", attr); - } - } - if (leakage_power_) { - const char *func = getAttrString(attr); - if (func) { - LeakagePowerGroup *leakage_pwr = leakage_power_; - makeLibertyFunc(func, - [leakage_pwr] (FuncExpr *expr) { leakage_pwr->setWhen(expr);}, - false, "when", attr); - } - } -} - -void -LibertyReader::visitSdfCond(LibertyAttr *attr) -{ - if (mode_value_) { - const char *cond = getAttrString(attr); - if (cond) - mode_value_->setSdfCond(cond); - } - else if (timing_) { - const char *cond = getAttrString(attr); - if (cond) - timing_->attrs()->setSdfCond(cond); - } - // sdf_cond can also appear inside minimum_period groups. -} - -//////////////////////////////////////////////////////////////// - -const char * -LibertyReader::getAttrString(LibertyAttr *attr) -{ - if (attr->isSimpleAttr()) { - LibertyAttrValue *value = attr->firstValue(); - if (value->isString()) - return value->stringValue().c_str(); - else - libWarn(1266, attr, "%s attribute is not a string.", attr->name().c_str()); - } - else - libWarn(1267, attr, "%s is not a simple attribute.", attr->name().c_str()); - return nullptr; -} - -void -LibertyReader::getAttrInt(LibertyAttr *attr, +LibertyReader::getAttrInt(const LibertySimpleAttr *attr, // Return values. int &value, bool &exists) { value = 0; exists = false; - if (attr->isSimpleAttr()) { - LibertyAttrValue *attr_value = attr->firstValue(); - if (attr_value->isFloat()) { - float float_val = attr_value->floatValue(); - value = static_cast(float_val); - exists = true; - } - else - libWarn(1268, attr, "%s attribute is not an integer.",attr->name().c_str()); + const LibertyAttrValue &attr_value = attr->value(); + if (attr_value.isFloat()) { + float float_val = attr_value.floatValue(); + value = static_cast(float_val); + exists = true; } else - libWarn(1269, attr, "%s is not a simple attribute.", attr->name().c_str()); + libWarn(1268, attr, "%s attribute is not an integer.",attr->name().c_str()); } +// Get two floats in a complex attribute. +// attr(float1, float2); void -LibertyReader::getAttrFloat(LibertyAttr *attr, - // Return values. - float &value, - bool &valid) +LibertyReader::getAttrFloat2(const LibertyComplexAttr *attr, + // Return values. + float &value1, + float &value2, + bool &exists) { - valid = false; - if (attr->isSimpleAttr()) - getAttrFloat(attr, attr->firstValue(), value, valid); + exists = false; + const LibertyAttrValueSeq &values = attr->values(); + if (values.size() == 2) { + LibertyAttrValue *value = values[0]; + getAttrFloat(attr, value, value1, exists); + if (!exists) + libWarn(1272, attr, "%s is not a float.", attr->name().c_str()); + + value = values[1]; + getAttrFloat(attr, value, value2, exists); + if (!exists) + libWarn(1273, attr, "%s is not a float.", attr->name().c_str()); + } else - libWarn(1270, attr, "%s is not a simple attribute.", attr->name().c_str()); + libWarn(1274, attr, "%s requires 2 valules.", attr->name().c_str()); } void -LibertyReader::getAttrFloat(LibertyAttr *attr, - LibertyAttrValue *attr_value, +LibertyReader::getAttrFloat(const LibertyComplexAttr *attr, + const LibertyAttrValue *attr_value, // Return values. float &value, bool &valid) @@ -5032,17 +3225,13 @@ LibertyReader::getAttrFloat(LibertyAttr *attr, } else if (attr_value->isString()) { const std::string &str = attr_value->stringValue(); - // See if attribute string is a variable. variableValue(str.c_str(), value, valid); if (!valid) { - // For some reason area attributes for pads are quoted floats. - // Check that the string is a valid double. char *end; value = strtof(str.c_str(), &end); if ((*end && !isspace(*end)) - // strtof support INF as a valid float. || str == "inf") - libWarn(1271, attr, "%s value %s is not a float.", + libWarn(1183, attr->line(), "%s value %s is not a float.", attr->name().c_str(), str.c_str()); valid = true; @@ -5050,48 +3239,56 @@ LibertyReader::getAttrFloat(LibertyAttr *attr, } } -// Get two floats in a complex attribute. -// attr(float1, float2); -void -LibertyReader::getAttrFloat2(LibertyAttr *attr, - // Return values. - float &value1, - float &value2, - bool &exists) -{ - exists = false; - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *values = attr->values(); - if (values->size() == 2) { - LibertyAttrValue *value = (*values)[0]; - getAttrFloat(attr, value, value1, exists); - if (!exists) - libWarn(1272, attr, "%s is not a float.", attr->name().c_str()); - - value = (*values)[1]; - getAttrFloat(attr, value, value2, exists); - if (!exists) - libWarn(1273, attr, "%s is not a float.", attr->name().c_str()); - } - else - libWarn(1274, attr, "%s requires 2 valules.", attr->name().c_str()); - } - else - libWarn(1345, attr, "%s requires 2 valules.", attr->name().c_str()); -} - // Parse string of comma separated floats. // Note that some brain damaged vendors (that used to "Think") are not // consistent about including the delimiters. FloatSeq LibertyReader::parseStringFloatList(const std::string &float_list, float scale, - LibertyAttr *attr) + const LibertySimpleAttr *attr) { FloatSeq values; + values.reserve(std::max(10, float_list.size() / 5)); const char *token = float_list.c_str(); while (*token != '\0') { // Some (brain dead) libraries enclose floats in brackets. + if (*token == '{') + token++; + char *end; + float value = strtof(token, &end) * scale; + if (end == token + || !(*end == '\0' + || isspace(*end) + || *end == ',' + || *end == '}')) { + std::string token_end = token; + if (end != token) { + token_end.clear(); + for (const char *t = token; t <= end; t++) + token_end += *t; + } + libWarn(1310, attr, "%s is not a float.", token_end.c_str()); + token += token_end.size(); + } + else { + values.push_back(value); + token = end; + } + while (*token == ',' || *token == ' ' || *token == '}') + token++; + } + return values; +} + +FloatSeq +LibertyReader::parseStringFloatList(const std::string &float_list, + float scale, + const LibertyComplexAttr *attr) +{ + FloatSeq values; + values.reserve(std::max(10, float_list.size() / 5)); + const char *token = float_list.c_str(); + while (*token != '\0') { if (*token == '{') token++; char *end; @@ -5121,108 +3318,93 @@ LibertyReader::parseStringFloatList(const std::string &float_list, } FloatSeq -LibertyReader::readFloatSeq(LibertyAttr *attr, +LibertyReader::readFloatSeq(const LibertyComplexAttr *attr, float scale) { FloatSeq values; - if (attr->isComplexAttr()) { - LibertyAttrValueSeq *attr_values = attr->values(); - if (attr_values->size() == 1) { - LibertyAttrValue *value = (*attr_values)[0]; - if (value->isString()) { - values = parseStringFloatList(value->stringValue(), scale, attr); - } - else if (value->isFloat()) { - values.push_back(value->floatValue()); - } - else - libWarn(1276, attr, "%s is missing values.", attr->name().c_str()); - } - else - libWarn(1277, attr, "%s has more than one string.", attr->name().c_str()); - } - else { - LibertyAttrValue *value = attr->firstValue(); + const LibertyAttrValueSeq &attr_values = attr->values(); + if (attr_values.size() == 1) { + LibertyAttrValue *value = attr_values[0]; if (value->isString()) { values = parseStringFloatList(value->stringValue(), scale, attr); } + else if (value->isFloat()) { + values.push_back(value->floatValue() * scale); + } else - libWarn(1278, attr, "%s is missing values.", attr->name().c_str()); + libWarn(1276, attr, "%s is missing values.", attr->name().c_str()); } + else if (attr_values.size() > 1) { + for (LibertyAttrValue *val : attr_values) { + if (val->isFloat()) + values.push_back(val->floatValue() * scale); + else if (val->isString()) { + FloatSeq parsed = parseStringFloatList(val->stringValue(), scale, attr); + values.insert(values.end(), parsed.begin(), parsed.end()); + } + } + } + else + libWarn(1277, attr, "%s has no values.", attr->name().c_str()); return values; } +//////////////////////////////////////////////////////////////// + void -LibertyReader::getAttrBool(LibertyAttr *attr, +LibertyReader::getAttrBool(const LibertySimpleAttr *attr, // Return values. bool &value, bool &exists) { exists = false; - if (attr->isSimpleAttr()) { - LibertyAttrValue *val = attr->firstValue(); - if (val->isString()) { - const std::string &str = val->stringValue(); - if (stringEqual(str.c_str(), "true")) { - value = true; - exists = true; - } - else if (stringEqual(str.c_str(), "false")) { - value = false; - exists = true; - } - else - libWarn(1279, attr, "%s attribute is not boolean.", attr->name().c_str()); + const LibertyAttrValue &val = attr->value(); + if (val.isString()) { + const std::string &str = val.stringValue(); + if (stringEqual(str.c_str(), "true")) { + value = true; + exists = true; + } + else if (stringEqual(str.c_str(), "false")) { + value = false; + exists = true; } else - libWarn(1280, attr, "%s attribute is not boolean.", attr->name().c_str()); + libWarn(1288, attr, "%s attribute is not boolean.", attr->name().c_str()); } else - libWarn(1281, attr, "%s is not a simple attribute.", attr->name().c_str()); + libWarn(1289, attr, "%s attribute is not boolean.", attr->name().c_str()); } // Read L/H/X string attribute values as bool. LogicValue -LibertyReader::getAttrLogicValue(LibertyAttr *attr) +LibertyReader::getAttrLogicValue(const LibertySimpleAttr *attr) { - const char *str = getAttrString(attr); + const std::string *str = attr->stringValue(); if (str) { - if (stringEq(str, "L")) + if (*str == "L") return LogicValue::zero; - else if (stringEq(str, "H")) + else if (*str == "H") return LogicValue::one; - else if (stringEq(str, "X")) + else if (*str == "X") return LogicValue::unknown; else libWarn(1282, attr, "attribute %s value %s not recognized.", - attr->name().c_str(), str); + attr->name().c_str(), str->c_str()); // fall thru } return LogicValue::unknown; } -FuncExpr * -LibertyReader::parseFunc(const char *func, - const char *attr_name, - int line) -{ - string error_msg; - stringPrint(error_msg, "%s, line %d %s", - filename_, - line, - attr_name); - return parseFuncExpr(func, cell_, error_msg.c_str(), report_); -} - const EarlyLateAll * -LibertyReader::getAttrEarlyLate(LibertyAttr *attr) +LibertyReader::getAttrEarlyLate(const LibertySimpleAttr *attr) { - const char *value = getAttrString(attr); - if (stringEq(value, "early")) + const std::string *value = attr->stringValue(); + if (*value == "early") return EarlyLateAll::early(); - else if (stringEq(value, "late")) + else if (*value == "late") return EarlyLateAll::late(); - else if (stringEq(value, "early_and_late")) + else if (*value == "early_and_late") return EarlyLateAll::all(); else { libWarn(1283, attr, "unknown early/late value."); @@ -5232,16 +3414,30 @@ LibertyReader::getAttrEarlyLate(LibertyAttr *attr) //////////////////////////////////////////////////////////////// +FuncExpr * +LibertyReader::parseFunc(const char *func, + const char *attr_name, + const LibertyCell *cell, + int line) +{ + std::string error_msg; + stringPrint(error_msg, "%s, line %d %s", + filename_, + line, + attr_name); + return parseFuncExpr(func, cell, error_msg.c_str(), report_); +} + +//////////////////////////////////////////////////////////////// + void LibertyReader::visitVariable(LibertyVariable *var) { - if (var_map_ == nullptr) - var_map_ = new LibertyVariableMap; - const string &var_name = var->variable(); + const std::string &var_name = var->variable(); float value; bool exists; findKeyValue(var_map_, var_name, value, exists); - (*var_map_)[var_name] = var->value(); + var_map_[var_name] = var->value(); } void @@ -5249,23 +3445,44 @@ LibertyReader::variableValue(const char *var, float &value, bool &exists) { - if (var_map_) - findKeyValue(var_map_, var, value, exists); - else - exists = false; + findKeyValue(var_map_, var, value, exists); } //////////////////////////////////////////////////////////////// void LibertyReader::libWarn(int id, - LibertyStmt *stmt, + const LibertyGroup *obj, const char *fmt, ...) { va_list args; va_start(args, fmt); - report_->vfileWarn(id, filename_, stmt->line(), fmt, args); + report_->vfileWarn(id, filename_, obj->line(), fmt, args); + va_end(args); +} + +void +LibertyReader::libWarn(int id, + const LibertySimpleAttr *obj, + const char *fmt, + ...) +{ + va_list args; + va_start(args, fmt); + report_->vfileWarn(id, filename_, obj->line(), fmt, args); + va_end(args); +} + +void +LibertyReader::libWarn(int id, + const LibertyComplexAttr *obj, + const char *fmt, + ...) +{ + va_list args; + va_start(args, fmt); + report_->vfileWarn(id, filename_, obj->line(), fmt, args); va_end(args); } @@ -5283,821 +3500,138 @@ LibertyReader::libWarn(int id, void LibertyReader::libError(int id, - LibertyStmt *stmt, + const LibertyGroup *obj, const char *fmt, ...) { va_list args; va_start(args, fmt); - report_->vfileError(id, filename_, stmt->line(), fmt, args); + report_->vfileError(id, filename_, obj->line(), fmt, args); + va_end(args); +} + +void +LibertyReader::libError(int id, + const LibertySimpleAttr *obj, + const char *fmt, + ...) +{ + va_list args; + va_start(args, fmt); + report_->vfileError(id, filename_, obj->line(), fmt, args); + va_end(args); +} + +void +LibertyReader::libError(int id, + const LibertyComplexAttr *obj, + const char *fmt, + ...) +{ + va_list args; + va_start(args, fmt); + report_->vfileError(id, filename_, obj->line(), fmt, args); va_end(args); } //////////////////////////////////////////////////////////////// void -LibertyReader::beginTableTemplatePower(LibertyGroup *group) +LibertyReader::readDefaultOcvDerateGroup(const LibertyGroup *library_group) { - beginTableTemplate(group, TableTemplateType::power); -} - -void -LibertyReader::beginLeakagePower(LibertyGroup *group) -{ - if (cell_) { - leakage_power_ = new LeakagePowerGroup(group->line()); - leakage_powers_.push_back(leakage_power_); - } -} - -void -LibertyReader::endLeakagePower(LibertyGroup *) -{ - leakage_power_ = nullptr; -} - -void -LibertyReader::beginInternalPower(LibertyGroup *group) -{ - if (port_group_) { - internal_power_ = new InternalPowerGroup(group->line()); - port_group_->addInternalPowerGroup(internal_power_); - } -} - -void -LibertyReader::endInternalPower(LibertyGroup *) -{ - internal_power_ = nullptr; -} - -void -LibertyReader::beginFallPower(LibertyGroup *group) -{ - if (internal_power_) - beginTableModel(group, TableTemplateType::power, - RiseFall::fall(), energy_scale_, - ScaleFactorType::internal_power); -} - -void -LibertyReader::beginRisePower(LibertyGroup *group) -{ - if (internal_power_) - beginTableModel(group, TableTemplateType::power, - RiseFall::rise(), energy_scale_, - ScaleFactorType::internal_power); -} - -void -LibertyReader::endRiseFallPower(LibertyGroup *) -{ - if (table_) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - internal_power_->setModel(rf_, std::make_shared(table_model)); - } - endTableModel(); -} - -void -LibertyReader::endPower(LibertyGroup *) -{ - if (table_) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - // Share the model for rise/fall. - auto power_model = std::make_shared(table_model); - internal_power_->setModel(RiseFall::rise(), power_model); - internal_power_->setModel(RiseFall::fall(), power_model); - } - endTableModel(); -} - -void -LibertyReader::visitRelatedGroundPin(LibertyAttr *attr) -{ - if (ports_) { - const char *related_ground_pin = getAttrString(attr); - for (LibertyPort *port : *ports_) - port->setRelatedGroundPin(related_ground_pin); - } -} - -void -LibertyReader::visitRelatedPowerPin(LibertyAttr *attr) -{ - if (ports_) { - const char *related_power_pin = getAttrString(attr); - for (LibertyPort *port : *ports_) - port->setRelatedPowerPin(related_power_pin); - } -} - -void -LibertyReader::visitRelatedPgPin(LibertyAttr *attr) -{ - if (internal_power_) - internal_power_->setRelatedPgPin(getAttrString(attr)); - else if (leakage_power_) - leakage_power_->setRelatedPgPin(getAttrString(attr)); -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginTableTemplateOcv(LibertyGroup *group) -{ - beginTableTemplate(group, TableTemplateType::ocv); -} - -void -LibertyReader::visitOcvArcDepth(LibertyAttr *attr) -{ - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) { - if (timing_) - timing_->attrs()->setOcvArcDepth(value); - else if (cell_) - cell_->setOcvArcDepth(value); + const std::string *derate_name = + library_group->findAttrString("default_ocv_derate_group"); + if (derate_name) { + OcvDerate *derate = library_->findOcvDerate(derate_name->c_str()); + if (derate) + library_->setDefaultOcvDerate(derate); else - library_->setOcvArcDepth(value); + libWarn(1284, library_group, "OCV derate group named %s not found.", + derate_name->c_str()); } } +// Read cell or library level ocv_derate groups. void -LibertyReader::visitDefaultOcvDerateGroup(LibertyAttr *attr) +LibertyReader::readOcvDerateFactors(LibertyCell *cell, + const LibertyGroup *parent_group) { - const char *derate_name = getAttrString(attr); - OcvDerate *derate = library_->findOcvDerate(derate_name); - if (derate) - library_->setDefaultOcvDerate(derate); - else - libWarn(1284, attr, "OCV derate group named %s not found.", derate_name); -} - -void -LibertyReader::visitOcvDerateGroup(LibertyAttr *attr) -{ - ocv_derate_name_ = stringCopy(getAttrString(attr)); -} - -void -LibertyReader::beginOcvDerate(LibertyGroup *group) -{ - const char *name = group->firstName(); - if (name) - ocv_derate_ = library_->makeOcvDerate(name); - else - libWarn(1285, group, "ocv_derate missing name."); -} - -void -LibertyReader::endOcvDerate(LibertyGroup *) -{ - ocv_derate_ = nullptr; -} - -void -LibertyReader::beginOcvDerateFactors(LibertyGroup *group) -{ - if (ocv_derate_) { - rf_type_ = RiseFallBoth::riseFall(); - derate_type_ = EarlyLateAll::all(); - path_type_ = PathType::clk_and_data; - beginTable(group, TableTemplateType::ocv, 1.0); - } -} - -void -LibertyReader::endOcvDerateFactors(LibertyGroup *) -{ - if (ocv_derate_) { - for (auto early_late : derate_type_->range()) { - for (auto rf : rf_type_->range()) { - if (path_type_ == PathType::clk_and_data) { - ocv_derate_->setDerateTable(rf, early_late, PathType::clk, table_); - ocv_derate_->setDerateTable(rf, early_late, PathType::data, table_); + for (const LibertyGroup *ocv_derate_group : + parent_group->findSubgroups("ocv_derate")) { + const char *name = ocv_derate_group->firstName(); + if (name) { + OcvDerate *ocv_derate = cell + ? cell->makeOcvDerate(name) + : library_->makeOcvDerate(name); + for (const LibertyGroup *factors_group : + ocv_derate_group->findSubgroups("ocv_derate_factors")) { + const RiseFallBoth *rf_type = RiseFallBoth::riseFall(); + const std::string *rf_attr = factors_group->findAttrString("rf_type"); + if (rf_attr) { + if (*rf_attr == "rise") + rf_type = RiseFallBoth::rise(); + else if (*rf_attr == "fall") + rf_type = RiseFallBoth::fall(); + else if (*rf_attr == "rise_and_fall") + rf_type = RiseFallBoth::riseFall(); + else + libError(1286, factors_group, "unknown rise/fall."); + } + + const EarlyLateAll *derate_type = EarlyLateAll::all(); + const std::string *derate_attr = factors_group->findAttrString("derate_type"); + if (derate_attr) { + if (*derate_attr == "early") + derate_type = EarlyLateAll::early(); + else if (*derate_attr == "late") + derate_type = EarlyLateAll::late(); + else if (*derate_attr == "early_and_late") + derate_type = EarlyLateAll::all(); + else { + libWarn(1309, factors_group, "unknown early/late value."); + } + } + + PathType path_type = PathType::clk_and_data; + const std::string *path_attr = factors_group->findAttrString("path_type"); + if (path_attr) { + if (*path_attr == "clock") + path_type = PathType::clk; + else if (*path_attr == "data") + path_type = PathType::data; + else if (*path_attr == "clock_and_data") + path_type = PathType::clk_and_data; + else + libWarn(1287, factors_group, "unknown derate type."); + } + + const char *template_name = factors_group->firstName(); + if (template_name) { + TableTemplate *tbl_template = + library_->findTableTemplate(template_name, TableTemplateType::ocv); + if (tbl_template) { + TablePtr table = readTableModel(factors_group, tbl_template, 1.0F); + if (table) { + for (const EarlyLate *early_late : derate_type->range()) { + for (const RiseFall *rf : rf_type->range()) { + if (path_type == PathType::clk_and_data) { + ocv_derate->setDerateTable(rf, early_late, PathType::clk, table); + ocv_derate->setDerateTable(rf, early_late, PathType::data, table); + } + else + ocv_derate->setDerateTable(rf, early_late, path_type, table); + } + } + } + } + else + libWarn(1308, factors_group, "table template %s not found.", template_name); } - else - ocv_derate_->setDerateTable(rf, early_late, path_type_, table_); } } - } - endTable(); -} - -void -LibertyReader::visitRfType(LibertyAttr *attr) -{ - const char *rf_name = getAttrString(attr); - if (stringEq(rf_name, "rise")) - rf_type_ = RiseFallBoth::rise(); - else if (stringEq(rf_name, "fall")) - rf_type_ = RiseFallBoth::fall(); - else if (stringEq(rf_name, "rise_and_fall")) - rf_type_ = RiseFallBoth::riseFall(); - else - libError(1286, attr, "unknown rise/fall."); -} - -void -LibertyReader::visitDerateType(LibertyAttr *attr) -{ - derate_type_ = getAttrEarlyLate(attr); -} - -void -LibertyReader::visitPathType(LibertyAttr *attr) -{ - const char *path_type = getAttrString(attr); - if (stringEq(path_type, "clock")) - path_type_ = PathType::clk; - else if (stringEq(path_type, "data")) - path_type_ = PathType::data; - else if (stringEq(path_type, "clock_and_data")) - path_type_ = PathType::clk_and_data; - else - libWarn(1287, attr, "unknown derate type."); -} - -//////////////////////////////////////////////////////////////// - -void -LibertyReader::beginOcvSigmaCellRise(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::unknown); -} - -void -LibertyReader::beginOcvSigmaCellFall(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::unknown); -} - -void -LibertyReader::endOcvSigmaCell(LibertyGroup *group) -{ - if (table_) { - if (GateTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - if (sigma_type_ == EarlyLateAll::all()) { - timing_->setDelaySigma(rf_, EarlyLate::min(), table_model); - timing_->setDelaySigma(rf_, EarlyLate::max(), table_model); - } - else - timing_->setDelaySigma(rf_, sigma_type_->asMinMax(), table_model); - } else - libWarn(1288, group, "unsupported model axis."); + libWarn(1285, ocv_derate_group, "ocv_derate missing name."); } - endTableModel(); -} - -void -LibertyReader::beginOcvSigmaRiseTransition(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::unknown); -} - -void -LibertyReader::beginOcvSigmaFallTransition(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::unknown); -} - -void -LibertyReader::endOcvSigmaTransition(LibertyGroup *group) -{ - if (table_) { - if (GateTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - if (sigma_type_ == EarlyLateAll::all()) { - timing_->setSlewSigma(rf_, EarlyLate::min(), table_model); - timing_->setSlewSigma(rf_, EarlyLate::max(), table_model); - } - else - timing_->setSlewSigma(rf_, sigma_type_->asMinMax(), table_model); - } - else - libWarn(1289, group, "unsupported model axis."); - } - endTableModel(); -} - -void -LibertyReader::beginOcvSigmaRiseConstraint(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::rise(), ScaleFactorType::unknown); -} - -void -LibertyReader::beginOcvSigmaFallConstraint(LibertyGroup *group) -{ - beginTimingTableModel(group, RiseFall::fall(), ScaleFactorType::unknown); -} - -void -LibertyReader::endOcvSigmaConstraint(LibertyGroup *group) -{ - if (table_) { - if (CheckTableModel::checkAxes(table_)) { - TableModel *table_model = new TableModel(table_, tbl_template_, - scale_factor_type_, rf_); - if (sigma_type_ == EarlyLateAll::all()) { - timing_->setConstraintSigma(rf_, EarlyLate::min(), table_model); - timing_->setConstraintSigma(rf_, EarlyLate::max(), table_model); - } - else - timing_->setConstraintSigma(rf_, sigma_type_->asMinMax(), table_model); - } - else - libWarn(1290, group, "unsupported model axis."); - } - endTableModel(); -} - -void -LibertyReader::visitSigmaType(LibertyAttr *attr) -{ - sigma_type_ = getAttrEarlyLate(attr); -} - -void -LibertyReader::visitCellLeakagePower(LibertyAttr *attr) -{ - if (cell_) { - float value; - bool exists; - getAttrFloat(attr, value, exists); - if (exists) - cell_->setLeakagePower(value * power_scale_); - } -} - -void -LibertyReader::beginPgPin(LibertyGroup *group) -{ - if (cell_) { - const char *name = group->firstName(); - pg_port_ = builder_.makePort(cell_, name); - } -} - -void -LibertyReader::endPgPin(LibertyGroup *) -{ - pg_port_ = nullptr; -} - -void -LibertyReader::visitPgType(LibertyAttr *attr) -{ - if (pg_port_) { - const char *type_name = getAttrString(attr); - PwrGndType type = findPwrGndType(type_name); - PortDirection *dir = PortDirection::unknown(); - switch (type) { - case PwrGndType::primary_ground: - case PwrGndType::backup_ground: - case PwrGndType::internal_ground: - dir = PortDirection::ground(); - break; - case PwrGndType::primary_power: - case PwrGndType::backup_power: - case PwrGndType::internal_power: - dir = PortDirection::power(); - break; - case PwrGndType::none: - libError(1291, attr, "unknown pg_type."); - break; - default: - break; - } - pg_port_->setPwrGndType(type); - pg_port_->setDirection(dir); - } -} - -void -LibertyReader::visitVoltageName(LibertyAttr *attr) -{ - if (pg_port_) { - const char *voltage_name = getAttrString(attr); - pg_port_->setVoltageName(voltage_name); - } -} - -// Contents Ignored. -void -LibertyReader::beginCcsn(LibertyGroup *) -{ - in_ccsn_ = true; -} - -void -LibertyReader::endCcsn(LibertyGroup *) -{ - in_ccsn_ = false; -} - -// Contents Ignored. -void -LibertyReader::beginEcsmWaveform(LibertyGroup *) -{ - in_ecsm_waveform_ = true; -} - -void -LibertyReader::endEcsmWaveform(LibertyGroup *) -{ - in_ecsm_waveform_ = false; -} - -//////////////////////////////////////////////////////////////// - -LibertyFunc::LibertyFunc(const char *expr, - LibertySetFunc set_func, - bool invert, - const char *attr_name, - int line) : - expr_(stringCopy(expr)), - set_func_(set_func), - invert_(invert), - attr_name_(stringCopy(attr_name)), - line_(line) -{ -} - -LibertyFunc::~LibertyFunc() -{ - stringDelete(expr_); - stringDelete(attr_name_); -} - -//////////////////////////////////////////////////////////////// - -PortGroup::PortGroup(LibertyPortSeq *ports, - int line) : - ports_(ports), - line_(line) -{ -} - -PortGroup::~PortGroup() -{ - deleteContents(timings_); - delete ports_; - deleteContents(internal_power_groups_); -} - -void -PortGroup::addTimingGroup(TimingGroup *timing) -{ - timings_.push_back(timing); -} - -void -PortGroup::addInternalPowerGroup(InternalPowerGroup *internal_power) -{ - internal_power_groups_.push_back(internal_power); -} - -//////////////////////////////////////////////////////////////// - -SequentialGroup::SequentialGroup(bool is_register, - bool is_bank, - LibertyPort *out_port, - LibertyPort *out_inv_port, - int size, - int line) : - is_register_(is_register), - is_bank_(is_bank), - out_port_(out_port), - out_inv_port_(out_inv_port), - size_(size), - clk_(nullptr), - data_(nullptr), - preset_(nullptr), - clear_(nullptr), - clr_preset_var1_(LogicValue::unknown), - clr_preset_var2_(LogicValue::unknown), - line_(line) -{ -} - -SequentialGroup::~SequentialGroup() -{ - if (clk_) - stringDelete(clk_); - if (data_) - stringDelete(data_); - if (preset_) - stringDelete(preset_); - if (clear_) - stringDelete(clear_); -} - -void -SequentialGroup::setClock(const char *clk) -{ - clk_ = clk; -} - -void -SequentialGroup::setData(const char *data) -{ - data_ = data; -} - -void -SequentialGroup::setClear(const char *clr) -{ - clear_ = clr; -} - -void -SequentialGroup::setPreset(const char *preset) -{ - preset_ = preset; -} - -void -SequentialGroup::setClrPresetVar1(LogicValue var) -{ - clr_preset_var1_ = var; -} - -void -SequentialGroup::setClrPresetVar2(LogicValue var) -{ - clr_preset_var2_ = var; -} - -//////////////////////////////////////////////////////////////// - -StatetableGroup::StatetableGroup(StdStringSeq &input_ports, - StdStringSeq &internal_ports, - int line) : - input_ports_(input_ports), - internal_ports_(internal_ports), - line_(line) -{ -} - -void -StatetableGroup::addRow(StateInputValues &input_values, - StateInternalValues ¤t_values, - StateInternalValues &next_values) -{ - table_.emplace_back(input_values, current_values, next_values); -} - -//////////////////////////////////////////////////////////////// - -RelatedPortGroup::RelatedPortGroup(int line) : - related_port_names_(nullptr), - line_(line) -{ -} - -RelatedPortGroup::~RelatedPortGroup() -{ - if (related_port_names_) { - deleteContents(related_port_names_); - delete related_port_names_; - } -} - -void -RelatedPortGroup::setRelatedPortNames(StringSeq *names) -{ - related_port_names_ = names; -} - -void -RelatedPortGroup::setIsOneToOne(bool one) -{ - is_one_to_one_ = one; -} - -//////////////////////////////////////////////////////////////// - -TimingGroup::TimingGroup(int line) : - RelatedPortGroup(line), - attrs_(make_shared()), - related_output_port_name_(nullptr), - receiver_model_(nullptr) -{ - for (auto rf_index : RiseFall::rangeIndex()) { - cell_[rf_index] = nullptr; - constraint_[rf_index] = nullptr; - transition_[rf_index] = nullptr; - intrinsic_[rf_index] = 0.0F; - intrinsic_exists_[rf_index] = false; - resistance_[rf_index] = 0.0F; - resistance_exists_[rf_index] = false; - output_waveforms_[rf_index] = nullptr; - - for (auto el_index : EarlyLate::rangeIndex()) { - delay_sigma_[rf_index][el_index] = nullptr; - slew_sigma_[rf_index][el_index] = nullptr; - constraint_sigma_[rf_index][el_index] = nullptr; - } - } -} - -TimingGroup::~TimingGroup() -{ - if (related_output_port_name_) - stringDelete(related_output_port_name_); -} - -void -TimingGroup::setRelatedOutputPortName(const char *name) -{ - related_output_port_name_ = stringCopy(name); -} - -void -TimingGroup::setIntrinsic(const RiseFall *rf, - float value) -{ - int rf_index = rf->index(); - intrinsic_[rf_index] = value; - intrinsic_exists_[rf_index] = true; -} - -void -TimingGroup::intrinsic(const RiseFall *rf, - // Return values. - float &value, - bool &exists) -{ - int rf_index = rf->index(); - value = intrinsic_[rf_index]; - exists = intrinsic_exists_[rf_index]; -} - -void -TimingGroup::setResistance(const RiseFall *rf, - float value) -{ - int rf_index = rf->index(); - resistance_[rf_index] = value; - resistance_exists_[rf_index] = true; -} - -void -TimingGroup::resistance(const RiseFall *rf, - // Return values. - float &value, - bool &exists) -{ - int rf_index = rf->index(); - value = resistance_[rf_index]; - exists = resistance_exists_[rf_index]; -} - -TableModel * -TimingGroup::cell(const RiseFall *rf) -{ - return cell_[rf->index()]; -} - -void -TimingGroup::setCell(const RiseFall *rf, - TableModel *model) -{ - cell_[rf->index()] = model; -} - -TableModel * -TimingGroup::constraint(const RiseFall *rf) -{ - return constraint_[rf->index()]; -} - -void -TimingGroup::setConstraint(const RiseFall *rf, - TableModel *model) -{ - constraint_[rf->index()] = model; -} - -TableModel * -TimingGroup::transition(const RiseFall *rf) -{ - return transition_[rf->index()]; -} - -void -TimingGroup::setTransition(const RiseFall *rf, - TableModel *model) -{ - transition_[rf->index()] = model; -} - -void -TimingGroup::setDelaySigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model) -{ - delay_sigma_[rf->index()][early_late->index()] = model; -} - -void -TimingGroup::setSlewSigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model) -{ - slew_sigma_[rf->index()][early_late->index()] = model; -} - -void -TimingGroup::setConstraintSigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model) -{ - constraint_sigma_[rf->index()][early_late->index()] = model; -} - -void -TimingGroup::setReceiverModel(ReceiverModelPtr receiver_model) -{ - receiver_model_ = receiver_model; -} - -OutputWaveforms * -TimingGroup::outputWaveforms(const RiseFall *rf) -{ - return output_waveforms_[rf->index()]; -} - -void -TimingGroup::setOutputWaveforms(const RiseFall *rf, - OutputWaveforms *output_waveforms) -{ - output_waveforms_[rf->index()] = output_waveforms; -} - -//////////////////////////////////////////////////////////////// - -InternalPowerGroup::InternalPowerGroup(int line) : - RelatedPortGroup(line), - when_(), - models_{} -{ -} - -void -InternalPowerGroup::setWhen(std::shared_ptr when) -{ - when_ = std::move(when); -} - -void -InternalPowerGroup::setModel(const RiseFall *rf, - std::shared_ptr model) -{ - models_[rf->index()] = std::move(model); -} - -void -InternalPowerGroup::setRelatedPgPin(std::string related_pg_pin) -{ - related_pg_pin_ = std::move(related_pg_pin); -} - -//////////////////////////////////////////////////////////////// - -LeakagePowerGroup::LeakagePowerGroup(int line) : - when_(nullptr), - power_(0.0), - line_(line) -{ -} - -void -LeakagePowerGroup::setRelatedPgPin(std::string pin_name) -{ - related_pg_pin_ = std::move(pin_name); -} - -void -LeakagePowerGroup::setWhen(FuncExpr *when) -{ - when_ = when; -} - -void -LeakagePowerGroup::setPower(float power) -{ - power_ = power; } //////////////////////////////////////////////////////////////// @@ -6121,7 +3655,7 @@ PortNameBitIterator::PortNameBitIterator(LibertyCell *cell, void PortNameBitIterator::init(const char *port_name) { - LibertyPort *port = visitor_->findPort(port_name); + LibertyPort *port = visitor_->findPort(cell_, port_name); if (port) { if (port->isBus()) bit_iterator_ = new LibertyPortMemberIterator(port); @@ -6133,13 +3667,13 @@ PortNameBitIterator::init(const char *port_name) // Check for bus range. LibertyLibrary *library = visitor_->library(); bool is_bus, is_range, subscript_wild; - string bus_name; + std::string bus_name; int from, to; parseBusName(port_name, library->busBrktLeft(), library->busBrktRight(), '\\', is_bus, is_range, bus_name, from, to, subscript_wild); if (is_range) { - port = visitor_->findPort(port_name); + port = visitor_->findPort(cell_, port_name); if (port) { if (port->isBus()) { if (port->busIndexInRange(from) @@ -6224,13 +3758,9 @@ PortNameBitIterator::findRangeBusNameNext() ? range_bit_ >= range_to_ : range_bit_ <= range_to_) { LibertyLibrary *library = visitor_->library(); - string bus_bit_name; - stringPrint(bus_bit_name, "%s%c%d%c", - range_bus_name_.c_str(), - library->busBrktLeft(), - range_bit_, - library->busBrktRight()); - range_name_next_ = visitor_->findPort(bus_bit_name.c_str()); + std::string bus_bit_name = range_bus_name_ + library->busBrktLeft() + + std::to_string(range_bit_) + library->busBrktRight(); + range_name_next_ = visitor_->findPort(cell_, bus_bit_name.c_str()); if (range_name_next_) { if (range_from_ > range_to_) range_bit_--; @@ -6257,17 +3787,10 @@ OutputWaveform::OutputWaveform(float slew, { } -OutputWaveform::~OutputWaveform() -{ - delete currents_; -} - Table * -OutputWaveform::stealCurrents() +OutputWaveform::releaseCurrents() { - Table *currents = currents_; - currents_ = nullptr; - return currents; + return currents_.release(); } } // namespace diff --git a/liberty/LibertyReaderPvt.hh b/liberty/LibertyReaderPvt.hh index b4a8e604..91fdf260 100644 --- a/liberty/LibertyReaderPvt.hh +++ b/liberty/LibertyReaderPvt.hh @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -47,33 +48,17 @@ namespace sta { class LibertyBuilder; class LibertyReader; -class LibertyFunc; -class PortGroup; -class SequentialGroup; -class StatetableGroup; -class RelatedPortGroup; -class TimingGroup; -class InternalPowerGroup; -class LeakagePowerGroup; class PortNameBitIterator; class TimingArcBuilder; -class LibertyAttr; class OutputWaveform; -using LibraryAttrVisitor = void (LibertyReader::*)(LibertyAttr *attr); -using LibraryGroupVisitor = void (LibertyReader::*)(LibertyGroup *group); -using LibraryAttrMap = std::unordered_map; -using LibraryGroupMap = std::unordered_map; -using PortGroupSeq = std::vector; -using SequentialGroupSeq = std::vector; -using LibertyFuncSeq = std::vector; -using TimingGroupSeq = std::vector; -using InternalPowerGroupSeq = std::vector; -using LeakagePowerGroupSeq = std::vector; -using LibertyPortBoolSetter = void (LibertyPort::*)(bool value); -using OutputWaveformSeq = std::vector; +using LibraryGroupVisitor = void (LibertyReader::*)(const LibertyGroup *group, + LibertyGroup *parent_group); +using LibraryGroupVisitorMap = std::unordered_map; using StdStringSeq = std::vector; -using LibertySetFunc = std::function; +using LibertyPortGroupMap = std::map; +using OutputWaveformSeq = std::vector; class LibertyReader : public LibertyGroupVisitor { @@ -81,428 +66,124 @@ public: LibertyReader(const char *filename, bool infer_latches, Network *network); - virtual ~LibertyReader(); virtual LibertyLibrary *readLibertyFile(const char *filename); LibertyLibrary *library() { return library_; } const LibertyLibrary *library() const { return library_; } - virtual void init(const char *filename, - bool infer_latches, - Network *network); - virtual bool save(LibertyGroup *) { return false; } - virtual bool save(LibertyAttr *) { return false; } - virtual bool save(LibertyVariable *) { return false; } + virtual void beginLibrary(const LibertyGroup *group, + LibertyGroup *library_group); + virtual void endLibrary(const LibertyGroup *group, + LibertyGroup *null_group); + virtual void visitAttr(const LibertySimpleAttr *attr); + virtual void visitAttr(const LibertyComplexAttr *attr); + virtual void visitVariable(LibertyVariable *var); + // Extension points for custom attributes (e.g. LibertyExt). + virtual void visitAttr1(const LibertySimpleAttr *) {} + virtual void visitAttr2(const LibertySimpleAttr *) {} - virtual void beginLibrary(LibertyGroup *group); - virtual void endLibrary(LibertyGroup *group); - virtual void endLibraryAttrs(LibertyGroup *group); - virtual void visitAttr(LibertyAttr *attr); - virtual void visitTimeUnit(LibertyAttr *attr); - virtual void visitCapacitiveLoadUnit(LibertyAttr *attr); - virtual void visitResistanceUnit(LibertyAttr *attr); - virtual void visitPullingResistanceUnit(LibertyAttr *attr); - virtual void visitVoltageUnit(LibertyAttr *attr); - virtual void visitCurrentUnit(LibertyAttr *attr); - virtual void visitPowerUnit(LibertyAttr *attr); - virtual void visitDistanceUnit(LibertyAttr *attr); - virtual void parseUnits(LibertyAttr *attr, - const char *suffix, - float &scale_var, - Unit *unit_suffix); - virtual void visitDelayModel(LibertyAttr *attr); - virtual void visitVoltageMap(LibertyAttr *attr); - virtual void visitBusStyle(LibertyAttr *attr); - virtual void visitNomTemp(LibertyAttr *attr); - virtual void visitNomVolt(LibertyAttr *attr); - virtual void visitNomProc(LibertyAttr *attr); - virtual void visitDefaultInoutPinCap(LibertyAttr *attr); - virtual void visitDefaultInputPinCap(LibertyAttr *attr); - virtual void visitDefaultOutputPinCap(LibertyAttr *attr); - virtual void visitDefaultMaxTransition(LibertyAttr *attr); - virtual void visitDefaultMaxFanout(LibertyAttr *attr); - virtual void visitDefaultIntrinsicRise(LibertyAttr *attr); - virtual void visitDefaultIntrinsicFall(LibertyAttr *attr); - virtual void visitDefaultIntrinsic(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitDefaultInoutPinRiseRes(LibertyAttr *attr); - virtual void visitDefaultInoutPinFallRes(LibertyAttr *attr); - virtual void visitDefaultInoutPinRes(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitDefaultOutputPinRiseRes(LibertyAttr *attr); - virtual void visitDefaultOutputPinFallRes(LibertyAttr *attr); - virtual void visitDefaultOutputPinRes(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitDefaultFanoutLoad(LibertyAttr *attr); - virtual void visitDefaultWireLoad(LibertyAttr *attr); - virtual void visitDefaultWireLoadMode(LibertyAttr *attr); - virtual void visitDefaultWireLoadSelection(LibertyAttr *attr); - virtual void visitDefaultOperatingConditions(LibertyAttr *attr); - virtual void visitInputThresholdPctFall(LibertyAttr *attr); - virtual void visitInputThresholdPctRise(LibertyAttr *attr); - virtual void visitInputThresholdPct(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitOutputThresholdPctFall(LibertyAttr *attr); - virtual void visitOutputThresholdPctRise(LibertyAttr *attr); - virtual void visitOutputThresholdPct(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitSlewLowerThresholdPctFall(LibertyAttr *attr); - virtual void visitSlewLowerThresholdPctRise(LibertyAttr *attr); - virtual void visitSlewLowerThresholdPct(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitSlewUpperThresholdPctFall(LibertyAttr *attr); - virtual void visitSlewUpperThresholdPctRise(LibertyAttr *attr); - virtual void visitSlewUpperThresholdPct(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitSlewDerateFromLibrary(LibertyAttr *attr); + void endCell(const LibertyGroup *group, + LibertyGroup *library_group); + void endScaledCell(const LibertyGroup *group, + LibertyGroup *library_group); + void checkScaledCell(LibertyCell *scaled_cell, + LibertyCell *owner, + const LibertyGroup *scaled_cell_group, + const char *op_cond_name); - virtual void beginTechnology(LibertyGroup *group); - virtual void endTechnology(LibertyGroup *group); - virtual void beginTableTemplateDelay(LibertyGroup *group); - virtual void beginTableTemplateOutputCurrent(LibertyGroup *group); - virtual void beginTableTemplate(LibertyGroup *group, - TableTemplateType type); - virtual void endTableTemplate(LibertyGroup *group); - virtual void visitVariable1(LibertyAttr *attr); - virtual void visitVariable2(LibertyAttr *attr); - virtual void visitVariable3(LibertyAttr *attr); - virtual void visitIndex1(LibertyAttr *attr); - virtual void visitIndex2(LibertyAttr *attr); - virtual void visitIndex3(LibertyAttr *attr); + void setPortCapDefault(LibertyPort *port); + void checkLatchEnableSense(FuncExpr *enable_func, + int line); + FloatTable makeFloatTable(const LibertyComplexAttr *attr, + const LibertyGroup *table_group, + size_t rows, + size_t cols, + float scale); - virtual void beginType(LibertyGroup *group); - virtual void endType(LibertyGroup *group); - virtual void visitBitFrom(LibertyAttr *attr); - virtual void visitBitTo(LibertyAttr *attr); - - virtual void beginCell(LibertyGroup *group); - virtual void endCell(LibertyGroup *group); - virtual void beginScaledCell(LibertyGroup *group); - virtual void endScaledCell(LibertyGroup *group); - virtual void checkScaledCell(LibertyGroup *group); - virtual void finishPortGroups(); - virtual void checkPort(LibertyPort *port, - int line); - virtual void makeTimingArcs(PortGroup *port_group); - virtual void makeInternalPowers(PortGroup *port_group); - virtual void makeCellSequentials(); - virtual void makeCellSequential(SequentialGroup *seq); - virtual void makeStatetable(); - virtual void makeLeakagePowers(); - virtual void parseCellFuncs(); - virtual void makeLibertyFunc(const char *expr, - LibertySetFunc set_func, - bool invert, - const char *attr_name, - LibertyStmt *stmt); - virtual void makeTimingArcs(LibertyPort *to_port, - TimingGroup *timing); - virtual void makeTimingArcs(const char *from_port_name, - PortNameBitIterator &from_port_iter, - LibertyPort *to_port, - LibertyPort *related_out_port, - TimingGroup *timing); - virtual void makeTimingArcs(LibertyPort *to_port, - LibertyPort *related_out_port, - TimingGroup *timing); - - virtual void visitClockGatingIntegratedCell(LibertyAttr *attr); - virtual void visitArea(LibertyAttr *attr); - virtual void visitDontUse(LibertyAttr *attr); - virtual void visitIsMacro(LibertyAttr *attr); - virtual void visitIsMemory(LibertyAttr *attr); - virtual void visitIsPadCell(LibertyAttr *attr); - virtual void visitIsPad(LibertyAttr *attr); - virtual void visitIsClockCell(LibertyAttr *attr); - virtual void visitIsLevelShifter(LibertyAttr *attr); - virtual void visitLevelShifterType(LibertyAttr *attr); - virtual void visitIsIsolationCell(LibertyAttr *attr); - virtual void visitAlwaysOn(LibertyAttr *attr); - virtual void visitSwitchCellType(LibertyAttr *attr); - virtual void visitInterfaceTiming(LibertyAttr *attr); - virtual void visitScalingFactors(LibertyAttr *attr); - virtual void visitCellLeakagePower(LibertyAttr *attr); - virtual void visitCellFootprint(LibertyAttr *attr); - virtual void visitCellUserFunctionClass(LibertyAttr *attr); - - virtual void beginPin(LibertyGroup *group); - virtual void endPin(LibertyGroup *group); - virtual void beginBus(LibertyGroup *group); - virtual void endBus(LibertyGroup *group); - virtual void beginBundle(LibertyGroup *group); - virtual void endBundle(LibertyGroup *group); - virtual void beginBusOrBundle(LibertyGroup *group); - virtual void endBusOrBundle(); - virtual void endPorts(); - virtual void setPortCapDefault(LibertyPort *port); - virtual void visitMembers(LibertyAttr *attr); - virtual void visitDirection(LibertyAttr *attr); - virtual void visitFunction(LibertyAttr *attr); - virtual void visitThreeState(LibertyAttr *attr); - virtual void visitBusType(LibertyAttr *attr); - virtual void visitCapacitance(LibertyAttr *attr); - virtual void visitRiseCap(LibertyAttr *attr); - virtual void visitFallCap(LibertyAttr *attr); - virtual void visitRiseCapRange(LibertyAttr *attr); - virtual void visitFallCapRange(LibertyAttr *attr); - virtual void visitFanoutLoad(LibertyAttr *attr); - virtual void visitMaxFanout(LibertyAttr *attr); - virtual void visitMinFanout(LibertyAttr *attr); - virtual void visitFanout(LibertyAttr *attr, - const MinMax *min_max); - virtual void visitMaxTransition(LibertyAttr *attr); - virtual void visitMinTransition(LibertyAttr *attr); - virtual void visitMinMaxTransition(LibertyAttr *attr, - const MinMax *min_max); - virtual void visitMaxCapacitance(LibertyAttr *attr); - virtual void visitMinCapacitance(LibertyAttr *attr); - virtual void visitMinMaxCapacitance(LibertyAttr *attr, - const MinMax *min_max); - virtual void visitMinPeriod(LibertyAttr *attr); - virtual void visitMinPulseWidthLow(LibertyAttr *attr); - virtual void visitMinPulseWidthHigh(LibertyAttr *attr); - virtual void visitMinPulseWidth(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitPulseClock(LibertyAttr *attr); - virtual void visitClockGateClockPin(LibertyAttr *attr); - virtual void visitClockGateEnablePin(LibertyAttr *attr); - virtual void visitClockGateOutPin(LibertyAttr *attr); - void visitIsPllFeedbackPin(LibertyAttr *attr); - virtual void visitSignalType(LibertyAttr *attr); - const EarlyLateAll *getAttrEarlyLate(LibertyAttr *attr); - virtual void visitClock(LibertyAttr *attr); - virtual void visitIsolationCellDataPin(LibertyAttr *attr); - virtual void visitIsolationCellEnablePin(LibertyAttr *attr); - virtual void visitLevelShifterDataPin(LibertyAttr *attr); - virtual void visitSwitchPin(LibertyAttr *attr); - void visitPortBoolAttr(LibertyAttr *attr, - LibertyPortBoolSetter setter); - - virtual void beginScalingFactors(LibertyGroup *group); - virtual void endScalingFactors(LibertyGroup *group); - virtual void defineScalingFactorVisitors(); - virtual void visitScaleFactorSuffix(LibertyAttr *attr); - virtual void visitScaleFactorPrefix(LibertyAttr *attr); - virtual void visitScaleFactorHiLow(LibertyAttr *attr); - virtual void visitScaleFactor(LibertyAttr *attr); - - virtual void beginOpCond(LibertyGroup *group); - virtual void endOpCond(LibertyGroup *group); - virtual void visitProc(LibertyAttr *attr); - virtual void visitVolt(LibertyAttr *attr); - virtual void visitTemp(LibertyAttr *attr); - virtual void visitTreeType(LibertyAttr *attr); - - virtual void beginWireload(LibertyGroup *group); - virtual void endWireload(LibertyGroup *group); - virtual void visitResistance(LibertyAttr *attr); - virtual void visitSlope(LibertyAttr *attr); - virtual void visitFanoutLength(LibertyAttr *attr); - - virtual void beginWireloadSelection(LibertyGroup *group); - virtual void endWireloadSelection(LibertyGroup *group); - virtual void visitWireloadFromArea(LibertyAttr *attr); - - virtual void beginMemory(LibertyGroup *group); - virtual void endMemory(LibertyGroup *group); - - virtual void beginFF(LibertyGroup *group); - virtual void endFF(LibertyGroup *group); - virtual void beginFFBank(LibertyGroup *group); - virtual void endFFBank(LibertyGroup *group); - virtual void beginLatch(LibertyGroup *group); - virtual void endLatch(LibertyGroup *group); - virtual void beginLatchBank(LibertyGroup *group); - virtual void endLatchBank(LibertyGroup *group); - virtual void beginSequential(LibertyGroup *group, - bool is_register, - bool is_bank); - virtual void seqPortNames(LibertyGroup *group, - const char *&out_name, - const char *&out_inv_name, - bool &has_size, - int &size); - virtual void checkLatchEnableSense(FuncExpr *enable_func, - int line); - virtual void visitClockedOn(LibertyAttr *attr); - virtual void visitDataIn(LibertyAttr *attr); - virtual void visitClear(LibertyAttr *attr); - virtual void visitPreset(LibertyAttr *attr); - virtual void visitClrPresetVar1(LibertyAttr *attr); - virtual void visitClrPresetVar2(LibertyAttr *attr); - - virtual void beginStatetable(LibertyGroup *group); - virtual void endStatetable(LibertyGroup *group); - virtual void visitTable(LibertyAttr *attr); - - virtual void beginTiming(LibertyGroup *group); - virtual void endTiming(LibertyGroup *group); - virtual void visitRelatedPin(LibertyAttr *attr); - virtual void visitRelatedPin(LibertyAttr *attr, - RelatedPortGroup *group); - virtual void visitRelatedBusPins(LibertyAttr *attr); - virtual void visitRelatedBusPins(LibertyAttr *attr, - RelatedPortGroup *group); - virtual void visitRelatedOutputPin(LibertyAttr *attr); - virtual void visitTimingType(LibertyAttr *attr); - virtual void visitTimingSense(LibertyAttr *attr); - virtual void visitSdfCondStart(LibertyAttr *attr); - virtual void visitSdfCondEnd(LibertyAttr *attr); - virtual void visitMode(LibertyAttr *attr); - virtual void visitIntrinsicRise(LibertyAttr *attr); - virtual void visitIntrinsicFall(LibertyAttr *attr); - virtual void visitIntrinsic(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitRiseResistance(LibertyAttr *attr); - virtual void visitFallResistance(LibertyAttr *attr); - virtual void visitRiseFallResistance(LibertyAttr *attr, - const RiseFall *rf); - virtual void visitValue(LibertyAttr *attr); - virtual void visitValues(LibertyAttr *attr); - virtual void beginCellRise(LibertyGroup *group); - virtual void beginCellFall(LibertyGroup *group); - virtual void endCellRiseFall(LibertyGroup *group); - virtual void beginRiseTransition(LibertyGroup *group); - virtual void endRiseFallTransition(LibertyGroup *group); - virtual void beginFallTransition(LibertyGroup *group); - virtual void beginRiseConstraint(LibertyGroup *group); - virtual void endRiseFallConstraint(LibertyGroup *group); - virtual void beginFallConstraint(LibertyGroup *group); - - virtual void beginRiseTransitionDegredation(LibertyGroup *group); - virtual void beginFallTransitionDegredation(LibertyGroup *group); - virtual void endRiseFallTransitionDegredation(LibertyGroup *group); - - virtual void beginTableModel(LibertyGroup *group, - TableTemplateType type, - const RiseFall *rf, - float scale, - ScaleFactorType scale_factor_type); - virtual void endTableModel(); - virtual void beginTimingTableModel(LibertyGroup *group, - const RiseFall *rf, - ScaleFactorType scale_factor_type); - virtual void beginTable(LibertyGroup *group, - TableTemplateType type, - float scale); - virtual void endTable(); - virtual void makeTable(LibertyAttr *attr, - float scale); - virtual FloatTable makeFloatTable(LibertyAttr *attr, - size_t rows, - size_t cols, - float scale); - - virtual void beginLut(LibertyGroup *group); - virtual void endLut(LibertyGroup *group); - - virtual void beginTestCell(LibertyGroup *group); - virtual void endTestCell(LibertyGroup *group); - - virtual void beginModeDef(LibertyGroup *group); - virtual void endModeDef(LibertyGroup *group); - virtual void beginModeValue(LibertyGroup *group); - virtual void endModeValue(LibertyGroup *group); - virtual void visitWhen(LibertyAttr *attr); - virtual void visitSdfCond(LibertyAttr *attr); - - // Power attributes. - virtual void beginTableTemplatePower(LibertyGroup *group); - virtual void beginLeakagePower(LibertyGroup *group); - virtual void endLeakagePower(LibertyGroup *group); - virtual void beginInternalPower(LibertyGroup *group); - virtual void endInternalPower(LibertyGroup *group); - virtual void beginFallPower(LibertyGroup *group); - virtual void beginRisePower(LibertyGroup *group); - virtual void endRiseFallPower(LibertyGroup *group); - virtual void endPower(LibertyGroup *group); - virtual void visitRelatedGroundPin(LibertyAttr *attr); - virtual void visitRelatedPowerPin(LibertyAttr *attr); - virtual void visitRelatedPgPin(LibertyAttr *attr); - virtual void makeInternalPowers(LibertyPort *port, - InternalPowerGroup *power_group); - virtual void makeInternalPowers(LibertyPort *port, - const char *related_port_name, - PortNameBitIterator &related_port_iter, - LibertyPort *related_pg_pin, - InternalPowerGroup *power_group); - - // AOCV attributes. - virtual void beginTableTemplateOcv(LibertyGroup *group); - virtual void visitOcvArcDepth(LibertyAttr *attr); - virtual void visitDefaultOcvDerateGroup(LibertyAttr *attr); - virtual void visitOcvDerateGroup(LibertyAttr *attr); - virtual void beginOcvDerate(LibertyGroup *group); - virtual void endOcvDerate(LibertyGroup *group); - virtual void beginOcvDerateFactors(LibertyGroup *group); - virtual void endOcvDerateFactors(LibertyGroup *group); - virtual void visitRfType(LibertyAttr *attr); - virtual void visitDerateType(LibertyAttr *attr); - virtual void visitPathType(LibertyAttr *attr); - - // POCV attributes. - virtual void beginOcvSigmaCellRise(LibertyGroup *group); - virtual void beginOcvSigmaCellFall(LibertyGroup *group); - virtual void endOcvSigmaCell(LibertyGroup *group); - virtual void beginOcvSigmaRiseTransition(LibertyGroup *group); - virtual void beginOcvSigmaFallTransition(LibertyGroup *group); - virtual void endOcvSigmaTransition(LibertyGroup *group); - virtual void beginOcvSigmaRiseConstraint(LibertyGroup *group); - virtual void beginOcvSigmaFallConstraint(LibertyGroup *group); - virtual void endOcvSigmaConstraint(LibertyGroup *group); - virtual void visitSigmaType(LibertyAttr *attr); - - // PgPin group. - virtual void beginPgPin(LibertyGroup *group); - virtual void endPgPin(LibertyGroup *group); - virtual void visitPgType(LibertyAttr *attr); - virtual void visitVoltageName(LibertyAttr *attr); - - // ccs receiver capacitance - virtual void beginReceiverCapacitance(LibertyGroup *group); - virtual void endReceiverCapacitance(LibertyGroup *group); - - virtual void visitSegement(LibertyAttr *attr); - - virtual void beginReceiverCapacitance1Rise(LibertyGroup *group); - virtual void endReceiverCapacitanceRiseFall(LibertyGroup *group); - virtual void beginReceiverCapacitance1Fall(LibertyGroup *group); - virtual void beginReceiverCapacitance2Rise(LibertyGroup *group); - virtual void beginReceiverCapacitance2Fall(LibertyGroup *group); - void beginReceiverCapacitance(LibertyGroup *group, - int index, - const RiseFall *rf); - void endReceiverCapacitance(LibertyGroup *group, - int index, - const RiseFall *rf); - // ccs - void beginOutputCurrentRise(LibertyGroup *group); - void beginOutputCurrentFall(LibertyGroup *group); - void beginOutputCurrent(const RiseFall *rf, - LibertyGroup *group); - void endOutputCurrentRiseFall(LibertyGroup *group); - void beginVector(LibertyGroup *group); - void endVector(LibertyGroup *group); - void visitReferenceTime(LibertyAttr *attr); - - void beginNormalizedDriverWaveform(LibertyGroup *group); - void endNormalizedDriverWaveform(LibertyGroup *group); - void visitDriverWaveformName(LibertyAttr *attr); - - void visitDriverWaveformRise(LibertyAttr *attr); - void visitDriverWaveformFall(LibertyAttr *attr); - void visitDriverWaveformRiseFall(LibertyAttr *attr, - const RiseFall *rf); - - void beginCcsn(LibertyGroup *group); - void endCcsn(LibertyGroup *group); - void beginEcsmWaveform(LibertyGroup *group); - void endEcsmWaveform(LibertyGroup *group); LibertyPort *findPort(LibertyCell *cell, const char *port_name); - virtual void begin(LibertyGroup *group); - virtual void end(LibertyGroup *group); + StdStringSeq findAttributStrings(const LibertyGroup *group, + const char *name_attr); protected: + virtual void begin(const LibertyGroup *group, + LibertyGroup *library_group); + virtual void end(const LibertyGroup *group, + LibertyGroup *library_group); + + // Library gruops. + void makeLibrary(const LibertyGroup *libary_group); + void readLibraryAttributes(const LibertyGroup *library_group); + void readLibraryUnits(const LibertyGroup *library_group); + void readDelayModel(const LibertyGroup *library_group); + void readBusStyle(const LibertyGroup *library_group); + void readDefaultWireLoad(const LibertyGroup *library_group); + void readDefaultWireLoadMode(const LibertyGroup *library_group); + void readTechnology(const LibertyGroup *library_group); + void readDefaultWireLoadSelection(const LibertyGroup *library_group); + void readUnit(const char *unit_attr_name, + const char *unit_suffix, + float &scale_var, + Unit *unit, + const LibertyGroup *library_group); + void readBusTypes(LibertyCell *cell, + const LibertyGroup *type_group); + void readTableTemplates(const LibertyGroup *library_group); + void readTableTemplates(const LibertyGroup *library_group, + const char *group_name, + TableTemplateType type); + void readThresholds(const LibertyGroup *library_group); + TableAxisPtr makeTableTemplateAxis(const LibertyGroup *template_group, + int axis_index); + void readVoltateMaps(const LibertyGroup *library_group); + void readWireloads(const LibertyGroup *library_group); + void readWireloadSelection(const LibertyGroup *library_group); + void readOperatingConds(const LibertyGroup *library_group); + void readScaleFactors(const LibertyGroup *library_group); + void readScaleFactors(const LibertyGroup *scale_group, + ScaleFactors *scale_factors); + void readOcvDerateFactors(LibertyCell *cell, + const LibertyGroup *library_group); + void readDefaultOcvDerateGroup(const LibertyGroup *library_group); + void readNormalizedDriverWaveform(const LibertyGroup *library_group); + void readSlewDegradations(const LibertyGroup *library_group); + void readLibAttrFloat(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(float value), + float scale); + void readLibAttrFloat(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(const RiseFall *rf, + float value), + const RiseFall *rf, + float scale); + void readLibAttrFloatWarnZero(const LibertyGroup *library_group, + const char *attr_name, + void (LibertyLibrary::*set_func)(float value), + float scale); + + // Cell groups. + void readCell(LibertyCell *cell, + const LibertyGroup *cell_group); + void readScaledCell(const LibertyGroup *scaled_cell_group); + LibertyPortGroupMap makeCellPorts(LibertyCell *cell, + const LibertyGroup *cell_group); + void makePinPort(LibertyCell *cell, + const LibertyGroup *pin_group, + LibertyPortGroupMap &port_group_map); + void makeBusPort(LibertyCell *cell, + const LibertyGroup *bus_group, + LibertyPortGroupMap &port_group_map); + void makeBusPinPorts(LibertyCell *cell, + const LibertyGroup *bus_group, + LibertyPortGroupMap &port_group_map); + void makeBundlePort(LibertyCell *cell, + const LibertyGroup *bundle_group, + LibertyPortGroupMap &port_group_map); + void makeBundlePinPorts(LibertyCell *cell, + const LibertyGroup *bundle_group, + LibertyPortGroupMap &port_group_map); + void makePgPinPort(LibertyCell *cell, + const LibertyGroup *pg_pin_group); LibertyPort *makePort(LibertyCell *cell, const char *port_name); LibertyPort *makeBusPort(LibertyCell *cell, @@ -511,78 +192,270 @@ protected: int to_index, BusDcl *bus_dcl); - TimingModel *makeScalarCheckModel(float value, + void readPortAttributes(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readPortAttrString(const char *attr_name, + void (LibertyPort::*set_func)(const char *value), + const LibertyPortSeq &ports, + const LibertyGroup *group); + void readPortAttrFloat(const char *attr_name, + void (LibertyPort::*set_func)(float value), + const LibertyPortSeq &ports, + const LibertyGroup *group, + float scale); + void readPortAttrBool(const char *attr_name, + void (LibertyPort::*set_func)(bool value), + const LibertyPortSeq &ports, + const LibertyGroup *group); + void readDriverWaveform(const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readPortAttrFloatMinMax(const char *attr_name, + void (LibertyPort::*set_func)(float value, + const MinMax *min_max), + const LibertyPortSeq &ports, + const LibertyGroup *group, + const MinMax *min_max, + float scale); + void readPulseClock(const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readSignalType(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readMinPulseWidth(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readModeDefs(LibertyCell *cell, + const LibertyGroup *cell_group); + void makeTimingArcs(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + bool isGateTimingType(TimingType timing_type); + TableModel *readGateTableModel(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type); + TableModelsEarlyLate + readEarlyLateTableModels(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type); + TableModel *readCheckTableModel(const LibertyGroup *timing_group, + const char *table_group_name, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type); + ReceiverModelPtr readReceiverCapacitance(const LibertyGroup *timing_group, + const RiseFall *rf); + void readReceiverCapacitance(const LibertyGroup *timing_group, + const char *cap_group_name, + int index, + const RiseFall *rf, + ReceiverModelPtr &receiver_model); + OutputWaveforms *readOutputWaveforms(const LibertyGroup *timing_group, + const RiseFall *rf); + OutputWaveforms *makeOutputWaveforms(const LibertyGroup *current_group, + OutputWaveformSeq &output_currents, + const RiseFall *rf); + + TableModel *readTableModel(const LibertyGroup *table_group, + const RiseFall *rf, + TableTemplateType template_type, + float scale, + ScaleFactorType scale_factor_type); + TablePtr readTableModel(const LibertyGroup *table_group, + const TableTemplate *tbl_template, + float scale); + void makeTimingModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void makeLinearModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void makeTableModels(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + + TableAxisPtr makeTableAxis(const LibertyGroup *table_group, + const char *index_attr_name, + TableAxisPtr template_axis); + void readGroupAttrFloat(const char *attr_name, + const LibertyGroup *group, + const std::function &set_func, + float scale = 1.0F); + void readTimingArcAttrs(LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void readTimingSense(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void readTimingType(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void readTimingWhen(const LibertyCell *cell, + const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void readTimingMode(const LibertyGroup *timing_group, + TimingArcAttrsPtr timing_attrs); + void makePortFuncs(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + + void makeSequentials(LibertyCell *cell, + const LibertyGroup *cell_group); + void makeSequentials(LibertyCell *cell, + const LibertyGroup *cell_group, + bool is_register, + const char *seq_group_name, + const char *clk_attr_name, + const char *data_attr_name); + FuncExpr *makeSeqFunc(LibertyCell *cell, + const LibertyGroup *seq_group, + const char *attr_name, + int size); + void makeSeqPorts(LibertyCell *cell, + const LibertyGroup *seq_group, + // Return values. + LibertyPort *&out_port, + LibertyPort *&out_port_inv, + size_t &size); + void seqPortNames(const LibertyGroup *group, + const char *&out_name, + const char *&out_inv_name, + bool &has_size, + size_t &size); + TimingModel *makeScalarCheckModel(LibertyCell *cell, + float value, ScaleFactorType scale_factor_type, const RiseFall *rf); - void makeMinPulseWidthArcs(LibertyPort *port, - int line); - void setEnergyScale(); + void readPortDir(const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readCapacitance(const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void makeTimingArcs(LibertyCell *cell, + const std::string &from_port_name, + LibertyPort *to_port, + LibertyPort *related_out_port, + bool one_to_one, + TimingArcAttrsPtr timing_attrs, + int timing_line); + void makeTimingArcs(LibertyCell *cell, + LibertyPort *to_port, + LibertyPort *related_out_port, + TimingArcAttrsPtr timing_attrs, + int timing_line); + + void readInternalPowerGroups(LibertyCell *cell, + const LibertyPortSeq &ports, + const LibertyGroup *port_group); + void readLeagageGrouops(LibertyCell *cell, + const LibertyGroup *port_group); + + void readCellAttributes(LibertyCell *cell, + const LibertyGroup *cell_group); + void readScaleFactors(LibertyCell *cell, + const LibertyGroup *cell_group); + void readCellAttrString(const char *attr_name, + void (LibertyCell::*set_func)(const char *value), + LibertyCell *cell, + const LibertyGroup *group); + void readCellAttrFloat(const char *attr_name, + void (LibertyCell::*set_func)(float value), + LibertyCell *cell, + const LibertyGroup *group, + float scale); + void readCellAttrBool(const char *attr_name, + void (LibertyCell::*set_func)(bool value), + LibertyCell *cell, + const LibertyGroup *group); + void readLevelShifterType(LibertyCell *cell, + const LibertyGroup *cell_group); + void readSwitchCellType(LibertyCell *cell, + const LibertyGroup *cell_group); + void readCellOcvDerateGroup(LibertyCell *cell, + const LibertyGroup *cell_group); + void readStatetable(LibertyCell *cell, + const LibertyGroup *cell_group); + void readTestCell(LibertyCell *cell, + const LibertyGroup *cell_group); + + FuncExpr *readFuncExpr(LibertyCell *cell, + const LibertyGroup *group, + const char *attr_name); + LibertyPort *findLibertyPort(LibertyCell *cell, + const LibertyGroup *group, + const char *port_name_attr); + LibertyPortSeq findLibertyPorts(LibertyCell *cell, + const LibertyGroup *group, + const char *port_name_attr); + + float energyScale(); void defineVisitors(); + void defineGroupVisitor(const char *type, LibraryGroupVisitor begin_visitor, LibraryGroupVisitor end_visitor); - void defineAttrVisitor(const char *attr_name, - LibraryAttrVisitor visitor); - void parseNames(const char *name_str); - void clearAxisValues(); - void makeTableAxis(int index, - LibertyAttr *attr); - StringSeq *parseNameList(const char *name_list); - StdStringSeq parseTokenList(const char *token_str, - const char separator); - LibertyPort *findPort(const char *port_name); float defaultCap(LibertyPort *port); - virtual void visitVariable(LibertyVariable *var); void visitPorts(std::function func); StateInputValues parseStateInputValues(StdStringSeq &inputs, - LibertyAttr *attr); + const LibertySimpleAttr *attr); StateInternalValues parseStateInternalValues(StdStringSeq &states, - LibertyAttr *attr); + const LibertySimpleAttr *attr); - const char *getAttrString(LibertyAttr *attr); - void getAttrInt(LibertyAttr *attr, + void getAttrInt(const LibertySimpleAttr *attr, // Return values. int &value, bool &exists); - void getAttrFloat(LibertyAttr *attr, - // Return values. - float &value, - bool &valid); - void getAttrFloat(LibertyAttr *attr, - LibertyAttrValue *attr_value, - // Return values. - float &value, - bool &valid); - void getAttrFloat2(LibertyAttr *attr, + void getAttrFloat2(const LibertyComplexAttr *attr, // Return values. float &value1, float &value2, bool &exists); - FloatSeq parseStringFloatList(const std::string &float_list, - float scale, - LibertyAttr *attr); - LogicValue getAttrLogicValue(LibertyAttr *attr); - void getAttrBool(LibertyAttr *attr, + void getAttrFloat(const LibertyComplexAttr *attr, + const LibertyAttrValue *attr_value, + // Return values. + float &value, + bool &valid); + LogicValue getAttrLogicValue(const LibertySimpleAttr *attr); + void getAttrBool(const LibertySimpleAttr *attr, // Return values. bool &value, bool &exists); - void visitVariable(int index, - LibertyAttr *attr); - void visitIndex(int index, - LibertyAttr *attr); + const EarlyLateAll *getAttrEarlyLate(const LibertySimpleAttr *attr); + + FloatSeq parseStringFloatList(const std::string &float_list, + float scale, + const LibertySimpleAttr *attr); + FloatSeq parseStringFloatList(const std::string &float_list, + float scale, + const LibertyComplexAttr *attr); TableAxisPtr makeAxis(int index, - LibertyGroup *group); - FloatSeq readFloatSeq(LibertyAttr *attr, + const LibertyGroup *group); + FloatSeq readFloatSeq(const LibertyComplexAttr *attr, float scale); void variableValue(const char *var, float &value, bool &exists); FuncExpr *parseFunc(const char *func, const char *attr_name, + const LibertyCell *cell, int line); void libWarn(int id, - LibertyStmt *stmt, + const LibertyGroup *obj, + const char *fmt, + ...) + __attribute__((format (printf, 4, 5))); + void libWarn(int id, + const LibertySimpleAttr *obj, + const char *fmt, + ...) + __attribute__((format (printf, 4, 5))); + void libWarn(int id, + const LibertyComplexAttr *obj, const char *fmt, ...) __attribute__((format (printf, 4, 5))); @@ -592,7 +465,15 @@ protected: ...) __attribute__((format (printf, 4, 5))); void libError(int id, - LibertyStmt *stmt, + const LibertyGroup *obj, + const char *fmt, ...) + __attribute__((format (printf, 4, 5))); + void libError(int id, + const LibertySimpleAttr *obj, + const char *fmt, ...) + __attribute__((format (printf, 4, 5))); + void libError(int id, + const LibertyComplexAttr *obj, const char *fmt, ...) __attribute__((format (printf, 4, 5))); @@ -602,64 +483,12 @@ protected: Debug *debug_; Network *network_; LibertyBuilder builder_; - LibertyVariableMap *var_map_; + LibertyVariableMap var_map_; LibertyLibrary *library_; - LibraryGroupMap group_begin_map_; - LibraryGroupMap group_end_map_; - LibraryAttrMap attr_visitor_map_; - Wireload *wireload_; - WireloadSelection *wireload_selection_; - const char *default_wireload_; - const char *default_wireload_selection_; - ScaleFactors *scale_factors_; - ScaleFactors *save_scale_factors_; - bool have_input_threshold_[RiseFall::index_count]; - bool have_output_threshold_[RiseFall::index_count]; - bool have_slew_lower_threshold_[RiseFall::index_count]; - bool have_slew_upper_threshold_[RiseFall::index_count]; - TableTemplate *tbl_template_; - LibertyCell *cell_; - LibertyCell *scaled_cell_owner_; - const char *ocv_derate_name_; - PortGroupSeq cell_port_groups_; - OperatingConditions *op_cond_; - LibertyPortSeq *ports_; - PortGroup *port_group_; - LibertyPortSeq *saved_ports_; - PortGroup *saved_port_group_; - StringSeq bus_names_; - bool in_bus_; - bool in_bundle_; - bool in_ccsn_; - bool in_ecsm_waveform_; - TableAxisVariable axis_var_[3]; - FloatSeq axis_values_[3]; - int type_bit_from_; - bool type_bit_from_exists_; - int type_bit_to_; - bool type_bit_to_exists_; - SequentialGroup *sequential_; - SequentialGroupSeq cell_sequentials_; - StatetableGroup *statetable_; - TimingGroup *timing_; - InternalPowerGroup *internal_power_; - LeakagePowerGroup *leakage_power_; - LeakagePowerGroupSeq leakage_powers_; - const RiseFall *rf_; - int index_; - OcvDerate *ocv_derate_; - const RiseFallBoth *rf_type_; - const EarlyLateAll *derate_type_; - const EarlyLateAll *sigma_type_; - PathType path_type_; - LibertyPort *pg_port_; - ScaleFactorType scale_factor_type_; - TableAxisPtr axis_[3]; - TablePtr table_; - float table_model_scale_; - ModeDef *mode_def_; - ModeValueDef *mode_value_; - LibertyFuncSeq cell_funcs_; + bool first_cell_; + LibraryGroupVisitorMap group_begin_map_; + LibraryGroupVisitorMap group_end_map_; + float time_scale_; float cap_scale_; float res_scale_; @@ -668,263 +497,11 @@ protected: float power_scale_; float energy_scale_; float distance_scale_; - const char *default_operating_condition_; - ReceiverModelPtr receiver_model_; - OutputWaveformSeq output_currents_; - OutputWaveforms *output_waveforms_; - float reference_time_; - bool reference_time_exists_; - std::string driver_waveform_name_; - - TestCell *test_cell_; - // Saved state while parsing test_cell. - LibertyCell *save_cell_; - PortGroupSeq save_cell_port_groups_; - StatetableGroup *save_statetable_; - SequentialGroupSeq save_cell_sequentials_; - LibertyFuncSeq save_cell_funcs_; static constexpr char escape_ = '\\'; private: friend class PortNameBitIterator; - friend class TimingGroup; -}; - -// Reference to a function that will be parsed at the end of the cell -// definition when all of the ports are defined. -class LibertyFunc -{ -public: - LibertyFunc(const char *expr, - LibertySetFunc set_func, - bool invert, - const char *attr_name, - int line); - ~LibertyFunc(); - const char *expr() const { return expr_; } - LibertySetFunc setFunc() const { return set_func_; } - bool invert() const { return invert_; } - const char *attrName() const { return attr_name_; } - int line() const { return line_; } - -protected: - const char *expr_; - LibertySetFunc set_func_; - bool invert_; - const char *attr_name_; - int line_; -}; - -// Port attributes that refer to other ports cannot be parsed -// until all of the ports are defined. This class saves them -// so they can be parsed at the end of the cell. -class PortGroup -{ -public: - PortGroup(LibertyPortSeq *ports, - int line); - ~PortGroup(); - LibertyPortSeq *ports() const { return ports_; } - TimingGroupSeq &timingGroups() { return timings_; } - void addTimingGroup(TimingGroup *timing); - InternalPowerGroupSeq &internalPowerGroups() { return internal_power_groups_; } - void addInternalPowerGroup(InternalPowerGroup *internal_power); - ReceiverModel *receiverModel() const { return receiver_model_; } - void setReceiverModel(ReceiverModelPtr receiver_model); - int line() const { return line_; } - -private: - LibertyPortSeq *ports_; - TimingGroupSeq timings_; - InternalPowerGroupSeq internal_power_groups_; - ReceiverModel *receiver_model_; - int line_; -}; - -// Liberty group with related_pins group attribute. -class RelatedPortGroup -{ -public: - RelatedPortGroup(int line); - virtual ~RelatedPortGroup(); - int line() const { return line_; } - StringSeq *relatedPortNames() const { return related_port_names_; } - void setRelatedPortNames(StringSeq *names); - bool isOneToOne() const { return is_one_to_one_; } - void setIsOneToOne(bool one); - -protected: - StringSeq *related_port_names_; - bool is_one_to_one_; - int line_; -}; - -class SequentialGroup -{ -public: - SequentialGroup(bool is_register, - bool is_bank, - LibertyPort *out_port, - LibertyPort *out_inv_port, - int size, - int line); - ~SequentialGroup(); - LibertyPort *outPort() const { return out_port_; } - LibertyPort *outInvPort() const { return out_inv_port_; } - int size() const { return size_; } - bool isRegister() const { return is_register_; } - bool isBank() const { return is_bank_; } - const char *clock() const { return clk_; } - void setClock(const char *clk); - const char *data() const { return data_; } - void setData(const char *data); - const char *clear() const { return clear_; } - void setClear(const char *clr); - const char *preset() const { return preset_; } - void setPreset(const char *preset); - LogicValue clrPresetVar1() const { return clr_preset_var1_; } - void setClrPresetVar1(LogicValue var); - LogicValue clrPresetVar2() const { return clr_preset_var2_; } - void setClrPresetVar2(LogicValue var); - int line() const { return line_; } - -protected: - bool is_register_; - bool is_bank_; - LibertyPort *out_port_; - LibertyPort *out_inv_port_; - int size_; - const char *clk_; - const char *data_; - const char *preset_; - const char *clear_; - LogicValue clr_preset_var1_; - LogicValue clr_preset_var2_; - int line_; -}; - -class StatetableGroup -{ -public: - StatetableGroup(StdStringSeq &input_ports, - StdStringSeq &internal_ports, - int line); - const StdStringSeq &inputPorts() const { return input_ports_; } - const StdStringSeq &internalPorts() const { return internal_ports_; } - void addRow(StateInputValues &input_values, - StateInternalValues ¤t_values, - StateInternalValues &next_values); - StatetableRows &table() { return table_; } - int line() const { return line_; } - -private: - StdStringSeq input_ports_; - StdStringSeq internal_ports_; - StatetableRows table_; - int line_; -}; - -class TimingGroup : public RelatedPortGroup -{ -public: - TimingGroup(int line); - virtual ~TimingGroup(); - TimingArcAttrsPtr attrs() { return attrs_; } - const char *relatedOutputPortName()const {return related_output_port_name_;} - void setRelatedOutputPortName(const char *name); - void intrinsic(const RiseFall *rf, - // Return values. - float &value, - bool &exists); - void setIntrinsic(const RiseFall *rf, - float value); - void resistance(const RiseFall *rf, - // Return values. - float &value, - bool &exists); - void setResistance(const RiseFall *rf, - float value); - TableModel *cell(const RiseFall *rf); - void setCell(const RiseFall *rf, - TableModel *model); - TableModel *constraint(const RiseFall *rf); - void setConstraint(const RiseFall *rf, - TableModel *model); - TableModel *transition(const RiseFall *rf); - void setTransition(const RiseFall *rf, - TableModel *model); - void makeTimingModels(LibertyCell *cell, - LibertyReader *visitor); - void setDelaySigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model); - void setSlewSigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model); - void setConstraintSigma(const RiseFall *rf, - const EarlyLate *early_late, - TableModel *model); - void setReceiverModel(ReceiverModelPtr receiver_model); - OutputWaveforms *outputWaveforms(const RiseFall *rf); - void setOutputWaveforms(const RiseFall *rf, - OutputWaveforms *output_current); - -protected: - void makeLinearModels(LibertyCell *cell); - void makeTableModels(LibertyCell *cell, - LibertyReader *reader); - - TimingArcAttrsPtr attrs_; - const char *related_output_port_name_; - float intrinsic_[RiseFall::index_count]; - bool intrinsic_exists_[RiseFall::index_count]; - float resistance_[RiseFall::index_count]; - bool resistance_exists_[RiseFall::index_count]; - TableModel *cell_[RiseFall::index_count]; - TableModel *constraint_[RiseFall::index_count]; - TableModel *constraint_sigma_[RiseFall::index_count][EarlyLate::index_count]; - TableModel *transition_[RiseFall::index_count]; - TableModel *delay_sigma_[RiseFall::index_count][EarlyLate::index_count]; - TableModel *slew_sigma_[RiseFall::index_count][EarlyLate::index_count]; - OutputWaveforms *output_waveforms_[RiseFall::index_count]; - ReceiverModelPtr receiver_model_; -}; - -class InternalPowerGroup : public RelatedPortGroup -{ -public: - InternalPowerGroup(int line); - const std::string &relatedPgPin() const { return related_pg_pin_; } - void setRelatedPgPin(std::string related_pg_pin); - const std::shared_ptr &when() const { return when_; } - void setWhen(std::shared_ptr when); - void setModel(const RiseFall *rf, - std::shared_ptr model); - InternalPowerModels &models() { return models_; } - -private: - std::string related_pg_pin_; - std::shared_ptr when_; - InternalPowerModels models_; -}; - -class LeakagePowerGroup -{ -public: - LeakagePowerGroup(int line); - const std::string &relatedPgPin() const { return related_pg_pin_; } - void setRelatedPgPin(std::string pin_name); - FuncExpr *when() const { return when_; } - void setWhen(FuncExpr *when); - float power() const { return power_; } - void setPower(float power); - -protected: - std::string related_pg_pin_; - FuncExpr *when_; - float power_; - int line_; }; // Named port iterator. Port name can be: @@ -968,17 +545,16 @@ public: float axis_value2, Table *currents, float reference_time); - ~OutputWaveform(); float slew() const { return slew_; } float cap() const { return cap_; } - Table *currents() const { return currents_; } - Table *stealCurrents(); + Table *releaseCurrents(); + float referenceTime() { return reference_time_; } private: float slew_; float cap_; - Table *currents_; + std::unique_ptr
currents_; float reference_time_; }; diff --git a/liberty/TableModel.cc b/liberty/TableModel.cc index 27512dc5..977c9b08 100644 --- a/liberty/TableModel.cc +++ b/liberty/TableModel.cc @@ -45,9 +45,7 @@ size_t findValueIndex(float value, const FloatSeq *values); static void -sigmaModelsMvOwner(TableModel *models[EarlyLate::index_count], - std::array, - EarlyLate::index_count> &out); +sigmaModelsDelete(TableModelsEarlyLate &models); static string reportPvt(const LibertyCell *cell, const Pvt *pvt, @@ -63,40 +61,50 @@ TimingModel::TimingModel(LibertyCell *cell) : GateTableModel::GateTableModel(LibertyCell *cell, TableModel *delay_model, - TableModel *delay_sigma_models[EarlyLate::index_count], + TableModelsEarlyLate delay_sigma_models, TableModel *slew_model, - TableModel *slew_sigma_models[EarlyLate::index_count], + TableModelsEarlyLate slew_sigma_models, ReceiverModelPtr receiver_model, OutputWaveforms *output_waveforms) : GateTimingModel(cell), delay_model_(delay_model), + delay_sigma_models_(std::move(delay_sigma_models)), slew_model_(slew_model), + slew_sigma_models_(std::move(slew_sigma_models)), receiver_model_(receiver_model), output_waveforms_(output_waveforms) { - sigmaModelsMvOwner(delay_sigma_models, delay_sigma_models_); - sigmaModelsMvOwner(slew_sigma_models, slew_sigma_models_); } -GateTableModel::~GateTableModel() = default; +GateTableModel::GateTableModel(LibertyCell *cell, + TableModel *delay_model, + TableModel *slew_model) : + GateTimingModel(cell), + delay_model_(delay_model), + delay_sigma_models_{}, + slew_model_(slew_model), + slew_sigma_models_{}, + receiver_model_(nullptr), + output_waveforms_(nullptr) +{ +} + +GateTableModel::~GateTableModel() +{ + sigmaModelsDelete(slew_sigma_models_); + sigmaModelsDelete(delay_sigma_models_); +} static void -sigmaModelsMvOwner(TableModel *models[EarlyLate::index_count], - std::array, - EarlyLate::index_count> &out) +sigmaModelsDelete(TableModelsEarlyLate &models) { - TableModel *early_model = models ? models[EarlyLate::earlyIndex()] : nullptr; - TableModel *late_model = models ? models[EarlyLate::lateIndex()] : nullptr; - if (early_model) { - out[EarlyLate::earlyIndex()].reset(early_model); - if (late_model && late_model != early_model) { - out[EarlyLate::lateIndex()].reset(late_model); - } else if (late_model == early_model) { - out[EarlyLate::lateIndex()] = - std::make_unique(*out[EarlyLate::earlyIndex()]); - } - } else if (late_model) { - out[EarlyLate::lateIndex()].reset(late_model); + TableModel *early_model = models[EarlyLate::earlyIndex()]; + TableModel *late_model = models[EarlyLate::lateIndex()]; + if (early_model == late_model) + delete early_model; + else { + delete early_model; + delete late_model; } } @@ -122,19 +130,19 @@ GateTableModel::gateDelay(const Pvt *pvt, float sigma_early = 0.0; float sigma_late = 0.0; if (pocv_enabled && delay_sigma_models_[EarlyLate::earlyIndex()]) - sigma_early = findValue(pvt, delay_sigma_models_[EarlyLate::earlyIndex()].get(), + sigma_early = findValue(pvt, delay_sigma_models_[EarlyLate::earlyIndex()], in_slew, load_cap, 0.0); if (pocv_enabled && delay_sigma_models_[EarlyLate::lateIndex()]) - sigma_late = findValue(pvt, delay_sigma_models_[EarlyLate::lateIndex()].get(), + sigma_late = findValue(pvt, delay_sigma_models_[EarlyLate::lateIndex()], in_slew, load_cap, 0.0); gate_delay = makeDelay(delay, sigma_early, sigma_late); float slew = findValue(pvt, slew_model_.get(), in_slew, load_cap, 0.0); if (pocv_enabled && slew_sigma_models_[EarlyLate::earlyIndex()]) - sigma_early = findValue(pvt, slew_sigma_models_[EarlyLate::earlyIndex()].get(), + sigma_early = findValue(pvt, slew_sigma_models_[EarlyLate::earlyIndex()], in_slew, load_cap, 0.0); if (pocv_enabled && slew_sigma_models_[EarlyLate::lateIndex()]) - sigma_late = findValue(pvt, slew_sigma_models_[EarlyLate::lateIndex()].get(), + sigma_late = findValue(pvt, slew_sigma_models_[EarlyLate::lateIndex()], in_slew, load_cap, 0.0); // Clip negative slews to zero. if (slew < 0.0) @@ -166,22 +174,22 @@ GateTableModel::reportGateDelay(const Pvt *pvt, load_cap, 0.0, digits); if (pocv_enabled && delay_sigma_models_[EarlyLate::earlyIndex()]) result += reportTableLookup("Delay sigma(early)", pvt, - delay_sigma_models_[EarlyLate::earlyIndex()].get(), + delay_sigma_models_[EarlyLate::earlyIndex()], in_slew, load_cap, 0.0, digits); if (pocv_enabled && delay_sigma_models_[EarlyLate::lateIndex()]) result += reportTableLookup("Delay sigma(late)", pvt, - delay_sigma_models_[EarlyLate::lateIndex()].get(), + delay_sigma_models_[EarlyLate::lateIndex()], in_slew, load_cap, 0.0, digits); result += '\n'; result += reportTableLookup("Slew", pvt, slew_model_.get(), in_slew, load_cap, 9.0, digits); if (pocv_enabled && slew_sigma_models_[EarlyLate::earlyIndex()]) result += reportTableLookup("Slew sigma(early)", pvt, - slew_sigma_models_[EarlyLate::earlyIndex()].get(), + slew_sigma_models_[EarlyLate::earlyIndex()], in_slew, load_cap, 0.0, digits); if (pocv_enabled && slew_sigma_models_[EarlyLate::lateIndex()]) result += reportTableLookup("Slew sigma(late)", pvt, - slew_sigma_models_[EarlyLate::lateIndex()].get(), + slew_sigma_models_[EarlyLate::lateIndex()], in_slew, load_cap, 0.0, digits); float drvr_slew = findValue(pvt, slew_model_.get(), in_slew, load_cap, 0.0); if (drvr_slew < 0.0) @@ -285,13 +293,13 @@ GateTableModel::driveResistance(const Pvt *pvt) const const TableModel * GateTableModel::delaySigmaModel(const EarlyLate *el) const { - return delay_sigma_models_[el->index()].get(); + return delay_sigma_models_[el->index()]; } const TableModel * GateTableModel::slewSigmaModel(const EarlyLate *el) const { - return slew_sigma_models_[el->index()].get(); + return slew_sigma_models_[el->index()]; } void @@ -354,7 +362,7 @@ GateTableModel::axisValue(const TableAxis *axis, } bool -GateTableModel::checkAxes(const TablePtr &table) +GateTableModel::checkAxes(const TableModel *table) { const TableAxis *axis1 = table->axis1(); const TableAxis *axis2 = table->axis2(); @@ -395,7 +403,7 @@ ReceiverModel::setCapacitanceModel(TableModel table_model, } bool -ReceiverModel::checkAxes(TablePtr table) +ReceiverModel::checkAxes(const TableModel *table) { const TableAxis *axis1 = table->axis1(); const TableAxis *axis2 = table->axis2(); @@ -415,14 +423,25 @@ ReceiverModel::checkAxes(TablePtr table) CheckTableModel::CheckTableModel(LibertyCell *cell, TableModel *model, - TableModel *sigma_models[EarlyLate::index_count]) : + TableModelsEarlyLate sigma_models) : CheckTimingModel(cell), - model_(model) + model_(model), + sigma_models_(std::move(sigma_models)) { - sigmaModelsMvOwner(sigma_models, sigma_models_); } -CheckTableModel::~CheckTableModel() = default; +CheckTableModel::CheckTableModel(LibertyCell *cell, + TableModel *model) : + CheckTimingModel(cell), + model_(model), + sigma_models_{} +{ +} + +CheckTableModel::~CheckTableModel() +{ + sigmaModelsDelete(sigma_models_); +} void CheckTableModel::setIsScaled(bool is_scaled) @@ -434,7 +453,7 @@ CheckTableModel::setIsScaled(bool is_scaled) const TableModel * CheckTableModel::sigmaModel(const EarlyLate *el) const { - return sigma_models_[el->index()].get(); + return sigma_models_[el->index()]; } ArcDelay @@ -449,10 +468,10 @@ CheckTableModel::checkDelay(const Pvt *pvt, float sigma_early = 0.0; float sigma_late = 0.0; if (pocv_enabled && sigma_models_[EarlyLate::earlyIndex()]) - sigma_early = findValue(pvt, sigma_models_[EarlyLate::earlyIndex()].get(), + sigma_early = findValue(pvt, sigma_models_[EarlyLate::earlyIndex()], from_slew, to_slew, related_out_cap); if (pocv_enabled && sigma_models_[EarlyLate::lateIndex()]) - sigma_late = findValue(pvt, sigma_models_[EarlyLate::lateIndex()].get(), + sigma_late = findValue(pvt, sigma_models_[EarlyLate::lateIndex()], from_slew, to_slew, related_out_cap); return makeDelay(mean, sigma_early, sigma_late); } @@ -491,12 +510,12 @@ CheckTableModel::reportCheckDelay(const Pvt *pvt, related_out_cap, digits); if (pocv_enabled && sigma_models_[EarlyLate::earlyIndex()]) result += reportTableDelay("Check sigma early", pvt, - sigma_models_[EarlyLate::earlyIndex()].get(), + sigma_models_[EarlyLate::earlyIndex()], from_slew, from_slew_annotation, to_slew, related_out_cap, digits); if (pocv_enabled && sigma_models_[EarlyLate::lateIndex()]) result += reportTableDelay("Check sigma late", pvt, - sigma_models_[EarlyLate::lateIndex()].get(), + sigma_models_[EarlyLate::lateIndex()], from_slew, from_slew_annotation, to_slew, related_out_cap, digits); return result; @@ -587,7 +606,7 @@ CheckTableModel::axisValue(const TableAxis *axis, } bool -CheckTableModel::checkAxes(const TablePtr table) +CheckTableModel::checkAxes(const TableModel *table) { const TableAxis *axis1 = table->axis1(); const TableAxis *axis2 = table->axis2(); diff --git a/liberty/TimingArc.cc b/liberty/TimingArc.cc index 347c56fe..1f1ea2c1 100644 --- a/liberty/TimingArc.cc +++ b/liberty/TimingArc.cc @@ -204,6 +204,16 @@ TimingArcSet::TimingArcSet(const TimingRole *role, { } +std::string +TimingArcSet::to_string() +{ + std::string str = from_->name(); + str += " -> "; + str += to_->name(); + str += " " + role()->to_string(); + return str; +} + TimingArcSet::~TimingArcSet() { deleteContents(arcs_); @@ -622,7 +632,7 @@ TimingArc::equiv(const TimingArc *arc1, } void -TimingArc::setIndex(unsigned index) +TimingArc::setIndex(size_t index) { index_ = index; } diff --git a/power/Power.cc b/power/Power.cc index db3ef053..4319de04 100644 --- a/power/Power.cc +++ b/power/Power.cc @@ -292,7 +292,7 @@ Power::reportDesign(const Scene *scene, PowerResult total, sequential, combinational, clock, macro, pad; power(scene, total, sequential, combinational, clock, macro, pad); ReportPower report_power(this); - report_power.reportDesign(total, sequential, combinational, clock, macro, pad, digits); + report_power.reportDesign(total, sequential, combinational, clock, macro, pad, digits); } void diff --git a/search/MakeTimingModel.cc b/search/MakeTimingModel.cc index 7e3f89b8..1c605a26 100644 --- a/search/MakeTimingModel.cc +++ b/search/MakeTimingModel.cc @@ -79,7 +79,7 @@ MakeTimingModel::MakeTimingModel(const char *lib_name, scene_(scene), cell_(nullptr), min_max_(MinMax::max()), - lib_builder_(new LibertyBuilder), + lib_builder_(new LibertyBuilder(debug_, report_)), tbl_template_index_(1), sdc_(scene->sdc()), sdc_backup_(nullptr), @@ -611,7 +611,7 @@ MakeTimingModel::makeScalarCheckModel(float value, library_->findTableTemplate("scalar", TableTemplateType::delay); TableModel *table_model = new TableModel(table, tbl_template, scale_factor_type, rf); - CheckTableModel *check_model = new CheckTableModel(cell_, table_model, nullptr); + CheckTableModel *check_model = new CheckTableModel(cell_, table_model); return check_model; } @@ -628,9 +628,7 @@ MakeTimingModel::makeGateModelScalar(Delay delay, ScaleFactorType::cell, rf); TableModel *slew_model = new TableModel(slew_table, tbl_template, ScaleFactorType::cell, rf); - GateTableModel *gate_model = new GateTableModel(cell_, delay_model, nullptr, - slew_model, nullptr, - nullptr, nullptr); + GateTableModel *gate_model = new GateTableModel(cell_, delay_model, slew_model); return gate_model; } @@ -643,9 +641,7 @@ MakeTimingModel::makeGateModelScalar(Delay delay, library_->findTableTemplate("scalar", TableTemplateType::delay); TableModel *delay_model = new TableModel(delay_table, tbl_template, ScaleFactorType::cell, rf); - GateTableModel *gate_model = new GateTableModel(cell_, delay_model, nullptr, - nullptr, nullptr, - nullptr, nullptr); + GateTableModel *gate_model = new GateTableModel(cell_, delay_model, nullptr); return gate_model; } @@ -721,10 +717,8 @@ MakeTimingModel::makeGateModelTable(const Pin *output_pin, ScaleFactorType::cell, rf); TableModel *slew_model = new TableModel(slew_table, model_template, ScaleFactorType::cell, rf); - GateTableModel *gate_model = new GateTableModel(cell_, - delay_model, nullptr, - slew_model, nullptr, - nullptr, nullptr); + GateTableModel *gate_model = new GateTableModel(cell_, delay_model, + slew_model); return gate_model; } } diff --git a/search/PathEnd.cc b/search/PathEnd.cc index 2a7af024..7e72e6fb 100644 --- a/search/PathEnd.cc +++ b/search/PathEnd.cc @@ -1178,7 +1178,7 @@ PathEndLatchCheck::sourceClkOffset(const StaState *sta) const const TimingRole * PathEndLatchCheck::checkRole(const StaState *sta) const { - if (clk_path_->clkInfo(sta)->isPulseClk()) + if (clk_path_ && clk_path_->clkInfo(sta)->isPulseClk()) // Pulse latches use register cycle accounting. return TimingRole::setup(); else diff --git a/test/get_is_memory.tcl b/test/get_is_memory.tcl index 23080a99..61d9d461 100644 --- a/test/get_is_memory.tcl +++ b/test/get_is_memory.tcl @@ -1,4 +1,4 @@ -# Tests whether the is_memory attribute works for cells and libcells +# Tests whether the is_memory attribute works for instances and cells read_liberty gf180mcu_sram.lib.gz read_liberty asap7_small.lib.gz read_verilog get_is_memory.v diff --git a/test/gf180mcu_sram.lib.gz b/test/gf180mcu_sram.lib.gz index b4ab4b9f..84279e46 100644 Binary files a/test/gf180mcu_sram.lib.gz and b/test/gf180mcu_sram.lib.gz differ diff --git a/test/liberty_arcs_one2one_1.ok b/test/liberty_arcs_one2one_1.ok index dc99d32b..eac1a900 100644 --- a/test/liberty_arcs_one2one_1.ok +++ b/test/liberty_arcs_one2one_1.ok @@ -1,3 +1,4 @@ +Warning 1195: liberty_arcs_one2one_1.lib line 45, port Y function size does not match port size. Warning 1216: liberty_arcs_one2one_1.lib line 48, timing port A and related port Y are different sizes. report_edges -from partial_wide_inv_cell/A[0] A[0] -> Y[0] combinational diff --git a/test/liberty_arcs_one2one_2.ok b/test/liberty_arcs_one2one_2.ok index 323145d3..0dbc0a3a 100644 --- a/test/liberty_arcs_one2one_2.ok +++ b/test/liberty_arcs_one2one_2.ok @@ -1,3 +1,4 @@ +Warning 1195: liberty_arcs_one2one_2.lib line 45, port Y function size does not match port size. Warning 1216: liberty_arcs_one2one_2.lib line 48, timing port A and related port Y are different sizes. report_edges -to partial_wide_inv_cell/Y[0] A[0] -> Y[0] combinational diff --git a/util/TokenParser.cc b/util/TokenParser.cc index e048cecf..d0a44859 100644 --- a/util/TokenParser.cc +++ b/util/TokenParser.cc @@ -87,4 +87,27 @@ TokenParser::next() return token_; } +//////////////////////////////////////////////////////////////// + +// Parse space separated tokens. +StdStringSeq +parseTokens(const std::string &s, + const char delimiter) +{ + StdStringSeq tokens; + size_t i = 0; + while (i < s.size()) { + while (i < s.size() && std::isspace(s[i])) + ++i; + size_t start = i; + while (i < s.size() && s[i] != delimiter) + ++i; + if (start < i) { + tokens.emplace_back(s, start, i - start); + ++i; + } + } + return tokens; +} + } // namespace