RPA Toolkit
work on RVM relocation
authorMartin Stoilov <martin@rpasearch.com>
Mon, 14 Feb 2011 07:17:41 +0000 (23:17 -0800)
committerMartin Stoilov <martin@rpasearch.com>
Mon, 14 Feb 2011 07:17:41 +0000 (23:17 -0800)
13 files changed:
rast/rastnode.c
rvm/rvmcodegen.c
rvm/rvmcodemap.c
rvm/rvmcodemap.h
rvm/rvmcpu.c
rvm/rvmcpu.h
tests/asm-bl.c
tests/codegen-test.c
tests/codemap-test.c
tests/funcarg-test.c
tests/rast-test.c
tests/regex-test.c
tests/string-test.c

index 37f1ed6..c305992 100644 (file)
@@ -31,10 +31,6 @@ void r_astnode_addchild(rastnode_t *node, rastnode_t *child)
 
 void r_astnode_cleanup(robject_t *obj)
 {
-       rastnode_t *node = (rastnode_t*)obj;
-
-//     if (node->props)
-//             r_object_destroy((robject_t*)node->props);
        r_object_cleanup(obj);
 }
 
index 249e794..b05832e 100644 (file)
@@ -75,7 +75,7 @@ ruint rvm_codegen_funcstart(rvm_codegen_t *cg, const rchar* name, ruint namesize
        start = rvm_codegen_addins(cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(FP)|BIT(SP)|BIT(LR)));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, FP, SP, XX, 0));
        rvm_codegen_addins(cg, rvm_asm(RVM_ADD, SP, SP, DA, args));
-       rvm_codemap_add(cg->codemap, name, namesize, start);
+       rvm_codemap_addindex(cg->codemap, name, namesize, start);
        return start;
 }
 
@@ -93,7 +93,7 @@ ruint rvm_codegen_vargs_funcstart(rvm_codegen_t *cg, const rchar* name, ruint na
        start = rvm_codegen_addins(cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(FP)|BIT(SP)|BIT(LR)));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, FP, SP, XX, 0));
        rvm_codegen_addins(cg, rvm_asm(RVM_ADD, SP, SP, R0, 0));
-       rvm_codemap_add(cg->codemap, name, namesize, start);
+       rvm_codemap_addindex(cg->codemap, name, namesize, start);
        return start;
 }
 
index 3590af9..eaa661c 100644 (file)
@@ -79,32 +79,66 @@ static rvm_codelabel_t *rvm_codemap_dolookup(rvm_codemap_t *codemap, const rchar
 }
 
 
-
-rvm_codelabel_t *rvm_codemap_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rulong index)
+static rvm_codelabel_t *rvm_codemap_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
 {
        rvm_codelabel_t *label;
 
        label = rvm_codemap_dolookup(codemap, name, namesize);
        if (!label) {
-               label = r_malloc(sizeof(*label));
+               label = r_zmalloc(sizeof(*label));
                label->name = r_rstrdup(name, namesize);
                r_hash_insert(codemap->hash, label->name, label);
                r_array_add(codemap->labels, &label);
        }
-       label->index = index;
        return label;
 }
 
 
