Property add units

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2022-04-21 10:59:47 -07:00
parent 05844f2698
commit 489ffac144
3 changed files with 73 additions and 46 deletions

View File

@ -49,10 +49,10 @@ 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();
explicit PropertyValue(const char *value); PropertyValue(const char *value);
explicit PropertyValue(string &value); PropertyValue(string &value);
explicit PropertyValue(float value); PropertyValue(float value,
explicit PropertyValue(double value); const Unit *unit);
explicit PropertyValue(bool value); explicit PropertyValue(bool value);
PropertyValue(Library *value); PropertyValue(Library *value);
PropertyValue(Cell *value); PropertyValue(Cell *value);
@ -76,6 +76,8 @@ public:
PropertyValue(PropertyValue &&props); PropertyValue(PropertyValue &&props);
~PropertyValue(); ~PropertyValue();
Type type() const { return type_; } Type type() const { return type_; }
const Unit *unit() const { return unit_; }
const char *stringValue() const { return string_; } const char *stringValue() const { return string_; }
float floatValue() const { return float_; } float floatValue() const { return float_; }
bool boolValue() const { return bool_; } bool boolValue() const { return bool_; }
@ -93,6 +95,7 @@ public:
ClockSeq *clocks() const { return clks_; } ClockSeq *clocks() const { return clks_; }
PathRefSeq *pathRefs() const { return path_refs_; } PathRefSeq *pathRefs() const { return path_refs_; }
PwrActivity pwrActivity() const { return pwr_activity_; } PwrActivity pwrActivity() const { return pwr_activity_; }
// Copy assignment. // Copy assignment.
PropertyValue &operator=(const PropertyValue &); PropertyValue &operator=(const PropertyValue &);
// Move assignment. // Move assignment.
@ -119,6 +122,7 @@ private:
PathRefSeq *path_refs_; PathRefSeq *path_refs_;
PwrActivity pwr_activity_; PwrActivity pwr_activity_;
}; };
const Unit *unit_;
}; };
PropertyValue PropertyValue

View File

