Mercurial > hg > Members > kono > compiler-examples
changeset 23:8c4683873ec8
try aarch code generation
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 19 Oct 2022 17:51:34 +0900 |
parents | 7412ef4ef789 |
children | aecd80408312 |
files | s-code-arm-mac.c |
diffstat | 1 files changed, 32 insertions(+), 125 deletions(-) [+] |
line wrap: on
line diff
--- a/s-code-arm-mac.c Wed Oct 19 17:09:53 2022 +0900 +++ b/s-code-arm-mac.c Wed Oct 19 17:51:34 2022 +0900 @@ -9,167 +9,74 @@ char *comments = "#####"; static char *intro[] = { - " .cstring\n", - "LC0:\n", - " .ascii \"%d\\n\\0\"\n" - " .text\n", - ".globl _print\n", - "_print:\n", - "LFB2:\n", - " pushq %rbp\n", - "LCFI0:\n", - " movq %rsp, %rbp\n", - "LCFI1:\n", - " subq $16, %rsp\n", - "LCFI2:\n", - " movl %edi, -4(%rbp)\n", - " movl -4(%rbp), %esi\n", - " leaq LC0(%rip), %rdi\n", - " movl $0, %eax\n", - " call _printf\n", - " leave\n", - " ret\n", - "LFE2:\n", - ".globl _main\n", - "_main:\n", - "LFB3:\n", - " pushq %rbp\n", - "LCFI3:\n", - " movq %rsp, %rbp\n", - "LCFI4:\n", - " subq $16, %rsp\n", - "LCFI5:\n", - "\n", - "\n", +" .section __TEXT,__text,regular,pure_instructions\n" +" .build_version macos, 12, 0 sdk_version 12, 3\n" +" .globl _main ; -- Begin function main\n" +" .p2align 2\n" +" _main: ; @main\n" +" .cfi_startproc\n" +" ; %bb.0:\n" +" adrp x8, _v@PAGE\n" +"\n\n", NULL }; static char *ending[] = { - " movq %rax, %rdi\n", - " call _print\n", - " movq $0,%rax\n", - " leave\n", - " ret\n", - "LFE3:\n", - ".comm _v,96,5\n", - " .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support\n", - "EH_frame1:\n", - " .set L$set$0,LECIE1-LSCIE1\n", - " .long L$set$0\n", - "LSCIE1:\n", - " .long 0x0\n", - " .byte 0x1\n", - " .ascii \"zR\\0\"\n", - " .byte 0x1\n", - " .byte 0x78\n", - " .byte 0x10\n", - " .byte 0x1\n", - " .byte 0x10\n", - " .byte 0xc\n", - " .byte 0x7\n", - " .byte 0x8\n", - " .byte 0x90\n", - " .byte 0x1\n", - " .align 3\n", - "LECIE1:\n", - " .globl _print.eh\n", - "_print.eh:\n", - "LSFDE1:\n", - " .set L$set$1,LEFDE1-LASFDE1\n", - " .long L$set$1\n", - "LASFDE1:\n", - " .long LASFDE1-EH_frame1\n", - " .quad LFB2-.\n", - " .set L$set$2,LFE2-LFB2\n", - " .quad L$set$2\n", - " .byte 0x0\n", - " .byte 0x4\n", - " .set L$set$3,LCFI0-LFB2\n", - " .long L$set$3\n", - " .byte 0xe\n", - " .byte 0x10\n", - " .byte 0x86\n", - " .byte 0x2\n", - " .byte 0x4\n", - " .set L$set$4,LCFI1-LCFI0\n", - " .long L$set$4\n", - " .byte 0xd\n", - " .byte 0x6\n", - " .align 3\n", - "LEFDE1:\n", - " .globl _main.eh\n", - "_main.eh:\n", - "LSFDE3:\n", - " .set L$set$5,LEFDE3-LASFDE3\n", - " .long L$set$5\n", - "LASFDE3:\n", - " .long LASFDE3-EH_frame1\n", - " .quad LFB3-.\n", - " .set L$set$6,LFE3-LFB3\n", - " .quad L$set$6\n", - " .byte 0x0\n", - " .byte 0x4\n", - " .set L$set$7,LCFI3-LFB3\n", - " .long L$set$7\n", - " .byte 0xe\n", - " .byte 0x10\n", - " .byte 0x86\n", - " .byte 0x2\n", - " .byte 0x4\n", - " .set L$set$8,LCFI4-LCFI3\n", - " .long L$set$8\n", - " .byte 0xd\n", - " .byte 0x6\n", - " .align 3\n", - "LEFDE3:\n", - " .subsections_via_symbols\n", +" .loh AdrpLdr Lloh0, Lloh1\n" +" .cfi_endproc\n" +" ; -- End function\n" +" .section __DATA,__data\n" +" .globl _v ; @a\n" +" .p2align 3\n" +" _a:\n" +" .quad 64 ; 64\n" +"\n" +" .subsections_via_symbols\n", NULL }; void emit_push() { - printf("\tpushq %%rax\n"); + printf("\tstr x0,[sp, -8]!\n"); } void emit_compare() { - printf("\tcmpq %%rax,(%%rsp)\n"); - printf("\t%s %%al\n","setg"); - printf("\tmovzbq %%al,%%rax\n"); - printf("\taddq $8,%%rsp\n"); + printf("\tldr x1,[sp, 8]!\n"); + printf("\tcmp x0,x0,x1\n"); } void emit_store( int d ) { - printf("\tmovq _v@GOTPCREL(%%rip), %%rcx\n"); - printf("\tmovq %%rax, %d(%%rcx)\n" ,d*8); + printf("add x9, x8, _v@PAGEOFF\n"); + printf("str x0, [x9, %d ]\n",d); } void emit_load(int d) { - printf("\tmovq _v@GOTPCREL(%%rip), %%rcx\n"); - printf("\tmovq %d(%%rcx),%%rax\n" ,d*8); + printf("add x9, x8, _v@PAGEOFF\n"); + printf("ldr x0, [x9, %d ]\n",d); } static char *opcode[] = { "", - "subq", - "addq", - "imulq", - "idivq", + "sub", + "add", + "mul", + "sdiv", "", "", "", "", - "subq", - "idivq", + "sub", + "sdiv", }; void