-rvm_codelabel_t *rvm_codemap_add_s(rvm_codemap_t *codemap, const rchar *name, rulong index)
+
+rvm_codelabel_t *rvm_codemap_addindex(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rulong index)
+{
+       rvm_codelabel_t *label = rvm_codemap_add(codemap, name, namesize);
+
+       if (label) {
+               label->loc.index = index;
+               label->type = RVM_CODELABEL_INDEX;
+       }
+       return label;
+}
+
+
+rvm_codelabel_t *rvm_codemap_addindex_s(rvm_codemap_t *codemap, const rchar *name, rulong index)
 {
-       return rvm_codemap_add(codemap, name, r_strlen(name), index);
+       return rvm_codemap_addindex(codemap, name, r_strlen(name), index);
+}
+
+
+rvm_codelabel_t *rvm_codemap_addpointer(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rvm_asmins_t *ptr)
+{
+       rvm_codelabel_t *label = rvm_codemap_add(codemap, name, namesize);
+
+       if (label) {
+               label->loc.ptr = ptr;
+               label->type = RVM_CODELABEL_POINTER;
+       }
+       return label;
+}
+
+
+rvm_codelabel_t *rvm_codemap_addpointer_s(rvm_codemap_t *codemap, const rchar *name, rvm_asmins_t *ptr)
+{
+       return rvm_codemap_addpointer(codemap, name, r_strlen(name), ptr);
 }
 
 
 rvm_codelabel_t *rvm_codemap_invalid_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
 {
-       return rvm_codemap_add(codemap, name, namesize, RVM_CODELABEL_INVALID);
+       rvm_codelabel_t *label = rvm_codemap_add(codemap, name, namesize);
+
+       if (label) {
+               label->type = RVM_CODELABEL_INVALID;
+       }
+       return label;
 }
 
 
