netlist_db/
instance.rs

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