Return errors from f_logicexp and f_pindly without calling exit.
This commit is contained in:
parent
a340515e77
commit
d35491fa8f
|
|
@ -606,9 +606,9 @@ static void ptable_print(PTABLE pt)
|
||||||
static char *get_inst_name(void);
|
static char *get_inst_name(void);
|
||||||
static char *get_inverter_output_name(char *input);
|
static char *get_inverter_output_name(char *input);
|
||||||
static void aerror(char *s);
|
static void aerror(char *s);
|
||||||
static void amatch(int t);
|
static BOOL amatch(int t);
|
||||||
static void bexpr(void);
|
static BOOL bexpr(void);
|
||||||
static void bfactor(void);
|
static BOOL bfactor(void);
|
||||||
static BOOL bparse(char *line, BOOL new_lexer);
|
static BOOL bparse(char *line, BOOL new_lexer);
|
||||||
|
|
||||||
static int lookahead = 0;
|
static int lookahead = 0;
|
||||||
|
|
@ -618,6 +618,13 @@ static DSTRING d_curr_line;
|
||||||
static int number_of_instances = 0;
|
static int number_of_instances = 0;
|
||||||
static BOOL use_tmodel_delays = FALSE;
|
static BOOL use_tmodel_delays = FALSE;
|
||||||
|
|
||||||
|
static void cleanup_parser(void)
|
||||||
|
{
|
||||||
|
delete_lexer(parse_lexer);
|
||||||
|
parse_lexer = NULL;
|
||||||
|
delete_parse_gen_tables();
|
||||||
|
}
|
||||||
|
|
||||||
static char *get_inst_name(void)
|
static char *get_inst_name(void)
|
||||||
{
|
{
|
||||||
static char name[64];
|
static char name[64];
|
||||||
|
|
@ -714,7 +721,7 @@ static void aerror(char *s)
|
||||||
{
|
{
|
||||||
LEXER lx = parse_lexer;
|
LEXER lx = parse_lexer;
|
||||||
printf("%s [%s]\n", s, lx->lexer_line + lx->lexer_pos);
|
printf("%s [%s]\n", s, lx->lexer_line + lx->lexer_pos);
|
||||||
exit(1);
|
cleanup_parser();
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_temp_name(void)
|
char *get_temp_name(void)
|
||||||
|
|
@ -726,19 +733,28 @@ char *get_temp_name(void)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void amatch(int t)
|
static BOOL amatch(int t)
|
||||||
{
|
{
|
||||||
LEXER lx = parse_lexer;
|
LEXER lx = parse_lexer;
|
||||||
if (lookahead == t) {
|
if (lookahead == t) {
|
||||||
lookahead = lex_scan();
|
lookahead = lex_scan();
|
||||||
} else {
|
} else {
|
||||||
printf("t = '%c' [%d] lookahead = '%c' [%d] lexer_buf %s\n",
|
printf("expect = '%c' [%d] lookahead = '%c' [%d] lexer_buf %s\n",
|
||||||
t, t, lookahead, lookahead, lx->lexer_buf);
|
t, t, lookahead, lookahead, lx->lexer_buf);
|
||||||
aerror("amatch: syntax error");
|
aerror("amatch: syntax error");
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bfactor(void)
|
#define AMATCH_BFACTOR(n) \
|
||||||
|
{ \
|
||||||
|
if (!amatch((n))) { \
|
||||||
|
return FALSE; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL bfactor(void)
|
||||||
{
|
{
|
||||||
/* factor is : ['~'] rest
|
/* factor is : ['~'] rest
|
||||||
where rest is: input_name_id | '(' expr ')' | error
|
where rest is: input_name_id | '(' expr ')' | error
|
||||||
|
|
@ -789,7 +805,10 @@ static void bfactor(void)
|
||||||
ds_clear(&d_curr_line);
|
ds_clear(&d_curr_line);
|
||||||
|
|
||||||
lookahead = lex_scan();
|
lookahead = lex_scan();
|
||||||
bexpr();
|
if (!bexpr()) {
|
||||||
|
cleanup_parser();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
||||||
ds_clear(&d_curr_line);
|
ds_clear(&d_curr_line);
|
||||||
|
|
@ -799,44 +818,62 @@ static void bfactor(void)
|
||||||
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
||||||
ds_clear(&d_curr_line);
|
ds_clear(&d_curr_line);
|
||||||
|
|
||||||
amatch(')');
|
|
||||||
ds_free(&tmpnam);
|
ds_free(&tmpnam);
|
||||||
|
AMATCH_BFACTOR(')');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
aerror("bfactor: syntax error");
|
aerror("bfactor: syntax error");
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
adepth--;
|
adepth--;
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bexpr(void)
|
static BOOL bexpr(void)
|
||||||
{
|
{
|
||||||
/* expr is: factor { gate_op factor }+
|
/* expr is: factor { gate_op factor }+
|
||||||
where {}+ means 0 or more times.
|
where {}+ means 0 or more times.
|
||||||
*/
|
*/
|
||||||
bfactor();
|
if (!bfactor()) {
|
||||||
|
cleanup_parser();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
while (lex_gate_op(lookahead)) {
|
while (lex_gate_op(lookahead)) {
|
||||||
ds_cat_printf(&d_curr_line, "%c ", lookahead);
|
ds_cat_printf(&d_curr_line, "%c ", lookahead);
|
||||||
|
|
||||||
lookahead = lex_scan();
|
lookahead = lex_scan();
|
||||||
bfactor();
|
if (!bfactor()) {
|
||||||
|
cleanup_parser();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bstmt(void)
|
#define AMATCH_BSTMT(n) \
|
||||||
|
{ \
|
||||||
|
if (!amatch((n))) { \
|
||||||
|
ds_free(&tname); ds_free(&assign); \
|
||||||
|
return FALSE; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL bstmt(void)
|
||||||
{
|
{
|
||||||
/* A stmt is: output_name_id = '{' expr '}' */
|
/* A stmt is: output_name_id = '{' expr '}' */
|
||||||
BOOL verbose = PRINT_ALL;
|
BOOL verbose = PRINT_ALL;
|
||||||
int end_pos = 0, start_pos = 0;
|
int end_pos = 0, start_pos = 0;
|
||||||
SYM_TAB entry = NULL;
|
SYM_TAB entry = NULL;
|
||||||
LEXER lx = parse_lexer;
|
|
||||||
DS_CREATE(tname, 64);
|
DS_CREATE(tname, 64);
|
||||||
DS_CREATE(assign, LEX_BUF_SZ);
|
DS_CREATE(assign, LEX_BUF_SZ);
|
||||||
|
|
||||||
if (lookahead == LEX_ID) {
|
if (lookahead == LEX_ID) {
|
||||||
entry = add_sym_tab_entry(lx->lexer_buf, SYM_ID, &lx->lexer_sym_tab);
|
entry = add_sym_tab_entry(parse_lexer->lexer_buf, SYM_ID,
|
||||||
|
&parse_lexer->lexer_sym_tab);
|
||||||
} else {
|
} else {
|
||||||
aerror("bstmt: syntax error");
|
aerror("bstmt: syntax error");
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
adepth++;
|
adepth++;
|
||||||
|
|
@ -844,18 +881,18 @@ static void bstmt(void)
|
||||||
max_adepth = adepth;
|
max_adepth = adepth;
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
start_pos = lx->lexer_pos;
|
start_pos = parse_lexer->lexer_pos;
|
||||||
printf("* %s", lx->lexer_buf);
|
printf("* %s", parse_lexer->lexer_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
amatch(LEX_ID);
|
AMATCH_BSTMT(LEX_ID);
|
||||||
amatch('=');
|
AMATCH_BSTMT('=');
|
||||||
|
|
||||||
ds_clear(&assign);
|
ds_clear(&assign);
|
||||||
ds_cat_printf(&assign, "%s =", entry->name);
|
ds_cat_printf(&assign, "%s =", entry->name);
|
||||||
(void) ptab_add_line(ds_get_buf(&assign), TRUE);
|
(void) ptab_add_line(ds_get_buf(&assign), TRUE);
|
||||||
|
|
||||||
amatch('{');
|
AMATCH_BSTMT('{');
|
||||||
|
|
||||||
ds_clear(&tname);
|
ds_clear(&tname);
|
||||||
ds_cat_str(&tname, get_temp_name());
|
ds_cat_str(&tname, get_temp_name());
|
||||||
|
|
@ -863,7 +900,12 @@ static void bstmt(void)
|
||||||
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
||||||
ds_clear(&d_curr_line);
|
ds_clear(&d_curr_line);
|
||||||
|
|
||||||
bexpr();
|
if (!bexpr()) {
|
||||||
|
cleanup_parser();
|
||||||
|
ds_free(&assign);
|
||||||
|
ds_free(&tname);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (ds_get_length(&d_curr_line) > 0) {
|
if (ds_get_length(&d_curr_line) > 0) {
|
||||||
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
(void) ptab_add_line(ds_get_buf(&d_curr_line), TRUE);
|
||||||
|
|
@ -875,19 +917,19 @@ static void bstmt(void)
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
DS_CREATE(stmt_str, 128);
|
DS_CREATE(stmt_str, 128);
|
||||||
end_pos = lx->lexer_pos;
|
end_pos = parse_lexer->lexer_pos;
|
||||||
ds_cat_mem(&stmt_str, &lx->lexer_line[start_pos],
|
ds_cat_mem(&stmt_str, &parse_lexer->lexer_line[start_pos],
|
||||||
(size_t) (end_pos - start_pos));
|
(size_t) (end_pos - start_pos));
|
||||||
printf("%s\n", ds_get_buf(&stmt_str));
|
printf("%s\n", ds_get_buf(&stmt_str));
|
||||||
ds_free(&stmt_str);
|
ds_free(&stmt_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
amatch('}');
|
AMATCH_BSTMT('}');
|
||||||
|
|
||||||
ds_free(&assign);
|
ds_free(&assign);
|
||||||
ds_free(&tname);
|
ds_free(&tname);
|
||||||
adepth--;
|
adepth--;
|
||||||
return;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PTABLE optimize_gen_tab(PTABLE pt)
|
static PTABLE optimize_gen_tab(PTABLE pt)
|
||||||
|
|
@ -1374,7 +1416,6 @@ static BOOL bparse(char *line, BOOL new_lexer)
|
||||||
{
|
{
|
||||||
int stmt_num = 0;
|
int stmt_num = 0;
|
||||||
BOOL ret_val = TRUE, prit = PRINT_ALL;
|
BOOL ret_val = TRUE, prit = PRINT_ALL;
|
||||||
LEXER lx;
|
|
||||||
PTABLE opt_tab1 = NULL, opt_tab2 = NULL;
|
PTABLE opt_tab1 = NULL, opt_tab2 = NULL;
|
||||||
DS_CREATE(stmt, LEX_BUF_SZ);
|
DS_CREATE(stmt, LEX_BUF_SZ);
|
||||||
char *seed_buf;
|
char *seed_buf;
|
||||||
|
|
@ -1389,7 +1430,6 @@ static BOOL bparse(char *line, BOOL new_lexer)
|
||||||
if (new_lexer)
|
if (new_lexer)
|
||||||
lex_init(line);
|
lex_init(line);
|
||||||
if (!parse_lexer) return FALSE;
|
if (!parse_lexer) return FALSE;
|
||||||
lx = parse_lexer;
|
|
||||||
lookahead = lex_set_start("logic:");
|
lookahead = lex_set_start("logic:");
|
||||||
lookahead = lex_scan(); // "logic"
|
lookahead = lex_scan(); // "logic"
|
||||||
lookahead = lex_scan(); // ':'
|
lookahead = lex_scan(); // ':'
|
||||||
|
|
@ -1400,8 +1440,12 @@ static BOOL bparse(char *line, BOOL new_lexer)
|
||||||
adepth = max_adepth = 0;
|
adepth = max_adepth = 0;
|
||||||
stmt_num++;
|
stmt_num++;
|
||||||
ds_clear(&stmt);
|
ds_clear(&stmt);
|
||||||
ds_cat_str(&stmt, lx->lexer_buf);
|
ds_cat_str(&stmt, parse_lexer->lexer_buf);
|
||||||
bstmt();
|
if (!bstmt()) {
|
||||||
|
cleanup_parser();
|
||||||
|
ret_val= FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (prit) {
|
if (prit) {
|
||||||
printf("START parse_tab\n");
|
printf("START parse_tab\n");
|
||||||
|
|
@ -1418,7 +1462,7 @@ 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) {
|
||||||
ret_val = gen_gates(gen_tab, lx->lexer_sym_tab);
|
ret_val = gen_gates(gen_tab, parse_lexer->lexer_sym_tab);
|
||||||
if (!ret_val) {
|
if (!ret_val) {
|
||||||
printf("ERROR generating gates for logicexp\n");
|
printf("ERROR generating gates for logicexp\n");
|
||||||
}
|
}
|
||||||
|
|
@ -1447,9 +1491,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) {
|
||||||
ret_val = gen_gates(opt_tab2, lx->lexer_sym_tab);
|
ret_val = gen_gates(opt_tab2, parse_lexer->lexer_sym_tab);
|
||||||
if (!ret_val) {
|
if (!ret_val) {
|
||||||
printf("ERROR generating gates for logicexp\n");
|
printf(
|
||||||
|
"ERROR generating gates for logicexp\n");
|
||||||
}
|
}
|
||||||
delete_parse_table(opt_tab2);
|
delete_parse_table(opt_tab2);
|
||||||
}
|
}
|
||||||
|
|
@ -1466,9 +1511,10 @@ static BOOL bparse(char *line, BOOL new_lexer)
|
||||||
} // end while lookahead loop
|
} // end while lookahead loop
|
||||||
|
|
||||||
ds_free(&d_curr_line);
|
ds_free(&d_curr_line);
|
||||||
gen_models();
|
if (ret_val)
|
||||||
|
gen_models();
|
||||||
ds_free(&stmt);
|
ds_free(&stmt);
|
||||||
delete_lexer(lx);
|
cleanup_parser();
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
/* End of logicexp parser */
|
/* End of logicexp parser */
|
||||||
|
|
@ -1487,7 +1533,8 @@ static BOOL expect_token(
|
||||||
{
|
{
|
||||||
if (tok != expected_tok) {
|
if (tok != expected_tok) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
printf("ERROR expect_token failed tok %d expected_tok %d loc %d\n",
|
printf(
|
||||||
|
"ERROR expect_token failed tok %d expected_tok %d loc %d\n",
|
||||||
tok, expected_tok, loc);
|
tok, expected_tok, loc);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -1595,6 +1642,7 @@ BOOL f_logicexp(char *line)
|
||||||
if (!ret_val) {
|
if (!ret_val) {
|
||||||
printf("ERROR parsing logicexp\n");
|
printf("ERROR parsing logicexp\n");
|
||||||
printf("ERROR in \"%s\"\n", line);
|
printf("ERROR in \"%s\"\n", line);
|
||||||
|
cleanup_parser();
|
||||||
}
|
}
|
||||||
return ret_val;
|
return ret_val;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3612,16 +3612,25 @@ BOOL u_process_instance(char *nline)
|
||||||
char *p1, *itype, *xspice;
|
char *p1, *itype, *xspice;
|
||||||
struct instance_hdr *hdr = create_instance_header(nline);
|
struct instance_hdr *hdr = create_instance_header(nline);
|
||||||
Xlatorp xp = NULL;
|
Xlatorp xp = NULL;
|
||||||
|
BOOL behav_ret = TRUE;
|
||||||
|
|
||||||
itype = hdr->instance_type;
|
itype = hdr->instance_type;
|
||||||
xspice = find_xspice_for_delay(itype);
|
xspice = find_xspice_for_delay(itype);
|
||||||
if (!xspice) {
|
if (!xspice) {
|
||||||
if (eq(itype, "logicexp")) {
|
if (eq(itype, "logicexp")) {
|
||||||
delete_instance_hdr(hdr);
|
delete_instance_hdr(hdr);
|
||||||
return f_logicexp(nline);
|
behav_ret = f_logicexp(nline);
|
||||||
|
if (!behav_ret && current_subckt && ps_udevice_msgs >= 1) {
|
||||||
|
printf("ERROR in %s\n", current_subckt);
|
||||||
|
}
|
||||||
|
return behav_ret;
|
||||||
} else if (eq(itype, "pindly")) {
|
} else if (eq(itype, "pindly")) {
|
||||||
delete_instance_hdr(hdr);
|
delete_instance_hdr(hdr);
|
||||||
return f_pindly(nline);
|
behav_ret = f_pindly(nline);
|
||||||
|
if (!behav_ret && current_subckt && ps_udevice_msgs >= 1) {
|
||||||
|
printf("ERROR in %s\n", current_subckt);
|
||||||
|
}
|
||||||
|
return behav_ret;
|
||||||
} else if (eq(itype, "constraint")) {
|
} else if (eq(itype, "constraint")) {
|
||||||
delete_instance_hdr(hdr);
|
delete_instance_hdr(hdr);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue