changeset 3:f03bba45ae77

*** empty log message ***
author kinjo
date Sun, 11 Dec 2005 21:46:14 +0900
parents bf65d90b8dc8
children daa6a4e92480
files Makefile dbg.c struct-interface.c symbol-c.c symbol.c
diffstat 5 files changed, 107 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Nov 28 13:34:57 2005 +0900
+++ b/Makefile	Sun Dec 11 21:46:14 2005 +0900
@@ -2,8 +2,9 @@
 #MCC=./mcc
 #MCC=mc-mips
 MCC=mc-ia32
-TARGET=first hello_mod separate dumparg arg arg-c dumparg-struct struct struct2 arg-dbg deep-nested-struct code-ptr-array func-ptr-array struct-ptr-arg for struct-align struct-array struct-array2 struct-mips struct-interface
+TARGET=first hello_mod separate dumparg arg arg-c dumparg-struct struct struct2 deep-nested-struct code-ptr-array func-ptr-array struct-ptr-arg for struct-align struct-array struct-array2 struct-mips struct-interface symbol symbol-c symbol-gcc symbol-mcc
 
+MCCFLAGS=-s
 CFLAGS=-g -Wall
 
 #%.o: %.c
@@ -14,15 +15,16 @@
 	$(MCC) -s $<
 	$(CC) $(CFLAGS) -o $@ -c $(<:.c=.s)
 
-CFLAGS=-g -Wall
-
 all: $(TARGET)
 
-struct-interface:struct-interface.o
-	$(CC) $(CFLAGS) -o $@ $^
+dbg.o:dbg.c
+	$(CC) $(CFLAGS) -o $@ -c $<
+
+struct-interface:struct-interface.o dbg.o
+	$(CC) -o $@ $^
 
 struct-array2:struct-array2.o
-	$(CC) $(CFLAGS) -o $@ $^
+	$(CC) -o $@ $^
 
 struct-array: struct-array.o
 	$(CC) -o $@ $^
@@ -78,16 +80,6 @@
 asm-studies: asm-studies.o
 	$(CC) -o $@ $^
 
-arg-dbg.o: arg.c
-	$(CC) -DDEBUG -P -E -o $(@:.o=.d) $<
-	$(MCC) -o$(@:.o=.s) $(@:.o=.d)
-	$(CC) $(CFLAGS) -o $@ -c $(@:.o=.s)
-
-dbg.o:dbg.c
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-arg-dbg: arg-dbg.o dbg.o
-	$(CC) -o $@ $^
 deep-nested-struct: deep-nested-struct.o
 	$(CC) -o $@ $^
 struct-ptr-arg: struct-ptr-arg.o
@@ -103,6 +95,23 @@
 
 struct-mips: struct-mips.o
 	$(CC) -o $@ $^
+
+symbol.c:symbol.o
+	$(CC) -o $@ $^
+
+symbol-gcc.o:symbol-c.c
+	$(CC) $(CFLAGS) -c -o $@ $<
+
+symbol-gcc:symbol-gcc.o
+	$(CC) -o $@ $^
+
+symbol-mcc.o:symbol-c.c
+	$(MCC) -s $<
+	$(CC) $(CFLAGS) -c -o $@ $(<:.c=.s)
+
+symbol-mcc:symbol-mcc.o
+	$(CC) -o $@ $^
+
 clean:
 	rm -f $(TARGET)
 	rm -f *.s *.o *.d *.i a.out
--- a/dbg.c	Mon Nov 28 13:34:57 2005 +0900
+++ b/dbg.c	Sun Dec 11 21:46:14 2005 +0900
@@ -1,38 +1,4 @@
-extern int option(int,char**);
-extern void usage();
-extern int printf(char*,...);
-
-extern int help;
-extern char* outfile;
-extern char* infile;
-
 void
-breakp(void *ret, void *env)
-{
-    return;
-}
-
-int
-main(int argc,char **argv)
+breakp(void *from,void *intf)
 {
-    if(option(argc,argv)){
-	printf("Invalid option\n");
-	usage();
-	return 1;
-    }
-    if(help){
-	usage();
-	return 0;
-    }
-    if(infile){
-	printf("infile: %s\n", infile);
-    } else{
-	printf("Invalid usage\n");
-	usage();
-	return 1;
-    }
-    if(outfile){
-	printf("outfile: %s\n", outfile);
-    }
-    return 0;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/struct-interface.c	Sun Dec 11 21:46:14 2005 +0900
@@ -0,0 +1,45 @@
+// interfaceに1つだけのstructを使う
+#include"my-stdio.h"
+#define USE_BREAKP
+#include"dbg.h"
+
+struct interface {
+    int a;
+    int b;
+    float c;
+    int d;
+    code (*ret)(int);
+    void *env;
+} intf;
+
+code
+testexit(struct interface *i)
+{
+    goto i->ret(0),i->env;
+}
+
+code
+printit(struct interface *i)
+{
+    BREAKP(printit,i);
+    printf("%d %d %f %d\n",i->a,i->b,i->c,i->d);
+    goto testexit(i);
+}
+
+code
+test0(struct interface *i)
+{
+    i->a=10;
+    i->b=20;
+    i->c=30;
+    i->d=40;
+    goto printit(i);
+}
+
+int
+main()
+{
+    intf.ret=return;
+    intf.env=environment;
+    goto test0(&intf);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/symbol-c.c	Sun Dec 11 21:46:14 2005 +0900
@@ -0,0 +1,16 @@
+extern int printf(char*,...);
+
+void test_func(){
+}
+unsigned long addrs[]={
+     (unsigned long)test_func,
+     0,
+};
+int main()
+{
+     int i;
+     for(i=0;addrs[i]>0;i++)
+	  printf("%lx\n",addrs[i]);
+     printf("%lx\n",(unsigned long)test_func);
+     return(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/symbol.c	Sun Dec 11 21:46:14 2005 +0900
@@ -0,0 +1,20 @@
+extern int printf(char*,...);
+code test_code(int a){
+     goto test_code(a);
+}
+void test_func(){}
+unsigned long addrs[]={
+     test_code,
+     test_func,
+     0,
+};
+int
+main()
+{
+     int i;
+     for(i=0;addrs[i]>0;i++){
+	  printf("%lx\n",addrs[i]);
+     }
+     printf("%lx\n",(unsigned long)test_code);
+     printf("%lx\n",(unsigned long)test_func);
+}