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