NAPA Compiler V4.50
Author: Yves Leduc, yves.leduc.be@gmail.com
Loading...
Searching...
No Matches
C:/Simulate/Napados/Source/bl.c File Reference
#include "./napa.h"
#include "./proto.h"

Go to the source code of this file.

Macros

#define EXTERN   extern

Functions

void build_main_loop (void)
void build_main_loop_control1 (void)
void build_main_loop_control2 (void)
void build_main_loop_time (void)
void build_main_loop_option (long opt)
void build_main_loop_conditions (void)
void build_main_loop_block1 (void)
void build_main_loop_block2 (void)
void build_main_loop_block3 (void)
void build_main_loop_segment_begin (long nseg)
void build_main_loop_segment_end (void)
void build_node (long out)
void build_main_loop_inject (void)
void build_update (long i, const char *indent)
void build_input (long i)
void build_output (long o)
void build_main_loop_dump1 (void)
void build_main_loop_dump2 (void)
void build_main_loop_dump3 (void)
void build_main_loop_gateway (void)
void build_main_loop_synchro (void)
void print_node_width_postprocessing (long nod)
void print_var_width_postprocessing (long var)

Macro Definition Documentation

◆ EXTERN

#define EXTERN   extern

Definition at line 4 of file bl.c.

Function Documentation

◆ build_input()

void build_input ( long i)

Definition at line 1105 of file bl.c.

1105 {
1106 long c, n;
1107 long nn, nv;
1108 char *s = (char*) NULL;
1109 char tok[STRLENGTH] = {'\0'};
1110 char v1[LINLENGTH] = {'\0'};
1111 char v2[LINLENGTH] = {'\0'};
1112 char v3[LINLENGTH] = {'\0'};
1113 char v4[LINLENGTH] = {'\0'};
1114 long d;
1115 if (INPUT_TYPE != IO_List[i].type) {
1116 return;
1117 }
1118 c = 0L;
1119 s = IO_List[i].element; /* unprocessed I/O list of elements */
1120 s = get_token(s, tok, false); /* input stream */
1121 n = var_id(IO_List[i].fname);
1122 if (UNDEFINED != n) {
1123 (void) strcpy(v1, Var_List[n].name1); /* stream is a variable */
1124 (void) build_name("", v1, RIGHT_VALUE);
1125 } else {
1126 (void) snprintf(v1, (size_t) (LINLENGTH-1L),"\"%s\"", IO_List[i].fname); /* stream is a constant */
1127 }
1128 (void) strcpy(v2, "");
1129 (void) strcpy(v3, "");
1130 (void) fprintf(STDOUT, " do {\n");
1131 (void) fprintf(STDOUT, " napa_input_pointer = fgets(napa_input_buffer, %ld, napa_fp_%ld);\n", STRLENGTH, i);
1132 (void) fprintf(STDOUT, " } while ( '#' == napa_input_buffer[0] );\n");
1133 (void) fprintf(STDOUT, " if ( (char*) NULL == napa_input_pointer ) {\n");
1134 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Information: loop[%%lld] (input)\\n\", (I_TYPE) napa_abs_loop);\n");
1135 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" Simulation stopped at end of input file <\\\"%%s\\\">\\n\", %s);\n", v1);
1136 (void) fprintf(STDOUT, " break;\n");
1137 (void) fprintf(STDOUT, " }\n");
1138 while (ISNOTEMPTY(tok)) {
1139 nn = node_id(tok);
1140 nv = var_id(tok);
1141 if (UNDEFINED != nn) {
1142 print_error_location( "input", IO_List[i].mline, IO_List[i].mfile);
1143 (void) fprintf(STDERR, " only user's variables can be input at run-time\n");
1145 break;
1146 }
1147 if (UNDEFINED != nv) {
1148 (void) strcpy(v4, Var_List[nv].name1);
1149 (void) build_name("", v4, RIGHT_VALUE);
1150 (void) strcat(v2, " &");
1151 (void) strcat(v2, v4);
1152 (void) strcat(v2, ",");
1153 switch (Var_List[nv].type) {
1154 case DIGITAL_DATA_TYPE:
1155 if (ISNOTEMPTY(Var_List[nv].value)) {
1156 print_warning_location( "input", Var_List[nv].mline, Var_List[nv].mfile);
1157 (void) fprintf(STDERR, " initialization of ivar <%s> will be overwritten by run-time input\n", Var_List[nv].name1);
1158 }
1159 (void) strcat(v3, "%lli "); /* decimal, octal or hexadecimal compatible */
1160 break; /* octal must start by prefix 0, hexa by 0X */
1161 case ANALOG_DATA_TYPE:
1162 if (ISNOTEMPTY(Var_List[nv].value)) {
1163 print_warning_location( "input", Var_List[nv].mline, Var_List[nv].mfile);
1164 (void) fprintf(STDERR, " initialization of dvar <%s> will be overwritten by run-time input\n", Var_List[nv].name1);
1165 }
1166 (void) strcat(v3, "%lf ");
1167 break;
1168 case STRING_DATA_TYPE:
1169 print_error_location( "input", IO_List[i].mline, IO_List[i].mfile);
1170 (void) fprintf(STDERR, " <%s> cannot be a string variable\n", tok);
1171 break;
1172 default:
1173 /* do nothing */;
1174 }
1175 c++;
1176 } else {
1177 print_error_location( "input", IO_List[i].mline, IO_List[i].mfile);
1178 (void) fprintf(STDERR, " <%s> is not a user's variable\n", tok);
1180 }
1181 s = get_token(s, tok, false);
1182 }
1183 v2[LENGTH(v2) - 1L] = '\0'; /* remove a comma */
1184 v3[LENGTH(v3) - 1L] = '\0'; /* remove a space */
1185 (void) fprintf(STDOUT, " napa_input_test = sscanf(napa_input_buffer, \"%s\",%s);\n", v3, v2);
1186 (void) fprintf(STDOUT, " if ( %ld != napa_input_test ) {\n", c);
1187 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (input)\\n\");\n");
1188 if (!Cmdline_Flag) {
1189 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of main netlist\\n\");\n", IO_List[i].mline[0]);
1190 for (d = 1L; d < MAXDEPTH; d++) {
1191 if (0UL == IO_List[i].mline[d]) {
1192 break;
1193 }
1194 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" -> at line %3lu of \\\"%s\\\"\\n\");\n",
1195 IO_List[i].mline[d], Record_Cell_File_Table[IO_List[i].mfile[d]]);
1196 }
1197 }
1198 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" unsuccessful input from <\\\"%%s\\\">\\n\", %s);\n", v1);
1199 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
1200 (void) fprintf(STDOUT, " }\n");
1201 s = IO_List[i].element; /* unprocessed I/O list of elements */
1202 s = get_token(s, tok, false); /* input stream */
1203 while (ISNOTEMPTY(tok)) {
1204 nv = var_id(tok);
1205 switch (Var_List[nv].type) {
1206 case DIGITAL_DATA_TYPE:
1208 break;
1209 case ANALOG_DATA_TYPE:
1210 case STRING_DATA_TYPE:
1211 default:
1212 /* do nothing */;
1213 }
1214 s = get_token(s, tok, false);
1215 }
1216 return;
1217}
void print_var_width_postprocessing(long var)
Definition bl.c:1820
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
long node_id(const char *identifier)
Definition id.c:718
long var_id(const char *identifier)
Definition id.c:855
void process_variable_error(const char *tok1)
Definition mp.c:331
#define RIGHT_VALUE
Definition napa.h:416
#define MAXDEPTH
Definition napa.h:212
EXTERN VAR_TYPE Var_List[2047L]
Definition napa.h:970
#define LENGTH(s)
Definition napa.h:397
#define UNDEFINED
Definition napa.h:331
#define STDERR
Definition napa.h:105
#define INPUT_TYPE
Definition napa.h:358
#define ANALOG_DATA_TYPE
Definition napa.h:338
EXTERN char * Record_Cell_File_Table[511L]
Definition napa.h:940
EXTERN int Cmdline_Flag
Definition napa.h:846
#define LINLENGTH
Definition napa.h:216
#define STDOUT
Definition napa.h:104
#define ISNOTEMPTY(s)
Definition napa.h:395
#define STRLENGTH
Definition napa.h:217
#define STRING_DATA_TYPE
Definition napa.h:339
EXTERN IO_TYPE IO_List[63L]
Definition napa.h:961
#define DIGITAL_DATA_TYPE
Definition napa.h:337
char * get_token(char *str, char *tok, long keep_quotes)
Definition tk.c:1210
char * build_name(const char *sgn, char *tok, long lr_type)
Definition tk.c:69

References ANALOG_DATA_TYPE, build_name(), Cmdline_Flag, DIGITAL_DATA_TYPE, get_token(), INPUT_TYPE, IO_List, ISNOTEMPTY, LENGTH, LINLENGTH, MAXDEPTH, node_id(), print_error_location(), print_var_width_postprocessing(), print_warning_location(), process_variable_error(), Record_Cell_File_Table, RIGHT_VALUE, STDERR, STDOUT, STRING_DATA_TYPE, STRLENGTH, UNDEFINED, var_id(), and Var_List.

Referenced by build_main_loop_block1().

◆ build_main_loop()

void build_main_loop ( void )

Definition at line 45 of file bl.c.

45 {
46
47 if (!Loop_Flag) { /* no main loop will be built */
48 (void) fprintf(STDOUT, "\n /* (main loop empty) */\n");
49 if (!Post_Flag) { /* no postprocessing */
50 print_warning_location("terminate", Terminate_List.mline, Terminate_List.mfile);
51 (void) fprintf(STDERR, " No simulation?\n");
52 }
53 return;
54 }
55
57
58 (void) fprintf(STDOUT, "\n /* (start main loop) */\n");
59
60 /* write the do-while loop header */
61
63
64 /* write the current time computation and segment conditions */
65
69
70 /* write the 3 blocks: variable update, node update, output */
71
72 build_main_loop_block1(); /* write the block: variable update */
73 build_main_loop_block2(); /* write the block: node update */
74 build_main_loop_block3(); /* write the block: output */
75
77
78 /* write the tool synchronization mechanism if necessary */
79
82
83 (void) fprintf(STDOUT, " /* (prepare next loop) */\n");
84 (void) fprintf(STDOUT, " napa_abs_loop++;\n");
85 if ((Synchro_Flag) && (1L <= Num_Tools)) {
86 (void) fprintf(STDOUT, " napa_rel_loop++;\n");
87 }
88 /* end of simulator main loop */
89
91
92 (void) fprintf(STDOUT, " /* (main loop completed) */\n");
93 (void) fprintf(STDOUT, " napa_waypoint = 5;\n");
94
97
98 return;
99}
void build_main_loop_block1(void)
Definition bl.c:360
void build_main_loop_control2(void)
Definition bl.c:114
void build_main_loop_time(void)
Definition bl.c:123
void build_main_loop_dump2(void)
Definition bl.c:1556
void build_main_loop_block3(void)
Definition bl.c:465
void build_main_loop_option(long opt)
Definition bl.c:219
void build_main_loop_dump3(void)
Definition bl.c:1576
void build_main_loop_synchro(void)
Definition bl.c:1625
void build_main_loop_conditions(void)
Definition bl.c:267
void build_main_loop_block2(void)
Definition bl.c:427
void build_main_loop_control1(void)
Definition bl.c:104
EXTERN int Synchro_Flag
Definition napa.h:879
EXTERN int Post_Flag
Definition napa.h:876
EXTERN long Num_Tools
Definition napa.h:833
EXTERN TERMINATE_TYPE Terminate_List
Definition napa.h:980
EXTERN int Loop_Flag
Definition napa.h:866

References build_main_loop_block1(), build_main_loop_block2(), build_main_loop_block3(), build_main_loop_conditions(), build_main_loop_control1(), build_main_loop_control2(), build_main_loop_dump2(), build_main_loop_dump3(), build_main_loop_option(), build_main_loop_synchro(), build_main_loop_time(), Loop_Flag, Num_Tools, Post_Flag, print_warning_location(), STDERR, STDOUT, Synchro_Flag, and Terminate_List.

Referenced by main().

◆ build_main_loop_block1()

void build_main_loop_block1 ( void )

Definition at line 360 of file bl.c.

