This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.ts
281 lines (244 loc) · 7.05 KB
/
common.ts
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
// Copyright 2022
// Carlos Alberto Ruiz Naranjo [[email protected]]
//
// This file is part of colibri2
//
// Colibri is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Colibri is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with colibri2. If not, see <https://www.gnu.org/licenses/>.
import { HDL_LANG } from "../common/general";
// Common
export type Position_hdl = {
line: number;
column: number;
}
export enum TYPE_HDL_ELEMENT {
NONE = "none",
ENTITY = "entity",
PACKAGE = "package",
INTERFACE = "interface",
SIGNAL = "signal",
CONSTANT = "constant",
TYPE = "type",
FUNCTION = "function",
GENERIC = "generic",
PORT = "port",
VIRTUAL_BUS = "virtual_bus",
INSTANTIATION = "instantiation",
PROCESS = "process",
MODPORT = "modport",
LOGIC = "logic",
CUSTOM = "custom",
INTERFACE_DECLARATION = "interface_declaration"
}
export type Common_info = {
position: Position_hdl;
name: string;
description: string;
}
// HDL elements
export type Signal_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.SIGNAL;
info: Common_info;
type: string;
};
export type Constant_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.CONSTANT;
info: Common_info;
type: string;
default_value: string;
};
export type Type_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.TYPE;
info: Common_info;
type: string;
logic: Logic_hdl[];
};
export type Function_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.FUNCTION;
info: Common_info;
type: string;
arguments: string;
return: string;
};
export type Virtual_bus_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.VIRTUAL_BUS;
info: Common_info;
direction: string;
keepports: boolean;
port_list: Port_hdl[];
type: string;
};
export type Port_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.PORT;
info: Common_info;
over_comment: string;
inline_comment: string;
direction: string;
default_value: string;
type: string;
subtype: string;
};
export type Instantiation_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.INSTANTIATION;
info: Common_info;
type: string;
};
export type Process_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.PROCESS;
info: Common_info;
sens_list: string;
type: string;
};
export type Modport_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.MODPORT;
info: Common_info;
ports: Port_hdl[];
};
export type Logic_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.LOGIC;
info: Common_info;
type: string;
};
export type Custom_hdl = {
hdl_element_type: TYPE_HDL_ELEMENT.CUSTOM;
info: Common_info;
type: string;
};
export class Hdl_element {
public lang: HDL_LANG = HDL_LANG.VHDL;
public hdl_type: TYPE_HDL_ELEMENT = TYPE_HDL_ELEMENT.NONE;
private _name = "";
private _description = "";
private signal_array: Signal_hdl[] = [];
private constant_array: Constant_hdl[] = [];
private type_array: Type_hdl[] = [];
private function_array: Function_hdl[] = [];
private generic_array: Port_hdl[] = [];
private port_array: Port_hdl[] = [];
private instantiation_array: Instantiation_hdl[] = [];
private process_array: Process_hdl[] = [];
private modport_array: Modport_hdl[] = [];
private logic_array: Logic_hdl[] = [];
private custom_array: Custom_hdl[] = [];
private interface_array: Hdl_element[] = [];
public error_state = false;
constructor(lang: HDL_LANG, hdl_type: TYPE_HDL_ELEMENT) {
this.lang = lang;
this.hdl_type = hdl_type;
}
public get_hdl_type() {
return this.hdl_type;
}
public set_hdl_type(hdl_type: TYPE_HDL_ELEMENT) {
this.hdl_type = hdl_type;
}
public get name() {
return this._name;
}
public set name(name: string) {
this._name = name;
}
public get description() {
return this._description;
}
public set description(description: string) {
this._description = description;
}
public add_signal(element: Signal_hdl) {
this.signal_array.push(element);
}
public get_signal_array(): Signal_hdl[] {
return this.signal_array;
}
public add_constant(element: Constant_hdl) {
this.constant_array.push(element);
}
public get_constant_array(): Constant_hdl[] {
return this.constant_array;
}
public add_type(element: Type_hdl) {
this.type_array.push(element);
}
public get_type_array(): Type_hdl[] {
return this.type_array;
}
public add_function(element: Function_hdl) {
this.function_array.push(element);
}
public get_function_array(): Function_hdl[] {
return this.function_array;
}
public add_generic(element: Port_hdl) {
this.generic_array.push(element);
}
public get_generic_array(): Port_hdl[] {
return this.generic_array;
}
public add_port(element: Port_hdl) {
this.port_array.push(element);
}
public get_port_array(): Port_hdl[] {
return this.port_array;
}
public add_instantiation(element: Instantiation_hdl) {
this.instantiation_array.push(element);
}
public get_instantiation_array(): Instantiation_hdl[] {
return this.instantiation_array;
}
public add_process(element: Process_hdl) {
this.process_array.push(element);
}
public get_process_array(): Process_hdl[] {
return this.process_array;
}
public add_modport(element: Modport_hdl) {
this.modport_array.push(element);
}
public get_modport_array(): Modport_hdl[] {
return this.modport_array;
}
public add_logic(element: Logic_hdl) {
this.logic_array.push(element);
}
public get_logic_array(): Logic_hdl[] {
return this.logic_array;
}
public add_custom(element: Custom_hdl) {
this.custom_array.push(element);
}
public get_custom_array(): Custom_hdl[] {
return this.custom_array;
}
public add_interface(element: Hdl_element) {
this.interface_array.push(element);
}
public get_interface_array(): Hdl_element[] {
return this.interface_array;
}
public is_empty(): boolean {
if (
this.signal_array.length === 0 &&
this.constant_array.length === 0 &&
this.type_array.length === 0 &&
this.function_array.length === 0 &&
this.generic_array.length === 0 &&
this.port_array.length === 0 &&
this.instantiation_array.length === 0 &&
this.process_array.length === 0
) {
return true;
}
return false;
}
}