codea: refactor, teil1
[uebersetzerbau-ss10.git] / codea / chelper.c
index 37c03be8b1c0b889cfe5e08f154794b631d4272f..015e7a35244bfd13de60e33cd2f4584737f642f9 100644 (file)
@@ -4,13 +4,13 @@
 #include "chelper.h"
 #include "tree.h"
 
-#if 1
+#if 0
 #define DDCHELP
 #endif
 
-#define REGLEN 9
-static char *regs64[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
-static char *regs8l[] = {"al", "r10b", "r11b", "r9b", "r8b", "cl", "dl", "sil", "dil"};
+#define REGLEN 4
+static char *regs64[] = {"rax", "r10", "r11", "r9"};
+static char *regs8l[] = {"al", "r10b", "r11b", "r9b"};
 
 void func_header(char *s)
 {
@@ -24,12 +24,6 @@ void func_footer(void)
 
 void move(char *src, char *dst)
 {
-       if(src == NULL) {
-               printf("//wtf, src ist null\n");
-       }
-       if(dst == NULL) {
-               printf("//wtf, dst ist null\n");
-       }
        if(strcmp(src,dst) != 0) {
                printf("\tmovq %%%s, %%%s\n", src, dst);
        }
@@ -42,35 +36,18 @@ void moveimm(long imm, char *dst)
        printf("\tmovq %s, %%%s\n", buf, dst);
 }
 
-void ret(void)
-{
-       printf("\tret\n");
-}
-
-char *next_reg(char *s, short skip, int params)
+char *next_reg(char *s, int params)
 {
        int i = 0;
        if (s != (char*) NULL) {
-               while(i < REGLEN) {
-                       if(!strcmp(s, regs64[i++])) {
-                               break;
-                       }
+               while(strcmp(s, regs64[i]) != 0) {
+                       i = (i+1) % REGLEN;
                }
-       }
-       if(skip) {
-               i++;
+               i = (i+1) % REGLEN;
        }
 #ifdef DDCHELP
        fprintf(stderr, "next_reg(): %s (bei %i parameter)\n", regs64[i], params);
 #endif
-       /* TODO: <= passt? */
-       if(REGLEN - params <= i) {
-               fprintf(stderr, "next_reg(): register \"%s\" in dem sich ein parameter befindet wird als temporaeres register verwendet(params: %i, i: %i)\n", regs64[i], params, i);
-               /* TODO: exit hier? */
-#if 0
-               exit(4);
-#endif
-       }
        return regs64[i];
 }
 
@@ -78,19 +55,15 @@ char *reg_64to8l(char *s)
 {
        int i = 0;
        if (s != (char*) NULL) {
-               while(i < REGLEN) {
-                       if(!strcmp(s, regs64[i])) {
-                               return regs8l[i];
-                       } else {
-                               i++;
-                       }
+               while(strcmp(s, regs64[i]) != 0) {
+                       i = (i+1) % REGLEN;
                }
+               return regs8l[i];
        }
        fprintf(stderr, "reg_64to8l(): sollte nicht passieren\n");
        exit(4);
 }
 
-
 char *param_reg(int num)
 {
        char *regs[] = {"rdi", "rsi", "rdx", "rcx", "r8", "r9"};