360 {
361 long current_nseg;
362 long i;
363 int open_segment_flag;
364 char indent[3] = {'\0'};
365 if (!variable_update_block()) {
366 (void) fprintf(STDOUT, "\n /* block 1 (update variables) is empty */\n"); /* nothing to process in this block */
367 return;
368 }
369 (void) fprintf(STDOUT, "\n /* block 1 (update variables) */\n");
370 open_segment_flag = false;
371 if (Input_Flag) { /* 'input' id first to be processed */
372 current_nseg = -999;
373 i = 0L;
374 while (i < Num_IOs) {
375 if (IO_List[i].segment != current_nseg) {
376 current_nseg = IO_List[i].segment;
377 open_segment_flag = true;
378 build_main_loop_segment_begin(current_nseg);
379 }
380 build_input(i);
381 i++;
382 if ((IO_List[i].segment != current_nseg) && (open_segment_flag)) {
384 open_segment_flag = false;
385 }
386 }
387 if (open_segment_flag) {
389 open_segment_flag = false;
390 }
391 }
392 current_nseg = -999L;
393 i = 0L;
394 while (i < Num_Updates) { /* process now instructions 'update' if any */
395 if (Update_List[i].segment != current_nseg) { /* new segment: open */
396 current_nseg = Update_List[i].segment;
397 open_segment_flag = true;
398 build_main_loop_segment_begin(current_nseg);
399 }
400 if ((ISEMPTY(Update_List[i].condition)) && (!Update_List[i].constant)) {
401 (void) strcpy(indent, "");
402 build_update(i, indent);
403 }
404 if ((ISNOTEMPTY(Update_List[i].condition)) && (!Update_List[i].constant)) {
405 (void) strcpy(indent, " ");
406 (void) fprintf(STDOUT, " ");
407 build_condition(Update_List[i].condition, Update_List[i].mline, Update_List[i].mfile);
408 build_update(i, indent);
409 (void) fprintf(STDOUT, " }\n");
410 }
411 i++;
412 if ((Update_List[i].segment != current_nseg) && (open_segment_flag)) { /* next update belongs to next segment */
414 open_segment_flag = false;
415 }
416 }
417 if (open_segment_flag) { /* close last segment */
419 }
420 build_main_loop_inject(); /* 'inject' must be OUTSIDE segment conditions */
421 return;
422}
void build_update(long i, const char *indent)
Definition bl.c:822
void build_main_loop_segment_begin(long nseg)
Definition bl.c:490
void build_main_loop_inject(void)
Definition bl.c:781
void build_input(long i)
Definition bl.c:1105
void build_main_loop_segment_end(void)
Definition bl.c:523
void build_condition(char *cond, const unsigned long *mlin, const unsigned long *mfil)
Definition fc.c:958
int variable_update_block(void)
Definition id.c:1083
EXTERN long Num_Updates
Definition napa.h:834
EXTERN int Input_Flag
Definition napa.h:862
EXTERN long Num_IOs
Definition napa.h:822
#define ISEMPTY(s)
Definition napa.h:394
EXTERN UPDATE_TYPE Update_List[2047L]
Definition napa.h:968

References build_condition(), build_input(), build_main_loop_inject(), build_main_loop_segment_begin(), build_main_loop_segment_end(), build_update(), Input_Flag, IO_List, ISEMPTY, ISNOTEMPTY, Num_IOs, Num_Updates, STDOUT, Update_List, and variable_update_block().

Referenced by build_main_loop().

◆ build_main_loop_block2()

void build_main_loop_block2 ( void )

Definition at line 427 of file bl.c.

427 {
428 long nseg;
429 long i;
430 long s;
431 int open_segment_flag;
432 if (node_update_block()) {
433 (void) fprintf(STDOUT, "\n /* block 2 (update nodes) */\n");
434 } else {
435 (void) fprintf(STDOUT, "\n /* block 2 (update nodes) is empty */\n");
436 return;
437 }
438 open_segment_flag = false;
439 nseg = -999L;
440 i = 0L;
441 while (i < Num_Nodes) {
442 s = Node_List[i].segment;
443 if (s != nseg) {
444 nseg = s;
445 open_segment_flag = true;
447 }
448 build_node(i);
449 i++;
450 s = Node_List[i].segment;
451 if ((s != nseg) && (open_segment_flag)) {
453 open_segment_flag = false;
454 }
455 }
456 if (open_segment_flag) {
458 }
459 return;
460}
void build_node(long out)
Definition bl.c:529
int node_update_block(void)
Definition id.c:1100
EXTERN NODE_TYPE Node_List[4095L]
Definition napa.h:962
EXTERN long Num_Nodes
Definition napa.h:824

References build_main_loop_segment_begin(), build_main_loop_segment_end(), build_node(), Node_List, node_update_block(), Num_Nodes, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_block3()

void build_main_loop_block3 ( void )

Definition at line 465 of file bl.c.

465 {
466 long o;
467 if (time_output_block()) {
468 (void) fprintf(STDOUT, "\n /* block 3 (time domain output) */\n");
469 } else {
470 (void) fprintf(STDOUT, "\n /* block 3 (output) is empty */\n");
471 return;
472 }
473 if (Output_Flag) {
474 o = 0L;
475 while (o < Num_IOs) {
476 build_output(o);
477 o++;
478 }
479 }
480 if (Dump_Flag) {
482 }
483 if ((Gateway_Flag) && (Assert_Flag)) {
485 }
486 return;
487}
void build_main_loop_dump1(void)
Definition bl.c:1538
void build_output(long o)
Definition bl.c:1220
void build_main_loop_gateway(void)
Definition bl.c:1592
int time_output_block(void)
Definition id.c:1114
EXTERN int Dump_Flag
Definition napa.h:852
EXTERN int Assert_Flag
Definition napa.h:844
EXTERN int Gateway_Flag
Definition napa.h:859
EXTERN int Output_Flag
Definition napa.h:872

References Assert_Flag, build_main_loop_dump1(), build_main_loop_gateway(), build_output(), Dump_Flag, Gateway_Flag, Num_IOs, Output_Flag, STDOUT, and time_output_block().

Referenced by build_main_loop().

◆ build_main_loop_conditions()

void build_main_loop_conditions ( void )

Definition at line 267 of file bl.c.

267 {
268 int cnt;
269 int first;
270 long n, nseg;
271 char *str = (char*) NULL;
272 char tok[STRLENGTH] = {'\0'};
273 char buf[STRLENGTH] = {'\0'};
274 if (1L >= Num_Segments) {
275 return;
276 }
277 first = true;
278 for (nseg = 0L; nseg < Num_Segments; nseg++) {
279 if (!((Segment_List[nseg].used1) || (Segment_List[nseg].used2) || (Segment_List[nseg].used3))) {
280 (void) strcpy(Segment_Condition[nseg], "false"); /* not used */
281 continue;
282 }
283 if (DROP_SEGMENT_TYPE == Segment_List[nseg].type) { /* 'drop' segment */
284 if (ISNOTEQUAL(1.0, Segment_List[nseg].rate)) {
285 if (0L == nseg) {
286 (void) snprintf(buf, (size_t) (STRLENGTH-1L), "(%2LdLL == ((I_TYPE) napa_abs_loop) %%%3LdLL) && (",
287 (long long) Segment_List[nseg].rate, (long long) Segment_List[nseg].offset);
288 } else {
289 (void) snprintf(buf, (size_t) (STRLENGTH-1L), " napa_segment_run_%-2ld && (", nseg-1L);
290 }
291 (void) strcpy(Segment_Condition[nseg], buf);
292 } else {
293 (void) strcpy(Segment_Condition[nseg], "");
294 }
295 str = Segment_List[nseg].value;
296 for (;;) {
297 str = get_token(str, tok, false);
298 if (ISEMPTY(tok)) {
299 if (ISNOTEQUAL(1.0, Segment_List[nseg].rate)) {
300 (void) strcat(Segment_Condition[nseg], ") ");
301 }
302 break;
303 }
304 (void) build_name("", tok, RIGHT_VALUE);
305 (void) snprintf(buf, (size_t) (STRLENGTH-1L), "%s", tok);
306 (void) strcat(Segment_Condition[nseg], buf);
307 }
308 } else { /* for other types of segment */
309 if (ISEQUAL(1.0, Segment_List[nseg].rate)) {
310 (void) strcpy(Segment_Condition[nseg], "true");
311 } else {
312 (void) snprintf(buf, (size_t) (STRLENGTH-1L), "%2LdLL == ((I_TYPE) napa_abs_loop) %%%3LdLL ",
313 (long long) Segment_List[nseg].offset, (long long) Segment_List[nseg].rate);
314 (void) strcpy(Segment_Condition[nseg], buf);
315 }
316 }
317 }
318 for (nseg = 1L; nseg < Num_Segments; nseg++) { /* do not recompute if possible */
319 for (n = 0L; n < nseg; n++) {
320 if ((0 != strcmp(Segment_Condition[nseg], "true" )) && (0 != strcmp(Segment_Condition[nseg], "false"))
321 && (0 == strcmp(Segment_Condition[nseg], Segment_Condition[n]))) {
322 (void) snprintf(Segment_Condition[nseg], (size_t) (STRLENGTH-1L), " napa_segment_run_%-2ld", n);
323 }
324 }
325 }
326 cnt = 0;
327 for (nseg = 0L; nseg < Num_Segments; nseg++) { /* determines the number of conditions */
328 if ((0 == strcmp(Segment_Condition[nseg], "false")) || (0 == strcmp(Segment_Condition[nseg], "true"))) {
329 continue; /* already defined in initialization */
330 }
331 if ((!Segment_List[nseg].used1) && (!Segment_List[nseg].used2)) {
332 continue;
333 }
334 cnt++;
335 }
336 for (nseg = 0L; nseg < Num_Segments; nseg++) {
337 if ((0 == strcmp(Segment_Condition[nseg], "false")) || (0 == strcmp(Segment_Condition[nseg], "true"))) {
338 continue; /* already defined in initialization */
339 }
340 if ((!Segment_List[nseg].used1) && (!Segment_List[nseg].used2)) {
341 continue;
342 }
343 if (first) {
344 first = false;
345 if (1 == cnt) {
346 (void) fprintf(STDOUT, "\n /* block 0 (segment condition) */\n");
347 } else if (1 < cnt) {
348 (void) fprintf(STDOUT, "\n /* block 0 (segments conditions) */\n");
349 }
350 }
351 (void) fprintf(STDOUT, " napa_segment_run_%-2ld = (%s);\n", nseg, Segment_Condition[nseg]);
352 }
353 return;
354}
#define DROP_SEGMENT_TYPE
Definition napa.h:353
#define ISEQUAL(x, y)
Definition napa.h:379
EXTERN long Num_Segments
Definition napa.h:831
EXTERN char Segment_Condition[127L][2047L]
Definition napa.h:943
#define ISNOTEQUAL(x, y)
Definition napa.h:380
EXTERN SEGMENT_TYPE Segment_List[127L]
Definition napa.h:966

References build_name(), DROP_SEGMENT_TYPE, get_token(), ISEMPTY, ISEQUAL, ISNOTEQUAL, Num_Segments, RIGHT_VALUE, Segment_Condition, Segment_List, STDOUT, and STRLENGTH.

Referenced by build_main_loop().

◆ build_main_loop_control1()

void build_main_loop_control1 ( void )

Definition at line 104 of file bl.c.

104 {
105 double frq;
106 (void) fprintf(STDOUT, " napa_waypoint = 4;\n\n");
107 (void) fprintf(STDOUT, " do {");
108 frq = Sampling_List.frequency * Segment_List[0].rate;
109 (void) fprintf(STDOUT, " %*s /* @ f %-16s*/\n\n", 89, " ", format_suffixed_number(frq, 4L, "Hz"));
110 return;
111}
EXTERN SAMPLING_TYPE Sampling_List
Definition napa.h:978
char * format_suffixed_number(double value, long places, const char *unit)
Definition tk.c:1725

References format_suffixed_number(), Sampling_List, Segment_List, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_control2()

void build_main_loop_control2 ( void )

Definition at line 114 of file bl.c.

114 {
115 if (1L < Num_Segments) {
116 (void) fprintf(STDOUT, "\n napa_segment = 0L;\n"); /* terminate condition tested at the fastest rate */
117 }
118 (void) fprintf(STDOUT, "\n } while ( !TERMINATE );\n\n");
119 return;
120}

References Num_Segments, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_dump1()

void build_main_loop_dump1 ( void )

Definition at line 1538 of file bl.c.

1538 {
1539 if (0 == strcmp(Dump_List.condition, "false")) { /* no dump except if fired by "assert" */
1540 return;
1541 }
1542 if (0 == strcmp(Dump_List.condition, "true")) {
1543 (void) fprintf(STDOUT, "\n /* (dump triggering) */\n");
1544 (void) fprintf(STDOUT, " napa_dump_flag = true;\n");
1545 } else {
1546 (void) fprintf(STDOUT, "\n /* (dump triggering) */\n");
1547 (void) fprintf(STDOUT, " ");
1548 build_condition(Dump_List.condition, Dump_List.mline, Dump_List.mfile);
1549 (void) fprintf(STDOUT, " napa_dump_flag = true;\n" );
1550 (void) fprintf(STDOUT, " }\n");
1551 }
1552 return;
1553}
EXTERN DUMP_TYPE Dump_List
Definition napa.h:972

References build_condition(), Dump_List, and STDOUT.

Referenced by build_main_loop_block3().

◆ build_main_loop_dump2()

void build_main_loop_dump2 ( void )

Definition at line 1556 of file bl.c.

1556 {
1557 if (!Dump_Flag) {
1558 return;
1559 }
1560 if (0 == strcmp(Dump_List.condition, "false")) {
1561 return;
1562 }
1563 (void) fprintf(STDOUT, "\n /* (dump) */\n" );
1564 if (Assert_Flag) {
1565 (void) fprintf(STDOUT, " if ( (napa_dump_flag) || (napa_assert_flag) ) {\n");
1566 } else {
1567 (void) fprintf(STDOUT, " if ( napa_dump_flag ) {\n");
1568 }
1569 (void) fprintf(STDOUT, " napa_dump_states();\n");
1570 (void) fprintf(STDOUT, " napa_dump_flag = false;\n");
1571 (void) fprintf(STDOUT, " }\n");
1572 return;
1573}

