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