Browse Source

Add more error checks for f_logicexp and f_pindly.

pre-master-46
Brian Taylor 3 years ago
committed by Holger Vogt
parent
commit
0a3cdf8e3a
  1. 59
      src/frontend/logicexp.c

59
src/frontend/logicexp.c

@ -1100,7 +1100,7 @@ quick_return:
return new_gen; return new_gen;
} }
static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
static BOOL gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
{ {
/* gen_gates is called with PTABLE gate_tab being the final /* gen_gates is called with PTABLE gate_tab being the final
PTABLE produced by optimize_gen_tab(,..) calls. PTABLE produced by optimize_gen_tab(,..) calls.
@ -1122,11 +1122,11 @@ static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
ds_free(&in_names); ds_free(&in_names);
ds_free(&gate_name); ds_free(&gate_name);
ds_free(&instance); ds_free(&instance);
return;
return FALSE;
} }
t = gate_tab->first; t = gate_tab->first;
lxr = new_lexer(t->line); lxr = new_lexer(t->line);
while (t) {
while (t) { // while t loop
ds_clear(&out_name); ds_clear(&out_name);
ds_clear(&in_names); ds_clear(&in_names);
ds_clear(&gate_name); ds_clear(&gate_name);
@ -1160,25 +1160,25 @@ static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
} }
} else if (val == '~') { } else if (val == '~') {
found_tilde = TRUE; found_tilde = TRUE;
if (tok_count != 3) goto quick_return;
if (tok_count != 3) goto gen_error;
} else if (val == '=') { } else if (val == '=') {
if (tok_count != 2) goto quick_return;
if (tok_count != 2) goto gen_error;
} else if (lex_gate_op(val)) { } else if (lex_gate_op(val)) {
if (gate_op != 0) { if (gate_op != 0) {
if (val != gate_op) goto quick_return;
if (val != gate_op) goto gen_error;
} }
gate_op = val; gate_op = val;
} else { } else {
goto quick_return;
goto gen_error;
} }
val = lexer_scan(lxr); val = lexer_scan(lxr);
} // end while val loop } // end while val loop
if (in_count == 1) { // buffer or inverter if (in_count == 1) { // buffer or inverter
if (gate_op != 0) goto quick_return;
if (gate_op != 0) goto gen_error;
ds_cat_str(&gate_name, lex_gate_name('~', found_tilde)); ds_cat_str(&gate_name, lex_gate_name('~', found_tilde));
} else if (in_count >= 2) { // AND, OR. XOR and inverses } else if (in_count >= 2) { // AND, OR. XOR and inverses
if (gate_op == 0) goto quick_return;
if (gate_op == 0) goto gen_error;
if (use_tmodel_delays) { if (use_tmodel_delays) {
/* This is the case when logicexp has a UGATE /* This is the case when logicexp has a UGATE
timing model (not d0_gate) and no pindly. timing model (not d0_gate) and no pindly.
@ -1200,7 +1200,7 @@ static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
ds_cat_str(&gate_name, lex_gate_name(gate_op, found_tilde)); ds_cat_str(&gate_name, lex_gate_name(gate_op, found_tilde));
} }
} else { } else {
goto quick_return;
goto gen_error;
} }
ds_cat_printf(&instance, "%s ", get_inst_name()); ds_cat_printf(&instance, "%s ", get_inst_name());
if (in_count == 1) { if (in_count == 1) {
@ -1217,10 +1217,10 @@ static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
ds_get_buf(&out_name)); ds_get_buf(&out_name));
ent = member_sym_tab(tail, parser_symbols); ent = member_sym_tab(tail, parser_symbols);
if (!ent) { if (!ent) {
goto quick_return;
goto gen_error;
} }
if ((ent->attribute & SYM_INVERTER) == 0) { if ((ent->attribute & SYM_INVERTER) == 0) {
goto quick_return;
goto gen_error;
} }
ent->ref_count--; ent->ref_count--;
} else { } else {
@ -1241,15 +1241,22 @@ static void gen_gates(PTABLE gate_tab, SYM_TAB parser_symbols)
if (ds_get_length(&instance) > 0) { if (ds_get_length(&instance) > 0) {
u_add_instance(ds_get_buf(&instance)); u_add_instance(ds_get_buf(&instance));
} }
}
} // end while t loop
quick_return:
delete_lexer(lxr); delete_lexer(lxr);
ds_free(&out_name); ds_free(&out_name);
ds_free(&in_names); ds_free(&in_names);
ds_free(&gate_name); ds_free(&gate_name);
ds_free(&instance); ds_free(&instance);
return;
return TRUE;
gen_error:
delete_lexer(lxr);
ds_free(&out_name);
ds_free(&in_names);
ds_free(&gate_name);
ds_free(&instance);
return FALSE;
} }
/* /*
@ -1387,7 +1394,7 @@ static BOOL bparse(char *line, BOOL new_lexer)
lookahead = lex_scan(); // "logic" lookahead = lex_scan(); // "logic"
lookahead = lex_scan(); // ':' lookahead = lex_scan(); // ':'
lookahead = lex_scan(); lookahead = lex_scan();
while (lookahead != '\0') {
while (lookahead != '\0') { // while lookahead loop
unsigned int last_count = 0, curr_count = 0; unsigned int last_count = 0, curr_count = 0;
init_parse_tables(); init_parse_tables();
adepth = max_adepth = 0; adepth = max_adepth = 0;
@ -1411,7 +1418,10 @@ static BOOL bparse(char *line, BOOL new_lexer)
} }
last_count = gen_tab->entry_count; last_count = gen_tab->entry_count;
if (last_count == 1) { if (last_count == 1) {
gen_gates(gen_tab, lx->lexer_sym_tab);
ret_val = gen_gates(gen_tab, lx->lexer_sym_tab);
if (!ret_val) {
printf("ERROR generating gates for logicexp\n");
}
} else if (last_count > 1) { } else if (last_count > 1) {
opt_tab1 = optimize_gen_tab(gen_tab); opt_tab1 = optimize_gen_tab(gen_tab);
if (prit) { if (prit) {
@ -1437,7 +1447,10 @@ static BOOL bparse(char *line, BOOL new_lexer)
curr_count = opt_tab2->entry_count; curr_count = opt_tab2->entry_count;
} }
if (opt_tab2) { if (opt_tab2) {
gen_gates(opt_tab2, lx->lexer_sym_tab);
ret_val = gen_gates(opt_tab2, lx->lexer_sym_tab);
if (!ret_val) {
printf("ERROR generating gates for logicexp\n");
}
delete_parse_table(opt_tab2); delete_parse_table(opt_tab2);
} }
} else { } else {
@ -1450,7 +1463,7 @@ static BOOL bparse(char *line, BOOL new_lexer)
if (!ret_val) { if (!ret_val) {
break; break;
} }
}
} // end while lookahead loop
ds_free(&d_curr_line); ds_free(&d_curr_line);
gen_models(); gen_models();
@ -1579,6 +1592,10 @@ BOOL f_logicexp(char *line)
ret_val = bparse(line, FALSE); ret_val = bparse(line, FALSE);
current_lexer = NULL; current_lexer = NULL;
if (!ret_val) {
printf("ERROR parsing logicexp\n");
printf("ERROR in \"%s\"\n", line);
}
return ret_val; return ret_val;
error_return: error_return:
@ -1720,7 +1737,7 @@ static void print_pindly_table(PINTABLE pint)
static PLINE nth_pindly_entry(PINTABLE pint, int n) static PLINE nth_pindly_entry(PINTABLE pint, int n)
{ {
/* Entries ore from 0 to num_entries - 1 */
/* Entries are from 0 to num_entries - 1 */
PLINE p, next; PLINE p, next;
int count = 0; int count = 0;
if (n < 0) return NULL; if (n < 0) return NULL;
@ -2099,7 +2116,6 @@ static BOOL new_gen_output_models(LEXER lx)
return TRUE; return TRUE;
err_return: err_return:
printf("ERROR in new_gen_output_models\n");
ds_free(&enable_name); ds_free(&enable_name);
ds_free(&last_enable); ds_free(&last_enable);
tfree(pline_arr); tfree(pline_arr);
@ -2195,6 +2211,7 @@ BOOL f_pindly(char *line)
} }
if (!new_gen_output_models(lxr)) { if (!new_gen_output_models(lxr)) {
printf("ERROR generating models for pindly\n");
printf("ERROR in \"%s\"\n", line); printf("ERROR in \"%s\"\n", line);
goto error_return;; goto error_return;;
} }

Loading…
Cancel
Save