Reworked the "def read" command such that it creates a new CellDef

for the DEF file contents, and loads the cell into the layout
window when done.  That makes it consistent with other similar
functions such as "gds read".  Existing scripts which create (by
loading) a new cell before reading the DEF should not be affected
by the change.
This commit is contained in:
R. Timothy Edwards 2025-08-26 14:48:27 -04:00
parent e04307c085
commit e9f2628f41
3 changed files with 77 additions and 13 deletions

View File

@ -2354,6 +2354,37 @@ DefReadComponents(
"the number declared (%d).\n", processed, total); "the number declared (%d).\n", processed, total);
} }
/*
*------------------------------------------------------------
* DefNewCell --
*
* Create a new CellDef for the DEF file contents.
*
* Returns:
* Pointer to new CellDef
*
* Side effects:
* If a cell of the given name did not exist, then
* a new CellDef is allocated.
*------------------------------------------------------------
*/
CellDef *
DefNewCell(
const char *name)
{
CellDef *newDef;
newDef = DBCellLookDef(name);
if (newDef == NULL)
{
newDef = DBCellNewDef(name);
DBReComputeBbox(newDef);
DBCellClearDef(newDef);
DBCellSetAvail(newDef);
}
return newDef;
}
/* /*
*------------------------------------------------------------ *------------------------------------------------------------
* *
@ -2383,7 +2414,7 @@ enum def_sections {DEF_VERSION = 0, DEF_NAMESCASESENSITIVE,
DEF_CONSTRAINTS, DEF_GROUPS, DEF_EXTENSION, DEF_BLOCKAGES, DEF_CONSTRAINTS, DEF_GROUPS, DEF_EXTENSION, DEF_BLOCKAGES,
DEF_NONDEFAULTRULES, DEF_END}; DEF_NONDEFAULTRULES, DEF_END};
void CellDef *
DefRead( DefRead(
const char *inName, const char *inName,
bool dolabels, bool dolabels,
@ -2398,6 +2429,7 @@ DefRead(
int keyword, dscale, total; int keyword, dscale, total;
float oscale; float oscale;
Rect *dierect; Rect *dierect;
bool design_is_root = FALSE;
static const char * const sections[] = { static const char * const sections[] = {
"VERSION", "VERSION",
@ -2450,7 +2482,7 @@ DefRead(
TxError("Cannot open input file: "); TxError("Cannot open input file: ");
perror(filename); perror(filename);
#endif #endif
return; return NULL;
} }
/* Initialize */ /* Initialize */
@ -2459,11 +2491,8 @@ DefRead(
TxPrintf("This action cannot be undone.\n"); TxPrintf("This action cannot be undone.\n");
UndoDisable(); UndoDisable();
/* This works for CIF reads; maybe should only do this if the top */ rootDef = NULL;
/* cell is (UNNAMED)? */
rootDef = EditCellUse->cu_def;
DBCellRenameDef(rootDef, inName);
oscale = CIFGetOutputScale(1000); oscale = CIFGetOutputScale(1000);
lefCurrentLine = 0; lefCurrentLine = 0;
@ -2501,7 +2530,16 @@ DefRead(
break; break;
case DEF_DESIGN: case DEF_DESIGN:
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
DBCellRenameDef(rootDef, token);
/* If rootDef is not NULL, then it was created before DESIGN
* was specified; this should not happen, but if so, then
* rename the rootDef rather than creating a new CellDef.
*/
if (rootDef == NULL)
rootDef = DefNewCell(token);
else
DBCellRenameDef(rootDef, token);
LefEndStatement(f); LefEndStatement(f);
break; break;
case DEF_UNITS: case DEF_UNITS:
@ -2545,6 +2583,7 @@ DefRead(
dierect->r_ybot, dierect->r_ybot,
dierect->r_xtop, dierect->r_xtop,
dierect->r_ytop); dierect->r_ytop);
if (rootDef == NULL) rootDef = DefNewCell(inName);
DBPropPut(rootDef, "FIXED_BBOX", bboxstr); DBPropPut(rootDef, "FIXED_BBOX", bboxstr);
LefEndStatement(f); LefEndStatement(f);
break; break;
@ -2561,8 +2600,11 @@ DefRead(
if (annotate) if (annotate)
LefSkipSection(f, sections[DEF_COMPONENTS]); LefSkipSection(f, sections[DEF_COMPONENTS]);
else else
{
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadComponents(f, rootDef, sections[DEF_COMPONENTS], DefReadComponents(f, rootDef, sections[DEF_COMPONENTS],
oscale, total); oscale, total);
}
break; break;
case DEF_VIAS: case DEF_VIAS:
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
@ -2574,6 +2616,7 @@ DefRead(
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
if (sscanf(token, "%d", &total) != 1) total = 0; if (sscanf(token, "%d", &total) != 1) total = 0;
LefEndStatement(f); LefEndStatement(f);
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadPins(f, rootDef, sections[DEF_PINS], oscale, total, annotate); DefReadPins(f, rootDef, sections[DEF_PINS], oscale, total, annotate);
break; break;
case DEF_PINPROPERTIES: case DEF_PINPROPERTIES:
@ -2583,6 +2626,7 @@ DefRead(
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
if (sscanf(token, "%d", &total) != 1) total = 0; if (sscanf(token, "%d", &total) != 1) total = 0;
LefEndStatement(f); LefEndStatement(f);
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadNets(f, rootDef, sections[DEF_SPECIALNETS], oscale, TRUE, DefReadNets(f, rootDef, sections[DEF_SPECIALNETS], oscale, TRUE,
dolabels, annotate, total); dolabels, annotate, total);
break; break;
@ -2590,6 +2634,7 @@ DefRead(
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
if (sscanf(token, "%d", &total) != 1) total = 0; if (sscanf(token, "%d", &total) != 1) total = 0;
LefEndStatement(f); LefEndStatement(f);
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadNets(f, rootDef, sections[DEF_NETS], oscale, FALSE, DefReadNets(f, rootDef, sections[DEF_NETS], oscale, FALSE,
dolabels, annotate, total); dolabels, annotate, total);
break; break;
@ -2597,6 +2642,7 @@ DefRead(
token = LefNextToken(f, TRUE); token = LefNextToken(f, TRUE);
if (sscanf(token, "%d", &total) != 1) total = 0; if (sscanf(token, "%d", &total) != 1) total = 0;
LefEndStatement(f); LefEndStatement(f);
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadNonDefaultRules(f, rootDef, sections[DEF_NONDEFAULTRULES], DefReadNonDefaultRules(f, rootDef, sections[DEF_NONDEFAULTRULES],
oscale, total); oscale, total);
break; break;
@ -2622,8 +2668,11 @@ DefRead(
if (annotate || noblockage) if (annotate || noblockage)
LefSkipSection(f, sections[DEF_BLOCKAGES]); LefSkipSection(f, sections[DEF_BLOCKAGES]);
else else
{
if (rootDef == NULL) rootDef = DefNewCell(inName);
DefReadBlockages(f, rootDef, sections[DEF_BLOCKAGES], DefReadBlockages(f, rootDef, sections[DEF_BLOCKAGES],
oscale, total); oscale, total);
}
break; break;
case DEF_END: case DEF_END:
if (!LefParseEndStatement(f, "DESIGN")) if (!LefParseEndStatement(f, "DESIGN"))
@ -2640,12 +2689,18 @@ DefRead(
/* Cleanup */ /* Cleanup */
DBAdjustLabels(rootDef, &TiPlaneRect); if (rootDef != NULL)
DBReComputeBbox(rootDef); {
DBWAreaChanged(rootDef, &rootDef->cd_bbox, DBW_ALLWINDOWS, DBAdjustLabels(rootDef, &TiPlaneRect);
DBReComputeBbox(rootDef);
DBWAreaChanged(rootDef, &rootDef->cd_bbox, DBW_ALLWINDOWS,
&DBAllButSpaceBits); &DBAllButSpaceBits);
DBCellSetModified(rootDef, TRUE); DBCellSetModified(rootDef, TRUE);
}
else
TxPrintf("DEF read: Design has no contents.\n");
if (f != NULL) fclose(f); if (f != NULL) fclose(f);
UndoEnable(); UndoEnable();
return rootDef;
} }

View File

@ -261,7 +261,16 @@ CmdLef(
if (is_lef) if (is_lef)
LefRead(namep, lefImport, lefAnnotate, lefDateStamp); LefRead(namep, lefImport, lefAnnotate, lefDateStamp);
else else
DefRead(namep, defLabelNets, defAnnotate, defNoBlockage); {
selectedDef = DefRead(namep, defLabelNets, defAnnotate, defNoBlockage);
if (selectedDef != (CellDef *)NULL)
{
/* Load this in the layout window */
windCheckOnlyWindow(&w, DBWclientID);
if (w != (MagWindow *) NULL)
DBWloadWindow(w, selectedDef->cd_name, DBW_LOAD_IGNORE_TECH);
}
}
break; break;
case LEF_WRITEALL: case LEF_WRITEALL:
if (!is_lef) if (!is_lef)

View File

@ -170,7 +170,7 @@ extern void LefError(int type, const char *fmt, ...) ATTR_FORMAT_PRINTF_2;
/* C99 compat */ /* C99 compat */
extern void LefRead(const char *inName, bool importForeign, bool doAnnotate, int lefTimestamp); extern void LefRead(const char *inName, bool importForeign, bool doAnnotate, int lefTimestamp);
extern void DefRead(const char *inName, bool dolabels, bool annotate, bool noblockage); extern CellDef *DefRead(const char *inName, bool dolabels, bool annotate, bool noblockage);
extern void LefWriteAll(CellUse *rootUse, bool writeTopCell, bool lefTech, int lefHide, int lefPinOnly, bool lefTopLayer, extern void LefWriteAll(CellUse *rootUse, bool writeTopCell, bool lefTech, int lefHide, int lefPinOnly, bool lefTopLayer,
bool lefDoMaster, bool recurse); bool lefDoMaster, bool recurse);