changeset 316:22d92986c7f7

asm, valued statement, local decls continue...
author kono
date Wed, 16 Jun 2004 13:15:01 +0900
parents 84df3dd8cc3d
children 3dfac70ef7e1
files .gdbinit Changes mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c mc.h
diffstat 7 files changed, 140 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Tue Jun 15 14:34:06 2004 +0900
+++ b/.gdbinit	Wed Jun 16 13:15:01 2004 +0900
@@ -1,7 +1,7 @@
 tb main
 # run  -s test/arg.c
 # run  -s -ob00.s mc-parse.c
-run  -s test/macro.c
+run  -s asm-powerpc.c
 # run -s test/code-gen-all.c
 define regs 
 printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
--- a/Changes	Tue Jun 15 14:34:06 2004 +0900
+++ b/Changes	Wed Jun 16 13:15:01 2004 +0900
@@ -4959,3 +4959,11 @@
 というわけで、asm が先の方がいいんじゃない?
 
 ia32 のswitch 文がおかしくなってるぞ。
+
+Wed Jun 16 13:05:40 JST 2004
+
+asm は、({....; val;}) も一緒に実装しないとだめ。あと、
+local_decls での redefined だけど、なんかいい方法あるの?
+無視ってもいいんだけど...
+
+association list を使って、unwind すれば良いんだけどね。
--- a/mc-code-powerpc.c	Tue Jun 15 14:34:06 2004 +0900
+++ b/mc-code-powerpc.c	Wed Jun 16 13:15:01 2004 +0900
@@ -4932,5 +4932,15 @@
 
 #endif
 
+#if ASM_CODE
+
+void
+code_asm(int asm0,int in,int out,int opt,int e)
+{
+}
+
+#endif
+
+
 /* end */
 
--- a/mc-code.h	Tue Jun 15 14:34:06 2004 +0900
+++ b/mc-code.h	Wed Jun 16 13:15:01 2004 +0900
@@ -224,4 +224,8 @@
 extern void code_table_close();
 #endif
 
+#if ASM_CODE
+extern void code_asm(int asm0,int in,int out,int opt,int e);
+#endif
+
 /* */
--- a/mc-codegen.c	Tue Jun 15 14:34:06 2004 +0900
+++ b/mc-codegen.c	Wed Jun 16 13:15:01 2004 +0900
@@ -424,6 +424,12 @@
     case ENVIRONMENT:
 	code_environment(USE_CREG);
 	return ADDRESS;
+#if ASM_CODE
+    case ASM:
+	code_asm(car(e2),cadr(e2),caddr(e2),cadddr(e2),caddr(e1));
+        /*        asm    in (str) out (str) opt(str)   expr */
+	return VOID;
+#endif
     default:
 	code_bool(e1,USE_CREG); /* type? */
 	return INT;
--- a/mc-parse.c	Tue Jun 15 14:34:06 2004 +0900
+++ b/mc-parse.c	Wed Jun 16 13:15:01 2004 +0900
@@ -62,7 +62,7 @@
 static void copy(NMTBL *nptr, char *s);
 static void decl(void);
 static void docase(void);
-static void docomp(void);
+static void docomp(int);
 static void dodefault(void);
 static void dodo(void);
 static void dofor(void);
@@ -72,6 +72,9 @@
 static void doreturn(void);
 static void doswitch(void);
 static void dowhile(void);
+#if ASM_CODE
+static void doasm();
+#endif
 static void errmsg(void);
 static void fcheck(NMTBL *n);
 static void fdecl(NMTBL *n);
@@ -90,7 +93,7 @@
 static void reserve(char *s, int d);
 static void reverse(int t1);
 static void set_converter(char *s);
-static void statement(void);
+static void statement(int);
 static int correct_type(int e,int t);
 static int arg_reorder(int old_arg,int new_arg);
 static int search_struct_type(int t,char *name,int *dsp);
@@ -118,6 +121,7 @@
 
 static char *chinput=0;
 static int in_quote=0;
+static int lastexp = 0;
 
 int
 main(int argc, char **argv)