References Assert_Flag, Dump_Flag, Dump_List, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_dump3()

void build_main_loop_dump3 ( void )

Definition at line 1576 of file bl.c.

1576 {
1577 if (!Dump_Flag) {
1578 return;
1579 }
1580 if (0 == strcmp(Dump_List.condition, "false")) {
1581 return;
1582 }
1583 if (Assert_Flag) {
1584 (void) fprintf(STDOUT, " if ( napa_assert_flag ) {\n");
1585 (void) fprintf(STDOUT, " napa_dump_states();\n" );
1586 (void) fprintf(STDOUT, " }\n");
1587 }
1588 return;
1589}

References Assert_Flag, Dump_Flag, Dump_List, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_gateway()

void build_main_loop_gateway ( void )

Definition at line 1592 of file bl.c.

1592 {
1593 (void) fprintf(STDOUT, "\n /* (gateway) */\n");
1594 (void) fprintf(STDOUT, " #if !defined(NO_ASSERT)\n" );
1595 (void) fprintf(STDOUT, " if ( napa_assert_flag ) {\n");
1596 if (25L > Gateway_List.counter) {
1597 (void) fprintf(STDOUT, " if ( 0LL >= napa_gateway ) {\n" );
1598 } else {
1599 (void) fprintf(STDOUT, " if ( 0LL >= napa_gateway1 ) {\n");
1600 }
1601 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" ... gateway countdown %4lld\\n\\n\");\n", (long long) 0);
1602 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" End of countdown, exiting simulation now\\n\\n\");\n");
1603 (void) fprintf(STDOUT, " break;\n");
1604 if (0L == Gateway_List.counter) {
1605 (void) fprintf(STDOUT, " }\n" );
1606 } else {
1607 (void) fprintf(STDOUT, " } else {\n");
1608 if (25L > Gateway_List.counter) {
1609 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" ... gateway countdown %%4lld\\n\", napa_gateway);\n" );
1610 (void) fprintf(STDOUT, " napa_gateway--;\n");
1611 } else {
1612 (void) fprintf(STDOUT, " if ( 0LL == (napa_gateway1 %% napa_gateway2) ) {\n");
1613 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" ... gateway countdown %%4lld\\n\", napa_gateway1);\n");
1614 (void) fprintf(STDOUT, " }\n");
1615 (void) fprintf(STDOUT, " napa_gateway1--;\n");
1616 }
1617 (void) fprintf(STDOUT, " }\n" );
1618 }
1619 (void) fprintf(STDOUT, " }\n" );
1620 (void) fprintf(STDOUT, " #endif\n" );
1621 return;
1622}
EXTERN GATEWAY_TYPE Gateway_List
Definition napa.h:973

References Gateway_List, and STDOUT.

Referenced by build_main_loop_block3().

◆ build_main_loop_inject()

void build_main_loop_inject ( void )

Definition at line 781 of file bl.c.

781 {
782 long i;
783 long n;
784 char tok[STRLENGTH] = {'\0'};
785 char v1[LINLENGTH] = {'\0'};
786 char *str = (char*) NULL;
787 if (!Inject_Flag) {
788 return;
789 }
790 if (1L < Num_Segments) {
791 (void) fprintf(STDOUT, "\n napa_segment = 0L;\n");
792 } else {
793 (void) fprintf(STDOUT, "\n");
794 }
795 for (i = 0L; i < Num_Injects; i++) {
796 n = node_id(Inject_List[i].name);
797 str = Inject_List[i].value;
799 (void) fprintf(STDOUT, " inject_%s = (R_TYPE) (", Node_List[n].name1);
800 for (;;) {
801 str = get_token(str, tok, false);
802 if (ISEMPTY(tok)) {
803 (void) fprintf(STDOUT, ");\n");
804 break;
805 }
806 if (UNDEFINED != (n = node_id(tok))) { /* otherwise a parasitic delay is introduced */
807 print_error_location("inject", Inject_List[i].mline, Inject_List[i].mfile);
808 (void) fprintf(STDERR, " a node is not allowed to inject a signal\n");
809 } else if (UNDEFINED != (n = var_id(tok))) {
810 (void) strcpy(v1, Var_List[n].name1);
811 (void) build_name("", v1, RIGHT_VALUE);
812 (void) fprintf(STDOUT, "%s", v1);
813 } else {
814 (void) fprintf(STDOUT, "%s", tok);
815 }
816 }
817 }
818 return;
819}
EXTERN long Num_Injects
Definition napa.h:820
EXTERN INJECT_TYPE Inject_List[63L]
Definition napa.h:960
EXTERN int Inject_Flag
Definition napa.h:861
void clean_parentheses(char *tok)
Definition tk.c:403

References build_name(), clean_parentheses(), get_token(), Inject_Flag, Inject_List, ISEMPTY, LINLENGTH, node_id(), Node_List, Num_Injects, Num_Segments, print_error_location(), RIGHT_VALUE, STDERR, STDOUT, STRLENGTH, UNDEFINED, var_id(), and Var_List.

Referenced by build_main_loop_block1().

◆ build_main_loop_option()

void build_main_loop_option ( long opt)

Definition at line 219 of file bl.c.

219 {
220
221 switch (opt) {
222
223#if YES == COMPILE_LOOP_OPTION /* defined in "napa.h", default: NO */
224
225 case 0: /* -before- the loop */
226 (void) fprintf(STDOUT, "\n#if defined(NAPA_LOOP_OPTION)\n");
227 if ((Periodic_Flag) && (1L < Num_Segments)) {
228 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
229 }
230 (void) fprintf(STDOUT, " napa_loop_option(0);\n");
231 (void) fprintf(STDOUT, "#endif\n");
232 break;
233 case 1: /* begin of the loop */
234 (void) fprintf(STDOUT, "\n#if defined(NAPA_LOOP_OPTION)\n");
235 if ((Periodic_Flag) && (1L < Num_Segments)) {
236 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
237 }
238 (void) fprintf(STDOUT, " napa_loop_option(1);\n");
239 (void) fprintf(STDOUT, "#endif\n");
240 break;
241 case 2: /* end of the loop */
242 (void) fprintf(STDOUT, "#if defined(NAPA_LOOP_OPTION)\n");
243 if ((Periodic_Flag) && (1L < Num_Segments)) {
244 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
245 }
246 (void) fprintf(STDOUT, " napa_loop_option(2);\n");
247 (void) fprintf(STDOUT, "#endif\n\n");
248 break;
249 case 3: /* -after- the loop */
250 (void) fprintf(STDOUT, "#if defined(NAPA_LOOP_OPTION)\n");
251 if ((Periodic_Flag) && (1L < Num_Segments)) {
252 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
253 }
254 (void) fprintf(STDOUT, " napa_loop_option(3);\n");
255 (void) fprintf(STDOUT, "#endif\n\n");
256 break;
257
258#endif
259
260 default:
261 break;
262 }
263 return;
264}
EXTERN int Periodic_Flag
Definition napa.h:873

References Num_Segments, Periodic_Flag, and STDOUT.

Referenced by build_main_loop().

◆ build_main_loop_segment_begin()

void build_main_loop_segment_begin ( long nseg)

Definition at line 490 of file bl.c.

490 {
491 int len;
492 double frq;
493 if (1L < Num_Segments) {
494 if ((ISEQUAL(1.0, Segment_List[nseg].rate)) && (DROP_SEGMENT_TYPE != Segment_List[nseg].type)) {
495 len = fprintf(STDOUT, " if ( true ) {"); /* no condition to execute block */
496 } else {
497 len = fprintf(STDOUT, " if ( napa_segment_run_%-2ld) {", nseg); /* conditional execution */
498 }
499 if (DROP_SEGMENT_TYPE != Segment_List[nseg].type) {
500 frq = Sampling_List.frequency * Segment_List[0].rate / Segment_List[nseg].rate;
501 if (ISNOTEQUAL(1.0, Segment_List[nseg].rate)) {
502 (void) fprintf(STDOUT, " %*s /* @ f/%-5g %-16s*/\n", 95-len, " ", Segment_List[nseg].rate, format_suffixed_number(frq, 4L,"Hz"));
503 } else {
504 (void) fprintf(STDOUT, " %*s /* @ f %-16s*/\n", 95-len, " ", format_suffixed_number(frq, 4L,"Hz"));
505 }
506 } else {
507 (void) fprintf(STDOUT, "\n");
508 }
509 (void) fprintf(STDOUT, " napa_segment = %ldL;\n", nseg);
510 } else {
511 len = fprintf(STDOUT, " if ( true ) {"); /* no condition to execute block */
512 frq = Sampling_List.frequency * Segment_List[0].rate / Segment_List[nseg].rate;
513 if (ISNOTEQUAL(1.0, Segment_List[nseg].rate)) {
514 (void) fprintf(STDOUT, " %*s /* @ f/%-5g %-16s*/\n", 95-len, " ", Segment_List[nseg].rate, format_suffixed_number(frq, 4L,"Hz"));
515 } else {
516 (void) fprintf(STDOUT, " %*s /* @ f %-16s*/\n", 95-len, " ", format_suffixed_number(frq, 4L,"Hz"));
517 }
518 }
519 return;
520}

References DROP_SEGMENT_TYPE, format_suffixed_number(), ISEQUAL, ISNOTEQUAL, Num_Segments, Sampling_List, Segment_List, and STDOUT.

Referenced by build_main_loop_block1(), and build_main_loop_block2().

◆ build_main_loop_segment_end()

void build_main_loop_segment_end ( void )

Definition at line 523 of file bl.c.

523 {
524 (void) fprintf(STDOUT, " }\n");
525 return;
526}

References STDOUT.

Referenced by build_main_loop_block1(), and build_main_loop_block2().

◆ build_main_loop_synchro()

void build_main_loop_synchro ( void )

Definition at line 1625 of file bl.c.

