/* This file is AUTOMAGICALLY created by cpjit.h.in. Modifications in cpjit.h will be lost. cpjit.h -- c portable jit in time compiler Copyright (C) 2005 Marc Lehmann This file is part of libcpjit. libcpjit is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with gvpe; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include namespace cpjit { #define CPJIT_MAX_ARGS 9 #define CPJIT_NULLID "" typedef unsigned char U8; typedef signed char I8; typedef uint16_t U16; typedef int16_t I16; typedef uint32_t U32; typedef int32_t I32; typedef uint64_t U64; typedef int64_t I64; typedef float FLT; typedef double DBL; typedef void * PTR; template struct typestr { }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; template<> struct typestr { static const char str[]; }; typedef std::string funid; // the source of a function struct funsrc { funid id; // the unique id (md5 of source) std::set hdrlist; // any unique headers std::string retlist; // the return type std::string arglist; // the argument declaration std::string body; // the function body funsrc (); void update_id (const char *pfx); }; struct fun { struct env &e; funid id; void *funptr; fun (env &e, const funid &id); // is compiled function available? bool compiled () { return funptr; } // returns the function pointer void *ptr (); #line 110 "cpjit.h.in" template R call () { return ((R (*)()) ptr ())(); } #line 110 "cpjit.h.in" template R call (A1 a1) { return ((R (*)(A1)) ptr ())(a1); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2) { return ((R (*)(A1, A2)) ptr ())(a1, a2); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3) { return ((R (*)(A1, A2, A3)) ptr ())(a1, a2, a3); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4) { return ((R (*)(A1, A2, A3, A4)) ptr ())(a1, a2, a3, a4); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { return ((R (*)(A1, A2, A3, A4, A5)) ptr ())(a1, a2, a3, a4, a5); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { return ((R (*)(A1, A2, A3, A4, A5, A6)) ptr ())(a1, a2, a3, a4, a5, a6); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { return ((R (*)(A1, A2, A3, A4, A5, A6, A7)) ptr ())(a1, a2, a3, a4, a5, a6, a7); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8); } #line 110 "cpjit.h.in" template R call (A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8, a9); } #line 116 "cpjit.h.in" #line 118 "cpjit.h.in" template R operator ()() { call (); } #line 118 "cpjit.h.in" template R operator ()(A1 a1) { call (a1); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2) { call (a1, a2); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3) { call (a1, a2, a3); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4) { call (a1, a2, a3, a4); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) { call (a1, a2, a3, a4, a5); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) { call (a1, a2, a3, a4, a5, a6); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) { call (a1, a2, a3, a4, a5, a6, a7); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) { call (a1, a2, a3, a4, a5, a6, a7, a8); } #line 118 "cpjit.h.in" template R operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) { call (a1, a2, a3, a4, a5, a6, a7, a8, a9); } #line 124 "cpjit.h.in" }; // environment for persistent or temporary storage struct env { std::string path, idxpath; bool temporary; int idxfd; long idxstamp; int nextid; void dolock (bool lock); void lock (); void unlock (); bool load_index (); void save_index (); std::map id2file; // id to object/sofile mapping (or empty) std::map file2so; // file to loaded so handle std::vector fragments; // not-yet-compiled sources // std::set funs; // should go away void register_fragment (const funsrc &frag); void *dlsym (const std::string &id, const char *symbol); void *sym (const std::string &id, const char *symbol); public: env (const std::string &path = CPJIT_NULLID, bool temporary = false); ~env (); struct fun *get (funid id); // compact all fragments && invalidate ALL pointers void compact (); // completely delete the environment on disk void clear (); }; struct funbuild : funsrc { std::ostringstream bodystream; env &e; funbuild (env &e, const char *rettype, ...); void header (const std::string &hdr); funbuild &operator <<(const char *src); funbuild &operator <<(const std::string &src); fun *get (); }; #line 179 "cpjit.h.in" template struct funbuild0 : funbuild { funbuild0 (env &e) : funbuild(e, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild1 : funbuild { funbuild1 (env &e) : funbuild(e, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild2 : funbuild { funbuild2 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild3 : funbuild { funbuild3 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild4 : funbuild { funbuild4 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild5 : funbuild { funbuild5 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild6 : funbuild { funbuild6 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild7 : funbuild { funbuild7 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild8 : funbuild { funbuild8 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 179 "cpjit.h.in" template struct funbuild9 : funbuild { funbuild9 (env &e) : funbuild(e, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, typestr::str, (const char *)0) { } }; #line 188 "cpjit.h.in" }