@@ -318,8 +322,13 @@
     reserve("inline",INLINE);
     reserve("enum",ENUM);
     reserve("volatile",VOLATILE);
+    reserve("__volatile__",VOLATILE);
     reserve("typeof",TYPEOF);
     reserve("__builtin_alloca",ALLOCA);
+#if ASM_CODE
+    reserve("asm",ASM);
+    reserve("__asm__",ASM);
+#endif
 
     gpc=glineno=0;
     gfree=ilabel=1;
@@ -1494,7 +1503,7 @@
     cslabel = -1;
     if(!chk) code_enter1(args);
     emit_init_vars();
-    while(sym!=RC) statement();
+    while(sym!=RC) statement(0);
     if(control)
 	error(STERR);
     control=0;
@@ -1611,7 +1620,7 @@
     cslabel = -1;
     if(!chk) enter1();
     emit_init_vars();
-    while(sym!=RC) statement();
+    while(sym!=RC) statement(0);
 
     conv->function_end_(); conv->rc_();
     if(!chk) leave(control,n->nm);
@@ -1722,10 +1731,14 @@
 	control=0;
 	retpending=0;
     }
+    if (lastexp) {
+	gexpr(lastexp,0);
+	lastexp = 0;
+    }
 }
 
 static void
-statement(void)
+statement(int use)
 {
     int slfree;
 
@@ -1750,7 +1763,7 @@
 	doswitch();
 	return;
     case LC:
-	docomp();
+	docomp(use);
 	return;
     case BREAK:
 	checkret();
@@ -1768,29 +1781,37 @@
 	return;
     case CASE:
 	docase();
-	statement();
-	return;
+	statement(use); return;
     case DEFAULT:
 	dodefault();
-	statement();
-	return;
+	statement(use); return;
     case RETURN:
 	doreturn();
 	return;
     case GOTO:
 	dogoto();
 	return;
+#if ASM_CODE
+    case ASM:
+	doasm();
+	return;
+#endif
     default:
+	checkret();
 	if(sym==IDENT&&skipspc()==':') {
 	    dolabel();
-	    statement();
+	    statement(use);
 	} else {
-	    checkret();
-	    slfree=lfree;
-	    gexpr(expr(0),0);
-	    lfree=slfree;
-	    conv->sm_();
-	    checksym(SM);
+	    if (use) {
+		lastexp = expr(0);
+		return;
+	    } else {
+		slfree=lfree;
+		gexpr(expr(0),use);
+		lfree=slfree;
+		conv->sm_();
+		checksym(SM);
+	    }
 	}
     }
 }
@@ -1808,7 +1829,7 @@
     lfree=slfree;
     conv->if_then_();
     checksym(RPAR);
-    statement();
+    statement(0);
     checkret();
     if(sym==ELSE) {
 	conv->if_else_();
@@ -1816,7 +1837,7 @@
 	    jmp(l2=fwdlabel());
 	fwddef(l1);
 	getsym(0);
-	statement();
+	statement(0);
 	checkret();
 	if (l2) fwddef(l2);
     }
@@ -1850,7 +1871,7 @@
     } else {
 	bexpr(e,0,blabel);
 	// lfree=slfree;
-	statement();
+	statement(0);
 	checkret();
 	if(control)
 	    jmp(clabel);
@@ -1875,7 +1896,7 @@
     l=backdef();
     conv->dowhile_();
     getsym(0);
-    statement();
+    statement(0);
     checkret();
     fwddef(clabel);
     checksym(WHILE);
@@ -1930,14 +1951,14 @@
 	clabel=l;
 	conv->for_body_();
 	getsym(0);
-	statement();
+	statement(0);
 	checkret();
     } else {
 	clabel=fwdlabel();
 	e=expr(0);
 	conv->for_body_();
 	checksym(RPAR);
-	statement();
+	statement(0);
 	checkret();
 	fwddef(clabel);
 	gexpr(e,0);
@@ -1951,12 +1972,12 @@
 }
 
 static void
