… | |
… | |
22 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <string> |
25 | #include <string> |
26 | #include <sstream> |
26 | #include <sstream> |
|
|
27 | #include <map> |
|
|
28 | #include <vector> |
|
|
29 | |
27 | #include <inttypes.h> |
30 | #include <inttypes.h> |
28 | |
31 | |
29 | namespace cpjit |
32 | namespace cpjit |
30 | { |
33 | { |
31 | |
34 | |
… | |
… | |
37 | { |
40 | { |
38 | std::string path, idxpath; |
41 | std::string path, idxpath; |
39 | bool temporary; |
42 | bool temporary; |
40 | int idxfd; |
43 | int idxfd; |
41 | long idxstamp; |
44 | long idxstamp; |
|
|
45 | int nextid; |
42 | |
46 | |
43 | void dolock (bool lock); |
47 | void dolock (bool lock); |
44 | void lock (); |
48 | void lock (); |
45 | void unlock (); |
49 | void unlock (); |
46 | |
50 | |
47 | void load_index (); |
51 | bool load_index (); |
48 | void save_index (); |
52 | void save_index (); |
49 | |
53 | |
|
|
54 | std::map<std::string, std::string> id2file; // id to object/sofile mapping (or empty) |
|
|
55 | std::map<std::string, void *> file2so; // file to loaded so handle |
|
|
56 | std::vector< std::pair<std::string, std::string> > fragments; // not-yet-compiled sources |
|
|
57 | |
|
|
58 | void register_fragment (const std::string &id, const std::string &source); |
|
|
59 | void *dlsym (const std::string &id, const char *symbol); |
|
|
60 | void *sym (const std::string &id, const char *symbol); |
|
|
61 | |
50 | public: |
62 | public: |
51 | env (const std::string &path = CPJIT_NULLID, bool temporary = true); |
63 | env (const std::string &path = CPJIT_NULLID, bool temporary = false); |
52 | ~env (); |
64 | ~env (); |
53 | |
65 | |
54 | // compact all fragments && invalidate ALL pointers |
66 | // compact all fragments && invalidate ALL pointers |
55 | void compact (); |
67 | void compact (); |
56 | // completely delete the environment on disk |
68 | // completely delete the environment on disk |
… | |
… | |
58 | }; |
70 | }; |
59 | |
71 | |
60 | struct fun |
72 | struct fun |
61 | { |
73 | { |
62 | env &e; |
74 | env &e; |
63 | std::string id, source; |
75 | std::string id; |
64 | void *funptr; |
76 | void *funptr; |
65 | |
77 | |
66 | fun (env &e, const std::string &id, const std::string &source); |
78 | fun (env &e, const std::string &id, const std::string &source); |
67 | |
79 | |
68 | // is compiled function available? |
80 | // is compiled function available? |