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