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
/
section_creator_interface.ts
224 lines (176 loc) · 7.75 KB
/
section_creator_interface.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
// Copyright 2022
// Carlos Alberto Ruiz Naranjo [[email protected]]
// Ismael Perez Rojo [[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/>.
const showdown = require('showdown');
import * as translator_lib from "./translator";
import * as common_hdl from "../parser/common";
import * as common_documenter from "./common";
import * as utils from "./utils";
import * as markdown_table from "./markdown_table";
import { t_documenter_options } from "../config/auxiliar_config";
export class Section_creator_interface {
get_interface_section(hdl_element: common_hdl.Hdl_element,
configuration: t_documenter_options, output_type: common_documenter.doc_output_type): string {
let section = "";
if (hdl_element.hdl_type !== common_hdl.TYPE_HDL_ELEMENT.INTERFACE_DECLARATION) {
return section;
}
const interface_list = hdl_element.get_interface_array();
interface_list.forEach(element => {
section += this.get_interface(element, configuration, output_type);
});
return section;
}
get_interface(interface_inst: common_hdl.Hdl_element,
configuration: t_documenter_options, output_type: common_documenter.doc_output_type) {
const translator = new translator_lib.Translator(configuration.language);
let doc = '';
let doc_raw = '';
const converter = new showdown.Converter({ tables: true, ghCodeBlocks: true });
converter.setFlavor('github');
// Title
doc_raw = `# ${translator.get_str('Interface')}: ${interface_inst['name']}\n\n`;
if (output_type === common_documenter.doc_output_type.MARKDOWN) {
doc += doc_raw;
}
else {
doc += converter.makeHtml(doc_raw);
}
// Description
const description = utils.normalize_description(interface_inst.description);
doc_raw = `${description}\n\n`;
if (output_type === common_documenter.doc_output_type.MARKDOWN) {
doc = doc_raw;
}
else {
doc += converter.makeHtml(doc_raw);
}
// Ports
doc += this.get_ports_interface(interface_inst.get_port_array(), translator, output_type);
// Parameters
doc += this.get_parameters_interface(interface_inst.get_generic_array(), translator, output_type);
// Logics
doc += this.get_logics(interface_inst.get_logic_array(), translator, output_type);
// Modports
doc += this.get_modports(interface_inst.get_modport_array(), translator, output_type);
// // Others
// doc += this.get_others(interface_inst['others']);
return doc;
}
get_parameters_interface(items: common_hdl.Port_hdl[], translator: translator_lib.Translator,
output_type: common_documenter.doc_output_type) {
const title = "Parameters";
const header = [
translator.get_str("Name"),
translator.get_str("Default value"),
translator.get_str("Description")
];
const keys = ['name', 'default_value', 'description'];
return utils.get_table_with_title(items, title, header, keys, translator, output_type);
}
get_ports_interface(items: common_hdl.Port_hdl[], translator: translator_lib.Translator,
output_type: common_documenter.doc_output_type) {
const title = "Ports";
const header = [
translator.get_str("Port name"),
translator.get_str("Direction"),
translator.get_str("Type"),
translator.get_str("Description")
];
const keys = ['name', 'direction', 'type', 'description'];
return utils.get_table_with_title(items, title, header, keys, translator, output_type);
}
get_types_data_interface(items: any, translator: translator_lib.Translator,
output_type: common_documenter.doc_output_type) {
const title = "Signals";
const header = [
translator.get_str("Name"),
translator.get_str("Type"),
translator.get_str("Description")
];
const keys = ['name', 'type', 'description'];
return utils.get_table_with_title(items, title, header, keys, translator, output_type);
}
get_logics(items: common_hdl.Logic_hdl[], translator: translator_lib.Translator,
output_type: common_documenter.doc_output_type) {
const title = "Signals";
const header = [
translator.get_str("Name"),
translator.get_str("Type"),
translator.get_str("Description")
];
const keys = ['name', 'type', 'description'];
return utils.get_table_with_title(items, title, header, keys, translator, output_type);
}
get_others(items: any, translator: translator_lib.Translator, output_type: common_documenter.doc_output_type) {
const title = "Others";
const header = [
translator.get_str("Name"),
translator.get_str("Type"),
translator.get_str("Description")
];
const keys = ['name', 'kind', 'description'];
return utils.get_table_with_title(items, title, header, keys, translator, output_type);
}
get_modports(modports: common_hdl.Modport_hdl[], translator: translator_lib.Translator,
output_type: common_documenter.doc_output_type) {
const converter = new showdown.Converter({ tables: true, ghCodeBlocks: true });
converter.setFlavor('github');
let doc_markdown = '';
let doc_html = '';
if (modports.length === 0) {
return '';
}
// Title
let doc_raw = `## Modports\n\n`;
doc_markdown += doc_raw;
doc_html += converter.makeHtml(doc_raw);
// Modports
for (const modport of modports) {
// Name
doc_raw = `- ${translator.get_str("Name")}: **${modport.info.name}**\n\n`;
doc_markdown += doc_raw;
doc_html += converter.makeHtml(doc_raw);
// Description
const description = utils.normalize_description(modport.info.description);
doc_raw = `${description}\n\n`;
doc_markdown += doc_raw;
doc_html += converter.makeHtml(doc_raw);
//Table
const modport_items = modport.ports;
const table = [];
table.push([translator.get_str("Port name"), translator.get_str("Direction"),
translator.get_str("Description")]);
for (const modport_item of modport_items) {
const modport_item_name = modport_item.info.name;
const modport_item_direction = modport_item.direction;
const modport_description = modport_item.info.description;
table.push([modport_item_name, modport_item_direction, modport_description]);
}
doc_raw = markdown_table.get_table(table, undefined) + '\n';
doc_markdown += doc_raw;
doc_html += converter.makeHtml(doc_raw);
}
if (output_type === common_documenter.doc_output_type.MARKDOWN) {
return doc_markdown;
}
else {
return doc_html;
}
}
}