# HG changeset patch # User kono # Date 1161936590 -32400 # Node ID 1ee4fa9364c7260185fc275677ec0be77ea6a364 # Parent 6bf66c125dbc10c86f65d76aba339cfd213f0e6e *** empty log message *** diff -r 6bf66c125dbc -r 1ee4fa9364c7 s-code-ppc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/s-code-ppc.c Fri Oct 27 17:09:50 2006 +0900 @@ -0,0 +1,190 @@ +/* + Very Simple Code Generator for Mac OS X (PPC) + $Id$ + */ + +#include "s-compile.h" + +int label = 0; +char *comments = "#####"; + +static +char *intro[] = { +" .section __TEXT,__text,regular,pure_instructions", +" .section __TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32", +" .machine ppc", +" .text", +" .align 2", +" .globl _main", +" _main:", +" mflr r0", +" bcl 20,31,"L00000000001$pb"", +" "L00000000001$pb":", +" mflr r10", +" mtlr r0", + NULL +}; + +static +char *ending[] = { +" .cstring", +" .align 2", +" LC0:", +" .ascii "= %d\12\0"", +" .text", +" .align 2", +" .globl _print", +" _print:", +" mflr r0", +" stw r31,-4(r1)", +" stw r0,8(r1)", +" stwu r1,-80(r1)", +" 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)", +" bl L_printf$stub", +" addi r1,r1,80", +" lwz r0,8(r1)", +" mtlr r0", +" lwz r31,-4(r1)", +" mtlr r0", +" lwz r31,-4(r1)", +" blr", +" .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":", +" mflr r11", +" addis r11,r11,ha16(L_printf$lazy_ptr-"L00000000001$spb")", +" mtlr r0", +" 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", + NULL +}; + +void +emit_push() +{ + printf("\tstwu r3,-4(r1)\n"); +} + +void +emit_compare() +{ + printf("\tlwz r4,(r1)\n"); + printf("\taddis r1,r1,4\n"); + cmpw cr7,r3,r4 + mfcr r3 + rlwinm r3,r3,30,1 + +} + +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 + +} + +static +char *opcode[] = { + "", + "sub", + "add", + "mul", + "div", + "", + "", + "", + "", + "sub", + "div", +}; + +void +emit_calc(enum opcode op) +{ + printf("\tlwz r4,(r1)\n"); + printf("\taddis r1,r1,4\n"); + if(op==O_DIV) { + printf("\tdiv r4,r3,r3\n"); + } else if(op==O_SUB) { + printf("\tsub r4,r3,r3\n"); + } else { + printf("\t%s r4,r3,r3\n",opcode[op]); + } +} + +void +emit_value(d) +int d; +{ + printf("\tmovl $%d,%%eax\n",d); +} + +void +emit_load(d) +int d; +{ + printf("\tmovl _variable+%d,%%eax\n",d*4); +} + +void +emit_comment() +{ + if (before < ptr) { + putchar('#'); putchar('#'); putchar(' '); + while (before < ptr) { + if(*before && *before!='\n') { + putchar(*before); + } + before++; + } + putchar('\n'); + } +} + +void +emit_print() +{ + printf("\tbl _print\n"); +} + + +void +emit_intro() +{ + char **iptr; + for(iptr=intro;*iptr;iptr++) { + printf("%s",*iptr); + } +} + +void +emit_ending() +{ + char **iptr; + for(iptr=ending;*iptr;iptr++) { + printf("%s",*iptr); + } +} + +/* end */