netlist_db/lexer/
instance.rs

1use alloc::borrow::Cow;
2
3use super::{KeyValue, Value};
4
5/// ``` spice
6/// XX1 net48 D VDD VNW PHVT11LL_CKT W=0.22u L=40.00n
7/// ```
8#[derive(Debug, Clone)]
9pub struct Instance<'s> {
10    pub name: Cow<'s, str>,
11    /// subckt/model name is the last arg
12    /// (fisrt, rest)
13    pub ctx: InstanceCtx<'s>,
14}
15
16#[derive(Debug, Clone)]
17pub enum InstanceCtx<'s> {
18    Resistor(Resistor<'s>),
19    Capacitor(Capacitor<'s>),
20    Inductor(Inductor<'s>),
21    Voltage(Voltage<'s>),
22    Current(Current<'s>),
23    MOSFET(MOSFET<'s>),
24    BJT(BJT<'s>),
25    Diode(Diode<'s>),
26    Subckt(Subckt<'s>),
27    Unknown {
28        r#type: u8,
29        ports: Vec<Cow<'s, str>>,
30        params: Vec<KeyValue<'s>>,
31    },
32}
33#[derive(Debug, Clone)]
34pub struct Resistor<'s> {
35    pub n1: Cow<'s, str>,
36    pub n2: Cow<'s, str>,
37    pub value: Value<'s>,
38}
39#[derive(Debug, Clone)]
40pub struct Capacitor<'s> {
41    pub n1: Cow<'s, str>,
42    pub n2: Cow<'s, str>,
43    pub value: Value<'s>,
44}
45#[derive(Debug, Clone)]
46pub struct Inductor<'s> {
47    pub n1: Cow<'s, str>,
48    pub n2: Cow<'s, str>,
49    pub value: Value<'s>,
50}
51#[derive(Debug, Clone)]
52pub struct Subckt<'s> {
53    pub ports: Vec<Cow<'s, str>>,
54    pub cktname: Cow<'s, str>,
55    pub params: Vec<KeyValue<'s>>,
56}
57/// https://eda-cpu1.eias.junzhuo.site/~junzhuo/hspice/index.htm#page/hspice_11/bipolar_junction_transistor_bjt_element.htm
58#[derive(Debug, Clone)]
59pub struct BJT<'s> {
60    pub nc: Cow<'s, str>,
61    pub nb: Cow<'s, str>,
62    pub ne: Cow<'s, str>,
63    pub ns: Option<Cow<'s, str>>,
64    pub mname: Cow<'s, str>,
65    pub params: Vec<KeyValue<'s>>,
66}
67#[derive(Debug, Clone)]
68pub struct MOSFET<'s> {
69    pub nd: Cow<'s, str>,
70    pub ng: Cow<'s, str>,
71    pub ns: Cow<'s, str>,
72    pub nb: Option<Cow<'s, str>>,
73    pub mname: Cow<'s, str>,
74    pub params: Vec<KeyValue<'s>>,
75}
76/// https://eda-cpu1.eias.junzhuo.site/~junzhuo/hspice/index.htm#page/hspice_11/diode_element.htm
77#[derive(Debug, Clone)]
78pub struct Diode<'s> {
79    pub nplus: Cow<'s, str>,
80    pub nminus: Cow<'s, str>,
81    pub mname: Cow<'s, str>,
82    pub params: Vec<KeyValue<'s>>,
83}
84#[derive(Debug, Clone)]
85pub struct Voltage<'s> {
86    pub n1: Cow<'s, str>,
87    pub n2: Cow<'s, str>,
88    pub source: VoltageSource<'s>,
89}
90#[derive(Debug, Clone)]
91pub enum VoltageSource<'s> {
92    Params(Vec<KeyValue<'s>>),
93    Value(Value<'s>),
94    PWL(PWL<'s>),
95}
96#[derive(Debug, Clone)]
97pub struct Current<'s> {
98    pub n1: Cow<'s, str>,
99    pub n2: Cow<'s, str>,
100    pub source: CurrentSource<'s>,
101}
102#[derive(Debug, Clone)]
103pub enum CurrentSource<'s> {
104    Params(Vec<KeyValue<'s>>),
105    Value(Value<'s>),
106    PWL(PWL<'s>),
107}
108#[derive(Debug, Clone)]
109pub struct TimeValuePoint<'s> {
110    pub time: Value<'s>,
111    pub value: Value<'s>,
112}
113/// https://eda-cpu1.eias.junzhuo.site/~junzhuo/hspice/index.htm#page/hspice_11/pwl_source.htm
114#[derive(Debug, Clone, Default)]
115pub struct PWL<'s> {
116    pub points: Vec<TimeValuePoint<'s>>,
117    /// Keyword and time value to specify a repeating function.
118    /// With no argument, the source repeats from the beginning of the function.
119    /// repeat is the time, in units of seconds, which specifies
120    /// the startpoint of the waveform to repeat. This time needs
121    /// to be less than the greatest time point, tn.
122    pub repeat: Option<Value<'s>>,
123    /// Specifies the stop time for the repeat.
124    pub rstop: Option<Value<'s>>,
125    /// Specifies the value of the current/voltage source at the time of rstop.
126    /// stopvalue can be either a real number or Z for high impedance state.
127    pub stopvalue: Option<Value<'s>>,
128    /// stopeslope is the switching time from the last PWL value to the stopvalue.
129    /// Default value is 30ps, if unspecified.
130    pub stopslope: Option<Value<'s>>,
131    /// `TD=delay`
132    ///
133    /// Time, in units of seconds, which specifies the length of time to delay (propagation delay) the piecewise linear function.
134    pub delay: Option<Value<'s>>,
135    pub edgetype: EdgeType,
136}
137#[derive(Debug, Clone, Copy, Default)]
138pub enum EdgeType {
139    #[default]
140    Linear,
141    HalfSine,
142}