1625 { /* tool synchronization mechanism */
1626 long n, ncut;
1627 long na = 0L;
1628 long nb = 0L;
1629 long nc = 0L;
1630 na = Interlude_List.number1 * ((long) Simulation_Rate); /* correction to correspond to FS rate */
1631 nb = Interlude_List.number2 * ((long) Simulation_Rate) - na;
1632 nc = Interlude_List.number3 * ((long) Simulation_Rate);
1633 if (Synchro_Flag) {
1634 switch (Num_Tools) {
1635 case 0L:
1636 break;
1637 case 1L:
1638 (void) fprintf(STDOUT, "\n /* (update the mailbox of the tool) */\n");
1639 if ((!Interlude_Flag1) || ((0L == na) && (0L == nb))) { /* no interlude */
1640 (void) fprintf(STDOUT, " if ( napa_msg->o >= napa_packet ) {\n");
1641 (void) fprintf(STDOUT, " napa_rel_loop = -1.0L;\n");
1642 (void) fprintf(STDOUT, " napa_tool_index = napa_packet;\n"); /* before napa_packet++ */
1643 (void) fprintf(STDOUT, " napa_msg->i = START;\n");
1644 (void) fprintf(STDOUT, " napa_packet++;\n");
1645 (void) fprintf(STDOUT, " }\n");
1646 } else { /* interlude */
1647 (void) fprintf(STDOUT, " if ( napa_msg->o >= napa_packet ) {\n");
1648 (void) fprintf(STDOUT, " if ( 0LL >= napa_tool_start ) {\n");
1649 (void) fprintf(STDOUT, " if ( EOF == fflush((FILE*) NULL) ) {\n");
1650 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (I/O manager for tools)\\n\");\n");
1651 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" flushing data from buffer I/O was not successful\\n\" );\n");
1652 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
1653 (void) fprintf(STDOUT, " }\n");
1654 if (!Interlude_Flag2) {
1655 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
1656 } else {
1657 if ((0L == na) && (0L == nb)) {
1658 (void) fprintf(STDOUT, " napa_tool_start = 0LL);\n" );
1659 }
1660 if ((0L != na) && (0L == nb)) {
1661 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
1662 }
1663 if ((0L == na) && (0L != nb)) {
1664 (void) fprintf(STDOUT, " napa_tool_start = napa_rand_integer(%ldLL);\n", nb);
1665 if (0L != nc) {
1666 (void) fprintf(STDOUT, " napa_tool_start = (napa_tool_start / %ldLL) * %ldLL;\n", nc, nc);
1667 }
1668 }
1669 if ((0L != na) && (0L != nb)) {
1670 (void) fprintf(STDOUT, " napa_tool_start = %ldLL + napa_rand_integer(%ldLL);\n", na, nb);
1671 if (0L != nc) {
1672 (void) fprintf(STDOUT, " napa_tool_start = (napa_tool_start / %ldLL) * %ldLL;\n", nc, nc);
1673 }
1674 }
1675 }
1676 (void) fprintf(STDOUT, " napa_rel_loop = -1.0L;\n");
1677 (void) fprintf(STDOUT, " napa_tool_index = napa_packet;\n"); /* before napa_packet++ */
1678 (void) fprintf(STDOUT, " napa_msg->i = START;\n");
1679 (void) fprintf(STDOUT, " napa_packet++;\n");
1680 (void) fprintf(STDOUT, " } else {\n");
1681 (void) fprintf(STDOUT, " napa_tool_start--;\n");
1682 (void) fprintf(STDOUT, " }\n");
1683 (void) fprintf(STDOUT, " }\n");
1684 }
1685 break;
1686 default:
1687 if (9 >= Num_Tools) {
1688 (void) fprintf(STDOUT, "\n /* (update the mailbox of the %ld tools) */\n", Num_Tools);
1689 } else {
1690 (void) fprintf(STDOUT, "\n /* (update the mailbox of the %2ld tools) */\n", Num_Tools);
1691 }
1692 if (!Interlude_Flag1) {
1693 if ((2L == Num_Tools) || (4L == Num_Tools)) {
1694 ncut = 2L;
1695 } else {
1696 ncut = 3L;
1697 }
1698 } else {
1699 if ((1L == Num_Tools) || (3L == Num_Tools)) {
1700 ncut = 2L;
1701 } else {
1702 ncut = 3L;
1703 }
1704 }
1705 if ((!Interlude_Flag1) || ((0L == na) && (0L == nb))) { /* no interlude */
1706 for (n = 0L; n < Num_Tools; n++) {
1707 if (0L == n) {
1708 (void) fprintf(STDOUT, " if ( (napa_mailbox[%ld].o >= napa_packet)", n);
1709 } else {
1710 if (0L != (n % ncut)) {
1711 (void) fprintf(STDOUT, " && (napa_mailbox[%ld].o >= napa_packet)", n);
1712 } else {
1713 (void) fprintf(STDOUT, "\n && (napa_mailbox[%ld].o >= napa_packet)", n);
1714 }
1715 }
1716 }
1717 (void) fprintf(STDOUT, " ) {\n");
1718 (void) fprintf(STDOUT, " napa_rel_loop = -1.0L;\n");
1719 (void) fprintf(STDOUT, " napa_tool_index = napa_packet;\n"); /* before napa_packet++ */
1720 for (n = 0L; n < Num_Tools; n++) {
1721 (void) fprintf(STDOUT, " napa_mailbox[%ld].i = START;\n", n );
1722 }
1723 (void) fprintf(STDOUT, " napa_packet++;\n");
1724 (void) fprintf(STDOUT, " }\n");
1725
1726 } else { /* interlude */
1727 for (n = 0L; n < Num_Tools; n++) {
1728 if (0L == n) {
1729 (void) fprintf(STDOUT, " if ( ((napa_mailbox[%ld].o >= napa_packet)", n);
1730 } else {
1731 if (0L != (n % ncut)) {
1732 (void) fprintf(STDOUT, " && (napa_mailbox[%ld].o >= napa_packet)", n);
1733 } else {
1734 (void) fprintf(STDOUT, "\n && (napa_mailbox[%ld].o >= napa_packet)", n);
1735 }
1736 }
1737 }
1738 (void) fprintf(STDOUT, ") ) {\n");
1739 (void) fprintf(STDOUT, " if ( 0LL >= napa_tool_start ) {\n");
1740 (void) fprintf(STDOUT, " if ( EOF == fflush((FILE*) NULL) ) {\n");
1741 (void) fprintf(STDOUT, " (void) fprintf(stderr, \"\\nNAPA Run Time Error: (I/O manager for tools)\\n\");\n");
1742 (void) fprintf(STDOUT, " (void) fprintf(stderr, \" flushing data from buffer I/O was not successful\\n\" );\n");
1743 (void) fprintf(STDOUT, " napa_exit(EXIT_FAILURE);\n");
1744 (void) fprintf(STDOUT, " }\n");
1745 if (!Interlude_Flag2) {
1746 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
1747 } else {
1748 if ((0L == na) && (0L == nb)) {
1749 (void) fprintf(STDOUT, " napa_tool_start = 0LL);\n" );
1750 }
1751 if ((0L != na) && (0L == nb)) {
1752 (void) fprintf(STDOUT, " napa_tool_start = %ldLL;\n", na);
1753 }
1754 if ((0L == na) && (0L != nb)) {
1755 (void) fprintf(STDOUT, " napa_tool_start = napa_rand_integer(%ldLL);\n", nb);
1756 if (0L != nc) {
1757 (void) fprintf(STDOUT, " napa_tool_start = %ldLL * (napa_tool_start / %ldLL);\n", nc, nc);
1758 }
1759 }
1760 if ((0L != na) && (0L != nb)) {
1761 (void) fprintf(STDOUT, " napa_tool_start = %ldLL + napa_rand_integer(%ldLL);\n", na, nb);
1762 if (0L != nc) {
1763 (void) fprintf(STDOUT, " napa_tool_start = %ldLL * (napa_tool_start / %ldLL);\n", nc, nc);
1764 }
1765 }
1766 }
1767 (void) fprintf(STDOUT, " napa_rel_loop = -1.0L;\n");
1768 (void) fprintf(STDOUT, " napa_tool_index = napa_packet;\n"); /* before napa_packet++ */
1769 for (n = 0L; n < Num_Tools; n++) {
1770 (void) fprintf(STDOUT, " napa_mailbox[%ld].i = START;\n", n);
1771 }
1772 (void) fprintf(STDOUT, " napa_packet++;\n");
1773 (void) fprintf(STDOUT, " } else {\n");
1774 (void) fprintf(STDOUT, " napa_tool_start--;\n");
1775 (void) fprintf(STDOUT, " }\n");
1776 (void) fprintf(STDOUT, " }\n");
1777 }
1778 break;
1779 }
1780 } else {
1781 switch (Num_Tools) {
1782 case 0L:
1783 break;
1784 case 1L:
1785 (void) fprintf(STDOUT, "\n /* (force tool start) */\n");
1786 (void) fprintf(STDOUT, " napa_msg->i = START;\n");
1787 break;
1788 default:
1789 (void) fprintf(STDOUT, "\n /* (force tools start) */\n");
1790 for (n = 0L; n < Num_Tools; n++) {
1791 (void) fprintf(STDOUT, " napa_mailbox[%ld].i = START;\n", n);
1792 }
1793 break;
1794 }
1795 }
1796 (void) fprintf(STDOUT, "\n");
1797 return;
1798}
EXTERN INTERLUDE_TYPE Interlude_List
Definition napa.h:974
EXTERN int Interlude_Flag1
Definition napa.h:868
EXTERN double Simulation_Rate
Definition napa.h:982
EXTERN int Interlude_Flag2
Definition napa.h:869

References Interlude_Flag1, Interlude_Flag2, Interlude_List, Num_Tools, Simulation_Rate, STDOUT, and Synchro_Flag.

Referenced by build_main_loop().

◆ build_main_loop_time()

void build_main_loop_time ( void )

Definition at line 123 of file bl.c.

123 {
124 char *str = (char*) NULL;
125 char tok[STRLENGTH] = {'\0'};
126 if (Periodic_Flag) { /* periodic sampling */
127 if ((Fs_Ext_Flag) || (Ts_Ext_Flag)) {
128 if ((Synchro_Flag) && (1L <= Num_Tools)) {
129 if (ISEQUAL(1.0, Segment_List[0].rate)) {
130 (void) fprintf(STDOUT, " napa_rel_time = napa_rel_loop * napa_ts_ext;\n");
131 } else {
132 (void) fprintf(STDOUT, " napa_rel_time = napa_rel_loop * (napa_ts_ext * %.15eL);\n", 1.0 / Segment_List[0].rate);
133 }
134 }
135 if (UNDEFINED != directive_id("JITTER")) {
136 if ((Periodic_Flag) && (1L < Num_Segments)) {
137 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
138 }
139 if (ISEQUAL(1.0, Segment_List[0].rate)) {
140 (void) fprintf(STDOUT, " napa_ref_time = napa_abs_loop * napa_ts_ext;\n");
141 } else {
142 (void) fprintf(STDOUT, " napa_ref_time = napa_abs_loop * (napa_ts_ext * %.15eL);\n", 1.0 / Segment_List[0].rate);
143 }
144 (void) fprintf(STDOUT, " napa_abs_time = napa_ref_time + JITTER;\n");
145 if ((Synchro_Flag) && (1L < Num_Tools)) {
146 (void) fprintf(STDOUT, " napa_rel_time += JITTER;\n");
147 }
148 } else {
149 if (ISEQUAL(1.0, Segment_List[0].rate)) {
150 (void) fprintf(STDOUT, " napa_abs_time = napa_abs_loop * napa_ts_ext;\n");
151 } else {
152 (void) fprintf(STDOUT, " napa_abs_time = napa_abs_loop * (napa_ts_ext * %.15eL);\n", 1.0 / Segment_List[0].rate);
153 }
154 }
155 } else {
156 if ((Synchro_Flag) && (1L <= Num_Tools)) {
157 if (ISEQUAL(1.0, Sampling_List.frequency * Segment_List[0].rate)) {
158 (void) fprintf(STDOUT, " napa_rel_time = napa_rel_loop;\n"); /* input frequency = 1.0 */
159 } else {
160 (void) fprintf(STDOUT, " napa_rel_time = napa_rel_loop * %.15eL;\n", /* input frequency */
161 1.0 / (Sampling_List.frequency * Segment_List[0].rate));
162 }
163 }
164 if (UNDEFINED != directive_id("JITTER")) {
165 if ((Periodic_Flag) && (1L < Num_Segments)) {
166 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
167 }
168 if (ISEQUAL(1.0, Sampling_List.frequency * Segment_List[0].rate)) {
169 (void) fprintf(STDOUT, " napa_ref_time = napa_abs_loop;\n"); /* input frequency = 1.0 */
170 } else {
171 (void) fprintf(STDOUT, " napa_ref_time = napa_abs_loop * %.15eL;\n", /* input frequency */
172 1.0 / (Sampling_List.frequency * Segment_List[0].rate));
173 }
174 (void) fprintf(STDOUT, " napa_abs_time = napa_ref_time + JITTER;\n");
175 if ((Synchro_Flag) && (1L < Num_Tools)) {
176 (void) fprintf(STDOUT, " napa_rel_time += JITTER;\n");
177 }
178 } else {
179 if (ISEQUAL(1.0, Sampling_List.frequency * Segment_List[0].rate)) {
180 (void) fprintf(STDOUT, " napa_abs_time = napa_abs_loop;\n"); /* input frequency = 1.0 */
181 } else {
182 (void) fprintf(STDOUT, " napa_abs_time = napa_abs_loop * %.15eL;\n", /* input frequency */
183 1.0 / (Sampling_List.frequency * Segment_List[0].rate));
184 }
185 }
186 }
187 } else { /* non periodic sampling, rel. time not supported */
188 (void) fprintf(STDOUT, " napa_ref_time = ");
189 str = Sampling_List.formula;
190 for (;;) {
191 str = get_token(str, tok, false);
192 if (ISEMPTY(tok)) {
193 (void) fprintf(STDOUT, ";\n");
194 break;
195 }
196 (void) build_name("", tok, RIGHT_VALUE);
197 (void) fprintf(STDOUT, "%s", tok);
198 }
199 (void) fprintf(STDOUT, "\n");
200 if (UNDEFINED != directive_id("JITTER")) {
201 (void) fprintf(STDOUT, " napa_abs_time = napa_ref_time + (JITTER);\n");
202 if ((Synchro_Flag) && (1L < Num_Tools)) {
203 (void) fprintf(STDOUT, " napa_rel_time += (JITTER);\n");
204 }
205 } else {
206 (void) fprintf(STDOUT, " napa_abs_time = napa_ref_time;\n");
207 }
208 }
209 if (UNDEFINED != directive_id("TIME_OFFSET")) {
210 if ((Periodic_Flag) && (1L < Num_Segments)) {
211 (void) fprintf(STDOUT, " napa_segment = 0L;\n");
212 }
213 (void) fprintf(STDOUT, " napa_abs_time += (TIME_OFFSET);\n"); /* NB: no meaning for napa_rel_time */
214 }
215 return;
216}
long directive_id(const char *identifier)
Definition id.c:707
EXTERN int Ts_Ext_Flag
Definition napa.h:885
EXTERN int Fs_Ext_Flag
Definition napa.h:857

References build_name(), directive_id(), Fs_Ext_Flag, get_token(), ISEMPTY, ISEQUAL, Num_Segments, Num_Tools, Periodic_Flag, RIGHT_VALUE, Sampling_List, Segment_List, STDOUT, STRLENGTH, Synchro_Flag, Ts_Ext_Flag, and UNDEFINED.

Referenced by build_main_loop().

◆ build_node()

void build_node ( long out)

Definition at line 529 of file bl.c.

