2 * Regular Pattern Analyzer Toolkit (RPA/Tk)
3 * Copyright (c) 2009-2012 Martin Stoilov
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Martin Stoilov <martin@rpasearch.com>
21 #ifndef _RVMCODEGEN_H_
22 #define _RVMCODEGEN_H_
25 #include "rvm/rvmerror.h"
26 #include "rlib/rarray.h"
27 #include "rlib/rhash.h"
28 #include "rvm/rvmcpu.h"
29 #include "rvm/rvmcodemap.h"
30 #include "rvm/rvmrelocmap.h"
37 #define RVM_CODEGEN_FUNCINITOFFSET 3
38 #define RVM_CODEGEN_E_NONE 0
41 typedef struct rvm_codegen_s {
44 rcarray_t *dynamicdata;
47 rvm_codemap_t *codemap;
48 rvm_relocmap_t *relocmap;
49 unsigned long cursrcidx;
50 unsigned long userdata;
54 rvm_codegen_t *rvm_codegen_create();
55 void rvm_codegen_destroy(rvm_codegen_t *cg);
56 void rvm_codegen_setsource(rvm_codegen_t *cg, unsigned long srcidx);
57 long rvm_codegen_getsource(rvm_codegen_t *cg, unsigned long codeidx);
58 unsigned int rvm_codegen_funcstart(rvm_codegen_t *cg, const char* name, unsigned int namesize, unsigned int args);
59 unsigned int rvm_codegen_funcstart_s(rvm_codegen_t *cg, const char* name, unsigned int args);
60 unsigned int rvm_codegen_vargs_funcstart(rvm_codegen_t *cg, const char* name, unsigned int namesize);
61 unsigned int rvm_codegen_vargs_funcstart_s(rvm_codegen_t *cg, const char* name);
62 void rvm_codegen_funcend(rvm_codegen_t *cg);
63 unsigned long rvm_codegen_addins(rvm_codegen_t *cg, rvm_asmins_t ins);
64 unsigned long rvm_codegen_addlabelins(rvm_codegen_t *cg, const char* name, unsigned int namesize, rvm_asmins_t ins);
65 unsigned long rvm_codegen_addlabelins_s(rvm_codegen_t *cg, const char* name, rvm_asmins_t ins);
66 unsigned long rvm_codegen_index_addrelocins(rvm_codegen_t *cg, rvm_reloctype_t type, unsigned long index, rvm_asmins_t ins);
67 unsigned long rvm_codegen_addrelocins(rvm_codegen_t *cg, rvm_reloctype_t type, const char* name, unsigned int namesize, rvm_asmins_t ins);
68 unsigned long rvm_codegen_addrelocins_s(rvm_codegen_t *cg, rvm_reloctype_t type, const char* name, rvm_asmins_t ins);
69 unsigned long rvm_codegen_insertins(rvm_codegen_t *cg, unsigned int index, rvm_asmins_t ins);
70 unsigned long rvm_codegen_replaceins(rvm_codegen_t *cg, unsigned int index, rvm_asmins_t ins);
71 rvm_asmins_t *rvm_codegen_getcode(rvm_codegen_t *cg, unsigned int index);
72 unsigned long rvm_codegen_getcodesize(rvm_codegen_t *cg);
73 void rvm_codegen_setcodesize(rvm_codegen_t *cg, unsigned int size);
74 void rvm_codegen_clear(rvm_codegen_t *cg);
75 int rvm_codegen_relocate(rvm_codegen_t *cg, rvm_codelabel_t **err);
76 long rvm_codegen_validlabel(rvm_codegen_t *cg, long index);
77 long rvm_codegen_redefinelabel(rvm_codegen_t *cg, long index, unsigned long offset);
78 long rvm_codegen_redefinelabel_default(rvm_codegen_t *cg, long index);
79 long rvm_codegen_redefinepointer(rvm_codegen_t *cg, long index, rpointer data);
80 long rvm_codegen_addlabel(rvm_codegen_t *cg, const char* name, unsigned int namesize, unsigned long offset);
81 long rvm_codegen_addlabel_s(rvm_codegen_t *cg, const char* name, unsigned long offset);
82 long rvm_codegen_addlabel_default(rvm_codegen_t *cg, const char* name, unsigned int namesize);
83 long rvm_codegen_addlabel_default_s(rvm_codegen_t *cg, const char* name);
84 long rvm_codegen_invalid_addlabel(rvm_codegen_t *cg, const char* name, unsigned int namesize);
85 long rvm_codegen_invalid_addlabel_s(rvm_codegen_t *cg, const char* name);
86 long rvm_codegen_adddata(rvm_codegen_t *cg, const char *name, unsigned int namesize, rconstpointer data, unsigned long size);
87 long rvm_codegen_adddata_s(rvm_codegen_t *cg, const char *name, rconstpointer data, unsigned long size);
88 long rvm_codegen_addstring(rvm_codegen_t *cg, const char *name, unsigned int namesize, const char* data);
89 long rvm_codegen_addstring_s(rvm_codegen_t *cg, const char *name, const char* data);
90 long rvm_codegen_add_numlabel_s(rvm_codegen_t *cg, const char *alphaname, long numname);
91 long rvm_codegen_invalid_add_numlabel_s(rvm_codegen_t *cg, const char *alphaname, long numname);