index 58b19b0..72d51e5 100644 (file)
 extern "C" {
 #endif
 
-#define RVM_CODELABEL_INVALID ((rulong)-1)
-
-typedef struct rvm_codelabel_s {
-       rstr_t *name;
-       rulong index;
-       rulong size; // Optional, used for function declarations
-} rvm_codelabel_t;
-
-
 typedef struct rvm_loopblock_s {
        rulong begin;
        rulong size;
@@ -38,8 +29,10 @@ void rvm_codemap_destroy(rvm_codemap_t *codemap);
 void rvm_codemap_clear(rvm_codemap_t *codemap);
 rvm_codelabel_t *rvm_codemap_invalid_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize);
 rvm_codelabel_t *rvm_codemap_invalid_add_s(rvm_codemap_t *codemap, const rchar *name);
-rvm_codelabel_t *rvm_codemap_add(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rulong index);
-rvm_codelabel_t *rvm_codemap_add_s(rvm_codemap_t *codemap, const rchar *name, rulong index);
+rvm_codelabel_t *rvm_codemap_addindex(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rulong index);
+rvm_codelabel_t *rvm_codemap_addindex_s(rvm_codemap_t *codemap, const rchar *name, rulong index);
+rvm_codelabel_t *rvm_codemap_addpointer(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rvm_asmins_t *ptr);
+rvm_codelabel_t *rvm_codemap_addpointer_s(rvm_codemap_t *codemap, const rchar *name, rvm_asmins_t *ptr);
 rvm_codelabel_t *rvm_codemap_lookup(rvm_codemap_t *codemap, const rchar *name, ruint namesize);
 rvm_codelabel_t *rvm_codemap_lookup_s(rvm_codemap_t *codemap, const rchar *name);
 rvm_codelabel_t *rvm_codemap_lastlabel(rvm_codemap_t *codemap);
index 6ead029..25b5dd8 100644 (file)
@@ -26,6 +26,7 @@
 #include "rvmoperatorcast.h"
 #include "rvmoperatornot.h"
 #include "rvmoperatorlogicnot.h"
+#include "rvmcodemap.h"
 #include "rmem.h"
 #include "rstring.h"
 #include "rvmreg.h"
@@ -2115,25 +2116,6 @@ rvm_asmins_t rvm_asm2(rword opcode, rword op1, rword op2, rword op3, ruint32 p1,
 }
 
 
-
-rvm_asmins_t rvm_asmr(rword opcode, rword op1, rword op2, rword op3, rpointer pReloc)
-{
-       rvm_asmins_t a;
-
-       r_memset(&a, 0, sizeof(a));
-       a.opcode = (ruint32) RVM_ASMINS_OPCODE(opcode);
-       a.swi = (ruint32) RVM_ASMINS_SWI(opcode);
-       a.op1 = (ruint8)op1;
-       a.op2 = (ruint8)op2;
-       a.op3 = (ruint8)op3;
-       a.data.u = (rword)pReloc;
-       a.flags = RVM_ASMINS_RELOC | RVM_ASMINS_RELOCPTR;
-       a.da = 1;
-
-       return a;
-}
-
-
 rvm_asmins_t rvm_asmx(rword opcode, rword op1, rword op2, rword op3, rpointer pReloc)
 {
        rvm_asmins_t a;
@@ -2151,25 +2133,37 @@ rvm_asmins_t rvm_asmx(rword opcode, rword op1, rword op2, rword op3, rpointer pR
        return a;
 }
 
+/*
+ * On success return NULL, otherwise
+ * return a pointer to undefined label
+ */
 
-void rvm_relocate(rvm_asmins_t *code, rsize_t size)
+rvm_codelabel_t *rvm_relocate(rvm_asmins_t *code, rsize_t size)
 {
+       rvm_codelabel_t *label;
        rvm_asmins_t *reloc;
        rulong relocindex;
        rulong off;
 
+//     code->data.u = reloc - code;
+
        for (off = 0; off < size; off++, code++) {
                if (code->flags & RVM_ASMINS_RELOC) {
-                       if (code->flags & RVM_ASMINS_RELOCPTR) {
-                               reloc = *((rvm_asmins_t **)code->data.u);
+                       label = (rvm_codelabel_t *)code->data.u;
+                       if (label->type == RVM_CODELABEL_INDEX) {
+                               relocindex = label->loc.index;
+                               code->data.u = relocindex - off;
+                               code->flags &= ~RVM_ASMINS_RELOC;
+                       } else if (label->type == RVM_CODELABEL_POINTER) {
+                               reloc = label->loc.ptr;
                                code->data.u = reloc - code;
+                               code->flags &= ~RVM_ASMINS_RELOC;
                        } else {
-                               relocindex = *((rulong *)code->data.u);
-                               code->data.u = relocindex - off;
+                               return label;
                        }
-                       code->flags &= ~(RVM_ASMINS_RELOCPTR | RVM_ASMINS_RELOC);
                }
        }
+       return NULL;
 }
 
 
index 27e012c..c032655 100644 (file)
@@ -279,7 +279,6 @@ typedef struct rvm_switable_s {
 
 
 #define RVM_ASMINS_RELOC (1 << 0)
-#define RVM_ASMINS_RELOCPTR (1 << 1)
 
 struct rvm_asmins_s {
        union {
@@ -297,6 +296,22 @@ struct rvm_asmins_s {
        ruint32 flags:3;
 };
 
+
+typedef struct rvm_codelabel_s {
+       enum {
+               RVM_CODELABEL_INDEX = 0,
+               RVM_CODELABEL_POINTER,
+               RVM_CODELABEL_INVALID,
+       } type;
+       union {
+               rulong index;
+               rvm_asmins_t *ptr;
+       } loc;
+       rstr_t *name;
+       rulong size; // Optional, used for function declarations
+} rvm_codelabel_t;
+
+
 struct rvm_opmap_s;
 
 struct rvmcpu_s {
@@ -329,7 +344,7 @@ rint rvm_cpu_exec(rvmcpu_t *cpu, rvm_asmins_t *prog, rword off);
 rint rvm_cpu_exec_debug(rvmcpu_t *cpu, rvm_asmins_t *prog, rword off);
 rint rvm_cpu_getswi(rvmcpu_t *cpu, const rchar *swiname, rsize_t size);
 rint rvm_cpu_getswi_s(rvmcpu_t *cpu, const rchar *swiname);
-void rvm_relocate(rvm_asmins_t *code, rsize_t size);
+rvm_codelabel_t *rvm_relocate(rvm_asmins_t *code, rsize_t size);
 rvmreg_t *rvm_cpu_alloc_global(rvmcpu_t *cpu);
 int rvm_cpu_setreg(rvmcpu_t *cpu, rword regnum, const rvmreg_t *src);
 rvmreg_t * rvm_cpu_getreg(rvmcpu_t *cpu, rword regnum);
index 213fe86..e7321e0 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include "common.h"
+#include "rvmcodemap.h"
 
 
        
@@ -7,18 +8,20 @@ int main(int argc, char *argv[])
 {
        ruint ret = 0;
        ruint off = 0;
-       rvm_asmins_t *l_add2 = NULL, *l_add3 = NULL, *l_main = NULL;
+       rvm_codelabel_t l_add2 = {RVM_CODELABEL_POINTER};
+       rvm_codelabel_t l_add3 = {RVM_CODELABEL_POINTER};
        rvm_asmins_t vmcode[256];
        rvmcpu_t *vm = rvm_cpu_create_default();
-       
+       rvm_codemap_t *codemap = rvm_codemap_create();
+
        rvm_cpu_addswitable(vm, common_calltable);
 
-       vmcode[off++]   = rvm_asmr(RVM_B,   DA, XX, XX, &l_main);
+       vmcode[off++]   = rvm_asmx(RVM_B,   DA, XX, XX, rvm_codemap_lookup_s(codemap, "l_main"));
 
        /*
         * R0 = R0 + R1
         */
-       l_add2 = &vmcode[off];
+       l_add2.loc.ptr = &vmcode[off];
        vmcode[off++] = rvm_asm(RVM_ADD, R0, R0, R1, 0);
        vmcode[off++] = rvm_asm(RVM_RET, XX, XX, XX, 0);
 
@@ -26,12 +29,12 @@ int main(int argc, char *argv[])
        /*
         * R0 = R0 + R1 + R2
         */
-       l_add3 = &vmcode[off];
+       l_add3.loc.ptr = &vmcode[off];
        vmcode[off++] = rvm_asm(RVM_PUSHM,DA, XX, XX, BIT(R7)|BIT(R8)|BIT(SP)|BIT(LR));
        vmcode[off++] = rvm_asm(RVM_PUSH, R2, XX, XX, 0);
-       vmcode[off++] = rvm_asmr(RVM_BL,   DA, XX, XX, &l_add2);
+       vmcode[off++] = rvm_asmx(RVM_BL,   DA, XX, XX, &l_add2);
        vmcode[off++] = rvm_asm(RVM_POP,  R1, XX, XX, 0);
-       vmcode[off++] = rvm_asmr(RVM_BL,   DA, XX, XX, &l_add2);
+       vmcode[off++] = rvm_asmx(RVM_BL,   DA, XX, XX, &l_add2);
        vmcode[off++] = rvm_asm(RVM_POPM, DA, XX, XX, BIT(R7)|BIT(R8)|BIT(SP)|BIT(LR));
        vmcode[off++] = rvm_asm(RVM_RET,  XX, XX, XX, 0);
        /*
@@ -41,20 +44,18 @@ int main(int argc, char *argv[])
         *
         */
 
-
-       l_main = &vmcode[off];
+       rvm_codemap_addpointer_s(codemap, "l_main", &vmcode[off]);
        vmcode[off++] = rvm_asm(RVM_MOV, R0, DA, XX, 1);
        vmcode[off++] = rvm_asm(RVM_MOV, R1, DA, XX, 2);
-       vmcode[off++] = rvm_asmr(RVM_BL,  DA, XX, XX, &l_add2);
+       vmcode[off++] = rvm_asmx(RVM_BL,  DA, XX, XX, &l_add2);
        VMTEST_REG(vmcode, off, 0, 3, "BL/RET");
        vmcode[off++] = rvm_asm(RVM_MOV, R0, DA, XX, 1);
        vmcode[off++] = rvm_asm(RVM_MOV, R1, DA, XX, 2);
        vmcode[off++] = rvm_asm(RVM_MOV, R2, DA, XX, 4);
-       vmcode[off++] = rvm_asmr(RVM_BL,  DA, XX, XX, &l_add3);
+       vmcode[off++] = rvm_asmx(RVM_BL,  DA, XX, XX, &l_add3);
        VMTEST_REG(vmcode, off, 0, 7, "BL/RET");
        vmcode[off++] = rvm_asm(RVM_EXT, R0, XX, XX, 0);
 
-
        rvm_relocate(vmcode, off);
 #ifdef EXECDEBUG
        ret = rvm_cpu_exec_debug(vm, vmcode, 0);
@@ -62,5 +63,6 @@ int main(int argc, char *argv[])
        ret = rvm_cpu_exec(vm, vmcode, 0);
 #endif
        rvm_cpu_destroy(vm);
+       rvm_codemap_destroy(codemap);
        return 0;
 }
index 95aaac3..0a2715e 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 9));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 3 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 3));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "add3")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "add3")));
        rvm_codegen_addins(cg, rvm_asm(RVM_OPSWI(RVM_SWI_ID(ntable, 0)), R0, XX, XX, 0));
 
 
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 4));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 4 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 4));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "varadd")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "varadd")));
        rvm_codegen_addins(cg, rvm_asm(RVM_OPSWI(RVM_SWI_ID(ntable, 0)), R0, XX, XX, 0));
 
 
