]> git.unchartedbackwaters.co.uk Git - francis/libjit.git/commitdiff
add register classes
authorAleksey Demakov <ademakov@gmail.com>
Fri, 29 Dec 2006 19:08:14 +0000 (19:08 +0000)
committerAleksey Demakov <ademakov@gmail.com>
Fri, 29 Dec 2006 19:08:14 +0000 (19:08 +0000)
ChangeLog
jit/jit-reg-class.c [new file with mode: 0644]
jit/jit-reg-class.h [new file with mode: 0644]
jit/jit-rules-x86.c

index 9853442bb5b93307b31ebcd69556fc3ac78512a7..9baa196e1e54b50f264212378d3557e1c25d0bde 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-12-30  Aleksey Demakov  <ademakov@gmail.com>
+
+       * jit/jit-reg-class.c, jit/jit-reg-class.h, jit/Makefile.am: add
+       register classes.
+
+       * jit/jit-rules-x86.c (_jit_init_backend): initialize x86 register
+       classes.
+
 2006-12-20  Aleksey Demakov  <ademakov@gmail.com>
 
        * jit/jit-thread.h, jit/jit-thread.c: add _jit_global_lock mutex.
diff --git a/jit/jit-reg-class.c b/jit/jit-reg-class.c
new file mode 100644 (file)
index 0000000..fe42838
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * jit-reg-class.c - Register class routines for the JIT.
+ *
+ * Copyright (C) 2006  Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "jit-internal.h"
+#include "jit-reg-class.h"
+#include <stdarg.h>
+
+_jit_regclass_t *
+_jit_regclass_create(const char *name, int flags, int num_regs, ...)
+{
+       _jit_regclass_t *regclass;
+       va_list args;
+       int reg;
+
+       regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1));
+       if(!regclass)
+       {
+               return 0;
+       }
+       regclass->name = name;
+       regclass->flags = flags;
+       regclass->num_regs = num_regs;
+
+       va_start(args, num_regs);
+       for(reg = 0; reg < num_regs; reg++)
+       {
+               regclass->regs[reg] = va_arg(args, int);
+       }
+       va_end(args);
+
+       return regclass;
+}
+
+_jit_regclass_t *
+_jit_regclass_combine(const char *name, int flags,
+                     _jit_regclass_t *class1,
+                     _jit_regclass_t *class2)
+{
+       _jit_regclass_t *regclass;
+       int num_regs;
+
+       num_regs = class1->num_regs + class2->num_regs;
+
+       regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1));
+       if(!regclass)
+       {
+               return 0;
+       }
+       regclass->name = name;
+       regclass->flags = flags;
+       regclass->num_regs = num_regs;
+
+       jit_memcpy(regclass->regs, class1->regs, sizeof(int) * class1->num_regs);
+       jit_memcpy(regclass->regs + class1->num_regs, class2->regs, sizeof(int) * class2->num_regs);
+
+       return regclass;
+}
+
+void
+_jit_regclass_free(_jit_regclass_t *regclass)
+{
+       jit_free(regclass);
+}
diff --git a/jit/jit-reg-class.h b/jit/jit-reg-class.h
new file mode 100644 (file)
index 0000000..bbadd3a
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * jit-reg-class.h - Register class routines for the JIT.
+ *
+ * Copyright (C) 2006  Southern Storm Software, Pty Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef        _JIT_REG_CLASS_H
+#define        _JIT_REG_CLASS_H
+
+#include "jit-rules.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Information about a register class.
+ */
+typedef struct
+{
+       const char      *name;          /* Name of the register class, for debugging */
+       int             flags;          /* Register flags */
+       int             num_regs;       /* The number of registers in the class */
+       int             regs[1];        /* JIT_REG_INFO index for each register */
+
+} _jit_regclass_t;
+
+/* Create a register class.  */
+_jit_regclass_t *_jit_regclass_create(const char *name, int flags, int num_regs, ...);
+
+/* Combine two register classes into another one.  */
+_jit_regclass_t *_jit_regclass_combine(const char *name, int flags,
+                                      _jit_regclass_t *class1,
+                                      _jit_regclass_t *class2);
+
+/* Free a register class.  */
+void _jit_regclass_free(_jit_regclass_t *regclass);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif /* _JIT_REG_CLASS_H */
index 39b669d39b3de2ddad15ae96dba71c1041c1fd65..3c6e48b3f19990ed9464f255f8b33e46de9766b6 100644 (file)
@@ -44,7 +44,7 @@
 #define        X86_REG_ESP                     7
 #define        X86_REG_ST0                     8
 #define        X86_REG_ST1                     9
-#define        X85_REG_ST2                     10
+#define        X86_REG_ST2                     10
 #define        X86_REG_ST3                     11
 #define        X86_REG_ST4                     12
 #define        X86_REG_ST5                     13
 #define        ROUND_STACK(size)       \
                (((size) + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1))
 
+static _jit_regclass_t *x86_reg;
+static _jit_regclass_t *x86_breg;
+static _jit_regclass_t *x86_freg;
+static _jit_regclass_t *x86_lreg;
+
 void _jit_init_backend(void)
 {
-       /* Nothing to do here for the x86 */
+       x86_reg = _jit_regclass_create(
+               "reg", JIT_REG_WORD, 6,
+               X86_REG_EAX, X86_REG_ECX,
+               X86_REG_EDX, X86_REG_EBX,
+               X86_REG_ESI, X86_REG_EDI);
+
+       x86_breg = _jit_regclass_create(
+               "breg", JIT_REG_WORD, 4,
+               X86_REG_EAX, X86_REG_ECX,
+               X86_REG_EDX, X86_REG_EBX);
+
+       x86_freg = _jit_regclass_create(
+               "freg", JIT_REG_X86_FLOAT | JIT_REG_IN_STACK, 8,
+               X86_REG_ST0, X86_REG_ST1,
+               X86_REG_ST2, X86_REG_ST3,
+               X86_REG_ST4, X86_REG_ST5,
+               X86_REG_ST6, X86_REG_ST7);
+
+       x86_lreg = _jit_regclass_create(
+               "lreg", JIT_REG_LONG, 2,
+               X86_REG_EAX, X86_REG_ECX);
 }
 
 void _jit_gen_get_elf_info(jit_elf_info_t *info)