NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/pr.c
Go to the documentation of this file.
1/* *** VARIOUS INITIALIZATIONS AND DECLARATIONS IN THE OUTPUT CODE ************************************************************** */
2
3#undef EXTERN
4#define EXTERN extern
5
6#include "./napa.h"
7#include "./proto.h"
8
9
10/* *** In this file: ************************************************************************************************************ */
11
12/* void build_usage_comment(void) */
13/* void call_closedown_functions(void) */
14/* void call_initialization_functions_A(void) */
15/* void call_initialization_functions_B(void) */
16/* void call_napa_initialization_function(void) */
17/* void call_ping_1(void) */
18/* void call_ping_2(void) */
19/* void call_postprocess_functions(const char *indent, char const *type) */
20/* void call_user_functions(const char *indent, const char *type) */
21/* void check_directive_function(void) */
22/* void close_IO_files(void) */
23/* void close_main(void) */
24/* void command_line_usage_function(void) */
25/* void control_init_function(void) */
26/* void declare_a_digital_node(long i) */
27/* void declare_an_analog_node(long i) */
28/* void declare_arrays(void) */
29/* void declare_file_handles(void) */
30/* void declare_function_pointers(void) */
31/* void declare_global_values(void) */
32/* void declare_nodes(void) */
33/* void declare_prototypes(void) */
34/* void declare_records(void) */
35/* void declare_vars(void) */
36/* void define_directives(void) */
37/* void define_macros(void) */
38/* void dump_function(void) */
39/* void include_ANSI_C_header_files(void) */
40/* void include_napa_header_files(void) */
41/* void load_files(void) */
42/* void load_function(void) */
43/* void napa_exit_functions(void) */
44/* void napa_timer_function(void) */
45/* void open_IO_files(void) */
46/* void open_main(void) */
47/* void open_ping_file(void) */
48/* void prepare_tool_synchronization(void) */
49/* void print_C_code_banner_a(void) */
50/* void print_C_code_banner_b(void) */
51/* void print_check_arrays(void) */
52/* void print_check_output(void) */
53/* void print_error_banner_and_exit(void) */
54/* void print_output_banner_0(void) */
55/* void print_output_banner_1(long i, long j) */
56/* void print_output_banner_2(long i) */
57/* void print_output_banner_3(void) */
58/* void print_output_banner_4(char *tok) */
59/* void print_output_banner_function(void) */
60/* void print_ping_function(void) */
61/* void print_terminate_condition(void) */
62/* void reset_a_command_line_parameter(long) */
63/* void reset_a_dc_node(long i) */
64/* void reset_a_digital_node(long i) */
65/* void reset_an_analog_node(long i) */
66/* void reset_arrays_function(void) */
67/* void reset_nodes_function(void) */
68/* void reset_records_function(void) */
69/* void reset_simulator_variables(void) */
70/* void reset_user_variables(void) */
71/* void reset_variables_function(void) */
72/* void that_s_all(void) */
73
74
75/* ****************************************************************************************************************************** */
76
78 long i, j, k;
79 int flag;
80 char v0[STRLENGTH] = {'\0'};
81 if (!Cmdline_Flag) { /* used only when building standalone simulator */
82 return;
83 }
84 do { /* compact list of parms by removing void parameter */
85 flag = false;
86 for (j = 0L; j < Num_Cmdlines; j++) { /* inspect parms of command line */
87 if (0 == strcmp(Cmdline_List[j].parms, "void")) { /* compact list of parms */
88 for (k = (j+1L); k < Num_Cmdlines; k++) {
89 strcpy_realloc(&(Cmdline_List[k-1L].parms), Cmdline_List[k].parms, Cmdline_List[k].mline, Cmdline_List[k].mfile);
90 strcpy_realloc(&(Cmdline_List[k-1L].comment), Cmdline_List[k].comment, Cmdline_List[k].mline, Cmdline_List[k].mfile);
91 }
93 flag = true;
94 continue;
95 }
96 }
97 } while (flag);
98 for (j = 0L; j < Num_Cmdlines; j++) { /* build the line of parms */
99 (void) strcpy(v0, Cmdline_String);
100 (void) snprintf(Cmdline_String, (size_t) (STRLENGTH-1L), "%s %s", v0, Cmdline_List[j].parms);
101 }
102 for (j = 0L; j < Num_Cmdlines; j++) { /* inspect parms of command line */
103 if (0 == strcmp(Cmdline_List[j].parms, "fs")) {
104 strcpy_realloc(&(Cmdline_List[j].comment), "sampling frequency", Cmdline_List[j].mline, Cmdline_List[j].mfile);
105 Fs_Ext_Flag = true;
106 continue;
107 }
108 if (0 == strcmp(Cmdline_List[j].parms, "ts")) {
109 strcpy_realloc(&(Cmdline_List[j].comment), "sampling period", Cmdline_List[j].mline, Cmdline_List[j].mfile);
110 Ts_Ext_Flag = true;
111 continue;
112 }
113 i = var_id(Cmdline_List[j].parms);
114 if (UNDEFINED == i) {
115 print_error_location("command_line", Cmdline_List[j].mline, Cmdline_List[j].mfile);
116 (void) fprintf(STDERR, " <%s> must be a user's variable,", Cmdline_List[j].parms);
117 (void) fprintf(STDERR, " the sampling frequency <fs> or the sampling period <ts>\n");
118 }
119 Var_List[i].external = true; /* part of command line */
120 }
121 for (i = 0L; i < Num_Vars; i++) { /* inspect vars */
122 if (Var_List[i].external) { /* variable part of command line */
123 j = cmdline_id(Var_List[i].name1);
124 strcpy_realloc(&(Cmdline_List[j].comment), Var_List[i].comment, Cmdline_List[j].mline, Cmdline_List[j].mfile);
125 } else { /* variable not part of command line */
126 if (ISEMPTY(Var_List[i].value)) {
127 if (DIGITAL_DATA_TYPE == Var_List[i].type) {
128 print_error_location("ivar", Var_List[i].mline, Var_List[i].mfile);
129 }
130 if (ANALOG_DATA_TYPE == Var_List[i].type) {
131 print_error_location("dvar", Var_List[i].mline, Var_List[i].mfile);
132 }
133 if (STRING_DATA_TYPE == Var_List[i].type) {
134 print_error_location("string", Var_List[i].mline, Var_List[i].mfile);
135 }
136 (void) fprintf(STDERR, " variable <%s> has no definition\n", Var_List[i].name1);
137 continue;
138 }
139 if ((DIGITAL_DATA_TYPE == Var_List[i].type) && (is_a_string(Var_List[i].comment))) {
140 print_error_location("ivar", Var_List[i].mline, Var_List[i].mfile);
141 (void) fprintf(STDERR, " variable <%s> cannot be defined here as a string,", Var_List[i].name1);
142 (void) fprintf(STDERR, " as it is declared as digital\n");
143 continue;
144 }
145 if ((ANALOG_DATA_TYPE == Var_List[i].type) && (is_a_string(Var_List[i].comment))) {
146 print_error_location("dvar", Var_List[i].mline, Var_List[i].mfile);
147 (void) fprintf(STDERR, " variable <%s> cannot be defined here as a string,", Var_List[i].name1);
148 (void) fprintf(STDERR, " as it is declared as analog\n");
149 continue;
150 }
151 strcpy_realloc(&(Var_List[i].comment), "", Var_List[i].mline, Var_List[i].mfile);
152 }
153 }
154 return;
155}
156
157/* Start to print the C code file on 'STDOUT' */
159 long i, n, m;
160 int a, b, c;
161 int len, numused;
162 char *str1 = (char*) NULL;
163 char *str2 = (char*) NULL;
164 char tok1[LINLENGTH] = {'\0'};
165 char tok2[LINLENGTH] = {'\0'};
166 char buf[LINLENGTH] = {'\0'};
167 numused = 0;
168 if ((!Cmdline_Flag) && (Comment_Flag)) {
169 (void) fprintf(STDERR, "\n\n");
170 for (i = 0L; i < Num_Comments; i++) {
171 (void) fprintf(STDERR, " **** %s\n", Comment_String[i]);
172 }
173 (void) fprintf(STDERR, "\n\n");
174 }
175 (void) fprintf(STDOUT, "\n/* *** CREATED BY NAPA %6s [%5s]", NAPA_COMPILER_VERSION, MACHINE);
176 (void) fprintf(STDOUT, " ***** %24s %s */\n\n", NAPA_Compile_Time, multiple('*', 58L));
177 (void) fprintf(STDOUT, "/* *** Ad Hoc Cycle-Based ANSI-C Simulator");
178 (void) fprintf(STDOUT, " Compiled for '%s' %*s *** */\n\n", User_Name, 64 - (int) strlen(User_Name), " ");
179 (void) fprintf(STDOUT, "/* *** Author and support: Yves Leduc %66s *** */\n", " ");
180 (void) fprintf(STDOUT, "/* *** Email: yves.leduc.be@gmail.com %78s *** */\n\n", " ");
181 if (Title_Flag) {
182 (void) fprintf(STDOUT, "/* *** %115s *** */\n", " ");
183 (void) fprintf(STDOUT, "/* *** %115s *** */\n", " ");
184 (void) snprintf(tok1, (size_t) (LINLENGTH-1L), "%s", Title_String);
185 str1 = tok1;
186 str2 = tok2;
187 while (ISNOTEMPTY(str1)) { /* cut Title_String in lines */
188 str1 = extract_line(str1, str2);
189 n = (long) strlen(str2);
190 (void) fprintf(STDOUT, "/* *** %s %s *** */\n", str2, multiple(' ', 115 - n));
191 }
192 (void) fprintf(STDOUT, "/* *** %115s *** */\n", " ");
193 (void) fprintf(STDOUT, "/* *** %115s *** */\n\n", " ");
194 }
195 (void) strcpy(tok1, NAPA_COMPILER_VERSION);
196 if ('X' == tok1[0]) {
197 tok1[0] = 'V';
198 tok1[5] = '\0';
199 (void) fprintf(STDOUT, "\n/* %s */\n", multiple('*', 124L));
200 (void) fprintf(STDOUT, "/* *** This file has been produced by a BETA RELEASE of version %-56s *** */\n", tok1);
201 (void) fprintf(STDOUT, "/* *** Use this version for evaluation only. %-56s *** */\n", " ");
202 (void) fprintf(STDOUT, "/* *** Switch to next standard release as soon as possible. %-56s *** */\n", " ");
203 (void) fprintf(STDOUT, "/* %s */\n\n\n", multiple('*', 124L));
204 }
205 if (Stuck_Flag) {
206 (void) fprintf(STDOUT, "\n/* %s */\n", multiple('*', 124L));
207 (void) fprintf(STDOUT, "/* *** FAULT MODELLING. This file does not describe the circuit under %48s *** */\n", " ");
208 if (1L == Num_Stucks) {
209 (void) fprintf(STDOUT, "/* *** test but a variant to simulate the behavior with a stuck node: %48s *** */\n", " ");
210 } else {
211 (void) fprintf(STDOUT, "/* *** test but a variant to simulate the behavior with %2ld stuck nodes: %50s *** */\n", Num_Stucks, " ");
212 }
213 for (n = 0L; n < Num_Stucks; n++) {
214 (void) fprintf(STDOUT, "/* *** -> %-112s *** */\n", Stuck_List[n].name);
215 }
216 (void) fprintf(STDOUT, "/* %s */\n\n\n", multiple('*', 124L));
217 }
218 if (Cmdline_Flag) {
219 (void) fprintf(STDERR, "\n ****\n");
220 (void) fprintf(STDERR, " ****\n");
221 (void) fprintf(STDERR, " ****\n");
222 (void) fprintf(STDERR, " **** Building a Standalone Simulator to be run on %5s OS\n", MACHINE);
223 (void) fprintf(STDERR, " ****\n");
224 (void) fprintf(STDERR, " ****\n");
225 (void) fprintf(STDERR, " ****\n\n");
226 (void) fprintf(STDOUT, "\n/* %s */\n", multiple('*', 124L));
227 (void) fprintf(STDOUT, "/* *** File is built to produce a STANDALONE EXECUTABLE running on %5s OS. %49s */\n", MACHINE, " ");
228 if (0L == Num_Cmdlines) {
229 (void) fprintf(STDOUT, "/* *** No parameter %-103s */\n", " ");
230 } else if (1L == Num_Cmdlines) {
231 (void) fprintf(STDOUT, "/* *** %2ld parameter : %-105s */\n", 1L, Cmdline_String);
232 } else {
233 (void) fprintf(STDOUT, "/* *** %2ld parameters: %-105s */\n", Num_Cmdlines, Cmdline_String);
234 }
235 (void) fprintf(STDOUT, "/* %s */\n\n\n", multiple('*', 124L));
236 }
237 if (!verify_rshift()) {
238 (void) fprintf(STDOUT, "\n/* %s */\n", multiple('*', 124L));
239 (void) fprintf(STDOUT, "/* *** %50s *** */\n", " ");
240 (void) fprintf(STDOUT, "/* *** THIS PLATFORM DOES -NOT- SUPPORT SIGN EXTENSION ON RIGHT SHIFTS!%50s *** */\n", " ");
241 (void) fprintf(STDOUT, "/* *** %50s *** */\n", " ");
242 (void) fprintf(STDOUT, "/* %s */\n\n\n", multiple('*', 124L));
243 }
244 if (!Loop_Flag) {
245 (void) fprintf(STDOUT, "\n/* %s */\n", multiple('*', 124L));
246 (void) fprintf(STDOUT, "/* MAIN SIMULATION LOOP IS EMPTY AS TERMINATE CONDITION IS SET TO 'true' %54s */\n", " ");
247 (void) fprintf(STDOUT, "/* %s */\n\n\n", multiple('*', 124L));
248 }
249 if (0L == Num_Cells) {
250 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Main_File_Name);
251 if (38L < (LENGTH(buf))) {
252 (void) fprintf(STDOUT, "/* Main NAPA netlist file name : %-91s */\n", " ");
253 (void) fprintf(STDOUT, "/* -> %-117s */\n", buf);
254 } else {
255 (void) fprintf(STDOUT, "/* Main NAPA netlist file name : %-91s */\n", buf);
256 }
257 } else {
258 (void) fprintf(STDOUT, "/* This ANSI-C [c2x] code has been produced by the NAPA compiler from these");
259 if (10L <= Num_FileCells) {
260 (void) fprintf(STDOUT, " %2ld netlist files: %30s */\n", Num_FileCells, " ");
261 } else {
262 (void) fprintf(STDOUT, " %ld netlist files: %30s */\n", Num_FileCells, " ");
263 }
264 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Cur_Fil_Name[0]);
265 (void) fprintf(STDOUT, "\n/* (main) -> %-112s */\n", buf);
266 for (n = 1L; n < Num_FileCells; n++) {
267 if (1L >= Record_Cell_File_Usage[n]) {
268 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Record_Cell_File_Table[n] );
269 (void) fprintf(STDOUT, "/* -> %-112s */\n", buf);
270 } else {
271 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Record_Cell_File_Table[n] );
272 (void) fprintf(STDOUT, "/* %2ldx -> %-112s */\n", Record_Cell_File_Usage[n], buf);
273 }
274 }
275 }
276 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Header_Lib_Name);
277 (void) fprintf(STDOUT, "\n/* These libraries have been REGISTERED by the user" );
278 (void) fprintf(STDOUT, " in the NAPA compiler line command: %40s */\n", " ");
279 if (42L < (LENGTH(buf))) {
280 (void) fprintf(STDOUT, "\n/* Generic headers: %100s */\n", " ");
281 (void) fprintf(STDOUT, "/* -> %-112s */\n", buf);
282 } else {
283 (void) fprintf(STDOUT, "\n/* -> Generic headers : %-88s */\n", buf);
284 }
285 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Net_Lib_Name);
286 if (42L < (LENGTH(buf))) {
287 (void) fprintf(STDOUT, "/* Generic cells: %100s */\n", " ");
288 (void) fprintf(STDOUT, "/* -> %-112s */\n", buf);
289 } else {
290 (void) fprintf(STDOUT, "/* -> Generic cells : %-88s */\n", buf);
291 }
292 (void) snprintf(buf, (size_t) (LINLENGTH-1L), "\"%s\"", Generator_Lib_Name);
293 if (42L < (LENGTH(buf))) {
294 (void) fprintf(STDOUT, "/* Generic generators: %100s */\n", " ");
295 (void) fprintf(STDOUT, "/* -> %-112s */\n", buf);
296 } else {
297 (void) fprintf(STDOUT, "/* -> Generic generators : %-88s */\n", buf);
298 }
299 if (Ping_Flag) {
300 (void) fprintf(STDOUT, "\n/* According to the user's demand,");
301 (void) fprintf(STDOUT, " the ping function is implemented and activated. %44s */\n", " ");
302 }
303 if (Loop_Flag) {
305 b = node_update_block();
306 c = time_output_block();
307 if (1 < (a + b + c)) {
308 (void) fprintf(STDOUT, "\n/* The main loop of the simulator is divided by the compiler");
309 (void) fprintf(STDOUT, " in %d blocks containing the code %34s */\n", a+b+c, " ");
310 if ((!a) && (b) && (c)) {
311 (void) fprintf(STDOUT, "/* respectively for the node updates and the time domain output. %49s */\n", " ");
312 }
313 if ((a) && (b) && (!c)) {
314 (void) fprintf(STDOUT, "/* respectively for the variable and node updates. %49s */\n", " ");
315 }
316 if ((a) && (b) && (c)) {
317 (void) fprintf(STDOUT, "/* respectively for the variable and node updates and the time domain output. %49s */\n", " ");
318 }
319 (void) fprintf(STDOUT, "\n");
320 for (n = 0L; n < Num_Segments; n++) {
321 if (Segment_List[n].used1 || Segment_List[n].used2) {
322 numused++;
323 }
324 }
325 if (9 < numused) {
326 (void) fprintf(STDOUT, "/* Each block may be divided up to %2d segments according to the netlist. %51s */\n", numused, " ");
327 } else if (1 < numused) {
328 (void) fprintf(STDOUT, "/* Each block may be divided up to %d segments according to the netlist. %51s */\n", numused, " ");
329 }
330 if (Output_Flag) {
331 (void) fprintf(STDOUT, "/* One or several segments have been added for the");
332 (void) fprintf(STDOUT, " appropriate processing of the 'output' instruction. %24s */\n", " ");
333 }
334 } else {
335 if (9 < numused) {
336 (void) fprintf(STDOUT, "\n/* Main loop is divided up to %2d segments according to the netlist. %50s */\n", numused, " ");
337 } else if (1 < numused) {
338 (void) fprintf(STDOUT, "\n/* Main loop is divided up to %d segments according to the netlist. %51s */\n", numused, " ");
339 }
340 if (Output_Flag) {
341 (void) fprintf(STDOUT, "/* One or several segments have been added for the");
342 (void) fprintf(STDOUT, " appropriate processing of the 'output' instruction. %24s */\n", " ");
343 }
344 }
345 }
346#if (IS_WIN64 == PLATFORM) /* case-insensitive OS */
347 (void) fprintf(STDOUT, "\n/* This simulator is built for Windows OS, where the file names are not case-sensitive. %39s */\n", " ");
348#endif
349 (void) fprintf(STDOUT, "\n/* (char) coded with : %4ld %-86s */\n", (long) sizeof (char), "byte (C_TYPE)");
350 (void) fprintf(STDOUT, "/* (short int) coded with : %4ld %-86s */\n", (long) sizeof (short), "bytes" );
351 (void) fprintf(STDOUT, "/* (int) coded with : %4ld %-86s */\n", (long) sizeof (int), "bytes" );
352 (void) fprintf(STDOUT, "/* (long int) coded with : %4ld %-86s */\n", (long) sizeof (long), "bytes (P_TYPE)");
353 (void) fprintf(STDOUT, "/* (long long int) coded with : %4ld %-86s */\n", (long) sizeof (long long), "bytes (I_TYPE)");
354 (void) fprintf(STDOUT, "/* (float) coded with : %4ld %-86s */\n", (long) sizeof (float), "bytes (L_PREC)");
355 (void) fprintf(STDOUT, "/* (double float) coded with : %4ld %-86s */\n", (long) sizeof (double), "bytes (R_TYPE)");
356 (void) fprintf(STDOUT, "/* (long double float) coded with : %4ld %-86s */\n", (long) sizeof (long double), "bytes (H_PREC)");
357 (void) fprintf(STDOUT, "/* (size_t) coded with : %4ld %-86s */\n", (long) sizeof (size_t), "bytes" );
358 (void) fprintf(STDOUT, "/* (void*) coded with : %4ld %-86s */\n", (long) sizeof (void*), "bytes" );
359 (void) fprintf(STDOUT, "\n/* Resolution of a (double float) : %4ld %-86s */\n", (long) DBL_DIG, "digits" );
360 if (!Stuck_Flag) {
361 (void) fprintf(STDOUT, "\n/* Number of user's nodes : %4ld %-86s */\n", Num_Nodes - Num_Creates, " " );
362 } else {
364 if (1L >= Num_Stucks) {
365 (void) fprintf(STDOUT, "\n/* Number of user's nodes : %4ld (INCLUDING 1 STUCK NODE) %53s */\n", n, " " );
366 } else {
367 (void) fprintf(STDOUT, "\n/* Number of user's nodes : %4ld (INCLUDING %2ld STUCK NODES)%55s */\n", n, Num_Stucks, " ");
368 }
369 }
370 if (0L < Num_Creates) {
371 (void) fprintf(STDOUT, "/* Number of created nodes : %4ld %-86s */\n", Num_Creates, " ");
372 }
373 if (0L < Num_Injects) {
374 (void) fprintf(STDOUT, "/* Number of node injections : %4ld %-86s */\n", Num_Injects, " ");
375 }
376 m = 0L;
377 for (n = 0L; n < Num_Vars; n++) { /* count number of true variables */
378 if ((0 != strncmp(Var_List[n].name1, "$init$", (size_t) 6))
379 && (0 != strncmp(Var_List[n].name1, "$null$", (size_t) 6))
380 && (0 != strncmp(Var_List[n].name1, "$declare$", (size_t) 9))) {
381 m++;
382 }
383 }
384 if (0L < m) {
385 len = fprintf(STDOUT, "/* Number of user's variables : %4ld %5s ", m - Num_Consts, " ");
386 (void) fprintf(STDOUT, " %*s */\n", 126 - len, " ");
387 }
388 if (0L < Num_Consts) {
389 (void) fprintf(STDOUT, "/* Number of created constants : %4ld %86s */\n", Num_Consts, " ");
390 }
391 if (0L < Num_Directives) {
392 (void) fprintf(STDOUT, "/* Number of user's directives : %4ld %86s */\n", Num_Directives, " ");
393 }
394 if (0L < Num_Tools) {
395 (void) fprintf(STDOUT, "/* Number of analysis tools : %4ld %86s */\n", Num_Tools, " ");
396 }
397 if (0L < Num_Posts) {
398 m = 0L;
399 for (n = 0L; n < Num_Posts; n++) {
400 if (0 != strcmp(Post_List[n].function, "post_void")) {
401 m++;
402 }
403 }
404 (void) fprintf(STDOUT, "/* Number of postprocessings : %4ld %86s */\n", m, " ");
405 }
407 if (0L < n) {
408 (void) fprintf(STDOUT, "/* Number of user's declarations : %4ld %86s */\n", n, " ");
409 }
410 if (0L < Num_Cells) {
411 (void) fprintf(STDOUT, "/* Number of cell instantiations : %4ld %86s */\n", Num_Cells, " ");
412 if (1L < Max_Depth) {
413 (void) fprintf(STDOUT, "/* Maximum cell hierarchy depth : %4ld %86s */\n\n", Max_Depth, " ");
414 } else {
415 (void) fprintf(STDOUT, "\n");
416 }
417 } else {
418 (void) fprintf(STDOUT, "\n");
419 }
420 return;
421}
422
423
425 long n, m;
426 double f, r;
427 int first, flag;
428 char *str = (char*) NULL;
429 char buf1[LINLENGTH] = {'\0'};
430 char buf2[LINLENGTH] = {'\0'};
431 char tok[LINLENGTH] = {'\0'};
432 char unit[7] = {'\0'};
433 if (Periodic_Flag) {
434 flag = true;
435 for (n = 1L; n < Num_Segments; n++) {
436 if (ISNOTEQUAL(Segment_List[n].rate, Segment_List[0].rate)) {
437 flag = false; /* at least one segment is not running at sim rate */
438 break;
439 }
440 }
441 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
442 (void) fprintf(STDOUT, "/* N.B. These sampling and rate informations are RELATIVE to the sampling %52s */\n", " ");
443 (void) fprintf(STDOUT, "/* frequency input from the command line of this standalone simulator: %52s */\n\n", " ");
444 (void) strcpy(unit, " x fs "); /* relative information, no unit */
445 } else {
446 (void) strcpy(unit, "Hz "); /* absolute information */
447 }
448 f = Simulation_Rate * Sampling_List.frequency; /* main loop frequency */
449 if (1L < Num_Segments) {
450 (void) fprintf(STDOUT, "/* Simulation rate : ");
451 (void) fprintf(STDOUT, " %s [ main loop ]", format_suffixed_number(f, 6, unit));
452 (void) fprintf(STDOUT, " %56s */\n", " ");
453 } else {
454 (void) fprintf(STDOUT, "/* Simulation rate : ");
455 (void) fprintf(STDOUT, " %s ", format_suffixed_number(f, 6, unit));
456 (void) fprintf(STDOUT, " %56s */\n", " ");
457 }
458 if (flag) { /* all segments are running at the same rate */
459 if (1L < Num_Segments) {
460 (void) fprintf(STDOUT, "/* Sampling frequency : ");
461 (void) fprintf(STDOUT, " %s [all segments]", format_suffixed_number(f, 6, unit));
462 (void) fprintf(STDOUT, " %56s */\n\n", " ");
463 } else {
464 (void) fprintf(STDOUT, "/* Sampling frequency : ");
465 (void) fprintf(STDOUT, " %s ", format_suffixed_number(f, 6, unit));
466 (void) fprintf(STDOUT, " %56s */\n\n", " ");
467 }
468 } else { /* segments are NOT running at the same rate */
469 first = true;
470 for (n = 0L; n < Num_Segments; n++) {
471 if (Segment_List[n].used1 || Segment_List[n].used2) {
472 if (first) {
473 (void) fprintf(STDOUT, "/* Sampling frequency : ");
474 first = false;
475 } else {
476 (void) fprintf(STDOUT, "/* : ");
477 }
478 (void) fprintf(STDOUT, " %s [ segment %-2ld]", format_suffixed_number(Segment_List[n].frequency, 6, unit), n);
479 r = f / Segment_List[n].frequency;
480 if (ISNOTINTEGER(r)) {
481 print_error_location("segment rate", Segment_List[n].mline, Segment_List[n].mfile);
482 (void) fprintf(STDERR, " NAPA compiler internal bug, segment %ld: an integer was expected\n", n);
483 continue;
484 }
485 if (1.0 == r) {
486 (void) fprintf(STDOUT, " i.e. segment always triggered */\n" );
487 } else {
488 (void) fprintf(STDOUT, " i.e. segment triggered 1 over %-11ld */\n", D2I(r) );
489 }
490 }
491 }
492 }
493 }
494 if ((Export_Flag) || (Dump_Flag) || (Load_Flag)) {
495 (void) fprintf(STDOUT, "\n");
496 }
497 if (Export_Flag) {
499 for (;;) {
500 str = get_token(str, tok, true);
501 if (ISEMPTY(tok)) {
502 break;
503 }
504 n = node_id(tok);
505 if (UNDEFINED != n) {
506 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
507 (void) fprintf(STDOUT, "/* A digital node is exported : %-88s */\n", tok);
508 } else {
509 (void) fprintf(STDOUT, "/* An analog node is exported : %-88s */\n", tok);
510 }
511 }
512 m = var_id(tok);
513 if (UNDEFINED != m) {
514 (void) fprintf(STDOUT, "/* A variable is exported : %-88s */\n", tok);
515 }
516 if ((UNDEFINED == n) && (UNDEFINED == m)) {
517 if ((0 != strcmp(tok, "TIME"))
518 && (0 != strcmp(tok, "ABS_TIME"))
519 && (0 != strcmp(tok, "REF_TIME"))
520 && (0 != strcmp(tok, "REL_TIME"))
521 && (0 != strcmp(tok, "LOOP_INDEX"))
522 && (0 != strcmp(tok, "ABS_LOOP_INDEX"))
523 && (0 != strcmp(tok, "REL_LOOP_INDEX"))
524 && (0 != strcmp(tok, "WALL_CLOCK"))) {
525 print_error_location("export", NULL, NULL);
526 (void) fprintf(STDERR, " export <%s> must be a node, a variable\n", tok);
527 (void) fprintf(STDERR, " or macros 'TIME', 'ABS_TIME', 'REF_TIME', 'REL_TIME', 'WALL_CLOCK'\n");
528 (void) fprintf(STDERR, " 'LOOP_INDEX', 'ABS_LOOP_INDEX' and 'REL_LOOP_INDEX'\n");
531 } else {
532 (void) fprintf(STDOUT, "/* A macro is exported : %-88s */\n", tok);
533 }
534 }
535 }
536 }
537 if (Dump_Flag) {
538 (void) strcpy(buf1, Dump_List.fname);
539 drop_pathname(buf1);
540 (void) snprintf(buf2, (size_t) (LINLENGTH-1L), "\"%s\"", buf1);
541 (void) fprintf(STDOUT, "/* A dump file may be output : %-88s */\n", buf2);
542 }
543 if (Load_Flag) {
544 (void) strcpy(buf1, Load_List.fname);
545 drop_pathname(buf1);
546 (void) snprintf(buf2, (size_t) (LINLENGTH-1L), "\"%s\"", buf1);
547 (void) fprintf(STDOUT, "/* A load file is input : %-88s */\n", buf2);
548 }
549 if ((!Periodic_Flag) && (Loop_Flag)) {
550 (void) fprintf(STDOUT, "\n/* The sampling period is user-defined %46s */\n", " ");
551 }
552 if ((1L < Num_Tools) && (Loop_Flag)) {
553 (void) fprintf(STDOUT, "\n");
554 if (Synchro_Flag) {
555 (void) fprintf(STDOUT, "/* This simulator is set-up to exchange synchronization messages with the tools, %46s */\n", " ");
556 (void) fprintf(STDOUT, "/* global variable TOOL_INDEX is set-up for this purpose. %46s */\n", " ");
557 } else {
558 (void) fprintf(STDOUT, "/* This simulator is set-up in such a way that tools are NOT synchronized. %46s */\n", " ");
559 }
560 }
561 if (Seed_Flag) {
562 (void) fprintf(STDOUT, "\n/* FYI, the internal pseudo-random generator uses");
563 (void) fprintf(STDOUT, " here a seed chosen randomly at the NAPA COMPILATION time. %19s */\n", " ");
564 if (!Cmdline_Flag) {
565 (void) fprintf(STDOUT, "/* It uses the value of the macro RANDOM_SEED defined below");
566 (void) fprintf(STDOUT, " to restart a simulation from this C file in the same conditions. */\n");
567 }
568 } else if (0L == Seed_List.rndseed) {
569 (void) fprintf(STDOUT, "\n/* FYI, the internal pseudo-random generator");
570 (void) fprintf(STDOUT, " uses a seed chosen randomly at the SIMULATION time. %24s */\n", " ");
571 if (!Cmdline_Flag) {
572 (void) fprintf(STDOUT, "/* Use the RANDOM_SEED value produced during this simulation");
573 (void) fprintf(STDOUT, " to restart a new simulation in the same conditions. %7s */\n", " ");
574 }
575 } else {
576 (void) fprintf(STDOUT, "\n/* FYI, the internal pseudo-random generator");
577 (void) fprintf(STDOUT, " uses the seed given by the USER in the netlist. %24s */\n", " ");
578 if (Antithetic_Flag) {
579 (void) fprintf(STDOUT, "/* A stream of pseudo-random numbers ANTITHETIC to the reference is generated. %48s */\n", " ");
580 }
581 (void) fprintf(STDOUT, "/* A new run of the same netlist will give therefore the same results again. %48s */\n", " ");
582 }
583 (void) fprintf(STDOUT, "\n/* Please feel free to report bugs or suggestions to 'yves.leduc.be@gmail.com' %48s */\n", " ");
584 return;
585}
586
587
589 (void) fprintf(STDOUT, "\n\n/* *** INCLUDE ANSI-C [c2x] STANDARD HEADER FILES %s */\n\n", multiple('*', 77L));
590 (void) fprintf(STDOUT, "#include <ctype.h>\n" );
591 (void) fprintf(STDOUT, "#include <limits.h>\n" );
592 (void) fprintf(STDOUT, "#include <float.h>\n" );
593 (void) fprintf(STDOUT, "#include <math.h>\n" );
594 (void) fprintf(STDOUT, "#include <stdio.h>\n" );
595 (void) fprintf(STDOUT, "#include <stdlib.h>\n" );
596 (void) fprintf(STDOUT, "#include <string.h>\n" );
597 (void) fprintf(STDOUT, "#include <time.h>\n" );
598 (void) fprintf(STDOUT, "#include <stdbool.h>\n");
599 (void) fprintf(STDOUT, "\n#ifdef __GNUC__\n" );
600 (void) fprintf(STDOUT, " #include <unistd.h>\n"); /* not an ANSI-C header, optional information */
601 (void) fprintf(STDOUT, "#endif\n");
602 return;
603}
604
605
606/* Print the list of macros, some of them are processed according to user's napa netlist */
607void define_macros(void) { /* parenthesis around definition to forbid redef. */
608 char tok3[STRLENGTH] = {'\0'};
609 long i, n;
610 int l, m, flag, len;
611 time_t t;
612 if (!Seed_Flag) { /* choose seed now at compilation time */
613 t = time((time_t*) NULL);
614 Seed_List.rndseed = ((long) t) / 2L;
615 }
616 (void) fprintf(STDOUT, "\n\n/* *** MACRO CONSTANTS AND VARIABLES AVAILABLE TO USER %s */\n", multiple('*', 72L));
617 (void) fprintf(STDOUT, "\n#define PLATFORM \"%s\"\n", MACHINE );
618 (void) fprintf(STDOUT, "#define NAPA_VERSION \"%s for \" PLATFORM\n\n", NAPA_COMPILER_VERSION);
619 if (Comment_Flag) {
620 if (1L == Num_Comments) { /* a single line of comment */
621 if (62L < LENGTH(Comment_String[0])) {
622 (void) fprintf(STDOUT, "\n#define COMMENT \\\n");
623 (void) fprintf(STDOUT, " \"%s\"\n", Comment_String[0]);
624 } else if (50L < LENGTH(Comment_String[0])) {
625 (void) fprintf(STDOUT, "\n#define COMMENT \"%s\"\n", Comment_String[0]);
626 } else {
627 (void) fprintf(STDOUT, "\n#define COMMENT \"%s\"\n", Comment_String[0]);
628 }
629 } else { /* more than one line of comments */
630 (void) fprintf(STDOUT, "\n#define COMMENT \\\n");
631 for (i = 0L; i < (Num_Comments-1L); i++) {
632 (void) fprintf(STDOUT, " \"%s\\n\" \\\n", Comment_String[i] ); /* all but last line */
633 }
634 (void) fprintf(STDOUT, " \"%s\\n\\n\"\n", Comment_String[Num_Comments-1L]); /* last line */
635 }
636 }
637 if (Cmdline_Flag) {
638 (void) fprintf(STDOUT, "\n#define COMMAND_LINE ( napa_cmd_line )\n" ); /* avoid redefinition */
639 (void) fprintf(STDOUT, "#define COMMAND_PARMS ( napa_cmd_parms )\n" ); /* avoid redefinition */
640 }
641 if (Cmdline_Flag) {
642 (void) fprintf(STDOUT, "\n#define USER \"NAPA Standalone Simulator\"\n");
643 (void) fprintf(STDOUT, "#define CREATED ( napa_sim_time ) %49s/* unique time */\n", " ");
644 (void) fprintf(STDOUT, "#define NAPA_JOB_ID ( napa_job_id ) %49s/* unique tag */\n\n", " ");
645 } else {
646 l = 58 - ((int) strlen(NAPA_Job_ID));
647 if (ISEMPTY(User_Name)) {
648 (void) fprintf(STDOUT, "#define USER \"?\"\n");
649 (void) fprintf(STDOUT, "#define CREATED \"%s\"\n", NAPA_Compile_Time );
650 } else {
651 (void) fprintf(STDOUT, "#define USER \"%s\"", User_Name );
652 (void) fprintf(STDOUT, " %*s /* from NAPA line command */\n", 63 - (int) strlen(User_Name), " ");
653 (void) fprintf(STDOUT, "#define CREATED \"%s by \" USER\n", NAPA_Compile_Time );
654 }
655 (void) fprintf(STDOUT, "#define NAPA_JOB_ID \"%s\" %*s/* unique time */\n\n", NAPA_Job_ID, l, " ");
656
657 }
659 (void) strcpy(Root_String, Main_File_Name);
661 if (!Cmdline_Flag) {
662 len = (int) strlen(Root_String);
663 (void) fprintf(STDOUT, "#define ORIGIN \"%s\"\n", Root_String );
664 (void) fprintf(STDOUT, "#define SOURCE \"%s\"", Main_File_Name);
665 if (0L == Num_Cells) {
666 (void) fprintf(STDOUT, "%*s /* NAPA netlist file */\n", 60 - len, " ");
667 } else {
668 (void) fprintf(STDOUT, "%*s /* NAPA main netlist file */\n", 60 - len, " ");
669 }
670 (void) fprintf(STDOUT, "#define CODE \"%s.c\"", Root_String );
671 (void) fprintf(STDOUT, "%*s /* this C file */\n", 62 - len, " ");
672 } else {
673 (void) fprintf(STDOUT, "#define ORIGIN \"%s\"\n", replace_char(User_Name, ' ', '_'));
674 (void) fprintf(STDOUT, "#define SOURCE \" - \"\n");
675 (void) fprintf(STDOUT, "#define CODE \" - \"\n");
676 }
680 (void) fprintf(STDOUT, "\n#define HEADERS_LIB \"%s\"\n", Header_Lib_Name);
681 (void) fprintf(STDOUT, "#define CELLS_LIB \"%s\"\n", Net_Lib_Name);
682 (void) fprintf(STDOUT, "#define GENERATORS_LIB \"%s\"\n", Generator_Lib_Name);
683 (void) fprintf(STDOUT, "\n#define CWD napa_cwd %58s/* current working directory */\n", " ");
684 (void) fprintf(STDOUT, "\n#define TITLE napa_title\n" );
685 if (0 != strcmp(Title_String, Short_Title_String)) {
686 (void) fprintf(STDOUT, "#define SHORT_TITLE napa_short_title\n");
687 } else {
688 (void) fprintf(STDOUT, "#define SHORT_TITLE napa_title\n" );
689 }
690 (void) fprintf(STDOUT, "\n#define TERMINATE " );
692 if (!Periodic_Flag) {
693 (void) fprintf(STDOUT, "\n#define USER_DEFINED_SAMPLING\n" );
694 }
695 n = 0L;
696 for (i = 0L; i < Num_IOs; i++) {
697 if (OUTPUT_TYPE == IO_List[i].type) {
698 n++;
699 }
700 }
701 (void) fprintf(STDOUT, "\n#define NUM_OF_TIME_OUTPUTS %ldL\n", n );
702 (void) fprintf(STDOUT, "#define NUM_OF_SEGMENTS %ldL\n\n", Num_Segments);
703 if (1L >= Num_Segments) {
704 (void) fprintf(STDOUT, "#define SEGMENT ( 0L )\n" );
705 } else {
706 (void) fprintf(STDOUT, "#define SEGMENT ( napa_segment )\n" ); /* avoid redefinition */
707 }
708 (void) fprintf(STDOUT, "#define WAYPOINT ( napa_waypoint )\n\n" );
709 if (0L != Seed_List.rndseed) {
710 (void) snprintf(tok3, (size_t) (STRLENGTH-1L), "% ld", Seed_List.rndseed );
711 m = fprintf(STDOUT, "#define RANDOM_SEED (%sLL )", tok3 );
712 if (!Seed_Flag) {
713 (void) fprintf(STDOUT, "%*s/* unique random seed */\n", 98 - m, " " );
714 } else {
715 (void) fprintf(STDOUT, "%*s/* user's random seed */\n", 98 - m, " " );
716 }
717 } else {
718 (void) fprintf(STDOUT, "#define RANDOM_SEED ( napa_random_seed )\n"); /* avoid redefinition */
719 }
720 if (Antithetic_Flag) {
721 (void) fprintf(STDOUT, "#define ANTITHETIC ( true )\n" );
722 } else {
723 (void) fprintf(STDOUT, "#define ANTITHETIC ( false )\n");
724 }
725 (void) fprintf(STDOUT, "\n#define TIME ( (R_TYPE) napa_abs_time )\n" );
726 if (UNDEFINED == directive_id("JITTER")) {
727 (void) fprintf(STDOUT, "#define REF_TIME ( (R_TYPE) napa_abs_time )\n" );
728 } else{
729 (void) fprintf(STDOUT, "#define REF_TIME ( (R_TYPE) napa_ref_time )\n" );
730 }
731 (void) fprintf(STDOUT, "#define ABS_TIME ( (R_TYPE) napa_abs_time )\n" );
732 if ((Synchro_Flag) && (1L <= Num_Tools)) {
733 (void) fprintf(STDOUT, "#define REL_TIME ( (R_TYPE) napa_rel_time )\n\n");
734 } else {
735 (void) fprintf(STDOUT, "#define REL_TIME ( (R_TYPE) napa_abs_time )\n\n");
736 }
737 if (Periodic_Flag) {
738 if (ISEQUAL(1.0, Segment_List[0].rate)) {
739 (void) fprintf(STDOUT, "#define LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n" );
740 } else {
741 m = fprintf(STDOUT, "#define LOOP_INDEX ( ((I_TYPE) napa_abs_loop)/%lldLL ) ", (NAPA_DIGITAL_TYPE) Segment_List[0].rate);
742 (void) fprintf(STDOUT, " %*s /* increment according to FS */\n", 96 - m, " " );
743 }
744 if ((Synchro_Flag) && (1L <= Num_Tools)) {
745 (void) fprintf(STDOUT, "#define ABS_LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n" );
746 (void) fprintf(STDOUT, "#define REL_LOOP_INDEX ( (I_TYPE) napa_rel_loop )\n" );
747 } else {
748 (void) fprintf(STDOUT, "#define ABS_LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n" );
749 (void) fprintf(STDOUT, "#define REL_LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n" );
750 }
751 (void) fprintf(STDOUT, "\n");
752 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
753 if (ISEQUAL(1.0, Segment_List[0].rate)) {
754 (void) fprintf(STDOUT, "#define SIM_RATE ( napa_fs_ext )\n");
755 } else {
756 (void) fprintf(STDOUT, "#define SIM_RATE ( napa_fs_ext * %.15eL )\n", Segment_List[0].rate);
757 }
758 (void) fprintf(STDOUT, "#define FS ( napa_fs_ext )\n");
759 } else {
760 (void) fprintf(STDOUT, "#define SIM_RATE ( %.15eL )\n", Sampling_List.frequency * Segment_List[0].rate);
761 (void) fprintf(STDOUT, "#define FS ( %.15eL )\n", Sampling_List.frequency );
762 }
763 if (1L < Num_Segments) {
764 (void) fprintf(STDOUT, "#define FSL ( (R_TYPE) napa_fsl[napa_segment] )");
765 (void) fprintf(STDOUT, " %*s /* segment dependent value */\n", 30, " " );
766 (void) fprintf(STDOUT, "#define STL ( napa_stl[napa_segment] ) ");
767 (void) fprintf(STDOUT, " %*s /* segment dependent value */\n", 30, " " );
768 } else {
769 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
770 (void) fprintf(STDOUT, "#define FSL ( (R_TYPE) napa_fs_ext ) ");
771 (void) fprintf(STDOUT, " %*s /* constant */\n", 30, " " );
772 } else {
773 (void) fprintf(STDOUT, "#define FSL %.15e\n", Sampling_List.frequency );
774 }
775 (void) fprintf(STDOUT, "#define STL 0LL\n" );
776 }
777 } else {
778 (void) fprintf(STDOUT, "#define LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n" );
779 (void) fprintf(STDOUT, "#define ABS_LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n\n");
780 (void) fprintf(STDOUT, "#define REL_LOOP_INDEX ( (I_TYPE) napa_abs_loop )\n\n");
781 (void) fprintf(STDOUT, "#define SIM_RATE ( 0.0L )\n");
782 (void) fprintf(STDOUT, "#define FS ( 0.0L )\n");
783 (void) fprintf(STDOUT, "#define FSL 0.0\n" );
784 (void) fprintf(STDOUT, "#define STL 0LL\n" );
785 }
786 if (1L < Num_Segments) {
787 (void) fprintf(STDOUT, "#define PERIODIC ( napa_per[napa_segment] )" );
788 (void) fprintf(STDOUT, " %*s /* segment dependent flag */\n", 39, " " );
789 } else {
790 if (Periodic_Flag) {
791 (void) fprintf(STDOUT, "#define PERIODIC ( true )\n" );
792 } else {
793 (void) fprintf(STDOUT, "#define PERIODIC ( false )\n");
794 }
795 }
796 if (Assert_Flag) {
797 (void) fprintf(STDOUT, "\n#define ERROR_FLAG ( napa_error_flag )\n");
798 (void) fprintf(STDOUT, "#define ASSERT_FLAG ( napa_assert_flag )\n");
799 } else {
800 (void) fprintf(STDOUT, "\n#define ERROR_FLAG ( napa_error_flag )\n" );
801 }
802 if (Dump_Flag) {
803 (void) fprintf(STDOUT, "\n#define DUMP_FLAG ( napa_dump_flag )\n" );
804 }
805 (void) fprintf(STDOUT, "\n#define WALL_CLOCK ( ((R_TYPE) (clock()-napa_wall_clock)) / ((R_TYPE) CLOCKS_PER_SEC) )\n");
806 (void) fprintf(STDOUT, "\n");
807 if (0L < Num_Tools) {
808 if (Synchro_Flag) {
809 (void) fprintf(STDOUT, "#define TOOL_INDEX ( napa_tool_index )\n" );
810 }
811 (void) fprintf(STDOUT, "#define PACKET ( napa_packet )\n" );
812 m = fprintf(STDOUT, "#define MAILBOX %ld", Num_Tools );
813 (void) fprintf(STDOUT, "%*s /* one box per tool instance */\n", 97 - m, " " );
814
815 }
816 if ((0L < Num_Tools) && (Loop_Flag)) {
817 if (Synchro_Flag) {
818 (void) fprintf(STDOUT, "#define SYNCHRONIZE ( YES )\n");
819 } else {
820 (void) fprintf(STDOUT, "#define SYNCHRONIZE ( NO )\n" );
821 }
822 }
823 (void) fprintf(STDOUT, "\n");
824 if (Export_Flag) {
825 (void) fprintf(STDOUT, "#define EXPORT %ldL\n", Num_Exports );
826 (void) fprintf(STDOUT, "#define V_HEAD \"%s\"\n", Export1_Head_String);
827 (void) fprintf(STDOUT, "#define V_NAME %s\n", Export1_List_String);
828 (void) fprintf(STDOUT, "#define E_HEAD \"%s\"\n", Export0_Head_String);
829 (void) fprintf(STDOUT, "#define E_LIST %s\n\n", Export0_List_String);
830 }
831 m = fprintf(STDOUT, "#define I_FORMAT \"%s\"", I_Format );
832 if (0 == strcmp(I_Format, DEFAULT_I_FORMAT)) {
833 (void) fprintf(STDOUT, "%*s /* output format by default */\n", 97 - m, " ");
834 } else {
835 (void) fprintf(STDOUT, "%*s /* as defined by user */\n", 97 - m, " ");
836 }
837 m = fprintf(STDOUT, "#define X_FORMAT \"%s\"", X_Format );
838 if (0 == strcmp(X_Format, DEFAULT_X_FORMAT)) {
839 (void) fprintf(STDOUT, "%*s /* output format by default */\n", 97 - m, " ");
840 } else {
841 (void) fprintf(STDOUT, "%*s /* as defined by user */\n", 97 - m, " ");
842 }
843 m = fprintf(STDOUT, "#define R_FORMAT \"%s\"", R_Format );
844 if (0 == strcmp(R_Format, DEFAULT_R_FORMAT)) {
845 (void) fprintf(STDOUT, "%*s /* output format by default */\n", 97 - m, " ");
846 } else {
847 (void) fprintf(STDOUT, "%*s /* as defined by user */\n", 97 - m, " ");
848 }
849 m = fprintf(STDOUT, "#define S_FORMAT \"%s\"", S_Format );
850 if (0 == strcmp(S_Format, DEFAULT_S_FORMAT)) {
851 (void) fprintf(STDOUT, "%*s /* output format by default */\n", 97 - m, " ");
852 } else {
853 (void) fprintf(STDOUT, "%*s /* as defined by user */\n", 97 - m, " ");
854 }
855 if (Export_Flag) {
856 (void) fprintf(STDOUT, "#define V_FORMAT \"%s\"\n", V_Format );
857 (void) fprintf(STDOUT, "#define E_FORMAT \"%s\"\n", E_Format );
858 }
859 (void) fprintf(STDOUT, "\n#define SEPARATOR \"\\n\"\n" );
860 (void) fprintf(STDOUT, "\n#define ANALOG_INI 0.0\n" );
861 (void) fprintf(STDOUT, "#define DIGITAL_INI 0LL\n" );
862 (void) fprintf(STDOUT, "\n#define TRUE ( true )\n" );
863 (void) fprintf(STDOUT, "#define FALSE ( false )\n" );
864 (void) fprintf(STDOUT, "#define YES ( true )\n" );
865 (void) fprintf(STDOUT, "#define NO ( false )\n" );
866 (void) fprintf(STDOUT, "\n#define LITTLE_ENDIAN ( 1 )\n" );
867 (void) fprintf(STDOUT, "#define BIG_ENDIAN ( 0 )\n" );
869 (void) fprintf(STDOUT, "#define CPU_ARCHITECTURE ( LITTLE_ENDIAN )" );
870 } else {
871 (void) fprintf(STDOUT, "#define CPU_ARCHITECTURE ( BIG_ENDIAN )" );
872 }
873 (void) fprintf(STDOUT, " %*s /* targetted architecture */\n", 48, " " );
874 if (0 < Num_UserTools) {
875 (void) fprintf(STDOUT, "\n\n/* *** MACRO FUNCTIONS MADE AVAILABLE TO USER AND USER'S FUNCTIONS %s */\n", multiple('*', 60L));
876 } else {
877 (void) fprintf(STDOUT, "\n\n/* *** MACRO FUNCTIONS MADE AVAILABLE TO USER %s */\n", multiple('*', 81L));
878 }
879 (void) fprintf(STDOUT, "\n#define MIN(x,y) (((x)<(y))?(x):(y))" );
880 (void) fprintf(STDOUT, " %31s /* regardless of the type */\n", " " );
881 (void) fprintf(STDOUT, "#define MAX(x,y) (((x)>(y))?(x):(y))" );
882 (void) fprintf(STDOUT, " %31s /* regardless of the type */\n", " " );
883 (void) fprintf(STDOUT, "#define CLIP(x,l,h) (((x)<(l))?(l):(((x)>(h))?(h):(x)))" );
884 (void) fprintf(STDOUT, " %15s /* regardless of the type */\n", " " );
885 (void) fprintf(STDOUT, "\n#define ABS(x) ((0.0<(x))?(x):-(x))" );
886 (void) fprintf(STDOUT, " %30s /* regardless of the type */\n", " " );
887 (void) fprintf(STDOUT, "#define SIGN(x) ((EPSILON<(x))-(-EPSILON>(x))) " );
888 (void) fprintf(STDOUT, " /* returns -1, 0 or 1 */\n" );
889 (void) fprintf(STDOUT, "\n#define ISSMALL(x) (EPSILON>=ABS(x)) " );
890 (void) fprintf(STDOUT, " /* to be used in replacement of ( 0.0 == x ) */\n" );
891 (void) fprintf(STDOUT, "#define ISNOTSMALL(x) (EPSILON< ABS(x)) " );
892 (void) fprintf(STDOUT, " /* to be used in replacement of ( 0.0 != x ) */\n" );
893 (void) fprintf(STDOUT, "\n#define ISINTEGER(x) (((I_TYPE)(x))==(x)) " );
894 (void) fprintf(STDOUT, " /* check the value, regardless of the type */\n" );
895 (void) fprintf(STDOUT, "#define ISNAN(x) ((x)!=(x)) " );
896 (void) fprintf(STDOUT, " /* check if the value is NaN */\n" );
897 (void) fprintf(STDOUT, "\n#define ISEVEN(x) (0LL==(D2I(x)%%2LL)) " );
898 (void) fprintf(STDOUT, " /* check the value, regardless of the type */\n");
899 (void) fprintf(STDOUT, "#define ISODD(x) (0LL!=(D2I(x)%%2LL)) " );
900 (void) fprintf(STDOUT, " /* check the value, regardless of the type */\n");
901 (void) fprintf(STDOUT, "\n#define ISEQUAL(x,y) (ABS((x)-(y))<=(EPSILON*(ABS(x)+ABS(y))))");
902 (void) fprintf(STDOUT, " /* to be used in replacement of ( x == y ) */\n" );
903 (void) fprintf(STDOUT, "#define ISNOTEQUAL(x,y) (ABS((x)-(y))> (EPSILON*(ABS(x)+ABS(y))))");
904 (void) fprintf(STDOUT, " /* to be used in replacement of ( x != y ) */\n" );
905 (void) fprintf(STDOUT, "\n#define ISINSIDE(x,l,h) (((x)>=(l))&&((x)<=(h))) " );
906 (void) fprintf(STDOUT, " /* inside the interval [l,h] */\n" );
907 (void) fprintf(STDOUT, "#define ISOUTSIDE(x,l,h) (((x)< (l))||((x)> (h))) " );
908 (void) fprintf(STDOUT, " /* outside the interval ]l,h[ */\n" );
909 (void) fprintf(STDOUT, "#define ISTIME(t) (((FSL*((t)-TIME))<0.5)&&((FSL*(TIME-(t)))<=0.5))");
910 (void) fprintf(STDOUT, " /* time inside the local sampling interval */\n" );
911 (void) fprintf(STDOUT, "\n#define MODULO(x,y) ((x)-((y)*floor(((R_TYPE)(x))/((R_TYPE)(y)))))" );
912 (void) fprintf(STDOUT, " /* regardless of the type */\n" );
913 (void) fprintf(STDOUT, "\n#define SIN(x) ((R_TYPE)sinl((H_PREC)(x))) " );
914 (void) fprintf(STDOUT, " /* keep the best precision when x is large */\n" );
915 (void) fprintf(STDOUT, "#define COS(x) ((R_TYPE)cosl((H_PREC)(x))) " );
916 (void) fprintf(STDOUT, " /* keep the best precision when x is large */\n" );
917 (void) fprintf(STDOUT, "#define SQR(x) ((x)*(x)) " );
918 (void) fprintf(STDOUT, " /* regardless of the type */\n" );
919 (void) fprintf(STDOUT, "#define SQRT(x) sqrt(MAX(0.0,(x))) " );
920 (void) fprintf(STDOUT, " /* avoiding negative values */\n" );
921 (void) fprintf(STDOUT, "#define LOG(x) log(MAX(EPSILON,(x))) " );
922 (void) fprintf(STDOUT, " /* avoiding values below or equal to zero */\n" );
923 (void) fprintf(STDOUT, "#define POW(x,y) pow(MAX(0.0,(x)),(y)) " );
924 (void) fprintf(STDOUT, " /* avoiding negative values */\n" );
925 (void) fprintf(STDOUT, "#define ROOT(x,y) POW((x),1.0/((R_TYPE)(y))) " );
926 (void) fprintf(STDOUT, " /* avoiding negative values */\n" );
927 (void) fprintf(STDOUT, "#define LOG10(x) log10(MAX(EPSILON,(x))) " );
928 (void) fprintf(STDOUT, " /* avoiding values below or equal to zero */\n" );
929 (void) fprintf(STDOUT, "#define POW10(y) pow(10.0,(y))\n" );
930 (void) fprintf(STDOUT, "\n#define POWEROF2(n) ((0LL<((I_TYPE)(n)))?(1LL<<((I_TYPE)(n))):1LL)");
931 (void) fprintf(STDOUT, " /* valid only for positive integers */\n" );
932 (void) fprintf(STDOUT, "\n#define I2D(n) ((R_TYPE)(n))" );
933 (void) fprintf(STDOUT, " %*s /* convert integer to real */\n", 37, " " );
934 (void) fprintf(STDOUT, "#define D2I(x) ((0.0<(x))?((I_TYPE)((x)+0.5)):((I_TYPE)((x)-0.5)))");
935 (void) fprintf(STDOUT, " /* convert real to nearest integer */\n" );
936 (void) fprintf(STDOUT, "\n#define DB2LIN(x,r) ((r)*POW10(0.05*(x)))" );
937 (void) fprintf(STDOUT, " %*s /* convert dB to linear */\n", 29, " " );
938 (void) fprintf(STDOUT, "#define LIN2DB(x,r) (20.0*LOG10(((R_TYPE)(x))/((R_TYPE)(r))))");
939 (void) fprintf(STDOUT, " %*s /* convert linear to dB */\n", 9, " " );
940 (void) fprintf(STDOUT, "#define DB2POW(x,r) ((r)*POW10(0.10*(x)))" );
941 (void) fprintf(STDOUT, " %*s /* convert dB to power */\n", 29, " " );
942 (void) fprintf(STDOUT, "#define POW2DB(x,r) (10.0*LOG10(((R_TYPE)(x))/((R_TYPE)(r))))");
943 (void) fprintf(STDOUT, " %*s /* convert power to dB */\n", 9, " " );
944 (void) fprintf(STDOUT, "#define RAD2DEG(x) (%19.16Lf*((R_TYPE)(x)))", _R2D_ );
945 (void) fprintf(STDOUT, " %*s /* convert radian to degree */\n", 15, " " );
946 (void) fprintf(STDOUT, "#define DEG2RAD(x) (%21.20Lf*((R_TYPE)(x)))", _D2R_ );
947 (void) fprintf(STDOUT, " %*s /* convert degree to radian */\n", 12, " " );
948 (void) fprintf(STDOUT, "\n#define B2A(b) ((b)?\"true\":\"false\")" );
949 (void) fprintf(STDOUT, " %*s /* convert boolean to string %*s */\n", 30, " ", 15, " " );
950 (void) fprintf(STDOUT, "#define LENGTH(s) ((I_TYPE)strlen(s))" );
951 (void) fprintf(STDOUT, " %*s /* length of a string */\n", 31, " " );
952 (void) fprintf(STDOUT, "\n#define LINDOMAIN(c,b,e) ((b)+((c)*((e)-(b)))) ");
953 (void) fprintf(STDOUT, " /* linear rule of thumb */\n" );
954 (void) fprintf(STDOUT, "#define LOGDOMAIN(c,b,e) ((b)*POW10((c)*LOG10(((R_TYPE)(e))/((R_TYPE)(b))))) ");
955 (void) fprintf(STDOUT, " /* logarithmic rule of thumb */\n" );
956 (void) fprintf(STDOUT, "#define LINSWEEP(c,b,e,n) LINDOMAIN((((R_TYPE)(c))/((R_TYPE)((n)-1L))),(b),(e)) ");
957 (void) fprintf(STDOUT, " /* linearly spaced */\n" );
958 (void) fprintf(STDOUT, "#define LOGSWEEP(c,b,e,n) LOGDOMAIN((((R_TYPE)(c))/((R_TYPE)((n)-1L))),(b),(e)) ");
959 (void) fprintf(STDOUT, " /* logarithmically spaced */\n\n" );
960 if (!Antithetic_Flag) {
961 (void) fprintf(STDOUT, "#define RAND_01() (1.11022302462515666e-16* ((R_TYPE)(napa_rand()>>10)) )");
962 (void) fprintf(STDOUT, " /* number in interval [0,1] */\n" );
963 (void) fprintf(STDOUT, "#define RAND_01_X() (2.22044604925031332e-16*(((R_TYPE)(napa_rand()>>11))+0.5))");
964 (void) fprintf(STDOUT, " /* number in interval ]0,1[ */\n\n" );
965 } else {
966 (void) fprintf(STDOUT, "#define RAND_01() (1.0-(1.11022302462515666e-16*( (R_TYPE)(napa_rand()>>10)))) ");
967 (void) fprintf(STDOUT, " /* number in interval [0,1] */\n" );
968 (void) fprintf(STDOUT, "#define RAND_01_X() (1.0-(2.22044604925031332e-16*(((R_TYPE)(napa_rand()>>11))+0.5)))");
969 (void) fprintf(STDOUT, " /* number in interval ]0,1[ */\n\n" );
970 }
971 if (Periodic_Flag) {
972 if (10L < Num_Segments) {
973 (void) fprintf(STDOUT, "#define FSS(s) ((R_TYPE)napa_fsl[s])");
974 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%2ld */\n", 44, " ", Num_Segments-1L);
975 (void) fprintf(STDOUT, "#define STS(s) (napa_stl[s])" );
976 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%2ld */\n", 52, " ", Num_Segments-1L);
977 } else if (1L < Num_Segments) {
978 (void) fprintf(STDOUT, "#define FSS(s) ((R_TYPE)napa_fsl[s])");
979 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%ld */\n", 44, " ", Num_Segments-1L);
980 (void) fprintf(STDOUT, "#define STS(s) (napa_stl[s])" );
981 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%ld */\n", 52, " ", Num_Segments-1L);
982 } else {
983 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
984 (void) fprintf(STDOUT, "#define FSS(s) ((R_TYPE)napa_fs_ext)" );
985 (void) fprintf(STDOUT, " %s /* constant */\n", multiple(' ', 96L-n) );
986 } else {
987 n = fprintf(STDOUT, "#define FSS(s) %.15e", Sampling_List.frequency);
988 (void) fprintf(STDOUT, " %s /* constant */\n", multiple(' ', 96L-n) );
989 }
990 (void) fprintf(STDOUT, "#define STS(s) 0LL" );
991 (void) fprintf(STDOUT, " %62s /* constant */\n", " ");
992 }
993 } else {
994 (void) fprintf(STDOUT, "#define FSS(s) 0.0" );
995 (void) fprintf(STDOUT, " %62s /* constant */\n", " ");
996 (void) fprintf(STDOUT, "#define STS(s) 0LL\n" );
997 (void) fprintf(STDOUT, " %62s /* constant */\n", " ");
998 }
999 if (10L < Num_Segments) {
1000 (void) fprintf(STDOUT, "#define PS(s) (napa_per[s])" );
1001 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%2ld */\n", 52, " ", Num_Segments-1L);
1002 } else if (1L < Num_Segments) {
1003 (void) fprintf(STDOUT, "#define PS(s) (napa_per[s])" );
1004 (void) fprintf(STDOUT, " %*s /* applied to segment 0..%ld */\n", 52, " ", Num_Segments-1L);
1005 } else {
1006 (void) fprintf(STDOUT, "#define PS(s) true" );
1007 (void) fprintf(STDOUT, " %61s /* constant */\n", " ");
1008 }
1009 if (Ping_Flag) { /* determine max length of functions ID strings */
1010 n = 0L; /* only to have a nice formatting */
1011 for (i = 0L; i < Num_Functions; i++) {
1012 if (0L >= Function_List[i].number) { /* not a tool or user node */
1013 continue;
1014 }
1015 if (0 == strcmp(Function_List[i].table, "post_void")) { /* instruction 'void' */
1016 continue;
1017 }
1018 n = MAX(LENGTH(Function_List[i].table), n); /* record max length of function ID */
1019 }
1020 for (i = 0L; i < Num_Functions; i++) {
1021 if (0L < Function_List[i].number) { /* not a function */
1022 continue;
1023 }
1024 if (0 == strcmp(Function_List[i].table, "post_void")) { /* instruction 'void' */
1025 continue;
1026 }
1027 n = MAX(LENGTH(Function_List[i].table), n); /* record max length of function ID */
1028 }
1029 for (i = 0L; i < Num_Directives; i++) {
1030 if (Directive_List[i].function) { /* a macro function is defined in a directive */
1031 Num_Macros++; /* count number of macro functions */
1032 n = MAX(n, LENGTH(Directive_List[i].name) + 2L); /* record max length of macro ID, including () */
1033 continue;
1034 }
1035 }
1036 if (0L >= n) {
1037 Ping_Flag = false; /* nothing to ping! */
1038 }
1039 }
1040 (void) fprintf(STDOUT, "\n#define TIMER(n) napa_timer(n)" );
1041 (void) fprintf(STDOUT, " %52s /* pause for n seconds */\n", " ");
1042 if (Ping_Flag) {
1043 if (0 == strcmp(Ping_List.fname, "stderr")) {
1044 (void) fprintf(STDOUT, "\n#define PING(fun) \\\n" );
1045 (void) fprintf(STDOUT, " void napa_ping_ ## fun(void); \\\n" );
1046 (void) fprintf(STDOUT, " void napa_ping_ ## fun(void) { \\\n" );
1047 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"NAPA Ping Information : \" ); \\\n" );
1048 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"function '%%-%lds\", #fun \"()' \" ); \\\n", 5L+n);
1049 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"from file \\\"%%s\\\"\\n\", __FILE__ ); \\\n" );
1050 (void) fprintf(STDOUT, " return; \\\n" );
1051 (void) fprintf(STDOUT, " }\n");
1052 (void) fprintf(STDOUT, "#define PING_FAIL(fun) %44s \\\n", " ");
1053 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"NAPA Ping Information : \" ); \\\n" );
1054 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"function '%%-%lds\", #fun \"()' \" ); \\\n", 5L+n);
1055 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"exists but cannot be located\\n\");\n" );
1056 } else {
1057 (void) fprintf(STDOUT, "\n#define PING(fun) \\\n");
1058 (void) fprintf(STDOUT, " void napa_ping_ ## fun(void); \\\n");
1059 (void) fprintf(STDOUT, " void napa_ping_ ## fun(void) { \\\n");
1060 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" function '%%-%lds\", #fun \"()'\"); \\\n", 5L+n);
1061 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \"from file \\\"%%s\\\"\\n\", __FILE__ ); \\\n" );
1062 (void) fprintf(STDOUT, " return; \\\n");
1063 (void) fprintf(STDOUT, " }\n");
1064 (void) fprintf(STDOUT, "#define PING_FAIL(fun) %47s \\\n", " ");
1065 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" function '%%-%lds\", #fun \"()'\"); \\\n", 5L+n);
1066 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \"exists but cannot be located\\n\" );\n" );
1067 }
1068 } else {
1069 (void) fprintf(STDOUT, "\n#define PING(fun) %78s /* empty function */\n", " " );
1070 }
1071 (void) fprintf(STDOUT, "\n\n/* *** MACRO FUNCTIONS TO BE USED IN USER, TOOL AND POST FUNCTIONS %s */\n", multiple('*', 60L));
1072 (void) fprintf(STDOUT, "\n#define IO_COMMAND_NAME(c) (napa_IO_cmd[c])");
1073 (void) fprintf(STDOUT, " %49s /* list defined below */\n", " " );
1074 (void) fprintf(STDOUT, "#define IO_MANAGER(c,f,n,s,t) napa_IO_manager(c,f,n,s,t)");
1075 (void) fprintf(STDOUT, " %39s /* function defined below */\n", " " );
1076 if ((UserTool_Flag) || (Post_Flag)) {
1077 (void) fprintf(STDOUT, "\n#define ISOPTION(f,i,o) (0.0<(*napa_check_for_option(f,i,o,1)))");
1078 (void) fprintf(STDOUT, " %26s /* for user, tool, post */\n", " " );
1079 if (User_Flag) {
1080 (void) fprintf(STDOUT, "#define ISNOTOPTION(f,i) (ISOPTION(f,i,\"_another_\")" );
1081 (void) fprintf(STDOUT, "&&(!ISOPTION(f,i,\"delayed_node\")))" );
1082 (void) fprintf(STDOUT, " /* for user, tool, post */\n" );
1083 } else {
1084 (void) fprintf(STDOUT, "#define ISNOTOPTION(f,i) (ISOPTION(f,i,\"_another_\"))");
1085 (void) fprintf(STDOUT, " %38s /* for user, tool, post */\n", " " );
1086 }
1087 (void) fprintf(STDOUT, "#define ISPARAMETER(f,i,o) (((double*)NULL)!=napa_check_for_option(f,i,o,0))");
1088 (void) fprintf(STDOUT, " %16s /* for user, tool, post */\n", " " );
1089 (void) fprintf(STDOUT, "#define GETPARMADDRESS(f,i,o) napa_check_for_option(f,i,o,0)" );
1090 (void) fprintf(STDOUT, " %35s /* for user, tool, post */\n", " " );
1091 if (User_Flag) {
1092 (void) fprintf(STDOUT, "#define ISDELAYED(f,i) (ISOPTION(f,i,\"delayed_node\"))");
1093 (void) fprintf(STDOUT, " %35s /* for user functions only */\n", " " );
1094 }
1095 }
1096 (void) fprintf(STDOUT, "\n\n/* *** SUGGESTION: USE THESE NAPA DIRECTIVES IN THE NAPA NETLIST");
1097 (void) fprintf(STDOUT, " TO CONFIGURE FURTHER THIS SIMULATION %s */\n\n", multiple('*', 24L));
1098 flag = false;
1099 if (UNDEFINED == directive_id("TIME_OFFSET")) {
1100 (void) fprintf(STDOUT, "/* directive TIME_OFFSET <H_PREC Number> %79s */\n", " ");
1101 flag = true;
1102 }
1103 if (UNDEFINED == directive_id("JITTER")) {
1104 (void) fprintf(STDOUT, "/* directive JITTER <H_PREC Formula> %79s */\n", " ");
1105 flag = true;
1106 }
1107 if ((Output_Flag) || (Dump_Flag)) {
1108 if (UNDEFINED == directive_id("STRICTLY_NO_BANNER")) {
1109 (void) fprintf(STDOUT, "/* directive STRICTLY_NO_BANNER %94s */\n", " ");
1110 flag = true;
1111 }
1112 }
1113 if (Output_Flag) {
1114 if ((UNDEFINED == directive_id("STRICTLY_NO_BANNER")) && (UNDEFINED == directive_id("NO_BANNER"))) {
1115 (void) fprintf(STDOUT, "/* directive NO_BANNER %98s */\n", " ");
1116 flag = true;
1117 }
1118 if (UNDEFINED == directive_id("NO_TIME_OUTPUT")) {
1119 (void) fprintf(STDOUT, "/* directive NO_TIME_OUTPUT %98s */\n", " ");
1120 flag = true;
1121 }
1122 }
1123 if (Assert_Flag) {
1124 if (UNDEFINED == directive_id("NO_ASSERT")) {
1125 (void) fprintf(STDOUT, "/* directive NO_ASSERT %98s */\n", " ");
1126 flag = true;
1127 }
1128 }
1129 if (UNDEFINED == directive_id("EXTERNAL_PSEUDO_RANDOM_NUMBER_GENERATOR")) {
1130 (void) fprintf(STDOUT, "/* directive EXTERNAL_PSEUDO_RANDOM_NUMBER_GENERATOR <File Pathname> %50s */\n", " ");
1131 flag = true;
1132 }
1133 if (UNDEFINED == directive_id("NAPA_EXIT_STATUS")) {
1134 (void) fprintf(STDOUT, "/* directive NAPA_EXIT_STATUS %96s */\n", " ");
1135 flag = true;
1136 }
1137#if YES == COMPILE_LOOP_OPTION /* defined in "napa.h", default: NO (recommended) */
1138 if (UNDEFINED == directive_id("NAPA_LOOP_OPTION")) {
1139 (void) fprintf(STDOUT, "/* directive NAPA_LOOP_OPTION <YES|NO> %86s */\n", " ");
1140 flag = true;
1141 }
1142#endif
1143 if (flag) {
1144 (void) fprintf(STDOUT, "\n");
1145 }
1146 flag = false;
1147 if (Dump_Flag) {
1148 if (UNDEFINED == debug_id("DUMP")) {
1149 (void) fprintf(STDOUT, "/* debug DUMP %108s */\n", " ");
1150 flag = true;
1151 }
1152 }
1153 if (UNDEFINED == debug_id("IO")) {
1154 (void) fprintf(STDOUT, "/* debug IO %102s */\n", " ");
1155 flag = true;
1156 }
1157 if (flag) {
1158 (void) fprintf(STDOUT, "\n");
1159 }
1160 if (UNDEFINED == directive_id("ALL_DEBUG")) {
1161 (void) fprintf(STDOUT, "/* directive ALL_DEBUG %102s */\n", " ");
1162 flag = true;
1163 }
1164 if (UNDEFINED == directive_id("VERBOSE")) {
1165 (void) fprintf(STDOUT, "/* directive VERBOSE %105s */\n\n", " ");
1166 }
1167 (void) fprintf(STDOUT, "/* [ The header files of the library may also be configured with specific directives,");
1168 (void) fprintf(STDOUT, " please consult related documentation ] */\n\n");
1169 flag = false;
1170 if (UNDEFINED != directive_id("TIME_OFFSET")) {
1171 (void) fprintf(STDOUT, "#define TIME_OFFSET_IS_REGISTERED\n");
1172 flag = true;
1173 }
1174 if (UNDEFINED != directive_id("ALL_DEBUG")) {
1175 (void) fprintf(STDOUT, "#define ALL_DEBUG_IS_REGISTERED\n" );
1176 flag = true;
1177 }
1178 if (UNDEFINED != directive_id("JITTER")) {
1179 (void) fprintf(STDOUT, "#define JITTER_IS_REGISTERED\n" );
1180 flag = true;
1181 }
1182 if ((Output_Flag) || (Dump_Flag)) {
1183 if (UNDEFINED != directive_id("STRICTLY_NO_BANNER")) {
1184 (void) fprintf(STDOUT, "#define STRICTLY_NO_BANNER_IS_REGISTERED\n");
1185 flag = true;
1186 }
1187 }
1188 if (Output_Flag) {
1189 if (UNDEFINED != directive_id("NO_BANNER")) {
1190 (void) fprintf(STDOUT, "#define NO_BANNER_IS_REGISTERED\n" );
1191 flag = true;
1192 }
1193 if (UNDEFINED != directive_id("NO_TIME_OUTPUT")) {
1194 (void) fprintf(STDOUT, "#define NO_TIME_OUTPUT_IS_REGISTERED\n");
1195 flag = true;
1196 }
1197 }
1198 if (Assert_Flag) {
1199 if (UNDEFINED != directive_id("NO_ASSERT")) {
1200 (void) fprintf(STDOUT, "#define NO_ASSERT_IS_REGISTERED\n" );
1201 flag = true;
1202 }
1203 }
1204 if (UNDEFINED != directive_id("EXTERNAL_PSEUDO_RANDOM_NUMBER_GENERATOR")) {
1205 (void) fprintf(STDOUT, "#define EXTERNAL_PSEUDO_RANDOM_NUMBER_GENERATOR_IS_REGISTERED\n");
1206 flag = true;
1207 }
1208 if (UNDEFINED != directive_id("NAPA_EXIT_STATUS")) {
1209 (void) fprintf(STDOUT, "#define NAPA_EXIT_STATUS_IS_REGISTERED\n");
1210 flag = true;
1211 }
1212
1213#if YES == COMPILE_LOOP_OPTION /* defined in "napa.h", default: NO (recommended) */
1214 if (UNDEFINED != directive_id("NAPA_LOOP_OPTION")) {
1215 (void) fprintf(STDOUT, "#define NAPA_LOOP_OPTION_IS_REGISTERED\n");
1216 flag = true;
1217 }
1218#endif
1219 if (flag) {
1220 (void) fprintf(STDOUT, "\n");
1221 }
1222 flag = false;
1223 if (Dump_Flag) {
1224 if (UNDEFINED != debug_id("DUMP")) {
1225 (void) fprintf(STDOUT, "#define DEBUG_MODE_DUMP_IS_REGISTERED\n" );
1226 flag = true;
1227 }
1228 }
1229 if (UNDEFINED != debug_id("IO")) {
1230 (void) fprintf(STDOUT, "#define DEBUG_MODE_IO_IS_REGISTERED\n" );
1231 flag = true;
1232 }
1233 if (flag) {
1234 (void) fprintf(STDOUT, "\n");
1235 }
1236 if (UNDEFINED != directive_id("VERBOSE")) {
1237 (void) fprintf(STDOUT, "#define VERBOSE_IS_REGISTERED\n\n" );
1238 }
1239 return;
1240}
1241
1242
1244 char tok[STRLENGTH] = {'\0'};
1245 char *str = (char*) NULL;
1246 str = Terminate_List.condition;
1247 (void) fprintf(STDOUT, "( " );
1248 for (;;) {
1249 str = get_token(str, tok, true);
1250 if (ISEMPTY(tok)) {
1251 (void) fprintf(STDOUT, " )\n");
1252 break;
1253 }
1254 (void) build_name("", tok, RIGHT_VALUE);
1255 (void) fprintf(STDOUT, "%s", tok);
1256 }
1257 return;
1258}
1259
1260
1262 long double cst;
1263 double rate1, rate2;
1264 double factor;
1265 int len;
1266 long i, arr, seg;
1267 long kd, tp;
1268 int d_ram1_flag, i_ram1_flag;
1269 int d_ram2_flag, i_ram2_flag;
1270 int d_rom1_flag, i_rom1_flag;
1271 int d_rom2_flag, i_rom2_flag;
1272 char spc[2];
1273 (void) fprintf(STDOUT, "\n/* *** DECLARE NAPA TYPES %s */\n\n", multiple('*', 101L));
1274 (void) fprintf(STDOUT, "typedef %11s I_TYPE;\n", "long long" ); /* NAPA digital type */
1275 (void) fprintf(STDOUT, "typedef %11s R_TYPE;\n", "double" ); /* NAPA analog type */
1276 (void) fprintf(STDOUT, "typedef %11s C_TYPE;\n", "char" ); /* NAPA char type */
1277 (void) fprintf(STDOUT, "typedef %11s P_TYPE;\n", "long" ); /* NAPA iterator type */
1278 if (Export_Flag) {
1279 if (0 == strcmp(V_Format, I_FORMAT_V)) {
1280 (void) fprintf(STDOUT, "typedef %11s V_TYPE;\n", "long long" ); /* NAPA export type is digital */
1281 }
1282 if (0 == strcmp(V_Format, R_FORMAT_V)) {
1283 (void) fprintf(STDOUT, "typedef %11s V_TYPE;\n", "double" ); /* NAPA export type is analog */
1284 }
1285 }
1286 (void) fprintf(STDOUT, "\ntypedef %11s L_PREC;\n", "float" );
1287 (void) fprintf(STDOUT, "typedef %11s H_PREC;\n", "long double" ); /* Use to compute the NAPA simulation time */
1288 (void) fprintf(STDOUT, "\n#define _IO_LST_ \\\n"); /* A smart way to define an enumeration */
1289 (void) fprintf(STDOUT, " _IO_( UNKNOWN ) \\\n");
1290 (void) fprintf(STDOUT, " _IO_( CLOSE ) \\\n");
1291 (void) fprintf(STDOUT, " _IO_( OPENREAD ) \\\n");
1292 (void) fprintf(STDOUT, " _IO_( OPENREAD_BINARY ) \\\n");
1293 (void) fprintf(STDOUT, " _IO_( OPENWRITE ) \\\n");
1294 (void) fprintf(STDOUT, " _IO_( OPENWRITE_BINARY ) \\\n");
1295 (void) fprintf(STDOUT, " _IO_( OPENAPPEND ) \\\n");
1296 (void) fprintf(STDOUT, " _IO_( OPENAPPEND_BINARY ) \\\n");
1297 (void) fprintf(STDOUT, " _IO_( QUERY ) \\\n");
1298 (void) fprintf(STDOUT, " _IO_( REWIND ) \\\n");
1299 (void) fprintf(STDOUT, " _IO_( REWRITE ) \\\n");
1300 (void) fprintf(STDOUT, " _IO_( ALLOCATE ) \\\n");
1301 (void) fprintf(STDOUT, " _IO_( FREE ) \\\n");
1302 (void) fprintf(STDOUT, " _IO_( DELETE ) \\\n");
1303 (void) fprintf(STDOUT, " _IO_( RESET ) \\\n");
1304 (void) fprintf(STDOUT, " _IO_( DEBUG )\n" );
1305 (void) fprintf(STDOUT, "#define _IO_(x) x,\n");
1306 (void) fprintf(STDOUT, "typedef enum { _IO_LST_ } IO_COMMAND;");
1307 (void) fprintf(STDOUT, " %*s /* enumeration of the NAPA I/O commands %*s */\n\n", 43, " ", 4, " ");
1308 (void) fprintf(STDOUT, "#undef _IO_\n" );
1309 (void) fprintf(STDOUT, "#define _IO_(x) #x,\n" );
1310 (void) fprintf(STDOUT, "const char* const napa_IO_cmd[16] = { _IO_LST_ };");
1311 (void) fprintf(STDOUT, " %*s /* strings corresponding to the I/O commands */\n\n", 30, " ");
1312 (void) fprintf(STDOUT, "#undef _IO_\n" );
1313 (void) fprintf(STDOUT, "#undef _IO_LST_\n\n" );
1314 (void) fprintf(STDOUT, "typedef struct {\n" ); /* record structure for array of pointers */
1315 (void) fprintf(STDOUT, " C_TYPE name[512];\n"); /* name of array as defined in NAPA netlist */
1316 (void) fprintf(STDOUT, " C_TYPE **s_ptr;\n" ); /* name of parameters as defined in NAPA netlist */
1317 (void) fprintf(STDOUT, " C_TYPE **n_ptr;\n" ); /* name of target for passing parameters by name */
1318 (void) fprintf(STDOUT, " I_TYPE **i_ptr;\n" ); /* must be included with or without */
1319 (void) fprintf(STDOUT, " R_TYPE **d_ptr;\n" ); /* effective call of this function */
1320 (void) fprintf(STDOUT, " C_TYPE **c_ptr;\n" ); /* as user defined function may used this structure */
1321 (void) fprintf(STDOUT, " int nflag;\n" ); /* passing parameters by name */
1322 (void) fprintf(STDOUT, " int pflag;\n" ); /* passing parameters by position */
1323 (void) fprintf(STDOUT, " long length;\n" );
1324 (void) fprintf(STDOUT, " long nrow;\n" );
1325 (void) fprintf(STDOUT, " long ncol;\n" );
1326 (void) fprintf(STDOUT, "} DATA_RECORD;\n\n" );
1327 d_ram1_flag = false;
1328 i_ram1_flag = false;
1329 d_ram2_flag = false;
1330 i_ram2_flag = false;
1331 d_rom1_flag = false;
1332 i_rom1_flag = false;
1333 d_rom2_flag = false;
1334 i_rom2_flag = false;
1335 for (arr = 0L; arr < Num_Arrays; arr++) {
1336 if (!Array_List[arr].used) {
1337 continue;
1338 }
1339 kd = Array_List[arr].kind;
1340 tp = Array_List[arr].type;
1341 switch (kd) {
1342 case RAM_KIND:
1343 if (ANALOG_DATA_TYPE == tp) {
1344 d_ram1_flag = true;
1345 } else {
1346 i_ram1_flag = true;
1347 }
1348 break;
1349 case RAM2_KIND:
1350 if (ANALOG_DATA_TYPE == tp) {
1351 d_ram2_flag = true;
1352 } else {
1353 i_ram2_flag = true;
1354 }
1355 break;
1356 case ROM_KIND:
1357 if (ANALOG_DATA_TYPE == tp) {
1358 d_rom1_flag = true;
1359 } else {
1360 i_rom1_flag = true;
1361 }
1362 break;
1363 case ROM2_KIND:
1364 if (ANALOG_DATA_TYPE == tp) {
1365 d_rom2_flag = true;
1366 } else {
1367 i_rom2_flag = true;
1368 }
1369 break;
1370 default:
1371 break;
1372 }
1373 }
1374 if (d_ram1_flag) {
1375 (void) fprintf(STDOUT, "typedef struct {\n" );
1376 (void) fprintf(STDOUT, " R_TYPE *data;\n" );
1377 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1378 (void) fprintf(STDOUT, " H_PREC last;\n" );
1379 (void) fprintf(STDOUT, " int *flag;\n" );
1380 (void) fprintf(STDOUT, "} RAM_R_RECORD;\n\n" );
1381 }
1382 if (i_ram1_flag) {
1383 (void) fprintf(STDOUT, "typedef struct {\n" );
1384 (void) fprintf(STDOUT, " I_TYPE *data;\n" );
1385 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1386 (void) fprintf(STDOUT, " H_PREC last;\n" );
1387 (void) fprintf(STDOUT, " int *flag;\n" );
1388 (void) fprintf(STDOUT, "} RAM_I_RECORD;\n\n" );
1389 }
1390 if (d_ram2_flag) {
1391 (void) fprintf(STDOUT, "typedef struct {\n" );
1392 (void) fprintf(STDOUT, " R_TYPE *data;\n" );
1393 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1394 (void) fprintf(STDOUT, " I_TYPE address;\n");
1395 (void) fprintf(STDOUT, " I_TYPE rw;\n" );
1396 (void) fprintf(STDOUT, " H_PREC last;\n" );
1397 (void) fprintf(STDOUT, " int *flag;\n" );
1398 (void) fprintf(STDOUT, "} RAM2_R_RECORD;\n\n" );
1399 }
1400 if (i_ram2_flag) {
1401 (void) fprintf(STDOUT, "typedef struct {\n" );
1402 (void) fprintf(STDOUT, " I_TYPE *data;\n" );
1403 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1404 (void) fprintf(STDOUT, " I_TYPE address;\n");
1405 (void) fprintf(STDOUT, " I_TYPE rw;\n" );
1406 (void) fprintf(STDOUT, " H_PREC last;\n" );
1407 (void) fprintf(STDOUT, " int *flag;\n" );
1408 (void) fprintf(STDOUT, "} RAM2_I_RECORD;\n\n" );
1409 }
1410 if (d_rom1_flag) {
1411 (void) fprintf(STDOUT, "typedef struct {\n" );
1412 (void) fprintf(STDOUT, " R_TYPE *data;\n" );
1413 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1414 (void) fprintf(STDOUT, "} ROM_R_RECORD;\n\n" );
1415 }
1416 if (i_rom1_flag) {
1417 (void) fprintf(STDOUT, "typedef struct {\n" );
1418 (void) fprintf(STDOUT, " I_TYPE *data;\n" );
1419 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1420 (void) fprintf(STDOUT, "} ROM_I_RECORD;\n\n" );
1421 }
1422 if (d_rom2_flag) {
1423 (void) fprintf(STDOUT, "typedef struct {\n" );
1424 (void) fprintf(STDOUT, " R_TYPE *data;\n" );
1425 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1426 (void) fprintf(STDOUT, " I_TYPE address;\n");
1427 (void) fprintf(STDOUT, "} ROM2_R_RECORD;\n\n" );
1428 }
1429 if (i_rom2_flag) {
1430 (void) fprintf(STDOUT, "typedef struct {\n" );
1431 (void) fprintf(STDOUT, " I_TYPE *data;\n" );
1432 (void) fprintf(STDOUT, " I_TYPE length;\n" );
1433 (void) fprintf(STDOUT, " I_TYPE address;\n");
1434 (void) fprintf(STDOUT, "} ROM2_I_RECORD;\n\n" );
1435 }
1436 (void) fprintf(STDOUT, "typedef struct {\n" ); /* record for IO resources manager */
1437 (void) fprintf(STDOUT, " FILE *f_ptr;\n" );
1438 (void) fprintf(STDOUT, " C_TYPE *user;\n" );
1439 (void) fprintf(STDOUT, " long id;\n" );
1440 (void) fprintf(STDOUT, " IO_COMMAND mode;\n" );
1441 (void) fprintf(STDOUT, " int iflag;\n" );
1442 (void) fprintf(STDOUT, " int oflag;\n" );
1443 (void) fprintf(STDOUT, "} IO_RECORD;\n");
1444 if (0L < Num_Tools) {
1445 (void) fprintf(STDOUT, "\ntypedef struct {\n"); /* record for mailbox */
1446 (void) fprintf(STDOUT, " long *store_i; %*s /* managed by user */\n", 74, " ");
1447 (void) fprintf(STDOUT, " I_TYPE *store_l; %*s /* managed by user */\n", 74, " ");
1448 (void) fprintf(STDOUT, " R_TYPE *store_d; %*s /* managed by user */\n", 74, " ");
1449 (void) fprintf(STDOUT, " C_TYPE **store_s; %*s /* managed by user */\n", 74, " ");
1450 (void) fprintf(STDOUT, " I_TYPE n; %*s /* managed by user */\n", 74, " ");
1451 (void) fprintf(STDOUT, " I_TYPE i; %*s /* message input */\n", 74, " ");
1452 (void) fprintf(STDOUT, " I_TYPE o; %*s /* message output */\n", 74, " ");
1453 (void) fprintf(STDOUT, " long m; %*s /* mailbox ID */\n", 74, " ");
1454 (void) fprintf(STDOUT, " long s; %*s /* segment ID */\n", 74, " ");
1455 (void) fprintf(STDOUT, " char t[64]; %*s /* tool name */\n", 74, " ");
1456 (void) fprintf(STDOUT, " char u[%ld]; %*s /* node name */\n", STRLENGTH, 73, " ");
1457 (void) fprintf(STDOUT, "} MAILBOX_RECORD;\n");
1458 }
1459
1460 /* from http://www.raspberryginger.com/jbailey/minix/html/pc__math_8h-source.html */
1461 /* PI 3.14159265358979323846264338327950288 */
1462 /* 2PI 6.28318530717958647692528676655900576 */
1463 /* 3PI_4 2.35619449019234492884698253745962716 */
1464 /* PI_2 1.57079632679489661923132169163975144 */
1465 /* 3PI_8 1.17809724509617246442349126872981358 */
1466 /* PI_4 0.78539816339744830961566084581987572 */
1467 /* PI_8 0.39269908169872415480783042290993786 */
1468 /* 1_PI 0.31830988618379067153776752674502872 */
1469 /* 2_PI 0.63661977236758134307553505349005744 */
1470 /* 4_PI 1.27323954473516268615107010698011488 */
1471 /* E 2.71828182845904523536028747135266250 */
1472 /* LOG2E 1.44269504088896340735992468100189213 */
1473 /* LOG10E 0.43429448190325182765112891891660508 */
1474 /* LN2 0.69314718055994530941723212145817657 */
1475 /* LN10 2.30258509299404568401799145468436421 */
1476 /* SQRT2 1.41421356237309504880168872420969808 */
1477 /* 1_SQRT2 0.70710678118654752440084436210484904 */
1478 /* EULER 0.57721566490153286060651209008240243 */
1479
1480 (void) fprintf(STDOUT, "\n\n/* *** DECLARE GLOBAL CONSTANTS %s */\n\n", multiple('*', 95L));
1481
1482 (void) fprintf(STDOUT, "const I_TYPE START = 1LL;\n" );
1483 (void) fprintf(STDOUT, "const I_TYPE STOP = 0LL;\n\n" );
1484
1485 cst = 3.14159265358979323846264338327950288L;
1486 (void) fprintf(STDOUT, "const R_TYPE _pi_ = %1.15Lf;\n", cst);
1487 cst = 1.57079632679489661923132169163975144L;
1488 (void) fprintf(STDOUT, "const R_TYPE _pi2_ = %1.15Lf;\n", cst);
1489 cst = 0.78539816339744830961566084581987572L;
1490 (void) fprintf(STDOUT, "const R_TYPE _pi4_ = %1.16Lf;\n", cst);
1491 cst = 0.39269908169872415480783042290993786L;
1492 (void) fprintf(STDOUT, "const R_TYPE _pi8_ = %1.16Lf;\n", cst);
1493 cst = 6.28318530717958647692528676655900576L;
1494 (void) fprintf(STDOUT, "const R_TYPE _2pi_ = %1.15Lf;\n", cst);
1495 cst = 2.71828182845904523536028747135266250L;
1496 (void) fprintf(STDOUT, "const R_TYPE _e_ = %1.15Lf;\n\n", cst);
1497
1498 cst = 3.14159265358979323846264338327950288L;
1499 (void) fprintf(STDOUT, "const H_PREC _PI_ = %1.18LfL;\n", cst);
1500 cst = 1.57079632679489661923132169163975144L;
1501 (void) fprintf(STDOUT, "const H_PREC _PI2_ = %1.18LfL;\n", cst);
1502 cst = 0.78539816339744830961566084581987572L;
1503 (void) fprintf(STDOUT, "const H_PREC _PI4_ = %1.19LfL;\n", cst);
1504 cst = 0.39269908169872415480783042290993786L;
1505 (void) fprintf(STDOUT, "const H_PREC _PI8_ = %1.19LfL;\n", cst);
1506 cst = 6.28318530717958647692528676655900576L;
1507 (void) fprintf(STDOUT, "const H_PREC _2PI_ = %1.18LfL;\n", cst);
1508 cst = 2.71828182845904523536028747135266250L;
1509 (void) fprintf(STDOUT, "const H_PREC _E_ = %1.18LfL;\n\n", cst);
1510
1511 (void) fprintf(STDOUT, "const R_TYPE EPSILON = %.1e;", 2.0*pow(10.0, -(double) DBL_DIG));
1512 (void) fprintf(STDOUT, "%54s /* used as 'small' number */\n\n", " " );
1513 (void) fprintf(STDOUT, "\n/* *** DECLARE GLOBAL CONSTANTS *** ");
1514 (void) fprintf(STDOUT, "(not to be used outside of this code, use corresponding macros defined above instead) %s */\n\n", multiple('*', 5L));
1515 if (Periodic_Flag) {
1516 if (9L < Num_Segments) {
1517 (void) strcpy(spc, "");
1518 } else {
1519 (void) strcpy(spc, " ");
1520 }
1521 if (1L < Num_Segments) {
1522 if ((!Fs_Ext_Flag) && (!Ts_Ext_Flag)) {
1523 if (11 >= Num_Segments) {
1524 (void) fprintf(STDOUT, "const H_PREC napa_fsl[%ld] %s = { ", Num_Segments, spc );
1525 } else {
1526 (void) fprintf(STDOUT, "const H_PREC napa_fsl[%ld] %s = \n", Num_Segments, spc );
1527 (void) fprintf(STDOUT, " { ");
1528 }
1529 for (seg = 0L; seg < Num_Segments; seg++) {
1530 if (0L != seg) {
1531 (void) fprintf(STDOUT, ", ");
1532 }
1533 rate1 = Segment_List[ 0L].rate;
1534 rate2 = Segment_List[seg].rate;
1535 factor = GCD(rate1, rate2);
1536 rate1 /= factor;
1537 rate2 /= factor;
1538 if (ISEQUAL(rate1, rate2)) {
1539 (void) fprintf(STDOUT, "FS");
1540 } else {
1541 if ((ISNOTEQUAL(1.0, rate1)) && (ISNOTEQUAL(1.0, rate2))) {
1542 (void) fprintf(STDOUT, "(FS*%.1fL)/%.1fL", rate1, rate2);
1543 } else if ((ISNOTEQUAL(1.0, rate1)) && ( ISEQUAL(1.0, rate2))) {
1544 (void) fprintf(STDOUT, "FS*%.1fL", rate1);
1545 } else if (( ISEQUAL(1.0, rate1)) && (ISNOTEQUAL(1.0, rate2))) {
1546 (void) fprintf(STDOUT, "FS/%.1fL", rate2);
1547 }
1548 }
1549 }
1550 (void) fprintf(STDOUT, " };\n");
1551 }
1552 (void) fprintf(STDOUT, "const I_TYPE napa_stl[%ld] %s = { ", Num_Segments, spc);
1553 for (seg = 0L; seg < Num_Segments; seg++) {
1554 if (0L != seg) {
1555 (void) fprintf(STDOUT, ", " );
1556 }
1557 (void) fprintf(STDOUT, "%-ldLL", (long) Segment_List[seg].offset);
1558 }
1559 (void) fprintf(STDOUT, " };\n");
1560 }
1561 }
1562 (void) fprintf(STDOUT, "const int napa_per[%ld] %s = { ", Num_Segments, spc);
1563 for (seg = 0L; seg < Num_Segments; seg++) {
1564 if (0L != seg) {
1565 (void) fprintf(STDOUT, ", " );
1566 }
1567 if (!Segment_List[seg].periodic) {
1568 (void) fprintf(STDOUT, "false");
1569 } else {
1570 (void) fprintf(STDOUT, "true" );
1571 }
1572 }
1573 (void) fprintf(STDOUT, " };\n\n");
1574 len = fprintf(STDOUT, "const C_TYPE napa_title[%ld]", 1L + LENGTH(Title_String));
1575 if (0 != strcmp(Title_String, Short_Title_String)) { /* a short title has been built */
1576 (void) fprintf(STDOUT, "%*s = ", 33-len, " ");
1577 } else {
1578 (void) fprintf(STDOUT, "%*s = ", 30-len, " ");
1579 }
1580 if (80L < LENGTH(Title_String)) {
1581 (void) fprintf(STDOUT, "\n " );
1582 }
1583 (void) fprintf(STDOUT, " \"" );
1584 for (i = 0L; i < LENGTH(Title_String); i++) {
1585 if ('\\' == Title_String[i]) {
1586 (void) fprintf(STDOUT, "\\\\" ); /* double the slash to freeze the string */
1587 } else {
1588 (void) fprintf(STDOUT, "%c", Title_String[i]);
1589 }
1590 }
1591 (void) fprintf(STDOUT, "\";\n");
1592 if (0 != strcmp(Title_String, Short_Title_String)) { /* a short title has been built */
1593 len = fprintf(STDOUT, "const C_TYPE napa_short_title[%ld] ", 1L + LENGTH(Short_Title_String));
1594 (void) fprintf(STDOUT, "%*s= ", 33-len, " ");
1595 if (80L < LENGTH(Short_Title_String)) {
1596 (void) fprintf(STDOUT, "\n " );
1597 }
1598 (void) fprintf(STDOUT, " \"%s\";\n\n", Short_Title_String);
1599 } else {
1600 (void) fprintf(STDOUT, "\n" );
1601 }
1602 (void) fprintf(STDOUT, "\n/* *** DECLARE GLOBAL VARIABLES *** " );
1603 (void) fprintf(STDOUT, "(not to be used outside of this code, use corresponding macros defined above instead) %s */\n\n", multiple('*', 5L));
1604 (void) fprintf(STDOUT, "char napa_cwd[128] = \"Unknown\";\n\n");
1605 (void) fprintf(STDOUT, "int napa_waypoint = -1;\n\n" );
1606 if (Periodic_Flag) {
1607 if (1L < Num_Segments) {
1608 (void) fprintf(STDOUT, "long napa_segment = 0L;\n" );
1609 for (seg = 0L; seg < Num_Segments; seg++) {
1610 (void) fprintf(STDOUT, "int napa_segment_run_%-2ld = true;\n", seg );
1611 }
1612 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
1613 (void) fprintf(STDOUT, "H_PREC napa_fsl[%ld];\n", Num_Segments );
1614 }
1615 }
1616 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
1617 (void) fprintf(STDOUT, "R_TYPE napa_fs_ext = 1.0;\n" );
1618 (void) fprintf(STDOUT, "R_TYPE napa_ts_ext = 1.0;\n" );
1619 }
1620 }
1621 if ((Synchro_Flag) && (0L < Num_Tools)) {
1622 (void) fprintf(STDOUT, "\nI_TYPE napa_tool_index = 0LL;\n\n" );
1623 } else {
1624 (void) fprintf(STDOUT, "\n");
1625 }
1626 (void) fprintf(STDOUT, "H_PREC napa_abs_loop = 0.0L;\n" );
1627 if ((Synchro_Flag) && (1L <= Num_Tools)) {
1628 (void) fprintf(STDOUT, "H_PREC napa_rel_loop = 0.0L;\n\n" );
1629 }
1630 (void) fprintf(STDOUT, "H_PREC napa_abs_time = 0.0L;\n" );
1631 (void) fprintf(STDOUT, "H_PREC napa_ref_time = 0.0L;\n" );
1632 if ((Synchro_Flag) && (1L <= Num_Tools)) {
1633 (void) fprintf(STDOUT, "H_PREC napa_rel_time = 0.0L;\n" );
1634 }
1635 (void) fprintf(STDOUT, "\nI_TYPE napa_random_seed = 0LL;\n" );
1636 (void) fprintf(STDOUT, "\nlong napa_IO_count = 0L;\n" );
1637 (void) fprintf(STDOUT, "IO_RECORD napa_IO_record[%ld];\n\n", MAXFILES);
1638 if (0L < Num_Tools) {
1639 if (Synchro_Flag) {
1640 (void) fprintf(STDOUT, "I_TYPE napa_packet = 1LL;\n" );
1641 } else {
1642 (void) fprintf(STDOUT, "I_TYPE napa_packet = 0LL;\n" );
1643 }
1644 if (Interlude_Flag1) {
1645 (void) fprintf(STDOUT, "I_TYPE napa_tool_start = 0LL;\n" );
1646 }
1647 }
1648 (void) fprintf(STDOUT, "\nclock_t napa_wall_clock = 0;\n\n" );
1649 if (Input_Flag) {
1650 (void) fprintf(STDOUT, "int napa_input_test = 0;\n" );
1651 (void) fprintf(STDOUT, "char *napa_input_pointer = (char*) NULL;\n");
1652 (void) fprintf(STDOUT, "char napa_input_buffer[%ld];\n", STRLENGTH);
1653 }
1654 if (Gateway_Flag) {
1655 if (25L > Gateway_List.counter) {
1656 (void) fprintf(STDOUT, "I_TYPE napa_gateway = %ldLL;\n", Gateway_List.counter - 1L);
1657 } else {
1658 (void) fprintf(STDOUT, "I_TYPE napa_gateway1 = %ldLL;\n", Gateway_List.counter - 1L);
1659 (void) fprintf(STDOUT, "I_TYPE napa_gateway2 = %ldLL;\n",
1660 ((long) pow(10.0, floor(log10((double) Gateway_List.counter)))));
1661 }
1662 }
1663 if (Assert_Flag) {
1664 (void) fprintf(STDOUT, "int napa_assert_flag = false;\n" );
1665 }
1666 if (Dump_Flag) {
1667 (void) fprintf(STDOUT, "int napa_dump_flag = false;\n" );
1668 }
1669 if ((!Output_Flag) && (!Dump_Flag) && (!Assert_Flag)) {
1670 (void) fprintf(STDOUT, "int napa_output_flag = false;\n" );
1671 }
1672 (void) fprintf(STDOUT, "int napa_error_flag = false;\n" );
1673 if (Cmdline_Flag) {
1674 (void) fprintf(STDOUT, "\nC_TYPE napa_sim_time[36] = {'\\0'};\n");
1675 (void) fprintf(STDOUT, "C_TYPE napa_job_id[32] = {'\\0'};\n");
1676 (void) fprintf(STDOUT, "C_TYPE napa_cmd_line[256] = {'\\0'};\n");
1677 (void) fprintf(STDOUT, "C_TYPE napa_cmd_parms[256] = {'\\0'};\n");
1678 }
1679 if (0L < Num_Tools) {
1680 (void) fprintf(STDOUT, "\nMAILBOX_RECORD *napa_msg = (MAILBOX_RECORD*) NULL;\n");
1681 }
1682 if (1L <= Num_Tools) {
1683 (void) fprintf(STDOUT, "MAILBOX_RECORD napa_mailbox[MAILBOX];\n" );
1684 }
1685 return;
1686}
1687
1688
1690 (void) fprintf(STDOUT, "\n\n/* *** DECLARE GLOBAL FUNCTION POINTERS %s */\n\n", multiple('*', 87L));
1691 (void) fprintf(STDOUT, "I_TYPE (*napa_seed)(I_TYPE) = NULL;\n");
1692 (void) fprintf(STDOUT, "I_TYPE (*napa_rand)(void) = NULL;\n");
1693 (void) fprintf(STDOUT, "I_TYPE (*napa_root)(I_TYPE) = NULL;\n");
1694 return;
1695}
1696
1697
1699 int n;
1700 char buffer[LINLENGTH] = {'\0'};
1701 (void) fprintf(STDOUT, "\n\n/* *** NAPA FUNCTION PROTOTYPES %s */\n\n", multiple('*', 95L));
1702 n = snprintf(buffer, (size_t) (LINLENGTH-1L), " /* see \"%s\" */", Header_List[0].fname);
1703 n = 102 - n;
1704 if (0 >= n) {
1705 n = 1;
1706 }
1707#if YES == COMPILE_LOOP_OPTION /* defined by user in "napa.h", default: NO */
1708 (void) fprintf(STDOUT, "void napa_loop_option(long);\n" );
1709#endif
1710 (void) fprintf(STDOUT, "void napa_control_init(void);\n");
1711 if (Loop_Flag) {
1712 (void) fprintf(STDOUT, "void napa_tool_setup(void);\n" );
1713 }
1714 (void) fprintf(STDOUT, "\n");
1715 if (Cmdline_Flag) {
1716 (void) fprintf(STDOUT, "void napa_print_usage(const char*, FILE*, long);\n\n");
1717 }
1718 (void) fprintf(STDOUT, "void napa_init(void); %*s%s\n", n, " ", buffer);
1719 (void) fprintf(STDOUT, "void napa_close(void);%*s%s\n", n, " ", buffer);
1720 (void) fprintf(STDOUT, "void napa_end(void);\n" );
1721 (void) fprintf(STDOUT, "void napa_exit(int);\n\n" );
1722 (void) fprintf(STDOUT, "void napa_timer(long);\n\n");
1723 if ((0L < Num_Vars) || (0L < Num_Injects)) {
1724 (void) fprintf(STDOUT, "void napa_reset_variables(void);\n" );
1725 }
1726 if (0L < Num_Nodes) {
1727 (void) fprintf(STDOUT, "void napa_reset_nodes(void);\n\n" );
1728 }
1729 if (Array_Flag) {
1730 (void) fprintf(STDOUT, "void napa_array_setup(IO_COMMAND);\n");
1731 }
1732 if ((Output_Flag) || (Dump_Flag) || ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr")))) {
1733 (void) fprintf(STDOUT, "void napa_file_banner(void);\n" );
1734 }
1735 if (Dump_Flag) {
1736 (void) fprintf(STDOUT, "void napa_dump_states(void);\n" );
1737 }
1738 if (Load_Flag) {
1739 (void) fprintf(STDOUT, "void napa_load_states(void);\n" );
1740 }
1741 if (((Debug_Flag) || (Directive_Flag)) && (!Cmdline_Flag)) {
1742 (void) fprintf(STDOUT, "void napa_check_directives(void);\n" );
1743 }
1744 if ((UserTool_Flag) || (Post_Flag)) {
1745 (void) fprintf(STDOUT, "double *napa_check_for_option(const char*, long, const char*, int);\n" );
1746 }
1747 (void) fprintf(STDOUT, "\nIO_COMMAND napa_IO_manager(IO_COMMAND, FILE**, const char*, const char*, const char*);\n");
1748 if (Pointer_Flag) {
1749 (void) fprintf(STDOUT, "IO_COMMAND napa_record_manager(IO_COMMAND, DATA_RECORD*, long, long, long, const char*);\n");
1750 (void) fprintf(STDOUT, "void napa_record_setup(IO_COMMAND);\n");
1751 }
1752 (void) fprintf(STDOUT, "\n");
1753 (void) fprintf(STDOUT, "I_TYPE napa_rand_integer(I_TYPE); %59s /* basic random generator */\n", " ");
1754 (void) fprintf(STDOUT, "\nI_TYPE napa_default_seed(I_TYPE); %59s /* seed generator */\n", " ");
1755 (void) fprintf(STDOUT, "I_TYPE napa_default_root(I_TYPE); %59s /* seed randomizer */\n", " ");
1756 (void) fprintf(STDOUT, "I_TYPE napa_default_rand(void); %59s /* random generator */\n", " ");
1757 if (Ping_Flag) {
1758 (void) fprintf(STDOUT, "\nvoid napa_ping(int);\n" );
1759 }
1760 return;
1761}
1762
1763
1765 char tok1[STRLENGTH] = {'\0'};
1766 char tok2[STRLENGTH] = {'\0'};
1767 char *s = (char*) NULL;
1768 long fun, dir, dbg;
1769 long n;
1770 int len1, len2, len3;
1771 int flag;
1772 flag = false;
1773 if ((0L < Num_UserTools) || (0L < Num_Functions)) {
1774 if (1L >= Num_Functions) {
1775 (void) fprintf(STDOUT, "\n\n/* *** USER'S FUNCTION COMPILATION DIRECTIVE %s */\n\n", multiple('*', 82L));
1776 } else {
1777 (void) fprintf(STDOUT, "\n\n/* *** USER'S FUNCTION COMPILATION DIRECTIVES %s */\n\n", multiple('*', 81L));
1778 qsort((void*) Function_List, (size_t) Num_Functions, sizeof (Function_List[0]), sort_names);
1779 }
1780 flag = false;
1781
1782 len1 = 0;
1783 for (fun = 0L; fun < Num_Functions; fun++) {
1784 if (0L >= Function_List[fun].number) { /* not a tool or user node */
1785 continue;
1786 }
1787 if (0 == strcmp(Function_List[fun].table, "post_void")) { /* instruction 'void' */
1788 continue;
1789 }
1790 len1 = MAX(len1, (int) strlen(Function_List[fun].table));
1791 }
1792 for (fun = 0L; fun < Num_Functions; fun++) {
1793 if (0L >= Function_List[fun].number) { /* not a tool or user node */
1794 continue;
1795 }
1796 if (0 == strcmp(Function_List[fun].table, "post_void")) { /* instruction 'void' */
1797 continue;
1798 }
1799 len2 = len1 - (int) strlen(Function_List[fun].table) + 1;
1800 len3 = snprintf(tok2, (size_t) (STRLENGTH-1L), "#define COMPILE_%s %*s %-ld", Function_List[fun].table, len2, " ", Function_List[fun].number);
1801 if (1L >= Function_List[fun].number) {
1802 (void) fprintf(STDOUT, "%s %*s /* % 2ld instance in netlist */\n", tok2, 96 - len3 , " ", Function_List[fun].number);
1803 } else {
1804 (void) fprintf(STDOUT, "%s %*s /* % 2ld instances in netlist */\n", tok2, 96 - len3 , " ", Function_List[fun].number);
1805 }
1806 flag = true;
1807 }
1808 for (fun = 0L; fun < Num_Functions; fun++) {
1809 if (0L < Function_List[fun].number) { /* not a function */
1810 continue;
1811 }
1812 if (0 == strcmp(Function_List[fun].table, "post_void")) { /* instruction 'void' */
1813 continue;
1814 }
1815 if (flag) {
1816 (void) fprintf(STDOUT, "\n");
1817 flag = false;
1818 }
1819 (void) fprintf(STDOUT, "#define COMPILE_%s\n", Function_List[fun].table);
1820 }
1821 }
1822 flag = false;
1823 if ((0L < Num_Directives) || (0L < Num_Debugs)) {
1824 (void) fprintf(STDOUT, "\n\n/* *** USER'S COMPILATION DIRECTIVES %s */\n\n", multiple('*', 90L));
1825 qsort((void*) Directive_List, (size_t) Num_Directives, sizeof (Directive_List[0]), sort_names);
1826 for (dir = 0L; dir < Num_Directives; dir++) {
1827 if (0 == strcmp(Directive_List[dir].name, "TIME_OFFSET")) { /* macro in produced C code */
1828 if (ISEMPTY(Directive_List[dir].value)) { /* default value if empty ! */
1829 strcpy_alloc(&(Directive_List[dir].value), "0.0", Directive_List[dir].mline, Directive_List[dir].mfile);
1830 }
1831 }
1832 if (0 == strcmp(Directive_List[dir].name, "JITTER")) { /* macro in produced C code */
1833 if (ISEMPTY(Directive_List[dir].value)) { /* default value if empty ! */
1834 strcpy_alloc(&(Directive_List[dir].value), "0.0", Directive_List[dir].mline, Directive_List[dir].mfile);
1835 }
1836 }
1837 if (!Directive_List[dir].function) { /* not a macro function */
1838 n = fprintf(STDOUT, "#define %s", Directive_List[dir].name);
1839 } else { /* macro function */
1840 n = fprintf(STDOUT, "#define %s(%s)", Directive_List[dir].name, Directive_List[dir].parms);
1841 }
1842 if (ISNOTEMPTY(Directive_List[dir].value)) { /* process value of macro */
1843 (void) fprintf(STDOUT, "%*s", (int) MAX(25L-n, 2L), " ");
1844 s = Directive_List[dir].value;
1845 for (;;) {
1846 s = get_token(s, tok1, true);
1847 if (ISEMPTY(tok1)) {
1848 break;
1849 }
1850 (void) build_name("", tok1, RIGHT_VALUE);
1851 (void) fprintf(STDOUT, "%s", tok1);
1852 }
1853 }
1854 (void) fprintf(STDOUT, "\n");
1855 if (ISEMPTY(Directive_List[dir].value)) { /* empty directive */
1856 (void) fprintf(STDOUT, "#define %s_IS_EMPTY\n", Directive_List[dir].name);
1857 }
1858 flag = true;
1859 }
1860 qsort((void*) Debug_List, (size_t) Num_Debugs, sizeof (Debug_List[0]), sort_names);
1861 if (0L < Num_Debugs) {
1862 if (flag) {
1863 (void) fprintf(STDOUT, "\n");
1864 }
1865 for (dbg = 0L; dbg < Num_Debugs; dbg++) {
1866 (void) fprintf(STDOUT, "#define DEBUG_MODE_%s\n", Debug_List[dbg].name);
1867 }
1868 }
1869 for (dir = 0L; dir < Num_Directives; dir++) {
1870 if (Directive_List[dir].function) {
1871 if (flag) {
1872 (void) fprintf(STDOUT, "\n");
1873 flag = false;
1874 }
1875 (void) fprintf(STDOUT, "PING(%s);\n", Directive_List[dir].name);
1876 }
1877 }
1878 }
1879 return;
1880}
1881
1882
1884 long h;
1885 if (1L == Num_Headers) {
1886 (void) fprintf(STDOUT, "\n/* *** INCLUDE NAPA USER'S HEADER FILE %s */\n\n", multiple('*', 88L));
1887 } else {
1888 (void) fprintf(STDOUT, "\n/* *** INCLUDE NAPA USER'S HEADER FILES %s */\n\n", multiple('*', 87L));
1889 }
1890 for (h = 0L; h < Num_Headers; h++) {
1891 if (0 == strcmp(Header_List[h].option, "expand")) {
1892 (void) fprintf(STDOUT, "\n");
1893 cat_file(Header_List[h].fname, "header", EXPAND, Header_List[h].mline, Header_List[h].mfile);
1894 (void) fprintf(STDOUT, "\n");
1895 } else if (ISEMPTY(Header_List[h].option) || (0 == strcmp(Header_List[h].option, "noexpand"))) {
1896 cat_file(Header_List[h].fname, "header", NO_EXPAND, Header_List[h].mline, Header_List[h].mfile);
1897 (void) fprintf(STDOUT, "#include \"%s\"\n", Header_List[h].fname);
1898 } else { /* already tested, anyway safer to check */
1899 print_error_location("header", Header_List[h].mline, Header_List[h].mfile);
1900 (void) fprintf(STDERR, " (%s) is not a valid header qualifier\n", Header_List[h].option);
1901 (void) fprintf(STDERR, " valid qualifiers are: (noexpand), (expand)\n");
1902 }
1903 }
1904 (void) fprintf(STDOUT, "\n\n/* *** DEFAULT PSEUDO-RANDOM NUMBER GENERATOR %s */\n\n", multiple('*', 81L));
1905 (void) fprintf(STDOUT, "#if !defined(EXTERNAL_PSEUDO_RANDOM_NUMBER_GENERATOR)\n");
1906 (void) fprintf(STDOUT, " #define NAPA_RAND &napa_default_rand %*s /* pointer to function */\n", 58, " ");
1907 (void) fprintf(STDOUT, " #define NAPA_SEED &napa_default_seed %*s /* pointer to function */\n", 58, " ");
1908 (void) fprintf(STDOUT, " #define NAPA_ROOT &napa_default_root %*s /* pointer to function */\n", 58, " ");
1909 (void) fprintf(STDOUT, "#endif\n");
1910 return;
1911}
1912
1913
1915 long i;
1916 (void) fprintf(STDOUT, "\n\n/* *** DECLARATIONS %s */\n\n", multiple('*', 107L));
1917 if (0L < Num_IOs) {
1918 (void) fprintf(STDOUT, "/* (declare I/O's file handles) */\n");
1919 for (i = 0L; i < Num_IOs; i++) {
1920 (void) fprintf(STDOUT, "FILE *napa_fp_%ld = (FILE*) NULL;\n", i );
1921 }
1922 (void) fprintf(STDOUT, "\n");
1923 }
1924 if (Array_Flag) {
1925 (void) fprintf(STDOUT, "/* (declare array file handles) */\n");
1926 for (i = 0L; i < Num_Arrays; i++) {
1927 if (ISNOTEMPTY(Array_List[i].fname) && (Array_List[i].used)) {
1928 (void) fprintf(STDOUT, "FILE *napa_fp_init_%ld = (FILE*) NULL;\n", i );
1929 }
1930 }
1931 (void) fprintf(STDOUT, "\n");
1932 }
1933 if ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr"))) {
1934 (void) fprintf(STDOUT, "/* (declare ping file handle) */\n");
1935 (void) fprintf(STDOUT, "FILE *napa_fp_ping = (FILE*) NULL;\n" );
1936 (void) fprintf(STDOUT, "\n");
1937 }
1938 if (Dump_Flag) {
1939 (void) fprintf(STDOUT, "/* (declare dump file handle) */\n");
1940 (void) fprintf(STDOUT, "FILE *napa_fp_dump = (FILE*) NULL;\n" );
1941 (void) fprintf(STDOUT, "\n");
1942 }
1943 return;
1944}
1945
1946
1947void declare_vars(void) {
1948 long i, j, m, n;
1949 char *str = (char*) NULL;
1950 char sgn[2] = {'\0'};
1951 char tok[STRLENGTH] = {'\0'};
1952 char v1[LINLENGTH] = {'\0'};
1953 char buf[STRLENGTH] = {'\0'};
1954 int flag;
1955 flag = false;
1956 if (0L < Num_Injects) {
1957 (void) fprintf(STDOUT, "/* (declare node injections) */\n");
1958 for (i = 0L; i < Num_Injects; i++) {
1959 n = node_id(Inject_List[i].name);
1960 (void) fprintf(STDOUT, "R_TYPE inject_%s;\n", Node_List[n].name1);
1961 }
1962 (void) fprintf(STDOUT, "\n");
1963 }
1964
1965 if (0L < Num_Vars) { /* any variable to declare ? */
1966 for (i = 0L; i < Num_Vars; i++) {
1967 if ((0 != strncmp(Var_List[i].name1, "$init$", (size_t) 6))
1968 && (0 != strncmp(Var_List[i].name1, "$null$", (size_t) 6))
1969 && (0 != strncmp(Var_List[i].name1, "$declare$", (size_t) 9))) {
1970 flag = true; /* true variables */
1971 break;
1972 } else {
1973 str = Var_List[i].value;
1974 str = get_sign_and_token(str, sgn, tok);
1975 m = node_id(tok);
1976 if (UNDEFINED != m) {
1977 flag = true; /* initialization, node declaration */
1978 break;
1979 }
1980 }
1981 }
1982 }
1983 if (!flag) {
1984 return; /* no variable to declare */
1985 }
1986 if (0L < Num_Consts) {
1987 (void) fprintf(STDOUT, "/* (declare constants and variables) */\n");
1988 } else {
1989 (void) fprintf(STDOUT, "/* (declare variables) */\n");
1990 }
1991 for (j = 0L; j < Num_Vars; j++) { /* true variables, not an 'init' */
1992 i = (j + Num_Vars - Num_Consts) % Num_Vars; /* place created constants first */
1993 if (0L > i) {
1994 i = j + Num_Consts;
1995 }
1996 if (0 == strncmp(Var_List[i].name1, "$declare$", (size_t) 9)) {
1997 continue;
1998 } else if ((0 != strncmp(Var_List[i].name1, "$init$", (size_t) 6))
1999 && (0 != strncmp(Var_List[i].name1, "$null$", (size_t) 6))) {
2000 (void) strcpy(v1, Var_List[i].name1);
2001 (void) build_name("", v1, LEFT_VALUE);
2002 switch (Var_List[i].type) {
2003 case DIGITAL_DATA_TYPE :
2004 (void) fprintf(STDOUT, "I_TYPE %s;\n", v1);
2005 if (2 == Var_List[i].event) {
2006 (void) fprintf(STDOUT, "I_TYPE %s%s_new;\n", "ivar_", Var_List[i].name1);
2007 (void) fprintf(STDOUT, "I_TYPE %s%s_old;\n", "ivar_", Var_List[i].name1);
2008 }
2009 break;
2010 case ANALOG_DATA_TYPE :
2011 (void) fprintf(STDOUT, "R_TYPE %s;\n", v1);
2012 break;
2013 case STRING_DATA_TYPE :
2014 if (Var_List[i].external) { /* length unknown at compilation */
2015 (void) fprintf(STDOUT, "C_TYPE %s[%ld];\n", v1, STRLENGTH);
2016 } else { /* "" will be removed from string */
2017 (void) fprintf(STDOUT, "C_TYPE %s[%ld];\n", v1, (int) strlen(Var_List[i].value) - 1L);
2018 }
2019 break;
2020 default:
2021 break;
2022 }
2023 } else { /* initialization */
2024 str = Var_List[i].value;
2025 str = get_sign_and_token(str, sgn, tok); /* 1st token could be a node name */
2026 m = node_id(tok);
2027 if (UNDEFINED != m) { /* yes, specific declaration */
2028 if (NO == Node_List[m].flag) {
2029 print_error_location("init", Var_List[i].mline, Var_List[i].mfile);
2030 (void) fprintf(STDERR, " <%s>: this node is not allowed to be initialized\n", Node_List[m].name1);
2031 (void) snprintf(buf, (size_t) 31, "$null$_%ld", Num_Nulls);
2032 Num_Nulls++;
2033 strcpy_realloc(&(Var_List[i].name1), buf, Var_List[i].mline, Var_List[i].mfile);
2034 continue; /* remove initialization from list */
2035 }
2036 if (MAYBE == Node_List[m].flag) {
2037 print_warning_location("init", Var_List[i].mline, Var_List[i].mfile);
2038 (void) fprintf(STDERR, " the initialization of <%s> has no effect, as this node is not\n", Node_List[m].name1);
2039 (void) fprintf(STDERR, " - the output of any 'delay' node or delayed node\n");
2040 (void) fprintf(STDERR, " - the input of any user function 'duser', 'iuser', 'dtool' or 'itool'\n");
2041 (void) fprintf(STDERR, " - the output of any 'integrator' node\n");
2042 (void) fprintf(STDERR, " - the output of any 'latch', 'toggle', 'hold', 'track' or 'register' node\n");
2043 (void) fprintf(STDERR, " - part of the expression determining the termination of the simulation\n" );
2044 }
2045 switch (Node_List[m].type) {
2046 case DIGITAL_DATA_TYPE :
2047 (void) fprintf(STDOUT, "I_TYPE init_%s;\n", Node_List[m].name1);
2048 break;
2049 case ANALOG_DATA_TYPE :
2050 (void) fprintf(STDOUT, "R_TYPE init_%s;\n", Node_List[m].name1);
2051 break;
2052 default:
2053 break;
2054 }
2055 }
2056 }
2057 }
2058 (void) fprintf(STDOUT, "\n");
2059 return;
2060}
2061
2062
2063void declare_arrays(void) {
2064 long i;
2065 long kd, tp;
2066 char v1[LINLENGTH] = {'\0'};
2067 if (!Array_Flag) {
2068 return;
2069 }
2070 (void) fprintf(STDOUT, "/* (declare arrays) */\n");
2071 for (i = 0L; i < Num_Arrays; i++) {
2072 if (!Array_List[i].used) {
2073 continue;
2074 }
2075 kd = Array_List[i].kind;
2076 tp = Array_List[i].type;
2077 (void) strcpy(v1, Array_List[i].name);
2078 (void) build_name("", v1, LEFT_VALUE);
2079 switch (kd) {
2080 case RAM_KIND:
2081 if (ANALOG_DATA_TYPE == tp) {
2082 (void) fprintf(STDOUT, "RAM_R_RECORD %s;\n", v1);
2083 } else {
2084 (void) fprintf(STDOUT, "RAM_I_RECORD %s;\n", v1);
2085 }
2086 break;
2087 case RAM2_KIND:
2088 if (ANALOG_DATA_TYPE == tp) {
2089 (void) fprintf(STDOUT, "RAM2_R_RECORD %s;\n", v1);
2090 } else {
2091 (void) fprintf(STDOUT, "RAM2_I_RECORD %s;\n", v1);
2092 }
2093 break;
2094 case ROM_KIND:
2095 if (ANALOG_DATA_TYPE == tp) {
2096 (void) fprintf(STDOUT, "ROM_R_RECORD %s;\n", v1);
2097 } else {
2098 (void) fprintf(STDOUT, "ROM_I_RECORD %s;\n", v1);
2099 }
2100 break;
2101 case ROM2_KIND:
2102 if (ANALOG_DATA_TYPE == tp) {
2103 (void) fprintf(STDOUT, "ROM2_R_RECORD %s;\n", v1);
2104 } else {
2105 (void) fprintf(STDOUT, "ROM2_I_RECORD %s;\n", v1);
2106 }
2107 break;
2108 default:
2109 break;
2110 }
2111 }
2112 (void) fprintf(STDOUT, "\n");
2113 return;
2114}
2115
2116
2118 long i;
2119 char v1[LINLENGTH] = {'\0'};
2120 if (!Pointer_Flag) {
2121 return;
2122 }
2123 (void) fprintf(STDOUT, "/* (declare arrays of pointers) */\n");
2124 for (i = 0L; i < Num_Records; i++) {
2125 if (!Record_List[i].used) {
2126 continue;
2127 }
2128 (void) strcpy(v1, Record_List[i].name);
2129 (void) build_name("", v1, LEFT_VALUE);
2130 (void) fprintf(STDOUT, "DATA_RECORD %s;\n", v1);
2131 }
2132 (void) fprintf(STDOUT, "\n");
2133 return;
2134}
2135
2136
2137void declare_nodes(void) {
2138 long i;
2139 if (0L >= Num_Nodes) {
2140 return;
2141 }
2142 (void) fprintf(STDOUT, "/* (declare nodes) */\n");
2143 for (i = 0L; i < Num_Nodes; i++) {
2144 switch (Node_List[i].type) {
2145 case DIGITAL_DATA_TYPE :
2147 break;
2148 case ANALOG_DATA_TYPE :
2150 break;
2151 default:
2152 break;
2153 }
2154 }
2155 (void) fprintf(STDOUT, "\n");
2156 return;
2157}
2158
2159
2161 long kd;
2162 long j, m, n, v;
2163 long ndel;
2164 char sgn[2] = {'\0'};
2165 char tok1[STRLENGTH] = {'\0'};
2166 char tok2[STRLENGTH] = {'\0'};
2167 char v1[LINLENGTH] = {'\0'};
2168 char *str = (char*) NULL;
2169 char *nm = (char*) NULL;
2170 int flag;
2171 nm = Node_List[i].name1;
2172 kd = Node_List[i].kind;
2173 (void) strcpy(v1, nm);
2174 (void) build_name("", v1, LEFT_VALUE);
2175 /* regular declaration of I_TYPE nodes */
2176 (void) fprintf(STDOUT, "I_TYPE %s;\n", v1);
2177 str = Node_List[i].value;
2178 /* additional declarations for specific kind of nodes */
2179 switch (kd) {
2180 case DELAY_KIND: /* unprocessed value: num input_nod_nam */
2181 str = get_sign_and_token(str, sgn, tok1); /* get number of delays */
2182 v = var_id(tok1);
2183 if (UNDEFINED != v) { /* defined by constant ivar */
2184 (void) fprintf(STDOUT, "I_TYPE *%s_delay = (I_TYPE*) NULL;\n", v1);
2185 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr;\n", nm);
2186 } else { /* defined by a hard coded number */
2187 flag = sscanf(tok1, "%li", &ndel);
2188 if (1 != flag) {
2189 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
2190 (void) fprintf(STDERR, " number of digital delays is not a well-formed positive integer <%s>\n", tok1);
2191 ndel = 99L;
2192 }
2193 if (1L > ndel) {
2194 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
2195 (void) fprintf(STDERR, " number of digital delays <%ld> must at least equal to 1\n", ndel);
2196 ndel = 99L;
2197 }
2198 (void) fprintf(STDOUT, "I_TYPE %s_delay[%ld];\n", v1, ndel);
2199 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr;\n", nm);
2200 }
2201 break;
2202 case DELAY2_KIND: /* unprocessed value: input_node_name */
2203 (void) fprintf(STDOUT, "I_TYPE %s_delay;\n", v1);
2204 break;
2205 case DELAY3_KIND: /* unprocessed value: input_node_name */
2206 (void) fprintf(STDOUT, "I_TYPE %s_delay[2];\n", v1);
2207 break;
2208 case DC_KIND: /* unprocessed value: input_node_name */
2209 (void) fprintf(STDOUT, "I_TYPE %s_dc;\n", v1);
2210 break;
2211 case DIFFERENTIATOR_KIND: /* unprocessed value: input_node_name */
2212 (void) fprintf(STDOUT, "I_TYPE %s_delay;\n", v1);
2213 break;
2214 case TRIG_KIND: /* [sgn] value node_name mode */
2215 str = get_sign_and_token(str, sgn, tok1);
2216 str = get_sign_and_token(str, sgn, tok1); /* get the input node name */
2217 n = node_id(tok1);
2218 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
2219 (void) fprintf(STDOUT, "I_TYPE inode_%s_store;\n", nm);
2220 } else {
2221 (void) fprintf(STDOUT, "R_TYPE dnode_%s_store;\n", nm);
2222 }
2223 break;
2224 case RSHIFT1_KIND: /* unprocessed value: shift_val nod_nam */
2225 str = get_token(str, tok1, false);
2226 n = node_id(tok1);
2227 v = var_id(tok1);
2228 if ((UNDEFINED != n) || (UNDEFINED != v)) {
2229 (void) fprintf(STDOUT, "R_TYPE dnode_%s_s;\n", nm);
2230 }
2231 break;
2232 case RSHIFT2_KIND: /* unprocessed value: shift_val nod_nam */
2233 str = get_token(str, tok1, false);
2234 str = get_token(str, tok1, false);
2235 n = node_id(tok1);
2236 if (UNDEFINED != n) {
2237 (void) fprintf(STDOUT, "R_TYPE dnode_%s_d;\n", nm);
2238 (void) fprintf(STDOUT, "R_TYPE dnode_%s_r;\n", nm);
2239 (void) fprintf(STDOUT, "I_TYPE %s_l;\n", v1);
2240 }
2241 break;
2242 case BSHIFT_KIND: /* unprocessed value: shift_val nod_nam */
2243 str = get_token(str, tok1, false);
2244 n = constant_type(tok1);
2245 if (UNKNOWN_TYPE == n) {
2246 (void) fprintf(STDOUT, "I_TYPE %s_s;\n", v1);
2247 }
2248 break;
2249 case CHG_KIND: /* unprocessed value: input_nod_nam */
2250 str = get_token(str, tok1, false); /* get the input node name */
2251 n = node_id(tok1);
2252 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
2253 (void) fprintf(STDOUT, "I_TYPE inode_%s_store;\n", nm);
2254 } else {
2255 (void) fprintf(STDOUT, "R_TYPE dnode_%s_store;\n", nm);
2256 }
2257 break;
2258 case ADC_KIND:
2259 case UADC_KIND:
2260 (void) fprintf(STDOUT, "R_TYPE dnode_%s_norm;\n", nm);
2261 break;
2262 case CLOCK_KIND: /* unprocessed value: in_val width */
2263 str = get_token(str, tok1, false); /* clock descriptor */
2264 str = get_token(str, tok2, false); /* clock width */
2265 n = 0L;
2266 m = 0L;
2267 for (j = 0L; j < (LENGTH(tok1)); j++) {
2268 if (('0' == tok1[j])|| ('1' == tok1[j])) {
2269 n++;
2270 }
2271 if ('.' == tok1[j]) {
2272 m++;
2273 }
2274 }
2275 if (1L < m) {
2276 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
2277 (void) fprintf(STDERR, " pattern descriptor cannot contain more than one '.'\n");
2278 (void) fprintf(STDERR, " pattern: <%s>\n", Node_List[i].value);
2279 }
2280 Node_List[i].ID2 = n; /* store length of clock in ID2 */
2281 (void) fprintf(STDOUT, "I_TYPE %s_clock[%ld];\n", v1, Node_List[i].ID2);
2282 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr1;\n", nm);
2283 if (0 != strcmp("1", tok2)) {
2284 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr2;\n", nm);
2285 (void) fprintf(STDOUT, "P_TYPE pnode_%s_width;\n", nm);
2286 }
2287 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ini;\n", nm);
2288 break;
2289 case LATCH_KIND: /* unprocessed value: input_set input_reset */
2290 (void) fprintf(STDOUT, "I_TYPE inode_%s_set;\n", nm);
2291 (void) fprintf(STDOUT, "I_TYPE inode_%s_rst;\n", nm);
2292 break;
2293 case ZERO_KIND: /* unprocessed value: decim_fact node_name */
2294 (void) fprintf(STDOUT, "I_TYPE inode_%s_ctr;\n", nm);
2295 break;
2296 default:
2297 break;
2298 }
2299 return;
2300}
2301
2302
2304 long v;
2305 long ndel;
2306 double dtemp1;
2307 long nn, nv;
2308 long kd;
2309 char sgn[2] = {'\0'};
2310 char tok[STRLENGTH] = {'\0'};
2311 char v1[LINLENGTH] = {'\0'};
2312 char *str = (char*) NULL;
2313 char *nm = (char*) NULL;
2314 long flag;
2315
2316 nm = Node_List[i].name1;
2317 kd = Node_List[i].kind;
2318 (void) strcpy(v1, nm);
2319 (void) build_name("", v1, LEFT_VALUE);
2320 /* regular declaration of R_TYPE nodes */
2321 (void) fprintf(STDOUT, "R_TYPE %s;\n", v1);
2322 str = Node_List[i].value;
2323 /* additional declarations for specific kind of nodes */
2324 switch (kd) { /* additional declarations */
2325 case DELAY_KIND: /* unprocessed value: num in_nod_nam */
2326 str = get_sign_and_token(str, sgn, tok); /* get number of delays */
2327 v = var_id(tok);
2328 if (UNDEFINED != v) { /* defined by constant ivar */
2329 (void) fprintf(STDOUT, "R_TYPE *%s_delay = (R_TYPE*) NULL;\n", v1);
2330 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr;\n", nm);
2331 } else { /* defined by a hard coded number */
2332 flag = sscanf(tok, "%li", &ndel);
2333 if (1 != flag) {
2334 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
2335 (void) fprintf(STDERR, " number of analog delays is not a well-formed positive integer <%s>\n", tok);
2336 ndel = 99L;
2337 }
2338 if (1L > ndel) {
2339 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
2340 (void) fprintf(STDERR, " number of analog delays <%ld> must at least equal to 1\n", ndel);
2341 ndel = 99L;
2342 }
2343 (void) fprintf(STDOUT, "R_TYPE %s_delay[%ld];\n", v1, ndel);
2344 (void) fprintf(STDOUT, "P_TYPE pnode_%s_ptr;\n", nm);
2345 }
2346 break;
2347 case DELAY2_KIND: /* unprocessed value: input_node_name */
2348 (void) fprintf(STDOUT, "R_TYPE %s_delay;\n", v1);
2349 break;
2350 case DELAY3_KIND: /* unprocessed value: input_node_name */
2351 (void) fprintf(STDOUT, "R_TYPE %s_delay[2];\n", v1);
2352 break;
2353 case DC_KIND: /* unprocessed value: input_node_name */
2354 (void) fprintf(STDOUT, "R_TYPE %s_dc;\n", v1);
2355 break;
2356 case DIFFERENTIATOR_KIND: /* unprocessed value: input_node_name */
2357 (void) fprintf(STDOUT, "R_TYPE %s_delay;\n", v1);
2358 break;
2359 case OSC_KIND: /* unprocessed value: off ampl freq phase */
2360 (void) fprintf(STDOUT, "H_PREC hnode_%s_fctr;\n", nm);
2361 (void) fprintf(STDOUT, "H_PREC hnode_%s_osc0;\n", nm);
2362 (void) fprintf(STDOUT, "H_PREC hnode_%s_osc1;\n", nm);
2363 (void) fprintf(STDOUT, "H_PREC hnode_%s_osc2;\n", nm);
2364 break;
2365 case SIN_KIND: /* unprocessed value: off ampl freq phase */
2366 case COS_KIND:
2367 str = get_sign_and_token(str, sgn, tok);
2368 str = get_sign_and_token(str, sgn, tok);
2369 str = get_sign_and_token(str, sgn, tok);
2370 if (1 > sscanf(tok, "%lf", &dtemp1)) { /* not a number, could be true node or var */
2371 flag = false; /* by default, a true variable */
2372 nv = var_id(tok);
2373 if (UNDEFINED != nv) {
2374 flag = Var_List[nv].constant;
2375 }
2376 nn = node_id(tok);
2377 if (UNDEFINED != nn) {
2378 flag = (long) ((DC_KIND == Node_List[nv].kind) || (CONST_KIND == Node_List[nv].kind));
2379 }
2380 if (!flag) { /* true variable, freq modulation expected */
2381 if (SIN_KIND == kd) {
2382 Node_List[i].kind = SIN2_KIND;
2383 }
2384 if (COS_KIND == kd) {
2385 Node_List[i].kind = COS2_KIND;
2386 }
2387 (void) fprintf(STDOUT, "I_TYPE inode_%s_first;\n", nm);
2388 (void) fprintf(STDOUT, "H_PREC hnode_%s_freq;\n", nm);
2389 (void) fprintf(STDOUT, "H_PREC hnode_%s_phase;\n", nm);
2390 }
2391 }
2392 break;
2393 case NOISE_KIND: /* unprocessed value: num num */
2394 (void) fprintf(STDOUT, "R_TYPE dnode_%s_g1;\n", nm);
2395 (void) fprintf(STDOUT, "R_TYPE dnode_%s_g2;\n", nm);
2396 (void) fprintf(STDOUT, "R_TYPE dnode_%s_rd;\n", nm);
2397 (void) fprintf(STDOUT, "R_TYPE dnode_%s_f;\n", nm);
2398 (void) fprintf(STDOUT, "I_TYPE inode_%s_ok;\n", nm);
2399 break;
2400 case ZERO_KIND: /* unprocessed value: decim_fact in_nod_nam */
2401 (void) fprintf(STDOUT, "I_TYPE inode_%s_ctr;\n", nm);
2402 break;
2403 default:
2404 break;
2405 }
2406 return;
2407}
2408
2409
2410void open_main(void) {
2411 long j;
2412 if (!Cmdline_Flag) {
2413 (void) fprintf(STDOUT, "\n\n/* *** MAIN %s */\n\n", multiple('*', 115L));
2414 (void) fprintf(STDOUT, "int main(void) {\n\n");
2415 } else {
2416 (void) fprintf(STDOUT, "\n\n/* *** MAIN **** (Standalone Simulator) %s */\n\n", multiple('*', 87L));
2417 (void) fprintf(STDOUT, "int main(int argc, char **argv) {\n\n");
2418 if (2L <= Num_Cmdlines) {
2419 (void) fprintf(STDOUT, " C_TYPE str[256] = {'\\0'};\n");
2420 (void) fprintf(STDOUT, " int parm;\n");
2421 }
2422 (void) fprintf(STDOUT, "\n /* (command line parsing ) */\n");
2423 (void) fprintf(STDOUT, " if ( 2 == argc ) {\n");
2424 (void) fprintf(STDOUT, " if ( (0 == strncmp(\"?\", argv[1], (size_t) 1)) || (0 == strncmp(\"-h\", argv[1], (size_t) 2)) ) {\n");
2425 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, YES);\n");
2426 (void) fprintf(STDOUT, " exit(EXIT_SUCCESS);\n");
2427 (void) fprintf(STDOUT, " }\n");
2428 (void) fprintf(STDOUT, " }\n");
2429 (void) fprintf(STDOUT, " napa_waypoint = 0;\n\n");
2430 if (0L == Num_Cmdlines) {
2431 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_parms, (size_t) 255, \"%%s %%s\", argv[0], \"%s\");\n", Cmdline_String);
2432 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_line, (size_t) 255, \"%%s\", argv[0]);\n");
2433 (void) fprintf(STDOUT, " if ( 1 < argc ) {\n");
2434 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
2435 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** No parameter is expected\\n\");\n");
2436 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
2437 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* not NAPA_EXIT(EXIT_FAILURE) to avoid message */
2438 (void) fprintf(STDOUT, " }\n");
2439 } else if (1L == Num_Cmdlines) {
2440 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_parms, (size_t) 255, \"%%s %%s\", argv[0], \"%s\");\n", Cmdline_String);
2441 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_line, (size_t) 255, \"%%s %%s\", argv[0], argv[1]);\n");
2442 (void) fprintf(STDOUT, " if ( 2 > argc ) {\n");
2443 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
2444 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The parameter of the simulator is missing.\\n\");\n");
2445 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
2446 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* not NAPA_EXIT(EXIT_FAILURE) to avoid message */
2447 (void) fprintf(STDOUT, " }\n");
2448 } else { /* Num_Cmdlines > 1 */
2449 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_parms, (size_t) 255, \"%%s %%s\", argv[0], \"%s\");\n", Cmdline_String);
2450 (void) fprintf(STDOUT, " for (parm = 0; parm < argc; parm++) {\n");
2451 (void) fprintf(STDOUT, " (void) strcpy(str, napa_cmd_line);\n");
2452 (void) fprintf(STDOUT, " (void) snprintf(napa_cmd_line, (size_t) 255, \"%%s %%s\", str, argv[parm]);\n");
2453 (void) fprintf(STDOUT, " }\n");
2454 (void) fprintf(STDOUT, " if ( %ld != argc ) {\n", Num_Cmdlines + 1L);
2455 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\");\n");
2456 (void) fprintf(STDOUT, " if ( 1 < argc ) {\n");
2457 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"NAPA Simulator Command Line Error:\\n\\n\\n\");\n" );
2458 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** Expecting %ld parameters instead of %%d !\\n\\n\", argc-1);\n", Num_Cmdlines);
2459 (void) fprintf(STDOUT, " }\n");
2460 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
2461 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() and not NAPA_EXIT(EXIT_FAILURE) to avoid message */
2462 (void) fprintf(STDOUT, " }\n");
2463 }
2464 if (0L < Num_Cmdlines) { /* at least one parameter */
2465 for (j = 0L; j < Num_Cmdlines; j++) {
2466 reset_a_command_line_parameter(j); /* command_line input */
2467 }
2468 }
2469 (void) fprintf(STDOUT, "\n");
2470 }
2471 (void) fprintf(STDOUT, " napa_waypoint = 1;\n\n");
2472 return;
2473}
2474
2475
2477 char command[256] = {'\0'};
2478 char tok1[LINLENGTH] = {'\0'};
2479 char tok2[LINLENGTH] = {'\0'};
2480 char *str1 = (char*) NULL;
2481 char *str2 = (char*) NULL;
2482 long nv, typ;
2483 long i, j;
2484 int len1, len2, len3;
2485 if (!Cmdline_Flag) {
2486 return;
2487 }
2488 (void) fprintf(STDOUT, "\nvoid napa_print_usage(const char *com, FILE *fp, long all) {\n");
2489#if (IS_WIN64 == PLATFORM) /* change slash by backslash */
2490 (void) fprintf(STDOUT, " char str[256] = {'\\0'};\n");
2491 (void) fprintf(STDOUT, " int n;\n");
2492 (void) fprintf(STDOUT, " for (n = 0; n < ((int) strlen(com)); n++) {\n");
2493 (void) fprintf(STDOUT, " if ( '/' == com[n] ) {\n");
2494 (void) fprintf(STDOUT, " str[n] = '\\\\';\n");
2495 (void) fprintf(STDOUT, " } else {\n");
2496 (void) fprintf(STDOUT, " str[n] = com[n];\n");
2497 (void) fprintf(STDOUT, " }\n");
2498 (void) fprintf(STDOUT, " }\n");
2499 (void) fprintf(STDOUT, " str[n] = '\\0';\n");
2500
2501 (void) strcpy(command, "str");
2502#else
2503 (void) strcpy(command, "com");
2504#endif
2505 if (Title_Flag) {
2506 (void) fprintf(STDOUT, " if ( NO != all ) {\n");
2507 (void) fprintf(STDOUT, " (void) fprintf(fp, \"\\n **** NAPA Standalone Simulator,\");\n");
2508 (void) fprintf(STDOUT, " (void) fprintf(fp, \" Build of %s\\n\\n\");\n", NAPA_Compile_Time);
2509 (void) fprintf(STDOUT, " }\n");
2510 (void) snprintf(tok1, (size_t) (LINLENGTH-1L), "%s", Title_String);
2511 str1 = tok1;
2512 str2 = tok2;
2513 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\");\n" );
2514 while (ISNOTEMPTY(str1)) {
2515 str1 = extract_line(str1, str2);
2516 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** %s\\n\");\n", str2);
2517 }
2518 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\\n\");\n");
2519 if ((0L == Num_Cmdlines) && (!Comment_Flag)) {
2520 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** USAGE: %%s\\n\\n\", %s);\n", command);
2521 } else {
2522 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** USAGE: %%s %s\\n\", %s);\n", Cmdline_String, command);
2523 }
2524 } else {
2525 (void) fprintf(STDOUT, " if ( NO != all ) {\n");
2526 (void) fprintf(STDOUT, " (void) fprintf(fp, \"\\n **** NAPA Standalone Simulator,\");\n");
2527 (void) fprintf(STDOUT, " (void) fprintf(fp, \" Build of %s\\n\");\n", NAPA_Compile_Time);
2528 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\");\n" );
2529 (void) fprintf(STDOUT, " }\n");
2530 if ((0L == Num_Cmdlines) && (!Comment_Flag)) {
2531 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** USAGE: %%s\\n\\n\", %s);\n", command);
2532 } else {
2533 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** USAGE: %%s %s\\n\", %s);\n", Cmdline_String, command);
2534 }
2535 }
2536 if (0L < Num_Cmdlines) {
2537 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\");\n" );
2538 len1 = 0;
2539 len2 = 0;
2540 for (j = 0L; j < Num_Cmdlines; j++) { /* process each expected parameter */
2541 len1 = MAX((int) strlen(Cmdline_List[j].parms), len1); /* max length of string for print */
2542 len2 = MAX((int) strlen(Cmdline_List[j].comment), len2); /* max length of string for print */
2543 }
2544 len2 += 2; /* we will have to add two double quotes to strings */
2545 for (j = 0L; j < Num_Cmdlines; j++) { /* process each expected parameter */
2546 if ((0 == strcmp(Cmdline_List[j].parms, "fs")) || (0 == strcmp(Cmdline_List[j].parms, "ts"))) {
2547 typ = ANALOG_DATA_TYPE;
2548 } else {
2549 nv = var_id(Cmdline_List[j].parms);
2550 if (UNDEFINED == nv) {
2551 continue; /* already syntaxed, just in case */
2552 }
2553 typ = Var_List[nv].type;
2554 }
2555 switch (typ) {
2556 case DIGITAL_DATA_TYPE :
2557 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** %-*s <- [digital]", len1, Cmdline_List[j].parms);
2558 break;
2559 case ANALOG_DATA_TYPE :
2560 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** %-*s <- [ analog]", len1, Cmdline_List[j].parms);
2561 break;
2562 case STRING_DATA_TYPE : /* replace slashes by backslashes */
2563 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** %-*s <- [ string]", len1, Cmdline_List[j].parms);
2564 break;
2565 }
2566 len3 = (int) strlen(Cmdline_List[j].comment);
2567 if (0 < len3) {
2568 if (STRING_DATA_TYPE == typ) {
2569 (Cmdline_List[j].comment)[len3-1] = '\0'; /* remove 1st and last character which are spaces */
2570 (void) fprintf(STDOUT, " ( \\\"%s\\\"%*s)\\n\");\n", Cmdline_List[j].comment+1, len2-len3-1, " ");
2571 } else {
2572 (void) fprintf(STDOUT, " ( %s%*s)\\n\");\n", Cmdline_List[j].comment, len2-len3-1, " ");
2573 }
2574 } else {
2575 (void) fprintf(STDOUT, "\\n\");\n");
2576 }
2577 if ((j > Num_Cmdlines) && (!Comment_Flag)) {
2578 (void) fprintf(STDOUT, "\\n\n");
2579 }
2580 }
2581 }
2582 if (Comment_Flag) {
2583 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\");\n");
2584 for (i = 0L; i < Num_Comments; i++) {
2585 (void) fprintf(STDOUT, " (void) fprintf(fp, \" **** %-s\\n\");\n", Comment_String[i]);
2586 }
2587 (void) fprintf(STDOUT, " (void) fprintf(fp, \" ****\\n\");\n");
2588 }
2589 (void) fprintf(STDOUT, " (void) fprintf(fp, \"\\n\\n\");\n");
2590 (void) fprintf(STDOUT, " return;\n");
2591 (void) fprintf(STDOUT, "}\n");
2592 return;
2593}
2594
2595
2597 if (0 == Error_Flag) {
2598 (void) fprintf(STDOUT, "\n\n/* *** NAPA SIMULATOR FUNCTIONS %s */\n\n", multiple('*', 95L));
2599 }
2600 (void) fprintf(STDOUT, "void napa_control_init(void) {\n");
2601 if (Cmdline_Flag) {
2602 (void) fprintf(STDOUT, " const struct tm *d;\n");
2603 (void) fprintf(STDOUT, " time_t t;\n");
2604 }
2605 (void) fprintf(STDOUT, " srand((unsigned int) (RANDOM_SEED %% ((I_TYPE) RAND_MAX)));\n");
2606 if (Cmdline_Flag) {
2607 (void) fprintf(STDOUT, " t = time((time_t*) NULL);\n");
2608 (void) fprintf(STDOUT, " d = localtime(&t);\n");
2609 (void) fprintf(STDOUT, " (void) snprintf(napa_sim_time, (size_t) 25, \"%%s\", ctime(&t));\n");
2610 (void) fprintf(STDOUT, " (void) snprintf(napa_job_id, (size_t) 31, \"%%4d%%02d%%02d_%%02d%%02d%%02d\",\n");
2611 (void) fprintf(STDOUT, " (*d).tm_year+1900, (*d).tm_mon+1, (*d).tm_mday, (*d).tm_hour, (*d).tm_min, (*d).tm_sec);\n");
2612 }
2613 (void) fprintf(STDOUT, " napa_seed = NAPA_SEED;\n"); /* define before calling first NAPA functions ! */
2614 (void) fprintf(STDOUT, " napa_root = NAPA_ROOT;\n");
2615 (void) fprintf(STDOUT, " napa_rand = NAPA_RAND;\n");
2616 (void) fprintf(STDOUT, " napa_wall_clock = clock();\n");
2617 if (0L != Seed_List.rndseed) {
2618 (void) fprintf(STDOUT, " napa_random_seed = napa_seed(RANDOM_SEED);\n");
2619 } else {
2620 (void) fprintf(STDOUT, " napa_random_seed = napa_seed(0LL);\n" );
2621 }
2622 (void) fprintf(STDOUT, " napa_init();\n");
2623 (void) fprintf(STDOUT, " if ( 0 != atexit(napa_end) ) {\n");
2624 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (atexit)\\n\");\n");
2625 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" registering of 'napa_end()' did not succeed\\n\" );\n");
2626 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
2627 (void) fprintf(STDOUT, " }\n");
2628 (void) fprintf(STDOUT, " if ( 0 != atexit(napa_close) ) {\n");
2629 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (atexit)\\n\");\n");
2630 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" registering of 'napa_close()' did not succeed\\n\");\n");
2631 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
2632 (void) fprintf(STDOUT, " }\n");
2634 (void) fprintf(STDOUT, " return;\n");
2635 (void) fprintf(STDOUT, "}\n");
2637 return;
2638}
2639
2640
2642 if ((0L == Num_Vars) && (0L == Num_Injects)) {
2643 return;
2644 }
2645 (void) fprintf(STDOUT, "\nvoid napa_reset_variables(void) {\n");
2647 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\");\n");
2648 (void) fprintf(STDOUT, " return;\n");
2649 (void) fprintf(STDOUT, "}\n");
2650 return;
2651}
2652
2653
2655 long i;
2656 double factor, rate1, rate2;
2657 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) { /* here, impossible to assign value in declare */
2658 if (1L < Num_Segments) {
2659 if (Periodic_Flag) {
2660 for (i = 0L; i < Num_Segments; i++) {
2661 rate1 = Segment_List[0].rate;
2662 rate2 = Segment_List[i].rate;
2663 factor = GCD(rate1, rate2);
2664 rate1 /= factor;
2665 rate2 /= factor;
2666 if (ISNOTEQUAL(rate1, rate2)) {
2667 if ((ISNOTEQUAL(1.0, rate1)) && (ISNOTEQUAL(1.0, rate2))) {
2668 (void) fprintf(STDOUT, " napa_fsl[%ld] = (FS * %.1fL) / %.1fL;\n", i, rate1, rate2);
2669 } else if ((ISNOTEQUAL(1.0, rate1)) && (ISEQUAL(1.0, rate2))) {
2670 (void) fprintf(STDOUT, " napa_fsl[%ld] = FS * %.1fL;\n", i, rate1);
2671 } else if ((ISEQUAL(1.0, rate1)) && (ISNOTEQUAL(1.0, rate2))) {
2672 (void) fprintf(STDOUT, " napa_fsl[%ld] = FS / %.1fL;\n", i, rate2);
2673 }
2674 } else {
2675 (void) fprintf(STDOUT, " napa_fsl[%ld] = FS;\n", i);
2676 }
2677 }
2678 }
2679 }
2680 }
2681 return;
2682}
2683
2684
2686 char v1[STRLENGTH] = {'\0'};
2687 long i;
2688 long na = 0L;
2689 long nb = 0L;
2690 long nc = 0L;
2691 if ((!Loop_Flag) || (!Tool_Flag)) {
2692 return;
2693 } else {
2694 na = Interlude_List.number1 * ((long) Simulation_Rate); /* correction to correspond to FS rate */
2695 nb = (Interlude_List.number2 * ((long) Simulation_Rate)) - na;
2696 nc = Interlude_List.number3 * ((long) Simulation_Rate);
2697 (void) fprintf(STDOUT, "\n\nvoid napa_tool_setup(void) {\n");
2698 }
2699 if ((2 <= Num_UserTools) && (Synchro_Flag) && (Tool_Flag)) {
2700 (void) fprintf(STDOUT, " long mb;\n");
2701 }
2702 if ((Synchro_Flag) && (Tool_Flag) && (Interlude_Flag1)) {
2703 (void) fprintf(STDOUT, " napa_packet = 0LL;\n" );
2704 if (!Interlude_Flag2) {
2705 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
2706 } else {
2707 if ((0L == na) && (0L == nb)) {
2708 (void) fprintf(STDOUT, " napa_tool_start = 0LL;\n" );
2709 }
2710 if ((0L != na) && (0L == nb)) {
2711 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
2712 }
2713 if ((0L == na) && (0L != nb)) {
2714 (void) fprintf(STDOUT, " napa_tool_start = napa_rand_integer(%ldLL);\n", nb);
2715 if (0L != nc) {
2716 (void) fprintf(STDOUT, " napa_tool_start = (napa_tool_start / %ldLL) * %ldLL;\n", nc, nc);
2717 }
2718 }
2719 if ((0L != na) && (0L != nb)) {
2720 (void) fprintf(STDOUT, " napa_tool_start = %ldLL + napa_rand_integer(%ldLL);\n", na, nb);
2721 if (0L != nc) {
2722 (void) fprintf(STDOUT, " napa_tool_start = (napa_tool_start / %ldLL) * %ldLL;\n", nc, nc);
2723 }
2724 }
2725 }
2726 }
2727 for (i = 0L; i < Num_UserTools; i++) {
2728 if (UNDEFINED == UserTool_List[i].mailbox) { /* i.e. if not a tool but a user function */
2729 continue;
2730 }
2731 (void) strcpy(v1, UserTool_List[i].name);
2732 (void) build_name("", v1, LEFT_VALUE);
2733 (void) fprintf(STDOUT, " napa_msg = &(napa_mailbox[%ld]);\n", UserTool_List[i].mailbox );
2734 (void) fprintf(STDOUT, " (void) strcpy(napa_msg->u, \"%s\");\n", v1);
2735 (void) fprintf(STDOUT, " (void) strcpy(napa_msg->t, \"%s\");\n", UserTool_List[i].function);
2736 (void) fprintf(STDOUT, " napa_msg->m = %ldL;\n", UserTool_List[i].mailbox );
2737 (void) fprintf(STDOUT, " napa_msg->s = %ldL;\n", UserTool_List[i].segment );
2738 }
2739 if (1L == Num_Tools) {
2740 if (!Interlude_Flag1) {
2741 (void) fprintf(STDOUT, " napa_msg->i = START;\n");
2742 } else {
2743 (void) fprintf(STDOUT, " napa_msg->i = STOP;\n" );
2744 }
2745 (void) fprintf(STDOUT, " napa_msg->o = -1LL;\n" );
2746 (void) fprintf(STDOUT, " napa_msg->n = 0L;\n" );
2747 (void) fprintf(STDOUT, " napa_msg->store_i = (long*) NULL;\n");
2748 (void) fprintf(STDOUT, " napa_msg->store_l = (I_TYPE*) NULL;\n");
2749 (void) fprintf(STDOUT, " napa_msg->store_d = (R_TYPE*) NULL;\n");
2750 (void) fprintf(STDOUT, " napa_msg->store_s = (C_TYPE**) NULL;\n");
2751 }
2752 if (2L <= Num_Tools) {
2753 (void) fprintf(STDOUT, " for (mb = 0L; mb < %ldL; mb++) {\n", Num_Tools);
2754 (void) fprintf(STDOUT, " napa_msg = &(napa_mailbox[mb]);\n");
2755 if (!Interlude_Flag1) {
2756 (void) fprintf(STDOUT, " napa_msg->i = START;\n");
2757 } else {
2758 (void) fprintf(STDOUT, " napa_msg->i = STOP;\n" );
2759 }
2760 (void) fprintf(STDOUT, " napa_msg->o = -1LL;\n");
2761 (void) fprintf(STDOUT, " napa_msg->n = 0L;\n" );
2762 (void) fprintf(STDOUT, " napa_msg->store_i = (long*) NULL;\n");
2763 (void) fprintf(STDOUT, " napa_msg->store_l = (I_TYPE*) NULL;\n");
2764 (void) fprintf(STDOUT, " napa_msg->store_d = (R_TYPE*) NULL;\n");
2765 (void) fprintf(STDOUT, " napa_msg->store_s = (C_TYPE**) NULL;\n");
2766 (void) fprintf(STDOUT, " }\n");
2767 }
2768 if ((Synchro_Flag) && (0L < Num_Tools)) {
2769 (void) fprintf(STDOUT, " napa_tool_index = napa_packet - 1LL;\n" );
2770 }
2771 (void) fprintf(STDOUT, " return;\n");
2772 (void) fprintf(STDOUT, "}\n\n");
2773 return;
2774}
2775
2776
2778 long i, j, k;
2779 long nseg, prev_nseg;
2780 NAPA_DIGITAL_TYPE lltemp1, lltemp2;
2781 long d, n, m, p;
2782 long m1;
2783 char tok[STRLENGTH] = {'\0'};
2784 char buf[STRLENGTH] = {'\0'};
2785 char v0[LINLENGTH] = {'\0'};
2786 char v1[LINLENGTH] = {'\0'};
2787 char v2[LINLENGTH] = {'\0'};
2788 char v3[LINLENGTH] = {'\0'};
2789 char *str1 = (char*) NULL;
2790 char *str2 = (char*) NULL;
2791 int flag, proceed;
2792 m1 = 0L;
2793 prev_nseg = -1L;
2794
2795 for (k = 0L; k < Num_Vars; k++) { /* scan list of variables: init, dvar/ivar/string */
2796 i = (k + Num_Vars - Num_Consts) % Num_Vars; /* place created constants first */
2797 if (0L > i) {
2798 i = k + Num_Consts;
2799 }
2800 /* change segment if necessary */
2801 nseg = Var_List[i].segment;
2802 if (nseg != prev_nseg) {
2803 if (1L < Num_Segments) { /* not necessary if only one segment */
2804 (void) fprintf(STDOUT, " napa_segment = %ldL;\n", nseg);
2805 }
2806 prev_nseg = nseg;
2807 }
2808 /* skip nulled initialization */
2809 if (0 == strncmp(Var_List[i].name1, "$null$", (size_t) 6)) {
2810 continue;
2811 }
2812 /* command_line parameter already processed */
2813 if ((Cmdline_Flag) && (Var_List[i].external)) {
2814 continue;
2815 }
2816 if (0 == strcmp(Var_List[i].value, "void")) {
2817 Var_List[i].constant = false; /* hidden update possible */
2818 }
2819 clean_line(Var_List[i].value);
2820 if (0 == strcmp(Var_List[i].value, " ")) {
2821 (void) strcpy(Var_List[i].value, "" );
2822 }
2823 if ((ISNOTEMPTY(Var_List[i].value)) && (0 != strcmp(Var_List[i].value, "void"))) {
2824 str1 = Var_List[i].value;
2825 } else { /* if there is no value, use def type initial value */
2826 switch (Var_List[i].type) {
2827 case DIGITAL_DATA_TYPE :
2828 (void) strcpy(tok, "DIGITAL_INI");
2829 break;
2830 case ANALOG_DATA_TYPE :
2831 (void) strcpy(tok, "ANALOG_INI" );
2832 break;
2833 case STRING_DATA_TYPE :
2834 (void) strcpy(tok, "");
2835 break;
2836 }
2837 str1 = tok;
2838 }
2839 /* the parm list is now ready to be processed and is guaranteed to be not empty */
2840 /* 'str1' points to the parm list */
2841 j = 0L; /* counter to separate left/right val */
2842
2843 /* variable is an explicit initialization defined by instruction 'init' */
2844 if (0 == strncmp(Var_List[i].name1, "$init$", (size_t) 6)) {
2845 (void) fprintf(STDOUT, " ");
2846 for (;;) { /* get symbols and vars, token by token, add to eq. */
2847 str1 = get_token(str1, tok, true);
2848 j++;
2849 if (ISEMPTY(tok)) {
2850 (void) fprintf(STDOUT, ";\n");
2851 break;
2852 }
2853 n = var_id(tok);
2854 m = node_id(tok);
2855 if (UNDEFINED != n) {
2856 (void) strcpy(v1, Var_List[n].name1);
2857 if (1L == j) { /* left value */
2858 /* initializing a variable! this is not allowed in an instruction 'init' */
2859 m1 = m;
2860 print_error_location("init", Var_List[i].mline, Var_List[i].mfile);
2861 (void) fprintf(STDERR, " a variable is initialized only during its declaration,\n");
2862 (void) fprintf(STDERR, " use the variable definition to initialize <%s>\n", Var_List[n].name1);
2863 } else {
2864 (void) build_name("", v1, RIGHT_VALUE);
2865 (void) fprintf(STDOUT, "%s", v1);
2866 }
2867 } else if (UNDEFINED != m) { /* not yet initialized node replaced by future val */
2868 if (1L == j) { /* left value */
2869 /* initializing a node ! this is allowed in an instruction 'init' */
2870 m1 = m;
2871 if (Node_List[m].init) {
2872 print_error_location("init", Var_List[i].mline, Var_List[i].mfile);
2873 (void) fprintf(STDERR, " overwriting previous initialization of node <%s>\n", Node_List[m].name1);
2874 }
2875 Node_List[m].init = true; /* mark as initialized */
2876 (void) fprintf(STDOUT, "init_%s = ", Node_List[m].name1);
2877 } else { /* right value */
2878 print_warning_location( "init", Var_List[i].mline, Var_List[i].mfile);
2879 (void) fprintf(STDERR, " at this point, nodes being not yet defined,\n");
2880 if (DIGITAL_DATA_TYPE == Node_List[m].type) {
2881 (void) fprintf(STDERR, " value of <%s> is replaced by DIGITAL_INI\n", Node_List[m].name1);
2882 (void) fprintf(STDOUT, "DIGITAL_INI"); /* digital nodes not yet initialized */
2883 } else {
2884 (void) fprintf(STDERR, " value of <%s> is replaced by ANALOG_INI\n", Node_List[m].name1);
2885 (void) fprintf(STDOUT, "ANALOG_INI" ); /* analog nodes not yet initialized */
2886 }
2887 }
2888 } else {
2889 if (1L == j) { /* left value */
2890 /* not a node nor a variable ! */
2891 m1 = m;
2892 if (0 == strcmp(tok, "void")) { /* function returning void is allowed */
2893 (void) fprintf(STDOUT, "(void) ");
2894 } else {
2895 (void) fprintf(STDOUT, "%s = ", tok); /* not a node nor a user variable */
2896 print_error_location( "init", Update_List[i].mline, Update_List[i].mfile);
2897 (void) fprintf(STDERR, " <%s> is not a defined node\n", tok);
2898 process_node_error(tok);
2899 }
2900 } else { /* right value */
2901 (void) fprintf(STDOUT, "%s", tok);
2902 }
2903 }
2904 }
2905 if (UNDEFINED != m1) {
2906 if (DIGITAL_DATA_TYPE == Node_List[m1].type) { /* process register arithmetic if any */
2907 str2 = Node_List[m1].name1;
2908 if (0L < Node_List[m1].width) {
2909 lltemp1 = 1LL << (Node_List[m1].width - 1L);
2910 lltemp2 = (2LL*lltemp1) - 1LL;
2911 (void) fprintf(STDOUT, " init_%s = (init_%s & ( 0X%llXLL))\n", str2, str2, lltemp1);
2912 (void) fprintf(STDOUT, " %*s ? (init_%s | (-0X%llXLL))\n", 5 + ((int) strlen(str2)), " ", str2, lltemp1);
2913 (void) fprintf(STDOUT, " %*s : (init_%s & ( 0X%llXLL));\n", 5 + ((int) strlen(str2)), " ", str2, lltemp2);
2914 } else if (0L > Node_List[m1].width) {
2915 lltemp1 = (1LL << -Node_List[m1].width) - 1LL;
2916 (void) fprintf(STDOUT, " init_%s &= 0X%llXLL;\n", str2, lltemp1);
2917 }
2918 }
2919 }
2920
2921 /* special variable defined by instruction 'declare (true) a_boolean_valued_function()' */
2922 } else if (0 == strncmp(Var_List[i].name1, "$declare$", (size_t) 9)) {
2923 flag = false;
2924 for (j = i+1L; j < Num_Vars; j++) { /* avoid repeated declarations ! */
2925 if (0 == strncmp(Var_List[j].name1, "$declare$", (size_t) 9)) {
2926 if (0 == strcmp(Var_List[i].value, Var_List[j].value)) {
2927 flag = true;
2928 }
2929 }
2930 }
2931 if (!flag) { /* new declaration */
2932 (void) strcpy(buf, str1);
2933 str2 = buf;
2934 (void) strcpy(v1, "" );
2935 proceed = false;
2936 for (;;) {
2937 str2 = get_token(str2, tok, true);
2938 if (ISEMPTY(tok)) {
2939 break;
2940 }
2941 m = node_id(tok);
2942 if (UNDEFINED != m) {
2943 print_warning_location( "declare", Var_List[i].mline, Var_List[i].mfile);
2944 (void) fprintf(STDERR, "\n Condition ( %s ) is inactivated\n", buf);
2945 (void) fprintf(STDERR, " as nodes cannot be tested before being initialized\n");
2946 proceed = true;
2947 break;
2948 }
2949 n = var_id(tok);
2950 (void) strcpy(v0, v1);
2951 if (UNDEFINED == n) {
2952 (void) snprintf(v1, (size_t) (LINLENGTH-1L), "%s%s", v0, tok);
2953 } else {
2954 (void) snprintf(v1, (size_t) (LINLENGTH-1L), "%s%s", v0, Var_List[n].name1);
2955 }
2956 }
2957 if (proceed) {
2958 continue;
2959 }
2960 (void) strcpy(buf, str1);
2961 (void) fprintf(STDOUT, " if ( !(");
2962 for (;;) { /* get symbols and vars, token by token, add to eq. */
2963 str1 = get_token(str1, tok, true);
2964 j++;
2965 if (ISEMPTY(tok)) {
2966 (void) fprintf(STDOUT, ") ) {\n");
2967 if (!Cmdline_Flag) { /* command line error message does not need header */
2968 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (declare)\\n\");\n");
2969 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Var_List[i].mline[0]);
2970 for (d = 1L; d < MAXDEPTH; d++) {
2971 if (0UL == Var_List[i].mline[d]) {
2972 break;
2973 }
2974 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
2975 Var_List[i].mline[d], Record_Cell_File_Table[Var_List[i].mfile[d]]);
2976 }
2977 }
2978 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n The condition [ %s ] is not satisfied!\\n\");\n", v1);
2979 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
2980 (void) fprintf(STDOUT, " }\n");
2981 break;
2982 }
2983 (void) build_name("", tok, RIGHT_VALUE);
2984 (void) fprintf(STDOUT, "%s", tok);
2985 }
2986 }
2987
2988 /* variable is regular variable defined by instructions 'ivar', 'dvar' or 'string' */
2989 } else {
2990 if (STRING_DATA_TYPE != Var_List[i].type) { /* dvar or ivar type but not svar */
2991 (void) strcpy(v1, Var_List[i].name1);
2992 (void) build_name("", v1, LEFT_VALUE);
2993 if (2 == Var_List[i].event) {
2994 (void) strcpy(v2, v1);
2995 (void) snprintf(v1, (size_t) (LINLENGTH-1L), "ivar_%s", Var_List[i].name1);
2996 (void) strcpy(v3, v1);
2997 }
2998 (void) fprintf(STDOUT, " %s = ", v1);
2999 for (;;) { /* get symbols and other vars, and add to equation */
3000 str1 = get_token(str1, tok, true); /* keep quotes */
3001 if (ISEMPTY(tok)) {
3002 (void) fprintf(STDOUT, ";\n");
3003 break;
3004 }
3005 m = node_id(tok);
3006 n = var_id(tok);
3007 if (UNDEFINED != n) {
3008 (void) strcpy(v1, Var_List[n].name1);
3009 (void) build_name("", v1, RIGHT_VALUE);
3010 (void) fprintf(STDOUT, "%s", v1);
3011 } else if (UNDEFINED != m) { /* node ! uninitialized nodes will be replaced by 0 */
3012 p = update_id(Var_List[i].name1, 1L); /* test the variable being initialised */
3013 if (UNDEFINED == p) { /* the variable is never updated */
3014 switch (Var_List[i].type) {
3015 case DIGITAL_DATA_TYPE :
3016 print_warning_location( "ivar", Var_List[i].mline, Var_List[i].mfile);
3017 break;
3018 case ANALOG_DATA_TYPE :
3019 print_warning_location( "dvar", Var_List[i].mline, Var_List[i].mfile);
3020 break;
3021 }
3022 (void) fprintf(STDERR, " Node <%s>: during the initialization of variables, nodes are not yet defined!\n", Node_List[m].name1);
3023 (void) fprintf(STDERR, " You should consider to add an update to the variable <%s>.\n", Var_List[i].name1);
3024 }
3025 if (DIGITAL_DATA_TYPE == Node_List[m].type) {
3026 (void) fprintf(STDOUT, "DIGITAL_INI");
3027 } else {
3028 (void) fprintf(STDOUT, "ANALOG_INI" );
3029 }
3030 } else {
3031 (void) fprintf(STDOUT, "%s", tok);
3032 }
3033 }
3034 if (2 == Var_List[i].event) {
3035 (void) fprintf(STDOUT, " %s_old = %s;\n", v3, v3);
3036 }
3037 if (DIGITAL_DATA_TYPE == Var_List[i].type) { /* specific process for digital variable */
3038 str2 = Var_List[i].name1; /* register arithmetic */
3039 (void) strcpy(v1, str2);
3040 (void) build_name("", v1, LEFT_VALUE);
3041 if (0L < Var_List[i].width) {
3042 lltemp1 = 1LL << (Var_List[i].width - 1L);
3043 lltemp2 = (2LL*lltemp1) - 1LL;
3044 (void) fprintf(STDOUT, " %s = (%s & ( 0X%llXLL))\n", v1, v1, lltemp1);
3045 (void) fprintf(STDOUT, " %*s ? (%s | (-0X%llXLL))\n", (int) strlen(str2), " ", v1, lltemp1);
3046 (void) fprintf(STDOUT, " %*s : (%s & ( 0X%llXLL));\n", (int) strlen(str2), " ", v1, lltemp2);
3047 } else if (0L > Var_List[i].width) {
3048 lltemp1 = (1LL << -Var_List[i].width) - 1LL;
3049 (void) fprintf(STDOUT, " %s &= 0X%llXLL;\n", v1, lltemp1);
3050 } /* otherwise, i.e. width is 0, do nothing */
3051 }
3052 } else {
3053 str2 = Var_List[i].name1; /* string type */
3054 (void) strcpy(v1, str2);
3055 (void) build_name("", v1, LEFT_VALUE);
3056 (void) fprintf(STDOUT, " (void) strcpy(%s,", v1);
3057 str1 = get_token(str1, tok, false); /* remove double quotes if any */
3058 expand_indirections(tok); /* expand variable string */
3059 (void) fprintf(STDOUT, " \"%s\");\n", tok); /* add brand new quotes */
3060 }
3061 }
3062 }
3063
3064 if (0L < Num_Injects) { /* node injections */
3065 for (i = 0L; i < Num_Injects; i++) {
3066 n = node_id(Inject_List[i].name);
3067 (void) fprintf(STDOUT, " inject_%s = 0.0;\n", Node_List[n].name1);
3068 }
3069 }
3070 return;
3071}
3072
3073
3075 long i, n;
3076 long kd, tp, tpaddr;
3077 char tok[STRLENGTH] = {'\0'};
3078 char v1[LINLENGTH] = {'\0'};
3079 char v2[LINLENGTH] = {'\0'};
3080 char v3[LINLENGTH] = {'\0'};
3081 int flag;
3082
3083 if (!Array_Flag) {
3084 return;
3085 }
3086
3087 flag = false;
3088 for (i = 0L; i < Num_Arrays; i++) { /* arrays for ROM and RAM */
3089 if (!Array_List[i].used) {
3090 continue;
3091 }
3092 if (ISNOTEMPTY(Array_List[i].fname)) {
3093 flag = true; /* need a few specific declarations */
3094 }
3095 }
3096
3097 (void) fprintf(STDOUT, "\nvoid napa_array_setup(IO_COMMAND command) {\n");
3098 if (!flag) {
3099 (void) fprintf(STDOUT, " I_TYPE i;\n");
3100 } else {
3101 (void) fprintf(STDOUT, " I_TYPE i, j, k;\n");
3102 (void) fprintf(STDOUT, " char *p = (char*) NULL;\n");
3103 (void) fprintf(STDOUT, " char buffer[%ld] = {'\\0'};\n", STRLENGTH + 1L);
3104 (void) fprintf(STDOUT, " char *string = (char*) NULL;\n");
3105 (void) fprintf(STDOUT, " char *tail = (char*) NULL;\n");
3106 }
3107 (void) fprintf(STDOUT, " switch(command) {\n");
3108 (void) fprintf(STDOUT, " case ALLOCATE:\n");
3109 tp = 0L;
3110 for (i = 0L; i < Num_Arrays; i++) { /* arrays for ROM and RAM */
3111 if (!Array_List[i].used) {
3112 continue;
3113 }
3114 kd = Array_List[i].kind;
3115 if (UNKNOWN_KIND == kd) {
3116 continue;
3117 }
3118 tp = Array_List[i].type;
3119 if (ISNOTEMPTY(Array_List[i].fname)) {
3120 n = var_id(Array_List[i].fname);
3121 if (UNDEFINED != n) {
3122 (void) strcpy(tok, Var_List[n].name1);
3123 (void) strcpy(v1, tok);
3124 (void) build_name("", v1, RIGHT_VALUE);
3125 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENREAD, &napa_fp_%ld, %s, \"\", \"array\");\n", i, v1);
3126 } else {
3127 (void) strcpy(tok, Array_List[i].fname);
3128 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENREAD, &napa_fp_init_%ld, \"%s\", \"\", \"array\");\n", i, tok);
3129 }
3130 }
3131 (void) strcpy(v1, Array_List[i].size);
3132 if (UNKNOWN_TYPE == constant_type(v1)) {
3133 if (UNDEFINED == var_id(v1)) {
3134 print_error_location( "array", Array_List[i].mline, Array_List[i].mfile);
3135 (void) fprintf(STDERR, " size <%s> of array <%s[]> is not a constant nor a variable\n", v1, Array_List[i].name);
3137 exit(EXIT_FAILURE);
3138 }
3139 if (UNDEFINED != update_id(v1, 1)) {
3140 print_error_location( "array", Array_List[i].mline, Array_List[i].mfile);
3141 (void) fprintf(STDERR, " variable <%s> determining the size of array <%s[]> cannot be updated\n",
3142 v1, Array_List[i].name);
3143 exit(EXIT_FAILURE);
3144 }
3145 }
3146 tpaddr = get_type(v1);
3147 if ((DIGITAL_DATA_TYPE != tpaddr) && (HEX_DATA_TYPE != tpaddr)) {
3148 print_error_location( "array", Array_List[i].mline, Array_List[i].mfile);
3149 (void) fprintf(STDERR, " size <%s> of array <%s[]> must be integer type\n", v1, Array_List[i].name);
3150 exit(EXIT_FAILURE);
3151 }
3152 (void) build_name("", v1, RIGHT_VALUE);
3153 (void) strcpy(v2, Array_List[i].name);
3154 (void) strcpy(v3, Array_List[i].name);
3155 (void) build_name("", v2, LEFT_VALUE);
3156 if ((RAM_KIND == Array_List[i].kind) || (RAM2_KIND == Array_List[i].kind)) {
3157 (void) fprintf(STDOUT, " %s.last = 0.0L;\n", v2);
3158 }
3159 (void) fprintf(STDOUT, " %s.length = %s;\n", v2, v1);
3160 (void) fprintf(STDOUT, " if ( 0L >= %s.length ) {\n", v2);
3161 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (array)\\n\");\n");
3162 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Size of array <%s[%%lld]> must be strictly positive\\n\", %s.length);\n",
3163 Array_List[i].name, v2);
3164 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3165 (void) fprintf(STDOUT, " }\n");
3166 switch (kd) {
3167 case RAM_KIND:
3168 case RAM2_KIND:
3169 if (ANALOG_DATA_TYPE == tp) {
3170 (void) fprintf(STDOUT, " %s.flag = (int*) calloc((size_t) %s.length, sizeof (int ));\n", v2, v2);
3171 (void) fprintf(STDOUT, " %s.data = (R_TYPE*) calloc((size_t) %s.length, sizeof (R_TYPE));\n", v2, v2);
3172 (void) fprintf(STDOUT, " if ( ((int*) NULL == %s.flag) || ((R_TYPE*) NULL == %s.data) ) {\n", v2, v2);
3173 } else {
3174 (void) fprintf(STDOUT, " %s.flag = (int*) calloc((size_t) %s.length, sizeof (int ));\n", v2, v2);
3175 (void) fprintf(STDOUT, " %s.data = (I_TYPE*) calloc((size_t) %s.length, sizeof (I_TYPE));\n", v2, v2);
3176 (void) fprintf(STDOUT, " if ( ((int*) NULL == %s.flag) || ((I_TYPE*) NULL == %s.data) ) {\n", v2, v2);
3177 }
3178 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (array)\\n\");\n");
3179 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" A dynamic memory allocation error occurred when\");\n" );
3180 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" processing RAM array <%s[%%lld]>\\n\", %s.length);\n", v3, v2);
3181 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3182 (void) fprintf(STDOUT, " }\n");
3183 break;
3184 case ROM_KIND:
3185 case ROM2_KIND:
3186 if (ANALOG_DATA_TYPE == tp) {
3187 (void) fprintf(STDOUT, " %s.data = (R_TYPE*) calloc((size_t) %s.length, sizeof (R_TYPE));\n", v2, v2);
3188 (void) fprintf(STDOUT, " if ( (R_TYPE*) NULL == %s.data ) {\n", v2);
3189 } else {
3190 (void) fprintf(STDOUT, " %s.data = (I_TYPE*) calloc((size_t) %s.length, sizeof (I_TYPE));\n", v2, v2);
3191 (void) fprintf(STDOUT, " if ( (I_TYPE*) NULL == %s.data ) {\n", v2);
3192 }
3193 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (array)\\n\");\n");
3194 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" A dynamic memory allocation error occurred when\");\n" );
3195 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" processing ROM array <%s[%%lld]>\\n\", %s.length);\n", v3, v2);
3196 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3197 (void) fprintf(STDOUT, " }\n");
3198 break;
3199 }
3200 if (ISEMPTY(Array_List[i].fname)) { /* no file ! */
3201 if (ROM_KIND == Array_List[i].kind) {
3202 print_error_location("rom", Array_List[i].mline, Array_List[i].mfile);
3203 (void) fprintf(STDERR, " the ROM array <%s> needs an initialization file\n", v3);
3204 }
3205 switch (Array_List[i].type) {
3206 case DIGITAL_DATA_TYPE :
3207 case HEX_DATA_TYPE :
3208 if (RAM2_KIND == Array_List[i].kind ) {
3209 (void) fprintf(STDOUT, " %s.rw = 0LL;\n", v2);
3210 }
3211 if ((RAM2_KIND == Array_List[i].kind ) || (ROM2_KIND == Array_List[i].kind )) {
3212 (void) fprintf(STDOUT, " %s.address = 0LL;\n", v2);
3213 }
3214 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3215 if ((RAM_KIND == Array_List[i].kind ) || (RAM2_KIND == Array_List[i].kind )) {
3216 (void) fprintf(STDOUT, " %s.flag[i] = false;\n", v2);
3217 }
3218 (void) fprintf(STDOUT, " %s.data[i] = DIGITAL_INI;\n", v2);
3219 (void) fprintf(STDOUT, " }\n");
3220 break;
3221 case ANALOG_DATA_TYPE :
3222 if (RAM2_KIND == Array_List[i].kind ) {
3223 (void) fprintf(STDOUT, " %s.rw = 0LL;\n", v2);
3224 }
3225 if ((RAM2_KIND == Array_List[i].kind ) || (ROM2_KIND == Array_List[i].kind )) {
3226 (void) fprintf(STDOUT, " %s.address = 0LL;\n", v2);
3227 }
3228 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3229 if ((RAM_KIND == Array_List[i].kind ) || (RAM2_KIND == Array_List[i].kind )) {
3230 (void) fprintf(STDOUT, " %s.flag[i] = false;\n", v2);
3231 }
3232 (void) fprintf(STDOUT, " %s.data[i] = ANALOG_INI;\n", v2);
3233 (void) fprintf(STDOUT, " }\n");
3234 break;
3235 default:
3236 break;
3237 }
3238 } else { /* read a file */
3239 if (RAM2_KIND == Array_List[i].kind ) {
3240 (void) fprintf(STDOUT, " %s.rw = 0LL;\n", v2);
3241 }
3242 if ((RAM2_KIND == Array_List[i].kind ) || (ROM2_KIND == Array_List[i].kind )) {
3243 (void) fprintf(STDOUT, " %s.address = 0LL;\n", v2);
3244 }
3245 (void) fprintf(STDOUT, " i = 0L;\n");
3246 (void) fprintf(STDOUT, " k = 1L;\n");
3247 (void) fprintf(STDOUT, " p = fgets(buffer, %ld, napa_fp_init_%ld);\n", STRLENGTH, i);
3248 (void) fprintf(STDOUT, " while ( ((char*) NULL != p) && (i < %s.length) ) {\n", v2);
3249 (void) fprintf(STDOUT, " string = buffer;\n");
3250 (void) fprintf(STDOUT, " if ( '#' != *string ) {\n");
3251 (void) fprintf(STDOUT, " while ( (int) isspace(*string) ) {\n");
3252 (void) fprintf(STDOUT, " string++;\n");
3253 (void) fprintf(STDOUT, " }\n");
3254 (void) fprintf(STDOUT, " if ( '\\0' == *string ) {\n");
3255 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\\n\");\n", v3);
3256 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> array file <\\\"%s\\\">, at line %%lld\\n\", k);\n", Array_List[i].fname);
3257 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" line is empty\\n\");\n");
3258 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3259 (void) fprintf(STDOUT, " }\n");
3260 (void) fprintf(STDOUT, " j = strtoll(string, &tail, 0);\n" );
3261 (void) fprintf(STDOUT, " string = tail;\n");
3262 (void) fprintf(STDOUT, " while ( (int) isspace(*string) ) {\n");
3263 (void) fprintf(STDOUT, " string++;\n");
3264 (void) fprintf(STDOUT, " }\n");
3265 (void) fprintf(STDOUT, " if ( '\\0' == *string ) {\n");
3266 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\\n\");\n", v3);
3267 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> array file <\\\"%s\\\">, at line %%lld\\n\", k);\n", Array_List[i].fname);
3268 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" data is missing\\n\");\n");
3269 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3270 (void) fprintf(STDOUT, " }\n");
3271 switch (Array_List[i].type) {
3272 case DIGITAL_DATA_TYPE :
3273 (void) fprintf(STDOUT, " if ( 2 > sscanf(buffer, \"%%lli %%lli\", &j, &(%s.data[i])) ) {\n", v2);
3274 break;
3275 case ANALOG_DATA_TYPE :
3276 (void) fprintf(STDOUT, " if ( 2 > sscanf(buffer, \"%%lli %%lf\", &j, &(%s.data[i])) ) {\n", v2);
3277 break;
3278 case HEX_DATA_TYPE :
3279 (void) fprintf(STDOUT, " if ( 2 > sscanf(buffer, \"%%lli 0x%%llx\", &j, &(%s.data[i])) ) {\n", v2);
3280 break;
3281 default:
3282 break;
3283 }
3284 (void) fprintf(STDOUT, " break;\n");
3285 (void) fprintf(STDOUT, " }\n");
3286
3287 if ((RAM_KIND == Array_List[i].kind ) || (RAM2_KIND == Array_List[i].kind )) {
3288 (void) fprintf(STDOUT, " %s.flag[i] = false;\n", v2);
3289 }
3290 (void) fprintf(STDOUT, " if ( i != j ) {\n");
3291 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\\n\");\n", v3);
3292 if (UNDEFINED != var_id(Array_List[i].fname)) {
3293 print_error_location("array", Array_List[i].mline, Array_List[i].mfile);
3294 (void) fprintf(STDERR, " the initialization file of the array <%s>", v3);
3295 (void) fprintf(STDERR, " cannot be parameterized by a variable\n");
3296 } else {
3297 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> array file <\\\"%s\\\">, at line %%lld\\n\", k);\n",
3298 Array_List[i].fname);
3299 }
3300 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" data is not properly numbered\\n\");\n");
3301 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3302 (void) fprintf(STDOUT, " }\n");
3303 (void) fprintf(STDOUT, " i++;\n");
3304 (void) fprintf(STDOUT, " }\n");
3305 (void) fprintf(STDOUT, " k++;\n");
3306 (void) fprintf(STDOUT, " p = fgets(buffer, %ld, napa_fp_init_%ld);\n", STRLENGTH, i);
3307 (void) fprintf(STDOUT, " }\n");
3308 (void) fprintf(STDOUT, " if ( %s.length != i ) {\n", v2);
3309 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\\n\");\n", v3);
3310 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> array file <\\\"%s\\\"> contains %%lld numbers,\\n\", i);\n", v3);
3311 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" but declaration of <%s[]> asked for\");\n", Array_List[i].name );
3312 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %%lld coefficients...\\n\", %s.length);\n", v2);
3313 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3314 (void) fprintf(STDOUT, " }\n");
3315 }
3316 if (ISNOTEMPTY(Array_List[i].fname)) {
3317 n = var_id(Array_List[i].fname);
3318 if (UNDEFINED != n) {
3319 (void) strcpy(tok, Var_List[n].name1);
3320 (void) strcpy(v2, tok);
3321 (void) build_name("", v2, RIGHT_VALUE);
3322 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_init_%ld, %s, \"\", \"array\");\n", i, v3);
3323 } else {
3324 (void) strcpy(tok, Array_List[i].fname);
3325 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_init_%ld, \"%s\", \"\", \"array\");\n", i, tok);
3326 }
3327 }
3328 }
3329 (void) fprintf(STDOUT, " break;\n");
3330 (void) fprintf(STDOUT, " case FREE:\n");
3331 for (i = 0L; i < Num_Arrays; i++) { /* arrays for ROM and RAM */
3332 if (!Array_List[i].used) {
3333 continue;
3334 }
3335 kd = Array_List[i].kind;
3336 if (UNKNOWN_KIND == kd) {
3337 continue;
3338 }
3339 (void) strcpy(v1, Array_List[i].size);
3340 (void) build_name("", v1, RIGHT_VALUE);
3341 (void) strcpy(v2, Array_List[i].name);
3342 (void) build_name("", v2, LEFT_VALUE);
3343 if ((RAM_KIND == kd) || (RAM2_KIND == kd)) {
3344 (void) fprintf(STDOUT, " free(%s.flag);\n", v2);
3345 (void) fprintf(STDOUT, " %s.flag = (int*) NULL;\n", v2);
3346 }
3347 (void) fprintf(STDOUT, " free(%s.data);\n", v2);
3348 (void) fprintf(STDOUT, " %s.data = (I_TYPE*) NULL;\n", v2);
3349 }
3350 (void) fprintf(STDOUT, " break;\n");
3351 (void) fprintf(STDOUT, " case RESET:\n");
3352 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\\n\");\n", v3);
3353 switch (tp) {
3354 case DIGITAL_DATA_TYPE :
3355 case HEX_DATA_TYPE :
3356 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" no reset possible for digital arrays\\n\");\n");
3357 break;
3358 case ANALOG_DATA_TYPE :
3359 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" no reset possible for analog arrays\\n\");\n" );
3360 break;
3361 default:
3362 break;
3363 }
3364 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3365 (void) fprintf(STDOUT, " case DEBUG:\n");
3366 for (i = 0L; i < Num_Arrays; i++) {
3367 if (!Array_List[i].used) {
3368 continue;
3369 }
3370 kd = Array_List[i].kind;
3371 if (UNKNOWN_KIND == kd) {
3372 continue;
3373 }
3374 tp = Array_List[i].type;
3375 (void) strcpy(v1, Array_List[i].size);
3376 (void) build_name("", v1, RIGHT_VALUE);
3377 (void) strcpy(v2, Array_List[i].name);
3378 (void) build_name("", v2, LEFT_VALUE);
3379 switch (tp) {
3380 case DIGITAL_DATA_TYPE :
3381 case HEX_DATA_TYPE :
3382 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Debug Information: (digital array) <%s>)\\n\");\n", Array_List[i].name);
3383 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" simulation loop # %%lld\\n\", LOOP_INDEX);\n");
3384 if ((RAM_KIND == kd) || (RAM2_KIND == kd)) {
3385 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3386 (void) fprintf(STDOUT, " if ( !%s.flag[i] ) {;\n", v2);
3387 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = ?\\n\", i);\n", Array_List[i].name);
3388 (void) fprintf(STDOUT, " } else {\n");
3389 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = %% lld\\n\", i, %s.data[i]);\n", Array_List[i].name, v2);
3390 (void) fprintf(STDOUT, " }\n");
3391 (void) fprintf(STDOUT, " }\n");
3392 } else {
3393 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3394 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = %% lld\\n\", i, %s.data[i]);\n", Array_List[i].name, v2);
3395 (void) fprintf(STDOUT, " }\n");
3396 }
3397 break;
3398 case ANALOG_DATA_TYPE :
3399 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Debug Information: (analog array) <%s>)\\n\");\n", Array_List[i].name);
3400 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" simulation loop # %%lld\\n\", LOOP_INDEX);\n");
3401 if ((RAM_KIND == kd) || (RAM2_KIND == kd)) {
3402 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3403 (void) fprintf(STDOUT, " if ( !%s.flag[i] ) {;\n", v2);
3404 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = ?\\n\", i);\n", Array_List[i].name);
3405 (void) fprintf(STDOUT, " } else {\n");
3406 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = %% 14e\\n\", i, %s.data[i]);\n", Array_List[i].name, v2);
3407 (void) fprintf(STDOUT, " }\n");
3408 (void) fprintf(STDOUT, " }\n");
3409 } else {
3410 (void) fprintf(STDOUT, " for (i = 0L; i < %s.length; i++) {\n", v2);
3411 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" %s[%%3lld] = %% 14e\\n\", i, %s.data[i]);\n", Array_List[i].name, v2);
3412 (void) fprintf(STDOUT, " }\n");
3413 }
3414 break;
3415 default:
3416 break;
3417 }
3418 }
3419 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\");\n");
3420 (void) fprintf(STDOUT, " break;\n");
3421 (void) fprintf(STDOUT, " default:\n");
3422 (void) fprintf(STDOUT, " break;\n");
3423 (void) fprintf(STDOUT, " }\n" );
3424 (void) fprintf(STDOUT, " return;\n" );
3425 (void) fprintf(STDOUT, "}\n" );
3426 return;
3427}
3428
3429
3431 long i, j, nr, nc, sz;
3432 long typ;
3433 int len;
3434 int newline;
3435 char *s = (char*) NULL;
3436 char *s1 = (char*) NULL;
3437 char *s2 = (char*) NULL;
3438 char sgn[2] = {'\0'};
3439 char tok[STRLENGTH] = {'\0'};
3440 char tok1[STRLENGTH] = {'\0'};
3441 char tok2[STRLENGTH] = {'\0'};
3442 char v1[LINLENGTH] = {'\0'};
3443 char v2[LINLENGTH] = {'\0'};
3444 if (!Pointer_Flag) {
3445 return;
3446 }
3447 (void) fprintf(STDOUT, "\nvoid napa_record_setup(IO_COMMAND command) {\n");
3448 for (i = 0L; i < Num_Records; i++) { /* arrays of pointers */
3449 if (!Record_List[i].used) {
3450 continue; /* skip unused records */
3451 }
3452 newline = false;
3453 sz = Record_List[i].size;
3454 (void) strcpy(v1, Record_List[i].name);
3455 (void) build_name("", v1, LEFT_VALUE);
3456 len = fprintf(STDOUT, " static char *%s[2][%ld] =", Record_List[i].name, sz);
3457 if (Record_List[i].nflag) {
3458 (void) fprintf(STDOUT, " %*s /* transfer of parameters by name %*s */\n", 76-len, " ", 15, " ");
3459 }
3460 if (Record_List[i].pflag) {
3461 (void) fprintf(STDOUT, " %*s /* transfer of parameters by position %*s */\n", 76-len, " ", 11, " ");
3462 }
3463 (void) fprintf(STDOUT, " { {");
3464 s1 = Record_List[i].list1; /* list of variables */
3465 s2 = Record_List[i].list2; /* list of targets for passing parameters by name */
3466 j = 0;
3467 for (;;) {
3468 s1 = get_sign_and_token(s1, sgn, tok1);
3469 s2 = get_sign_and_token(s2, sgn, tok2);
3470 len = 1 + ((int) (MAX(strlen(tok1), strlen(tok2)) - strlen(tok1)));
3471 if (ISEMPTY(tok1)) {
3472 break;
3473 }
3474 if (newline) {
3475 (void) fprintf(STDOUT, ",");
3476 (void) fprintf(STDOUT, "\n %s", " ");
3477 newline = false;
3478 }
3479 (void) snprintf(tok, (size_t) (STRLENGTH-1L), "\"%s\"", tok1);
3480 if (0 == j) {
3481 (void) fprintf(STDOUT, "%*s%s", len, " ", tok );
3482 } else {
3483 (void) fprintf(STDOUT, ",%*s%s", len, " ", tok );
3484 }
3485 j++;
3486 }
3487 (void) fprintf(STDOUT, " },\n" );
3488 (void) fprintf(STDOUT, " {");
3489 s1 = Record_List[i].list1; /* list of variables */
3490 s2 = Record_List[i].list2; /* list of targets for passing parameters by name */
3491 j = 0;
3492 for (;;) {
3493 s1 = get_sign_and_token(s1, sgn, tok1);
3494 s2 = get_sign_and_token(s2, sgn, tok2);
3495 len = 1 + ((int) (MAX(strlen(tok1), strlen(tok2)) - strlen(tok2)));
3496 if (ISEMPTY(tok2)) {
3497 break;
3498 }
3499 if (newline) {
3500 (void) fprintf(STDOUT, "," );
3501 (void) fprintf(STDOUT, "\n %s", " ");
3502 newline = false;
3503 }
3504 (void) snprintf(tok, (size_t) (STRLENGTH-1L), "\"%s\"", tok2);
3505 if (0 == j) {
3506 (void) fprintf(STDOUT, "%*s%s", len, " ", tok );
3507 } else {
3508 (void) fprintf(STDOUT, ",%*s%s", len, " ", tok );
3509 }
3510 j++;
3511 }
3512 (void) fprintf(STDOUT, " } };\n");
3513 }
3514 for (i = 0L; i < Num_Records; i++) { /* arrays of pointers */
3515 if (!Record_List[i].used) {
3516 continue; /* skip unused records */
3517 }
3518 sz = Record_List[i].size;
3519 nr = Record_List[i].nrow;
3520 nc = Record_List[i].ncol;
3521 (void) strcpy(v1, Record_List[i].name);
3522 (void) build_name("", v1, LEFT_VALUE);
3523 (void) fprintf(STDOUT, " (void) napa_record_manager(command, &%s, %2ldL, %2ldL, %2ldL, \"%s\");\n", v1, sz, nr, nc, Record_List[i].name);
3524 }
3525 (void) fprintf(STDOUT, " switch (command) {\n");
3526 (void) fprintf(STDOUT, " case ALLOCATE:\n" ); /* memory allocated by 'napa_alloc_data_record' */
3527 for (i = 0L; i < Num_Records; i++) { /* arrays of pointers */
3528 if (!Record_List[i].used) {
3529 continue;
3530 }
3531 (void) strcpy(v1, Record_List[i].name);
3532 (void) build_name("", v1, LEFT_VALUE);
3533 s = Record_List[i].list1; /* list of variables */
3534 j = 0L;
3535 (void) fprintf(STDOUT, " %s.s_ptr = %s[0];\n", v1, Record_List[i].name);
3536 (void) fprintf(STDOUT, " %s.n_ptr = %s[1];\n", v1, Record_List[i].name);
3537 for (;;) {
3538 s = get_sign_and_token(s, sgn, tok);
3539 if (ISEMPTY(tok)) {
3540 break;
3541 }
3542 typ = get_type(tok);
3543 (void) strcpy(v2, tok);
3544 (void) build_name("", v2, RIGHT_VALUE);
3545 if (DIGITAL_DATA_TYPE == typ) {
3546 (void) fprintf(STDOUT, " %s.i_ptr[%2ld] = &%s;\n", v1, j, v2);
3547 } else if (ANALOG_DATA_TYPE == typ) {
3548 (void) fprintf(STDOUT, " %s.d_ptr[%2ld] = &%s;\n", v1, j, v2);
3549 } else if (STRING_DATA_TYPE == typ) {
3550 (void) fprintf(STDOUT, " %s.c_ptr[%2ld] = %s;\n", v1, j, v2);
3551 }
3552 j++;
3553 }
3554 if (!Record_List[i].nflag) {
3555 (void) fprintf(STDOUT, " %s.nflag = false;\n", v1);
3556 } else {
3557 (void) fprintf(STDOUT, " %s.nflag = true;\n", v1);
3558 }
3559 if (!Record_List[i].pflag) {
3560 (void) fprintf(STDOUT, " %s.pflag = false;\n", v1);
3561 } else {
3562 (void) fprintf(STDOUT, " %s.pflag = true;\n", v1);
3563 }
3564 }
3565 (void) fprintf(STDOUT, " break;\n" );
3566 (void) fprintf(STDOUT, " case RESET:\n");
3567 (void) fprintf(STDOUT, " case FREE:\n" );
3568 (void) fprintf(STDOUT, " break;\n" ); /* memory freed by 'napa_alloc_data_record' */
3569 (void) fprintf(STDOUT, " case DEBUG:\n");
3570 (void) fprintf(STDOUT, " if ( (3 > napa_waypoint) || (5 < napa_waypoint) ) {\n");
3571 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Debug Information: (array of pointers)\\n\\n\");\n");
3572 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" simulation loop # %%lld\\n\", LOOP_INDEX);\n");
3573 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" the pointers of all arrays are currently pointing to NULL\\n\");\n");
3574 (void) fprintf(STDOUT, " break;\n" );
3575 (void) fprintf(STDOUT, " }\n");
3576 for (i = 0L; i < Num_Records; i++) { /* arrays of pointers */
3577 if (!Record_List[i].used) {
3578 continue;
3579 }
3580 (void) strcpy(v1, Record_List[i].name);
3581 (void) build_name("", v1, LEFT_VALUE);
3582 s = Record_List[i].list1; /* list of variables */
3583 j = 0L;
3584 len = 0;
3585 for (;;) {
3586 s = get_sign_and_token(s, sgn, tok);
3587 if (ISEMPTY(tok)) {
3588 break;
3589 }
3590 len = MAX((int) strlen(tok), len);
3591 j++;
3592 }
3593 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Debug Information: (array of pointers: %s[%ld])\\n\\n\");\n",
3594 Record_List[i].name, j);
3595 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" simulation loop # %%lld\\n\", LOOP_INDEX);\n");
3596 s = Record_List[i].list1; /* list of variables */
3597 j = 0L;
3598 for (;;) {
3599 s = get_sign_and_token(s, sgn, tok);
3600 if (ISEMPTY(tok)) {
3601 break;
3602 }
3603 typ = get_type(tok);
3604 (void) strcpy(v2, tok);
3605 (void) build_name("", v2, RIGHT_VALUE);
3606 if (DIGITAL_DATA_TYPE == typ) {
3607 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" (digital) %-*s = %% lld\\n\", *(%s.i_ptr)[%ld]);\n", len,tok,v1,j);
3608 } else if (ANALOG_DATA_TYPE == typ) {
3609 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" ( analog) %-*s = %% 14e\\n\", *(%s.d_ptr)[%ld]);\n", len,tok,v1,j);
3610 } else if (STRING_DATA_TYPE == typ) {
3611 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" ( string) %-*s = \\\"%%s\\\"\\n\", (%s.c_ptr)[%ld]);\n",len,tok,v1,j);
3612 }
3613 j++;
3614 }
3615 }
3616 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\");\n");
3617 (void) fprintf(STDOUT, " break;\n");
3618 (void) fprintf(STDOUT, " default:\n");
3619 (void) fprintf(STDOUT, " break;\n");
3620 (void) fprintf(STDOUT, " }\n" );
3621 (void) fprintf(STDOUT, " return;\n" );
3622 (void) fprintf(STDOUT, "}\n" );
3623 return;
3624}
3625
3626
3628 long d, i;
3629 if (((!Debug_Flag) && (!Directive_Flag)) || (Cmdline_Flag)) { /* no directive to be checked for usage */
3630 return;
3631 }
3632 (void) fprintf(STDOUT, "\n\n/* *** GENERATE WARNINGS ONLY WHEN DIRECTIVES ARE NOT REGISTERED");
3633 (void) fprintf(STDOUT, " IN USER DEFINED FUNCTIONS AS EXPECTED %s */\n", multiple('*', 24L));
3634 (void) fprintf(STDOUT, "\nvoid napa_check_directives(void) {\n");
3635 for (d = 0L; d < Num_Directives; d++) {
3636 if (Directive_List[d].used) {
3637 continue;
3638 }
3639 (void) fprintf(STDOUT, "#if !defined(%s_IS_REGISTERED)\n", Directive_List[d].name);
3640 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"NAPA Run Time Warning: ( directive)\\n\");\n");
3641 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Directive_List[d].mline[0]);
3642 for (i = 1L; i < MAXDEPTH; i++) {
3643 if (0UL == Directive_List[d].mline[i]) {
3644 break;
3645 }
3646 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
3647 Directive_List[d].mline[i], Record_Cell_File_Table[Directive_List[d].mfile[i]]);
3648 }
3649 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" The directive <%s> is not REGISTERED\\n\\n\");\n", Directive_List[d].name);
3650 (void) fprintf(STDOUT, " napa_timer(1L);\n");
3651 (void) fprintf(STDOUT, "#endif\n");
3652 }
3653 for (d = 0L; d < Num_Debugs; d++) {
3654 if (0 == strcmp(Debug_List[d].name, "IO")) {
3655 continue;
3656 }
3657 (void) fprintf(STDOUT, "#if !defined(DEBUG_MODE_%s_IS_REGISTERED) \n", Debug_List[d].name );
3658 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"NAPA Run Time Warning: ( debug)\\n\");\n");
3659 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Debug_List[d].mline[0]);
3660 for (i = 1L; i < MAXDEPTH; i++) {
3661 if (0UL == Debug_List[d].mline[i]) {
3662 break;
3663 }
3664 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
3665 Debug_List[d].mline[i], Record_Cell_File_Table[Debug_List[d].mfile[i]]);
3666 }
3667 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" The debugging directive <%s> has no effect in the context\\n\\n\");\n",
3668 Debug_List[d].name);
3669 (void) fprintf(STDOUT, " napa_timer(1L);\n");
3670 (void) fprintf(STDOUT, "#endif\n" );
3671 }
3672 (void) fprintf(STDOUT, " return;\n");
3673 (void) fprintf(STDOUT, "}\n");
3674 return;
3675}
3676
3677
3679 long i;
3680 long nseg;
3681 if (0L >= Num_Nodes) {
3682 return;
3683 }
3684 (void) fprintf(STDOUT, "\nvoid napa_reset_nodes(void) {\n");
3685 if (Multdelay_Flag) {
3686 (void) fprintf(STDOUT, " long i;\n");
3687 }
3688 nseg = -999L;
3689 i = 0L;
3690 while (i < Num_Nodes) {
3691 if (Node_List[i].segment != nseg) {
3692 nseg = Node_List[i].segment;
3693 if (1L < Num_Segments) { /* not necessary if only one segment */
3694 (void) fprintf(STDOUT, " napa_segment = %ldL;\n", nseg);
3695 }
3696 }
3697 if (DC_KIND != Node_List[i].kind) {
3698 switch (Node_List[i].type) {
3699 case DIGITAL_DATA_TYPE :
3701 break;
3702 case ANALOG_DATA_TYPE :
3704 break;
3705 default:
3706 break;
3707 }
3708 } else { /* dc node */
3709 reset_a_dc_node(i);
3710 }
3711 i++;
3712 }
3713 (void) fprintf(STDOUT, " return;\n");
3714 (void) fprintf(STDOUT, "}\n" );
3715 return;
3716}
3717
3718
3720 long j, c, d, n, p, u, v;
3721 long kd;
3722 long ndel;
3723 char tok1[STRLENGTH] = {'\0'};
3724 char tok2[STRLENGTH] = {'\0'};
3725 char v1[LINLENGTH] = {'\0'};
3726 char v2[LINLENGTH] = {'\0'};
3727 char v3[LINLENGTH] = {'\0'};
3728 char *str = (char*) NULL;
3729 char *nm = (char*) NULL;
3730
3731 nm = Node_List[i].name1;
3732 kd = Node_List[i].kind;
3733 (void) strcpy(v1, nm);
3734 (void) build_name("", v1, LEFT_VALUE);
3735 /* regular reset of I_TYPE nodes */
3736 if (Node_List[i].init) { /* node initialized by "init" */
3737 (void) fprintf(STDOUT, " %s = init_%s;\n", v1, nm);
3738 } else {
3739 (void) fprintf(STDOUT, " %s = DIGITAL_INI;\n", v1 );
3740 }
3741 /* additional reset for specific nodes */
3742 str = Node_List[i].value;
3743 switch (kd) {
3744 case DELAY_KIND: /* unprocessed value: number node_name */
3745 str = get_token(str, tok1, false); /* get number of delay */
3746 str = get_token(str, tok2, false); /* get input node */
3747 n = node_id(tok2);
3748 if (Node_List[n].init) { /* input node initialized by "init" */
3749 (void) strcpy(v3, "init_");
3750 (void) strcat(v3, Node_List[n].name1);
3751 } else {
3752 (void) strcpy(v3, "DIGITAL_INI");
3753 }
3754 v = var_id(tok1);
3755 if (UNDEFINED != v) {
3756 if (DIGITAL_DATA_TYPE != Var_List[v].type) {
3757 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3758 (void) fprintf(STDERR, " the number of delays must be an integer or a digital variable\n");
3759 break;
3760 }
3761 u = update_id(tok1, 1);
3762 if (UNDEFINED != u) {
3763 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3764 (void) fprintf(STDERR, " the number of delays must be a constant and cannot be updated\n");
3765 (void) fprintf(STDERR, " this variable is updated\n\n");
3766 print_location(Update_List[u].mline, Update_List[u].mfile);
3767 break;
3768 }
3769 (void) strcpy(v2, Var_List[v].name1);
3770 (void) build_name("", v2, RIGHT_VALUE);
3771 (void) fprintf(STDOUT, " if ( 1L > %s ) {\n", v2);
3772 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (delay)\\n\");\n");
3773 if (!Cmdline_Flag) {
3774 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Node_List[i].mline[0]);
3775 for (d = 1L; d < MAXDEPTH; d++) {
3776 if (0UL == Node_List[i].mline[d]) {
3777 break;
3778 }
3779 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
3780 Node_List[i].mline[d], Record_Cell_File_Table[Node_List[i].mfile[d]]);
3781 }
3782 }
3783 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" The number of delays of node <%s> cannot be smaller than 1\\n\");\n", nm);
3784 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Its current value is <%%lld>\\n\", %s);\n", v2);
3785 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3786 (void) fprintf(STDOUT, " }\n");
3787 (void) fprintf(STDOUT, " if ( 2 == napa_waypoint ) {\n");
3788 (void) fprintf(STDOUT, " %s_delay = (I_TYPE*) malloc((size_t)(%s * sizeof (I_TYPE)));\n", v1, v2);
3789 (void) fprintf(STDOUT, " if ((I_TYPE*) NULL == %s_delay) {\n", v1 );
3790 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (delay)\\n\");\n" );
3791 if (!Cmdline_Flag) {
3792 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Node_List[i].mline[0]);
3793 for (d = 1L; d < MAXDEPTH; d++) {
3794 if (0UL == Node_List[i].mline[d]) {
3795 break;
3796 }
3797 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
3798 Node_List[i].mline[d], Record_Cell_File_Table[Node_List[i].mfile[d]]);
3799 }
3800 }
3801 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Dynamic memory allocation error for node <%s>\\n\");\n", Node_List[i].name1);
3802 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3803 (void) fprintf(STDOUT, " }\n");
3804 (void) fprintf(STDOUT, " }\n");
3805 (void) fprintf(STDOUT, " for (i = 0L; i < %s; i++) {\n", v2 );
3806 (void) fprintf(STDOUT, " %s_delay[i] = %s;\n", v1, v3);
3807 (void) fprintf(STDOUT, " }\n");
3808 (void) fprintf(STDOUT, " pnode_%s_ptr = 1L;\n", nm );
3809 } else {
3810 if (1 != sscanf(tok1, "%li", &ndel)) {
3811 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3812 (void) fprintf(STDERR, " the number of delays is not a well-formed positive C long integer <%s>\n", tok1);
3813 return;
3814 }
3815 (void) fprintf(STDOUT, " for (i = 0L; i < %ldL; i++) {\n", ndel);
3816 (void) fprintf(STDOUT, " %s_delay[i] = %s;\n", v1, v3);
3817 (void) fprintf(STDOUT, " }\n");
3818 (void) fprintf(STDOUT, " pnode_%s_ptr = 1L;\n", nm );
3819 }
3820 break;
3821 case DELAY2_KIND: /* unprocessed value: node_name */
3822 str = get_token(str, tok1, false); /* get number of delays */
3823 str = get_token(str, tok2, false); /* get input node */
3824 n = node_id(tok2);
3825 if (Node_List[n].init) { /* input node initialized by "init" */
3826 (void) strcpy(v3, "init_");
3827 (void) strcat(v3, Node_List[n].name1);
3828 } else {
3829 (void) strcpy(v3, "DIGITAL_INI");
3830 }
3831 (void) fprintf(STDOUT, " %s_delay = %s;\n", v1, v3);
3832 break;
3833 case DELAY3_KIND: /* unprocessed value: node_name */
3834 str = get_token(str, tok1, false); /* get number of delays */
3835 str = get_token(str, tok2, false); /* get input node */
3836 n = node_id(tok2);
3837 if (Node_List[n].init) { /* input node initialized by "init" */
3838 (void) strcpy(v3, "init_");
3839 (void) strcat(v3, Node_List[n].name1);
3840 } else {
3841 (void) strcpy(v3, "DIGITAL_INI");
3842 }
3843 (void) fprintf(STDOUT, " %s_delay[0] = %s;\n", v1, v3);
3844 (void) fprintf(STDOUT, " %s_delay[1] = %s;\n", v1, v3);
3845 break;
3846 case DIFFERENTIATOR_KIND: /* unprocessed value: node_name */
3847 (void) fprintf(STDOUT, " %s_delay = DIGITAL_INI;\n", v1 );
3848 break;
3849 case TRIG_KIND: /* unprocessed value: [sgn]val node mod */
3850 str = get_token(str, tok1, false);
3851 if ((0 == strcmp(tok1, "+")) || (0 == strcmp(tok1, "-"))) {
3852 str = get_token(str, tok1, false); /* skip sign and trig */
3853 }
3854 str = get_token(str, tok1, false); /* get the input node name */
3855 n = node_id(tok1);
3856 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
3857 (void) fprintf(STDOUT, " inode_%s_store = DIGITAL_INI;\n", nm);
3858 } else {
3859 (void) fprintf(STDOUT, " dnode_%s_store = ANALOG_INI;\n", nm);
3860 }
3861 break;
3862 case CHG_KIND: /* unprocessed value: _node_name */
3863 str = get_token(str, tok1, false); /* get the input node name */
3864 n = node_id(tok1);
3865 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
3866 (void) fprintf(STDOUT, " inode_%s_store = DIGITAL_INI;\n", nm);
3867 } else {
3868 (void) fprintf(STDOUT, " dnode_%s_store = ANALOG_INI;\n", nm);
3869 }
3870 break;
3871 case CLOCK_KIND: /* unprocessed value: value widening */
3872 c = 0L;
3873 p = 0L;
3874 str = get_token(str, tok1, false);
3875 str = get_token(str, tok2, false);
3876 for (j = 0L; j < LENGTH(tok1); j++) {
3877 if ('0' == tok1[j]) {
3878 (void) fprintf(STDOUT, " %s_clock[%ldL] = 0LL;\n", v1, c);
3879 c++;
3880 } else if ('1' == tok1[j]) {
3881 (void) fprintf(STDOUT, " %s_clock[%ldL] = 1LL;\n", v1, c);
3882 c++;
3883 } else if ('.' == tok1[j]) {
3884 p = c;
3885 } else {
3886 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3887 (void) fprintf(STDERR, " <%c> is not allowed in the pattern descriptor\n", tok1[j]);
3888 break;
3889 }
3890 }
3891 if (p >= c) {
3892 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3893 (void) fprintf(STDERR, " the right part of the pattern descriptor is missing\n" );
3894 }
3895 if (0 == strcmp("1", tok2)) {
3896 (void) fprintf(STDOUT, " pnode_%s_ini = %ldL;\n", nm, p);
3897 (void) fprintf(STDOUT, " pnode_%s_ptr1 = %dL;\n", nm, 0);
3898 } else {
3899 (void) build_name("", tok2, RIGHT_VALUE);
3900 (void) fprintf(STDOUT, " pnode_%s_ini = %ldL;\n", nm, p);
3901 (void) fprintf(STDOUT, " pnode_%s_ptr1 = %dL;\n", nm, 0);
3902 (void) fprintf(STDOUT, " pnode_%s_ptr2 = %dL;\n", nm, -1);
3903 (void) fprintf(STDOUT, " pnode_%s_width = (P_TYPE) %s;\n", nm, tok2);
3904 if (UNKNOWN_TYPE == constant_type(tok2)) {
3905 (void) build_name("", tok2, RIGHT_VALUE);
3906 (void) fprintf(STDOUT, " if ( 0L >= pnode_%s_width ) {\n", nm );
3907 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (%s)\\n\");\n", "clock");
3908 if (!Cmdline_Flag) {
3909 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Node_List[i].mline[0]);
3910 for (d = 1L; d < MAXDEPTH; d++) {
3911 if (0UL == Node_List[i].mline[d]) {
3912 break;
3913 }
3914 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
3915 Node_List[i].mline[d], Record_Cell_File_Table[Node_List[i].mfile[d]]);
3916 }
3917 }
3918 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n the widening of the clock must be a strictly positive integer\\n\");\n");
3919 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
3920 (void) fprintf(STDOUT, " }\n");
3921 }
3922 }
3923 break;
3924 case LATCH_KIND: /* unprocessed value: set reset */
3925 str = get_token(str, tok1, false);
3926 (void) fprintf(STDOUT, " inode_%s_set = DIGITAL_INI;\n", nm);
3927 (void) fprintf(STDOUT, " inode_%s_rst = DIGITAL_INI;\n", nm);
3928 break;
3929 case ZERO_KIND: /* unprocessed value: decim_fact node_name */
3930 (void) fprintf(STDOUT, " inode_%s_ctr = DIGITAL_INI;\n", nm);
3931 break;
3932 default:
3933 break;
3934 }
3935 return;
3936}
3937
3938
3940 long d, n, u, v;
3941 long ndel;
3942 double dtemp1;
3943 long kd;
3944 char tok1[STRLENGTH] = {'\0'};
3945 char tok2[STRLENGTH] = {'\0'};
3946 char v1[LINLENGTH] = {'\0'};
3947 char v2[LINLENGTH] = {'\0'};
3948 char v3[LINLENGTH] = {'\0'};
3949 char sgn[2] = {'\0'};
3950 char *str = (char*) NULL;
3951 char *nm = (char*) NULL;
3952 int flag;
3953
3954 nm = Node_List[i].name1;
3955 kd = Node_List[i].kind;
3956 (void) strcpy(v1, nm);
3957 (void) build_name("", v1, LEFT_VALUE);
3958 /* regular reset of I_TYPE nodes */
3959 if (Node_List[i].init) { /* node initialized by "init" */
3960 (void) fprintf(STDOUT, " %s = init_%s;\n", v1, nm);
3961 } else {
3962 (void) fprintf(STDOUT, " %s = ANALOG_INI;\n", v1 );
3963 }
3964 /* additional reset for specific nodes */
3965 str = Node_List[i].value;
3966 switch (kd) {
3967 case DELAY_KIND: /* unprocessed value: number node_name */
3968 str = get_sign_and_token(str, sgn, tok1); /* get number of delays */
3969 str = get_sign_and_token(str, sgn, tok2); /* get input node */
3970 n = node_id(tok2);
3971 if (Node_List[n].init) { /* input node initialized by "init" */
3972 (void) strcpy(v3, "init_");
3973 (void) strcat(v3, Node_List[n].name1);
3974 } else {
3975 (void) strcpy(v3, "ANALOG_INI");
3976 }
3977 v = var_id(tok1);
3978 if (UNDEFINED != v) {
3979 if (DIGITAL_DATA_TYPE != Var_List[v].type) {
3980 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3981 (void) fprintf(STDERR, " the number of delays must be an integer or a digital variable\n");
3982 break;
3983 }
3984 u = update_id(tok1, 1);
3985 if (UNDEFINED != u) {
3986 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
3987 (void) fprintf(STDERR, " the number of delays must be a constant and cannot be updated\n");
3988 (void) fprintf(STDERR, " this variable is updated\n\n");
3989 print_location(Update_List[u].mline, Update_List[u].mfile);
3990 break;
3991 }
3992 (void) strcpy(v2, Var_List[v].name1);
3993 (void) build_name("", v2, RIGHT_VALUE);
3994 (void) fprintf(STDOUT, " if ( 1L > %s ) {\n", v2);
3995 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (delay)\\n\");\n");
3996 if (!Cmdline_Flag) {
3997 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Node_List[i].mline[0]);
3998 for (d = 1L; d < MAXDEPTH; d++) {
3999 if (0UL == Node_List[i].mline[d]) {
4000 break;
4001 }
4002 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
4003 Node_List[i].mline[d], Record_Cell_File_Table[Node_List[i].mfile[d]]);
4004 }
4005 }
4006 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" The number of delays of node <%s> cannot be smaller than 1\\n\");\n", nm);
4007 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Its current value is <%%lld>\\n\", %s);\n", v2);
4008 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
4009 (void) fprintf(STDOUT, " }\n");
4010 (void) fprintf(STDOUT, " if ( 2 == napa_waypoint ) {\n");
4011 (void) fprintf(STDOUT, " %s_delay = (R_TYPE*) malloc((size_t)(%s * sizeof (R_TYPE)));\n", v1, v2);
4012 (void) fprintf(STDOUT, " if ( (R_TYPE*) NULL == %s_delay ) {\n", v1 );
4013 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (delay)\\n\");\n");
4014 if (!Cmdline_Flag) {
4015 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", Node_List[i].mline[0]);
4016 for (d = 1L; d < MAXDEPTH; d++) {
4017 if (0UL == Node_List[i].mline[d]) {
4018 break;
4019 }
4020 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
4021 Node_List[i].mline[d], Record_Cell_File_Table[Node_List[i].mfile[d]]);
4022 }
4023 }
4024 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Dynamic memory allocation error for node <%s>\\n\");\n", Node_List[i].name1);
4025 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
4026 (void) fprintf(STDOUT, " }\n");
4027 (void) fprintf(STDOUT, " }\n");
4028 (void) fprintf(STDOUT, " for (i = 0L; i < %s; i++) {\n", v2);
4029 (void) fprintf(STDOUT, " %s_delay[i] = %s;\n", v1, v3);
4030 (void) fprintf(STDOUT, " }\n");
4031 (void) fprintf(STDOUT, " pnode_%s_ptr = 1L;\n", nm);
4032 } else {
4033 if (1 != sscanf(tok1, "%li", &ndel)) {
4034 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4035 (void) fprintf(STDERR, " the number of delays is not a well-formed positive C long integer <%s>\n", tok1);
4036 return;
4037 }
4038 (void) fprintf(STDOUT, " for (i = 0L; i < %ldL; i++) {\n", ndel);
4039 (void) fprintf(STDOUT, " %s_delay[i] = %s;\n", v1, v3);
4040 (void) fprintf(STDOUT, " }\n");
4041 (void) fprintf(STDOUT, " pnode_%s_ptr = 0L;\n", nm);
4042 }
4043 break;
4044 case DELAY2_KIND: /* unprocessed value: input_node_name */
4045 str = get_token(str, tok1, false); /* get number of delays */
4046 str = get_token(str, tok2, false); /* get input node */
4047 n = node_id(tok2);
4048 if (Node_List[n].init) { /* input node initialized by "init" */
4049 (void) strcpy(v3, "init_");
4050 (void) strcat(v3, Node_List[n].name1);
4051 } else {
4052 (void) strcpy(v3, "ANALOG_INI");
4053 }
4054 (void) fprintf(STDOUT, " %s_delay = %s;\n", v1, v3);
4055 break;
4056 case DELAY3_KIND: /* unprocessed value: input_node_name */
4057 str = get_token(str, tok1, false); /* get number of delays */
4058 str = get_token(str, tok2, false); /* get input node */
4059 n = node_id(tok2);
4060 if (Node_List[n].init) { /* input node initialized by "init" */
4061 (void) strcpy(v3, "init_");
4062 (void) strcat(v3, Node_List[n].name1);
4063 } else {
4064 (void) strcpy(v3, "ANALOG_INI");
4065 }
4066 (void) fprintf(STDOUT, " %s_delay[0] = %s;\n", v1, v3);
4067 (void) fprintf(STDOUT, " %s_delay[1] = %s;\n", v1, v3);
4068 break;
4069 case DIFFERENTIATOR_KIND: /* unprocessed value: node_name */
4070 (void) fprintf(STDOUT, " %s_delay = ANALOG_INI;\n", v1);
4071 break;
4072 case SIN2_KIND: /* unprocessed value: off ampl freq ph */
4073 case COS2_KIND:
4074 str = get_sign_and_token(str, sgn, tok1);
4075 str = get_sign_and_token(str, sgn, tok1);
4076 str = get_sign_and_token(str, sgn, tok1);
4077 if (1 > sscanf(tok1, "%lf", &dtemp1)) {
4078 (void) fprintf(STDOUT, " inode_%s_first = true;\n", nm);
4079 (void) fprintf(STDOUT, " hnode_%s_freq = ANALOG_INI;\n", nm);
4080 (void) fprintf(STDOUT, " hnode_%s_phase = ANALOG_INI;\n", nm);
4081 }
4082 break;
4083 case NOISE_KIND: /* unprocessed value: DC RMS */
4084 (void) fprintf(STDOUT, " inode_%s_ok = 1LL;\n", nm);
4085 (void) fprintf(STDOUT, " dnode_%s_g1 = 0.0;\n", nm);
4086 (void) fprintf(STDOUT, " dnode_%s_g2 = 0.0;\n", nm);
4087 break;
4088 case OSC_KIND: /* unprocessed value: off ampl freq phae */
4089 str = get_sign_and_token(str, sgn, tok1); /* skip offset */
4090 str = get_sign_and_token(str, sgn, tok1); /* skip amplitude */
4091 str = get_sign_and_token(str, sgn, v2); /* frequency */
4092 u = update_id(v2, 1);
4093 if (UNDEFINED != u) {
4094 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4095 (void) fprintf(STDERR, " the frequency must be a constant,\n");
4096 (void) fprintf(STDERR, " this variable is updated\n\n");
4097 print_location(Update_List[u].mline, Update_List[u].mfile);
4098 }
4099 flag = sscanf(v2, "%lf", &dtemp1);
4100 (void) build_name(sgn, v2, RIGHT_VALUE);
4101 if (1 == flag) {
4102 (void) strcat(v2, "L");
4103 }
4104 str = get_sign_and_token(str, sgn, v3); /* phase */
4105 u = update_id(v3, 1);
4106 if (UNDEFINED != u) {
4107 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4108 (void) fprintf(STDERR, " the phase must be a constant,\n");
4109 (void) fprintf(STDERR, " this variable is updated\n\n" );
4110 print_location(Update_List[u].mline, Update_List[u].mfile);
4111 }
4112 flag = sscanf(v3, "%lf", &dtemp1);
4113 (void) build_name(sgn, v3, RIGHT_VALUE);
4114 if (1 == flag) {
4115 (void) strcat(v3, "L");
4116 }
4117 (void) fprintf(STDOUT, " hnode_%s_fctr = cosl(_2PI_*%s/((H_PREC) FSL)) * 2.0L;\n", nm, v2);
4118 if (0 == flag) {
4119 (void) fprintf(STDOUT, " hnode_%s_osc0 = sinl(%s);\n", nm, v3);
4120 (void) fprintf(STDOUT, " hnode_%s_osc1 = sinl(%s - (_2PI_*%s/((H_PREC) FSL)));\n", nm, v3, v2);
4121 } else if (0.0 == dtemp1) {
4122 (void) fprintf(STDOUT, " hnode_%s_osc0 = 0.0L;\n", nm );
4123 (void) fprintf(STDOUT, " hnode_%s_osc1 = -sinl(_2PI_*%s/((H_PREC) FSL));\n", nm, v2);
4124 } else {
4125 (void) fprintf(STDOUT, " hnode_%s_osc0 = sinl(%s);\n", nm, v3);
4126 (void) fprintf(STDOUT, " hnode_%s_osc1 = sinl(%s - (_2PI_*%s/((H_PREC) FSL)));\n", nm, v3, v2);
4127 }
4128 (void) fprintf(STDOUT, " hnode_%s_osc2 = 0.0L;\n", nm );
4129 break;
4130 case ZERO_KIND: /* unprocessed value: dec_fact node_name */
4131 (void) fprintf(STDOUT, " inode_%s_ctr = DIGITAL_INI;\n", nm );
4132 break;
4133 default:
4134 break;
4135 }
4136 return;
4137}
4138
4139
4140void reset_a_dc_node(long i) {
4141 long n;
4142 NAPA_DIGITAL_TYPE lltemp1, lltemp2;
4143 char tok[STRLENGTH] = {'\0'};
4144 char v1[LINLENGTH] = {'\0'};
4145 char v2[LINLENGTH] = {'\0'};
4146 char *str = (char*) NULL;
4147 char *nm = (char*) NULL;
4148 nm = Node_List[i].name1;
4149 (void) strcpy(v1, nm);
4150 (void) build_name("", v1, LEFT_VALUE);
4151 str = Node_List[i].value; /* unprocessed value: C expression */
4152 clean_parentheses(str);
4153 if (DIGITAL_DATA_TYPE == Node_List[i].type) {
4154 (void) fprintf(STDOUT, " %s = DIGITAL_INI;\n", v1);
4155 (void) fprintf(STDOUT, " %s_dc = (I_TYPE) (", v1);
4156 } else {
4157 (void) fprintf(STDOUT, " %s = ANALOG_INI;\n", v1);
4158 (void) fprintf(STDOUT, " %s_dc = (R_TYPE) (", v1);
4159 }
4160 for (;;) {
4161 str = get_token(str, tok, true);
4162 if (ISEMPTY(tok)) {
4163 (void) fprintf(STDOUT, ");\n");
4164 break;
4165 }
4166 if (UNDEFINED != (n = node_id(tok))) {
4167 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4168 (void) fprintf(STDERR, " a node is not allowed as input of a '%s' node,\n", Node_List[i].tag);
4169 if (DIGITAL_DATA_TYPE == Node_List[i].type) {
4170 (void) fprintf(STDERR, " use a 'ialgebra' node instead.\n");
4171 } else {
4172 (void) fprintf(STDERR, " use a 'dalgebra' node instead.\n");
4173 }
4174 } else if (UNDEFINED != (n = var_id(tok))) {
4175 (void) strcpy(v2, Var_List[n].name1);
4176 (void) build_name("", v2, RIGHT_VALUE);
4177 (void) fprintf(STDOUT, "%s", v2);
4178 } else {
4179 (void) build_name("", tok, RIGHT_VALUE);
4180 (void) fprintf(STDOUT, "%s", tok);
4181 }
4182 }
4183 if (0L < Node_List[i].width) {
4184 lltemp1 = 1LL << (Node_List[i].width - 1L);
4185 lltemp2 = (2LL*lltemp1) - 1LL;
4186 (void) fprintf(STDOUT, " %s_dc = (%s_dc & ( 0X%llXLL))\n", v1, v1, lltemp1);
4187 (void) fprintf(STDOUT, " %*s ? (%s_dc | (-0X%llXLL))\n", 3 + ((int) strlen(nm)), " ", v1, lltemp1);
4188 (void) fprintf(STDOUT, " %*s : (%s_dc & ( 0X%llXLL));\n", 3 + ((int) strlen(nm)), " ", v1, lltemp2);
4189 } else if (0L > Node_List[i].width) {
4190 lltemp1 = (1LL << -Node_List[i].width) - 1LL;
4191 (void) fprintf(STDOUT, " %s_dc &= 0X%llXLL;\n", v1, lltemp1);
4192 }
4193 return;
4194}
4195
4196
4198 NAPA_DIGITAL_TYPE lltemp1, lltemp2;
4199 long i;
4200 char v1[STRLENGTH] = {'\0'};
4201 char cc[3] = {'\0'};
4202 char *str1 = (char*) NULL;
4203 (void) strcpy(v1, Cmdline_List[j].parms); /* get the name of the variable */
4204 switch (j+1L) {
4205 case 1: (void) strcpy(cc, "st"); break;
4206 case 2: (void) strcpy(cc, "nd"); break;
4207 case 3: (void) strcpy(cc, "rd"); break;
4208 default: (void) strcpy(cc, "th");
4209 }
4210 if (0 == strcmp(v1, "fs")) { /* 'fs' & 'ts' cannot be together, already checked */
4211 (void) fprintf(STDOUT, " if ( 1 != sscanf(argv[%ld], \"%%lf\", &napa_fs_ext) ) {\n", j+1L);
4212 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4213 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (fs) of the simulator must be an analog number,\\n\");\n", j+1L, cc);
4214 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** the value <%%s> is read instead.\\n\\n\", argv[%ld]);\n", j+1L);
4215 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4216 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4217 (void) fprintf(STDOUT, " }\n");
4218 (void) fprintf(STDOUT, " if ( 0.0 >= napa_fs_ext ) {\n");
4219 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4220 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (fs) must be strictly positive.\\n\\n\");\n", j+1L, cc);
4221 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4222 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4223 (void) fprintf(STDOUT, " }\n");
4224 (void) fprintf(STDOUT, " napa_ts_ext = 1.0 / napa_fs_ext;\n");
4225 return;
4226 }
4227 if (0 == strcmp(v1, "ts")) { /* 'fs' & 'ts' cannot be together, already checked */
4228 (void) fprintf(STDOUT, " if ( 1 != sscanf(argv[%ld], \"%%lf\", &napa_ts_ext) ) {\n", j+1L);
4229 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4230 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (ts) of the simulator must be an analog number,\\n\");\n", j+1L, cc);
4231 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** the value <%%s> is read instead.\\n\\n\", argv[%ld]);\n", j+1L);
4232 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4233 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4234 (void) fprintf(STDOUT, " }\n");
4235 (void) fprintf(STDOUT, " if ( 0.0 >= napa_ts_ext ) {\n");
4236 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4237 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (ts) must be strictly positive.\\n\\n\");\n", j+1L, cc);
4238 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4239 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4240 (void) fprintf(STDOUT, " }\n");
4241 (void) fprintf(STDOUT, " napa_fs_ext = 1.0 / napa_ts_ext;\n");
4242 return;
4243 }
4244
4245 i = var_id(v1);
4246 (void) build_name("", v1, LEFT_VALUE);
4247 switch (Var_List[i].type) {
4248 case STRING_DATA_TYPE :
4249 (void) fprintf(STDOUT, " (void) strcpy(%s, argv[%ld]);\n", v1, j+1L);
4250 break;
4251 case DIGITAL_DATA_TYPE :
4252 (void) fprintf(STDOUT, " if ( 1 != sscanf(argv[%ld], \"%%lli\", &%s) ) {\n", j+1L, v1);
4253 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4254 if (1L == Num_Cmdlines) {
4255 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The parameter (%s) of the simulator must be an integer number,\\n\");\n", Var_List[i].name1);
4256 } else {
4257 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (%s) of the simulator must be an integer number,\\n\");\n", j+1L, cc, Var_List[i].name1);
4258 }
4259 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** the value <%%s> is read instead.\\n\\n\", argv[%ld]);\n", j+1L);
4260 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4261 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4262 (void) fprintf(STDOUT, " }\n");
4263 str1 = Var_List[i].name1; /* register arithmetic */
4264 (void) strcpy(v1, str1);
4265 (void) build_name("", v1, LEFT_VALUE);
4266 if (0L < Var_List[i].width) {
4267 lltemp1 = 1LL << (Var_List[i].width - 1L);
4268 lltemp2 = (2LL*lltemp1) - 1LL;
4269 (void) fprintf(STDOUT, " %s = (%s & ( 0X%llXLL))\n", v1, v1, lltemp1);
4270 (void) fprintf(STDOUT, " %*s ? (%s | (-0X%llXLL))\n", (int) strlen(str1), " ", v1, lltemp1);
4271 (void) fprintf(STDOUT, " %*s : (%s & ( 0X%llXLL));\n", (int) strlen(str1), " ", v1, lltemp2);
4272 } else if (0L > Var_List[i].width) {
4273 lltemp1 = (1LL << -Var_List[i].width) - 1LL;
4274 (void) fprintf(STDOUT, " %s &= 0X%llXLL;\n", v1, lltemp1);
4275 } /* otherwise, i.e. width is 0, do nothing */
4276 break;
4277 case ANALOG_DATA_TYPE :
4278 (void) fprintf(STDOUT, " if ( 1 != sscanf(argv[%ld], \"%%lf\", &%s) ) {\n", j+1L, v1);
4279 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Simulator Command Line Error:\\n\\n\");\n");
4280 if (1L == Num_Cmdlines) {
4281 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The parameter (%s) of the simulator must be an analog number,\\n\");\n",
4282 Var_List[i].name1);
4283 } else {
4284 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** The %ld%s parameter (%s) of the simulator must be an analog number,\\n\");\n",
4285 j+1L, cc, Var_List[i].name1);
4286 }
4287 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** the value <%%s> is read instead.\\n\\n\", argv[%ld]);\n", j+1L);
4288 (void) fprintf(STDOUT, " napa_print_usage(argv[0], stderr, NO);\n");
4289 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n"); /* exit() to avoid message */
4290 (void) fprintf(STDOUT, " }\n");
4291 break;
4292 default:
4293 break;
4294 }
4295 return;
4296}
4297
4298
4299void load_files(void) {
4300 if (!Load_Flag) {
4301 return;
4302 }
4303 (void) fprintf(STDOUT, "\n /* (load init file) */\n");
4304 (void) fprintf(STDOUT, " napa_load_states();\n");
4305 return;
4306}
4307
4308
4309void load_function(void) {
4310 if (!Load_Flag) {
4311 return;
4312 }
4313 (void) fprintf(STDOUT, "\nvoid napa_load_states(void) {\n");
4314 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Information (load)\\n\");\n");
4315 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Loading data at initialization from file <%s>\");\n", Load_List.fname);
4316 cat_file(Load_List.fname, "load", EXPAND, Load_List.mline, Load_List.mfile);
4317 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\\n\");\n");
4318 (void) fprintf(STDOUT, " return;\n");
4319 (void) fprintf(STDOUT, "}\n");
4320 return;
4321}
4322
4323
4324void dump_function(void) {
4325 long i, v;
4326 long flag;
4327 char tok[STRLENGTH] = {'\0'};
4328 char v1[LINLENGTH] = {'\0'};
4329 char v2[LINLENGTH] = {'\0'};
4330 char sgn[2] = {'\0'};
4331 char *nm = (char*) NULL;
4332 char *str = (char*) NULL;
4333 long n;
4334 long ndel;
4335 if (!Dump_Flag) {
4336 return;
4337 }
4338 (void) fprintf(STDOUT, "\nvoid napa_dump_states(void) {\n");
4339 if ((Multdelay_Flag) || (Array_Flag)) {
4340 (void) fprintf(STDOUT, " long i;\n");
4341 }
4342 (void) fprintf(STDOUT, " static long n = 0L;\n");
4343 (void) fprintf(STDOUT, "#if (defined(DEBUG_MODE_DUMP) || defined(VERBOSE) || defined(ALL_DEBUG))\n");
4344 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Debug Information: ( *** DUMP *** )\");\n");
4345 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" As requested by user, dumping simulation data at loop");
4346 (void) fprintf(STDOUT, " -> #%%Lg\\n\\n\", napa_abs_loop);\n");
4347 (void) fprintf(STDOUT, "#endif\n");
4348 (void) fprintf(STDOUT, " if ( EOF == fflush((FILE*) NULL) ) {\n");
4349 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (dump)\");\n");
4350 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Flushing data from buffers I/O was not successful\\n\");\n");
4351 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
4352 (void) fprintf(STDOUT, " }\n");
4353 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** %%118s *** */\\n\", \" \");\n");
4354 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\\n\", \" \");\n");
4355 (void) fprintf(STDOUT, " if ( 0L == n ) {\n");
4356 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#if ((!defined DUMP) || (%%ld == DUMP))\\n\", n);\n");
4357 (void) fprintf(STDOUT, " } else {\n");
4358 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#if (%%ld == DUMP)\\n\", n);\n" );
4359 (void) fprintf(STDOUT, " } \n");
4360 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #define DUMP_FLAG\\n\\n\");\n" );
4361 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" (void) fprintf(stderr, \\\" with %%ld == DUMP\\\");\\n\\n\", n);\n");
4362
4363 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(NO_GLOBAL)\\n\");\n");
4364 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_abs_time = %% .15LeL;\\n\", napa_abs_time);\n");
4365 if (UNDEFINED == directive_id("JITTER")) {
4366 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_ref_time = %% .15LeL;\\n\", napa_abs_time);\n");
4367 } else {
4368 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_ref_time = %% .15LeL;\\n\", napa_ref_time);\n");
4369 }
4370 if ((Synchro_Flag) && (1L <= Num_Tools)) {
4371 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_rel_time = %% .15LeL;\\n\", napa_rel_time);\n");
4372 }
4373 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_abs_loop = %% .15LeL;\\n\", napa_abs_loop);\n");
4374 if ((Synchro_Flag) && (1L <= Num_Tools)) {
4375 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_rel_loop = %% .15LeL;\\n\", napa_rel_loop);\n");
4376 }
4377 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #endif\\n\\n\");\n");
4378 if ((Synchro_Flag) && (1L <= Num_Tools)) {
4379 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(NO_TOOL)\\n\");\n");
4380 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_tool_index = %% lldLL\\n\", napa_tool_index);\n");
4381 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" napa_packet = %% lldLL\\n\", napa_packet );\n");
4382 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #endif\\n\\n\");\n");
4383 }
4384 if (0L < Num_Arrays) {
4385 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(NO_ARRAY)\\n\");\n");
4386 for (i = 0L; i < Num_Arrays; i++) {
4387 if ((!Array_List[i].used) || (UNKNOWN_KIND == Array_List[i].kind)) {
4388 continue;
4389 }
4390 (void) strcpy(v1, Array_List[i].name);
4391 (void) build_name("", v1, LEFT_VALUE);
4392 if ((RAM_KIND == Array_List[i].kind) || (RAM2_KIND == Array_List[i].kind)) {
4393 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.last = %% .1lld;\\n\", (I_TYPE) %s.last);\n", v1, v1);
4394 }
4395 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.length = %% lldLL;\\n\", %s.length);\n", v1, v1);
4396 if ((RAM2_KIND == Array_List[i].kind ) || (ROM2_KIND == Array_List[i].kind )) {
4397 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.address = %% lldLL;\\n\", %s.address);\n", v1, v1);
4398 }
4399 if (RAM2_KIND == Array_List[i].kind ) {
4400 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.rw = %% lldLL;\\n\", %s.rw);\n", v1, v1);
4401 }
4402 (void) fprintf(STDOUT, " for (i = 0L; i < ((long) %s.length); i++) {\n", v1);
4403 if ((RAM_KIND == Array_List[i].kind ) || (RAM2_KIND == Array_List[i].kind )) {
4404 (void) fprintf(STDOUT, " if ( %s.flag[i] ) {\n", v1);
4405 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.flag[%%3ld] = true;\", i);\n", v1);
4406 (void) fprintf(STDOUT, " } else {\n");
4407 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.flag[%%3ld] = false;\", i);\n", v1);
4408 (void) fprintf(STDOUT, " }\n");
4409 }
4410 switch (Array_List[i].type) {
4411 case DIGITAL_DATA_TYPE :
4412 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.data[%%3ld] = %% lldLL;\\n\", i, %s.data[i]);\n", v1, v1);
4413 break;
4414 case HEX_DATA_TYPE :
4415 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.data[%%3ld] = 0x%%07llxLL;\\n\", i, ABS(%s.data[i]));\n", v1, v1);
4416 break;
4417 case ANALOG_DATA_TYPE :
4418 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s.data[%%3ld] = %% .15e;\\n\", i, %s.data[i]);\n", v1, v1);
4419 break;
4420 default:
4421 break;
4422 }
4423 (void) fprintf(STDOUT, " }\n");
4424 }
4425 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #endif\\n\\n\");\n");
4426 }
4427 flag = false;
4428 for (i = 0L; i < Num_Vars; i++) {
4429 if ((0 != strncmp(Var_List[i].name1, "$init$", (size_t) 6))
4430 && (0 != strncmp(Var_List[i].name1, "$null$", (size_t) 6))
4431 && (0 != strncmp(Var_List[i].name1, "$declare$", (size_t) 9))) {
4432 flag = true;
4433 }
4434 }
4435 if (flag) {
4436 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(NO_VAR)\\n\");\n");
4437 for (i = 0L; i < Num_Vars; i++) {
4438 if ((0 == strncmp(Var_List[i].name1, "$init$", (size_t) 6))
4439 || (0 == strncmp(Var_List[i].name1, "$null$", (size_t) 6))
4440 || (0 == strncmp(Var_List[i].name1, "$declare$", (size_t) 9))) {
4441 continue;
4442 }
4443 (void) strcpy(v1, Var_List[i].name1);
4444 (void) build_name("", v1, LEFT_VALUE);
4445 switch (Var_List[i].type) {
4446 case DIGITAL_DATA_TYPE :
4447 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s = %% lldLL;\\n\", %s);\n", v1, v1);
4448 if (2 == Var_List[i].event) {
4449 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_new = %% lldLL;\\n\", %s_new);\n", v1, v1);
4450 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_old = %% lldLL;\\n\", %s_old);\n", v1, v1);
4451 }
4452 break;
4453 case ANALOG_DATA_TYPE :
4454 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s = %% .15e;\\n\", %s);\n", v1, v1);
4455 break;
4456 case STRING_DATA_TYPE :
4457 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" (void) strcpy(%s, \\\"%%s\\\");\\n\", %s);\n", v1, v1);
4458 break;
4459 default:
4460 break;
4461 }
4462 }
4463 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #endif\\n\\n\");\n");
4464 }
4465 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(NO_NODE)\\n\");\n");
4466 for (i = 0L; i < Num_Nodes; i++) {
4467 nm = Node_List[i].name1;
4468 (void) strcpy(v1, nm);
4469 (void) build_name("", v1, LEFT_VALUE);
4470 switch (Node_List[i].type) {
4471 case DIGITAL_DATA_TYPE :
4472 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s = %% lldLL;\\n\", %s);\n", v1, v1);
4473 if (DELAY_KIND == Node_List[i].kind) {
4474 str = Node_List[i].value;
4475 str = get_sign_and_token(str, sgn, tok); /* get number of delays */
4476 v = var_id(tok);
4477 if (UNDEFINED != v) {
4478 (void) strcpy(v2, Var_List[v].name1);
4479 (void) build_name("", v2, RIGHT_VALUE);
4480 (void) fprintf(STDOUT, " for (i = 0L; i < %s; i++) {\n", v2);
4481 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[%%ld] = %% lldLL;\\n\", i, %s_delay[i]);\n", v1, v1);
4482 (void) fprintf(STDOUT, " }\n");
4483 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr = %% ldL;\\n\", pnode_%s_ptr);\n", nm, nm);
4484 } else {
4485 if (1 != sscanf(tok, "%li", &ndel)) {
4486 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4487 (void) fprintf(STDERR, " the number of delays is not a well-formed positive C long integer <%s>\n", tok);
4488 return;
4489 }
4490 (void) fprintf(STDOUT, " for (i = 0L; i < %ld; i++) {\n", ndel);
4491 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[%%ld] = %% lldLL;\\n\", i, %s_delay[i]);\n", v1, v1);
4492 (void) fprintf(STDOUT, " }\n");
4493 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr = %% ldL;\\n\", pnode_%s_ptr);\n", nm, nm);
4494 }
4495 }
4496 if (DELAY2_KIND == Node_List[i].kind) {
4497 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay = %% lldLL;\\n\", %s_delay_0);\n", v1, v1);
4498 }
4499 if (DELAY3_KIND == Node_List[i].kind) {
4500 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[0] = %% lldLL;\\n\", %s_delay[0]);\n", v1, v1);
4501 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[1] = %% lldLL;\\n\", %s_delay[1]);\n", v1, v1);
4502 }
4503 if (DC_KIND == Node_List[i].kind) {
4504 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_dc = %% lldLL;\\n\", %s_dc);\n", v1, v1);
4505 }
4506 if (DIFFERENTIATOR_KIND == Node_List[i].kind) {
4507 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay = %% lldLL;\\n\", %s);\n", v1, v1);
4508 }
4509 if (LATCH_KIND == Node_List[i].kind) {
4510 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_set = %% lldLL;\\n\", %s_set);\n", v1, v1);
4511 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_rst = %% lldLL;\\n\", %s_rst);\n", v1, v1);
4512 }
4513 if (TRIG_KIND == Node_List[i].kind) {
4514 str = Node_List[i].value;
4515 str = get_token(str, tok, false);
4516 if ((0 == strcmp(tok, "+")) || (0 == strcmp(tok, "-"))) {
4517 str = get_token(str, tok, false); /* skip sign and trig */
4518 }
4519 str = get_token(str, tok, false); /* get the input node name */
4520 n = node_id(tok);
4521 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
4522 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_store = %% lldLL;\\n\", %s_store);\n", v1, v1);
4523 } else {
4524 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" dnode_%s_store = %% .15e;\\n\", dnode_%s_store);\n", nm, nm);
4525 }
4526 }
4527 if (CHG_KIND == Node_List[i].kind) {
4528 str = Node_List[i].value;
4529 str = get_token(str, tok, false); /* get the input node name */
4530 n = node_id(tok);
4531 if (DIGITAL_DATA_TYPE == Node_List[n].type) {
4532 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_store = %% lldLL;\\n\", %s_store);\n", v1, v1);
4533 } else {
4534 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" dnode_%s_store = %% .15e;\\n\", dnode_%s_store);\n", nm, nm);
4535 }
4536 }
4537 if (CLOCK_KIND == Node_List[i].kind) {
4538 str = Node_List[i].value;
4539 n = 0L;
4540 for (;;) {
4541 str = get_token(str, tok, false);
4542 if (ISEMPTY(tok)) {
4543 break;
4544 }
4545 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_clock[%ld] = %% lldLL;\\n\", %s_clock[%ld]);\n", v1, n, v1, n);
4546 n++;
4547 }
4548 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr1 = %% ldL;\\n\", pnode_%s_ptr1);\n", nm, nm);
4549 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr2 = %% ldL;\\n\", pnode_%s_ptr2);\n", nm, nm);
4550 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_width = %% ldL;\\n\", pnode_%s_width);\n", nm, nm);
4551 }
4552 if (ZERO_KIND == Node_List[i].kind) {
4553 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" inode_%s_ctr = %% lldLL;\\n\", inode_%s_ctr);\n", nm, nm);
4554 }
4555 break;
4556 case ANALOG_DATA_TYPE :
4557 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s = %% .15e;\\n\", %s);\n", v1, v1);
4558 if (DELAY_KIND == Node_List[i].kind) {
4559 str = Node_List[i].value;
4560 str = get_sign_and_token(str, sgn, tok); /* get number of delays */
4561 v = var_id(tok);
4562 if (UNDEFINED != v) {
4563 (void) strcpy(v2, Var_List[v].name1);
4564 (void) build_name("", v2, RIGHT_VALUE);
4565 (void) fprintf(STDOUT, " for (i = 0L; i < %s; i++) {\n", v2);
4566 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[%%ld] = %% .15e;\\n\", i, %s_delay[i]);\n", v1, v1);
4567 (void) fprintf(STDOUT, " }\n");
4568 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr = %% ldL;\\n\", pnode_%s_ptr);\n", nm, nm);
4569 } else {
4570 if (1 != sscanf(tok, "%li", &ndel)) {
4571 print_error_location(nm, Node_List[i].mline, Node_List[i].mfile);
4572 (void) fprintf(STDERR, " the number of delays is not a well-formed positive C long integer <%s>\n", tok);
4573 return;
4574 }
4575 (void) fprintf(STDOUT, " for (i = 0L; i < %ld; i++) {\n", ndel);
4576 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[%%ld] = %% .15e;\\n\", i, %s_delay[i]);\n", v1, v1);
4577 (void) fprintf(STDOUT, " }\n");
4578 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" pnode_%s_ptr = %% ldL;\\n\", pnode_%s_ptr);\n", nm, nm);
4579 }
4580 }
4581 if (DELAY2_KIND == Node_List[i].kind) {
4582 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay = %% .15e;\\n\", %s_delay_0);\n", v1, v1);
4583 }
4584 if (DELAY3_KIND == Node_List[i].kind) {
4585 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[0] = %% .15e;\\n\", %s_delay[0]);\n", v1, v1);
4586 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay[1] = %% .15e;\\n\", %s_delay[1]);\n", v1, v1);
4587 }
4588 if (DC_KIND == Node_List[i].kind) {
4589 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_dc = %% lldLL;\\n\", %s_dc);\n", v1, v1);
4590 }
4591 if (DIFFERENTIATOR_KIND == Node_List[i].kind) {
4592 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %s_delay = %% .15e;\\n\", %s);\n", v1, v1);
4593 }
4594 if (ZERO_KIND == Node_List[i].kind) {
4595 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" inode_%s_ctr = %% lldLL;\\n\", inode_%s_ctr);\n", nm, nm);
4596 }
4597 if (OSC_KIND == Node_List[i].kind) {
4598 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_fctr = %% .21Le;\\n\", hnode_%s_fctr);\n", nm, nm);
4599 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_osc0 = %% .21Le;\\n\", hnode_%s_osc0);\n", nm, nm);
4600 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_osc1 = %% .21Le;\\n\", hnode_%s_osc1);\n", nm, nm);
4601 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_osc2 = %% .21Le;\\n\", hnode_%s_osc2);\n", nm, nm);
4602 }
4603 if ((SIN2_KIND == Node_List[i].kind) || (COS2_KIND == Node_List[i].kind)) {
4604 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" inode_%s_first = %% lldLL;\\n\", inode_%s_first);\n", nm, nm);
4605 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_freq = %% .15e;\\n\", hnode_%s_freq);\n", nm, nm);
4606 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" hnode_%s_phase = %% .15e;\\n\", hnode_%s_phase);\n", nm, nm);
4607 }
4608 break;
4609 default:
4610 break;
4611 }
4612 }
4613 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #endif\\n\\n\");\n");
4614 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#endif\\n\\n\");\n" );
4615 (void) fprintf(STDOUT, " n++;\n");
4616 (void) fprintf(STDOUT, " return;\n");
4617 (void) fprintf(STDOUT, "}\n");
4618 return;
4619}
4620
4621
4623 (void) fprintf(STDOUT, "\n\n/* *** TIMER FUNCTION (freeze for 'num' seconds) %s */\n\n", multiple('*', 78L));
4624 (void) fprintf(STDOUT, "void napa_timer(long num) {\n" );
4625 (void) fprintf(STDOUT, " time_t time_start, time_stop;\n");
4626 (void) fprintf(STDOUT, " if ( 0L < num ) {\n");
4627 (void) fprintf(STDOUT, " time_start = time((time_t*) NULL);\n" );
4628 (void) fprintf(STDOUT, " do {\n");
4629 (void) fprintf(STDOUT, " time_stop = time((time_t*) NULL);\n" );
4630 (void) fprintf(STDOUT, " } while ( ((long) (time_stop-time_start)) <= num );\n");
4631 (void) fprintf(STDOUT, " }\n");
4632 (void) fprintf(STDOUT, " return;\n");
4633 (void) fprintf(STDOUT, "}\n");
4634 return;
4635}
4636
4637
4639 (void) fprintf(STDOUT, "\n\n/* *** EXIT FUNCTIONS %s */\n", multiple('*', 105L));
4640 (void) fprintf(STDOUT, "\nvoid napa_end(void) {\n");
4641 if (Array_Flag) {
4642 (void) fprintf(STDOUT, " napa_array_setup(FREE);\n");
4643 }
4644 if (Pointer_Flag) {
4645 (void) fprintf(STDOUT, " napa_record_setup(FREE);\n" );
4646 }
4647 (void) fprintf(STDOUT, " if ( !napa_error_flag ) {\n");
4648 (void) fprintf(STDOUT, " (void) napa_IO_manager(FREE, (FILE**) NULL, (char*) NULL, (char*) NULL, \"end\");\n" );
4649 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n **** Normal Termination %%25s ****\\n\", \" \");\n");
4650 (void) fprintf(STDOUT, " }\n");
4651 (void) fprintf(STDOUT, "#if defined(VERBOSE) && defined(NAPA_EXIT_STATUS)\n");
4652 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" **** NAPA Exit Status: %%10s < %%d >");
4653 (void) fprintf(STDOUT, " %%9s ****\\n\\n\", \" \", napa_waypoint, \" \");\n");
4654 (void) fprintf(STDOUT, "#endif\n" );
4655 (void) fprintf(STDOUT, " return;\n");
4656 (void) fprintf(STDOUT, "}\n");
4657 (void) fprintf(STDOUT, "\nvoid napa_exit(int exit_code) {\n");
4658 (void) fprintf(STDOUT, " if ( EOF == fflush((FILE*) NULL) ) {\n");
4659 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (exit)\");\n");
4660 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" flushing data from I/O buffers was not successful\\n\");\n");
4661 (void) fprintf(STDOUT, " exit_code = EXIT_FAILURE;\n");
4662 (void) fprintf(STDOUT, " }\n");
4663 (void) fprintf(STDOUT, " if ( EXIT_FAILURE == exit_code ) {\n");
4664 (void) fprintf(STDOUT, " napa_error_flag = true;\n" );
4665 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\\n **** ERROR detected \");\n");
4666 (void) fprintf(STDOUT, " switch (napa_waypoint) {\n" );
4667 if (Cmdline_Flag) {
4668 (void) fprintf(STDOUT, " case 0:");
4669 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"before the command line parsing.\" );" );
4670 (void) fprintf(STDOUT, " break;\n");
4671 }
4672 (void) fprintf(STDOUT, " case 1:");
4673 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"before the initialization of the simulation.\" );" );
4674 (void) fprintf(STDOUT, " break;\n");
4675 (void) fprintf(STDOUT, " case 2:");
4676 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"during the 1st part of the initialization of the simulation.\" );" );
4677 (void) fprintf(STDOUT, " break;\n");
4678 (void) fprintf(STDOUT, " case 3:");
4679 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"during the 2nd part of the initialization of the simulation.\" );" );
4680 (void) fprintf(STDOUT, " break;\n");
4681 (void) fprintf(STDOUT, " case 4:");
4682 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"at abs_loop #%%.0Lf during the simulation.\", napa_abs_loop);");
4683 (void) fprintf(STDOUT, " break;\n");
4684 (void) fprintf(STDOUT, " case 5:");
4685 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"at abs_loop #%%.0Lf when simulation is closing.\", napa_abs_loop);");
4686 (void) fprintf(STDOUT, " break;\n");
4687 (void) fprintf(STDOUT, " case 6:");
4688 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"during the execution of the NAPA exit code.\" );\n");
4689 (void) fprintf(STDOUT, " }\n");
4690 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\\n\");\n");
4691 (void) fprintf(STDOUT, " TIMER(1L);\n");
4692 (void) fprintf(STDOUT, "#if defined(NAPA_EXIT_STATUS)\n");
4693 (void) fprintf(STDOUT, " exit(napa_waypoint);\n" );
4694 (void) fprintf(STDOUT, "#else\n");
4695 (void) fprintf(STDOUT, " exit(EXIT_FAILURE);\n");
4696 (void) fprintf(STDOUT, "#endif\n");
4697 (void) fprintf(STDOUT, " } else {\n");
4698 (void) fprintf(STDOUT, " exit(EXIT_SUCCESS);\n");
4699 (void) fprintf(STDOUT, " }\n");
4700 (void) fprintf(STDOUT, "}\n");
4701 return;
4702}
4703
4704
4706 (void) fprintf(STDOUT, " #ifdef __GNUC__\n"); /* 'getcwd()' is not an ANSI-C function */
4707 (void) fprintf(STDOUT, " /* (current working directory) */\n");
4708 (void) fprintf(STDOUT, " if (NULL == getcwd(napa_cwd, 128)) {\n" );
4709 (void) fprintf(STDOUT, " (void) strcpy(napa_cwd, \"Unknown\");\n");
4710 (void) fprintf(STDOUT, " }\n");
4711 (void) fprintf(STDOUT, " #endif\n\n");
4712 (void) fprintf(STDOUT, " /* (initialize control) */\n");
4713 (void) fprintf(STDOUT, " napa_control_init();\n");
4714 if (((Debug_Flag) || (Directive_Flag)) && (!Cmdline_Flag)) {
4715 (void) fprintf(STDOUT, " napa_check_directives();\n");
4716 }
4717 (void) fprintf(STDOUT, " napa_waypoint = 2;\n");
4718 return;
4719}
4720
4721
4723 if (Tool_Flag) {
4724 (void) fprintf(STDOUT, "\n /* (initialize tool synchronization) */\n");
4725 (void) fprintf(STDOUT, " napa_tool_setup();\n");
4726 }
4727 (void) fprintf(STDOUT, "\n /* (initialize variables) */\n");
4728 if ((0L < Num_Vars) || (0L < Num_Injects)) {
4729 (void) fprintf(STDOUT, " napa_reset_variables();\n");
4730 }
4731 if (Pointer_Flag) {
4732 (void) fprintf(STDOUT, "\n /* (initialize records) */\n");
4733 (void) fprintf(STDOUT, " napa_record_setup(ALLOCATE);\n");
4734 }
4735 return;
4736}
4737
4738
4739void open_ping_file(void) {
4740 int n;
4741 char tok[STRLENGTH] = {'\0'};
4742 char v1[LINLENGTH] = {'\0'};
4743 if ((!Ping_Flag) || (0 == strcmp(Ping_List.fname, "stderr"))) {
4744 return;
4745 }
4746 (void) fprintf(STDOUT, "\n /* (open ping file) */\n");
4747 n = node_id(Ping_List.fname);
4748 if (UNDEFINED != n) {
4749 print_error_location("ping", Ping_List.mline, Ping_List.mfile);
4750 (void) fprintf(STDERR, " <%s> is not a file name but a node\n", Ping_List.fname);
4751 }
4752 n = var_id(Ping_List.fname);
4753 if (UNDEFINED != n) {
4754 if (STRING_DATA_TYPE != Var_List[n].type) {
4755 print_error_location("ping", Ping_List.mline, Ping_List.mfile);
4756 (void) fprintf(STDERR, " <%s> is not a file name\n", Ping_List.fname);
4757 }
4758 }
4759 if (UNDEFINED != n) {
4760 (void) strcpy(tok, Var_List[n].name1);
4761 (void) strcpy(v1, tok);
4762 (void) build_name("", v1, RIGHT_VALUE);
4763 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_ping, %s, \".png\", \"ping\");\n", v1);
4764 } else {
4765 (void) strcpy(tok, Ping_List.fname);
4766 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_ping, \"%s\", \".png\", \"ping\");\n", tok);
4767 }
4768 return;
4769}
4770
4771
4772void open_IO_files(void) {
4773 long i, n;
4774 char tok[STRLENGTH] = {'\0'};
4775 char v1[LINLENGTH] = {'\0'};
4776 if (0L < Num_IOs) {
4777 if (1L == Num_IOs) {
4778 (void) fprintf(STDOUT, "\n /* (open I/O stream) */\n");
4779 } else {
4780 (void) fprintf(STDOUT, "\n /* (open I/O streams) */\n");
4781 }
4782 for (i = 0L; i < Num_IOs; i++) {
4783 n = node_id(IO_List[i].fname);
4784 if (UNDEFINED != n) {
4785 print_error_location("I/O", IO_List[i].mline, IO_List[i].mfile);
4786 (void) fprintf(STDERR, " <%s> is not a file name but a node\n", IO_List[i].fname);
4787 continue;
4788 }
4789 n = var_id(IO_List[i].fname);
4790 if (UNDEFINED != n) {
4791 if (STRING_DATA_TYPE != Var_List[n].type) {
4792 print_error_location("I/O", IO_List[i].mline, IO_List[i].mfile);
4793 (void) fprintf(STDERR, " <%s> is not a file name\n", IO_List[i].fname);
4794 continue;
4795 }
4796 }
4797 if (OUTPUT_TYPE == IO_List[i].type) {
4798 if (UNDEFINED != n) {
4799 (void) strcpy(tok, Var_List[n].name1);
4800 (void) strcpy(v1, tok);
4801 (void) build_name("", v1, RIGHT_VALUE);
4802 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_%ld, %s, \".out\", \"output\");\n", i, v1);
4803 } else {
4804 (void) strcpy(tok, IO_List[i].fname);
4805 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_%ld, \"%s\", \".out\", \"output\");\n", i, tok);
4806 }
4807 } else if (INPUT_TYPE == IO_List[i].type) {
4808 if (UNDEFINED != n) {
4809 (void) strcpy(tok, Var_List[n].name1);
4810 (void) strcpy(v1, tok);
4811 (void) build_name("", v1, RIGHT_VALUE);
4812 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENREAD, &napa_fp_%ld, %s, \".in\", \"input\");\n", i, v1);
4813 } else {
4814 (void) strcpy(tok, IO_List[i].fname);
4815 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENREAD, &napa_fp_%ld, \"%s\", \".in\", \"input\");\n", i, tok);
4816 }
4817 }
4818 }
4819 }
4820 if (Dump_Flag) {
4821 if (0L >= Num_IOs) {
4822 (void) fprintf(STDOUT, "\n /* (open dump file) */\n");
4823 }
4824 n = node_id(Dump_List.fname);
4825 if (UNDEFINED != n) {
4826 print_error_location("dump", Dump_List.mline, Dump_List.mfile);
4827 (void) fprintf(STDERR, " <%s> is not a file name\n", Dump_List.fname);
4828 return;
4829 }
4830 n = var_id(Dump_List.fname);
4831 if (UNDEFINED != n) {
4832 if (STRING_DATA_TYPE != Var_List[n].type) {
4833 print_error_location("dump", Dump_List.mline, Dump_List.mfile);
4834 (void) fprintf(STDERR, " <%s> is not a file name\n", Dump_List.fname);
4835 return;
4836 }
4837 (void) strcpy(tok, Var_List[n].name1);
4838 (void) strcpy(v1, tok);
4839 (void) build_name("", v1, RIGHT_VALUE);
4840 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_dump, %s, \".dmp\", \"dump\");\n", v1);
4841 } else {
4842 (void) strcpy(tok, Dump_List.fname);
4843 (void) fprintf(STDOUT, " (void) IO_MANAGER(OPENWRITE, &napa_fp_dump, \"%s\", \".dmp\", \"dump\");\n", tok);
4844 }
4845 }
4846 return;
4847}
4848
4849
4851 if (0L < Num_Nodes) {
4852 (void) fprintf(STDOUT, "\n /* (initialize nodes) */\n");
4853 (void) fprintf(STDOUT, " napa_reset_nodes();\n");
4854 }
4855 (void) fprintf(STDOUT, " napa_waypoint = 3;\n");
4856 if (0L < Num_UserTools) {
4857 if (1L == Num_UserTools) {
4858 (void) fprintf(STDOUT, "\n /* (call user's check function) */\n");
4859 } else {
4860 (void) fprintf(STDOUT, "\n /* (call user's check functions) */\n");
4861 }
4862 call_user_functions("", "check_");
4863 if (1L == Num_UserTools) {
4864 (void) fprintf(STDOUT, "\n /* (call user's initialization function) */\n");
4865 } else {
4866 (void) fprintf(STDOUT, "\n /* (call user's initialization functions) */\n");
4867 }
4868 call_user_functions("", "init_");
4869 }
4870 if (0L < Num_Posts) {
4871 (void) fprintf(STDOUT, "\n /* (prepare postprocessing) */\n");
4872 call_postprocess_functions("", "prepare_");
4873 }
4874 if (Array_Flag) {
4875 if (1L == Num_Arrays) {
4876 (void) fprintf(STDOUT, "\n /* (initialize array) */\n");
4877 } else {
4878 (void) fprintf(STDOUT, "\n /* (initialize arrays) */\n");
4879 }
4880 (void) fprintf(STDOUT, " napa_array_setup(ALLOCATE);\n");
4881 }
4882 return;
4883}
4884
4885
4887 long i;
4888 char v0[LINLENGTH] = {'\0'};
4889 char v1[LINLENGTH] = {'\0'};
4890 int flag;
4891 flag = false;
4892 for (i = 0L; i < Num_Arrays; i++) {
4893 if ((RAM_KIND == Array_List[i].kind) || (RAM2_KIND == Array_List[i].kind)) {
4894 flag = true;
4895 break;
4896 }
4897 }
4898 if (!flag) {
4899 return;
4900 }
4901 (void) fprintf(STDOUT, " /* (RAM access report) */\n");
4902 for (i = 0L; i < Num_Arrays; i++) {
4903 if ((ROM_KIND == Array_List[i].kind) || (ROM2_KIND == Array_List[i].kind) || (UNKNOWN_KIND == Array_List[i].kind)) {
4904 continue;
4905 }
4906 (void) strcpy(v0, Array_List[i].name);
4907 (void) strcpy(v1, v0);
4908 (void) build_name("", v1, LEFT_VALUE);
4909 (void) fprintf(STDOUT, " if ( ISNOTSMALL(%s.last) ) {\n", v1 );
4910 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Information: loop[%%lld] (array)\\n\", (I_TYPE) %s.last );\n", v1);
4911 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Last access to uninitialized data in RAM <%s[%%lld]>\\n\", %s.length);\n", v0, v1);
4912 (void) fprintf(STDOUT, " if ( EOF == fflush((FILE*) NULL) ) {\n");
4913 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (array)\");\n");
4914 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Flushing data from buffers I/O was not successful\\n\");\n");
4915 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n" );
4916 (void) fprintf(STDOUT, " }\n");
4917 (void) fprintf(STDOUT, " }\n");
4918 }
4919 (void) fprintf(STDOUT, "\n");
4920 return;
4921}
4922
4923
4924void call_ping_1(void) { /* goal: to get this info asap on screen */
4925 if ((Ping_Flag) && (0 == strcmp(Ping_List.fname, "stderr"))) { /* see also 'main()' and 'call_ping2()' */
4926 if (1L == Num_Functions) {
4927 (void) fprintf(STDOUT, " /* (ping function defined in netlist) */\n");
4928 } else {
4929 (void) fprintf(STDOUT, " /* (ping functions defined in netlist) */\n");
4930 }
4931 (void) fprintf(STDOUT, " napa_ping(true);\n\n");
4932 }
4933 return;
4934}
4935
4936
4937void call_ping_2(void) { /* need to wait for output banner before processing */
4938 if ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr"))) { /* see also 'main()' and 'call_ping1()' */
4939 if (1L == Num_Functions) {
4940 (void) fprintf(STDOUT, "\n /* (ping function defined in netlist) */\n");
4941 } else {
4942 (void) fprintf(STDOUT, "\n /* (ping functions defined in netlist) */\n");
4943 }
4944 (void) fprintf(STDOUT, " napa_ping(false);\n");
4945 }
4946 return;
4947}
4948
4949
4951 if ((Output_Flag) || (Dump_Flag) || (Assert_Flag) || (Cmdline_Flag)) {
4952 return; /* no check of output existence */
4953 }
4954 (void) fprintf(STDOUT, "\n /* (check output) */\n");
4955 (void) fprintf(STDOUT, " if ( !napa_output_flag ) {\n");
4956 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Warning: ( I/O stream)\\n\");\n");
4957 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" there is no explicit output from simulator.\\n\\n\" );\n");
4958 (void) fprintf(STDOUT, " }\n");
4959 return;
4960}
4961
4962
4964 long i;
4965 int len;
4966 if (!Ping_Flag) {
4967 return;
4968 }
4969 (void) fprintf(STDOUT, "\n\n/* *** PING FUNCTION %s */\n", multiple('*', 106L));
4970 (void) fprintf(STDOUT, "\nvoid napa_ping(int always) {");
4971 if ((0L >= Num_UserTools) && (0L >= Num_Functions) && (0L >= Num_Macros)) { /* empty ping function */
4972 (void) fprintf(STDOUT, "\n");
4973 } else {
4974 (void) fprintf(STDOUT, " %*s /* localisation of functions identified in the netlist %*s */\n", 27, " ", 15, " ");
4975 }
4976 (void) fprintf(STDOUT, " static int done = false;\n");
4977 (void) fprintf(STDOUT, " if ( !always && done ) {\n");
4978 (void) fprintf(STDOUT, " return;\n");
4979 (void) fprintf(STDOUT, " }\n");
4980 if ((0L >= Num_UserTools) && (0L >= Num_Functions) && (0L >= Num_Macros)) { /* empty ping function */
4981 if (0 == strcmp(Ping_List.fname, "stderr")) {
4982 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\"); /* no function call in user's netlist */\n");
4983 } else {
4984 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \"\\n\"); /* no function call in user's netlist */\n");
4985 }
4986 (void) fprintf(STDOUT, " done = true;\n");
4987 (void) fprintf(STDOUT, " return;\n" );
4988 (void) fprintf(STDOUT, "}\n");
4989 return;
4990 }
4991 if (0 == strcmp(Ping_List.fname, "stderr")) {
4992 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\n\\n\");\n");
4993 } else {
4994 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \"\\n\");\n" );
4995 }
4996 if (1L < Num_Functions) {
4997 qsort((void*) Function_List, (size_t) Num_Functions, sizeof (Function_List[0]), sort_names);
4998 }
4999 for (i = 0L; i < Num_Functions; i++) { /* start by tool and user function */
5000 if (0L >= Function_List[i].number) { /* not a tool or user node */
5001 continue;
5002 }
5003 if (0 == strcmp(Function_List[i].table, "post_void")) { /* instruction 'void' */
5004 continue;
5005 }
5006 (void) fprintf(STDOUT, "#if defined(%s_IS_REGISTERED)\n", Function_List[i].table);
5007 (void) fprintf(STDOUT, " napa_ping_%s();", Function_List[i].table);
5008 len = MIN(39, (int) strlen(Function_List[i].table));
5009 (void) fprintf(STDOUT, " %*s /* as defined by macro 'PING( %s )' %*s*/\n", 40-len, " ", Function_List[i].table, 37-len, " ");
5010 (void) fprintf(STDOUT, "#else\n" );
5011 (void) fprintf(STDOUT, " PING_FAIL(%s);\n", Function_List[i].table);
5012 (void) fprintf(STDOUT, "#endif\n");
5013 }
5014 for (i = 0L; i < Num_Functions; i++) { /* continue with other functions */
5015 if (0L < Function_List[i].number) { /* not a function */
5016 continue;
5017 }
5018 if (0 == strcmp(Function_List[i].table, "post_void")) { /* instruction 'void' */
5019 continue;
5020 }
5021 (void) fprintf(STDOUT, "#if defined(%s_IS_REGISTERED)\n", Function_List[i].table);
5022 (void) fprintf(STDOUT, " napa_ping_%s();", Function_List[i].table);
5023 len = MIN(39, (int) strlen(Function_List[i].table));
5024 (void) fprintf(STDOUT, " %*s /* as defined by macro 'PING( %s )' %*s*/\n", 40-len, " ", Function_List[i].table, 37-len, " ");
5025 (void) fprintf(STDOUT, "#else\n");
5026 (void) fprintf(STDOUT, " PING_FAIL(%s);\n", Function_List[i].table);
5027 (void) fprintf(STDOUT, "#endif\n");
5028 }
5029 for (i = 0L; i < Num_Directives; i++) {
5030 if (Directive_List[i].function) { /* a macro function is defined in a directive */
5031 (void) fprintf(STDOUT, " napa_ping_%s();\n", Directive_List[i].name);
5032 continue;
5033 }
5034 }
5035 (void) fprintf(STDOUT, " done = true;\n");
5036 (void) fprintf(STDOUT, " return;\n" );
5037 (void) fprintf(STDOUT, "}\n");
5038 return;
5039}
5040
5041
5043 if ((Output_Flag) || (Dump_Flag) || ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr")))) {
5044 if (1L == Num_IOs) {
5045 (void) fprintf(STDOUT, "\n /* (write file banner opening) */\n");
5046 } else {
5047 (void) fprintf(STDOUT, "\n /* (write file banner openings) */\n");
5048 }
5049 (void) fprintf(STDOUT, " napa_file_banner();\n");
5050 }
5051 return;
5052}
5053
5054
5055void print_output_banner_1(long i, long j) {
5056 char frqs[STRLENGTH] = {'\0'};
5057 (void) snprintf(frqs, (size_t) (STRLENGTH-1L), "%s", format_suffixed_number(Segment_List[IO_List[i].segment].frequency, 6, "Hz"));
5058 if (0 == strcmp("stderr", IO_List[i].fname)) { /* minimal banner for an stderr output */
5059 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (time domain output)\\n\");\n", i);
5060 return;
5061 }
5062 (void) fprintf(STDOUT, " #if !defined(NO_BANNER)\n");
5063 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# %%s\\n\", TITLE);\n", i);
5064 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (time domain output ) Sampled at %s\\n\");\n", i, frqs);
5065 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (compiler version ) NAPA %%s\\n\", NAPA_VERSION);\n", i );
5066 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (source file ) \\\"%%s\\\"\\n\", SOURCE);\n", i );
5067 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (random seed ) %%lld\\n\", RANDOM_SEED);\n", i );
5068 (void) fprintf(STDOUT, " #if defined(NO_TIME_OUTPUT)\n");
5069 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (number of columns ) %ld\\n#\\n#\\n#\\n#\\n#\\n#\\n#\\n\");\n", i, j );
5070 (void) fprintf(STDOUT, " #else\n");
5071 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (number of columns ) %ld\\n#\\n#\\n#\\n#\\n#\\n#\\n#\\n\");\n", i, j+1L);
5072 (void) fprintf(STDOUT, " #endif\n");
5073 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# %%s\\n\", CREATED);\n", i);
5074 (void) fprintf(STDOUT, " #endif\n");
5075 return;
5076}
5077
5078
5079void print_output_banner_2(long i) { /* for file corresponding to filepointer #i */
5080 int space;
5081 long j, k, p;
5082 long nv;
5083 char *str = (char*) NULL;
5084 char scale[STRLENGTH] = {'\0'};
5085 char tok1[STRLENGTH] = {'\0'};
5086 char tok2[STRLENGTH] = {'\0'};
5087 char tok3[STRLENGTH] = {'\0'};
5088 char frm[LINLENGTH] = {'\0'};
5089 char sgn[2] = {'\0'};
5090 (void) fprintf(STDOUT, " #if defined(NO_TIME_OUTPUT)\n");
5091 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"#\");\n", i);
5092 (void) fprintf(STDOUT, " #else\n" );
5093 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# absolute_time \");\n", i);
5094 (void) fprintf(STDOUT, " #endif\n");
5095 space = false;
5096 str = IO_List[i].element; /* unprocessed list of elements for this file */
5097 for (;;) {
5098 str = get_output_and_scaling(str, sgn, tok1, scale);
5099 if (ISEMPTY(tok1)) {
5100 break;
5101 }
5102 if (!((0L == LENGTH(scale)) || /* empty scale */
5103 ((1L == LENGTH(scale)) && ('_' != scale[0])) || /* single letter, not '_' */
5104 ((1L < LENGTH(scale)) && ('_' == scale[0])) || /* '_' followed by text */
5105 ((2L < LENGTH(scale)) && ('_' != scale[0]) && ('_' == scale[1])) )) { /* single letter followed by '_' and text */
5106 print_error_location("output", IO_List[i].mline, IO_List[i].mfile);
5107 (void) fprintf(STDERR, " the scaling (%s) of element <%s> of output list is not valid\n", scale, tok1);
5108 (void) fprintf(STDERR, " the scaling single letter must be separated from other text by '_'\n");
5109 }
5110 if ((2L < LENGTH(scale)) && ('_' == scale[1])) { /* single letter followed by '_' and text */
5111 for (p = 2L; p <= LENGTH(scale); p++) {
5112 scale[p-1L] = scale[p]; /* remove '_' in second position */
5113 }
5114 }
5115 if (0 == strcmp(tok1, "LOOP_INDEX") ) { (void) strcpy(frm, " LOOP_INDEX" );
5116 } else if (0 == strcmp(tok1, "ABS_LOOP_INDEX")) { (void) strcpy(frm, " ABS_LOOP_INDEX" );
5117 } else if (0 == strcmp(tok1, "REL_LOOP_INDEX")) { (void) strcpy(frm, " REL_LOOP_INDEX" );
5118 } else if (0 == strcmp(tok1, "TOOL_INDEX") ) { (void) strcpy(frm, " TOOL_INDEX" );
5119 } else if (0 == strcmp(tok1, "TIME") ) { (void) strcpy(frm, " absolute_time");
5120 } else if (0 == strcmp(tok1, "ABS_TIME") ) { (void) strcpy(frm, " absolute_time");
5121 } else if (0 == strcmp(tok1, "REF_TIME") ) { (void) strcpy(frm, " reference_time");
5122 } else if (0 == strcmp(tok1, "REL_TIME") ) { (void) strcpy(frm, " relative_time");
5123 } else {
5124 j = get_type(tok1);
5125 (void) snprintf(tok2, (size_t) (STRLENGTH-1L), "%1s", tok1);
5126 if (DIGITAL_DATA_TYPE == j) { /* no need to indicate hexa format option if any */
5127 if ((0 == strncmp(scale, "X", (size_t) 1)) || (0 == strncmp(scale, "x", (size_t) 1))) { /* hexa output format */
5128 (void) snprintf(frm, (size_t) (STRLENGTH-1L), X_String_Format, tok2);
5129 } else {
5130 (void) snprintf(frm, (size_t) (STRLENGTH-1L), I_String_Format, tok2);
5131 }
5132 } else if (ANALOG_DATA_TYPE == j) {
5133 if (ISEMPTY(scale)) {
5134 (void) snprintf(frm, (size_t) (STRLENGTH-1L), R_String_Format, tok2);
5135 } else {
5136 if (0 == strcmp(scale, "%")) {
5137 (void) snprintf(tok3, (size_t) (STRLENGTH-1L), "%s(%%%%)", tok2); /* %% is printed % */
5138 (void) snprintf(frm, (size_t) (STRLENGTH-1L), R_String_Format, tok3);
5139 space = true; /* one space to get right formatting */
5140 } else {
5141 if ('_' == scale[0]) { /* remove '_' in first place if any */
5142 for (k = 0L; k < (LENGTH(scale) - 1L); k++) {
5143 scale[k] = scale[k+1];
5144 }
5145 scale[k] = '\0';
5146 }
5147 (void) snprintf(tok3, (size_t) (STRLENGTH-1L), "%s(%s)", tok2, scale);
5148 (void) snprintf(frm, (size_t) (STRLENGTH-1L), R_String_Format, tok3 );
5149 }
5150 }
5151 } else if (STRING_DATA_TYPE == j) {
5152 if (0 != strcmp("Space", tok1)) { /* not the token 'Space' */
5153 (void) snprintf(frm, (size_t) (STRLENGTH-1L), S_String_Format, tok1); /* ignore sign ! */
5154 } else { /* a token with the prefix 'Space' */
5155 nv = var_id(tok1);
5156 (void) snprintf(frm, (size_t) (STRLENGTH-1L), "%*s", (int) (LENGTH(Var_List[nv].value)-2L), " "); /* white spaces */
5157 }
5158 }
5159 }
5160 if (space) {
5161 if (ISNOTEMPTY(str)) {
5162 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \" %s\" );\n", i, frm);
5163 } else {
5164 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \" %s\\n\");\n", i, frm);
5165 break;
5166 }
5167 } else {
5168 if (ISNOTEMPTY(str)) {
5169 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \" %s\" );\n", i, frm);
5170 } else {
5171 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \" %s\\n\");\n", i, frm);
5172 break;
5173 }
5174 }
5175 }
5176 return;
5177}
5178
5179
5181 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" %%s\\n\", TITLE);\n" );
5182 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" (ping information )\\n\");\n");
5183 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" (compiler version ) NAPA %%s\\n\", NAPA_VERSION);\n");
5184 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" (source file ) \\\"%%s\\\"\\n\", SOURCE);\n" );
5185 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" (random seed ) %%lld\\n\", RANDOM_SEED);\n" );
5186 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \" %%s\\n\", CREATED);\n");
5187 return;
5188}
5189
5190
5191void print_output_banner_4(char *tok) {
5192 int flag;
5193 char *str1 = (char*) NULL;
5194 char *str2 = (char*) NULL;
5195 char tok1[LINLENGTH] = {'\0'};
5196 char tok2[LINLENGTH] = {'\0'};
5197
5198 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** THIS DUMP FILE CREATED BY NAPA %6s [%5s] AT RUN TIME,\");\n",
5200 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" IS BUILT TO BE LOADED BY THE INSTRUCTION 'load'. %%9s *** */\\n\", \" \");\n");
5201 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %24s %%92s *** */\\n\\n\", \" \");\n", NAPA_Compile_Time);
5202 (void) strcpy(tok, "\"/* *** SOURCE: %-109s *** */\\n\\n\"");
5203 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, %s, SOURCE);\n", tok);
5204 (void) snprintf(tok1, (size_t) (LINLENGTH-1L), "%s", Title_String);
5205 str1 = tok1;
5206 str2 = tok2;
5207 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\", \" \");\n" );
5208 while (ISNOTEMPTY(str1)) { /* cut Title_String in lines */
5209 str1 = extract_line(str1, str2);
5210 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%s\", \"%s\");\n", str2 );
5211 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" %%*s *** */\\n\", %d, \" \");\n", (115 - ((int) strlen(str2))));
5212 }
5213 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\\n\\n\", \" \");\n");
5214 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\", \" \");\n" );
5215 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\\n\", \" \");\n" );
5216 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#undef DUMP_FLAG\\n\\n\");\n" );
5217 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define DUMP_IS_REGISTERED\\n\\n\");\n" );
5218 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define NO_ARRAY_IS_REGISTERED\\n\");\n" );
5219 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define NO_GLOBAL_IS_REGISTERED\\n\");\n" );
5220 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define NO_NODE_IS_REGISTERED\\n\");\n" );
5221 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define NO_TOOL_IS_REGISTERED\\n\");\n" );
5222 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#define NO_VAR_IS_REGISTERED\\n\\n\");\n" );
5223 flag = false;
5224 if (0L < Num_UserTools) {
5225 flag = true;
5226 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* The content of user-defined functions is not dumped by NAPA. %%61s *** */\\n\", \" \");\n");
5227 }
5228 if (!Periodic_Flag) {
5229 flag = true;
5230 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* A user-defined formula was used to compute the NAPA time global variables. %%47s *** */\\n\", \" \");\n");
5231 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* This formula is not recorded in this dump file. %%74s *** */\\n\", \" \");\n");
5232 }
5233 if (flag) {
5234 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* Therefore, this dump file could not contain all\");\n" );
5235 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" the data necessary to continue the simulation. %%27s *** */\\n\", \" \");\n" );
5236 }
5237 if (Stuck_Flag) {
5238 if (1L < Num_Stucks) {
5239 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** CAUTION *** %3ld nodes have been stuck by user!%%71s", Num_Stucks );
5240 (void) fprintf(STDOUT, " *** */\\n\\n\", \" \");\n");
5241 } else {
5242 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** CAUTION *** A node has been stuck by user!%%74s" );
5243 (void) fprintf(STDOUT, " *** */\\n\\n\", \" \");\n");
5244 }
5245 }
5246 return;
5247}
5248
5249
5251 long o, j;
5252 char *str = (char*) NULL;
5253 char scale[STRLENGTH] = {'\0'};
5254 char tok[STRLENGTH] = {'\0'};
5255 char sgn[2] = {'\0'};
5256 if ((!Output_Flag) && (!Dump_Flag) && ((!Ping_Flag) || (0 == strcmp(Ping_List.fname, "stderr")))) {
5257 return;
5258 }
5259 (void) fprintf(STDOUT, "\nvoid napa_file_banner(void) {\n" );
5260 (void) fprintf(STDOUT, "#if defined(STRICTLY_NO_BANNER)\n");
5261 (void) fprintf(STDOUT, " return;\n");
5262 (void) fprintf(STDOUT, "#else\n" );
5263 if (Output_Flag) {
5264 for (o = 0L; o < Num_IOs; o++) {
5265 if (OUTPUT_TYPE == IO_List[o].type) {
5266 j = 0L;
5267 str = IO_List[o].element;
5268 for (;;) {
5269 str = get_output_and_scaling(str, sgn, tok, scale);
5270 if (ISEMPTY(tok)) {
5271 break;
5272 }
5273 j++;
5274 }
5275 (void) fprintf(STDOUT, " if ( (2 == napa_waypoint) || (3 == napa_waypoint) ) {\n");
5277 (void) fprintf(STDOUT, " }\n");
5278 (void) fprintf(STDOUT, " if ( (2 == napa_waypoint) || (3 == napa_waypoint) || (5 == napa_waypoint) ) {\n");
5280 (void) fprintf(STDOUT, " }\n");
5281 if (0 != strcmp("stderr", IO_List[o].fname)) {
5282 (void) fprintf(STDOUT, " #if !defined(NO_BANNER)\n");
5283 (void) fprintf(STDOUT, " if ( 5 == napa_waypoint ) {\n");
5284 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"#\\n\");\n", o);
5285 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"# (end of output file )\\n\");\n", o);
5286 (void) fprintf(STDOUT, " }\n");
5287 (void) fprintf(STDOUT, " #endif\n");
5288 }
5289 }
5290 }
5291 }
5292 if ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr"))) {
5293 (void) fprintf(STDOUT, " if ( (2 == napa_waypoint) || (3 == napa_waypoint) ) {\n");
5295 (void) fprintf(STDOUT, " }\n");
5296 (void) fprintf(STDOUT, " if ( 5 == napa_waypoint ) {\n");
5297 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_ping, \"\\n **** end of ping file\\n\");\n");
5298 (void) fprintf(STDOUT, " }\n");
5299 }
5300 if (Dump_Flag) {
5301 (void) fprintf(STDOUT, " if ( (2 == napa_waypoint) || (3 == napa_waypoint) ) {\n");
5303 (void) fprintf(STDOUT, " }\n");
5304 (void) fprintf(STDOUT, " if ( 5 == napa_waypoint ) {\n");
5305 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** %%118s *** */\\n\", \" \");\n");
5306 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\\n\", \" \");\n");
5307 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" #if !defined(DUMP_FLAG)\\n\");\n" );
5308 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \" (void) fprintf(stderr, \\\" has no effect.\\\\n\\\\n\\\");\\n\");\n");
5309 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"#endif\\n\\n\");\n" );
5310 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"\\n/* *** %%118s *** */\\n\", \" \");\n");
5311 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** %%118s *** */\\n\\n\", \" \");\n");
5312 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_dump, \"/* *** End of dump file %%101s *** */\\n\", \" \");\n");
5313 (void) fprintf(STDOUT, " }\n");
5314 }
5315 if (Output_Flag) {
5316 (void) fprintf(STDOUT, " if ( (4 == napa_waypoint) && (!TERMINATE) ) {\n");
5317 for (o = 0L; o < Num_IOs; o++) {
5318 if (OUTPUT_TYPE == IO_List[o].type) {
5319 (void) fprintf(STDOUT, " ");
5320 build_condition(IO_List[o].condition, IO_List[o].mline, IO_List[o].mfile);
5321 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, \"\\n%%s\", SEPARATOR);\n", o);
5322 (void) fprintf(STDOUT, " }\n" );
5323 }
5324 }
5325 (void) fprintf(STDOUT, " }\n" );
5326 }
5327 (void) fprintf(STDOUT, " return;\n");
5328 (void) fprintf(STDOUT, "#endif\n" );
5329 (void) fprintf(STDOUT, "}\n" );
5330 return;
5331}
5332
5333
5335 if (0L < Num_UserTools) {
5336 if (1L == Num_UserTools) {
5337 (void) fprintf(STDOUT, "\n /* (call user's closedown function) */\n");
5338 } else {
5339 (void) fprintf(STDOUT, "\n /* (call user's closedown functions) */\n");
5340 }
5341 call_user_functions("", "close_");
5342 }
5343 if (0L < Num_Posts) {
5344 if (1L == Num_Posts) {
5345 (void) fprintf(STDOUT, "\n /* (call postprocess function) */\n");
5346 } else {
5347 (void) fprintf(STDOUT, "\n /* (call postprocess functions) */\n");
5348 }
5349 call_postprocess_functions("", "execute_");
5350 }
5351 return;
5352}
5353
5354
5355void call_postprocess_functions(const char *indent, const char *type) {
5356 long i;
5357 long prev_nseg, nseg;
5358 char *s = (char*) NULL;
5359 char sgn[2] = {'\0'};
5360 char tok[STRLENGTH] = {'\0'};
5361 char v1[STRLENGTH] = {'\0'};
5362 prev_nseg = -1L;
5363 for (i = 0L; i < Num_Posts; i++) {
5364 if (0 == strcmp(Post_List[i].function, "post_void")) {
5365 continue;
5366 }
5367 nseg = Post_List[i].segment;
5368 if (nseg != prev_nseg) {
5369 if (1L < Num_Segments) {
5370 (void) fprintf(STDOUT, "%s napa_segment = %ldL;\n", indent, nseg);
5371 }
5372 prev_nseg = nseg;
5373 }
5374 (void) fprintf(STDOUT, " %s%s", indent, type);
5375 (void) fprintf(STDOUT, "%s_%02ld(", Post_List[i].function, Post_List[i].number);
5376 (void) fprintf(STDOUT, "\"%s\", ", Post_List[i].origin );
5377 s = Post_List[i].parms;
5378 for (;;) {
5379 s = get_sign_and_token(s, sgn, tok);
5380 if (ISEMPTY(tok)) {
5381 break;
5382 }
5383 (void) strcpy(v1, tok);
5384 (void) build_name("", v1, RIGHT_VALUE);
5385 replace_dollar(v1); /* remove $ in the qualifier identifier */
5386 (void) fprintf(STDOUT, "%s%s,", sgn, v1);
5387 }
5388 (void) fprintf(STDOUT, " %ld);\n", Post_List[i].ID);
5389 }
5390 return;
5391}
5392
5393
5394void close_IO_files(void) {
5395 long i, n;
5396 char tok[STRLENGTH] = {'\0'};
5397 char v1[LINLENGTH] = {'\0'};
5398 if (!Loop_Flag) { /* when no main loop is built */
5399 (void) fprintf(STDOUT, " napa_waypoint = 5;\n");
5400 }
5401 if ((Output_Flag) || (Dump_Flag) || ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr")))) {
5402 if (1L == Num_IOs) {
5403 (void) fprintf(STDOUT, "\n /* (write file banner closing) */\n");
5404 } else {
5405 (void) fprintf(STDOUT, "\n /* (write file banner closings) */\n");
5406 }
5407 (void) fprintf(STDOUT, " napa_file_banner();\n\n");
5408 }
5409 if (0L < Num_IOs) {
5410 if (1L == Num_IOs) {
5411 (void) fprintf(STDOUT, " /* (close I/O stream) */\n");
5412 } else {
5413 (void) fprintf(STDOUT, " /* (close I/O streams) */\n");
5414 }
5415 for (i = 0L; i < Num_IOs; i++) {
5416 if (OUTPUT_TYPE == IO_List[i].type) {
5417 n = var_id(IO_List[i].fname);
5418 if (UNDEFINED != n) {
5419 (void) strcpy(tok, Var_List[n].name1);
5420 (void) strcpy(v1, tok);
5421 (void) build_name("", v1, RIGHT_VALUE);
5422 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_%ld, %s, \".out\", \"output\");\n", i, v1);
5423 } else {
5424 (void) strcpy(tok, IO_List[i].fname);
5425 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_%ld, \"%s\", \".out\", \"output\");\n", i, tok);
5426 }
5427 } else if (INPUT_TYPE == IO_List[i].type) {
5428 n = var_id(IO_List[i].fname);
5429 if (UNDEFINED != n) {
5430 (void) strcpy(tok, Var_List[n].name1);
5431 (void) strcpy(v1, tok);
5432 (void) build_name("", v1, RIGHT_VALUE);
5433 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_%ld, %s, \".in\", \"input\");\n", i, v1);
5434 } else {
5435 (void) strcpy(tok, IO_List[i].fname);
5436 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_%ld, \"%s\", \".in\", \"input\");\n", i, tok);
5437 }
5438 }
5439 }
5440 }
5441 if ((Ping_Flag) && (0 != strcmp(Ping_List.fname, "stderr"))) {
5442 (void) fprintf(STDOUT, "\n /* (close ping file) */\n");
5443 n = var_id(Ping_List.fname);
5444 if (UNDEFINED != n) {
5445 (void) strcpy(tok, Var_List[n].name1);
5446 (void) strcpy(v1, tok);
5447 (void) build_name("", v1, RIGHT_VALUE);
5448 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_ping, %s, \".png\", \"ping\");\n", v1);
5449 } else {
5450 (void) strcpy(tok, Ping_List.fname);
5451 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_ping, \"%s\", \".png\", \"ping\");\n", tok);
5452 }
5453 }
5454 if (Dump_Flag) {
5455 if (0L >= Num_IOs) {
5456 (void) fprintf(STDOUT, "\n /* (close dump file) */\n");
5457 }
5458 n = var_id(Dump_List.fname);
5459 if (UNDEFINED != n) {
5460 (void) strcpy(tok, Var_List[n].name1);
5461 (void) strcpy(v1, tok);
5462 (void) build_name("", v1, RIGHT_VALUE);
5463 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_dump, %s, \".dmp\", \"dump\");\n\n", v1);
5464 } else {
5465 (void) strcpy(tok, Dump_List.fname);
5466 (void) fprintf(STDOUT, " (void) IO_MANAGER(CLOSE, &napa_fp_dump, \"%s\", \".dmp\", \"dump\");\n\n", tok);
5467 }
5468 }
5469 return;
5470}
5471
5472
5473void close_main(void) {
5474 (void) fprintf(STDOUT, "\n /* (end of simulation) */\n");
5475 (void) fprintf(STDOUT, " napa_waypoint = 6;\n" );
5476 (void) fprintf(STDOUT, " napa_exit(EXIT_SUCCESS);\n\n");
5477 (void) fprintf(STDOUT, "}\n");
5478 return;
5479}
5480
5481
5483 (void) fprintf(STDERR, "\n");
5484 (void) fprintf(STDOUT, "\n\n/* ******************************************************** */\n" );
5485 (void) fprintf(STDOUT, "/* **** NAPA COMPILER [%20s] **** */\n", NAPA_Identification_String);
5486 (void) fprintf(STDOUT, "/* **** ABNORMAL TERMINATION! **** */\n" );
5487 (void) fprintf(STDOUT, "/* ******************************************************** */\n\n\n");
5488 if (1 < Error_Flag) {
5489 (void) fprintf(STDOUT, "/* NAPA %6s has issued %2d error messages on %-12s */\n\n\n", NAPA_COMPILER_VERSION, Error_Flag, "stderr");
5490 } else {
5491 (void) fprintf(STDOUT, "/* NAPA %6s has issued an error message on %-13s */\n\n\n", NAPA_COMPILER_VERSION, "stderr");
5492 }
5493 if ((!Expand_Flag) && (!List_Flag)) {
5494 (void) fprintf(STDOUT, "#include <stdio.h>\n\n");
5495 (void) fprintf(STDOUT, "int main() {\n\n" );
5496 (void) fprintf(STDOUT, " fprintf(stderr, \"\\n\\n ****\\n\");\n");
5497 (void) fprintf(STDOUT, " fprintf(stderr, \" **** No code has been produced\\n\");\n");
5498 (void) fprintf(STDOUT, " fprintf(stderr, \" ****\\n\");\n" );
5499 (void) fprintf(STDOUT, " return 0;\n");
5500 (void) fprintf(STDOUT, "\n}\n" );
5501 }
5502 exit(EXIT_SUCCESS); /* this small code is submitted to the C compiler */
5503}
5504
5505
5506void that_s_all(void) {
5507 long n;
5508 int flag;
5509 flag = true;
5510 for (n = 0L; n < Num_Nodes; n++) {
5511 flag = (int) ((Node_List[n].used) && flag);
5512 }
5513 for (n = 0L; n < Num_Vars; n++) {
5514 flag = (int) ((Var_List[n].used) && flag);
5515 }
5516 for (n = 0L; n < Num_Arrays; n++) {
5517 flag = (int) ((Array_List[n].used) && flag);
5518 }
5519 if ((!flag) && (Loop_Flag)) {
5520 (void) fprintf(STDERR, "\nNAPA Compiler Warning (unused element):\n");
5521 for (n = 0L; n < Num_Nodes; n++) {
5522 if (!Node_List[n].used) {
5523 (void) fprintf(STDERR, " -> Node %s\n", Node_List[n].name1);
5524 }
5525 }
5526 for (n = 0L; n < Num_Vars; n++) {
5527 if (!Var_List[n].used) {
5528 (void) fprintf(STDERR, " -> Var %s\n", Var_List[n].name1 );
5529 }
5530 }
5531 for (n = 0L; n < Num_Arrays; n++) {
5532 if (!Array_List[n].used) {
5533 (void) fprintf(STDERR, " -> Array %s\n", Array_List[n].name);
5534 }
5535 }
5536 (void) fprintf(STDERR, "\n");
5537 }
5538 if ((Tool_Index_Flag) && (!Synchro_Flag)) {
5539 (void) fprintf(STDERR, "\nNAPA Error: (tool)\n\n");
5540 (void) fprintf(STDERR, " the TOOL_INDEX is not REGISTERED, as tool synchronization has been cut off");
5541 if ((1L > Num_Tools) && (0 == Error_Flag)) {
5542 (void) fprintf(STDERR, " and/or no tool has been instantiated");
5543 }
5544 (void) fprintf(STDERR, "\n");
5545 Error_Flag++;
5546 }
5547 if ((Tool_Index_Flag) && (1L > Num_Tools) && (0 == Error_Flag)) {
5548 (void) fprintf(STDERR, "\nNAPA Error: (tool)\n\n");
5549 (void) fprintf(STDERR, " the TOOL_INDEX is not REGISTERED, as no tool has been instantiated\n");
5550 Error_Flag++;
5551 }
5552 NAPA_Compile_Stop = ((double) clock())/((double) CLOCKS_PER_SEC);
5553 n = LENGTH(User_Name);
5554 if ((0L == n) || (31L < n)) {
5555 (void) fprintf(STDOUT, "\n\n/* *** C CODE PRODUCED BY THE NAPA COMPILER IN%s",
5557 (void) fprintf(STDOUT, " (WALL CLOCK) %s */\n\n", multiple('*', 58L));
5558 } else {
5559 (void) fprintf(STDOUT, "\n\n/* *** C CODE PRODUCED BY THE NAPA COMPILER IN%s (WALL CLOCK) FOR '%s' %s */\n\n",
5561 }
5562 if ((Warning_Flag) && (0 == Error_Flag)) {
5563 (void) fprintf(STDERR, "\n");
5564 }
5565 (void) f1flush((FILE*) NULL);
5566 return;
5567}
5568
5569
5570void call_user_functions(const char *indent, const char *type) {
5571 long i;
5572 long n;
5573 long kd;
5574 long first;
5575 char *str = (char*) NULL;
5576 long nseg, prev_nseg;
5577 char tok1[LINLENGTH] = {'\0'};
5578 char tok2[LINLENGTH] = {'\0'};
5579 char v1[LINLENGTH] = {'\0'};
5580 char v2[LINLENGTH] = {'\0'};
5581 if (0L == Num_UserTools) {
5582 return;
5583 }
5584 prev_nseg = -1L;
5585 for (i = 0L; i < Num_UserTools; i++) { /* function defined in user's xxx.hdr */
5586 kd = UserTool_List[i].kind;
5587 if (((ITOOL_KIND == kd) || (DTOOL_KIND == kd)) && (0 == strcmp(type,"reset_"))) {
5588 continue; /* tools are not reset by global reset */
5589 }
5590 nseg = UserTool_List[i].segment;
5591 if (nseg != prev_nseg) {
5592 if (1L < Num_Segments) { /* not necessary if only one segment */
5593 (void) fprintf(STDOUT, "%s napa_segment = %ldL;\n", indent, nseg);
5594 }
5595 prev_nseg = nseg;
5596 }
5597 if ((1L < Num_Tools) && (UNDEFINED != UserTool_List[i].mailbox)) { /* fixed addr if one tool */
5598 (void) fprintf(STDOUT, "%s napa_msg = &(napa_mailbox[%ld]);\n", indent, UserTool_List[i].mailbox);
5599 }
5600 (void) fprintf(STDOUT, "%s %s%s_%02ld(", indent, type, UserTool_List[i].function, UserTool_List[i].number);
5601 first = true;
5602 str = UserTool_List[i].parms;
5603 str = get_token(str, tok1, true); /* skip function */
5604 for (;;) {
5605 str = get_token(str, tok1, true); /* some parameters can be strings */
5606 if (ISEMPTY(tok1)) {
5607 if (first) {
5608 (void) fprintf(STDOUT, " %ld);\n", UserTool_List[i].ID);
5609 } else {
5610 (void) fprintf(STDOUT, ", %ld);\n", UserTool_List[i].ID);
5611 }
5612 break;
5613 }
5614 if ((0 == strcmp(tok1, "after")) || (0 == strcmp(tok1, "with"))) { /* skip node after these tokens */
5615 str = get_token(str, tok1, false);
5616 continue;
5617 }
5618 if (0 == strcmp(tok1, "-")) {
5619 (void) strcpy(v1, "-");
5620 str = get_token(str, tok1, true);
5621 } else {
5622 (void) strcpy(v1, "");
5623 }
5624 if ('$' == tok1[(LENGTH(tok1))-1L]) {
5625 replace_dollar(tok1); /* remove temporary '$' if any */
5626 (void) strcat(v1, tok1);
5627 } else if (UNDEFINED != (n = node_id(tok1))) {
5628 (void) strcpy(v2, Node_List[n].name1);
5629 (void) build_name("", v2, RIGHT_VALUE);
5630 (void) strcat(v1, v2);
5631 } else if (UNDEFINED != (n = var_id(tok1))) {
5632 (void) strcpy(v2, Var_List[n].name1);
5633 (void) build_name("", v2, RIGHT_VALUE);
5634 (void) strcat(v1, v2);
5635 } else if (UNDEFINED != (n = record_id(tok1))) {
5636 (void) strcpy(v1, Record_List[n].name);
5637 (void) build_name("", v1, RIGHT_VALUE);
5638 } else if ((0 == strcmp(tok1,"stdout")) || (0 == strcmp(tok1,"stdin")) || (0 == strcmp(tok1,"stderr"))) { /* IO without "" */
5639 (void) strcpy(tok2, tok1);
5640 (void) snprintf(tok1, (size_t) (LINLENGTH-1L), "\"%s\"", tok2); /* place IO token between double quotes */
5641 (void) strcat(v1, tok1);
5642 } else {
5643 (void) strcat(v1, tok1);
5644 }
5645 if (!first) {
5646 (void) fprintf(STDOUT, ",");
5647 }
5648 (void) fprintf(STDOUT, "%s", v1);
5649 first = false;
5650 }
5651 }
5652 return;
5653}
5654
5655
5656/* ****************************************************************************************************************************** */
5657/* end of file */
int verify_rshift(void)
Definition fc.c:1400
void print_location(const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1510
void cat_file(const char *fnam, const char *type, long command, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1411
void build_condition(char *cond, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:958
void print_warning_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1484
void print_error_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:1476
int test_endianness(void)
Definition fc.c:1537
double GCD(double a, double b)
Definition fc.c:1378
long constant_type(char *identifier)
Definition id.c:1130
long get_type(char *identifier)
Definition id.c:1190
int variable_update_block(void)
Definition id.c:1083
long update_id(const char *identifier, long num)
Definition id.c:807
long cmdline_id(const char *identifier)
Definition id.c:657
void strcpy_alloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
Definition id.c:114
long directive_id(const char *identifier)
Definition id.c:707
int time_output_block(void)
Definition id.c:1114
long node_id(const char *identifier)
Definition id.c:718
long var_id(const char *identifier)
Definition id.c:855
long debug_id(const char *identifier)
Definition id.c:685
int sort_names(const void *a, const void *b)
Definition id.c:572
int node_update_block(void)
Definition id.c:1100
long record_id(const char *identifier)
Definition id.c:796
void strcpy_realloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
Definition id.c:129
void process_node_error(const char *tok1)
Definition mp.c:259
void process_variable_error(const char *tok1)
Definition mp.c:331
#define DELAY2_KIND
Definition napa.h:255
EXTERN long Num_Injects
Definition napa.h:820
EXTERN char * Generator_Lib_Name
Definition napa.h:913
#define RIGHT_VALUE
Definition napa.h:416
EXTERN int Synchro_Flag
Definition napa.h:879
#define MAXDEPTH
Definition napa.h:212
#define _R2D_
Definition napa.h:144
EXTERN RANDOMSEED_TYPE Seed_List
Definition napa.h:979
EXTERN long Num_Macros
Definition napa.h:823
EXTERN VAR_TYPE Var_List[2047L]
Definition napa.h:970
EXTERN char NAPA_Compile_Time[33]
Definition napa.h:990
EXTERN int Error_Flag
Definition napa.h:853
EXTERN char I_String_Format[2047L]
Definition napa.h:902
EXTERN RECORD_TYPE Record_List[127L]
Definition napa.h:965
EXTERN long Num_Consts
Definition napa.h:807
EXTERN long Num_Debugs
Definition napa.h:809
EXTERN int Post_Flag
Definition napa.h:876
#define NO_EXPAND
Definition napa.h:412
EXTERN int Stuck_Flag
Definition napa.h:878
EXTERN long Num_Functions
Definition napa.h:815
EXTERN long Num_Vars
Definition napa.h:836
EXTERN ARRAY_TYPE Array_List[63L]
Definition napa.h:950
#define LENGTH(s)
Definition napa.h:397
EXTERN int Array_Flag
Definition napa.h:843
EXTERN char V_Format[2047L]
Definition napa.h:899
EXTERN char E_Format[2047L]
Definition napa.h:895
EXTERN int Load_Flag
Definition napa.h:865
EXTERN int Directive_Flag
Definition napa.h:850
#define MACHINE
Definition napa.h:91
#define UNKNOWN_TYPE
Definition napa.h:332
#define UNDEFINED
Definition napa.h:331
EXTERN long Num_Records
Definition napa.h:828
EXTERN char S_Format[2047L]
Definition napa.h:898
#define RSHIFT2_KIND
Definition napa.h:307
#define ROM2_KIND
Definition napa.h:304
EXTERN char R_Format[2047L]
Definition napa.h:897
EXTERN long Num_Arrays
Definition napa.h:800
EXTERN POST_TYPE Post_List[63L]
Definition napa.h:964
#define STDERR
Definition napa.h:105
EXTERN double NAPA_Compile_Start
Definition napa.h:988
EXTERN int Title_Flag
Definition napa.h:881
EXTERN NODE_TYPE Node_List[4095L]
Definition napa.h:962
#define LATCH_KIND
Definition napa.h:281
#define DIFFERENTIATOR_KIND
Definition napa.h:257
EXTERN char S_String_Format[2047L]
Definition napa.h:904
#define RSHIFT1_KIND
Definition napa.h:306
EXTERN long Num_UserTools
Definition napa.h:835
EXTERN char NAPA_Job_ID[19]
Definition napa.h:993
EXTERN long Max_Depth
Definition napa.h:797
EXTERN int Dump_Flag
Definition napa.h:852
EXTERN USERTOOL_TYPE UserTool_List[511L]
Definition napa.h:969
#define OSC_KIND
Definition napa.h:294
#define CONST_KIND
Definition napa.h:246
#define DELAY3_KIND
Definition napa.h:256
#define INPUT_TYPE
Definition napa.h:358
#define CLOCK_KIND
Definition napa.h:244
#define EXPAND
Definition napa.h:413
#define ANALOG_DATA_TYPE
Definition napa.h:338
EXTERN int Export_Flag
Definition napa.h:855
EXTERN int Expand_Flag
Definition napa.h:854
EXTERN SAMPLING_TYPE Sampling_List
Definition napa.h:978
EXTERN int Tool_Index_Flag
Definition napa.h:882
#define ADC_KIND
Definition napa.h:226
EXTERN int Tool_Flag
Definition napa.h:883
EXTERN char R_String_Format[2047L]
Definition napa.h:903
#define DEFAULT_S_FORMAT
Definition napa.h:176
EXTERN char Export0_Head_String[16383L]
Definition napa.h:919
EXTERN long Num_Headers
Definition napa.h:818
EXTERN char X_String_Format[2047L]
Definition napa.h:905
EXTERN char * Record_Cell_File_Table[511L]
Definition napa.h:940
EXTERN DIRECTIVE_TYPE Directive_List[255L]
Definition napa.h:955
EXTERN DEBUG_TYPE Debug_List[63L]
Definition napa.h:952
EXTERN HEADER_TYPE Header_List[63L]
Definition napa.h:959
EXTERN long Num_Declares
Definition napa.h:810
#define UADC_KIND
Definition napa.h:321
#define COS2_KIND
Definition napa.h:249
EXTERN int Cmdline_Flag
Definition napa.h:846
#define LINLENGTH
Definition napa.h:216
EXTERN long Num_Nodes
Definition napa.h:824
#define MIN(x, y)
Definition napa.h:376
EXTERN char X_Format[2047L]
Definition napa.h:900
EXTERN int Ts_Ext_Flag
Definition napa.h:885
EXTERN int Debug_Flag
Definition napa.h:848
#define RAM_KIND
Definition napa.h:298
#define I_FORMAT_V
Definition napa.h:155
EXTERN INJECT_TYPE Inject_List[63L]
Definition napa.h:960
#define NAPA_COMPILER_VERSION
Definition napa.h:30
EXTERN long Num_Tools
Definition napa.h:833
#define SIN_KIND
Definition napa.h:310
EXTERN LOAD_TYPE Load_List
Definition napa.h:975
EXTERN long Num_Exports
Definition napa.h:813
EXTERN PING_TYPE Ping_List
Definition napa.h:977
EXTERN int Warning_Flag
Definition napa.h:890
EXTERN INTERLUDE_TYPE Interlude_List
Definition napa.h:974
EXTERN long Num_Directives
Definition napa.h:812
#define LITTLE_ENDIAN
Definition napa.h:98
#define STDOUT
Definition napa.h:104
EXTERN int Interlude_Flag1
Definition napa.h:868
EXTERN char Comment_String[63L][16383L]
Definition napa.h:925
#define D2I(x)
Definition napa.h:382
EXTERN int Comment_Flag
Definition napa.h:847
EXTERN long Num_Posts
Definition napa.h:827
EXTERN char * Header_Lib_Name
Definition napa.h:914
EXTERN char Root_String[2047L]
Definition napa.h:929
EXTERN char Export0_List_String[16383L]
Definition napa.h:921
EXTERN int Input_Flag
Definition napa.h:862
#define ROM_KIND
Definition napa.h:303
#define MAXFILES
Definition napa.h:204
#define DC_KIND
Definition napa.h:252
#define NO
Definition napa.h:406
EXTERN double NAPA_Compile_Stop
Definition napa.h:989
EXTERN long Num_FileCells
Definition napa.h:814
#define DEFAULT_R_FORMAT
Definition napa.h:175
EXTERN char Export1_List_String[16383L]
Definition napa.h:922
#define ISEQUAL(x, y)
Definition napa.h:379
EXTERN int UserTool_Flag
Definition napa.h:888
EXTERN int List_Flag
Definition napa.h:864
EXTERN long Num_IOs
Definition napa.h:822
EXTERN char I_Format[2047L]
Definition napa.h:896
EXTERN double Simulation_Rate
Definition napa.h:982
#define LEFT_VALUE
Definition napa.h:415
EXTERN long Num_Nulls
Definition napa.h:825
EXTERN long Num_Segments
Definition napa.h:831
EXTERN GATEWAY_TYPE Gateway_List
Definition napa.h:973
EXTERN long Num_Comments
Definition napa.h:805
EXTERN long Record_Cell_File_Usage[511L]
Definition napa.h:941
#define ISNOTEMPTY(s)
Definition napa.h:395
#define ITOOL_KIND
Definition napa.h:279
#define DTOOL_KIND
Definition napa.h:260
#define RAM2_KIND
Definition napa.h:299
#define MAX(x, y)
Definition napa.h:377
EXTERN char Cur_Fil_Name[31L][2047L]
Definition napa.h:931
#define R_FORMAT_V
Definition napa.h:165
EXTERN int Fs_Ext_Flag
Definition napa.h:857
EXTERN CMDLINE_TYPE Cmdline_List[63L]
Definition napa.h:951
EXTERN long Num_Cmdlines
Definition napa.h:804
EXTERN long Num_Creates
Definition napa.h:808
#define ZERO_KIND
Definition napa.h:326
#define ISNOTEQUAL(x, y)
Definition napa.h:380
EXTERN char Title_String[2 *2047L]
Definition napa.h:927
EXTERN int User_Flag
Definition napa.h:887
EXTERN TERMINATE_TYPE Terminate_List
Definition napa.h:980
EXTERN SEGMENT_TYPE Segment_List[127L]
Definition napa.h:966
EXTERN char * Main_File_Name
Definition napa.h:911
EXTERN int Pointer_Flag
Definition napa.h:875
#define STRLENGTH
Definition napa.h:217
EXTERN char * User_Name
Definition napa.h:909
EXTERN int Multdelay_Flag
Definition napa.h:867
EXTERN int Assert_Flag
Definition napa.h:844
EXTERN long Num_Cells
Definition napa.h:803
EXTERN long Num_Stucks
Definition napa.h:832
EXTERN FUNCTION_TYPE Function_List[255L]
Definition napa.h:957
#define NAPA_DIGITAL_TYPE
Definition napa.h:129
#define ISEMPTY(s)
Definition napa.h:394
EXTERN char NAPA_Identification_String[35]
Definition napa.h:992
#define STRING_DATA_TYPE
Definition napa.h:339
#define ISNOTINTEGER(x)
Definition napa.h:389
EXTERN int Seed_Flag
Definition napa.h:877
#define BSHIFT_KIND
Definition napa.h:231
EXTERN int Antithetic_Flag
Definition napa.h:842
#define DELAY_KIND
Definition napa.h:253
EXTERN int Ping_Flag
Definition napa.h:874
#define HEX_DATA_TYPE
Definition napa.h:340
EXTERN char * Net_Lib_Name
Definition napa.h:915
EXTERN char Cmdline_String[2047L]
Definition napa.h:924
EXTERN char Export1_Head_String[16383L]
Definition napa.h:920
EXTERN STUCK_TYPE Stuck_List[63L]
Definition napa.h:967
#define DEFAULT_I_FORMAT
Definition napa.h:173
#define SIN2_KIND
Definition napa.h:311
EXTERN int Gateway_Flag
Definition napa.h:859
EXTERN int Output_Flag
Definition napa.h:872
#define UNKNOWN_KIND
Definition napa.h:224
#define CHG_KIND
Definition napa.h:242
EXTERN DUMP_TYPE Dump_List
Definition napa.h:972
#define OUTPUT_TYPE
Definition napa.h:359
#define MAYBE
Definition napa.h:405
EXTERN char Short_Title_String[2 *2047L]
Definition napa.h:926
#define TRIG_KIND
Definition napa.h:320
#define COS_KIND
Definition napa.h:248
#define NOISE_KIND
Definition napa.h:290
EXTERN IO_TYPE IO_List[63L]
Definition napa.h:961
EXTERN int Loop_Flag
Definition napa.h:866
EXTERN long Num_Declare_Commons
Definition napa.h:806
#define DIGITAL_DATA_TYPE
Definition napa.h:337
EXTERN int Interlude_Flag2
Definition napa.h:869
#define _D2R_
Definition napa.h:143
EXTERN UPDATE_TYPE Update_List[2047L]
Definition napa.h:968
EXTERN int Periodic_Flag
Definition napa.h:873
#define DEFAULT_X_FORMAT
Definition napa.h:174
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 print_output_banner_1(long i, long j)
Definition pr.c:5055
void reset_arrays_function(void)
Definition pr.c:3074
void print_terminate_condition(void)
Definition pr.c:1243
void call_initialization_functions_B(void)
Definition pr.c:4850
void include_napa_header_files(void)
Definition pr.c:1883
void declare_an_analog_node(long i)
Definition pr.c:2303
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 print_output_banner_2(long i)
Definition pr.c:5079
void reset_records_function(void)
Definition pr.c:3430
void call_user_functions(const char *indent, const char *type)
Definition pr.c:5570
void reset_nodes_function(void)
Definition pr.c:3678
void open_ping_file(void)
Definition pr.c:4739
void reset_a_command_line_parameter(long j)
Definition pr.c:4197
void print_output_banner_0(void)
Definition pr.c:5042
void reset_a_dc_node(long i)
Definition pr.c:4140
void define_macros(void)
Definition pr.c:607
void declare_prototypes(void)
Definition pr.c:1698
void print_output_banner_4(char *tok)
Definition pr.c:5191
void print_check_output(void)
Definition pr.c:4950
void command_line_usage_function(void)
Definition pr.c:2476
void prepare_tool_synchronization(void)
Definition pr.c:2685
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 reset_simulator_variables(void)
Definition pr.c:2654
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 reset_an_analog_node(long i)
Definition pr.c:3939
void that_s_all(void)
Definition pr.c:5506
void print_error_banner_and_exit(void)
Definition pr.c:5482
void declare_global_values(void)
Definition pr.c:1261
void define_directives(void)
Definition pr.c:1764
void reset_user_variables(void)
Definition pr.c:2777
void napa_exit_functions(void)
Definition pr.c:4638
void declare_a_digital_node(long i)
Definition pr.c:2160
void close_IO_files(void)
Definition pr.c:5394
void reset_a_digital_node(long i)
Definition pr.c:3719
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 call_postprocess_functions(const char *indent, const char *type)
Definition pr.c:5355
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 print_output_banner_3(void)
Definition pr.c:5180
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
char * extract_line(char *str1, char *str2)
Definition tk.c:1487
void strip_extension(char *fnam)
Definition tk.c:1598
char * replace_char(char *s, char b, char a)
Definition tk.c:1788
char * get_token(char *str, char *tok, long keep_quotes)
Definition tk.c:1210
void clean_line(char *str)
Definition tk.c:1397
char * build_name(const char *sgn, char *tok, long lr_type)
Definition tk.c:69
void clean_parentheses(char *tok)
Definition tk.c:403
int f1flush(FILE *fp)
Definition tk.c:1843
int is_a_string(char *str)
Definition tk.c:1369
char * get_output_and_scaling(char *str, char *sgn, char *out, char *scl)
Definition tk.c:1061
char * multiple(char c, long n)
Definition tk.c:1801
void replace_dollar(char *tok)
Definition tk.c:1713
void expand_indirections(char *str)
Definition tk.c:717
void simplify_pathname(char *pnam)
Definition tk.c:1543
void drop_pathname(char *pnam)
Definition tk.c:1526
char * format_suffixed_number(double value, long places, const char *unit)
Definition tk.c:1725
char * get_sign_and_token(char *str, char *sgn, char *tok)
Definition tk.c:1188