/* 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 «$max_args» #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 (); «repeat» template R call («A$_ a$_|, ») { return ((R (*)(«A$_|, »)) ptr ())(«a$_|, »); } «end» «repeat» template R operator ()(«A$_ a$_|, ») { call («a$_|, »); } «end» }; // 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 (); }; «repeat» template struct funbuild«$_» : funbuild { funbuild«$_» (env &e) : funbuild(e, typestr::str«, typestr::str|», (const char *)0) { } }; «end» }