RPA Toolkit
Changed the function declaration implementation.
authorMartin Stoilov <martin@rpasearch.com>
Sun, 15 May 2011 01:05:29 +0000 (18:05 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sun, 15 May 2011 01:05:29 +0000 (18:05 -0700)
rjs/ecma262.rpa
rjs/rjs.c
rjs/rjscompiler.c
rjs/rjscompiler.h
rjs/rjsuids.h
rpa2/rpacompiler.c
rvm/rvmcodegen.c
rvm/rvmcodemap.c
rvm/rvmcodemap.h
tests/asm-bl.c
tests/codemap-test.c

index 07317fb..84a2dbe 100644 (file)
@@ -88,6 +88,7 @@
 #!emitid WhileExpressionCompare                        UID_WHILEEXPRESSIONCOMPARE                      58
 #!emitid DoWhileExpressionCompare              UID_DOWHILEEXPRESSIONCOMPARE            59
 #!emitid Program                                               UID_PROGRAM                                             60
+#!emitid FunctionNameAlloc                             UID_FUNCTIONNAMEALLOC                           61
 
 
 # 6 Source Text
@@ -427,8 +428,9 @@ DefaultClauseOp                                             ::= <DefaultKeywordOp> <S>? ':' <S>? <StatementList>?
 
 # 13 Function Definition
 FunctionName                                           ::= <IdentifierNoEmit>
-FunctionDeclaration                                    ::= ('function'-'function'<IdentifierPart>)<S>?<FunctionName><S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
-FunctionExpression                                     ::= ('function'-'function'<IdentifierPart>)<S>?<FunctionName>?<S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
+FunctionNameAlloc                                      ::= <IdentifierNoEmit>
+FunctionDeclaration                                    ::= ('function'-'function'<IdentifierPart>)<S>?<FunctionNameAlloc><S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
+FunctionExpression                                     ::= ('function'-'function'<IdentifierPart>)<S>?<FunctionNameAlloc>?<S>?'('<S>?<FormalParameterList>?<S>?')'<S>?'{'<S>?<FunctionBody>?<S>?'}'
 FormalParameterList                            ::= <FunctionParameter> ( <S>? ',' <S>? <FunctionParameter> )*
 FunctionParameter                                      ::= <IdentifierNoEmit>
 FunctionBody                                           ::= <SourceElements>
index 85fa59d..4544483 100644 (file)
--- a/rjs/rjs.c
+++ b/rjs/rjs.c
@@ -214,6 +214,8 @@ static void rjs_engine_dbgprint(rvmcpu_t *cpu, rvm_asmins_t *ins)
        else if (rvm_reg_gettype(r) == RVM_DTYPE_HARRAY)
                r_printf("(hashed array) %p\n",RVM_REG_GETP(r));
        else if (rvm_reg_gettype(r) == RVM_DTYPE_SWIID)
+               r_printf("(swi function) %p\n",RVM_REG_GETP(r));
+       else if (rvm_reg_gettype(r) == RVM_DTYPE_FUNCTION)
                r_printf("(function) %p\n",RVM_REG_GETP(r));
        else
                r_printf("%p\n", RVM_REG_GETP(r));
index 82db4c0..6d863cf 100644 (file)
@@ -101,12 +101,6 @@ static rlong rjs_compiler_record2identifer(rjs_compiler_t *co, rarray_t *records
                functx->allocs += 1;
                rvm_scope_addoffset(co->scope, prec->input, prec->inputsiz, functx->allocs);
        } else {
-//             rjs_coctx_global_t *globalctx = (rjs_coctx_global_t *)ctx;
-//             r_carray_setlength(co->cpu->data, globalctx->allocs + 1);
-//             rvm_scope_addpointer(co->scope, prec->input, prec->inputsiz, r_carray_slot(co->cpu->data, globalctx->allocs));
-
-//             rvm_scope_addpointer(co->scope, prec->input, prec->inputsiz, r_carray_slot_expand(co->cpu->data, r_carray_length(co->cpu->data)));
-//             r_carray_setlength(co->cpu->data, r_carray_length(co->cpu->data) + 1);
                rvm_scope_addpointer(co->scope, prec->input, prec->inputsiz, rvm_cpu_alloc_global(co->cpu));
        }
        v = rvm_scope_tiplookup(co->scope, prec->input, prec->inputsiz);
@@ -361,10 +355,19 @@ rint rjs_compiler_rh_identifier(rjs_compiler_t *co, rarray_t *records, rlong rec
        rjs_compiler_debughead(co, records, rec);
        v = rvm_scope_lookup(co->scope, prec->input, prec->inputsiz);
        if (!v) {
-               /*
-                * Let see if this is a swiid
-                */
-               if ((swiid = rvm_cpu_swilookup(co->cpu, NULL, prec->input, prec->inputsiz)) >= 0) {
+               if (rvm_codemap_lookup(co->cg->codemap, prec->input, prec->inputsiz) >= 0) {
+                       /*
+                        * First let see if this is a function
+                        */
+
+                       rvm_codegen_addrelocins(co->cg, RVM_RELOC_JUMP, prec->input, prec->inputsiz, rvm_asmp(RVM_MOV, R0, DA, XX, 0));
+                       rvm_codegen_addins(co->cg, rvm_asm(RVM_SETTYPE, R0, DA, XX, RVM_DTYPE_FUNCTION));
+                       goto end;
+               } else if ((swiid = rvm_cpu_swilookup(co->cpu, NULL, prec->input, prec->inputsiz)) >= 0) {
+                       /*
+                        * Let see if this is a swiid
+                        */
+
                        rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, DA, XX, swiid));
                        rvm_codegen_addins(co->cg, rvm_asm(RVM_SETTYPE, R0, DA, XX, RVM_DTYPE_SWIID));
                        goto end;
@@ -679,35 +682,50 @@ rint rjs_compiler_rh_memberexpressionindexop(rjs_compiler_t *co, rarray_t *recor
 }
 
 
+rint rjs_compiler_rh_functionnamealloc(rjs_compiler_t *co, rarray_t *records, rlong rec)
+{
+       rparecord_t *prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_coctx_function_t *ctx = (rjs_coctx_function_t*)rjs_compiler_gettopctx(co);
+
+       if (ctx->base.type != RJS_COCTX_FUNCTION) {
+               rjs_compiler_adderror(co, RJS_ERROR_NOTAFUNCTION, prec->input, prec->inputsiz);
+               return 0;
+       }
+       R_ASSERT(ctx);
+
+       rjs_compiler_debughead(co, records, rec);
+       rvm_codegen_addlabel(co->cg, prec->input, prec->inputsiz);
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_DEFAULT, ctx->allocsidx, rvm_asm(RVM_ADD, SP, FP, DA, 0));
+       rjs_compiler_debugtail(co, records, rec);
+
+       if (rjs_compiler_playchildrecords(co, records, rec) < 0)
+               return -1;
+
+       rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_compiler_debughead(co, records, rec);
+       rjs_compiler_debugtail(co, records, rec);
+       return 0;
+}
+
+
 rint rjs_compiler_rh_functiondeclaration(rjs_compiler_t *co, rarray_t *records, rlong rec)
 {
        rjs_coctx_function_t ctx;
        rparecord_t *prec;
-       rlong start, execidx, endidx, allocsidx;
 
        r_memset(&ctx, 0, sizeof(ctx));
        ctx.base.type = RJS_COCTX_FUNCTION;
 
        prec = (rparecord_t *)r_array_slot(records, rec);
        rjs_compiler_debughead(co, records, rec);
-       start = rvm_codegen_getcodesize(co->cg);
-       endidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__funend", start);
-       execidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__funexec", start);
-       allocsidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__allocs", start);
+       ctx.start = rvm_codegen_getcodesize(co->cg);
+       ctx.endidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__funend", ctx.start);
+       ctx.execidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__funexec", ctx.start);
+       ctx.allocsidx = rvm_codegen_invalid_add_numlabel_s(co->cg, "__allocs", ctx.start);
 
-       if (rpa_record_getruleuid(records, rpa_recordtree_firstchild(records, rec, RPA_RECORD_START)) == UID_FUNCTIONNAME) {
-               if (rjs_compiler_record2identifer(co, records, rpa_recordtree_firstchild(records, rec, RPA_RECORD_START)) < 0)
-                       goto error;
-               rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R1, R0, XX, 0));
-       }
-       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_JUMP, execidx, rvm_asm(RVM_MOV, R0, DA, XX, 0));
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_SETTYPE, R0, DA, XX, RVM_DTYPE_FUNCTION));
-       if (rpa_record_getruleuid(records, rpa_recordtree_firstchild(records, rec, RPA_RECORD_START)) == UID_FUNCTIONNAME) {
-               rvm_codegen_addins(co->cg, rvm_asm(RVM_STRR, R0, R1, XX, 0));
-       }
-       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, endidx, rvm_asm(RVM_B, DA, XX, XX, 0));
-       rvm_codegen_redefinelabel(co->cg, execidx);
-       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_DEFAULT, allocsidx, rvm_asm(RVM_ADD, SP, FP, DA, 0));
+       rvm_codegen_index_addrelocins(co->cg, RVM_RELOC_BRANCH, ctx.endidx, rvm_asm(RVM_B, DA, XX, XX, 0));
+       rvm_codegen_redefinelabel(co->cg, ctx.execidx);
 
        rjs_compiler_debugtail(co, records, rec);
 