@ -67,10 +67,10 @@ static PropertyValue
delayPropertyValue(Delay delay, delayPropertyValue(Delay delay,
Sta *sta); Sta *sta);
static PropertyValue static PropertyValue
resistancePropertyValue(Delay delay, resistancePropertyValue(float res,
Sta *sta); Sta *sta);
static PropertyValue static PropertyValue
capacitancePropertyValue(Delay delay, capacitancePropertyValue(float cap,
Sta *sta); Sta *sta);
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -106,97 +106,107 @@ PropertyUnknown::what() const noexcept
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
PropertyValue::PropertyValue() : PropertyValue::PropertyValue() :
type_(type_none) type_(type_none),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(const char *value) : PropertyValue::PropertyValue(const char *value) :
type_(type_string), type_(type_string),
string_(stringCopy(value)) string_(stringCopy(value)),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(std::string &value) : PropertyValue::PropertyValue(std::string &value) :
type_(type_string), type_(type_string),
string_(stringCopy(value.c_str())) string_(stringCopy(value.c_str())),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(float value) : PropertyValue::PropertyValue(float value,
const Unit *unit) :
type_(type_float), type_(type_float),
float_(value) float_(value),
{ unit_(unit)
}
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),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(LibertyLibrary *value) : PropertyValue::PropertyValue(LibertyLibrary *value) :
type_(type_liberty_library), type_(type_liberty_library),
liberty_library_(value) liberty_library_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(LibertyCell *value) : PropertyValue::PropertyValue(LibertyCell *value) :
type_(type_liberty_cell), type_(type_liberty_cell),
liberty_cell_(value) liberty_cell_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(LibertyPort *value) : PropertyValue::PropertyValue(LibertyPort *value) :
type_(type_liberty_port), type_(type_liberty_port),
liberty_port_(value) liberty_port_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Library *value) : PropertyValue::PropertyValue(Library *value) :
type_(type_library), type_(type_library),
library_(value) library_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Cell *value) : PropertyValue::PropertyValue(Cell *value) :
type_(type_cell), type_(type_cell),
cell_(value) cell_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Port *value) : PropertyValue::PropertyValue(Port *value) :
type_(type_port), type_(type_port),
port_(value) port_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Instance *value) : PropertyValue::PropertyValue(Instance *value) :
type_(type_instance), type_(type_instance),
inst_(value) inst_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Pin *value) : PropertyValue::PropertyValue(Pin *value) :
type_(type_pin), type_(type_pin),
pin_(value) pin_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(PinSeq *value) : PropertyValue::PropertyValue(PinSeq *value) :
type_(type_pins), type_(type_pins),
pins_(value) pins_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(PinSet *value) : PropertyValue::PropertyValue(PinSet *value) :
type_(type_pins), type_(type_pins),
pins_(new PinSeq) pins_(new PinSeq),
unit_(nullptr)
{ {
PinSet::Iterator pin_iter(value); PinSet::Iterator pin_iter(value);
while (pin_iter.hasNext()) { while (pin_iter.hasNext()) {
@ -207,25 +217,29 @@ PropertyValue::PropertyValue(PinSet *value) :
PropertyValue::PropertyValue(Net *value) : PropertyValue::PropertyValue(Net *value) :
type_(type_net), type_(type_net),
net_(value) net_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(Clock *value) : PropertyValue::PropertyValue(Clock *value) :
type_(type_clk), type_(type_clk),
clk_(value) clk_(value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(ClockSeq *value) : PropertyValue::PropertyValue(ClockSeq *value) :
type_(type_clks), type_(type_clks),
clks_(new ClockSeq(*value)) clks_(new ClockSeq(*value)),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(ClockSet *value) : PropertyValue::PropertyValue(ClockSet *value) :
type_(type_clks), type_(type_clks),
clks_(new ClockSeq) clks_(new ClockSeq),
unit_(nullptr)
{ {
ClockSet::Iterator clk_iter(value); ClockSet::Iterator clk_iter(value);
while (clk_iter.hasNext()) { while (clk_iter.hasNext()) {
@ -236,18 +250,21 @@ PropertyValue::PropertyValue(ClockSet *value) :
PropertyValue::PropertyValue(PathRefSeq *value) : PropertyValue::PropertyValue(PathRefSeq *value) :
type_(type_path_refs), type_(type_path_refs),
path_refs_(new PathRefSeq(*value)) path_refs_(new PathRefSeq(*value)),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(PwrActivity *value) : PropertyValue::PropertyValue(PwrActivity *value) :
type_(type_pwr_activity), type_(type_pwr_activity),
pwr_activity_(*value) pwr_activity_(*value),
unit_(nullptr)
{ {
} }
PropertyValue::PropertyValue(const PropertyValue &value) : PropertyValue::PropertyValue(const PropertyValue &value) :
type_(value.type_) type_(value.type_),
unit_(value.unit_)
{ {
switch (type_) { switch (type_) {
case Type::type_none: case Type::type_none:
@ -307,7 +324,9 @@ PropertyValue::PropertyValue(const PropertyValue &value) :
} }
PropertyValue::PropertyValue(PropertyValue &&value) : PropertyValue::PropertyValue(PropertyValue &&value) :
type_(value.type_) type_(value.type_),
unit_(value.unit_)
{ {
switch (type_) { switch (type_) {
case Type::type_none: case Type::type_none:
@ -396,6 +415,8 @@ PropertyValue &
PropertyValue::operator=(const PropertyValue &value) PropertyValue::operator=(const PropertyValue &value)
{ {
type_ = value.type_; type_ = value.type_;
unit_ = value.unit_;
switch (type_) { switch (type_) {
case Type::type_none: case Type::type_none:
break; break;
@ -458,6 +479,8 @@ PropertyValue &
PropertyValue::operator=(PropertyValue &&value) PropertyValue::operator=(PropertyValue &&value)
{ {
type_ = value.type_; type_ = value.type_;
unit_ = value.unit_;
switch (type_) { switch (type_) {
case Type::type_none: case Type::type_none:
break; break;
@ -854,7 +877,7 @@ pinSlewProperty(const Pin *pin,
if (delayGreater(vertex_slew, slew, min_max, sta)) if (delayGreater(vertex_slew, slew, min_max, sta))
slew = vertex_slew; slew = vertex_slew;
} }
return PropertyValue(delayPropertyValue(slew, sta)); return delayPropertyValue(slew, sta);
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -969,7 +992,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()->staToUser(clk->period())); return PropertyValue(clk->period(), sta->units()->timeUnit());
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"))
@ -1035,21 +1058,21 @@ static PropertyValue
delayPropertyValue(Delay delay, delayPropertyValue(Delay delay,
Sta *sta) Sta *sta)
{ {
return PropertyValue(sta->units()->timeUnit()->staToUser(delayAsFloat(delay))); return PropertyValue(delayAsFloat(delay), sta->units()->timeUnit());
} }
static PropertyValue static PropertyValue
resistancePropertyValue(Delay delay, resistancePropertyValue(float res,
Sta *sta) Sta *sta)
{ {
return PropertyValue(sta->units()->resistanceUnit()->staToUser(delayAsFloat(delay))); return PropertyValue(res, sta->units()->resistanceUnit());
} }
static PropertyValue static PropertyValue
capacitancePropertyValue(Delay delay, capacitancePropertyValue(float cap,
Sta *sta) Sta *sta)
{ {
return PropertyValue(sta->units()->capacitanceUnit()->staToUser(delayAsFloat(delay))); return PropertyValue(cap, sta->units()->capacitanceUnit());
} }
} // namespace } // namespace

View File

@ -1420,9 +1420,9 @@ using namespace sta;
Tcl_SetResult(interp, const_cast<char*>(value.stringValue()), TCL_VOLATILE); Tcl_SetResult(interp, const_cast<char*>(value.stringValue()), TCL_VOLATILE);
break; break;
case PropertyValue::Type::type_float: { case PropertyValue::Type::type_float: {
char *float_string = stringPrint("%.6e", value.floatValue()); const Unit *unit = value.unit();
Tcl_SetResult(interp, float_string, TCL_VOLATILE); const char *float_string = unit->asString(value.floatValue(), 6);
stringDelete(float_string); Tcl_SetResult(interp, const_cast<char*>(float_string), TCL_VOLATILE);
} }
break; break;
case PropertyValue::Type::type_bool: { case PropertyValue::Type::type_bool: {