1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//! Data structure abstract in Technology file

/// Technology File abstract
pub struct TfData {
    pub basic: TfTechnology,
    pub color: Vec<TfColor>,
    pub stipple: Vec<TfStipple>,
    pub tile: TfTile,
    pub layer: Vec<TfLayerEnum>,
    pub contact: Vec<TfContact>,
    pub designrule: Vec<TfDesignRule>,
    pub prrule: TfPRRule,
    pub densityrule: Vec<TfDensityRule>,
}

// "Technology" Section abstract
#[derive(Debug)]
pub struct TfTechnology {
    pub technology: String,
    pub dielectric: f32,
    pub time_unit: String,
    pub time_precision: u32,
    pub length_unit: String,
    pub length_precision: u32,
    pub voltage_unit: String,
    pub voltage_precision: u32,
    pub current_unit: String,
    pub current_precision: u32,
    pub power_unit: String,
    pub power_precision: u32,
    pub resistance_unit: String,
    pub resistance_precision: u32,
    pub capacitance_unit: String,
    pub capacitance_precision: u32,
    pub inductance_unit: String,
    pub inductance_precision: u32,
    pub grid_resolution: u32,
}
/// "Color" Section abstract
pub struct TfColor {
    pub color_id: u32,
    pub rgb_defined: bool,
    pub red: u8,
    pub green: u8,
    pub blue: u8,
}

/// "Stipple" Section abstract
pub struct TfStipple {
    pub name: String,
    pub width: u32,
    pub height: u32,
    pub pattern: Vec<bool>,
}

/// "Tile" Section abstract
pub struct TfTile {
    pub name: String,
    pub width: f32,
    pub height: f32,
}

pub enum TfLayerEnum {
    Layer(TfLayer),
    DataType(TfLayerDataType),
}

/// "Layer" Section abstract, including cut layer and metal layer
pub struct TfLayer {
    pub layer_name: String,
    pub mask_name: Option<String>, // Text layer and diode layer
    pub layer_id: u32,
    pub visible: bool,
    pub selectable: bool,
    pub blink: bool,
    pub is_defaultlayer: bool,
    pub line_style: String,
    pub pattern: String,
    pub color: ColorEnum,
    pub layer_rule: Option<LayerRule>, // None mean it's text layer
}

/// "LayerDataType" Section abstract
pub struct TfLayerDataType {
    pub name: String,
    pub layer_number: u32,
    pub data_type_number: u32,
    pub visible: bool,
    pub selectable: bool,
    pub blink: bool,
    pub color: ColorEnum,
    pub line_style: String,
    pub pattern: String,
}

pub enum ColorEnum {
    SelfDef(String),
    Builtin(u32),
}

/// "LayerRule" Section abstract, including metal layer, cut layer, poly layer rule
pub enum LayerRule {
    Poly(PolyLayerRule),
    SMetal(SpecialMetalLayerRule),
    SCut(SpecialCutLayerRule),
    Metal(MetalLayerRule),
    Cut(CutLayerRule),
}

pub struct PolyLayerRule {
    pub pitch: f32,
    pub default_width: f32,
    pub min_width: f32,
    pub min_spacing: f32,
}

pub struct EndLine2Neighbor {
    pub line2neighbor_threshold: f32,
    pub line2neighbor_minspacing: f32,
    pub line2neighbor_side_minspacing: f32,
    pub line2neighbor_corner_keepout_width: f32,
    pub line2neighbor_side_keepout_length: f32,
}

pub struct MetalFatTbl {
    pub fat_tbl_dimension: u32,
    pub fat_tbl_threshold: Vec<f32>,
    pub fat_tbl_parallel_length: Vec<f32>,
    pub fat_tbl_spacing: Vec<f32>,
}

pub struct SpecialMetalLayerRule {
    pub pitch: f32,
    pub default_width: f32,
    pub min_width: f32,
    pub min_spacing: f32,
    pub max_seg_len_for_rc: f32,
}

