Hacking SPICE — tracing the function pointer to launch transient simulation job

 

The data structure of SPICE analysis is  https://github.com/zhuangh/ngspice/blob/master/src/spicelib/analysis/analysis.h

struct SPICEanalysis {
    IFanalysis if_analysis;
    int size;
    int domain;
    int do_ic;
    int (*setParm)(CKTcircuit *ckt, JOB *anal,
                         int which, IFvalue *value);
    int (*askQuest)(CKTcircuit *ckt, JOB *anal, 
                         int which, IFvalue *value);
    int (*an_init)(CKTcircuit *ckt, JOB *job);
    int (*an_func)(CKTcircuit *ckt, int restart);
};

when SPICE run initialization for that type of variable, it has a corresponding format as (transient simulation as a example)


SPICEanalysis TRANinfo  = {
    {
        "TRAN";,
        "Transient analysis",

        NUMELEMS(TRANparms),
        TRANparms
    },
    sizeof(TRANan),
    TIMEDOMAIN,
    1,
    TRANsetParm,
    TRANaskQuest,
    TRANinit,
    DCtran
};

https://github.com/zhuangh/ngspice/blob/master/src/spicelib/analysis/transetp.c#L85

Then, https://github.com/zhuangh/ngspice/blob/master/src/spicelib/analysis/cktdojob.c#L208 initializes the analysis job using the seventh member of SPICEanalysis TRANinfo, which is a function pointer pointing to TRANinit.

https://github.com/zhuangh/ngspice/blob/master/src/spicelib/analysis/cktdojob.c#L222

launches the analysis job using the eighth member of SPICEanalysis TRANinfo, which is a function pointer pointing to DCtran.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s