@@ -65,13 +65,13 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 1 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R1, SP, DA, 2 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 2));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "add2")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "add2")));
 
        rvm_codegen_addins(cg, rvm_asm(RVM_LDS, R1, FP, DA, 3));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 1 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R1, SP, DA, 2 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 2));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "add2")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "add2")));
        rvm_codegen_funcend(cg);
 
        rvm_codegen_vargs_funcstart_s(cg, "varadd");
index 99164c4..87cf2d4 100644 (file)
@@ -14,7 +14,7 @@ void codelabel_print_info(rvm_codemap_t *codemap, rchar* name)
        if (!label)
                fprintf(stdout, "%s (not found)\n", name);
        else
-               fprintf(stdout, "%s, asmins: 0x%d\n", label->name->str, (ruint)label->index);
+               fprintf(stdout, "%s, asmins: 0x%d\n", label->name->str, (ruint)label->loc.index);
 }
 
 
@@ -22,9 +22,9 @@ int main(int argc, char *argv[])
 {
        rvm_codemap_t *codemap = rvm_codemap_create();
 
-       rvm_codemap_add_s(codemap, "add2", 0);
-       rvm_codemap_add_s(codemap, "add3", 3);
-       rvm_codemap_add_s(codemap, "sub2", 7);
+       rvm_codemap_addindex_s(codemap, "add2", 0);
+       rvm_codemap_addindex_s(codemap, "add3", 3);
+       rvm_codemap_addindex_s(codemap, "sub2", 7);
 
        codelabel_print_info(codemap, "add2");
        codelabel_print_info(codemap, "add7");
index 9533005..ba48528 100644 (file)
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 1 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asm(RVM_MOV, R0, DA, XX, 8));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 2 + RVM_CODEGEN_FUNCINITOFFSET));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "add2")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "add2")));
        rvm_codegen_addins(cg, rvm_asm(RVM_OPSWI(rvm_cpu_getswi_s(cpu, "print")), R0, XX, XX, 0));
 
        rvm_codegen_addins(cg, rvm_asm(RVM_EXT, XX, XX, XX, 0));
