PropertyValue float use constructors instead of strings

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2022-04-15 14:15:25 -07:00
parent d7d40a6f22
commit 05844f2698
2 changed files with 56 additions and 29 deletions

View File

@ -49,10 +49,11 @@ public:
type_instance, type_pin, type_pins, type_net, type_instance, type_pin, type_pins, type_net,
type_clk, type_clks, type_path_refs, type_pwr_activity }; type_clk, type_clks, type_path_refs, type_pwr_activity };
PropertyValue(); PropertyValue();
PropertyValue(const char *value); explicit PropertyValue(const char *value);
PropertyValue(string &value); explicit PropertyValue(string &value);
PropertyValue(float value); explicit PropertyValue(float value);
PropertyValue(bool value); explicit PropertyValue(double value);
explicit PropertyValue(bool value);
PropertyValue(Library *value); PropertyValue(Library *value);
PropertyValue(Cell *value); PropertyValue(Cell *value);
PropertyValue(Port *value); PropertyValue(Port *value);

View File

@ -63,9 +63,15 @@ edgeDelayProperty(Edge *edge,
const RiseFall *rf, const RiseFall *rf,
const MinMax *min_max, const MinMax *min_max,
Sta *sta); Sta *sta);
static float static PropertyValue
delayPropertyValue(Delay delay, delayPropertyValue(Delay delay,
Sta *sta); Sta *sta);
static PropertyValue
resistancePropertyValue(Delay delay,
Sta *sta);
static PropertyValue
capacitancePropertyValue(Delay delay,
Sta *sta);
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -122,6 +128,12 @@ PropertyValue::PropertyValue(float value) :
{ {
} }
PropertyValue::PropertyValue(double value) :
type_(type_float),
float_(value)
{
}
PropertyValue::PropertyValue(bool value) : PropertyValue::PropertyValue(bool value) :
type_(type_bool), type_(type_bool),
bool_(value) bool_(value)
@ -685,55 +697,55 @@ getProperty(const LibertyPort *port,
return PropertyValue(port->direction()->name()); return PropertyValue(port->direction()->name());
else if (stringEqual(property, "capacitance")) { else if (stringEqual(property, "capacitance")) {
float cap = port->capacitance(RiseFall::rise(), MinMax::max()); float cap = port->capacitance(RiseFall::rise(), MinMax::max());
return PropertyValue(sta->units()->capacitanceUnit()->asString(cap, 6)); return capacitancePropertyValue(cap, sta);
} }
else if (stringEqual(property, "is_register_clock")) else if (stringEqual(property, "is_register_clock"))
return PropertyValue(port->isRegClk()); return PropertyValue(port->isRegClk());
else if (stringEqual(property, "drive_resistance")) { else if (stringEqual(property, "drive_resistance")) {
float res = port->driveResistance(); float res = port->driveResistance();
return PropertyValue(sta->units()->resistanceUnit()->asString(res, 6)); return resistancePropertyValue(res, sta);
} }
else if (stringEqual(property, "drive_resistance_rise_min")) { else if (stringEqual(property, "drive_resistance_rise_min")) {
float res = port->driveResistance(RiseFall::rise(), MinMax::min()); float res = port->driveResistance(RiseFall::rise(), MinMax::min());
return PropertyValue(sta->units()->resistanceUnit()->asString(res, 6)); return resistancePropertyValue(res, sta);
} }
else if (stringEqual(property, "drive_resistance_rise_max")) { else if (stringEqual(property, "drive_resistance_rise_max")) {
float res = port->driveResistance(RiseFall::rise(), MinMax::max()); float res = port->driveResistance(RiseFall::rise(), MinMax::max());
return PropertyValue(sta->units()->resistanceUnit()->asString(res, 6)); return resistancePropertyValue(res, sta);
} }
else if (stringEqual(property, "drive_resistance_fall_min")) { else if (stringEqual(property, "drive_resistance_fall_min")) {
float res = port->driveResistance(RiseFall::fall(), MinMax::min()); float res = port->driveResistance(RiseFall::fall(), MinMax::min());
return PropertyValue(sta->units()->resistanceUnit()->asString(res, 6)); return resistancePropertyValue(res, sta);
} }
else if (stringEqual(property, "drive_resistance_fall_max")) { else if (stringEqual(property, "drive_resistance_fall_max")) {
float res = port->driveResistance(RiseFall::fall(), MinMax::max()); float res = port->driveResistance(RiseFall::fall(), MinMax::max());
return PropertyValue(sta->units()->resistanceUnit()->asString(res, 6)); return resistancePropertyValue(res, sta);
} }
else if (stringEqual(property, "intrinsic_delay")) { else if (stringEqual(property, "intrinsic_delay")) {
float drive = delayAsFloat(port->intrinsicDelay(sta)); ArcDelay delay = port->intrinsicDelay(sta);
return PropertyValue(sta->units()->timeUnit()->asString(drive, 6)); return delayPropertyValue(delay, sta);
} }
else if (stringEqual(property, "intrinsic_delay_rise_min")) { else if (stringEqual(property, "intrinsic_delay_rise_min")) {
float drive = delayAsFloat(port->intrinsicDelay(RiseFall::rise(), ArcDelay delay = port->intrinsicDelay(RiseFall::rise(),
MinMax::min(), sta)); MinMax::min(), sta);
return PropertyValue(sta->units()->timeUnit()->asString(drive, 6)); return delayPropertyValue(delay, sta);
} }
else if (stringEqual(property, "intrinsic_delay_rise_max")) { else if (stringEqual(property, "intrinsic_delay_rise_max")) {
float drive = delayAsFloat(port->intrinsicDelay(RiseFall::rise(), ArcDelay delay = port->intrinsicDelay(RiseFall::rise(),
MinMax::max(), sta)); MinMax::max(), sta);
return PropertyValue(sta->units()->timeUnit()->asString(drive, 6)); return delayPropertyValue(delay, sta);
} }
else if (stringEqual(property, "intrinsic_delay_fall_min")) { else if (stringEqual(property, "intrinsic_delay_fall_min")) {
float drive = delayAsFloat(port->intrinsicDelay(RiseFall::fall(), ArcDelay delay = port->intrinsicDelay(RiseFall::fall(),
MinMax::min(), sta)); MinMax::min(), sta);
return PropertyValue(sta->units()->timeUnit()->asString(drive, 6)); return delayPropertyValue(delay, sta);
} }
else if (stringEqual(property, "intrinsic_delay_fall_max")) { else if (stringEqual(property, "intrinsic_delay_fall_max")) {
float drive = delayAsFloat(port->intrinsicDelay(RiseFall::fall(), ArcDelay delay = port->intrinsicDelay(RiseFall::fall(),
MinMax::max(), sta)); MinMax::max(), sta);
return PropertyValue(sta->units()->timeUnit()->asString(drive, 6)); return delayPropertyValue(delay, sta);
} }
else else
throw PropertyUnknown("liberty port", property); throw PropertyUnknown("liberty port", property);
@ -873,7 +885,7 @@ getProperty(Edge *edge,
auto graph = sta->graph(); auto graph = sta->graph();
const char *from = edge->from(graph)->name(network); const char *from = edge->from(graph)->name(network);
const char *to = edge->to(graph)->name(network); const char *to = edge->to(graph)->name(network);
return stringPrintTmp("%s -> %s", from, to); return PropertyValue(stringPrintTmp("%s -> %s", from, to));
} }
if (stringEqual(property, "delay_min_fall")) if (stringEqual(property, "delay_min_fall"))
return edgeDelayProperty(edge, RiseFall::fall(), MinMax::min(), sta); return edgeDelayProperty(edge, RiseFall::fall(), MinMax::min(), sta);
@ -957,7 +969,7 @@ getProperty(Clock *clk,
|| stringEqual(property, "full_name")) || stringEqual(property, "full_name"))
return PropertyValue(clk->name()); return PropertyValue(clk->name());
else if (stringEqual(property, "period")) else if (stringEqual(property, "period"))
return PropertyValue(sta->units()->timeUnit()->asString(clk->period(), 6)); return PropertyValue(sta->units()->timeUnit()->staToUser(clk->period()));
else if (stringEqual(property, "sources")) else if (stringEqual(property, "sources"))
return PropertyValue(&clk->pins()); return PropertyValue(&clk->pins());
else if (stringEqual(property, "propagated")) else if (stringEqual(property, "propagated"))
@ -1019,11 +1031,25 @@ getProperty(PathRef *path,
throw PropertyUnknown("path", property); throw PropertyUnknown("path", property);
} }
static float static PropertyValue
delayPropertyValue(Delay delay, delayPropertyValue(Delay delay,
Sta *sta) Sta *sta)
{ {
return delayAsFloat(delay) / sta->units()->timeUnit()->scale(); return PropertyValue(sta->units()->timeUnit()->staToUser(delayAsFloat(delay)));
}
static PropertyValue
resistancePropertyValue(Delay delay,
Sta *sta)
{
return PropertyValue(sta->units()->resistanceUnit()->staToUser(delayAsFloat(delay)));
}
static PropertyValue
capacitancePropertyValue(Delay delay,
Sta *sta)
{
return PropertyValue(sta->units()->capacitanceUnit()->staToUser(delayAsFloat(delay)));
} }
} // namespace } // namespace