529 { /* print C code of node, process node width */
530 char *str = (char*) NULL;
531 long kind;
532 kind = Node_List[out].kind;
533 str = Node_List[out].value;
534 switch (kind) {
535 case DELAY1_KIND:
536 print_delay1(str, out);
537 break;
538 case DELAY2_KIND:
539 print_delay2(str, out);
540 break;
541 case DELAY3_KIND:
542 print_delay3(str, out);
543 break;
544 case DELAY_KIND:
545 print_delay(str, out);
546 break;
547 case DC_KIND:
548 print_dc(out);
549 break;
551 print_differentiator(str, out);
552 break;
553 case INTEGRATOR_KIND:
554 print_integrator(str, out);
555 break;
556 case OSC_KIND:
557 print_osc(str, out);
558 break;
559 case SIN_KIND:
560 case COS_KIND:
561 case SIN2_KIND:
562 case COS2_KIND:
563 print_sincos(str, out, kind);
564 break;
565 case SQUARE_KIND:
566 print_square(str, out);
567 break;
568 case STEP_KIND:
569 print_step(str, out);
570 break;
571 case TRIANGLE_KIND:
572 print_triangle(str, out);
573 break;
574 case ITOB_KIND:
575 print_itob(str, out);
576 break;
577 case GAIN_KIND:
578 print_gain(str, out);
579 break;
580 case OFFSET_KIND:
581 print_offset(str, out);
582 break;
583 case HOLD_KIND:
584 case TRACK_KIND:
585 print_holdtrack(str, out, kind);
586 break;
587 case CLIP_KIND:
588 print_clip(str, out);
589 break;
590 case NOISE_KIND:
591 print_noise(str, out);
592 break;
593 case BSHIFT_KIND:
594 print_bshift(str, out);
595 break;
596 case LSHIFT_KIND:
597 case RSHIFT_KIND:
598 print_rlshift(str, out, kind);
599 break;
600 case RSHIFT1_KIND:
601 print_rshift1(str, out);
602 break;
603 case RSHIFT2_KIND:
604 print_rshift2(str, out);
605 break;
606 case CLOCK_KIND:
607 print_clock(str, out);
608 break;
609 case INV_KIND:
610 print_inv(str, out);
611 break;
612 case BUF_KIND:
613 print_buf(str, out);
614 break;
615 case TOGGLE_KIND:
616 print_toggle(str, out);
617 break;
618 case RIP_KIND:
619 print_rip(str, out);
620 break;
621 case ALU_KIND:
622 print_alu(str, out);
623 break;
624 case AVERAGE_KIND:
625 print_average(str, out);
626 break;
627 case COPY_KIND:
628 print_copy(str, out);
629 break;
630 case SUM_KIND:
631 case PROD_KIND:
632 print_dyadic0(str, out, kind);
633 break;
634 case SUB_KIND:
635 print_dyadic1(str, out, kind);
636 break;
637 case DIV_KIND:
638 case MOD_KIND:
639 print_dyadic7(str, out, kind);
640 break;
641 case QUANT_KIND:
642 print_quant(str, out);
643 break;
644 case RECT_KIND:
645 print_rect(str, out);
646 break;
647 case AND_KIND:
648 case OR_KIND:
649 case NAND_KIND:
650 case NOR_KIND:
651 print_dyadic2(str, out, kind);
652 break;
653 case WSUM_KIND:
654 print_wsum(str, out);
655 break;
656 case MULLER_KIND:
657 print_muller(str, out);
658 break;
659 case XOR_KIND:
660 case XNOR_KIND:
661 print_dyadic4(str, out, kind);
662 break;
663 case MIN_KIND:
664 case MAX_KIND:
665 print_minmax(str, out, kind);
666 break;
667 case ITOOL_KIND:
668 case DTOOL_KIND:
669 case IUSER_KIND:
670 case DUSER_KIND:
671 print_usertool(str, out, kind);
672 break;
673 case ALGEBRA_KIND:
674 case IALGEBRA_KIND:
675 case DALGEBRA_KIND:
676 print_algebra(str, out);
677 break;
678 case TEST_KIND:
679 print_test(str, out);
680 break;
681 case COMP_KIND:
682 print_comp(str, out);
683 break;
684 case EQUAL_KIND:
685 print_equal(str, out);
686 break;
687 case LATCH_KIND:
688 print_latch(str, out);
689 break;
690 case MUX_KIND:
691 print_mux(str, out);
692 break;
693 case MERGE_KIND:
694 print_merge(str, out);
695 break;
696 case RELAY_KIND:
697 print_relay(str, out);
698 break;
699 case ZERO_KIND:
700 print_zero(str, out);
701 break;
702 case TRIG_KIND:
703 print_trig(str, out);
704 break;
705 case CHG_KIND:
706 print_change(str, out);
707 break;
708 case SIGN_KIND:
709 print_sign(str, out);
710 break;
711 case ITOD_KIND:
712 print_itod(str, out);
713 break;
714 case DTOI_KIND:
715 print_dtoi(str, out);
716 break;
717 case BTOI_KIND:
718 print_btoi(str, out);
719 break;
720 case POLY_KIND:
721 print_poly(str, out);
722 break;
723 case BWINV_KIND:
724 print_bwinv(str, out);
725 break;
726 case BWAND_KIND:
727 case BWOR_KIND:
728 case BWNAND_KIND:
729 case BWNOR_KIND:
730 case BWXOR_KIND:
731 case BWXNOR_KIND:
732 print_dyadic3(str, out, kind);
733 break;
734 case ADC_KIND:
735 print_adc(str, out);
736 break;
737 case DAC_KIND:
738 print_dac(str, out);
739 break;
740 case UADC_KIND:
741 print_uadc(str, out);
742 break;
743 case UDAC_KIND:
744 print_udac(str, out);
745 break;
746 case ROM_KIND:
747 case ROM2_KIND:
748 print_rom(str, out);
749 break;
750 case RAM_KIND:
751 case RAM2_KIND:
752 print_ram(str, out);
753 break;
754 case FZINV_KIND:
755 print_fzinv(str, out);
756 break;
757 case FZBUF_KIND:
758 print_fzbuf(str, out);
759 break;
760 case FZAND_KIND:
761 case FZOR_KIND:
762 case FZNAND_KIND:
763 case FZNOR_KIND:
764 print_dyadic5(str, out, kind);
765 break;
766 case FZXOR_KIND:
767 case FZXNOR_KIND:
768 print_dyadic6(str, out, kind);
769 break;
770 case UNKNOWN_KIND: /* just in case */
771 default:
772 print_error_location( "node builder", Node_List[out].mline, Node_List[out].mfile);
773 (void) fprintf(STDERR, " <%s>, this node kind is not yet implemented\n", Node_List[out].tag);
774 break;
775 }
776 print_node_width_postprocessing(out); /* adjust width of integer if it is requested */
777 return;
778}
void print_node_width_postprocessing(long nod)
Definition bl.c:1801
void print_fzinv(char *str, long out)
Definition bn.c:1347
void print_delay1(char *str, long out)
Definition bn.c:148
void print_toggle(char *str, long out)
Definition bn.c:1238
void print_fzbuf(char *str, long out)
Definition bn.c:1330
void print_triangle(char *str, long out)
Definition bn.c:461
void print_uadc(char *str, long out)
Definition bn.c:2653
void print_offset(char *str, long out)
Definition bn.c:592
void print_muller(char *str, long out)
Definition bn.c:2230
void print_algebra(char *str, long out)
Definition bn.c:2443
void print_latch(char *str, long out)
Definition bn.c:2814
void print_dyadic3(char *str, long out, long k)
Definition bn.c:1803
void print_relay(char *str, long out)
Definition bn.c:3032
void print_holdtrack(char *str, long out, long k)
Definition bn.c:754
void print_noise(char *str, long out)
Definition bn.c:812
void print_alu(char *str, long out)
Definition bn.c:1362
void print_btoi(char *str, long out)
Definition bn.c:3290
void print_osc(char *str, long out)
Definition bn.c:270
void print_mux(char *str, long out)
Definition bn.c:2862
void print_square(char *str, long out)
Definition bn.c:410
void print_equal(char *str, long out)
Definition bn.c:2738
void print_wsum(char *str, long out)
Definition bn.c:675
void print_dyadic5(char *str, long out, long k)
Definition bn.c:1891
void print_change(char *str, long out)
Definition bn.c:3188
void print_dyadic4(char *str, long out, long k)
Definition bn.c:1847
void print_step(char *str, long out)
Definition bn.c:545
void print_itod(char *str, long out)
Definition bn.c:3260
void print_average(char *str, long out)
Definition bn.c:1445
void print_udac(char *str, long out)
Definition bn.c:2697
void print_gain(char *str, long out)
Definition bn.c:617
void print_dac(char *str, long out)
Definition bn.c:2600
void print_minmax(char *str, long out, long k)
Definition bn.c:2271
void print_poly(char *str, long out)
Definition bn.c:3588
void print_delay2(char *str, long out)
Definition bn.c:170
void print_rlshift(char *str, long out, long k)
Definition bn.c:963
void print_bwinv(char *str, long out)
Definition bn.c:1259
void print_ram(char *str, long out)
Definition bn.c:3445
void print_sincos(char *str, long out, long k)
Definition bn.c:310
void print_dyadic2(char *str, long out, long k)
Definition bn.c:1763
void print_usertool(char *str, long out, long k)
Definition bn.c:2330
void print_rip(char *str, long out)
Definition bn.c:1274
void print_test(char *str, long out)
Definition bn.c:2496
void print_trig(char *str, long out)
Definition bn.c:3148
void print_quant(char *str, long out)
Definition bn.c:2122
void print_differentiator(char *str, long out)
Definition bn.c:226
void print_integrator(char *str, long out)
Definition bn.c:249
void print_inv(char *str, long out)
Definition bn.c:1208
void print_zero(char *str, long out)
Definition bn.c:3088
void print_dyadic7(char *str, long out, long k)
Definition bn.c:1956
void print_sign(char *str, long out)
Definition bn.c:3238
void print_comp(char *str, long out)
Definition bn.c:2796
void print_clock(char *str, long out)
Definition bn.c:1171
void print_adc(char *str, long out)
Definition bn.c:2542
void print_clip(char *str, long out)
Definition bn.c:785
void print_dc(long out)
Definition bn.c:217
void print_merge(char *str, long out)
Definition bn.c:2933
void print_rect(char *str, long out)
Definition bn.c:2100
void print_delay(char *str, long out)
Definition bn.c:91
void print_buf(char *str, long out)
Definition bn.c:1223
void print_bshift(char *str, long out)
Definition bn.c:867
void print_dtoi(char *str, long out)
Definition bn.c:3275
void print_dyadic0(char *str, long out, long k)
Definition bn.c:1608
void print_rshift2(char *str, long out)
Definition bn.c:1084
void print_rshift1(char *str, long out)
Definition bn.c:1028
void print_delay3(char *str, long out)
Definition bn.c:193
void print_dyadic6(char *str, long out, long k)
Definition bn.c:1934
void print_itob(char *str, long out)
Definition bn.c:574
void print_copy(char *str, long out)
Definition bn.c:1569
void print_rom(char *str, long out)
Definition bn.c:3343
void print_dyadic1(char *str, long out, long k)
Definition bn.c:1711
#define DELAY2_KIND
Definition napa.h:255
#define MUX_KIND
Definition napa.h:288
#define EQUAL_KIND
Definition napa.h:262
#define ITOD_KIND
Definition napa.h:278
#define MOD_KIND
Definition napa.h:286
#define RIP_KIND
Definition napa.h:302
#define MULLER_KIND
Definition napa.h:287
#define WSUM_KIND
Definition napa.h:323
#define TRACK_KIND
Definition napa.h:318
#define RSHIFT2_KIND
Definition napa.h:307
#define AND_KIND
Definition napa.h:229
#define ROM2_KIND
Definition napa.h:304
#define TRIANGLE_KIND
Definition napa.h:319
#define LATCH_KIND
Definition napa.h:281
#define DIFFERENTIATOR_KIND
Definition napa.h:257
#define RSHIFT1_KIND
Definition napa.h:306
#define LSHIFT_KIND
Definition napa.h:282
#define INV_KIND
Definition napa.h:276
#define BWNAND_KIND
Definition napa.h:236
#define DTOI_KIND
Definition napa.h:259
#define FZNOR_KIND
Definition napa.h:267
#define OSC_KIND
Definition napa.h:294
#define DELAY3_KIND
Definition napa.h:256
#define CLOCK_KIND
Definition napa.h:244
#define NOR_KIND
Definition napa.h:291
#define ADC_KIND
Definition napa.h:226
#define COPY_KIND
Definition napa.h:247
#define OFFSET_KIND
Definition napa.h:292
#define OR_KIND
Definition napa.h:293
#define CLIP_KIND
Definition napa.h:243
#define RELAY_KIND
Definition napa.h:301
#define SQUARE_KIND
Definition napa.h:312
#define MIN_KIND
Definition napa.h:285
#define UADC_KIND
Definition napa.h:321
#define IUSER_KIND
Definition napa.h:280
#define NAND_KIND
Definition napa.h:289
#define COS2_KIND
Definition napa.h:249
#define AVERAGE_KIND
Definition napa.h:230
#define PROD_KIND
Definition napa.h:296
#define DUSER_KIND
Definition napa.h:261
#define TEST_KIND
Definition napa.h:316
#define DELAY1_KIND
Definition napa.h:254
#define GAIN_KIND
Definition napa.h:271
#define ITOB_KIND
Definition napa.h:277
#define BUF_KIND
Definition napa.h:233
#define HOLD_KIND
Definition napa.h:273
#define XOR_KIND
Definition napa.h:325
#define RAM_KIND
Definition napa.h:298
#define SIN_KIND
Definition napa.h:310
#define TOGGLE_KIND
Definition napa.h:317
#define XNOR_KIND
Definition napa.h:324
#define BWXNOR_KIND
Definition napa.h:239
#define DALGEBRA_KIND
Definition napa.h:251
#define RECT_KIND
Definition napa.h:300
#define MERGE_KIND
Definition napa.h:284
#define ROM_KIND
Definition napa.h:303
#define FZBUF_KIND
Definition napa.h:264
#define DC_KIND
Definition napa.h:252
#define SIGN_KIND
Definition napa.h:309
#define FZXNOR_KIND
Definition napa.h:269
#define IALGEBRA_KIND
Definition napa.h:274
#define ALU_KIND
Definition napa.h:228
#define SUM_KIND
Definition napa.h:315
#define BWXOR_KIND
Definition napa.h:240
#define BTOI_KIND
Definition napa.h:232
#define FZNAND_KIND
Definition napa.h:266
#define ITOOL_KIND
Definition napa.h:279
#define DTOOL_KIND
Definition napa.h:260
#define RAM2_KIND
Definition napa.h:299
#define SUB_KIND
Definition napa.h:314
#define DIV_KIND
Definition napa.h:258
#define FZOR_KIND
Definition napa.h:268
#define BWOR_KIND
Definition napa.h:238
#define FZXOR_KIND
Definition napa.h:270
#define POLY_KIND
Definition napa.h:295
#define RSHIFT_KIND
Definition napa.h:305
#define UDAC_KIND
Definition napa.h:322
#define ZERO_KIND
Definition napa.h:326
#define INTEGRATOR_KIND
Definition napa.h:275
#define MAX_KIND
Definition napa.h:283
#define BWNOR_KIND
Definition napa.h:237
#define COMP_KIND
Definition napa.h:245
#define BSHIFT_KIND
Definition napa.h:231
#define DELAY_KIND
Definition napa.h:253
#define FZINV_KIND
Definition napa.h:265
#define ALGEBRA_KIND
Definition napa.h:227
#define BWINV_KIND
Definition napa.h:235
#define FZAND_KIND
Definition napa.h:263
#define QUANT_KIND
Definition napa.h:297
#define STEP_KIND
Definition napa.h:313
#define SIN2_KIND
Definition napa.h:311
#define UNKNOWN_KIND
Definition napa.h:224
#define CHG_KIND
Definition napa.h:242
#define BWAND_KIND
Definition napa.h:234
#define DAC_KIND
Definition napa.h:250
#define TRIG_KIND
Definition napa.h:320
#define COS_KIND
Definition napa.h:248
#define NOISE_KIND
Definition napa.h:290