pub struct MetalLayerRule {
    pub pitch: f32,
    pub default_width: f32,
    pub min_width: f32,
    pub min_spacing: f32,
    pub max_width: f32,
    pub fat_wire_threshold: f32,
    pub fat_thin_minspacing: f32,
    pub fat_fat_minspacing: f32,
    pub max_current_density: f32,
    pub unit_resistance: (f32, f32, f32),
    pub unit_thickness: (f32, f32, f32),
    pub height_from_sub: (f32, f32, f32),
    pub fat_tbl: MetalFatTbl,
    pub min_area: f32,
    pub min_enclosed_area: f32,
    pub line2neighbor: Option<EndLine2Neighbor>,
}

pub struct CutFatTble {
    pub fat_tbl_dimension: u32,
    pub fat_tbl_threshold: Vec<f32>,
    pub fat_tbl_fat_contact_number: Vec<u32>,
    pub fat_tbl_fat_contact_mincuts: Vec<u32>,
}

pub struct CutFatExtTbl {
    pub fat_tbl_extension_dimension: u32,
    pub fat_tbl_extension_threshold: Vec<f32>,
    pub fat_tbl_extension_range_dimension: u32,
    pub fat_tbl_extension_range: Vec<f32>,
    pub fat_tbl_extension_area_dimension: u32,
    pub fat_tbl_extension_area_threshold: Vec<f32>,
    pub fat_tbl_extension_contact_number: Vec<u32>,
    pub fat_tbl_extension_mincuts: Vec<u32>,
}

pub struct SpecialCutLayerRule {
    pub min_spacing: f32,
}

pub struct CutLayerRule {
    pub pitch: f32,
    pub default_width: f32,
    pub min_width: f32,
    pub min_spacing: f32,
    pub corner_minspacing: Option<f32>,
    pub same_net_minspacing: Option<f32>,
    pub max_current_density: u32,
    pub fat_tbl: CutFatTble,
    pub fat_ext_tbl: Option<CutFatExtTbl>,
}

/// "ContactCode" Section abstract
pub struct TfContact {
    pub name: String,
    pub contact_id: u32,
    pub layer: (String, String, String), // (cutlayer,lowerlayer,upperlayer)
    pub layer_enc: (f32, f32, f32, f32), // upper, lower
    pub unit_resistance: Option<(f32, f32, f32)>,
    pub cutsize: (f32, f32),
    pub cutspacing: f32,
    pub viafarm_spacing: Option<f32>,
    pub is_defaultcontact: bool,
    pub is_fatcontact: bool,
}

/// "DesignRule" Section abstract, including metal2cut, metal2metal, metal2poly rule
pub struct TfDesignRule {
    pub layer1: String,
    pub layer2: String,
    pub rule_data: TfRule,
}

pub enum TfRule {
    MetalRule(TfMetalRule),
    CutRule(TfCutRule),
    PolyRule(TfPolyRule),
}

pub struct TfMetalRule {
    pub minspacing: f32,
    pub stackable: bool,
}

pub struct TfCutRule {
    pub tblsize: u32,
    pub threshold: f32,
    pub cornerkeepout_width: f32,
    pub sidekeepout_length: f32,
    pub sideminspacing: f32,
    pub minlength: f32,
    pub tbl: Vec<f32>,
    pub spacing_tbl: Vec<f32>,
    pub viaarray_excluded_tbl: Vec<f32>,
    pub wire_minthreshold: f32,
}

pub struct TfPolyRule {
    pub fat_wire_via_enc_tbl_size: u32,
    pub fat_wire_via_enc_width_threshold_tbl: Vec<f32>,
    pub fat_wire_via_enc_parallel_length_threshold_tbl: Vec<f32>,
    pub fat_wire_via_enc_max_spacing_threshold_tbl: Vec<f32>,
    pub fat_wire_via_enclosure_tbl: Vec<f32>,
    pub fat_wire_via_array_excluded_tbl: Vec<u32>,
}

/// "PRRule" Section abstract
pub struct TfPRRule {
    pub rowspacing_toptop: f32,
    pub rowspacing_topbot: Option<f32>,
    pub rowspacing_botbot: f32,
    pub abuttable_toptop: u32,
    pub abuttabletopbot: u32,
    pub abuttablebotbot: u32,
}

/// "DensityRule" Section abstract
pub struct TfDensityRule {
    pub layer: String,
    pub window_size: u32,
    pub min_density: u32,
    pub max_density: u32,
}