liberty reader range iteration

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2023-08-22 14:11:54 -07:00
parent 2c28538bea
commit 3a784e918e
2 changed files with 48 additions and 133 deletions

View File

@ -1904,15 +1904,10 @@ LibertyReader::endCell(LibertyGroup *group)
void void
LibertyReader::finishPortGroups() LibertyReader::finishPortGroups()
{ {
PortGroupSeq::Iterator group_iter(cell_port_groups_); for (PortGroup *port_group : cell_port_groups_) {
while (group_iter.hasNext()) {
PortGroup *port_group = group_iter.next();
int line = port_group->line(); int line = port_group->line();
LibertyPortSeq::Iterator port_iter(port_group->ports()); for (LibertyPort *port : *port_group->ports())
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
checkPort(port, line); checkPort(port, line);
}
makeTimingArcs(port_group); makeTimingArcs(port_group);
makeInternalPowers(port_group); makeInternalPowers(port_group);
delete port_group; delete port_group;
@ -1939,30 +1934,20 @@ LibertyReader::checkPort(LibertyPort *port,
void void
LibertyReader::makeTimingArcs(PortGroup *port_group) LibertyReader::makeTimingArcs(PortGroup *port_group)
{ {
TimingGroupSeq::Iterator timing_iter(port_group->timingGroups()); for (TimingGroup *timing : port_group->timingGroups()) {
while (timing_iter.hasNext()) {
TimingGroup *timing = timing_iter.next();
timing->makeTimingModels(library_, this); timing->makeTimingModels(library_, this);
LibertyPortSeq::Iterator port_iter(port_group->ports()); for (LibertyPort *port : *port_group->ports())
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
makeTimingArcs(port, timing); makeTimingArcs(port, timing);
} }
} }
}
void void
LibertyReader::makeInternalPowers(PortGroup *port_group) LibertyReader::makeInternalPowers(PortGroup *port_group)
{ {
InternalPowerGroupSeq::Iterator power_iter(port_group->internalPowerGroups()); for (InternalPowerGroup *power_group : port_group->internalPowerGroups()) {
while (power_iter.hasNext()) { for (LibertyPort *port : *port_group->ports())
InternalPowerGroup *power_group = power_iter.next();
LibertyPortSeq::Iterator port_iter(port_group->ports());
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
makeInternalPowers(port, power_group); makeInternalPowers(port, power_group);
}
cell_->addInternalPowerAttrs(power_group); cell_->addInternalPowerAttrs(power_group);
} }
} }
@ -1970,9 +1955,7 @@ LibertyReader::makeInternalPowers(PortGroup *port_group)
void void
LibertyReader::makeCellSequentials() LibertyReader::makeCellSequentials()
{ {
SequentialGroupSeq::Iterator seq_iter(cell_sequentials_); for (SequentialGroup *seq : cell_sequentials_) {
while (seq_iter.hasNext()) {
SequentialGroup *seq = seq_iter.next();
makeCellSequential(seq); makeCellSequential(seq);
delete seq; delete seq;
} }
@ -2077,9 +2060,7 @@ LibertyReader::checkLatchEnableSense(FuncExpr *enable_func,
void void
LibertyReader::makeLeakagePowers() LibertyReader::makeLeakagePowers()
{ {
LeakagePowerGroupSeq::Iterator power_iter(leakage_powers_); for (LeakagePowerGroup *power_group : leakage_powers_) {
while (power_iter.hasNext()) {
LeakagePowerGroup *power_group = power_iter.next();
builder_->makeLeakagePower(cell_, power_group); builder_->makeLeakagePower(cell_, power_group);
delete power_group; delete power_group;
} }
@ -2103,9 +2084,7 @@ LibertyReader::makeLibertyFunc(const char *expr,
void void
LibertyReader::parseCellFuncs() LibertyReader::parseCellFuncs()
{ {
LibertyFuncSeq::Iterator func_iter(cell_funcs_); for (LibertyFunc *func : cell_funcs_) {
while (func_iter.hasNext()) {
LibertyFunc *func = func_iter.next();
FuncExpr *expr = parseFunc(func->expr(), func->attrName(), func->line()); FuncExpr *expr = parseFunc(func->expr(), func->attrName(), func->line());
if (func->invert() && expr) { if (func->invert() && expr) {
if (expr->op() == FuncExpr::op_not) { if (expr->op() == FuncExpr::op_not) {
@ -2205,9 +2184,8 @@ LibertyReader::makeTimingArcs(LibertyPort *to_port,
if (type == TimingType::combinational && if (type == TimingType::combinational &&
to_port_dir->isInput()) to_port_dir->isInput())
libWarn(94, line, "combinational timing to an input port."); libWarn(94, line, "combinational timing to an input port.");
StringSeq::Iterator related_port_iter(timing->relatedPortNames()); if (timing->relatedPortNames()) {
while (related_port_iter.hasNext()) { for (const char *from_port_name : *timing->relatedPortNames()) {
const char *from_port_name = related_port_iter.next();
PortNameBitIterator from_port_iter(cell_, from_port_name, this, line); PortNameBitIterator from_port_iter(cell_, from_port_name, this, line);
if (from_port_iter.hasNext()) { if (from_port_iter.hasNext()) {
debugPrint(debug_, "liberty", 2, " timing %s -> %s", debugPrint(debug_, "liberty", 2, " timing %s -> %s",
@ -2217,6 +2195,7 @@ LibertyReader::makeTimingArcs(LibertyPort *to_port,
} }
} }
} }
}
void void
TimingGroup::makeTimingModels(LibertyLibrary *library, TimingGroup::makeTimingModels(LibertyLibrary *library,
@ -2662,9 +2641,7 @@ LibertyReader::makeInternalPowers(LibertyPort *port,
int line = power_group->line(); int line = power_group->line();
StringSeq *related_port_names = power_group->relatedPortNames(); StringSeq *related_port_names = power_group->relatedPortNames();
if (related_port_names) { if (related_port_names) {
StringSeq::Iterator related_port_iter(related_port_names); for (const char *related_port_name : *related_port_names) {
while (related_port_iter.hasNext()) {
const char *related_port_name = related_port_iter.next();
PortNameBitIterator related_port_iter(cell_, related_port_name, this, line); PortNameBitIterator related_port_iter(cell_, related_port_name, this, line);
if (related_port_iter.hasNext()) { if (related_port_iter.hasNext()) {
debugPrint(debug_, "liberty", 2, " power %s -> %s", debugPrint(debug_, "liberty", 2, " power %s -> %s",
@ -2925,9 +2902,7 @@ LibertyReader::beginPin(LibertyGroup *group)
saved_ports_ = ports_; saved_ports_ = ports_;
saved_port_group_ = port_group_; saved_port_group_ = port_group_;
ports_ = new LibertyPortSeq; ports_ = new LibertyPortSeq;
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *param : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *param = param_iter.next();
if (param->isString()) { if (param->isString()) {
const char *port_name = param->stringValue(); const char *port_name = param->stringValue();
debugPrint(debug_, "liberty", 1, " port %s", port_name); debugPrint(debug_, "liberty", 1, " port %s", port_name);
@ -2945,9 +2920,7 @@ LibertyReader::beginPin(LibertyGroup *group)
saved_ports_ = ports_; saved_ports_ = ports_;
saved_port_group_ = port_group_; saved_port_group_ = port_group_;
ports_ = new LibertyPortSeq; ports_ = new LibertyPortSeq;
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *param : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *param = param_iter.next();
if (param->isString()) { if (param->isString()) {
const char *name = param->stringValue(); const char *name = param->stringValue();
debugPrint(debug_, "liberty", 1, " port %s", name); debugPrint(debug_, "liberty", 1, " port %s", name);
@ -2963,9 +2936,7 @@ LibertyReader::beginPin(LibertyGroup *group)
else { else {
ports_ = new LibertyPortSeq; ports_ = new LibertyPortSeq;
// Multiple port names can share group def. // Multiple port names can share group def.
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *param : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *param = param_iter.next();
if (param->isString()) { if (param->isString()) {
const char *name = param->stringValue(); const char *name = param->stringValue();
debugPrint(debug_, "liberty", 1, " port %s", name); debugPrint(debug_, "liberty", 1, " port %s", name);
@ -3004,9 +2975,7 @@ LibertyReader::endPorts()
{ {
// Capacitances default based on direction so wait until the end // Capacitances default based on direction so wait until the end
// of the pin group to set them. // of the pin group to set them.
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
if (in_bus_ || in_bundle_) { if (in_bus_ || in_bundle_) {
// Do not clobber member port capacitances by setting the capacitance // Do not clobber member port capacitances by setting the capacitance
// on a bus or bundle. // on a bus or bundle.
@ -3061,9 +3030,7 @@ void
LibertyReader::beginBusOrBundle(LibertyGroup *group) LibertyReader::beginBusOrBundle(LibertyGroup *group)
{ {
// Multiple port names can share group def. // Multiple port names can share group def.
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *param : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *param = param_iter.next();
if (param->isString()) { if (param->isString()) {
const char *name = param->stringValue(); const char *name = param->stringValue();
if (name) if (name)
@ -3097,9 +3064,7 @@ LibertyReader::visitBusType(LibertyAttr *attr)
if (bus_dcl == nullptr) if (bus_dcl == nullptr)
bus_dcl = library_->findBusDcl(bus_type); bus_dcl = library_->findBusDcl(bus_type);
if (bus_dcl) { if (bus_dcl) {
StringSeq::Iterator name_iter(bus_names_); for (const char *name : bus_names_) {
while (name_iter.hasNext()) {
const char *name = name_iter.next();
debugPrint(debug_, "liberty", 1, " bus %s", name); debugPrint(debug_, "liberty", 1, " bus %s", name);
LibertyPort *port = builder_->makeBusPort(cell_, name, bus_dcl->from(), LibertyPort *port = builder_->makeBusPort(cell_, name, bus_dcl->from(),
bus_dcl->to(), bus_dcl); bus_dcl->to(), bus_dcl);
@ -3139,14 +3104,10 @@ LibertyReader::visitMembers(LibertyAttr *attr)
{ {
if (cell_) { if (cell_) {
if (attr->isComplex()) { if (attr->isComplex()) {
StringSeq::Iterator name_iter(bus_names_); for (const char *name : bus_names_) {
while (name_iter.hasNext()) {
const char *name = name_iter.next();
debugPrint(debug_, "liberty", 1, " bundle %s", name); debugPrint(debug_, "liberty", 1, " bundle %s", name);
ConcretePortSeq *members = new ConcretePortSeq; ConcretePortSeq *members = new ConcretePortSeq;
LibertyAttrValueIterator value_iter(attr->values()); for (LibertyAttrValue *value : *attr->values()) {
while (value_iter.hasNext()) {
LibertyAttrValue *value = value_iter.next();
if (value->isString()) { if (value->isString()) {
const char *port_name = value->stringValue(); const char *port_name = value->stringValue();
LibertyPort *port = findPort(port_name); LibertyPort *port = findPort(port_name);
@ -3231,14 +3192,11 @@ LibertyReader::visitFunction(LibertyAttr *attr)
if (ports_) { if (ports_) {
const char *func = getAttrString(attr); const char *func = getAttrString(attr);
if (func) { if (func) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
makeLibertyFunc(func, port->functionRef(), false, "function", attr); makeLibertyFunc(func, port->functionRef(), false, "function", attr);
} }
} }
} }
}
void void
LibertyReader::visitThreeState(LibertyAttr *attr) LibertyReader::visitThreeState(LibertyAttr *attr)
@ -3246,22 +3204,17 @@ LibertyReader::visitThreeState(LibertyAttr *attr)
if (ports_) { if (ports_) {
const char *three_state = getAttrString(attr); const char *three_state = getAttrString(attr);
if (three_state) { if (three_state) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
makeLibertyFunc(three_state, port->tristateEnableRef(), true, makeLibertyFunc(three_state, port->tristateEnableRef(), true,
"three_state", attr); "three_state", attr);
} }
} }
} }
}
void void
LibertyReader::visitPorts(std::function<void (LibertyPort *port)> func) LibertyReader::visitPorts(std::function<void (LibertyPort *port)> func)
{ {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
func(port); func(port);
LibertyPortMemberIterator member_iter(port); LibertyPortMemberIterator member_iter(port);
while (member_iter.hasNext()) { while (member_iter.hasNext()) {
@ -3278,14 +3231,11 @@ LibertyReader::visitClock(LibertyAttr *attr)
bool is_clk, exists; bool is_clk, exists;
getAttrBool(attr, is_clk, exists); getAttrBool(attr, is_clk, exists);
if (exists) { if (exists) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setIsClock(is_clk); port->setIsClock(is_clk);
} }
} }
} }
}
void void
LibertyReader::visitCapacitance(LibertyAttr *attr) LibertyReader::visitCapacitance(LibertyAttr *attr)
@ -3296,13 +3246,10 @@ LibertyReader::visitCapacitance(LibertyAttr *attr)
getAttrFloat(attr, cap, exists); getAttrFloat(attr, cap, exists);
if (exists) { if (exists) {
cap *= cap_scale_; cap *= cap_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setCapacitance(cap); port->setCapacitance(cap);
} }
} }
}
if (wireload_) { if (wireload_) {
float value; float value;
bool exists; bool exists;
@ -3321,9 +3268,7 @@ LibertyReader::visitRiseCap(LibertyAttr *attr)
getAttrFloat(attr, cap, exists); getAttrFloat(attr, cap, exists);
if (exists) { if (exists) {
cap *= cap_scale_; cap *= cap_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setCapacitance(RiseFall::rise(), MinMax::min(), cap); port->setCapacitance(RiseFall::rise(), MinMax::min(), cap);
port->setCapacitance(RiseFall::rise(), MinMax::max(), cap); port->setCapacitance(RiseFall::rise(), MinMax::max(), cap);
} }
@ -3340,9 +3285,7 @@ LibertyReader::visitFallCap(LibertyAttr *attr)
getAttrFloat(attr, cap, exists); getAttrFloat(attr, cap, exists);
if (exists) { if (exists) {
cap *= cap_scale_; cap *= cap_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setCapacitance(RiseFall::fall(), MinMax::min(), cap); port->setCapacitance(RiseFall::fall(), MinMax::min(), cap);
port->setCapacitance(RiseFall::fall(), MinMax::max(), cap); port->setCapacitance(RiseFall::fall(), MinMax::max(), cap);
} }
@ -3360,9 +3303,7 @@ LibertyReader::visitRiseCapRange(LibertyAttr *attr)
if (exists) { if (exists) {
min *= cap_scale_; min *= cap_scale_;
max *= cap_scale_; max *= cap_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setCapacitance(RiseFall::rise(), MinMax::min(), min); port->setCapacitance(RiseFall::rise(), MinMax::min(), min);
port->setCapacitance(RiseFall::rise(), MinMax::max(), max); port->setCapacitance(RiseFall::rise(), MinMax::max(), max);
} }
@ -3380,9 +3321,7 @@ LibertyReader::visitFallCapRange(LibertyAttr *attr)
if (exists) { if (exists) {
min *= cap_scale_; min *= cap_scale_;
max *= cap_scale_; max *= cap_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_) {
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setCapacitance(RiseFall::fall(), MinMax::min(), min); port->setCapacitance(RiseFall::fall(), MinMax::min(), min);
port->setCapacitance(RiseFall::fall(), MinMax::max(), max); port->setCapacitance(RiseFall::fall(), MinMax::max(), max);
} }
@ -3516,14 +3455,11 @@ LibertyReader::visitMinPeriod(LibertyAttr *attr)
bool exists; bool exists;
getAttrFloat(attr, value, exists); getAttrFloat(attr, value, exists);
if (exists) { if (exists) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setMinPeriod(value * time_scale_); port->setMinPeriod(value * time_scale_);
} }
} }
} }
}
void void
LibertyReader::visitMinPulseWidthLow(LibertyAttr *attr) LibertyReader::visitMinPulseWidthLow(LibertyAttr *attr)
@ -3547,14 +3483,11 @@ LibertyReader::visitMinPulseWidth(LibertyAttr *attr,
getAttrFloat(attr, value, exists); getAttrFloat(attr, value, exists);
if (exists) { if (exists) {
value *= time_scale_; value *= time_scale_;
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setMinPulseWidth(rf, value); port->setMinPulseWidth(rf, value);
} }
} }
} }
}
void void
LibertyReader::visitPulseClock(LibertyAttr *attr) LibertyReader::visitPulseClock(LibertyAttr *attr)
@ -3583,15 +3516,12 @@ LibertyReader::visitPulseClock(LibertyAttr *attr)
else else
libWarn(110,attr, "pulse_latch unknown pulse type."); libWarn(110,attr, "pulse_latch unknown pulse type.");
if (trigger) { if (trigger) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setPulseClk(trigger, sense); port->setPulseClk(trigger, sense);
} }
} }
} }
} }
}
void void
LibertyReader::visitClockGateClockPin(LibertyAttr *attr) LibertyReader::visitClockGateClockPin(LibertyAttr *attr)
@ -3667,14 +3597,11 @@ LibertyReader::visitPortBoolAttr(LibertyAttr *attr,
bool value, exists; bool value, exists;
getAttrBool(attr, value, exists); getAttrBool(attr, value, exists);
if (exists) { if (exists) {
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
(port->*setter)(value); (port->*setter)(value);
} }
} }
} }
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -3772,9 +3699,7 @@ LibertyReader::seqPortNames(LibertyGroup *group,
out_inv_name = nullptr; out_inv_name = nullptr;
size = 1; size = 1;
has_size = false; has_size = false;
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *value : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *value = param_iter.next();
if (i == 0) if (i == 0)
out_name = value->stringValue(); out_name = value->stringValue();
else if (i == 1) else if (i == 1)
@ -4343,9 +4268,7 @@ LibertyReader::makeFloatTable(LibertyAttr *attr,
{ {
FloatTable *table = new FloatTable; FloatTable *table = new FloatTable;
table->reserve(rows); table->reserve(rows);
LibertyAttrValueIterator value_iter(attr->values()); for (LibertyAttrValue *value : *attr->values()) {
while (value_iter.hasNext()) {
LibertyAttrValue *value = value_iter.next();
FloatSeq *row = new FloatSeq; FloatSeq *row = new FloatSeq;
row->reserve(cols); row->reserve(cols);
table->push_back(row); table->push_back(row);
@ -4406,9 +4329,7 @@ void
LibertyReader::beginLut(LibertyGroup *group) LibertyReader::beginLut(LibertyGroup *group)
{ {
if (cell_) { if (cell_) {
LibertyAttrValueIterator param_iter(group->params()); for (LibertyAttrValue *param : *group->params()) {
while (param_iter.hasNext()) {
LibertyAttrValue *param = param_iter.next();
if (param->isString()) { if (param->isString()) {
const char *names = param->stringValue(); const char *names = param->stringValue();
// Parse space separated list of related port names. // Parse space separated list of related port names.
@ -4948,26 +4869,20 @@ LibertyReader::visitRelatedGroundPin(LibertyAttr *attr)
{ {
if (ports_) { if (ports_) {
const char *related_ground_pin = getAttrString(attr); const char *related_ground_pin = getAttrString(attr);
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setRelatedGroundPin(related_ground_pin); port->setRelatedGroundPin(related_ground_pin);
} }
} }
}
void void
LibertyReader::visitRelatedPowerPin(LibertyAttr *attr) LibertyReader::visitRelatedPowerPin(LibertyAttr *attr)
{ {
if (ports_) { if (ports_) {
const char *related_power_pin = getAttrString(attr); const char *related_power_pin = getAttrString(attr);
LibertyPortSeq::Iterator port_iter(ports_); for (LibertyPort *port : *ports_)
while (port_iter.hasNext()) {
LibertyPort *port = port_iter.next();
port->setRelatedPowerPin(related_power_pin); port->setRelatedPowerPin(related_power_pin);
} }
} }
}
void void
LibertyReader::visitRelatedPgPin(LibertyAttr *attr) LibertyReader::visitRelatedPgPin(LibertyAttr *attr)

View File

@ -674,9 +674,9 @@ public:
int line); int line);
~PortGroup(); ~PortGroup();
LibertyPortSeq *ports() const { return ports_; } LibertyPortSeq *ports() const { return ports_; }
TimingGroupSeq *timingGroups() { return &timings_; } TimingGroupSeq &timingGroups() { return timings_; }
void addTimingGroup(TimingGroup *timing); void addTimingGroup(TimingGroup *timing);
InternalPowerGroupSeq *internalPowerGroups() { return &internal_power_groups_; } InternalPowerGroupSeq &internalPowerGroups() { return internal_power_groups_; }
void addInternalPowerGroup(InternalPowerGroup *internal_power); void addInternalPowerGroup(InternalPowerGroup *internal_power);
ReceiverModel *receiverModel() const { return receiver_model_; } ReceiverModel *receiverModel() const { return receiver_model_; }
void setReceiverModel(ReceiverModelPtr receiver_model); void setReceiverModel(ReceiverModelPtr receiver_model);