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

File Contents

# User Rev Content
1 root 1.8 #line 12 "cpjit.h.PL"
2 root 1.2 /*
3 root 1.5 This file is AUTOMAGICALLY created by cpjit.h.PL. Modifications will
4     be lost.
5    
6 root 1.2 cpjit.h -- c portable jit in time compiler
7 root 1.10 Copyright (C) 2005 Marc Lehmann <cpjit@schmorp.de>
8 root 1.2
9     This file is part of libcpjit.
10    
11     libcpjit is free software; you can redistribute it and/or modify
12     it under the terms of the GNU General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15    
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     GNU General Public License for more details.
20    
21     You should have received a copy of the GNU General Public License
22     along with gvpe; if not, write to the Free Software
23     Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24     */
25 root 1.3
26 root 1.6 #include <string>
27 root 1.8 #include <sstream>
28 root 1.7 #include <inttypes.h>
29 root 1.6
30 root 1.3 namespace cpjit
31     {
32    
33 root 1.8 #define CPJIT_MAX_ARGS 9
34     #define CPJIT_NULLID ""
35    
36 root 1.7 // environment for persistent or temporary storage
37     struct env
38     {
39 root 1.14 std::string path, idxpath;
40 root 1.9 bool temporary;
41 root 1.12 int idxfd;
42 root 1.14 long idxstamp;
43 root 1.9
44 root 1.12 void dolock (bool lock);
45     void lock ();
46     void unlock ();
47    
48     void load_index ();
49     void save_index ();
50    
51     public:
52 root 1.9 env (const std::string &path = CPJIT_NULLID, bool temporary = true);
53     ~env ();
54 root 1.12
55 root 1.13 // completely delete the environment on disk
56     void clear ();
57 root 1.7 };
58    
59 root 1.8 struct fun
60 root 1.7 {
61     env &e;
62 root 1.13 std::string id, source;
63 root 1.9 void *funptr;
64 root 1.8
65 root 1.13 fun (env &e, const std::string &id, const std::string &source);
66 root 1.8
67     // is compiled function available?
68 root 1.9 bool compiled ()
69     {
70     return funptr;
71     }
72 root 1.7
73 root 1.9 // returns the function pointer
74 root 1.7 void *ptr ();
75     };
76    
77 root 1.8 struct funbuild : std::ostringstream
78 root 1.7 {
79 root 1.8 env &e;
80 root 1.13 std::string retlist, arglist;
81 root 1.8
82 root 1.13 funbuild (env &e, const char *rettype, ...);
83     void finish (std::string &id, std::string &source);
84 root 1.7 };
85 root 1.5
86 root 1.7 typedef unsigned char U8;
87     typedef signed char I8;
88     typedef uint16_t U16;
89     typedef int16_t I16;
90     typedef uint32_t U32;
91     typedef int32_t I32;
92     typedef uint64_t U64;
93     typedef int64_t I64;
94 root 1.11 typedef float FLT;
95     typedef double DBL;
96 root 1.9 typedef void * PTR;
97 root 1.7
98     template<typename T> struct typestr { };
99    
100     template<> struct typestr<U8 > { static const char str[]; };
101     template<> struct typestr<U16 > { static const char str[]; };
102     template<> struct typestr<U32 > { static const char str[]; };
103     template<> struct typestr<U64 > { static const char str[]; };
104     template<> struct typestr<I8 > { static const char str[]; };
105     template<> struct typestr<I16 > { static const char str[]; };
106     template<> struct typestr<I32 > { static const char str[]; };
107     template<> struct typestr<I64 > { static const char str[]; };
108 root 1.11 template<> struct typestr<FLT > { static const char str[]; };
109     template<> struct typestr<DBL > { static const char str[]; };
110 root 1.9 template<> struct typestr<PTR > { static const char str[]; };
111 root 1.7 template<> struct typestr<U8 *> { static const char str[]; };
112     template<> struct typestr<U16 *> { static const char str[]; };
113     template<> struct typestr<U32 *> { static const char str[]; };
114     template<> struct typestr<U64 *> { static const char str[]; };
115     template<> struct typestr<I8 *> { static const char str[]; };
116     template<> struct typestr<I16 *> { static const char str[]; };
117     template<> struct typestr<I32 *> { static const char str[]; };
118     template<> struct typestr<I64 *> { static const char str[]; };
119 root 1.11 template<> struct typestr<FLT *> { static const char str[]; };
120     template<> struct typestr<DBL *> { static const char str[]; };
121 root 1.5
122 root 1.13 #line 133 "cpjit.h.PL"
123 root 1.8
124     template<typename R>
125     struct fun0 : fun
126     {
127 root 1.13 fun0 (env &e, const std::string &id, const std::string &source)
128     : fun(e, id, source)
129 root 1.8 {
130     }
131    
132     int operator ()()
133     {
134     return ((R (*)()) ptr ())();
135     }
136     };
137    
138     template<typename R>
139     struct funbuild0 : funbuild
140     {
141 root 1.13 funbuild0 (env &e)
142     : funbuild(e, typestr<R>::str, (const char *)0)
143 root 1.8 {
144     }
145    
146     fun0<R> *get ()
147     {
148 root 1.13 std::string id, source;
149     finish (id, source);
150     return new fun0<R> (e, id, source);
151 root 1.8 }
152     };
153    
154 root 1.13 #line 133 "cpjit.h.PL"
155 root 1.8
156 root 1.7 template<typename R, typename A1>
157 root 1.8 struct fun1 : fun
158 root 1.7 {
159 root 1.13 fun1 (env &e, const std::string &id, const std::string &source)
160     : fun(e, id, source)
161 root 1.5 {
162 root 1.7 }
163 root 1.6
164 root 1.7 int operator ()(A1 a1)
165 root 1.5 {
166 root 1.8 return ((R (*)(A1)) ptr ())(a1);
167     }
168     };
169    
170     template<typename R, typename A1>
171     struct funbuild1 : funbuild
172     {
173 root 1.13 funbuild1 (env &e)
174     : funbuild(e, typestr<R>::str, typestr<A1>::str, (const char *)0)
175 root 1.8 {
176     }
177    
178     fun1<R, A1> *get ()
179     {
180 root 1.13 std::string id, source;
181     finish (id, source);
182     return new fun1<R, A1> (e, id, source);
183 root 1.8 }
184     };
185    
186 root 1.13 #line 133 "cpjit.h.PL"
187 root 1.8
188     template<typename R, typename A1, typename A2>
189     struct fun2 : fun
190     {
191 root 1.13 fun2 (env &e, const std::string &id, const std::string &source)
192     : fun(e, id, source)
193 root 1.8 {
194     }
195    
196     int operator ()(A1 a1, A2 a2)
197     {
198     return ((R (*)(A1, A2)) ptr ())(a1, a2);
199     }
200     };
201    
202     template<typename R, typename A1, typename A2>
203     struct funbuild2 : funbuild
204     {
205 root 1.13 funbuild2 (env &e)
206     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, (const char *)0)
207 root 1.8 {
208     }
209    
210     fun2<R, A1, A2> *get ()
211     {
212 root 1.13 std::string id, source;
213     finish (id, source);
214     return new fun2<R, A1, A2> (e, id, source);
215 root 1.8 }
216     };
217    
218 root 1.13 #line 133 "cpjit.h.PL"
219 root 1.8
220     template<typename R, typename A1, typename A2, typename A3>
221     struct fun3 : fun
222     {
223 root 1.13 fun3 (env &e, const std::string &id, const std::string &source)
224     : fun(e, id, source)
225 root 1.8 {
226     }
227    
228     int operator ()(A1 a1, A2 a2, A3 a3)
229     {
230     return ((R (*)(A1, A2, A3)) ptr ())(a1, a2, a3);
231     }
232     };
233    
234     template<typename R, typename A1, typename A2, typename A3>
235     struct funbuild3 : funbuild
236     {
237 root 1.13 funbuild3 (env &e)
238     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, (const char *)0)
239 root 1.8 {
240     }
241    
242     fun3<R, A1, A2, A3> *get ()
243     {
244 root 1.13 std::string id, source;
245     finish (id, source);
246     return new fun3<R, A1, A2, A3> (e, id, source);
247 root 1.8 }
248     };
249    
250 root 1.13 #line 133 "cpjit.h.PL"
251 root 1.8
252     template<typename R, typename A1, typename A2, typename A3, typename A4>
253     struct fun4 : fun
254     {
255 root 1.13 fun4 (env &e, const std::string &id, const std::string &source)
256     : fun(e, id, source)
257 root 1.8 {
258     }
259    
260     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4)
261     {
262     return ((R (*)(A1, A2, A3, A4)) ptr ())(a1, a2, a3, a4);
263     }
264     };
265    
266     template<typename R, typename A1, typename A2, typename A3, typename A4>
267     struct funbuild4 : funbuild
268     {
269 root 1.13 funbuild4 (env &e)
270     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, (const char *)0)
271 root 1.8 {
272     }
273    
274     fun4<R, A1, A2, A3, A4> *get ()
275     {
276 root 1.13 std::string id, source;
277     finish (id, source);
278     return new fun4<R, A1, A2, A3, A4> (e, id, source);
279 root 1.8 }
280     };
281    
282 root 1.13 #line 133 "cpjit.h.PL"
283 root 1.8
284     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5>
285     struct fun5 : fun
286     {
287 root 1.13 fun5 (env &e, const std::string &id, const std::string &source)
288     : fun(e, id, source)
289 root 1.8 {
290     }
291    
292     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
293     {
294     return ((R (*)(A1, A2, A3, A4, A5)) ptr ())(a1, a2, a3, a4, a5);
295     }
296     };
297    
298     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5>
299     struct funbuild5 : funbuild
300     {
301 root 1.13 funbuild5 (env &e)
302     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, (const char *)0)
303 root 1.8 {
304     }
305    
306     fun5<R, A1, A2, A3, A4, A5> *get ()
307     {
308 root 1.13 std::string id, source;
309     finish (id, source);
310     return new fun5<R, A1, A2, A3, A4, A5> (e, id, source);
311 root 1.8 }
312     };
313    
314 root 1.13 #line 133 "cpjit.h.PL"
315 root 1.8
316     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
317     struct fun6 : fun
318     {
319 root 1.13 fun6 (env &e, const std::string &id, const std::string &source)
320     : fun(e, id, source)
321 root 1.8 {
322     }
323    
324     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
325     {
326     return ((R (*)(A1, A2, A3, A4, A5, A6)) ptr ())(a1, a2, a3, a4, a5, a6);
327     }
328     };
329    
330     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
331     struct funbuild6 : funbuild
332     {
333 root 1.13 funbuild6 (env &e)
334     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, typestr<A6>::str, (const char *)0)
335 root 1.8 {
336     }
337    
338     fun6<R, A1, A2, A3, A4, A5, A6> *get ()
339     {
340 root 1.13 std::string id, source;
341     finish (id, source);
342     return new fun6<R, A1, A2, A3, A4, A5, A6> (e, id, source);
343 root 1.8 }
344     };
345    
346 root 1.13 #line 133 "cpjit.h.PL"
347 root 1.8
348     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
349     struct fun7 : fun
350     {
351 root 1.13 fun7 (env &e, const std::string &id, const std::string &source)
352     : fun(e, id, source)
353 root 1.8 {
354     }
355    
356     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
357     {
358     return ((R (*)(A1, A2, A3, A4, A5, A6, A7)) ptr ())(a1, a2, a3, a4, a5, a6, a7);
359     }
360     };
361    
362     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
363     struct funbuild7 : funbuild
364     {
365 root 1.13 funbuild7 (env &e)
366     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, typestr<A6>::str, typestr<A7>::str, (const char *)0)
367 root 1.8 {
368     }
369    
370     fun7<R, A1, A2, A3, A4, A5, A6, A7> *get ()
371     {
372 root 1.13 std::string id, source;
373     finish (id, source);
374     return new fun7<R, A1, A2, A3, A4, A5, A6, A7> (e, id, source);
375 root 1.8 }
376     };
377    
378 root 1.13 #line 133 "cpjit.h.PL"
379 root 1.8
380     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
381     struct fun8 : fun
382     {
383 root 1.13 fun8 (env &e, const std::string &id, const std::string &source)
384     : fun(e, id, source)
385 root 1.8 {
386     }
387    
388     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
389     {
390     return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8);
391     }
392     };
393    
394     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
395     struct funbuild8 : funbuild
396     {
397 root 1.13 funbuild8 (env &e)
398     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, typestr<A6>::str, typestr<A7>::str, typestr<A8>::str, (const char *)0)
399 root 1.8 {
400     }
401    
402     fun8<R, A1, A2, A3, A4, A5, A6, A7, A8> *get ()
403     {
404 root 1.13 std::string id, source;
405     finish (id, source);
406     return new fun8<R, A1, A2, A3, A4, A5, A6, A7, A8> (e, id, source);
407 root 1.8 }
408     };
409    
410 root 1.13 #line 133 "cpjit.h.PL"
411 root 1.8
412     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
413     struct fun9 : fun
414     {
415 root 1.13 fun9 (env &e, const std::string &id, const std::string &source)
416     : fun(e, id, source)
417 root 1.8 {
418     }
419    
420     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
421     {
422     return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8, a9);
423     }
424     };
425    
426     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
427     struct funbuild9 : funbuild
428     {
429 root 1.13 funbuild9 (env &e)
430     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, typestr<A6>::str, typestr<A7>::str, typestr<A8>::str, typestr<A9>::str, (const char *)0)
431 root 1.8 {
432     }
433    
434     fun9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9> *get ()
435     {
436 root 1.13 std::string id, source;
437     finish (id, source);
438     return new fun9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9> (e, id, source);
439 root 1.7 }
440     };
441 root 1.6
442 root 1.3 }