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
192 lines (180 loc) · 5.81 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
// 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, LANG } from "../common/general";
/** Templates types for VHDL */
export class TEMPLATE_NAME_VHDL {
static readonly COCOTB = {
name: "cocotb",
id: "cocotb",
description: "cocotb",
lang: LANG.PYTHON
};
static readonly TESTBENCH_NORMAL = {
name: "testbench",
id: "testbench_normal",
description: "VHDL testbench",
lang: LANG.VHDL
};
static readonly TESTBENCH_VUNIT = {
name: "vunit_testbench",
id: "testbench_vunit",
description: "VUnit testbench",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_COMPONENT = {
name: "component",
id: "hdl_element_component",
description: "Copy as component",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_INSTANCE = {
name: "instance",
id: "hdl_element_instance",
description: "Copy as instance",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_SIGNAL = {
name: "signal",
id: "hdl_element_signal",
description: "Copy as signal",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_MIX_INSTANCE = {
name: "mix_instance",
id: "hdl_element_mix_instance",
description: "Copy as Verilog instance",
lang: LANG.VERILOG
};
static readonly HDL_ELEMENT_MIX_TESTBENCH_NORMAL = {
name: "mix_testbench",
id: "hdl_element_mix_testbench_normal",
description: "Copy as Verilog testbench",
lang: LANG.VERILOG
};
static readonly HDL_ELEMENT_MIX_TESTBENCH_VUNIT = {
name: "mix_vunit_testbench",
id: "hdl_element_mix_testbench_vunit",
description: "Copy as Verilog VUnit testbench",
lang: LANG.VERILOG
};
// private to disallow creating other instances of this type
private constructor(private readonly key: string, public readonly value: any) {
}
toString() {
return this.key;
}
}
/** Templates types for Verilog/SV */
export class TEMPLATE_NAME_VERILOG {
static readonly COCOTB = {
name: "cocotb",
id: "cocotb",
description: "cocotb",
lang: LANG.PYTHON
};
static readonly TESTBENCH_NORMAL = {
name: "testbench",
id: "testbench_normal",
description: "Verilog testbench",
lang: LANG.VERILOG
};
static readonly TESTBENCH_VUNIT = {
name: "vunit_testbench",
id: "testbench_vunit",
description: "Vunit testbench",
lang: LANG.VERILOG
};
static readonly HDL_ELEMENT_INSTANCE = {
name: "instance",
id: "testbench_vunit",
description: "Copy as instance",
lang: LANG.VERILOG
};
static readonly HDL_ELEMENT_SIGNAL = {
name: "signal",
id: "hdl_element_signal",
description: "Copy as signal",
lang: LANG.VERILOG
};
static readonly HDL_ELEMENT_MIX_INSTANCE = {
name: "mix_instance",
id: "hdl_element_mix_instance",
description: "Copy as VHDL instance",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_MIX_TESTBENCH_NORMAL = {
name: "mix_testbench",
id: "hdl_element_mix_testbench_normal",
description: "Copy as VHDL testbench",
lang: LANG.VHDL
};
static readonly HDL_ELEMENT_MIX_TESTBENCH_VUNIT = {
name: "mix_vunit_testbench",
id: "hdl_element_mix_testbench_vunit",
description: "Copy as VHDL VUnit testbench",
lang: LANG.VHDL
};
// private to disallow creating other instances of this type
private constructor(private readonly key: string, public readonly value: any) {
}
toString() {
return this.key;
}
}
/**
* Get type of templates for HDL language
* @param {HDL_LANG} lang HDL language
*/
export function get_template_names(lang: HDL_LANG) {
if (lang === HDL_LANG.VHDL) {
return TEMPLATE_NAME_VHDL;
}
else {
return TEMPLATE_NAME_VERILOG;
}
}
/**
* Get templete description and IDs
* @param {HDL_LANG} lang HDL language
*/
export function get_template_definition(lang: HDL_LANG) {
if (lang === HDL_LANG.VHDL) {
const template_names = TEMPLATE_NAME_VHDL;
const description_list: string[] = [];
const id_list: string[] = [];
const lang_list: LANG[] = [];
for (const [_key, value] of Object.entries(template_names)) {
description_list.push(value.description);
id_list.push(value.id);
lang_list.push(value.lang);
}
return { description_list: description_list, id_list: id_list, lang_list: lang_list };
}
else {
const template_names = TEMPLATE_NAME_VERILOG;
const description_list: string[] = [];
const id_list: string[] = [];
const lang_list: LANG[] = [];
for (const [_key, value] of Object.entries(template_names)) {
description_list.push(value.description);
id_list.push(value.id);
lang_list.push(value.lang);
}
return { description_list: description_list, id_list: id_list, lang_list: lang_list };
}
}