c5902329875f06f33f7b9ad0f23bedd6b3d35dd2
[uebersetzerbau-ss10.git] / codea / chelper.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "chelper.h"
4
5 void func_header(char *s)
6 {
7         printf("\t.globl %1$s\n\t.type %1$s, @function\n%1$s:\n", s);
8 }
9
10 void move(char *src, char *dst)
11 {
12         if(strcmp(src,dst) != 0) {
13                 printf("\tmovq %%%s, %%%s\n", src, dst);
14         }
15 }
16
17 void ret(void)
18 {
19         printf("\tret\n");
20 }
21
22 char *next_reg(char *s, short skip)
23 {
24         char *regs[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
25         int i=0;
26         if (s != (char*) NULL) {
27                 for(; i < 9;) {
28                         if(!strcmp(s, regs[i++])) {
29                                 break;
30                         }
31                 }
32         }
33         if(skip) {
34                 i++;
35         }
36         return regs[i];
37 }
38
39 char *param_reg(int num)
40 {
41         char *regs[] = {"rdi", "rsi", "rdx", "rcx", "r8", "r9"};
42         return regs[num-1];
43 }
44