References ADC_KIND, ALGEBRA_KIND, ALU_KIND, AND_KIND, AVERAGE_KIND, BSHIFT_KIND, BTOI_KIND, BUF_KIND, BWAND_KIND, BWINV_KIND, BWNAND_KIND, BWNOR_KIND, BWOR_KIND, BWXNOR_KIND, BWXOR_KIND, CHG_KIND, CLIP_KIND, CLOCK_KIND, COMP_KIND, COPY_KIND, COS2_KIND, COS_KIND, DAC_KIND, DALGEBRA_KIND, DC_KIND, DELAY1_KIND, DELAY2_KIND, DELAY3_KIND, DELAY_KIND, DIFFERENTIATOR_KIND, DIV_KIND, DTOI_KIND, DTOOL_KIND, DUSER_KIND, EQUAL_KIND, FZAND_KIND, FZBUF_KIND, FZINV_KIND, FZNAND_KIND, FZNOR_KIND, FZOR_KIND, FZXNOR_KIND, FZXOR_KIND, GAIN_KIND, HOLD_KIND, IALGEBRA_KIND, INTEGRATOR_KIND, INV_KIND, ITOB_KIND, ITOD_KIND, ITOOL_KIND, IUSER_KIND, LATCH_KIND, LSHIFT_KIND, MAX_KIND, MERGE_KIND, MIN_KIND, MOD_KIND, MULLER_KIND, MUX_KIND, NAND_KIND, Node_List, NOISE_KIND, NOR_KIND, OFFSET_KIND, OR_KIND, OSC_KIND, POLY_KIND, print_adc(), print_algebra(), print_alu(), print_average(), print_bshift(), print_btoi(), print_buf(), print_bwinv(), print_change(), print_clip(), print_clock(), print_comp(), print_copy(), print_dac(), print_dc(), print_delay(), print_delay1(), print_delay2(), print_delay3(), print_differentiator(), print_dtoi(), print_dyadic0(), print_dyadic1(), print_dyadic2(), print_dyadic3(), print_dyadic4(), print_dyadic5(), print_dyadic6(), print_dyadic7(), print_equal(), print_error_location(), print_fzbuf(), print_fzinv(), print_gain(), print_holdtrack(), print_integrator(), print_inv(), print_itob(), print_itod(), print_latch(), print_merge(), print_minmax(), print_muller(), print_mux(), print_node_width_postprocessing(), print_noise(), print_offset(), print_osc(), print_poly(), print_quant(), print_ram(), print_rect(), print_relay(), print_rip(), print_rlshift(), print_rom(), print_rshift1(), print_rshift2(), print_sign(), print_sincos(), print_square(), print_step(), print_test(), print_toggle(), print_triangle(), print_trig(), print_uadc(), print_udac(), print_usertool(), print_wsum(), print_zero(), PROD_KIND, QUANT_KIND, RAM2_KIND, RAM_KIND, RECT_KIND, RELAY_KIND, RIP_KIND, ROM2_KIND, ROM_KIND, RSHIFT1_KIND, RSHIFT2_KIND, RSHIFT_KIND, SIGN_KIND, SIN2_KIND, SIN_KIND, SQUARE_KIND, STDERR, STEP_KIND, SUB_KIND, SUM_KIND, TEST_KIND, TOGGLE_KIND, TRACK_KIND, TRIANGLE_KIND, TRIG_KIND, UADC_KIND, UDAC_KIND, UNKNOWN_KIND, WSUM_KIND, XNOR_KIND, XOR_KIND, and ZERO_KIND.

Referenced by build_main_loop_block2().

◆ build_output()

void build_output ( long o)

Definition at line 1220 of file bl.c.

