added EX_SIDEEFFECTS, options['p'] --> ! options['L'], fixed some bugs

This commit is contained in:
ceriel 1987-01-14 09:58:51 +00:00
parent 0ffdfb4f76
commit 493efb1bf7
10 changed files with 51 additions and 26 deletions

View file

@ -14,7 +14,7 @@ LINT = /usr/new/lint
SYSLIB = $(EMHOME)/modules/lib/libsystem.a SYSLIB = $(EMHOME)/modules/lib/libsystem.a
EMKLIB = $(EMHOME)/modules/lib/libemk.a EMKLIB = $(EMHOME)/modules/lib/libemk.a
EMELIB = $(EMHOME)/modules/lib/libeme.a EMELIB = $(EMHOME)/modules/lib/libeme.a
STRLIB = $(EMHOME)/modules/lib/libstr.a STRLIB = $(EMHOME)/modules/lib/libstring.a
PRTLIB = $(EMHOME)/modules/lib/libprint.a PRTLIB = $(EMHOME)/modules/lib/libprint.a
EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a EMMESLIB = $(EMHOME)/modules/lib/libem_mes.a
INPLIB = $(EMHOME)/modules/lib/libinput.a INPLIB = $(EMHOME)/modules/lib/libinput.a

View file

@ -42,8 +42,9 @@ set maximum identifier length to \fIn\fP.
do not generate EM register messages. do not generate EM register messages.
The user-declared variables are not stored into registers on the target The user-declared variables are not stored into registers on the target
machine. machine.
.IP \fB\-p\fR .IP \fB\-L\fR
generate the EM \fBfil\fR and \fBlin\fR instructions in order to enable don't generate the EM \fBfil\fR and \fBlin\fR instructions
that usually are generated to enable
an interpreter to keep track of the current location in the source code. an interpreter to keep track of the current location in the source code.
.IP \fB\-P\fR .IP \fB\-P\fR
like \fB\-E\fR but without #\fBline\fR control lines. like \fB\-E\fR but without #\fBline\fR control lines.

View file

@ -333,6 +333,7 @@ ch7asgn(expp, oper, expr)
*expp = new_oper((*expp)->ex_type, *expp, oper, expr); *expp = new_oper((*expp)->ex_type, *expp, oper, expr);
#endif NOBITFIELD #endif NOBITFIELD
(*expp)->OP_TYPE = tp; /* for EVAL() */ (*expp)->OP_TYPE = tp; /* for EVAL() */
(*expp)->ex_flags |= EX_SIDEEFFECTS;
} }
/* Some interesting (?) questions answered. /* Some interesting (?) questions answered.

View file

@ -77,6 +77,7 @@ ch7bin(expp, oper, expr)
else else
*expp = new_oper((*expp)->ex_type->tp_up, *expp = new_oper((*expp)->ex_type->tp_up,
*expp, '(', expr); *expp, '(', expr);
(*expp)->ex_flags |= EX_SIDEEFFECTS;
break; break;
case PARCOMMA: /* RM 7.1 */ case PARCOMMA: /* RM 7.1 */
if ((*expp)->ex_type->tp_fund == FUNCTION) if ((*expp)->ex_type->tp_fund == FUNCTION)
@ -149,8 +150,8 @@ ch7bin(expp, oper, expr)
} }
break; break;
case LEFT: case LEFT:
case LEFTAB:
case RIGHT: case RIGHT:
case LEFTAB:
case RIGHTAB: case RIGHTAB:
opnd2integral(expp, oper); opnd2integral(expp, oper);
opnd2integral(&expr, oper); opnd2integral(&expr, oper);

View file

