From 18131e26b3d3a4fb5ba4ebfa051a8319910ea581 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Sun, 9 Aug 2020 13:11:38 -0400 Subject: [PATCH] Pulled merge request from Jan Belohoubek, but corrected the problem of needing to revert parameter definitions after swapping them during a device source/drain swap. --- VERSION | 2 +- ext2spice/ext2hier.c | 13 ++++++++----- ext2spice/ext2spice.c | 33 +++++++++++++++++++-------------- ext2spice/ext2spice.h | 1 + 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/VERSION b/VERSION index 867d7b9f..a7af17d8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.3.48 +8.3.49 diff --git a/ext2spice/ext2hier.c b/ext2spice/ext2hier.c index 5b17bda0..dc57ce5c 100644 --- a/ext2spice/ext2hier.c +++ b/ext2spice/ext2hier.c @@ -439,8 +439,6 @@ subcktHierVisit(use, hierName, is_top) return subcktVisit(use, hierName, is_top); } -extern void swapDrainSource(); - /* * ---------------------------------------------------------------------------- * @@ -487,7 +485,7 @@ spcdevHierVisit(hc, dev, scale) EFNode *subnode, *snode, *dnode, *subnodeFlat = NULL; int l, w, i, parmval; Rect r; - bool subAP= FALSE, hierS, hierD, extHierSDAttr() ; + bool subAP = FALSE, hierS, hierD, extHierSDAttr(), swapped = FALSE; float sdM; char devchar; bool has_model = TRUE; @@ -517,9 +515,10 @@ spcdevHierVisit(hc, dev, scale) !strcmp(dev->dev_terms[1].dterm_attrs, "D")) || (dev->dev_terms[2].dterm_attrs && !strcmp(dev->dev_terms[2].dterm_attrs, "S"))) - { + { swapDrainSource(dev, &source, &drain); - } + swapped = TRUE; + } else drain = &dev->dev_terms[2]; } @@ -1009,6 +1008,10 @@ spcdevHierVisit(hc, dev, scale) break; } fprintf(esSpiceF, "\n"); + + /* If S/D parameters were swapped, then put them back */ + if (swapped) swapDrainSource(dev, NULL, NULL); + return 0; } diff --git a/ext2spice/ext2spice.c b/ext2spice/ext2spice.c index 1c8cd1e3..f8c4b891 100644 --- a/ext2spice/ext2spice.c +++ b/ext2spice/ext2spice.c @@ -2204,24 +2204,25 @@ swapDrainSource(dev, source, drain) DevParam *plist; /* swap drain/source ordering */ - *drain = &dev->dev_terms[1]; - *source = &dev->dev_terms[2]; + if (drain) *drain = &dev->dev_terms[1]; + if (source) *source = &dev->dev_terms[2]; - /* swap drain/source-related parameters */ + /* Swap drain/source-related parameters. Note that the parameter */ + /* *definitions* are swapped, so if this is done, it must be */ + /* reverted before the next device is processed. */ + plist = efGetDeviceParams(EFDevTypes[dev->dev_type]); while (plist != NULL) { - TxPrintf(" * param: %s; type: %c%c\n", plist->parm_name, plist->parm_type[0], plist->parm_type[1]); + // Diagnostic + // TxPrintf(" * param: %s; type: %c%c\n", plist->parm_name, plist->parm_type[0], plist->parm_type[1]); - /* swap drain/source parameters only */ - if (!(strcmp(plist->parm_name, "as")) || !(strcmp(plist->parm_name, "ps"))) - { + /* Swap drain/source parameters only */ + if (!(strcmp(plist->parm_type, "a1")) || !(strcmp(plist->parm_type, "p1"))) plist->parm_type[1] = '0' + 2; - } - else if (!(strcmp(plist->parm_name, "ad")) || !(strcmp(plist->parm_name, "pd"))) - { + + else if (!(strcmp(plist->parm_type, "a2")) || !(strcmp(plist->parm_type, "p2"))) plist->parm_type[1] = '0' + 1; - } /* move pointer */ plist = plist->parm_next; @@ -2275,7 +2276,7 @@ spcdevVisit(dev, hc, scale, trans) DevTerm *gate, *source, *drain; EFNode *subnode, *snode, *dnode, *subnodeFlat = NULL; int l, w, i, parmval; - bool subAP= FALSE, hierS, hierD, extHierSDAttr() ; + bool subAP= FALSE, hierS, hierD, extHierSDAttr(), swapped = FALSE ; float sdM; char name[12], devchar; bool has_model = TRUE; @@ -2308,8 +2309,8 @@ spcdevVisit(dev, hc, scale, trans) (dev->dev_terms[2].dterm_attrs && !strcmp(dev->dev_terms[2].dterm_attrs, "S"))) { - /* If D/S should be swapped, also parameters must be swapped */ - swapDrainSource(dev, &source, &drain); + swapDrainSource(dev, &source, &drain); + swapped = True; } else drain = &dev->dev_terms[2]; @@ -2817,6 +2818,10 @@ spcdevVisit(dev, hc, scale, trans) break; } fprintf(esSpiceF, "\n"); + + /* If S/D parameters on a subcircuit were swapped, put them back */ + if (swapped) swapDrainSource(dev, NULL, NULL); + return 0; } diff --git a/ext2spice/ext2spice.h b/ext2spice/ext2spice.h index 1aa38067..3992ca2e 100644 --- a/ext2spice/ext2spice.h +++ b/ext2spice/ext2spice.h @@ -29,6 +29,7 @@ extern EFNode *spcdevSubstrate(); extern char *nodeSpiceName(); extern int nodeVisitDebug(); extern void topVisit(); +extern void swapDrainSource(); extern int _ext2spice_start(); extern EFNode *spcdevHierSubstrate();