1220 {
1221 static int first1 = true;
1222 int first2;
1223 long i, k, l, oldl, len1, len2;
1224 long nn, nv;
1225 long tp;
1226 char *c = (char*) NULL;
1227 char *str = (char*) NULL;
1228 char indent[3] = {'\0'};
1229 char scale[STRLENGTH] = {'\0'};
1230 char tok[STRLENGTH] = {'\0'};
1231 char v1[LINLENGTH] = {'\0'};
1232 char v2[LINLENGTH] = {'\0'};
1233 char v3[LINLENGTH] = {'\0'};
1234 char v4[LINLENGTH] = {'\0'};
1235 char v5[LINLENGTH] = {'\0'};
1236 char sgn[2] = {'\0'};
1237 int ok;
1238 if (OUTPUT_TYPE != IO_List[o].type) {
1239 return;
1240 }
1241 if (first1) {
1242 (void) fprintf(STDOUT, " napa_segment = 0L;\n"); /* output is evaluated as positionned in segment 0 */
1243 first1 = false;
1244 }
1245 if (ISNOTEMPTY(IO_List[o].condition)) {
1246 (void) fprintf(STDOUT, " ");
1247 (void) strcpy(indent, "");
1248 build_condition(IO_List[o].condition, IO_List[o].mline, IO_List[o].mfile);
1249 } else {
1250 (void) fprintf(STDOUT, " if ( true ) {\n");
1251 (void) strcpy(indent, " ");
1252 }
1253 (void) strcpy(v1, "\"%.15Le\"");
1254 (void) fprintf(STDOUT, "#if !defined(NO_TIME_OUTPUT)\n");
1255 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, %s%s, %s);\n", o, indent, v1, "napa_abs_time");
1256 (void) fprintf(STDOUT, "#endif\n");
1257 str = IO_List[o].element; /* unprocessed list of elements */
1258 first2 = true;
1259 (void) strcpy(v1, "\" "); /* build string of output formats in 'v1' */
1260 (void) strcpy(v2, ""); /* build string of output identifiers in 'v2' */
1261 (void) strcpy(v3, ""); /* used to build 'v1' */
1262 (void) strcpy(v4, ""); /* used to build 'v1' */
1263 do {
1264 str = get_output_and_scaling(str, sgn, tok, scale); /* sign, identifier and scale factor */
1265 if ((0 == strcmp(sgn, "-")) || (0 == strcmp(sgn, "+"))) {
1266 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile);
1267 (void) fprintf(STDERR, " No sign expected in output instruction list: %s%s\n", sgn, tok);
1268 }
1269 if (!first2) {
1270 (void) strcat(v2, ", ");
1271 }
1272 first2 = false;
1273 /* process special identifiers: 'napa_abs_loop', 'LOOP_INDEX', 'ABS_LOOP_INDEX', 'REL_LOOP_INDEX', 'TOOL_INDEX' */
1274 if (0 == strcmp(tok, "napa_abs_loop")) {
1275 if (ISNOTEMPTY(scale)) {
1276 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1277 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1278 }
1279 (void) strcat(v1, " %15.0f");
1280 (void) strcat(v2, tok);
1281 continue;
1282 }
1283 if (0 == strcmp(tok, "LOOP_INDEX")) {
1284 if (ISNOTEMPTY(scale)) {
1285 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1286 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1287 }
1288 (void) strcat(v1, " %15lld");
1289 (void) strcat(v2, tok);
1290 continue;
1291 }
1292 if (0 == strcmp(tok, "ABS_LOOP_INDEX")) {
1293 if (ISNOTEMPTY(scale)) {
1294 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1295 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1296 }
1297 (void) strcat(v1, " %15lld");
1298 (void) strcat(v2, tok);
1299 continue;
1300 }
1301 if (0 == strcmp(tok, "REL_LOOP_INDEX")) {
1302 if (ISNOTEMPTY(scale)) {
1303 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1304 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1305 }
1306 (void) strcat(v1, " %15lld");
1307 (void) strcat(v2, tok);
1308 continue;
1309 }
1310 if (0 == strcmp(tok, "TOOL_INDEX")) {
1311 if (ISNOTEMPTY(scale)) {
1312 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1313 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1314 }
1315 (void) strcat(v1, " %15lld");
1316 (void) strcat(v2, tok);
1317 continue;
1318 }
1319 /* process special identifiers: 'TIME', 'ABS_TIME', 'REF_TIME', 'REL_TIME' */
1320 if (0 == strcmp(tok, "TIME")) {
1321 if (ISNOTEMPTY(scale)) {
1322 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1323 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1324 }
1325 (void) strcat(v1, " %.15e");
1326 (void) strcat(v2, tok);
1327 continue;
1328 }
1329 if (0 == strcmp(tok, "ABS_TIME")) {
1330 if (ISNOTEMPTY(scale)) {
1331 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1332 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1333 }
1334 (void) strcat(v1, " %.15e");
1335 (void) strcat(v2, tok);
1336 continue;
1337 }
1338 if (0 == strcmp(tok, "REF_TIME")) {
1339 if (ISNOTEMPTY(scale)) {
1340 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1341 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1342 }
1343 (void) strcat(v1, " %.15e");
1344 (void) strcat(v2, tok);
1345 continue;
1346 }
1347 if (0 == strcmp(tok, "REL_TIME")) {
1348 if (ISNOTEMPTY(scale)) {
1349 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile );
1350 (void) fprintf(STDERR, " no scaling is allowed for <%s>\n", tok);
1351 }
1352 (void) strcat(v1, " %.15e");
1353 (void) strcat(v2, tok);
1354 continue;
1355 }
1356 /* process nodes, variables and string identifiers */
1357 tp = UNKNOWN_TYPE;
1358 nn = node_id(tok);
1359 nv = var_id(tok);
1360 if ((UNDEFINED != nn) || (UNDEFINED != nv)) {
1361 if (UNDEFINED != nn) {
1362 tp = Node_List[nn].type;
1363 }
1364 if (UNDEFINED != nv) {
1365 tp = Var_List[nv].type;
1366 }
1367 switch (tp) {
1368 case DIGITAL_DATA_TYPE:
1369 (void) strcpy(v3, "");
1370 ok = false;
1371 if (0 == strncmp(scale, "X", (size_t) 1)) { /* long long int hexa output format (upper case) */
1372 (void) strcpy(v4, X_Format);
1373 c = strchr(v4, 'x');
1374 if ((char*) NULL != c) {
1375 *c = 'X';
1376 }
1377 ok = true;
1378 } else if (0 == strncmp(scale, "x", (size_t) 1)) { /* long long int hexa output format (lower case) */
1379 (void) strcpy(v4, X_Format);
1380 c = strchr(v4, 'X');
1381 if ((char*) NULL != c) {
1382 *c = 'x';
1383 }
1384 ok = true;
1385 } else if (0 == strncmp(scale, "\0", (size_t) 1)) {
1386 (void) strcpy(v4, I_Format); /* long long int output format */
1387 ok = true;
1388 }
1389 if (!ok) {
1390 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile);
1391 if (0 == strncmp(scale, "_", (size_t) 1)) {
1392 (void) fprintf(STDERR, " <%s>, no unit is expected for a digital output element\n", tok);
1393 } else {
1394 (void) fprintf(STDERR, " a scaling letter ('%c') for a digital output element (<%s>) is not expected\n", scale[0],tok);
1395 }
1396 }
1397 (void) strcat(v1, v4);
1398 break;
1399 case ANALOG_DATA_TYPE:
1400 (void) strcpy(v3, "");
1401 (void) strcat(v1, R_Format); /* double float output format */
1402 ok = false;
1403 if (0 == strcmp (scale, "\0")) { ok = true; } /* no scaling */
1404 if (0 == strncmp(scale, "_", 1)) { ok = true; } /* no scaling */
1405 if (0 == strncmp(scale, "y", 1)) { (void) strcpy(v3, "*1.0e24" ); ok = true; } /* 'y' yocto 10^-24 */
1406 if (0 == strncmp(scale, "z", 1)) { (void) strcpy(v3, "*1.0e21" ); ok = true; } /* 'z' zepto 10^-21 */
1407 if (0 == strncmp(scale, "a", 1)) { (void) strcpy(v3, "*1.0e18" ); ok = true; } /* 'a' atto 10^-18 */
1408 if (0 == strncmp(scale, "f", 1)) { (void) strcpy(v3, "*1.0e15" ); ok = true; } /* 'f' femto 10^-15 */
1409 if (0 == strncmp(scale, "p", 1)) { (void) strcpy(v3, "*1.0e12" ); ok = true; } /* 'p' pico 10^-12 */
1410 if (0 == strncmp(scale, "n", 1)) { (void) strcpy(v3, "*1.0e9" ); ok = true; } /* 'n' nano 10^-09 */
1411 if (0 == strncmp(scale, "u", 1)) { (void) strcpy(v3, "*1.0e6" ); ok = true; } /* 'u' micro 10^-06 */
1412 if (0 == strncmp(scale, "m", 1)) { (void) strcpy(v3, "*1.0e3" ); ok = true; } /* 'm' milli 10^-03 */
1413 if (0 == strncmp(scale, "k", 1)) { (void) strcpy(v3, "*1.0e-3" ); ok = true; } /* 'k' kilo 10^+03 */
1414 if (0 == strncmp(scale, "M", 1)) { (void) strcpy(v3, "*1.0e-6" ); ok = true; } /* 'M' mega 10^+06 */
1415 if (0 == strncmp(scale, "G", 1)) { (void) strcpy(v3, "*1.0e-9" ); ok = true; } /* 'G' giga 10^+09 */
1416 if (0 == strncmp(scale, "T", 1)) { (void) strcpy(v3, "*1.0e-12"); ok = true; } /* 'T' tera 10^+12 */
1417 if (0 == strncmp(scale, "P", 1)) { (void) strcpy(v3, "*1.0e-15"); ok = true; } /* 'P' peta 10^+15 */
1418 if (0 == strncmp(scale, "E", 1)) { (void) strcpy(v3, "*1.0e-18"); ok = true; } /* 'E' exa 10^+18 */
1419 if (0 == strncmp(scale, "Z", 1)) { (void) strcpy(v3, "*1.0e-21"); ok = true; } /* 'Z' zetta 10^+21 */
1420 if (0 == strncmp(scale, "Y", 1)) { (void) strcpy(v3, "*1.0e-24"); ok = true; } /* 'Y' yotta 10^+24 */
1421 if (0 == strncmp(scale, "%", 1)) { (void) strcpy(v3, "*1.0e2" ); ok = true; } /* '%' percent 10^-2 */
1422 if (!ok) {
1423 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile);
1424 (void) fprintf(STDERR, " scaling suffix '%s' of analog output element <%s> is not valid\n", scale, tok);
1425 }
1426 break;
1427 case STRING_DATA_TYPE:
1428 (void) strcpy(v3, ""); /* no scaling */
1429 if (UNDEFINED != nn) {
1430 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile);
1431 (void) fprintf(STDERR, " a node cannot be string type\n");
1432 }
1433 if (UNDEFINED != nv) {
1434 if (0 == strcmp("Space", Var_List[nv].name1)) {
1435 (void) strcat(v1, " %s");
1436 } else {
1437 (void) strcat(v1, S_String_Format);
1438 }
1439 }
1440 break;
1441 default:
1442 /* do nothing */;
1443 }
1444 if (UNDEFINED != nn) {
1445 (void) strcpy(tok, Node_List[nn].name1);
1446 }
1447 if (UNDEFINED != nv) {
1448 (void) strcpy(tok, Var_List[nv].name1 );
1449 }
1450 (void) build_name("", tok, RIGHT_VALUE);
1451 (void) strcat(v2, tok); /* add identifier */
1452 (void) strcat(v2, v3); /* add scaling string */
1453 continue;
1454 }
1455 print_error_location( "output", IO_List[o].mline, IO_List[o].mfile);
1456 (void) fprintf(STDERR, " There is no node nor variable called <%s>\n", tok);
1457 process_node_error(tok);
1459 } while (ISNOTEMPTY(str));
1460 /* formatting output to limit the length of lines of the C code */
1461 len1 = LENGTH(v1);
1462 len2 = LENGTH(v2);
1463 if (100L > (len1 + len2)) {
1464 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld, %s%s\\n\", %s);\n", o, indent, v1, v2);
1465 } else {
1466 (void) fprintf(STDOUT, " (void) fprintf(napa_fp_%ld,", o );
1467 if (95L > len1) {
1468 (void) fprintf(STDOUT, " %s", v1 );
1469 (void) fprintf(STDOUT, "\\n\",\n" );
1470 (void) fprintf(STDOUT, " %s", indent );
1471 } else {
1472 (void) fprintf(STDOUT, "\n" );
1473 (void) fprintf(STDOUT, "%s ", indent );
1474 l = len1;
1475 for (;;) { /* determine roughly the best length of line */
1476 l = (l / 2L) + (l % 2L);
1477 if (l < 120L) {
1478 break;
1479 }
1480 }
1481 oldl = l;
1482 k = 1L; /* drop first character, a " */
1483 while (oldl <= LENGTH(&(v1[k]))) {
1484 l = oldl;
1485 while ('%' != v1[k+l]) {
1486 l++; /* adjust length */
1487 }
1488 for (i = 0L; i < l; i++) {
1489 v5[i] = v1[k+i];
1490 }
1491 v5[l] = '\0'; /* terminate string */
1492 (void) fprintf(STDOUT, "\"%s\"\n", v5);
1493 (void) fprintf(STDOUT, " %s", indent );
1494 k += l;
1495 }
1496 (void) strcpy(v5, &(v1[k]));
1497 (void) fprintf(STDOUT, "\"%s", v5);
1498 (void) fprintf(STDOUT, "\\n\",\n" );
1499 (void) fprintf(STDOUT, " %s", indent );
1500 }
1501 if (120L > len2) {
1502 (void) fprintf(STDOUT, "%s", v2);
1503 (void) fprintf(STDOUT, ");\n" );
1504 } else {
1505 l = len2;
1506 for (;;) { /* determine the best length of line */
1507 l = (l / 2L) + (l % 2L);
1508 if (l < 120L) {
1509 break;
1510 }
1511 }
1512 oldl = l;
1513 k = 0L;
1514 while (oldl <= LENGTH(&(v2[k]))) {
1515 l = oldl;
1516 while (' ' != v2[k+l]) {
1517 l++; /* adjust length */
1518 }
1519 l++;
1520 for (i = 0L; i < l; i++) {
1521 v5[i] = v2[k+i];
1522 }
1523 v5[l-1L] = '\0'; /* terminate string and suppress last blank */
1524 (void) fprintf(STDOUT, "%s\n", v5);
1525 (void) fprintf(STDOUT, " %s", indent );
1526 k += l;
1527 }
1528 (void) strcpy(v5, &(v2[k]));
1529 (void) fprintf(STDOUT, "%s", v5);
1530 (void) fprintf(STDOUT, ");\n" );
1531 }
1532 }
1533 (void) fprintf(STDOUT, " }\n");
1534 return;
1535}
void process_node_error(const char *tok1)
Definition mp.c:259
#define UNKNOWN_TYPE
Definition napa.h:332
EXTERN char R_Format[2047L]
Definition napa.h:897
EXTERN char S_String_Format[2047L]
Definition napa.h:904
EXTERN char X_Format[2047L]
Definition napa.h:900
EXTERN char I_Format[2047L]
Definition napa.h:896
#define OUTPUT_TYPE
Definition napa.h:359
char * get_output_and_scaling(char *str, char *sgn, char *out, char *scl)
Definition tk.c:1061

References ANALOG_DATA_TYPE, build_condition(), build_name(), DIGITAL_DATA_TYPE, get_output_and_scaling(), I_Format, IO_List, ISNOTEMPTY, LENGTH, LINLENGTH, node_id(), Node_List, OUTPUT_TYPE, print_error_location(), process_node_error(), process_variable_error(), R_Format, RIGHT_VALUE, S_String_Format, STDERR, STDOUT, STRING_DATA_TYPE, STRLENGTH, UNDEFINED, UNKNOWN_TYPE, var_id(), Var_List, and X_Format.

Referenced by build_main_loop_block3().

◆ build_update()

void build_update ( long i,
const char * indent )

Definition at line 822 of file bl.c.

