codea: nicht wirklich was aufregendes, aber ein paar simple testfaelle gehen schon
[uebersetzerbau-ss10.git] / codea / chelper.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "chelper.h"
4 #include "tree.h"
5
6 #if 1
7 #define DDCHELP
8 #endif
9
10 void func_header(char *s)
11 {
12         printf("\t.globl %1$s\n\t.type %1$s, @function\n%1$s:\n", s);
13 }
14
15 void move(char *src, char *dst)
16 {
17         if(strcmp(src,dst) != 0) {
18                 printf("\tmovq %%%s, %%%s\n", src, dst);
19         }
20 }
21
22 void ret(void)
23 {
24         printf("\tret\n");
25 }
26
27 char *next_reg(char *s, short skip)
28 {
29         char *regs[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
30         int i=0;
31         if (s != (char*) NULL) {
32                 while(i < 9) {
33                         if(!strcmp(s, regs[i++])) {
34                                 break;
35                         }
36                 }
37         }
38         if(skip) {
39                 i++;
40         }
41 #ifdef DDCHELP
42         fprintf(stderr, "next_reg(): %s\n", regs[i]);
43 #endif
44
45         return regs[i];
46 }
47
48 char *param_reg(int num)
49 {
50         char *regs[] = {"rdi", "rsi", "rdx", "rcx", "r8", "r9"};
51         return regs[num];
52 }
53