@ -201,7 +201,7 @@ begin_proc(name, def) /* to be called when entering a procedure */
lab_count = (label) 1; lab_count = (label) 1;
return_label = text_label(); return_label = text_label();
return_expr_occurred = 0; return_expr_occurred = 0;
if (options['p']) { /* profiling */ if (! options['L']) { /* profiling */
if (strcmp(last_fn_given, FileName) != 0) { if (strcmp(last_fn_given, FileName) != 0) {
/* previous function came from other file */ /* previous function came from other file */
C_df_dlb(file_name_label = data_label()); C_df_dlb(file_name_label = data_label());
@ -479,7 +479,7 @@ code_expr(expr, val, code, tlbl, flbl)
generator. If line number trace is wanted, it generates a generator. If line number trace is wanted, it generates a
lin instruction. EVAL() is called directly. lin instruction. EVAL() is called directly.
*/ */
if (options['p']) /* profiling */ if (! options['L']) /* profiling */
C_lin((arith)LineNumber); C_lin((arith)LineNumber);
EVAL(expr, val, code, tlbl, flbl); EVAL(expr, val, code, tlbl, flbl);
} }

View file

@ -337,8 +337,10 @@ PRIVATE
do_endif() do_endif()
{ {
SkipRestOfLine(); SkipRestOfLine();
if (nestlevel-- < 0) if (nestlevel < 0) {
lexerror("#endif without corresponding #if"); lexerror("#endif without corresponding #if");
}
else nestlevel--;
} }
PRIVATE PRIVATE

View file

@ -94,8 +94,10 @@ EVAL(expr, val, code, true_label, false_label)
register struct expr *right = expr->OP_RIGHT; register struct expr *right = expr->OP_RIGHT;
register struct type *tp = expr->OP_TYPE; register struct type *tp = expr->OP_TYPE;
if (tp->tp_fund == ERRONEOUS) /* stop immediately */ if (tp->tp_fund == ERRONEOUS || (expr->ex_flags & EX_ERROR)) {
/* stop immediately */
break; break;
}
if (tp->tp_fund == VOID) if (tp->tp_fund == VOID)
gencode = 0; gencode = 0;
switch (oper) { switch (oper) {
@ -298,15 +300,7 @@ EVAL(expr, val, code, true_label, false_label)
C_bra(false_label); C_bra(false_label);
} }
else { else {
label l_true = text_label(); truthvalue(oper);
label l_end = text_label();
compare(oper, l_true);
C_loc((arith)0);
C_bra(l_end);
C_df_ilb(l_true);
C_loc((arith)1);
C_df_ilb(l_end);
} }
} }
break; break;
@ -384,9 +378,9 @@ EVAL(expr, val, code, true_label, false_label)
load_val(left, RVAL); load_val(left, RVAL);
} }
else else
if (left->ex_depth == 1 && left->OP_OPER == ARROW) { if (left->ex_depth == 1 &&
compl = 1; /* Value->sel */ !(left->ex_flags & EX_SIDEEFFECTS)) {
ASSERT(left->OP_LEFT->ex_class == Value); compl = 1;
EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL); EVAL(left, RVAL, newcode, NO_LABEL, NO_LABEL);
} }
else { else {
@ -662,6 +656,35 @@ compare(relop, lbl)
} }
} }
/* truthvalue() serves as an auxiliary function of EVAL */
truthvalue(relop)
int relop;
{
switch (relop) {
case '<':
C_tlt();
break;
case LESSEQ:
C_tle();
break;
case '>':
C_tgt();
break;
case GREATEREQ:
C_tge();
break;
case EQUAL:
C_teq();
break;
case NOTEQUAL:
C_tne();
break;
default:
CRASH();
}
}
/* assop() generates the opcode of an assignment operators op= */ /* assop() generates the opcode of an assignment operators op= */
assop(type, oper) assop(type, oper)
register struct type *type; register struct type *type;

View file

@ -94,6 +94,7 @@ struct expr {
#define EX_LOGICAL 0004 /* contains logical operator */ #define EX_LOGICAL 0004 /* contains logical operator */
#define EX_COMMA 0010 /* contains expression comma */ #define EX_COMMA 0010 /* contains expression comma */
#define EX_PARENS 0020 /* the top level is parenthesized */ #define EX_PARENS 0020 /* the top level is parenthesized */
#define EX_SIDEEFFECTS 0040 /* expression has side effects */
#define EX_ERROR 0200 /* the expression is wrong */ #define EX_ERROR 0200 /* the expression is wrong */
#define NILEXPR ((struct expr *)0) #define NILEXPR ((struct expr *)0)

View file

@ -115,7 +115,7 @@ do_option(text)
break; break;
case 'L' : case 'L' :
warning("-L: default no EM profiling; use -p for EM profiling"); options['L'] = 1; /* no fil/lin */
break; break;
case 'M': /* maximum identifier length */ case 'M': /* maximum identifier length */
@ -126,10 +126,6 @@ do_option(text)
fatal("maximum identifier length is %d", IDFSIZE); fatal("maximum identifier length is %d", IDFSIZE);
break; break;
case 'p' : /* generate profiling code (fil/lin) */
options['p'] = 1;
break;
case 'P' : /* run preprocessor stand-alone, without #'s */ case 'P' : /* run preprocessor stand-alone, without #'s */
#ifndef NOPP #ifndef NOPP
options['E'] = 1; options['E'] = 1;

View file

@ -155,7 +155,7 @@ macro2buffer(idef, actpars, siztext)
/* copy the text of the actual parameter /* copy the text of the actual parameter
into the replacement text into the replacement text
*/ */
for (p = actpars[n - 1]; p && *p; p++) { for (p = actpars[n - 1]; *p; p++) {
text[pos++] = *p; text[pos++] = *p;
if (pos == size) if (pos == size)
text = Srealloc(text, size += RSTRSIZE); text = Srealloc(text, size += RSTRSIZE);