ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libcpjit/cpjit.h.PL
(Generate patch)

Comparing cvsroot/libcpjit/cpjit.h.PL (file contents):
Revision 1.5 by root, Tue Oct 11 20:51:55 2005 UTC vs.
Revision 1.6 by root, Tue Oct 11 22:06:24 2005 UTC

3# create cpjit.h 3# create cpjit.h
4 4
5open STDOUT, ">cpjit.h" 5open STDOUT, ">cpjit.h"
6 or die "cpijit.h: $!"; 6 or die "cpijit.h: $!";
7 7
8$CPJIT_MAX_ARGS = 9;
9
8print <<EOF; 10print <<EOF;
9#line 10 "cpjit.h.PL" 11#line 12 "cpjit.h.PL"
10/* 12/*
11 This file is AUTOMAGICALLY created by cpjit.h.PL. Modifications will 13 This file is AUTOMAGICALLY created by cpjit.h.PL. Modifications will
12 be lost. 14 be lost.
13 15
14 cpjit.h -- c portable jit in time compiler 16 cpjit.h -- c portable jit in time compiler
30 along with gvpe; if not, write to the Free Software 32 along with gvpe; if not, write to the Free Software
31 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32*/ 34*/
33 35
34#include <string> 36#include <string>
37#include <sstream>
35#include <inttypes.h> 38#include <inttypes.h>
36 39
37namespace cpjit 40namespace cpjit
38{ 41{
42
43#define CPJIT_MAX_ARGS $CPJIT_MAX_ARGS
44#define CPJIT_NULLID ""
39 45
40typedef std::string idstr; 46typedef std::string idstr;
41 47
42// environment for persistent or temporary storage 48// environment for persistent or temporary storage
43struct env 49struct env
44{ 50{
45}; 51};
46 52
47struct func_base 53struct fun
48{ 54{
49 env &e; 55 env &e;
50 idstr id; 56 idstr id;
51 const char *retval; 57 std::string source;
52 58
53 func_base (env &e, const idstr &id, const char *retval, const char *args); 59 fun (env &e, const idstr &id);
60
61 // is compiled function available?
62 bool compiled ();
63
64 void set_source (const std::string source)
65 {
66 this->source = source;
67 }
54 68
55 // internal method to return the function pointer 69 // internal method to return the function pointer
56 void *ptr (); 70 void *ptr ();
57}; 71};
58 72
59struct funcbuilder_base 73struct funbuild : std::ostringstream
60{ 74{
75 env &e;
76 idstr id;
77
78 funbuild (env &e, const idstr &id, const char *rettype, ...);
79 void finish ();
80
81 fun *get ()
82 {
83 finish ();
84 fun *f = new fun (e, id);
85 f->set_source (str ());
86 return f;
87 }
61}; 88};
62 89
63typedef unsigned char U8; 90typedef unsigned char U8;
64typedef signed char I8; 91typedef signed char I8;
65typedef uint16_t U16; 92typedef uint16_t U16;
92template<> struct typestr<I32 *> { static const char str[]; }; 119template<> struct typestr<I32 *> { static const char str[]; };
93template<> struct typestr<I64 *> { static const char str[]; }; 120template<> struct typestr<I64 *> { static const char str[]; };
94template<> struct typestr<F32 *> { static const char str[]; }; 121template<> struct typestr<F32 *> { static const char str[]; };
95template<> struct typestr<F64 *> { static const char str[]; }; 122template<> struct typestr<F64 *> { static const char str[]; };
96 123
97template<typename R, typename A1> 124EOF
98struct function : func_base 125
126for (0 .. $CPJIT_MAX_ARGS) {
127 print <<EOF;
128#line 129 "cpjit.h.PL"
129
130template<typename R${\( join "", map ", typename A$_", 1..$_ )}>
131struct fun$_ : fun
99{ 132{
100 function (env &e, const idstr &id) 133 fun$_ (env &e, const idstr &id = CPJIT_NULLID)
101 : func_base (e, id, typestr<R>::str) 134 : fun (e, id)
102 { 135 {
103 } 136 }
104 137
105 int operator ()(A1 a1) 138 int operator ()(${\( join ", ", map "A$_ a$_", 1..$_ )})
106 { 139 {
107 return ((R (*)(A1 a1)) ptr ())(a1); 140 return ((R (*)(${\( join ", ", map "A$_", 1..$_ )})) ptr ())(${\( join ", ", map "a$_", 1..$_ )});
141 }
142};
143
144template<typename R${\( join "", map ", typename A$_", 1..$_ )}>
145struct funbuild$_ : funbuild
146{
147 funbuild$_ (env &e, const idstr &id = CPJIT_NULLID)
148 : funbuild (e, id, typestr<R>::str${\( join "", map ", typestr<A$_>::str", 1..$_ )}, (const char *)0)
149 {
150 }
151
152 fun$_<R${\( join "", map ", A$_", 1..$_ )}> *get ()
153 {
154 finish ();
155 fun$_<R${\( join "", map ", A$_", 1..$_ )}> *f = new fun$_<R${\( join "", map ", A$_", 1..$_ )}> (e, id);
156 f->set_source (str ());
157 return f;
108 } 158 }
109}; 159};
110 160
111EOF 161EOF
162}
112 163
113print <<EOF; 164print <<EOF;
114} 165}
115EOF 166EOF
116 167

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines