57 (void) fprintf(
STDERR,
"\n\nCURRENT LIMITATION OF THE NAPA COMPILER:\n\n" );
58 (void) fprintf(
STDERR,
" max number of nodes = %6ld\n",
MAXNODES );
59 (void) fprintf(
STDERR,
" max number of variables = %6ld\n",
MAXVARS );
61 (void) fprintf(
STDERR,
" max number of arrays of pointers = %6ld\n",
MAXRECORDS );
62 (void) fprintf(
STDERR,
" max number of instantiation of cells = %6ld\n",
MAXINSTANCES );
66 (void) fprintf(
STDERR,
" max number of cell file names recorded = %6ld\n",
MAXFILECELLS );
67 (void) fprintf(
STDERR,
" max number of functions to be recorded = %6ld\n",
MAXFUNCTIONS );
68 (void) fprintf(
STDERR,
" max number of options to be recorded = %6ld\n",
MAXOPTIONS );
69 (void) fprintf(
STDERR,
" max number of user's defined functions = %6ld\n",
MAXUSERTOOLS );
70 (void) fprintf(
STDERR,
" max number of postprocessing functions = %6ld\n",
MAXPOSTS );
71 (void) fprintf(
STDERR,
" max number of inject to nodes = %6ld\n",
MAXINJECTS );
72 (void) fprintf(
STDERR,
" max number of IO streams = %6ld\n",
MAXIOS );
73 (void) fprintf(
STDERR,
" max number of open files (simulation) = %6ld\n",
MAXFILES );
75 (void) fprintf(
STDERR,
" max number of directives = %6ld\n",
MAXDIRS );
76 (void) fprintf(
STDERR,
" max number of cell parameters = %6ld\n",
MAXPARMS );
77 (void) fprintf(
STDERR,
" max number of nodes stuck to a value = %6ld\n",
MAXSTUCKS );
78 (void) fprintf(
STDERR,
" max number of command line parameters = %6ld\n",
MAXCMDLINES );
81 (void) fprintf(
STDERR,
" max number of simulation segments = %6ld\n",
MAXSEGMENTS );
82 (void) fprintf(
STDERR,
" max number of exported variables = %6ld\n\n",
MAXEXPORTS );
83 (void) fprintf(
STDERR,
" max depth for cell hierarchy = %6ld\n\n",
MAXDEPTH );
84 (void) fprintf(
STDERR,
" max length of strings and tokens = %6ld\n",
STRLENGTH );
85 (void) fprintf(
STDERR,
" max length of instructions = %6ld\n\n",
LINLENGTH );
86 (void) fprintf(
STDERR,
"These limitations can be changed by a new compilation of the\n" );
87 (void) fprintf(
STDERR,
"sources after reworking the limits in source file 'napa.h'. \n" );
88 (void) fprintf(
STDERR,
"Please contact the author, yves.leduc.be@gmail.com \n\n" );
100char *
get_a_line(
char *buf,
unsigned long *nl, FILE *fp,
unsigned long *mlin,
const unsigned long *mfil) {
101 static char tok[
LINLENGTH + 1L] = {
'\0'};
102 static char *p = (
char*) NULL;
104 int continue_on_next_line;
105 (void) strcpy(buf,
"");
109 if ((
char*) NULL == p) {
113 (void) fprintf(
STDERR,
" end of file is detected although a new line was expected\n");
121 if ((1UL < *nl) && (0L == len)) {
124 (void) fprintf(
STDERR,
" 'all blank' or 'all comment' lines are not allowed inside an instruction\n");
128 continue_on_next_line = (int) ((
'.' == tok[len-3L]) && (
'.' == tok[len-2L]) && (
'.' == tok[len-1L]));
131 continue_on_next_line =
false;
133 if (continue_on_next_line) {
141 (void) fprintf(
STDERR,
" the length of instruction exceeds maximum length (%ld)\n",
LINLENGTH);
146 (void) strcat(buf,
" ");
148 (void) strcat(buf, tok);
149 }
while (continue_on_next_line);
157long f2printf(FILE *fp1, FILE *fp2,
char *fmt, ...) {
161 if ((FILE*) NULL != fp1) {
163 n1 = vfprintf(fp1, fmt, argp);
169 if ((FILE*) NULL != fp2) {
171 n2 = vfprintf(fp2, fmt, argp);
190 (void) fprintf(
STDERR,
" Registering 'last_message()' did not succeed\n");
325 char *str = (
char*) NULL;
330 (void) strcpy(tok,
Var_List[i].value);
332 if (0 != strcmp(tok,
Var_List[i].value)) {
339 if (0 == strcmp(tok,
"when")) {
341 (void) fprintf(
STDERR,
" the definition of a variable cannot be conditioned by an event\n");
380 long i, a, sz, nr, nc;
382 char *s = (
char*) NULL;
383 char *t1 = (
char*) NULL;
384 char *t2 = (
char*) NULL;
385 char sgn[2] = {
'\0'};
396 (void) strcpy(buf,
"");
409 (void) strcat(buf, sgn);
410 (void) strcat(buf, tok);
411 (void) strcat(buf,
" ");
415 (void) strcat(buf,
" ");
448 (void) strcpy(buf1,
"");
449 (void) strcpy(buf2,
"");
455 (void) strcpy(tok, sgn);
456 (void) strcat(tok, tok1);
461 (void) strcpy(tok1, tok);
462 (void) strcpy(tok2, tok);
463 t1 = strstr(tok1,
"::");
464 t2 = strstr(tok2,
"::");
465 if ((
char*) NULL != t1) {
467 nflag = nflag &&
true;
468 (void) strcpy(tok1, t1+2);
470 (void) strcat(buf1, tok1);
471 (void) strcat(buf1,
" " );
473 (void) strcat(buf2, tok2);
474 (void) strcat(buf2,
" " );
477 pflag = pflag &&
true;
479 (void) strcat(buf1, tok1);
480 (void) strcat(buf1,
" " );
481 (void) snprintf(tok2, (
size_t) (
STRLENGTH-1L),
"%d ", n);
482 (void) strcat(buf2, tok2);
486 if (!(pflag || nflag)) {
488 (void) fprintf(
STDERR,
" inconsistant parameters passing: by position or by name?\n");
506 char *s = (
char*) NULL;
507 char sgn[2] = {
'\0'};
563 char *s = (
char*) NULL;
564 char *s1 = (
char*) NULL;
565 char sgn[2] = {
'\0'};
674 char *str = (
char*) NULL;
677 char sgn[2] = {
'\0'};
693 (void) fprintf(
STDERR,
" export node or variable <%s> is not a NAPA identifier\n", tok1);
700 (void) fprintf(
STDERR,
" export node or variable <%s> cannot be signed\n", tok1);
737 (void) fprintf(
STDERR,
" a string variable cannot be exported <%s>", tok1);
780 char *str = (
char*) NULL;
781 char *nam = (
char*) NULL;
782 char *s = (
char*) NULL;
787 if ((0 == strncmp(nam,
"$call$", (
size_t) 6))
788 || (0 == strncmp(nam,
"$null$", (
size_t) 6))
789 || (0 == strncmp(nam,
"$restart$", (
size_t) 9))) {
793 if ((
UNDEFINED ==
var_id(nam)) && (0 != strncmp(nam,
"$assert$", (
size_t) 8))) {
795 (void) fprintf(
STDERR,
" variable to be updated <%s> does not exist!\n", nam );
801 (void) fprintf(
STDERR,
" string <%s>: a string cannot be updated!", nam );
808 if (0 == strcmp(tok,
"when")) {
811 (void) fprintf(
STDERR,
" an event cannot be conditioned\n");
833 (void) fprintf(
STDERR,
" no update expansion, as variable to be updated does not exist\n");
846 char *str = (
char*) NULL;
847 char *s = (
char*) NULL;
850 for (out = 0L; out <
Num_IOs; out++) {
855 if (0 == strcmp(tok,
"when")) {
857 (void) fprintf(
STDERR,
" this instruction cannot be conditioned by an event\n");
868 if (0 == strcmp(tok,
"when")) {
888 char *str = (
char*) NULL;
894 if (0 == strcmp(str,
"false")) {
898 if ((0 == strcmp(str,
"true")) ||
ISEMPTY(str)) {
903 if (
ISEMPTY(tok) || (0 != strcmp(tok,
"when"))) {
905 (void) fprintf(
STDERR,
" this instruction must be conditioned by an event\n");
918 char *s = (
char*) NULL;
919 char sgn[2] = {
'\0'};
920 char brc[3] = {
'\0'};
931 if ((0 == strcmp(brc,
"()")) && (0 == strcmp(tok,
"new"))) {
938 (void) fprintf(
STDERR,
"<%s> cannot be a node but an event\n", tok);
942 if ((
UNDEFINED == in) && (isalpha((
int) *tok))) {
944 (void) fprintf(
STDERR,
"<%s>? Only events and operators on boolean are allowed in a condition\n", tok);
949 (void) fprintf(
STDERR,
" <%s> cannot be a variable but an event\n", tok);
958void build_condition(
char *cond,
const unsigned long *mlin,
const unsigned long *mfil) {
960 char sgn[2] = {
'\0'};
964 char *str = (
char*) NULL;
968 (void) fprintf(
STDERR,
" syntax error in condition <%s>, event is missing\n", str);
971 (void) fprintf(
STDOUT,
" if ( ");
976 (void) strcpy(buf1, buf2);
977 if ((0 == strcmp(
"&&", tok)) || (0 == strcmp(
"||", tok))) {
978 (void) snprintf(buf2, (
size_t) (
LINLENGTH-1L),
"%s %s ", buf1, tok);
980 (void) snprintf(buf2, (
size_t) (
LINLENGTH-1L),
"%s%s", buf1, tok);
984 (void) strcpy(buf1, buf2);
986 (void) snprintf(buf2, (
size_t) (
LINLENGTH-1L),
"%s%s", buf1, tok);
989 (void) fprintf(
STDOUT,
"%s", buf2);
990 (void) fprintf(
STDOUT,
" ) {\n");
1002 char sgn[2] = {
'\0'};
1004 char *str = (
char*) NULL;
1005 for (out = 0L; out <
Num_Nodes; out++) {
1031 numerator[0L] = 1.0;
1032 denominator[0L] = 1.0;
1037 numerator[nseg] = numerator[nseg-1L] *
Segment_List[nseg].rate;
1038 denominator[nseg] = denominator[nseg-1L];
1041 denominator[nseg] = 1.0;
1046 numerator[nseg] = numerator[nseg-1L];
1047 denominator[nseg] = denominator[nseg-1L] *
Segment_List[nseg].rate;
1049 numerator[nseg] = 1.0;
1054 numerator[nseg] = 1.0;
1055 denominator[nseg] = 1.0;
1058 numerator[nseg] = numerator[nseg-1L];
1059 denominator[nseg] = denominator[nseg-1L];
1061 gcd =
GCD(numerator[nseg], denominator[nseg]);
1062 numerator[nseg] /= gcd;
1063 denominator[nseg] /= gcd;
1071 lcm =
LCM(lcm, numerator[nseg]);
1136 int ok, always, first, atleastone;
1141 char sgn[2] = {
'\0'};
1146 char *str = (
char*) NULL;
1147 for (out = 0L; out <
Num_IOs; out++) {
1158 (void) strcpy(lst,
IO_List[out].element);
1184 if (seglist[seg] != seg) {
1186 (void) snprintf(cnd2, (
size_t) (
LINLENGTH-1L),
"%s_%ld",
"napa_segment_run", seg);
1189 (void) strcpy(cnd1, cnd2);
1190 (void) snprintf(cnd2, (
size_t) (
LINLENGTH-1L),
"%s || %s_%ld", cnd1,
"napa_segment_run", seg);
1198 (void) strcpy(lst,
IO_List[out].element);
1221 if (seglist[seg] != seg) {
1223 (void) snprintf(cnd2, (
size_t) (
LINLENGTH-1L),
"%s_%ld",
"napa_segment_run", seg);
1226 (void) strcpy(cnd1, cnd2);
1227 (void) snprintf(cnd2, (
size_t) (
LINLENGTH-1L),
"%s || %s_%ld", cnd1,
"napa_segment_run", seg);
1233 (void) strcpy(cnd2,
" 0LL == ABS_LOOP_INDEX ");
1237 (void) strcpy(cnd1,
"true");
1239 (void) strcpy(cnd1, cnd2);
1243 (void) snprintf(cnd1, (
size_t) (
LINLENGTH-1L),
"%s",
IO_List[out].condition);
1245 (void) snprintf(cnd1, (
size_t) (
LINLENGTH-1L),
"(%s) && %s", cnd2,
IO_List[out].condition);
1275 long nseg, nseg1, nseg2;
1279 newseg[nseg] = nseg;
1288 for (nseg1 = 0L; nseg1 < nseg2; nseg1++) {
1295 newseg[nseg2] = nseg1;
1303 for (n = 0L; n <
Num_IOs; n++) {
1331 char *s = (
char*) NULL;
1335 (void) snprintf(tok, (
size_t) (
STRLENGTH-1L),
"%s", s);
1340 (void) fprintf(
STDERR,
" <%s> cannot be an alias of node <%s>,",
Alias_List[i].name, tok );
1341 (void) fprintf(
STDERR,
" as <%s> is already an alias\n",
Node_List[
id].name1 );
1352 (void) fprintf(
STDERR,
" <%s> cannot be an alias of variable <%s>,",
Alias_List[i].name, tok);
1353 (void) fprintf(
STDERR,
" as <%s> is already an alias\n",
Var_List[
id].name1 );
1361 (void) fprintf(
STDERR,
" no node and no variable correspond to target <%s> of alias <%s>\n", tok,
Alias_List[i].name);
1378double GCD(
double a,
double b) {
1385 return GCD(b, fmod(a, b));
1392double LCM(
double n1,
double n2) {
1393 return ((n1 /
GCD(n1, n2)) * n2);
1404 return ((0L != n2) ?
true :
false);
1411void cat_file(
const char *fnam,
const char *type,
long command,
const unsigned long *mlin,
const unsigned long *mfil) {
1412 FILE *fp = (FILE*) NULL;
1419 if ((FILE*) NULL == (fp = fopen(fnam,
"r"))) {
1421 (void) fprintf(
STDERR,
" OUCH!- (%s) can't find or access file <\"%s\">\n", type, fnam);
1425 while ((
char*) NULL != (fgets(lin1,
LINLENGTH, fp))) {
1428 for (i = 0L; i <
LENGTH(lin1); i++) {
1429 if ((flag1) && (
'/' == lin1[i]) && (
'*' == lin1[i+1L])) {
1438 if ((!flag1) && (
'*' == lin1[i-1L]) && (
'/' == lin1[i])) {
1445 (void) strcpy(lin1, lin2);
1448 for (i = 0L; i <
LENGTH(lin1); i++) {
1449 if (!isspace((
int) lin1[i])) {
1454 (void) fprintf(
STDOUT,
"%s", lin1);
1458 if (EOF == fclose(fp)) {
1460 (void) fprintf(
STDERR,
" OUCH!- (%s) can't close file <\"%s\"> opened for verification\n", type, fnam);
1478 (void) fprintf(
STDERR,
"\n");
1499 if (0 == strcmp(type,
"")) {
1500 (void) strcpy(tok,
"");
1502 (void) snprintf(tok, (
size_t) (
STRLENGTH-1L),
" (%s)", type);
1504 (void) fprintf(
STDERR,
"\nNAPA %s: %s\n", kind, tok);
1512 if (((
unsigned long*) NULL == mlin) || ((
unsigned long*) NULL == mfil)) {
1515 if (0UL == mlin[0]) {
1518 (void) fprintf(
STDERR,
" -> at line %3lu of main netlist\n", mlin[0]);
1520 if (0UL == mlin[d]) {
1521 (void) fprintf(
STDERR,
" ");
1538 short int word = (
short int) 0X0001LL;
1539 char *
byte = (
char*) &word;
1554 (void) fprintf(
STDERR,
"\n ****\n" );
1555 (void) fprintf(
STDERR,
" **** NAPA Compilation Error(s)\n");
1556 (void) fprintf(
STDERR,
" ****\n\n\n");
void check_record_usage(void)
void print_info_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
void print_location(const unsigned long *mlin, const unsigned long *mfil)
void cat_file(const char *fnam, const char *type, long command, const unsigned long *mlin, const unsigned long *mfil)
double LCM(double n1, double n2)
void process_error_if_any(void)
void compact_segment(void)
void expand_string_variables(void)
void build_condition(char *cond, const unsigned long *mlin, const unsigned long *mfil)
void print_warning_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
long process_condition(char *str, const unsigned long *mlin, const unsigned long *mfil)
void determine_segment_processing_rate(void)
void complete_directives(void)
void print_error_location(const char *type, const unsigned long *mlin, const unsigned long *mfil)
void print_problem_location(const char *type, const unsigned long *mlin, const unsigned long *mfil, const char *kind)
long f2printf(FILE *fp1, FILE *fp2, char *fmt,...)
void check_array_usage(void)
void build_to_be_delayed_node_list(void)
void expand_records(void)
int test_endianness(void)
void determine_output_segment_rate(void)
void check_directive_usage(void)
void expand_update_definitions(void)
double GCD(double a, double b)
void expand_dump_definitions(void)
char * get_a_line(char *buf, unsigned long *nl, FILE *fp, unsigned long *mlin, const unsigned long *mfil)
void collect_export_definitions(void)
void expand_IO_definitions(void)
void process_aliases(void)
void default_control_variables(void)
void determine_simulation_rate(void)
long get_type(char *identifier)
long update_id(const char *identifier, long num)
void strcpy_alloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
long array_id(const char *identifier)
long directive_id(const char *identifier)
void increment_directive_number(const char *kind)
long array_name_id(const char *identifier)
long node_id(const char *identifier)
long var_id(const char *identifier)
void increment_segment_number(const char *kind)
long record_id(const char *identifier)
void strcpy_realloc(char **dest, const char *sour, const unsigned long *mlin, const unsigned long *mfil)
void process_node_error(const char *tok1)
void process_variable_error(const char *tok1)
EXTERN int Interpolate_Flag
#define DECIMATE_SEGMENT_TYPE
#define DROP_SEGMENT_TYPE
EXTERN RANDOMSEED_TYPE Seed_List
EXTERN VAR_TYPE Var_List[2047L]
EXTERN char I_String_Format[2047L]
EXTERN int Interlude_Flag3
EXTERN RECORD_TYPE Record_List[127L]
EXTERN char Condition_Assign[16383L]
EXTERN long Num_Functions
EXTERN ARRAY_TYPE Array_List[63L]
EXTERN char V_Format[2047L]
EXTERN char E_Format[2047L]
EXTERN int Directive_Flag
EXTERN char S_Format[2047L]
EXTERN char R_Format[2047L]
EXTERN char Last_Postprocess[2047L]
EXTERN POST_TYPE Post_List[63L]
EXTERN double NAPA_Compile_Start
EXTERN NODE_TYPE Node_List[4095L]
EXTERN int Hierarchy_Flag
EXTERN char S_String_Format[2047L]
EXTERN long Num_UserTools
EXTERN USERTOOL_TYPE UserTool_List[511L]
EXTERN EXPORT_TYPE Export_List[31L]
EXTERN SAMPLING_TYPE Sampling_List
EXTERN int Tool_Index_Flag
EXTERN char R_String_Format[2047L]
EXTERN char Export0_Head_String[16383L]
EXTERN char X_String_Format[2047L]
EXTERN char * Record_Cell_File_Table[511L]
EXTERN ALIAS_TYPE Alias_List[127L]
EXTERN DIRECTIVE_TYPE Directive_List[255L]
#define INTERPOLATE_SEGMENT_TYPE
EXTERN char X_Format[2047L]
EXTERN INTERLUDE_TYPE Interlude_List
EXTERN long Num_Directives
EXTERN int Interlude_Flag1
EXTERN char Comment_String[63L][16383L]
#define MAXDECLARECOMMONS
EXTERN char Export0_List_String[16383L]
EXTERN double NAPA_Compile_Stop
EXTERN long Num_FileCells
EXTERN char Export1_List_String[16383L]
#define NOMINAL_SEGMENT_TYPE
EXTERN char I_Format[2047L]
EXTERN double Simulation_Rate
EXTERN GATEWAY_TYPE Gateway_List
EXTERN long Delay_Input[4095L]
EXTERN long Num_Instances
EXTERN CMDLINE_TYPE Cmdline_List[63L]
EXTERN char Title_String[2 *2047L]
EXTERN int Terminate_Flag
EXTERN SEGMENT_TYPE Segment_List[127L]
EXTERN int Multdelay_Flag
#define NAPA_DIGITAL_TYPE
EXTERN int Antithetic_Flag
EXTERN char Cmdline_String[2047L]
EXTERN char Export1_Head_String[16383L]
EXTERN long Num_Generators
EXTERN DUMP_TYPE Dump_List
EXTERN char Short_Title_String[2 *2047L]
EXTERN char Last_Instruction[2047L]
EXTERN IO_TYPE IO_List[63L]
EXTERN long Num_Declare_Commons
#define DIGITAL_DATA_TYPE
EXTERN int Interlude_Flag2
EXTERN UPDATE_TYPE Update_List[2047L]
void print_error_banner_and_exit(void)
char * get_token(char *str, char *tok, long keep_quotes)
void clean_line(char *str)
char * build_name(const char *sgn, char *tok, long lr_type)
void clean_parentheses(char *tok)
void mark_directives(void)
void expand_iterative_identifiers(char *str, unsigned long *mlin, const unsigned long *mfil)
int is_an_identifier(const char *tok)
char * get_token_between_braces(char *str, char *brc, char *tok)
void expand_indirections(char *str)
char * get_sign_and_token(char *str, char *sgn, char *tok)
void C_syntax_checker(char *str, const unsigned long *mlin, const unsigned long *mfil)