NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/main.c
Go to the documentation of this file.
1
2/* ****************************************************************************************************************************** */
3
4/* NAPA - High Level Simulator Generator for Mixed Signal Development ........................................................... */
5/* It generates an ANSI-c2x ad hoc cycle based simulator after compilation of a Napa netlist .................................... */
6
7/* Software developped following the demand of Dick Hester ...................................................................... */
8
9/* Version 1.00 K&R C written by Greg Warwar .............. 08/23/1990 ........................................................ */
10/* Digital signals coded as 'int', analog signals coded as 'float' .............................................................. */
11
12/* Translated, modified and augmented in ANSI-C by Yves Leduc with the help of JM Mari, JY Caron ................................ */
13
14/* 32 bits Version .............................................................................................................. */
15/* Digital signals coded as 'long int', analog signals coded as 'double' ........................................................ */
16/* Version 2.00 Yves Leduc ......................... Release 06/18/1993 ........................................................ */
17/* Version 2.80 Yves Leduc ......................... Release 04/30/2005 ........................................................ */
18/* Version 2.83 Yves Leduc.......................... Release 08/31/2009 ........................................................ */
19
20/* 64 bits Version .............................................................................................................. */
21/* Digital signals coded as 'long long int', analog signals coded as 'double', time coded as 'long double' ...................... */
22/* Version 3.00 Yves Leduc ......................... Release 10/27/2013 ... Polytech Sophia .................................... */
23/* Version 3.05 Yves Leduc ......................... Release 09/02/2017 ... Polytech Sophia .................................... */
24/* Version 3.06 Yves Leduc ......................... Release 12/04/2018 ... Polytech Sophia .................................... */
25
26
27/* ****************************************************************************************************************************** */
28
29/* CURRENT VERSION .............................................................................................................. */
30/* Version 4.00 Yves Leduc ......................... Release 12/16/2018 ........................................................ */
31/* Version 4.10 Yves Leduc ......................... Release 04/10/2020 ........................................................ */
32/* Version 4.20 Yves Leduc ......................... Release 11/28/2022 ........................................................ */
33/* Version 4.30 Yves Leduc ......................... Release 02/25/2023 ........................................................ */
34/* Version 4.40 Yves Leduc ......................... Release 11/26/2024 ........................................................ */
35/* Version 4.50 Yves Leduc ......................... Release 07/15/2025 ........................................................ */
36
37/* ****************************************************************************************************************************** */
38
39/* The compilation of this source places a DATE and TIME STAMP in the executable ................................................ */
40/* It should compile with ANSI-C c2x GNU gcc compiler without warning nor error (DOS, LINUX and UNIX) ........................... */
41
42/* See file './napa.h' for current version number and other information ......................................................... */
43
44
45/* ****************************************************************************************************************************** */
46
47/* The NAPA compiler is a simple 'ONE PASS' compiler. */
48
49/* The compiler is building lists of data structures, after reworking these lists, */
50/* it produces the ANSI-C c2x compliant code of the simulator from these lists. */
51
52/* Output C code is written to be portable, readable and documented. */
53
54/* The NAPA compiler error tracking has 3 levels: */
55
56/* ----------- critical error, compiler stops immediately and reports the error */
57/* */
58/* ----------- error, compile is allowed to continue to gather other errors before */
59/* stopping at an appropriate point [ function process_error_if_any() ] */
60/* */
61/* ----------- warning */
62
63/* All errors and warnings produce a message including the file name and the line number where the issue has been detected. */
64
65
66/* ****************************************************************************************************************************** */
67
68/* Source code of the NAPA compiler are located in files: */
69
70/* "./main.c" this file, a strictly linear sequence of high level function calls */
71
72/* "./bl.c" builds the main part of the output code */
73/* "./bn.c" builds the code corresponding to the NAPA nodes */
74/* "./cl.c" analyzes the NAPA command line */
75/* "./co.c" builds the user's options function */
76/* "./dc.c" processes the type declaration */
77/* "./fc.c" contains miscellaneous functions */
78/* "./id.c" contains function related to id numbers of the element of data lists */
79/* "./lp.c" contains the 'one pass' parser, processes cells and generators calls */
80/* "./mp.c" contains metaphone and damerau-levenstein algorithms for error handling */
81/* "./nd.c" determines the type of the nodes from analysis of the netlist */
82/* "./pr.c" builds the first part of the C code: macros, structure, declaration... */
83/* "./rd.c" redefines some nodes to optimize results, perform other redefinitions */
84/* "./rg.c" builds the random generator functions */
85/* "./rm.c" builds the I/O file manager */
86/* "./sn.c" sorts nodes by analyzing dependencies */
87/* "./sv.c" sorts variables and updates by analyzing dependencies */
88/* "./sx.c" verifies syntax */
89/* "./tk.c" contains token and string related functions */
90/* "./tp.c" checks the coherence of the types of the nodes */
91/* "./xr.c" contains the code to build a cross reference of the napa netlist */
92
93/* "./napa.h" global definitions and macros */
94/* "./proto.h" prototypes of functions */
95
96/* For more information, see file "./napa.h" */
97
98
99/* ****************************************************************************************************************************** */
100
101/* EXTERN is a macro defined at the beginning of each C file. */
102/* In this file 'main.c', its definition corresponds to a blank definition, in all other files, its definition corresponds to */
103/* 'extern' C identifier. The file './napa.h' included in all source files of the NAPA compiler is using this macro accordingly. */
104
105#undef EXTERN
106#define EXTERN /* defined empty in this file only */
107
108
109/* ****************************************************************************************************************************** */
110
111#include "./napa.h"
112#include "./proto.h"
113
114
115/* **** Modest Help for Debug ***** ( Tracking of the compilation's flow ) **************************************************** */
116
117#if defined(DEBUG_ALL)
118
119 #define DEBUG_IT(f,c) debug_it(f, c)
120
121void debug_it(const char* file, char c) {
122 static int tag = 0;
123 static char chr = '0';
124 (void) f1flush((FILE*) NULL);
125 if (1L >= LENGTH(file)) {
126 (void) fprintf(STDERR, "\n");
127 return;
128 }
129 if ((chr != c) && (' ' != c)) {
130 tag = 1;
131 chr = c;
132 (void) fprintf(STDERR, "\n");
133 }
134 (void) fprintf(STDERR, " ***** NAPA Compiler Flow Information: %4s -> %c.%02d ***\n", file, chr, tag);
135 (void) f1flush((FILE*) NULL);
136 tag++;
137 return;
138}
139
140#else
141
142 #define DEBUG_IT(f,c)
143
144#endif
145
146
147/* *** MAIN ********************************************************************************************************************* */
148
149int main(int argc, char **argv) {
150
151 /* time of compilation is added to executable for identification and traceability ............................................. */
152
153 tag_executable(__DATE__, __TIME__); DEBUG_IT("cl.c", 'a');
154
155
156 /* parse line of command, syntax options ...................................................................................... */
157
158 default_control_variables(); DEBUG_IT("fc.c", ' ');
159 process_command_line(argc, argv); DEBUG_IT("cl.c", ' ');
160
161 /* input file reading, parsing, and table building, cross reference on demand ................................................. */
162
163 line_parsing(); DEBUG_IT("lp.c", 'b');
164 process_aliases(); DEBUG_IT("fc.c", ' ');
165 build_cross_reference(); DEBUG_IT("xr.c", ' ');
166 build_usage_comment(); DEBUG_IT("pr.c", ' ');
167 process_error_if_any(); DEBUG_IT("fc.c", ' ');
168
169
170 /* postprocess parsed data .................................................................................................... */
171
172 redefine_random_seed(); DEBUG_IT("rd.c", 'c');
173 redefine_node_segments(); DEBUG_IT("rd.c", ' ');
174 separe_qualifiers(); DEBUG_IT("rd.c", ' ');
175 redefine_nodes(); DEBUG_IT("rd.c", ' ');
176 create_nodes(); DEBUG_IT("rd.c", ' ');
177 inject_nodes(); DEBUG_IT("rd.c", ' ');
178 process_error_if_any(); DEBUG_IT("fc.c", ' ');
179
180 expand_update_definitions(); DEBUG_IT("fc.c", 'd');
181 expand_IO_definitions(); DEBUG_IT("fc.c", ' ');
182 expand_dump_definitions(); DEBUG_IT("fc.c", ' ');
183 complete_directives(); DEBUG_IT("fc.c", ' ');
184 process_error_if_any(); DEBUG_IT("fc.c", ' ');
185
186
187 /* syntax parsed data ......................................................................................................... */
188
189 syntax_command_line(); DEBUG_IT("sx.c", 'e');
190 syntax_fs(); DEBUG_IT("sx.c", ' ');
191 syntax_directives(); DEBUG_IT("sx.c", ' ');
192 syntax_nodes(); DEBUG_IT("sx.c", ' ');
193 syntax_variables(); DEBUG_IT("sx.c", ' ');
194 syntax_records(); DEBUG_IT("sx.c", ' ');
195 syntax_terminate(); DEBUG_IT("sx.c", ' ');
196 syntax_segment_value(); DEBUG_IT("sx.c", ' ');
197 syntax_updates(); DEBUG_IT("sx.c", ' ');
198 process_error_if_any(); DEBUG_IT("fc.c", ' ');
199
200
201 /* determine and check the type of nodes ...................................................................................... */
202
203 declaration_type_A(); DEBUG_IT("dc.c", 'f');
204 node_determination(); DEBUG_IT("nd.c", ' ');
205 process_error_if_any(); DEBUG_IT("fc.c", ' ');
206
207 stuck_nodes(); DEBUG_IT("rd.c", 'g');
208 declaration_type_B(); DEBUG_IT("dc.c", ' ');
209 check_types(); DEBUG_IT("tp.c", ' ');
210 process_error_if_any(); DEBUG_IT("fc.c", ' ');
211
212
213 /* determine the sampling frequencies of each segment ......................................................................... */
214
215 determine_simulation_rate(); DEBUG_IT("fc.c", 'h');
217 compact_segment(); DEBUG_IT("fc.c", ' ');
219 process_error_if_any(); DEBUG_IT("fc.c", ' ');
220
221
222 /* expand records ............................................................................................................. */
223
224 build_record_dependencies(); DEBUG_IT("sv.c", 'i');
225 sort_records(); DEBUG_IT("sv.c", ' ');
226 expand_records(); DEBUG_IT("fc.c", ' ');
227 process_error_if_any(); DEBUG_IT("fc.c", ' ');
228
229
230 /* prepare the sorting of data ................................................................................................ */
231
232 build_node_dependencies(); DEBUG_IT("sn.c", 'j');
233 build_var_dependencies(); DEBUG_IT("sv.c", ' ');
234 build_update_dependencies(); DEBUG_IT("sv.c", ' ');
235 process_error_if_any(); DEBUG_IT("fc.c", ' ');
237 process_error_if_any(); DEBUG_IT("fc.c", ' ');
238
239
240 /* sort data .................................................................................................................. */
241
242 sort_nodes(); DEBUG_IT("sn.c", 'k');
243 sort_vars(); DEBUG_IT("sv.c", ' ');
244 sort_updates(); DEBUG_IT("sv.c", ' ');
245 process_error_if_any(); DEBUG_IT("fc.c", ' ');
246
247
248 /* process data to prepare the building of the production of C code ........................................................... */
249
250 name_mangling(); DEBUG_IT("rd.c", 'l');
251 collect_functions(); DEBUG_IT("rd.c", ' ');
252 process_init(); DEBUG_IT("rd.c", ' ');
253 process_error_if_any(); DEBUG_IT("fc.c", ' ');
254
255 expand_string_variables(); DEBUG_IT("fc.c", 'm');
256 mark_updates_if_constant(); DEBUG_IT("id.c", ' ');
257 mark_constants(); DEBUG_IT("id.c", ' ');
258 process_error_if_any(); DEBUG_IT("fc.c", ' ');
259
260 check_array_usage(); DEBUG_IT("fc.c", 'n');
261 check_record_usage(); DEBUG_IT("fc.c", ' ');
262 check_directive_usage(); DEBUG_IT("fc.c", ' ');
263 process_error_if_any(); DEBUG_IT("fc.c", ' ');
264
265
266 /* identify instructions and functions which will require a special processing ................................................ */
267
268 purge_constants_in_options(); DEBUG_IT("rd.c", 'o');
269 collect_string_of_options(); DEBUG_IT("co.c", ' ');
271 collect_export_definitions(); DEBUG_IT("fc.c", ' ');
272 purge_constants_in_ganging(); DEBUG_IT("rd.c", ' ');
273 process_error_if_any(); DEBUG_IT("fc.c", ' ');
274
275
276 /* write output C code, proceed to final verifications ....................................................................... */
277
278 print_C_code_banner_a(); DEBUG_IT("pr.c", 'p');
279 print_C_code_banner_b(); DEBUG_IT("pr.c", ' ');
281 define_macros(); DEBUG_IT("pr.c", ' ');
282 declare_global_values(); DEBUG_IT("pr.c", ' ');
283 declare_function_pointers(); DEBUG_IT("pr.c", ' ');
284 declare_prototypes(); DEBUG_IT("pr.c", ' ');
285 define_directives(); DEBUG_IT("pr.c", ' ');
286 declare_file_handles(); DEBUG_IT("pr.c", ' ');
287 declare_vars(); DEBUG_IT("pr.c", ' ');
288 declare_nodes(); DEBUG_IT("pr.c", ' ');
289 declare_records(); DEBUG_IT("pr.c", ' ');
290 declare_arrays(); DEBUG_IT("pr.c", ' ');
291 include_napa_header_files(); DEBUG_IT("pr.c", ' ');
292 process_error_if_any(); DEBUG_IT("fc.c", ' ');
293
294 open_main(); DEBUG_IT("pr.c", 'q');
295 call_ping_1(); DEBUG_IT("pr.c", ' ');
298
299 open_ping_file(); DEBUG_IT("pr.c", 'r');
300 open_IO_files(); DEBUG_IT("pr.c", ' ');
302 print_check_output(); DEBUG_IT("pr.c", ' ');
303 print_output_banner_0(); DEBUG_IT("pr.c", ' ');
304 call_ping_2(); DEBUG_IT("pr.c", ' ');
305 load_files(); DEBUG_IT("pr.c", ' ');
306 process_error_if_any(); DEBUG_IT("fc.c", ' ');
307
308 build_main_loop(); DEBUG_IT("pr.c", 's');
309 process_error_if_any(); DEBUG_IT("fc.c", ' ');
310
311 print_check_arrays(); DEBUG_IT("pr.c", 't');
312 close_IO_files(); DEBUG_IT("pr.c", ' ');
313 call_closedown_functions(); DEBUG_IT("pr.c", ' ');
314
315 close_main(); DEBUG_IT("pr.c", 'u');
316 process_error_if_any(); DEBUG_IT("fc.c", ' ');
317
318 control_init_function(); DEBUG_IT("pr.c", 'v');
319 reset_variables_function(); DEBUG_IT("pr.c", ' ');
320 reset_nodes_function(); DEBUG_IT("pr.c", ' ');
321 reset_arrays_function(); DEBUG_IT("pr.c", ' ');
322 reset_records_function(); DEBUG_IT("pr.c", ' ');
324 process_error_if_any(); DEBUG_IT("fc.c", ' ');
325
326 load_function(); DEBUG_IT("pr.c", 'w');
327 dump_function(); DEBUG_IT("pr.c", ' ');
328 process_error_if_any(); DEBUG_IT("fc.c", ' ');
329
331 check_option_function(); DEBUG_IT("co.c", ' ');
332 check_directive_function(); DEBUG_IT("pr.c", ' ');
333 napa_IO_manager_function(); DEBUG_IT("rm.c", ' ');
334 napa_data_record_function(); DEBUG_IT("rm.c", ' ');
335 process_error_if_any(); DEBUG_IT("fc.c", ' ');
336
337 randomizer_functions(); DEBUG_IT("rg.c", 'y');
338 random_functions(); DEBUG_IT("rg.c", ' ');
339 print_ping_function(); DEBUG_IT("pr.c", ' ');
340 napa_timer_function(); DEBUG_IT("pr.c", ' ');
341 napa_exit_functions(); DEBUG_IT("pr.c", ' ');
342 process_error_if_any(); DEBUG_IT("fc.c", ' ');
343
344
345 /* end of compilation ......................................................................................................... */
346
347 that_s_all(); DEBUG_IT("pr.c", 'z');
348 process_error_if_any(); DEBUG_IT("fc.c", ' ');
349 DEBUG_IT("", ' ');
350 return EXIT_SUCCESS;
351}
352
353
354/* ****************************************************************************************************************************** */
355
356/* end of main file */
void build_main_loop(void)
Definition bl.c:45
void process_command_line(long c, char **v)
Definition cl.c:108
void tag_executable(const char *d, const char *t)
Definition cl.c:62
void collect_string_of_options(void)
Definition co.c:379
void collect_string_of_functions(void)
Definition co.c:561
void check_option_function(void)
Definition co.c:87
void declaration_type_B(void)
Definition dc.c:227
void declaration_type_A(void)
Definition dc.c:25
void check_record_usage(void)
Definition fc.c:560
void process_error_if_any(void)
Definition fc.c:1467
void compact_segment(void)
Definition fc.c:1273
void expand_string_variables(void)
Definition fc.c:323
void determine_segment_processing_rate(void)
Definition fc.c:1080
void complete_directives(void)
Definition fc.c:310
void check_array_usage(void)
Definition fc.c:503
void build_to_be_delayed_node_list(void)
Definition fc.c:998
void expand_records(void)
Definition fc.c:377
void determine_output_segment_rate(void)
Definition fc.c:1135
void check_directive_usage(void)
Definition fc.c:631
void expand_update_definitions(void)
Definition fc.c:777
void expand_dump_definitions(void)
Definition fc.c:887
void collect_export_definitions(void)
Definition fc.c:671
void expand_IO_definitions(void)
Definition fc.c:844
void process_aliases(void)
Definition fc.c:1328
void default_control_variables(void)
Definition fc.c:184
void determine_simulation_rate(void)
Definition fc.c:1025
void mark_updates_if_constant(void)
Definition id.c:919
void mark_constants(void)
Definition id.c:1064
void line_parsing(void)
Definition lp.c:118
int main(int argc, char **argv)
Definition main.c:149
#define DEBUG_IT(f, c)
Definition main.c:142
#define LENGTH(s)
Definition napa.h:397
#define STDERR
Definition napa.h:105
void node_determination(void)
Definition nd.c:37
void check_directive_function(void)
Definition pr.c:3627
void print_ping_function(void)
Definition pr.c:4963
void declare_records(void)
Definition pr.c:2117
void open_main(void)
Definition pr.c:2410
void reset_arrays_function(void)
Definition pr.c:3074
void call_initialization_functions_B(void)
Definition pr.c:4850
void include_napa_header_files(void)
Definition pr.c:1883
void print_check_arrays(void)
Definition pr.c:4886
void include_ANSI_C_header_files(void)
Definition pr.c:588
void dump_function(void)
Definition pr.c:4324
void call_initialization_functions_A(void)
Definition pr.c:4722
void reset_records_function(void)
Definition pr.c:3430
void reset_nodes_function(void)
Definition pr.c:3678
void open_ping_file(void)
Definition pr.c:4739
void print_output_banner_0(void)
Definition pr.c:5042
void define_macros(void)
Definition pr.c:607
void declare_prototypes(void)
Definition pr.c:1698
void print_check_output(void)
Definition pr.c:4950
void command_line_usage_function(void)
Definition pr.c:2476
void napa_timer_function(void)
Definition pr.c:4622
void load_function(void)
Definition pr.c:4309
void call_ping_1(void)
Definition pr.c:4924
void build_usage_comment(void)
Definition pr.c:77
void declare_function_pointers(void)
Definition pr.c:1689
void print_C_code_banner_a(void)
Definition pr.c:158
void control_init_function(void)
Definition pr.c:2596
void declare_file_handles(void)
Definition pr.c:1914
void call_napa_initialization_function(void)
Definition pr.c:4705
void reset_variables_function(void)
Definition pr.c:2641
void that_s_all(void)
Definition pr.c:5506
void declare_global_values(void)
Definition pr.c:1261
void define_directives(void)
Definition pr.c:1764
void napa_exit_functions(void)
Definition pr.c:4638
void close_IO_files(void)
Definition pr.c:5394
void declare_arrays(void)
Definition pr.c:2063
void close_main(void)
Definition pr.c:5473
void call_ping_2(void)
Definition pr.c:4937
void declare_vars(void)
Definition pr.c:1947
void load_files(void)
Definition pr.c:4299
void print_C_code_banner_b(void)
Definition pr.c:424
void declare_nodes(void)
Definition pr.c:2137
void call_closedown_functions(void)
Definition pr.c:5334
void print_output_banner_function(void)
Definition pr.c:5250
void open_IO_files(void)
Definition pr.c:4772
void syntax_command_line(void)
Definition sx.c:45
void purge_constants_in_ganging(void)
Definition rd.c:1320
void stuck_nodes(void)
Definition rd.c:1689
void check_types(void)
Definition tp.c:28
void syntax_updates(void)
Definition sx.c:1462
void syntax_fs(void)
Definition sx.c:138
void name_mangling(void)
Definition rd.c:1050
void inject_nodes(void)
Definition rd.c:1002
void redefine_random_seed(void)
Definition rd.c:1038
void separe_qualifiers(void)
Definition rd.c:158
void syntax_directives(void)
Definition sx.c:113
void sort_nodes(void)
Definition sn.c:115
void build_cross_reference(void)
Definition xr.c:20
void syntax_variables(void)
Definition sx.c:1506
int f1flush(FILE *fp)
Definition tk.c:1843
void purge_constants_in_options(void)
Definition rd.c:1389
void sort_records(void)
Definition sv.c:444
void redefine_node_segments(void)
Definition rd.c:58
void process_init(void)
Definition rd.c:1735
void sort_updates(void)
Definition sv.c:325
void sort_vars(void)
Definition sv.c:209
void build_var_dependencies(void)
Definition sv.c:40
void syntax_records(void)
Definition sx.c:1362
void build_record_dependencies(void)
Definition sv.c:159
void syntax_nodes(void)
Definition sx.c:159
void syntax_terminate(void)
Definition sx.c:1441
void create_nodes(void)
Definition rd.c:715
void random_functions(void)
Definition rg.c:148
void randomizer_functions(void)
Definition rg.c:120
void redefine_nodes(void)
Definition rd.c:350
void napa_IO_manager_function(void)
Definition rm.c:58
void build_node_dependencies(void)
Definition sn.c:40
void collect_functions(void)
Definition rd.c:1148
void syntax_segment_value(void)
Definition sx.c:1414
void debug_it(const char *file, char c)
void napa_data_record_function(void)
Definition rm.c:509
void build_update_dependencies(void)
Definition sv.c:92