-docomp(void)
+docomp(int use)
 {
     conv->lc_();
     local_decl();
     emit_init_vars();
-    while(sym!=RC) statement(); 
+    while(sym!=RC) statement(use); 
     conv->rc_();
     getsym(0);
 }
@@ -1999,7 +2020,7 @@
        In this case, we have to jump into the first case label.
        Can be done in checkret();
     */
-    statement();
+    statement(0);
     conv->switch_end_();
     checkret();
 #if CASE_CODE
@@ -2227,6 +2248,57 @@
     checksym(COLON);
 }
 
+#if ASM_CODE
+static void
+doasm()
+{
+    int e1 = 0, asm0 = 0, input = 0, out = 0, opt = 0;
+    int e;
+
+    checkret();
+    getsym(0);
+    if (sym==VOLATILE) getsym(0);
+    checksym(LPAR);
+    // asm string
+    if (sym!=STRING) error(DCERR);
+    asm0=list3(STRING,(int)sptr,symval);
+    getsym(0);
+    if (sym!=COLON) error(DCERR);
+    do {
+	// output expression
+	getsym(0);
+	if (sym==COLON) break;
+	if (sym!=STRING) error(DCERR);
+	out=list2(list3(STRING,(int)sptr,symval),out);
+	getsym(0);
+	e1=list2(e=expr1(),e1);
+	lcheck(e);
+    } while(sym==COMMA);
+    if (sym==COLON) {
+	do {
+	    // input expression
+	    getsym(0);
+	    if (sym==COLON) break;
+	    if (sym!=STRING) error(DCERR);
+	    input=list2(list3(STRING,(int)sptr,symval),input);
+	    getsym(0);
+	    e1=list2(expr1(),e1);
+	} while(sym==COMMA);
+    }
+    if (sym==COLON) {
+	do {
+	    // option string
+	    getsym(0);
+	    if (sym!=STRING) error(DCERR);
+	    opt=list2(list3(STRING,(int)sptr,symval),opt);
+	    getsym(0);
+	} while(sym==COMMA);
+    }
+    checksym(RPAR);
+    gexpr(list3(ASM,list4(asm0,input,out,opt),e1),0);
+}
+#endif
+
 /* numerical type conversion */
 
 int
@@ -3097,9 +3169,15 @@
 	    }
 	    type=t;
 	    return e1;
+	} else if (sym==LC) {
+	    // statement in expression
+	    getsym(0);
+	    docomp(1);
+	    e1 = lastexp; lastexp = 0;
+	} else {
+	    e1=expr0();
+	    conv->rpar_();
 	}
-	e1=expr0();
-	conv->rpar_();
 	checksym(RPAR);
 	break;
     default:error(EXERR);
@@ -4704,6 +4782,7 @@
 	lineno=0;
 	++filep;
 	*(chptr = linebuf) = '\0';
+#if ASM_CODE
     } else if (macroeq("asm")) {
 	if (asmf) error(MCERR);
 	asmf = 1;
@@ -4715,6 +4794,7 @@
     } else if (macroeq("endasm")) {
 	if (!asmf) error(MCERR);
 	asmf = 0;
+#endif
     } else if (macroeq(" "))
 	getline();
     else error(MCERR);
--- a/mc.h	Tue Jun 15 14:34:06 2004 +0900
+++ b/mc.h	Wed Jun 16 13:15:01 2004 +0900
@@ -13,6 +13,7 @@
 #define FLOAT_CODE 1
 #define LONGLONG_CODE 1
 #define CASE_CODE 1
+#define ASM_CODE 1
 
 /* reserved word start */
 
@@ -76,6 +77,7 @@
 #define ULONGLONG	(-56)
 #define VOLATILE	(-57)
 #define TYPEOF	(-58)
+#define ASM	(-59)
 
 /* reserved word end */
 
@@ -111,7 +113,7 @@
 
 /* tree node tags start */
 
-#define LIST_ARGS(i) (i==FUNCTION||i==CODE)
+#define LIST_ARGS(i) (i==FUNCTION||i==CODE||i==ASM)
 
 /* nullary  argments */