changeset 3:a2f98ca2d764

*** empty log message ***
author kono
date Fri, 17 Nov 2006 16:28:43 +0900
parents 1ee4fa9364c7
children a7bc45dba4aa
files s-code-ppc.c
diffstat 1 files changed, 45 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/s-code-ppc.c	Fri Oct 27 17:09:50 2006 +0900
+++ b/s-code-ppc.c	Fri Nov 17 16:28:43 2006 +0900
@@ -18,9 +18,9 @@
 "	.globl _main",
 "	_main:",
 "	mflr r0",
-"	bcl 20,31,"L00000000001$pb"",
-"	"L00000000001$pb":",
-"	mflr r10",
+"	bcl 20,31,\"L00000000001$pb\"",
+"	\"L00000000001$pb\":",
+"	mflr r31",
 "	mtlr r0",
     NULL
 };
@@ -30,7 +30,7 @@
 "	.cstring",
 "	.align 2",
 "	LC0:",
-"	.ascii "= %d\12\0"",
+"	.ascii \"= %d\\12\\0\"",
 "	.text",
 "	.align 2",
 "	.globl _print",
@@ -39,12 +39,12 @@
 "	stw r31,-4(r1)",
 "	stw r0,8(r1)",
 "	stwu r1,-80(r1)",
-"	bcl 20,31,"L00000000002$pb"",
-"	"L00000000002$pb":",
+"	bcl 20,31,\"L00000000002$pb\"",
+"	\"L00000000002$pb\":",
 "	mflr r31",
 "	mr r4,r3",
-"	addis r3,r31,ha16(LC0-"L00000000002$pb")",
-"	la r3,lo16(LC0-"L00000000002$pb")(r3)",
+"	addis r3,r31,ha16(LC0-\"L00000000002$pb\")",
+"	la r3,lo16(LC0-\"L00000000002$pb\")(r3)",
 "	bl L_printf$stub",
 "	addi r1,r1,80",
 "	lwz r0,8(r1)",
@@ -53,81 +53,84 @@
 "	mtlr r0",
 "	lwz r31,-4(r1)",
 "	blr",
+    "\t.align 2",
+    ".comm _variable,192",
 "	.section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32",
 "	.align 5",
 "	L_printf$stub:",
 "	.indirect_symbol _printf",
 "	mflr r0",
-"	bcl 20,31,"L00000000001$spb"",
-"	"L00000000001$spb":",
+"	bcl 20,31,\"L00000000001$spb\"",
+"	\"L00000000001$spb\":",
 "	mflr r11",
-"	addis r11,r11,ha16(L_printf$lazy_ptr-"L00000000001$spb")",
+"	addis r11,r11,ha16(L_printf$lazy_ptr-\"L00000000001$spb\")",
 "	mtlr r0",
-"	lwzu r12,lo16(L_printf$lazy_ptr-"L00000000001$spb")(r11)",
+"	lwzu r12,lo16(L_printf$lazy_ptr-\"L00000000001$spb\")(r11)",
 "	mtctr r12",
 "	bctr",
 "	.lazy_symbol_pointer",
 "	L_printf$lazy_ptr:",
 "	.indirect_symbol _printf",
 "	.long   dyld_stub_binding_helper",
-"	.subsections_via_symbols",
-    "\t.align 2\n",
-    ".comm _variable,192\n",
+"        .non_lazy_symbol_pointer",
+"L_variable$non_lazy_ptr:",
+"        .indirect_symbol _variable",
+"        .long   0",
+"        .subsections_via_symbols",
+
     NULL
 };
 
 void
 emit_push()
 {
-    printf("\tstwu r3,-4(r1)\n");
+    printf("\taddis r1,r1,-4\n");
+    printf("\tstw r3,0(r1)\n");
 }
 
 void
 emit_compare() 
 {
-    printf("\tlwz r4,(r1)\n");
+    printf("\tlwz r4,0(r1)\n");
     printf("\taddis r1,r1,4\n");
-            cmpw cr7,r3,r4
-		        mfcr r3
-			        rlwinm r3,r3,30,1
-
+    printf("\tcmpw cr7,r3,r4\n");
+    printf("\tmfcr r3\n");
+    printf("\trlwinm r3,r3,30,1\n");
 }
 
 void
 emit_store(assign)
 int assign;
 {
-            slwi r3,r3,2
-		        addis r2,r10,ha16(L_variable$non_lazy_ptr-"L00000000002$pb")
-			        lwz r2,lo16(L_variable$non_lazy_ptr-"L00000000002$pb")(r2)
-				        stwx r4,r3,r2
-
+    printf("\taddis r2,r31,ha16(L_variable$non_lazy_ptr-\"L00000000002$pb\")\n");
+    printf("\tlwz r2,lo16(L_variable$non_lazy_ptr-\"L00000000002$pb\")(r2)\n");
+    printf("\tstw r3,%d(r2)\n",assign*4);
 }
 
 static
 char *opcode[] = {
     "",
-    "sub",
+    "subf",
     "add",
-    "mul",
-    "div",
+    "mullw",
+    "divw",
     "",
     "",
     "",
     "",
-    "sub",
-    "div",
+    "subf",
+    "divw",
 };
 
 void
 emit_calc(enum opcode op)
 {
-    printf("\tlwz r4,(r1)\n");
+    printf("\tlwz r4,0(r1)\n");
     printf("\taddis r1,r1,4\n");
     if(op==O_DIV) {
-	printf("\tdiv r4,r3,r3\n");
+	printf("\tdivw r4,r3,r3\n");
     } else if(op==O_SUB) {
-	printf("\tsub r4,r3,r3\n");
+	printf("\tsubf r4,r3,r3\n");
     } else {
 	printf("\t%s r4,r3,r3\n",opcode[op]);
     }
@@ -137,14 +140,18 @@
 emit_value(d) 
 int d;
 {
-    printf("\tmovl $%d,%%eax\n",d);
+    printf("\tlis r3,ha16(%d)\n",d);
+    printf("\tori r3,r3,lo16(%d)\n",d);
+
 }
 
 void
 emit_load(d)
 int d;
 {
-    printf("\tmovl _variable+%d,%%eax\n",d*4);
+    printf("\taddis r2,r31,ha16(L_variable$non_lazy_ptr-\"L00000000002$pb\")\n");
+    printf("\tlwz r2,lo16(L_variable$non_lazy_ptr-\"L00000000002$pb\")(r2)\n");
+    printf("\tlwz r3,%d(r2)\n",d*4);  //  -1024<d <1024
 }
 
 void
@@ -174,7 +181,7 @@
 {
     char **iptr;
     for(iptr=intro;*iptr;iptr++) {
-        printf("%s",*iptr);
+        printf("%s\n",*iptr);
     }
 }
 
@@ -183,7 +190,7 @@
 {
     char **iptr;
     for(iptr=ending;*iptr;iptr++) {
-        printf("%s",*iptr);
+        printf("%s\n",*iptr);
     }
 }