index 0959a1c..f543b90 100644 (file)
@@ -153,8 +153,6 @@ void r_astcompiler_dumptree(rastcompiler_t *aco)
 
 int r_astcompiler_dumpnotification(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
 {
-       rastcompiler_t *aco = (rastcompiler_t *)userdata;
-
        if (reason & RPA_REASON_START)
                fprintf(stdout, "START ");
        if (reason & RPA_REASON_MATCHED)
@@ -202,8 +200,6 @@ int main(int argc, char *argv[])
        int res, i;
        rstr_t *script = NULL, *unmapscript = NULL;
        rastcompiler_t *aco = r_astcompiler_create();
-       rastnode_t *node;
-
 
        aco->dbex = rpa_dbex_create();
 
index 16d30d0..bf25c70 100644 (file)
@@ -266,6 +266,7 @@ void codegen_rpa_match(rpa_compiler_t *co)
        rvm_codegen_addins(co->cg, rvm_asm(RVM_STRR, R0, R1, XX, 0));
        l2 = rvm_codegen_getcodesize(co->cg);
        rvm_codegen_addins(co->cg, rvm_asm(RVM_B, DA, XX, XX, 0));                                                      /* Will be re-written later */
+       rvm_codemap_addindex_s(co->cg->codemap, "rpa_match", rvm_codegen_getcodesize(co->cg));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(TP)|BIT(FP)|BIT(SP)|BIT(LR)));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, FP, SP, XX, 0));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_BXL, R0, XX, XX, 0));
@@ -322,6 +323,7 @@ void codegen_rpa_match_abc(rpa_compiler_t *co)
 int main(int argc, char *argv[])
 {
        rvmcpu_t *cpu;
+       rvm_codelabel_t *unresolved;
        rpa_compiler_t *co;
        rint i;
 
@@ -366,10 +368,17 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(co->cg, rvm_asm(RVM_LDS, R4, DA, XX, rvm_scope_lookup_s(co->scope, "rpa_match")->data.offset));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_LDS, R0, DA, XX, rvm_scope_lookup_s(co->scope, "rpa_match_abc")->data.offset));
 
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_BXL, R4, XX, XX, 0));
+//     rvm_codegen_addins(co->cg, rvm_asm(RVM_BXL, R4, XX, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asmx(RVM_BL, DA, XX, XX, rvm_codemap_lookup_s(co->cg->codemap, "rpa_match")));
+
        rvm_codegen_addins(co->cg, rvm_asm(RVM_NOP, XX, XX, XX, 0xabc));
        rvm_codegen_addins(co->cg, rvm_asm(RVM_EXT, XX, XX, XX, 0));
 
