Some refactoring - DEF scanner more modular (2)

This commit is contained in:
Matthias Koefferlein 2020-04-04 19:14:56 +02:00
parent 99af144d98
commit 9df6d29761
2 changed files with 833 additions and 794 deletions

View File

@ -360,137 +360,8 @@ DEFImporter::read_blockages (db::Layout &layout, db::Cell &design, double scale)
} }
void void
DEFImporter::do_read (db::Layout &layout) DEFImporter::read_nets (db::Layout &layout, db::Cell &design, double scale, bool specialnets)
{ {
double dbu_mic = 1000.0;
double scale = 1.0 / (dbu_mic * layout.dbu ());
std::map<int, db::Polygon> styles;
std::map<std::string, ViaDesc> via_desc = m_lef_importer.vias ();
std::map<std::string, std::vector<db::Polygon> > regions;
std::list<DEFImporterGroup> groups;
std::list<std::pair<std::string, db::CellInstArray> > instances;
db::Cell &design = layout.cell (layout.add_cell ("TOP"));
while (! at_end ()) {
bool specialnets = false;
if (test ("END")) {
// END DESIGN terminates the file
expect ("DESIGN");
break;
} else if (test ("DESIGN")) {
std::string cn = get ();
layout.rename_cell (design.cell_index (), layout.uniquify_cell_name (cn.c_str ()).c_str ());
expect (";");
} else if (test ("VERSION")) {
// ignore VERSION statement currently
take ();
expect (";");
} else if (test ("UNITS")) {
test ("DISTANCE");
test ("MICRONS");
double units = get_double ();
if (fabs (units) > 1e-6) {
scale = 1.0 / (units * layout.dbu ());
}
expect (";");
} else if (test ("DIEAREA")) {
read_diearea (layout, design, scale);
} else if (test ("PROPERTYDEFINITIONS")) {
// read over PROPERTYDEFINITIONS sections
while (! test ("END") || ! test ("PROPERTYDEFINITIONS")) {
take ();
}
} else if (test ("NONDEFAULTRULES")) {
// read NONDEFAULTRULES sections
get_long ();
expect (";");
read_nondefaultrules (scale);
expect ("END");
expect ("NONDEFAULTRULES");
} else if (test ("REGIONS")) {
// Read REGION statements
get_long ();
expect (";");
read_regions (regions, scale);
expect ("END");
expect ("REGIONS");
} else if (test ("PINPROPERTIES")) {
// read over PINPROPERTIES statements
while (! test ("END") || ! test ("PINPROPERTIES")) {
take ();
}
} else if (test ("SLOTS")) {
// read over SLOTS statements
while (! test ("END") || ! test ("SLOTS")) {
take ();
}
} else if (test ("FILLS")) {
// read over FILLS statements
while (! test ("END") || ! test ("FILLS")) {
take ();
}
} else if (test ("SCANCHAINS")) {
// read over SCANCHAINS statements
while (! test ("END") || ! test ("SCANCHAINS")) {
take ();
}
} else if (test ("GROUPS")) {
// Read GROUPS statements
get_long ();
expect (";");
read_groups (groups, scale);
expect ("END");
expect ("GROUPS");
} else if (test ("BEGINEXT")) {
// read over BEGINEXT sections
while (! test ("ENDEXT")) {
take ();
}
} else if (test ("BLOCKAGES")) {
get_long ();
expect (";");
read_blockages (layout, design, scale);
expect ("END");
expect ("BLOCKAGES");
} else if ((specialnets = test ("SPECIALNETS")) == true || test ("NETS")) {
get_long ();
expect (";");
while (test ("-")) { while (test ("-")) {
std::string net = get (); std::string net = get ();
@ -598,8 +469,8 @@ DEFImporter::do_read (db::Layout &layout)
def_ext = get_def_ext (ln, w, layout.dbu ()); def_ext = get_def_ext (ln, w, layout.dbu ());
} }
std::map<int, db::Polygon>::const_iterator s = styles.find (sn); std::map<int, db::Polygon>::const_iterator s = m_styles.find (sn);
if (s != styles.end ()) { if (s != m_styles.end ()) {
style = &s->second; style = &s->second;
} }
@ -825,8 +696,8 @@ DEFImporter::do_read (db::Layout &layout)
} }
std::map<std::string, ViaDesc>::const_iterator vd = via_desc.find (vn); std::map<std::string, ViaDesc>::const_iterator vd = m_via_desc.find (vn);
if (vd != via_desc.end () && ! pts.empty ()) { if (vd != m_via_desc.end () && ! pts.empty ()) {
if (nx <= 1 && ny <= 1) { if (nx <= 1 && ny <= 1) {
design.insert (db::CellInstArray (db::CellInst (vd->second.cell->cell_index ()), db::Trans (ft.rot (), db::Vector (pts.back ())))); design.insert (db::CellInstArray (db::CellInst (vd->second.cell->cell_index ()), db::Trans (ft.rot (), db::Vector (pts.back ()))));
} else { } else {
@ -908,23 +779,15 @@ DEFImporter::do_read (db::Layout &layout)
expect (";"); expect (";");
} }
test ("END");
if (specialnets) {
test ("SPECIALNETS");
} else {
test ("NETS");
} }
} else if (test ("VIAS")) { void
DEFImporter::read_vias (db::Layout &layout, db::Cell & /*design*/, double scale)
get_long (); {
expect (";");
while (test ("-")) { while (test ("-")) {
std::string n = get (); std::string n = get ();
ViaDesc &vd = via_desc.insert (std::make_pair (n, ViaDesc ())).first->second; ViaDesc &vd = m_via_desc.insert (std::make_pair (n, ViaDesc ())).first->second;
// produce a cell for vias // produce a cell for vias
std::string cellname = "VIA_" + n; std::string cellname = "VIA_" + n;
@ -1078,98 +941,11 @@ DEFImporter::do_read (db::Layout &layout)
} }
} }
expect ("END");
expect ("VIAS");
} else if (test ("STYLES")) {
get_long ();
expect (";");
while (test ("-")) {
test ("STYLE");
int sn = get_long ();
std::vector<db::Point> points;
double x = 0.0, y = 0.0;
while (! test (";")) {
test ("(");
if (! test ("*")) {
x = get_double ();
}
if (! test ("*")) {
y = get_double ();
}
points.push_back (db::Point (db::DPoint (x * scale, y * scale)));
test (")");
} }
styles.insert (std::make_pair (sn, db::Polygon ())).first->second.assign_hull (points.begin (), points.end ()); void
DEFImporter::read_pins (db::Layout &layout, db::Cell &design, double scale)
} {
test ("END");
test ("STYLES");
} else if (test ("COMPONENTS")) {
get_long ();
expect (";");
while (test ("-")) {
std::string inst_name = get ();
std::string model = get ();
db::Cell *cell = m_lef_importer.macro_by_name (model);
while (test ("+")) {
if (test ("PLACED") || test ("FIXED") || test ("COVER")) {
test ("(");
double x = get_double ();
double y = get_double ();
db::Point pt = db::Point (db::DPoint (x * scale, y * scale));
test (")");
db::FTrans ft = get_orient (false /*mandatory*/);
db::Vector d = pt - m_lef_importer.macro_bbox_by_name (model).transformed (ft).lower_left ();
if (cell) {
db::CellInstArray inst (db::CellInst (cell->cell_index ()), db::Trans (ft.rot (), d));
instances.push_back (std::make_pair (inst_name, inst));
} else {
warn (tl::to_string (tr ("Macro not found in LEF file: ")) + model);
}
} else {
while (! peek ("+") && ! peek ("-") && ! peek (";")) {
take ();
}
}
}
expect (";");
}
expect ("END");
expect ("COMPONENTS");
} else if (test ("PINS")) {
get_long ();
expect (";");
while (test ("-")) { while (test ("-")) {
take (); // pin name take (); // pin name
@ -1318,6 +1094,262 @@ DEFImporter::do_read (db::Layout &layout)
expect (";"); expect (";");
} }
}
void
DEFImporter::read_styles (double scale)
{
while (test ("-")) {
test ("STYLE");
int sn = get_long ();
std::vector<db::Point> points;
double x = 0.0, y = 0.0;
while (! test (";")) {
test ("(");
if (! test ("*")) {
x = get_double ();
}
if (! test ("*")) {
y = get_double ();
}
points.push_back (db::Point (db::DPoint (x * scale, y * scale)));
test (")");
}
m_styles.insert (std::make_pair (sn, db::Polygon ())).first->second.assign_hull (points.begin (), points.end ());
}
}
void
DEFImporter::read_components (std::list<std::pair<std::string, CellInstArray> > &instances, double scale)
{
while (test ("-")) {
std::string inst_name = get ();
std::string model = get ();
db::Cell *cell = m_lef_importer.macro_by_name (model);
while (test ("+")) {
if (test ("PLACED") || test ("FIXED") || test ("COVER")) {
test ("(");
double x = get_double ();
double y = get_double ();
db::Point pt = db::Point (db::DPoint (x * scale, y * scale));
test (")");
db::FTrans ft = get_orient (false /*mandatory*/);
db::Vector d = pt - m_lef_importer.macro_bbox_by_name (model).transformed (ft).lower_left ();
if (cell) {
db::CellInstArray inst (db::CellInst (cell->cell_index ()), db::Trans (ft.rot (), d));
instances.push_back (std::make_pair (inst_name, inst));
} else {
warn (tl::to_string (tr ("Macro not found in LEF file: ")) + model);
}
} else {
while (! peek ("+") && ! peek ("-") && ! peek (";")) {
take ();
}
}
}
expect (";");
}
}
void
DEFImporter::do_read (db::Layout &layout)
{
double dbu_mic = 1000.0;
double scale = 1.0 / (dbu_mic * layout.dbu ());
std::map<std::string, std::vector<db::Polygon> > regions;
std::list<DEFImporterGroup> groups;
std::list<std::pair<std::string, db::CellInstArray> > instances;
m_via_desc = m_lef_importer.vias ();
m_styles.clear ();
db::Cell &design = layout.cell (layout.add_cell ("TOP"));
while (! at_end ()) {
bool specialnets = false;
if (test ("END")) {
// END DESIGN terminates the file
expect ("DESIGN");
break;
} else if (test ("DESIGN")) {
std::string cn = get ();
layout.rename_cell (design.cell_index (), layout.uniquify_cell_name (cn.c_str ()).c_str ());
expect (";");
} else if (test ("VERSION")) {
// ignore VERSION statement currently
take ();
expect (";");
} else if (test ("UNITS")) {
test ("DISTANCE");
test ("MICRONS");
double units = get_double ();
if (fabs (units) > 1e-6) {
scale = 1.0 / (units * layout.dbu ());
}
expect (";");
} else if (test ("DIEAREA")) {
read_diearea (layout, design, scale);
} else if (test ("PROPERTYDEFINITIONS")) {
// read over PROPERTYDEFINITIONS sections
while (! test ("END") || ! test ("PROPERTYDEFINITIONS")) {
take ();
}
} else if (test ("NONDEFAULTRULES")) {
// read NONDEFAULTRULES sections
get_long ();
expect (";");
read_nondefaultrules (scale);
expect ("END");
expect ("NONDEFAULTRULES");
} else if (test ("REGIONS")) {
// Read REGION statements
get_long ();
expect (";");
read_regions (regions, scale);
expect ("END");
expect ("REGIONS");
} else if (test ("PINPROPERTIES")) {
// read over PINPROPERTIES statements
while (! test ("END") || ! test ("PINPROPERTIES")) {
take ();
}
} else if (test ("SLOTS")) {
// read over SLOTS statements
while (! test ("END") || ! test ("SLOTS")) {
take ();
}
} else if (test ("FILLS")) {
// read over FILLS statements
while (! test ("END") || ! test ("FILLS")) {
take ();
}
} else if (test ("SCANCHAINS")) {
// read over SCANCHAINS statements
while (! test ("END") || ! test ("SCANCHAINS")) {
take ();
}
} else if (test ("GROUPS")) {
// Read GROUPS statements
get_long ();
expect (";");
read_groups (groups, scale);
expect ("END");
expect ("GROUPS");
} else if (test ("BEGINEXT")) {
// read over BEGINEXT sections
while (! test ("ENDEXT")) {
take ();
}
} else if (test ("BLOCKAGES")) {
get_long ();
expect (";");
read_blockages (layout, design, scale);
expect ("END");
expect ("BLOCKAGES");
} else if ((specialnets = test ("SPECIALNETS")) == true || test ("NETS")) {
get_long ();
expect (";");
read_nets (layout, design, scale, specialnets);
expect ("END");
if (specialnets) {
expect ("SPECIALNETS");
} else {
expect ("NETS");
}
} else if (test ("VIAS")) {
get_long ();
expect (";");
read_vias (layout, design, scale);
expect ("END");
expect ("VIAS");
} else if (test ("STYLES")) {
get_long ();
expect (";");
read_styles (scale);
expect ("END");
expect ("STYLES");
} else if (test ("COMPONENTS")) {
get_long ();
expect (";");
read_components (instances, scale);
expect ("END");
expect ("COMPONENTS");
} else if (test ("PINS")) {
get_long ();
expect (";");
read_pins (layout, design, scale);
expect ("END"); expect ("END");
expect ("PINS"); expect ("PINS");

View File

@ -64,6 +64,8 @@ protected:
private: private:
LEFImporter m_lef_importer; LEFImporter m_lef_importer;
std::map<std::string, std::map<std::string, db::Coord> > m_nondefault_widths; std::map<std::string, std::map<std::string, db::Coord> > m_nondefault_widths;
std::map<std::string, ViaDesc> m_via_desc;
std::map<int, db::Polygon> m_styles;
db::FTrans get_orient (bool optional); db::FTrans get_orient (bool optional);
void read_polygon (db::Polygon &poly, double scale); void read_polygon (db::Polygon &poly, double scale);
@ -75,6 +77,11 @@ private:
void read_regions (std::map<std::string, std::vector<db::Polygon> > &regions, double scale); void read_regions (std::map<std::string, std::vector<db::Polygon> > &regions, double scale);
void read_groups (std::list<DEFImporterGroup> &groups, double scale); void read_groups (std::list<DEFImporterGroup> &groups, double scale);
void read_blockages (db::Layout &layout, db::Cell &design, double scale); void read_blockages (db::Layout &layout, db::Cell &design, double scale);
void read_nets (db::Layout &layout, db::Cell &design, double scale, bool specialnets);
void read_vias (db::Layout &layout, db::Cell &design, double scale);
void read_pins (db::Layout &layout, db::Cell &design, double scale);
void read_styles (double scale);
void read_components (std::list<std::pair<std::string, db::CellInstArray> > &instances, double scale);
}; };
} }