822 { /* conditional and non conditional update */
823 int l, m, p;
824 int flag;
825 long d, j, k;
826 long nn, nv;
827 long len;
828 char *s = (char*) NULL;
829 char *t = (char*) NULL;
830 char lst[MAXPARMS][STRLENGTH];
831 char tok1[STRLENGTH] = {'\0'};
832 char tok2[STRLENGTH] = {'\0'};
833 char tok3[STRLENGTH] = {'\0'};
834 char v0[LINLENGTH] = {'\0'};
835 char v1[LINLENGTH] = {'\0'};
836 char v2[LINLENGTH] = {'\0'};
837 char v3[LINLENGTH] = {'\0'};
838 char v4[LINLENGTH] = {'\0'};
839
840 s = Update_List[i].value; /* take definition of update */
841 /* CALL (to avoid subtle side effects, does not accept conditional execution) */
842 if (0 == strncmp(Update_List[i].name, "$call$", (size_t) 6)) {
843 (void) fprintf(STDOUT, " ");
844 j = 0L;
845 for (;;) {
846 s = get_token(s, tok1, true);
847 j++;
848 if (ISEMPTY(tok1)) {
849 (void) fprintf(STDOUT, ";\n");
850 break;
851 }
852 nn = node_id(tok1);
853 nv = var_id(tok1);
854 if (UNDEFINED != nv) { /* a variable */
855 (void) strcpy(v1, Var_List[nv].name1);
856 if (1L == j) {
857 (void) build_name("", v1, LEFT_VALUE);
858 (void) fprintf(STDOUT, "%s = ", v1);
859 } else {
860 (void) build_name("", v1, RIGHT_VALUE);
861 (void) fprintf(STDOUT, "%s", v1);
862 }
863 } else if (UNDEFINED != nn) { /* a node */
864 (void) strcpy(v1, Node_List[nn].name1);
865 if (1L == j) {
866 print_error_location( "call", Update_List[i].mline, Update_List[i].mfile);
867 (void) fprintf(STDERR, " <%s> a node cannot be updated using a function call\n", tok1);
868 } else {
869 (void) build_name("", v1, RIGHT_VALUE);
870 (void) fprintf(STDOUT, "%s", v1);
871 }
872 } else { /* not a node, nor a variable */
873 if (1L == j) {
874 if (0 == strcmp(tok1, "void")) {
875 /* do nothing */
876 } else {
877 (void) fprintf(STDOUT, "%s = ", tok1); /* not a node nor a user variable */
878 print_warning_location( "call", Update_List[i].mline, Update_List[i].mfile);
879 (void) fprintf(STDERR, " <%s> is not a user's variable!\n", tok1);
881 }
882 } else {
883 (void) fprintf(STDOUT, "%s", tok1);
884 }
885 }
886 }
887 return;
888 }
889
890 /* RESTART (does not accept conditional execution) */
891 if (0 == strncmp(Update_List[i].name, "$restart$", (size_t) 9)) {
892 if (0L < Num_Nodes) {
893 (void) fprintf(STDOUT, " napa_reset_nodes();\n");
894 }
895 (void) fprintf(STDOUT, " napa_abs_loop++;\n");
896 if (Load_Flag) {
897 (void) fprintf(STDOUT, "# include \"%s\"\n", Load_List.fname);
898 }
899 call_user_functions(" ", "reset_");
900 (void) fprintf(STDOUT, " continue;\n");
901 return;
902 }
903
904 /* ASSERT (accept conditional execution) */
905 if (0 == strncmp(Update_List[i].name, "$assert$", (size_t) 8)) {
906 (void) fprintf(STDOUT, "#if !defined(NO_ASSERT)\n");
907 s = get_token(s, v1, false); /* extract from s the text between double quotes */
908 t = s;
909 (void) strcpy(v2, "");
910 for (;;) {
911 t = get_token(t, tok1, true);
912 if (ISEMPTY(tok1)) {
913 break;
914 }
915 k = var_id(tok1);
916 (void) strcpy(v0, v2);
917 if (UNDEFINED == k) {
918 (void) snprintf(v2, (size_t) (LINLENGTH-1L), "%s%s", v0, tok1);
919 } else {
920 (void) snprintf(v2, (size_t) (LINLENGTH-1L), "%s%s", v0, Var_List[k].name1);
921 }
922 }
923 (void) fprintf(STDOUT, "%s if ( !(", indent);
924 for (;;) {
925 s = get_token(s, tok1, true);
926 if (ISEMPTY(tok1)) {
927 (void) fprintf(STDOUT, ") ) {\n");
928 (void) fprintf(STDOUT, "%s if ( (!napa_assert_flag) && (0.0L < napa_abs_loop) ) {\n", indent);
929 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\nNAPA Run Time Exit:", indent);
930 (void) fprintf(STDOUT, " loop[%%Lg]\\n\", napa_abs_loop);\n");
931 if (!Cmdline_Flag) {
932 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n -> Test at line %4lu of main netlist\\n\");\n",
933 indent, Update_List[i].mline[0]);
934 for (d = 1L; d < MAXDEPTH; d++) {
935 if (0UL == Update_List[i].mline[d]) {
936 break;
937 }
938 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" -> Test at line %4lu of \\\"%s\\\"\\n\");\n",
939 indent, Update_List[i].mline[d], Record_Cell_File_Table[Update_List[i].mfile[d]]);
940 }
941 }
942 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n ****\");\n", indent);
943 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n **** Assertion ' %s ' failed\");\n", indent, v2);
944 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n ****\\n\");\n", indent);
945 s = v2;
946 len = 0L;
947 p = 0;
948 for (;;) { /* list of nodes and variables in assert string */
949 s = get_token(s, tok2, false);
950 if (!ISNOTEMPTY(tok2)) {
951 break;
952 }
953 if ((UNDEFINED != node_id(tok2)) || (UNDEFINED != var_id(tok2))) {
954 len = MAX(LENGTH(tok2), len);
955 (void) strcpy(lst[p], tok2);
956 p++;
957 continue;
958 }
959 if (UNKNOWN_TYPE != constant_type(tok2)) {
960 continue;
961 }
962 if ((ANALOG_DATA_TYPE == get_type(tok2)) || (DIGITAL_DATA_TYPE == get_type(tok2))) {
963 len = MAX(LENGTH(tok2), len);
964 (void) strcpy(lst[p], tok2);
965 p++;
966 continue;
967 }
968 }
969 for (l = 0; l < p; l++) {
970 flag = false;
971 for (m = l + 1; m < p; m++) {
972 if (0 == strcmp(lst[l], lst[m])) {
973 flag = true;
974 }
975 }
976 if (flag) { /* a double entry is detected, skip this one */
977 continue;
978 }
979 (void) strcpy(tok2, lst[l]);
980 (void) strcpy(tok3, lst[l]);
981 if (UNDEFINED != node_id(tok2)) {
982 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" <- %-*s = ", indent, (int) len, tok2);
983 (void) build_name("", tok3, RIGHT_VALUE);
984 if (ANALOG_DATA_TYPE == get_type(tok2)) {
985 (void) fprintf(STDOUT, "%% 8e\\n\", %s);\n", tok3);
986 } else if (DIGITAL_DATA_TYPE == get_type(tok2)) {
987 (void) fprintf(STDOUT, "%% lld\\n\", %s);\n", tok3);
988 }
989 continue;
990 }
991 if (UNDEFINED != var_id(tok2)) {
992 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" <- %-*s = ", indent, (int) len, tok2);
993 (void) build_name("", tok3, RIGHT_VALUE);
994 if (ANALOG_DATA_TYPE == get_type(tok2)) {
995 (void) fprintf(STDOUT, "%% 8e\\n\", %s);\n", tok3);
996 } else if (DIGITAL_DATA_TYPE == get_type(tok2)) {
997 (void) fprintf(STDOUT, "%% lld\\n\", %s);\n", tok3);
998 }
999 continue;
1000 }
1001 if (UNKNOWN_TYPE != constant_type(tok2)) {
1002 continue;
1003 }
1004 if (ANALOG_DATA_TYPE == get_type(tok2)) {
1005 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" <- %-*s = ", indent, (int) len, tok2);
1006 (void) fprintf(STDOUT, "%% 8e\\n\", %s);\n", tok2);
1007 continue;
1008 }
1009 if (DIGITAL_DATA_TYPE == get_type(tok2)) {
1010 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" <- %-*s = ", indent, (int) len, tok2);
1011 (void) fprintf(STDOUT, "%% lld\\n\", %s);\n", tok2);
1012 continue;
1013 }
1014 }
1015 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \" ****\");\n", indent );
1016 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n **** %s\");\n", indent, v1);
1017 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n ****\\n\");\n", indent );
1018 if (!Gateway_Flag) { /* if no gateway defined, output is quasi-immediate */
1019 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n Exiting simulation now\\n\\n\");\n", indent );
1020 (void) fprintf(STDOUT, "%s napa_assert_flag = true;\n", indent );
1021 (void) fprintf(STDOUT, "%s break;\n", indent);
1022 } else { /* if gateway defined, make 1st dump, if requested */
1023 (void) fprintf(STDOUT, "%s (void) fprintf(stderr, \"\\n\");\n", indent );
1024 (void) fprintf(STDOUT, "%s napa_assert_flag = true;\n", indent );
1025 if (Dump_Flag) {
1026 (void) fprintf(STDOUT, "%s napa_dump_states();\n", indent);
1027 }
1028 }
1029 (void) fprintf(STDOUT, "%s }\n", indent);
1030 (void) fprintf(STDOUT, "%s }\n", indent);
1031 (void) fprintf(STDOUT, "#endif\n");
1032 break;
1033 }
1034 (void) build_name("", tok1, RIGHT_VALUE);
1035 (void) fprintf(STDOUT, "%s", tok1);
1036 }
1037 return;
1038 }
1039
1040 /* NULL (no process) */
1041 if (0 == strncmp(Update_List[i].name, "$null$", (size_t) 6)) {
1042 return;
1043 }
1044
1045 /* CONSTANT (no process) */
1046 if (Update_List[i].constant) {
1047 return;
1048 }
1049
1050 /* UPDATE OF REGULAR VARIABLES (accept conditional execution) */
1051 s = Update_List[i].value;
1052 nv = var_id(Update_List[i].name);
1053 if (UNDEFINED == nv) {
1054 print_error_location( "update", Update_List[i].mline, Update_List[i].mfile);
1055 (void) fprintf(STDERR, " <%s> is not declared as a variable\n", Update_List[i].name);
1056 }
1057 (void) strcpy(v2, Update_List[i].name);
1058 (void) build_name("", v2, LEFT_VALUE);
1059 if (2 == Update_List[i].event) {
1060 (void) strcpy(v3, v2);
1061 (void) snprintf(v4, (size_t) (LINLENGTH-1L), "ivar_%s_new", Update_List[i].name);
1062 (void) strcpy(v2, v4);
1063 }
1064 switch (Var_List[nv].type) {
1065 case ANALOG_DATA_TYPE:
1066 (void) fprintf(STDOUT, "%s %s = ", indent, v2);
1067 for (;;) {
1068 s = get_token(s, v2, false);
1069 if (ISEMPTY(v2)) {
1070 (void) fprintf(STDOUT, ";\n");
1071 break;
1072 }
1073 (void) build_name("", v2, RIGHT_VALUE);
1074 (void) fprintf(STDOUT, "%s", v2);
1075 }
1076 break;
1077 case DIGITAL_DATA_TYPE:
1078 (void) fprintf(STDOUT, "%s %s = ", indent, v2);
1079 for (;;) {
1080 s = get_token(s, v2, false);
1081 if (ISEMPTY(v2)) {
1082 (void) fprintf(STDOUT, ";\n");
1083 break;
1084 }
1085 (void) build_name("", v2, RIGHT_VALUE);
1086 (void) fprintf(STDOUT, "%s", v2);
1087 }
1088 if (2 == Update_List[i].event) { /* event with a '(new)' qualifier */
1089 (void) fprintf(STDOUT, "%s %s = (I_TYPE) (%s_old != %s_new);\n", indent, v3, v3, v3);
1090 (void) fprintf(STDOUT, "%s %s_old = %s_new;\n", indent, v3, v3);
1091 }
1093 break;
1094 case STRING_DATA_TYPE: /* NB: string update currently rejected */
1095 (void) fprintf(STDOUT, "%s (void) strcpy(%s, ", indent, v2);
1096 s = get_token(s, tok1, false); /* remove double quotes if any */
1097 (void) fprintf(STDOUT, "\"%s\");\n", tok1); /* add brand new quotes */
1098 break;
1099 }
1100 return;
1101
1102}
long constant_type(char *identifier)
Definition id.c:1130
long get_type(char *identifier)
Definition id.c:1190
EXTERN int Load_Flag
Definition napa.h:865
#define MAXPARMS
Definition napa.h:200
EXTERN LOAD_TYPE Load_List
Definition napa.h:975
#define LEFT_VALUE
Definition napa.h:415
#define MAX(x, y)
Definition napa.h:377
void call_user_functions(const char *indent, const char *type)
Definition pr.c:5570

References ANALOG_DATA_TYPE, build_name(), call_user_functions(), Cmdline_Flag, constant_type(), DIGITAL_DATA_TYPE, Dump_Flag, Gateway_Flag, get_token(), get_type(), ISEMPTY, ISNOTEMPTY, LEFT_VALUE, LENGTH, LINLENGTH, Load_Flag, Load_List, MAX, MAXDEPTH, MAXPARMS, node_id(), Node_List, Num_Nodes, print_error_location(), print_var_width_postprocessing(), print_warning_location(), process_variable_error(), Record_Cell_File_Table, RIGHT_VALUE, STDERR, STDOUT, STRING_DATA_TYPE, STRLENGTH, UNDEFINED, UNKNOWN_TYPE, Update_List, var_id(), and Var_List.

Referenced by build_main_loop_block1().

◆ print_node_width_postprocessing()

void print_node_width_postprocessing ( long nod)

Definition at line 1801 of file bl.c.

1801 {
1802 char v0[LINLENGTH] = {'\0'};
1803 NAPA_DIGITAL_TYPE lltemp1, lltemp2;
1804 (void) strcpy(v0, Node_List[nod].name1);
1805 (void) build_name("", v0, LEFT_VALUE);
1806 if ((0 < Node_List[nod].width) && (DC_KIND != Node_List[nod].kind) && (CONST_KIND != Node_List[nod].kind)) {
1807 lltemp1 = 1LL << (Node_List[nod].width - 1L);
1808 lltemp2 = (2LL*lltemp1) - 1LL;
1809 (void) fprintf(STDOUT, " %s = (%s & ( 0X%llXLL))\n", v0, v0, lltemp1);
1810 (void) fprintf(STDOUT, " %*s ? (%s | (-0X%llXLL))\n", (int) strlen(v0), " ", v0, lltemp1);
1811 (void) fprintf(STDOUT, " %*s : (%s & ( 0X%llXLL));\n", (int) strlen(v0), " ", v0, lltemp2);
1812 } else if (0L > Node_List[nod].width) {
1813 lltemp1 = (1LL << - Node_List[nod].width) - 1LL;
1814 (void) fprintf(STDOUT, " %s &= 0X%llXLL;\n", v0, lltemp1);
1815 }
1816 return;
1817}
#define CONST_KIND
Definition napa.h:246
#define NAPA_DIGITAL_TYPE
Definition napa.h:129

References build_name(), CONST_KIND, DC_KIND, LEFT_VALUE, LINLENGTH, NAPA_DIGITAL_TYPE, Node_List, and STDOUT.

Referenced by build_node().

◆ print_var_width_postprocessing()

void print_var_width_postprocessing ( long var)

Definition at line 1820 of file bl.c.

1820 {
1821 char v0[LINLENGTH] = {'\0'};
1822 NAPA_DIGITAL_TYPE lltemp1, lltemp2;
1823 (void) strcpy(v0, Var_List[var].name1);
1824 (void) build_name("", v0, LEFT_VALUE);
1825 if (0L < Var_List[var].width) {
1826 lltemp1 = 1LL << (Var_List[var].width - 1L);
1827 lltemp2 = (2LL*lltemp1) - 1LL;
1828 (void) fprintf(STDOUT, " %s = (%s & ( 0X%llXLL))\n", v0, v0, lltemp1);
1829 (void) fprintf(STDOUT, " %*s ? (%s | (-0X%llXLL))\n", (int) strlen(v0), " ", v0, lltemp1);
1830 (void) fprintf(STDOUT, " %*s : (%s & ( 0X%llXLL));\n", (int) strlen(v0), " ", v0, lltemp2);
1831 } else if (0L > Var_List[var].width) {
1832 lltemp1 = (1LL << -Var_List[var].width) - 1LL;
1833 (void) fprintf(STDOUT, " %s &= 0X%llXLL;\n", v0, lltemp1);
1834 }
1835 return;
1836}

References build_name(), LEFT_VALUE, LINLENGTH, NAPA_DIGITAL_TYPE, STDOUT, and Var_List.

Referenced by build_input(), and build_update().