From cec426292f550ced2cf47ac883d00d3f14c1e6f4 Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Fri, 3 Oct 2025 15:45:47 +0200 Subject: [PATCH] Improve reading the source code sequence by extra comments: While searching for 'Parsing the circuit', the sequence of major functions is revealed. --- src/frontend/inp.c | 16 +++++++++++++--- src/frontend/inpcom.c | 4 ++++ src/frontend/spiceif.c | 20 ++++++++++++++------ src/main.c | 5 ++++- src/spicelib/parser/inppas1.c | 5 ++--- src/winmain.c | 4 +++- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index c12489ef8..b857a1462 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -530,7 +530,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) char *dir_name = ngdirname(filename ? filename : "."); startTime = seconds(); - /* inp_source() called with fp: load from file, */ + /* Parsing the circuit 2. + This is the next major step: + inp_source() called with fp: load circuit netlist from file, */ /* called with *fp == NULL and intfile: we want to load circuit from circarray */ if (fp || intfile) { deck = inp_readall(fp, dir_name, filename, comfile, intfile, &expr_w_temper); @@ -931,7 +933,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) } } - /* Now expand subcircuit macros and substitute numparams.*/ + /* Parsing the circuit 4. + This is the next major step: + Expand subcircuit macros and substitute numparams.*/ if (!cp_getvar("nosubckt", CP_BOOL, NULL, 0)) if ((deck->nextcard = inp_subcktexpand(deck->nextcard)) == NULL) { line_free(realdeck, TRUE); @@ -1084,7 +1088,9 @@ inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile) if (newcompat.hs || newcompat.spe) rem_unused_mos_models(deck->nextcard); #endif - /* now load deck into ft_curckt -- the current circuit. */ + /* Parsing the circuit 5. + This is the next major step: + load deck into ft_curckt -- the current circuit. */ if(inp_dodeck(deck, tt, wl_first, FALSE, options, filename) != 0) return 1; @@ -1411,6 +1417,10 @@ inp_dodeck( *---------------------------------------------------*/ if (!noparse) { startTime = seconds(); + /* Parsing the circuit 6. + This is the next major step: + Input a single deck, and return a pointer to the circuit. + Parse all models and instances */ ckt = if_inpdeck(deck, &tab); ft_curckt->FTEstats->FTESTATnetParseTime = seconds() - startTime; /* if .probe, rename the current measurement node vcurr_ */ diff --git a/src/frontend/inpcom.c b/src/frontend/inpcom.c index ff693b115..0e8367926 100644 --- a/src/frontend/inpcom.c +++ b/src/frontend/inpcom.c @@ -1054,6 +1054,10 @@ struct card *inp_readall(FILE *fp, const char *dir_name, const char* file_name, /* set the members of the compatibility structure */ set_compat_mode(); + /* Parsing the circuit 3. + This is the next major step: + Reading the netlist line by line, handle .include and .lib, + line continuation and upper/lower casing */ rv = inp_read(fp, 0, dir_name, file_name, comfile, intfile); cc = rv.cc; diff --git a/src/frontend/spiceif.c b/src/frontend/spiceif.c index 2615a5978..9697d7298 100644 --- a/src/frontend/spiceif.c +++ b/src/frontend/spiceif.c @@ -93,8 +93,9 @@ static int finddev(CKTcircuit *ckt, char *name, GENinstance **devptr, GENmodel * /* espice fix integration */ static int finddev_special(CKTcircuit *ckt, char *name, GENinstance **devptr, GENmodel **modptr, int *device_or_model); -/* Input a single deck, and return a pointer to the circuit. */ - +/* Input a single deck, and return a pointer to the circuit. + Parse all models in function INPpas1, instances (devices) in INPpas2, + consider initial conditions (INPpas3), and shunt capacitors (INPpas4). */ CKTcircuit * if_inpdeck(struct card *deck, INPtables **tab) { @@ -162,16 +163,23 @@ if_inpdeck(struct card *deck, INPtables **tab) ft_curckt->ci_curTask = ft_curckt->ci_defTask; - /* Parse the .model lines. Enter the model into the global model table modtab. */ modtab = NULL; modtabhash = NULL; - /* Parse .model lines, put them into 'tab' */ + /* Parsing the circuit 7. + This is the next major step: + Parse the .model lines. + Enter the model into the global model table modtab + and into the corresponding hash table modtabhash. + The role of 'tab' is unclear (not used any more?). */ INPpas1(ckt, deck->nextcard, *tab); - /* store the new model table in the current circuit */ + /* store the new model tables in the current circuit */ ft_curckt->ci_modtab = modtab; ft_curckt->ci_modtabhash = modtabhash; - /* Scan through the instance lines and parse the circuit. */ + /* Parsing the circuit 8. + This is the next major step: + Scan through the instance lines and parse the circuit. + Set up the circuit matrix. */ INPpas2(ckt, deck->nextcard, *tab, ft_curckt->ci_defTask); #ifdef XSPICE if (!Evtcheck_nodes(ckt, *tab)) { diff --git a/src/main.c b/src/main.c index a5a83c011..986714e72 100644 --- a/src/main.c +++ b/src/main.c @@ -1490,7 +1490,10 @@ int main(int argc, char **argv) gotone = FALSE; // Re-use if (tempfile && (!err || !ft_batchmode)) { - /* Copy the input file name for becoming another file search path */ + /* Parsing the circuit 1. + This is the next major step: + Source the input file, then parse the data and create the circuit. + Copy the input file name for becoming another file search path */ if (inp_spsource(tempfile, FALSE, dname, FALSE) != 0) { fprintf(stderr, " Simulation interrupted due to error!\n\n"); if (ft_stricterror || (oflag && !cp_getvar("interactive", CP_BOOL, NULL, 0))) diff --git a/src/spicelib/parser/inppas1.c b/src/spicelib/parser/inppas1.c index b990cadf6..c5048d134 100644 --- a/src/spicelib/parser/inppas1.c +++ b/src/spicelib/parser/inppas1.c @@ -8,9 +8,8 @@ Author: 1985 Thomas L. Quarles #include "inppas1.h" /* - * The first pass of the circuit parser just looks for '.model' lines - */ - + The first pass of the circuit parser just looks for '.model' lines, + and sticks model into model table tab. */ void INPpas1(CKTcircuit *ckt, struct card *deck, INPtables * tab) { struct card *current; diff --git a/src/winmain.c b/src/winmain.c index d380ff753..a851f4242 100644 --- a/src/winmain.c +++ b/src/winmain.c @@ -1340,7 +1340,9 @@ wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR /* Wait until everything is settled */ WaitForIdle(); - /* Go to main() */ + /* Parsing the command line. + This is the next major step: + Go to main() for reading the start command line and preparing the simulator. */ nReturnCode = xmain(argc, argv); THE_END: