RPA Toolkit
RJS prop access changes... continued.
[rpatk.git] / rvm / rvmcodemap.h
1 /*
2  *  Regular Pattern Analyzer (RPA)
3  *  Copyright (c) 2009-2010 Martin Stoilov
4  *
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.
9  *
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.
14  *
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/>.
17  *
18  *  Martin Stoilov <martin@rpasearch.com>
19  */
20
21 #ifndef _RVMCODEMAP_H_
22 #define _RVMCODEMAP_H_
23
24 #include "rtypes.h"
25 #include "rvm/rvmcpu.h"
26 #include "rlib/rarray.h"
27 #include "rlib/rhash.h"
28 #include "rlib/rstring.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34
35 typedef struct rvm_codelabel_s {
36         enum {
37                 RVM_CODELABEL_OFFSET = 0,
38                 RVM_CODELABEL_POINTER,
39                 RVM_CODELABEL_INVALID,
40         } type;
41         unsigned long base;
42         ruword value;
43         rstr_t *name;
44         unsigned long size; // Optional, used for function declarations
45 } rvm_codelabel_t;
46
47
48 typedef struct rvm_codemap_s {
49         rarray_t *labels;
50         rhash_t *hash;
51 } rvm_codemap_t;
52
53
54 rvm_codemap_t *rvm_codemap_create();
55 void rvm_codemap_destroy(rvm_codemap_t *codemap);
56 void rvm_codemap_clear(rvm_codemap_t *codemap);
57 long rvm_codemap_invalid_add(rvm_codemap_t *codemap, const char *name, unsigned int namesize);
58 long rvm_codemap_invalid_add_s(rvm_codemap_t *codemap, const char *name);
59 long rvm_codemap_addoffset(rvm_codemap_t *codemap, const char *name, unsigned int namesize, unsigned long base, unsigned long offset);
60 long rvm_codemap_addoffset_s(rvm_codemap_t *codemap, const char *name, unsigned long base, unsigned long offset);
61 long rvm_codemap_addpointer(rvm_codemap_t *codemap, const char *name, unsigned int namesize, rpointer ptr);
62 long rvm_codemap_addpointer_s(rvm_codemap_t *codemap, const char *name, rpointer ptr);
63 long rvm_codemap_lookupadd(rvm_codemap_t *codemap, const char *name, unsigned int namesize);
64 long rvm_codemap_lookupadd_s(rvm_codemap_t *codemap, const char *name);
65 long rvm_codemap_lookup(rvm_codemap_t *codemap, const char *name, unsigned int namesize);
66 long rvm_codemap_lookup_s(rvm_codemap_t *codemap, const char *name);
67 long rvm_codemap_lastlabel(rvm_codemap_t *codemap);
68 rvm_codelabel_t *rvm_codemap_label(rvm_codemap_t *codemap, long index);
69 long rvm_codemap_validindex(rvm_codemap_t *codemap, long labelidx);
70 ruword rvm_codemap_resolve(rvm_codemap_t *codemap, long index, rvm_codelabel_t **err);
71 void rvm_codemap_dump(rvm_codemap_t *codemap);
72 void rvm_codelabel_setoffset(rvm_codelabel_t *label, unsigned long base, unsigned long offset);
73 void rvm_codelabel_setpointer(rvm_codelabel_t *label, rpointer ptr);
74 void rvm_codelabel_setinvalid(rvm_codelabel_t *label);
75
76 #ifdef __cplusplus
77 }
78 #endif
79
80 #endif