ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libcpjit/cpjit.h.PL
Revision: 1.12
Committed: Fri Oct 14 02:29:59 2005 UTC (21 years ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!/usr/bin/perl
2    
3     # create cpjit.h
4    
5     open STDOUT, ">cpjit.h"
6     or die "cpijit.h: $!";
7    
8 root 1.6 $CPJIT_MAX_ARGS = 9;
9    
10 root 1.1 print <<EOF;
11 root 1.6 #line 12 "cpjit.h.PL"
12 root 1.1 /*
13 root 1.2 This file is AUTOMAGICALLY created by cpjit.h.PL. Modifications will
14     be lost.
15    
16 root 1.1 cpjit.h -- c portable jit in time compiler
17 root 1.8 Copyright (C) 2005 Marc Lehmann <cpjit\@schmorp.de>
18 root 1.1
19     This file is part of libcpjit.
20    
21     libcpjit is free software; you can redistribute it and/or modify
22     it under the terms of the GNU General Public License as published by
23     the Free Software Foundation; either version 2 of the License, or
24     (at your option) any later version.
25    
26     This program is distributed in the hope that it will be useful,
27     but WITHOUT ANY WARRANTY; without even the implied warranty of
28     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29     GNU General Public License for more details.
30    
31     You should have received a copy of the GNU General Public License
32     along with gvpe; if not, write to the Free Software
33     Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34     */
35    
36 root 1.3 #include <string>
37 root 1.6 #include <sstream>
38 root 1.4 #include <inttypes.h>
39 root 1.3
40 root 1.1 namespace cpjit
41     {
42    
43 root 1.6 #define CPJIT_MAX_ARGS $CPJIT_MAX_ARGS
44     #define CPJIT_NULLID ""
45    
46 root 1.5 // environment for persistent or temporary storage
47     struct env
48     {
49 root 1.12 std::string path, idxpath;
50 root 1.7 bool temporary;
51 root 1.10 int idxfd;
52 root 1.12 long idxstamp;
53 root 1.7
54 root 1.10 void dolock (bool lock);
55     void lock ();
56     void unlock ();
57    
58     void load_index ();
59     void save_index ();
60    
61     public:
62 root 1.7 env (const std::string &path = CPJIT_NULLID, bool temporary = true);
63     ~env ();
64 root 1.10
65 root 1.11 // completely delete the environment on disk
66     void clear ();
67 root 1.5 };
68    
69 root 1.6 struct fun
70 root 1.5 {
71     env &e;
72 root 1.11 std::string id, source;
73 root 1.7 void *funptr;
74 root 1.6
75 root 1.11 fun (env &e, const std::string &id, const std::string &source);
76 root 1.5
77 root 1.6 // is compiled function available?
78 root 1.7 bool compiled ()
79     {
80     return funptr;
81     }
82 root 1.6
83 root 1.7 // returns the function pointer
84 root 1.5 void *ptr ();
85     };
86    
87 root 1.6 struct funbuild : std::ostringstream
88 root 1.5 {
89 root 1.6 env &e;
90 root 1.11 std::string retlist, arglist;
91 root 1.6
92 root 1.11 funbuild (env &e, const char *rettype, ...);
93     void finish (std::string &id, std::string &source);
94 root 1.5 };
95 root 1.2
96 root 1.5 typedef unsigned char U8;
97     typedef signed char I8;
98     typedef uint16_t U16;
99     typedef int16_t I16;
100     typedef uint32_t U32;
101     typedef int32_t I32;
102     typedef uint64_t U64;
103     typedef int64_t I64;
104 root 1.9 typedef float FLT;
105     typedef double DBL;
106 root 1.7 typedef void * PTR;
107 root 1.5
108     template<typename T> struct typestr { };
109    
110     template<> struct typestr<U8 > { static const char str[]; };
111     template<> struct typestr<U16 > { static const char str[]; };
112     template<> struct typestr<U32 > { static const char str[]; };
113     template<> struct typestr<U64 > { static const char str[]; };
114     template<> struct typestr<I8 > { static const char str[]; };
115     template<> struct typestr<I16 > { static const char str[]; };
116     template<> struct typestr<I32 > { static const char str[]; };
117     template<> struct typestr<I64 > { static const char str[]; };
118 root 1.9 template<> struct typestr<FLT > { static const char str[]; };
119     template<> struct typestr<DBL > { static const char str[]; };
120 root 1.7 template<> struct typestr<PTR > { static const char str[]; };
121 root 1.5 template<> struct typestr<U8 *> { static const char str[]; };
122     template<> struct typestr<U16 *> { static const char str[]; };
123     template<> struct typestr<U32 *> { static const char str[]; };
124     template<> struct typestr<U64 *> { static const char str[]; };
125     template<> struct typestr<I8 *> { static const char str[]; };
126     template<> struct typestr<I16 *> { static const char str[]; };
127     template<> struct typestr<I32 *> { static const char str[]; };
128     template<> struct typestr<I64 *> { static const char str[]; };
129 root 1.9 template<> struct typestr<FLT *> { static const char str[]; };
130     template<> struct typestr<DBL *> { static const char str[]; };
131 root 1.2
132 root 1.6 EOF
133    
134     for (0 .. $CPJIT_MAX_ARGS) {
135     print <<EOF;
136 root 1.11 #line 133 "cpjit.h.PL"
137 root 1.6
138     template<typename R${\( join "", map ", typename A$_", 1..$_ )}>
139     struct fun$_ : fun
140     {
141 root 1.11 fun$_ (env &e, const std::string &id, const std::string &source)
142     : fun(e, id, source)
143 root 1.6 {
144     }
145    
146     int operator ()(${\( join ", ", map "A$_ a$_", 1..$_ )})
147     {
148     return ((R (*)(${\( join ", ", map "A$_", 1..$_ )})) ptr ())(${\( join ", ", map "a$_", 1..$_ )});
149     }
150     };
151    
152     template<typename R${\( join "", map ", typename A$_", 1..$_ )}>
153     struct funbuild$_ : funbuild
154 root 1.5 {
155 root 1.11 funbuild$_ (env &e)
156     : funbuild(e, typestr<R>::str${\( join "", map ", typestr<A$_>::str", 1..$_ )}, (const char *)0)
157 root 1.2 {
158 root 1.5 }
159 root 1.3
160 root 1.6 fun$_<R${\( join "", map ", A$_", 1..$_ )}> *get ()
161 root 1.2 {
162 root 1.11 std::string id, source;
163     finish (id, source);
164     return new fun$_<R${\( join "", map ", A$_", 1..$_ )}> (e, id, source);
165 root 1.5 }
166     };
167 root 1.3
168 root 1.1 EOF
169 root 1.6 }
170 root 1.1
171     print <<EOF;
172     }
173     EOF
174