ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libcpjit/cpjit.h
Revision: 1.13
Committed: Fri Oct 14 01:29:45 2005 UTC (20 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.12: +87 -100 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.9 std::string path;
40     bool temporary;
41 root 1.12 int idxfd;
42 root 1.9
43 root 1.12 void dolock (bool lock);
44     void lock ();
45     void unlock ();
46    
47     void load_index ();
48     void save_index ();
49    
50     public:
51 root 1.9 env (const std::string &path = CPJIT_NULLID, bool temporary = true);
52     ~env ();
53 root 1.12
54 root 1.13 // completely delete the environment on disk
55     void clear ();
56 root 1.7 };
57    
58 root 1.8 struct fun
59 root 1.7 {
60     env &e;
61 root 1.13 std::string id, source;
62 root 1.9 void *funptr;
63 root 1.8
64 root 1.13 fun (env &e, const std::string &id, const std::string &source);
65 root 1.8
66     // is compiled function available?
67 root 1.9 bool compiled ()
68     {
69     return funptr;
70     }
71 root 1.7
72 root 1.9 // returns the function pointer
73 root 1.7 void *ptr ();
74     };
75    
76 root 1.8 struct funbuild : std::ostringstream
77 root 1.7 {
78 root 1.8 env &e;
79 root 1.13 std::string retlist, arglist;
80 root 1.8
81 root 1.13 funbuild (env &e, const char *rettype, ...);
82     void finish (std::string &id, std::string &source);
83 root 1.7 };
84 root 1.5
85 root 1.7 typedef unsigned char U8;
86     typedef signed char I8;
87     typedef uint16_t U16;
88     typedef int16_t I16;
89     typedef uint32_t U32;
90     typedef int32_t I32;
91     typedef uint64_t U64;
92     typedef int64_t I64;
93 root 1.11 typedef float FLT;
94     typedef double DBL;
95 root 1.9 typedef void * PTR;
96 root 1.7
97     template<typename T> struct typestr { };
98    
99     template<> struct typestr<U8 > { static const char str[]; };
100     template<> struct typestr<U16 > { static const char str[]; };
101     template<> struct typestr<U32 > { static const char str[]; };
102     template<> struct typestr<U64 > { static const char str[]; };
103     template<> struct typestr<I8 > { static const char str[]; };
104     template<> struct typestr<I16 > { static const char str[]; };
105     template<> struct typestr<I32 > { static const char str[]; };
106     template<> struct typestr<I64 > { static const char str[]; };
107 root 1.11 template<> struct typestr<FLT > { static const char str[]; };
108     template<> struct typestr<DBL > { static const char str[]; };
109 root 1.9 template<> struct typestr<PTR > { static const char str[]; };
110 root 1.7 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.11 template<> struct typestr<FLT *> { static const char str[]; };
119     template<> struct typestr<DBL *> { static const char str[]; };
120 root 1.5
121 root 1.13 #line 133 "cpjit.h.PL"
122 root 1.8
123     template<typename R>
124     struct fun0 : fun
125     {
126 root 1.13 fun0 (env &e, const std::string &id, const std::string &source)
127     : fun(e, id, source)
128 root 1.8 {
129     }
130    
131     int operator ()()
132     {
133     return ((R (*)()) ptr ())();
134     }
135     };
136    
137     template<typename R>
138     struct funbuild0 : funbuild
139     {
140 root 1.13 funbuild0 (env &e)
141     : funbuild(e, typestr<R>::str, (const char *)0)
142 root 1.8 {
143     }
144    
145     fun0<R> *get ()
146     {
147 root 1.13 std::string id, source;
148     finish (id, source);
149     return new fun0<R> (e, id, source);
150 root 1.8 }
151     };
152    
153 root 1.13 #line 133 "cpjit.h.PL"
154 root 1.8
155 root 1.7 template<typename R, typename A1>
156 root 1.8 struct fun1 : fun
157 root 1.7 {
158 root 1.13 fun1 (env &e, const std::string &id, const std::string &source)
159     : fun(e, id, source)
160 root 1.5 {
161 root 1.7 }
162 root 1.6
163 root 1.7 int operator ()(A1 a1)
164 root 1.5 {
165 root 1.8 return ((R (*)(A1)) ptr ())(a1);
166     }
167     };
168    
169     template<typename R, typename A1>
170     struct funbuild1 : funbuild
171     {
172 root 1.13 funbuild1 (env &e)
173     : funbuild(e, typestr<R>::str, typestr<A1>::str, (const char *)0)
174 root 1.8 {
175     }
176    
177     fun1<R, A1> *get ()
178     {
179 root 1.13 std::string id, source;
180     finish (id, source);
181     return new fun1<R, A1> (e, id, source);
182 root 1.8 }
183     };
184    
185 root 1.13 #line 133 "cpjit.h.PL"
186 root 1.8
187     template<typename R, typename A1, typename A2>
188     struct fun2 : fun
189     {
190 root 1.13 fun2 (env &e, const std::string &id, const std::string &source)
191     : fun(e, id, source)
192 root 1.8 {
193     }
194    
195     int operator ()(A1 a1, A2 a2)
196     {
197     return ((R (*)(A1, A2)) ptr ())(a1, a2);
198     }
199     };
200    
201     template<typename R, typename A1, typename A2>
202     struct funbuild2 : funbuild
203     {
204 root 1.13 funbuild2 (env &e)
205     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, (const char *)0)
206 root 1.8 {
207     }
208    
209     fun2<R, A1, A2> *get ()
210     {
211 root 1.13 std::string id, source;
212     finish (id, source);
213     return new fun2<R, A1, A2> (e, id, source);
214 root 1.8 }
215     };
216    
217 root 1.13 #line 133 "cpjit.h.PL"
218 root 1.8
219     template<typename R, typename A1, typename A2, typename A3>
220     struct fun3 : fun
221     {
222 root 1.13 fun3 (env &e, const std::string &id, const std::string &source)
223     : fun(e, id, source)
224 root 1.8 {
225     }
226    
227     int operator ()(A1 a1, A2 a2, A3 a3)
228     {
229     return ((R (*)(A1, A2, A3)) ptr ())(a1, a2, a3);
230     }
231     };
232    
233     template<typename R, typename A1, typename A2, typename A3>
234     struct funbuild3 : funbuild
235     {
236 root 1.13 funbuild3 (env &e)
237     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, (const char *)0)
238 root 1.8 {
239     }
240    
241     fun3<R, A1, A2, A3> *get ()
242     {
243 root 1.13 std::string id, source;
244     finish (id, source);
245     return new fun3<R, A1, A2, A3> (e, id, source);
246 root 1.8 }
247     };
248    
249 root 1.13 #line 133 "cpjit.h.PL"
250 root 1.8
251     template<typename R, typename A1, typename A2, typename A3, typename A4>
252     struct fun4 : fun
253     {
254 root 1.13 fun4 (env &e, const std::string &id, const std::string &source)
255     : fun(e, id, source)
256 root 1.8 {
257     }
258    
259     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4)
260     {
261     return ((R (*)(A1, A2, A3, A4)) ptr ())(a1, a2, a3, a4);
262     }
263     };
264    
265     template<typename R, typename A1, typename A2, typename A3, typename A4>
266     struct funbuild4 : funbuild
267     {
268 root 1.13 funbuild4 (env &e)
269     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, (const char *)0)
270 root 1.8 {
271     }
272    
273     fun4<R, A1, A2, A3, A4> *get ()
274     {
275 root 1.13 std::string id, source;
276     finish (id, source);
277     return new fun4<R, A1, A2, A3, A4> (e, id, source);
278 root 1.8 }
279     };
280    
281 root 1.13 #line 133 "cpjit.h.PL"
282 root 1.8
283     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5>
284     struct fun5 : fun
285     {
286 root 1.13 fun5 (env &e, const std::string &id, const std::string &source)
287     : fun(e, id, source)
288 root 1.8 {
289     }
290    
291     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
292     {
293     return ((R (*)(A1, A2, A3, A4, A5)) ptr ())(a1, a2, a3, a4, a5);
294     }
295     };
296    
297     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5>
298     struct funbuild5 : funbuild
299     {
300 root 1.13 funbuild5 (env &e)
301     : funbuild(e, typestr<R>::str, typestr<A1>::str, typestr<A2>::str, typestr<A3>::str, typestr<A4>::str, typestr<A5>::str, (const char *)0)
302 root 1.8 {
303     }
304    
305     fun5<R, A1, A2, A3, A4, A5> *get ()
306     {
307 root 1.13 std::string id, source;
308     finish (id, source);
309     return new fun5<R, A1, A2, A3, A4, A5> (e, id, source);
310 root 1.8 }
311     };
312    
313 root 1.13 #line 133 "cpjit.h.PL"
314 root 1.8
315     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
316     struct fun6 : fun
317     {
318 root 1.13 fun6 (env &e, const std::string &id, const std::string &source)
319     : fun(e, id, source)
320 root 1.8 {
321     }
322    
323     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
324     {
325     return ((R (*)(A1, A2, A3, A4, A5, A6)) ptr ())(a1, a2, a3, a4, a5, a6);
326     }
327     };
328    
329     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
330     struct funbuild6 : funbuild
331     {
332 root 1.13 funbuild6 (env &e)
333     : 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)
334 root 1.8 {
335     }
336    
337     fun6<R, A1, A2, A3, A4, A5, A6> *get ()
338     {
339 root 1.13 std::string id, source;
340     finish (id, source);
341     return new fun6<R, A1, A2, A3, A4, A5, A6> (e, id, source);
342 root 1.8 }
343     };
344    
345 root 1.13 #line 133 "cpjit.h.PL"
346 root 1.8
347     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
348     struct fun7 : fun
349     {
350 root 1.13 fun7 (env &e, const std::string &id, const std::string &source)
351     : fun(e, id, source)
352 root 1.8 {
353     }
354    
355     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
356     {
357     return ((R (*)(A1, A2, A3, A4, A5, A6, A7)) ptr ())(a1, a2, a3, a4, a5, a6, a7);
358     }
359     };
360    
361     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
362     struct funbuild7 : funbuild
363     {
364 root 1.13 funbuild7 (env &e)
365     : 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)
366 root 1.8 {
367     }
368    
369     fun7<R, A1, A2, A3, A4, A5, A6, A7> *get ()
370     {
371 root 1.13 std::string id, source;
372     finish (id, source);
373     return new fun7<R, A1, A2, A3, A4, A5, A6, A7> (e, id, source);
374 root 1.8 }
375     };
376    
377 root 1.13 #line 133 "cpjit.h.PL"
378 root 1.8
379     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
380     struct fun8 : fun
381     {
382 root 1.13 fun8 (env &e, const std::string &id, const std::string &source)
383     : fun(e, id, source)
384 root 1.8 {
385     }
386    
387     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
388     {
389     return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8);
390     }
391     };
392    
393     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
394     struct funbuild8 : funbuild
395     {
396 root 1.13 funbuild8 (env &e)
397     : 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)
398 root 1.8 {
399     }
400    
401     fun8<R, A1, A2, A3, A4, A5, A6, A7, A8> *get ()
402     {
403 root 1.13 std::string id, source;
404     finish (id, source);
405     return new fun8<R, A1, A2, A3, A4, A5, A6, A7, A8> (e, id, source);
406 root 1.8 }
407     };
408    
409 root 1.13 #line 133 "cpjit.h.PL"
410 root 1.8
411     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
412     struct fun9 : fun
413     {
414 root 1.13 fun9 (env &e, const std::string &id, const std::string &source)
415     : fun(e, id, source)
416 root 1.8 {
417     }
418    
419     int operator ()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
420     {
421     return ((R (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) ptr ())(a1, a2, a3, a4, a5, a6, a7, a8, a9);
422     }
423     };
424    
425     template<typename R, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
426     struct funbuild9 : funbuild
427     {
428 root 1.13 funbuild9 (env &e)
429     : 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)
430 root 1.8 {
431     }
432    
433     fun9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9> *get ()
434     {
435 root 1.13 std::string id, source;
436     finish (id, source);
437     return new fun9<R, A1, A2, A3, A4, A5, A6, A7, A8, A9> (e, id, source);
438 root 1.7 }
439     };
440 root 1.6
441 root 1.3 }