@@ -721,9 +739,9 @@ rint rjs_compiler_rh_functiondeclaration(rjs_compiler_t *co, rarray_t *records,
        prec = (rparecord_t *)r_array_slot(records, rec);
        rjs_compiler_debughead(co, records, rec);
        rvm_codegen_addins(co->cg, rvm_asm(RVM_BX, LR, XX, XX, 0));
-       rvm_codegen_redefinelabel(co->cg, endidx);
+       rvm_codegen_redefinelabel(co->cg, ctx.endidx);
        rvm_codegen_addins(co->cg, rvm_asm(RVM_NOP, XX, XX, XX, 0xffffffff));
-       rvm_codegen_redefinepointer(co->cg, allocsidx, (rpointer)ctx.allocs);
+       rvm_codegen_redefinepointer(co->cg, ctx.allocsidx, (rpointer)ctx.allocs);
        rjs_compiler_debugtail(co, records, rec);
 
        rvm_scope_pop(co->scope);
@@ -1558,6 +1576,7 @@ rjs_compiler_t *rjs_compiler_create(rvmcpu_t *cpu)
        co->handlers[UID_NEWARRAYEXPRESSION] = rjs_compiler_rh_newarrayexpression;
        co->handlers[UID_MEMBEREXPRESSIONDOTOP] = rjs_compiler_rh_memberexpressiondotop;
        co->handlers[UID_MEMBEREXPRESSIONINDEXOP] = rjs_compiler_rh_memberexpressionindexop;
+       co->handlers[UID_FUNCTIONNAMEALLOC] = rjs_compiler_rh_functionnamealloc;
        co->handlers[UID_FUNCTIONDECLARATION] = rjs_compiler_rh_functiondeclaration;
        co->handlers[UID_FUNCTIONEXPRESSION] = rjs_compiler_rh_functiondeclaration;
        co->handlers[UID_FUNCTIONPARAMETER] = rjs_compiler_rh_functionparameter;
index fdf9f0d..9a3a1e7 100644 (file)
@@ -44,6 +44,10 @@ typedef struct rjs_coctx_global_s {
 
 typedef struct rjs_coctx_function_s {
        rjs_coctx_t base;
+       rlong start;
+       rlong execidx;
+       rlong endidx;
+       rlong allocsidx;
        rsize_t allocs;
 } rjs_coctx_function_t;
 
index b4079a4..a616fb5 100644 (file)
@@ -75,3 +75,4 @@
 #define UID_WHILEEXPRESSIONCOMPARE 58
 #define UID_DOWHILEEXPRESSIONCOMPARE 59
 #define UID_PROGRAM 60
+#define UID_FUNCTIONNAMEALLOC 61
index f562c39..5fe1cf8 100644 (file)
@@ -31,7 +31,7 @@ void rpa_compiler_index_reference_nan(rpa_compiler_t *co, rulong index)
 
 void rpa_compiler_reference_nan(rpa_compiler_t *co, const rchar *name, rsize_t namesize)
 {
-       rpa_compiler_index_reference_nan(co, rvm_codemap_lookup(co->cg->codemap, name, namesize));
+       rpa_compiler_index_reference_nan(co, rvm_codemap_lookupadd(co->cg->codemap, name, namesize));
 }
 
 
@@ -52,7 +52,7 @@ void rpa_compiler_index_reference_opt(rpa_compiler_t *co, rulong index)
 
 void rpa_compiler_reference_opt(rpa_compiler_t *co, const rchar *name, rsize_t namesize)
 {
-       rpa_compiler_index_reference_opt(co, rvm_codemap_lookup(co->cg->codemap, name, namesize));
+       rpa_compiler_index_reference_opt(co, rvm_codemap_lookupadd(co->cg->codemap, name, namesize));
 }
 
 
@@ -77,7 +77,7 @@ void rpa_compiler_index_reference_mul(rpa_compiler_t *co, rulong index)
 
 void rpa_compiler_reference_mul(rpa_compiler_t *co, const rchar *name, rsize_t namesize)
 {
-       rpa_compiler_index_reference_mul(co, rvm_codemap_lookup(co->cg->codemap, name, namesize));
+       rpa_compiler_index_reference_mul(co, rvm_codemap_lookupadd(co->cg->codemap, name, namesize));
 
 }
 
@@ -103,7 +103,7 @@ void rpa_compiler_index_reference_mop(rpa_compiler_t *co, rulong index)
 
 void rpa_compiler_reference_mop(rpa_compiler_t *co, const rchar *name, rsize_t namesize)
 {
-       rpa_compiler_index_reference_mop(co, rvm_codemap_lookup(co->cg->codemap, name, namesize));
+       rpa_compiler_index_reference_mop(co, rvm_codemap_lookupadd(co->cg->codemap, name, namesize));
 }
 
 
@@ -129,7 +129,7 @@ void rpa_compiler_index_reference(rpa_compiler_t *co, rulong index, ruint qflag)
 
 void rpa_compiler_reference(rpa_compiler_t *co, const rchar *name, rsize_t namesize, ruint qflag)
 {
-       rpa_compiler_index_reference(co, rvm_codemap_lookup(co->cg->codemap, name, namesize), qflag);
+       rpa_compiler_index_reference(co, rvm_codemap_lookupadd(co->cg->codemap, name, namesize), qflag);
 }
 
 
index eb85e23..1fd4453 100644 (file)
@@ -67,7 +67,7 @@ rlong rvm_codegen_redefinelabel(rvm_codegen_t *cg, rlong index)
 
        if (!label)
                return -1;
-       return rvm_codemap_addoffset(cg->codemap, label->name->str, label->name->size, rvm_codemap_lookup_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
+       return rvm_codemap_addoffset(cg->codemap, label->name->str, label->name->size, rvm_codemap_lookupadd_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
 }
 
 
@@ -89,7 +89,7 @@ rlong rvm_codegen_redefinepointer(rvm_codegen_t *cg, rlong index, rpointer data)
 
 rlong rvm_codegen_addlabel(rvm_codegen_t *cg, const rchar* name, ruint namesize)
 {
-       return rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookup_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
+       return rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookupadd_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
 }
 
 
@@ -113,7 +113,7 @@ rlong rvm_codegen_invalid_addlabel_s(rvm_codegen_t *cg, const rchar* name)
 
 ruint rvm_codegen_addlabelins(rvm_codegen_t *cg, const rchar* name, ruint namesize, rvm_asmins_t ins)
 {
-       rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookup_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
+       rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookupadd_s(cg->codemap, ".code"), RVM_CODE2BYTE_OFFSET(rvm_codegen_getcodesize(cg)));
        return rvm_codegen_addins(cg, ins);
 }
 
@@ -133,7 +133,7 @@ ruint rvm_codegen_index_addrelocins(rvm_codegen_t *cg, rvm_reloctype_t type, rul
 
 ruint rvm_codegen_addrelocins(rvm_codegen_t *cg, rvm_reloctype_t type, const rchar* name, ruint namesize, rvm_asmins_t ins)
 {
-       return rvm_codegen_index_addrelocins(cg, type, rvm_codemap_lookup(cg->codemap, name, namesize), ins);
+       return rvm_codegen_index_addrelocins(cg, type, rvm_codemap_lookupadd(cg->codemap, name, namesize), ins);
 }
 
 
@@ -171,7 +171,7 @@ ruint rvm_codegen_funcstart(rvm_codegen_t *cg, const rchar* name, ruint namesize
        start = rvm_codegen_addlabelins(cg, name, namesize, 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_addoffset(cg->codemap, name, namesize, rvm_codemap_lookup_s(cg->codemap, ".code"), start);
+//     rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookupadd_s(cg->codemap, ".code"), start);
        return start;
 }
 
@@ -189,7 +189,7 @@ ruint rvm_codegen_vargs_funcstart(rvm_codegen_t *cg, const rchar* name, ruint na
        start = rvm_codegen_addlabelins(cg, name, namesize, 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_addoffset(cg->codemap, name, namesize, rvm_codemap_lookup_s(cg->codemap, ".code"), start);
+//     rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookupadd_s(cg->codemap, ".code"), start);
        return start;
 }
 
@@ -216,7 +216,7 @@ rlong rvm_codegen_adddata(rvm_codegen_t *cg, const rchar *name, ruint namesize,
        buffer = r_array_slot(cg->data, cursize);
        r_memset(buffer, 0, size + sizeof(rword));
        r_memmove(buffer, data, size);
-       return rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookup_s(cg->codemap, ".data"), cursize);
+       return rvm_codemap_addoffset(cg->codemap, name, namesize, rvm_codemap_lookupadd_s(cg->codemap, ".data"), cursize);
 }
 
 
index 03dd17d..f97298a 100644 (file)
@@ -148,7 +148,7 @@ rlong rvm_codemap_lastlabel(rvm_codemap_t *codemap)
 }
 
 
-rlong rvm_codemap_lookup(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
+rlong rvm_codemap_lookupadd(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
 {
        rstr_t lookupstr = {(char*)name, namesize};
        rlong labelidx = r_hash_lookup_indexval(codemap->hash, &lookupstr);
@@ -159,6 +159,21 @@ rlong rvm_codemap_lookup(rvm_codemap_t *codemap, const rchar *name, ruint namesi
 }
 
 
+rlong rvm_codemap_lookupadd_s(rvm_codemap_t *codemap, const rchar *name)
+{
+       return rvm_codemap_lookupadd(codemap, name, r_strlen(name));
+}
+
+
+rlong rvm_codemap_lookup(rvm_codemap_t *codemap, const rchar *name, ruint namesize)
+{
+       rstr_t lookupstr = {(char*)name, namesize};
+       rlong labelidx = r_hash_lookup_indexval(codemap->hash, &lookupstr);
+
+       return labelidx;
+}
+
+
 rlong rvm_codemap_lookup_s(rvm_codemap_t *codemap, const rchar *name)
 {
        return rvm_codemap_lookup(codemap, name, r_strlen(name));
index 37aa7a6..9e4463d 100644 (file)
@@ -40,6 +40,8 @@ rlong rvm_codemap_addoffset(rvm_codemap_t *codemap, const rchar *name, ruint nam
 rlong rvm_codemap_addoffset_s(rvm_codemap_t *codemap, const rchar *name, rulong base, rulong offset);
 rlong rvm_codemap_addpointer(rvm_codemap_t *codemap, const rchar *name, ruint namesize, rpointer ptr);
 rlong rvm_codemap_addpointer_s(rvm_codemap_t *codemap, const rchar *name, rpointer ptr);
+rlong rvm_codemap_lookupadd(rvm_codemap_t *codemap, const rchar *name, ruint namesize);
+rlong rvm_codemap_lookupadd_s(rvm_codemap_t *codemap, const rchar *name);
 rlong rvm_codemap_lookup(rvm_codemap_t *codemap, const rchar *name, ruint namesize);
 rlong rvm_codemap_lookup_s(rvm_codemap_t *codemap, const rchar *name);
 rlong rvm_codemap_lastlabel(rvm_codemap_t *codemap);
index 34fbdfc..f5b1fff 100644 (file)
@@ -17,13 +17,13 @@ int main(int argc, char *argv[])
 
        rvm_cpu_addswitable(vm, "common_table", common_calltable);
 
-       rvm_relocmap_add(relocmap, RVM_RELOC_BRANCH, off, rvm_codemap_lookup_s(codemap, "l_main"));
+       rvm_relocmap_add(relocmap, RVM_RELOC_BRANCH, off, rvm_codemap_lookupadd_s(codemap, "l_main"));
        vmcode[off++]   = rvm_asm(RVM_B,   DA, XX, XX, 0);
 
        /*
         * R0 = R0 + R1
         */
-       rvm_codemap_addoffset_s(codemap, "l_add2", rvm_codemap_lookup_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(off));
+       rvm_codemap_addoffset_s(codemap, "l_add2", rvm_codemap_lookupadd_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(off));
        vmcode[off++] = rvm_asm(RVM_ADD, R0, R0, R1, 0);
        vmcode[off++] = rvm_asm(RVM_RET, XX, XX, XX, 0);
 
@@ -31,13 +31,13 @@ int main(int argc, char *argv[])
        /*
         * R0 = R0 + R1 + R2
         */
-       rvm_codemap_addoffset_s(codemap, "l_add3", rvm_codemap_lookup_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(off));
+       rvm_codemap_addoffset_s(codemap, "l_add3", rvm_codemap_lookupadd_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(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);
-       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookup_s(codemap, "l_add2"));
+       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookupadd_s(codemap, "l_add2"));
        vmcode[off++] = rvm_asm(RVM_BXL,   DA, XX, XX, 0);
        vmcode[off++] = rvm_asm(RVM_POP,  R1, XX, XX, 0);
-       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookup_s(codemap, "l_add2"));
+       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookupadd_s(codemap, "l_add2"));
        vmcode[off++] = rvm_asm(RVM_BXL,   DA, XX, XX, 0);
        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);
@@ -48,16 +48,16 @@ int main(int argc, char *argv[])
         *
         */
 
-       rvm_codemap_addoffset_s(codemap, "l_main", rvm_codemap_lookup_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(off));
+       rvm_codemap_addoffset_s(codemap, "l_main", rvm_codemap_lookupadd_s(codemap, ".code"), RVM_CODE2BYTE_OFFSET(off));
        vmcode[off++] = rvm_asm(RVM_MOV, R0, DA, XX, 1);
        vmcode[off++] = rvm_asm(RVM_MOV, R1, DA, XX, 2);
-       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookup_s(codemap, "l_add2"));
+       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookupadd_s(codemap, "l_add2"));
        vmcode[off++] = rvm_asm(RVM_BXL,  DA, XX, XX, 0);
        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);
-       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookup_s(codemap, "l_add3"));
+       rvm_relocmap_add(relocmap, RVM_RELOC_JUMP, off, rvm_codemap_lookupadd_s(codemap, "l_add3"));
        vmcode[off++] = rvm_asm(RVM_BXL,  DA, XX, XX, 0);
        VMTEST_REG(vmcode, off, 0, 7, "BL/RET");
        vmcode[off++] = rvm_asm(RVM_EXT, R0, XX, XX, 0);
index 87df267..01c4528 100644 (file)
@@ -21,9 +21,9 @@ int main(int argc, char *argv[])
 {
        rvm_codemap_t *codemap = rvm_codemap_create();
 
-       rvm_codemap_addoffset_s(codemap, "add2", rvm_codemap_lookup_s(codemap, ".code"), 0);
-       rvm_codemap_addoffset_s(codemap, "add3", rvm_codemap_lookup_s(codemap, ".code"), 3);
-       rvm_codemap_addoffset_s(codemap, "sub2", rvm_codemap_lookup_s(codemap, ".code"), 7);
+       rvm_codemap_addoffset_s(codemap, "add2", rvm_codemap_lookupadd_s(codemap, ".code"), 0);
+       rvm_codemap_addoffset_s(codemap, "add3", rvm_codemap_lookupadd_s(codemap, ".code"), 3);
+       rvm_codemap_addoffset_s(codemap, "sub2", rvm_codemap_lookupadd_s(codemap, ".code"), 7);
 
        codelabel_print_info(codemap, "add2");
        codelabel_print_info(codemap, "add7");