+       unresolved = rvm_relocate(rvm_codegen_getcode(co->cg, 0), rvm_codegen_getcodesize(co->cg));
+       if (unresolved) {
+               fprintf(stderr, "ERROR: Undefined reference to: %s\n", unresolved->name->str);
+               goto end;
+       }
 
        if (debuginfo) {
                fprintf(stdout, "\nGenerated Code:\n");
@@ -385,7 +394,7 @@ int main(int argc, char *argv[])
                        rvm_cpu_exec(cpu, rvm_codegen_getcode(co->cg, 0), 0);
        }
 
-
+end:
        rpa_stat_destroy((rpastat_t *)cpu->userdata1);
        rvm_cpu_destroy(cpu);
 
index 8e58934..4e8f141 100644 (file)
@@ -88,14 +88,14 @@ int main(int argc, char *argv[])
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 1 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asml(RVM_MOV, R0, DA, XX, r_strlen(hello)));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 2 + RVM_CODEGEN_FUNCINITOFFSET));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "str_init")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "str_init")));
        rvm_codegen_addins(cg, rvm_asmp(RVM_MOV, R7, R0, XX, 0));
 
        rvm_codegen_addins(cg, rvm_asmp(RVM_MOV, R0, DA, XX, there));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 1 + RVM_CODEGEN_FUNCINITOFFSET));
        rvm_codegen_addins(cg, rvm_asml(RVM_MOV, R0, DA, XX, r_strlen(there)));
        rvm_codegen_addins(cg, rvm_asm(RVM_STS, R0, SP, DA, 2 + RVM_CODEGEN_FUNCINITOFFSET));
-       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, &rvm_codemap_lookup_s(cg->codemap, "str_init")->index));
+       rvm_codegen_addins(cg, rvm_asmx(RVM_BL,  DA, XX, XX, rvm_codemap_lookup_s(cg->codemap, "str_init")));
        rvm_codegen_addins(cg, rvm_asmp(RVM_MOV, R8, R0, XX, 0));
 
        rvm_codegen_addins(cg, rvm_asmp(RVM_MOV, R0, R7, XX, 0));