Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / share / swig / 1.3.26 / tcl / typemaps.i
CommitLineData
920dae64
AT
1/* -----------------------------------------------------------------------------
2 * typemaps.i
3 *
4 * Swig typemap library for Tcl8. This file contains various sorts
5 * of typemaps for modifying Swig's code generation.
6 *
7 * Author: David Beazley (beazley@cs.uchicago.edu)
8 *
9 * ----------------------------------------------------------------------------- */
10
11/*
12The SWIG typemap library provides a language independent mechanism for
13supporting output arguments, input values, and other C function
14calling mechanisms. The primary use of the library is to provide a
15better interface to certain C function--especially those involving
16pointers.
17*/
18
19// INPUT typemaps.
20// These remap a C pointer to be an "INPUT" value which is passed by value
21// instead of reference.
22
23/*
24The following methods can be applied to turn a pointer into a simple
25"input" value. That is, instead of passing a pointer to an object,
26you would use a real value instead.
27
28 int *INPUT
29 short *INPUT
30 long *INPUT
31 long long *INPUT
32 unsigned int *INPUT
33 unsigned short *INPUT
34 unsigned long *INPUT
35 unsigned long long *INPUT
36 unsigned char *INPUT
37 bool *INPUT
38 float *INPUT
39 double *INPUT
40
41To use these, suppose you had a C function like this :
42
43 double fadd(double *a, double *b) {
44 return *a+*b;
45 }
46
47You could wrap it with SWIG as follows :
48
49 %include typemaps.i
50 double fadd(double *INPUT, double *INPUT);
51
52or you can use the %apply directive :
53
54 %include typemaps.i
55 %apply double *INPUT { double *a, double *b };
56 double fadd(double *a, double *b);
57
58*/
59
60%typemap(in) double *INPUT(double temp), double &INPUT(double temp)
61{
62 if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) {
63 SWIG_fail;
64 }
65 $1 = &temp;
66}
67
68%typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp)
69{
70 if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) {
71 SWIG_fail;
72 }
73 temp = (float) dvalue;
74 $1 = &temp;
75}
76
77%typemap(in) int *INPUT(int temp), int &INPUT(int temp)
78{
79 if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) {
80 SWIG_fail;
81 }
82 $1 = &temp;
83}
84
85%typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp)
86{
87 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
88 SWIG_fail;
89 }
90 temp = (short) ivalue;
91 $1 = &temp;
92}
93
94%typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp)
95{
96 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
97 SWIG_fail;
98 }
99 temp = (long) ivalue;
100 $1 = &temp;
101}
102
103%typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp),
104 unsigned int &INPUT(int ivalue, unsigned int temp)
105{
106 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
107 SWIG_fail;
108 }
109 temp = (unsigned int) ivalue;
110 $1 = &temp;
111}
112
113%typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp),
114 unsigned short &INPUT(int ivalue, unsigned short temp)
115{
116 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
117 SWIG_fail;
118 }
119 temp = (unsigned short) ivalue;
120 $1 = &temp;
121}
122
123%typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp),
124 unsigned long &INPUT(int ivalue, unsigned long temp)
125{
126 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
127 SWIG_fail;
128 }
129 temp = (unsigned long) ivalue;
130 $1 = &temp;
131}
132
133%typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp),
134 unsigned char &INPUT(int ivalue, unsigned char temp)
135{
136 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
137 SWIG_fail;
138 }
139 temp = (unsigned char) ivalue;
140 $1 = &temp;
141}
142
143%typemap(in) signed char *INPUT(int ivalue, signed char temp),
144 signed char &INPUT(int ivalue, signed char temp)
145{
146 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
147 SWIG_fail;
148 }
149 temp = (signed char) ivalue;
150 $1 = &temp;
151}
152
153%typemap(in) bool *INPUT(int ivalue, bool temp),
154 bool &INPUT(int ivalue, bool temp)
155{
156 if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
157 SWIG_fail;
158 }
159 temp = ivalue ? true : false;
160 $1 = &temp;
161}
162
163%typemap(in) long long *INPUT($*1_ltype temp),
164 long long &INPUT($*1_ltype temp)
165{
166 temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);
167 $1 = &temp;
168}
169
170%typemap(in) unsigned long long *INPUT($*1_ltype temp),
171 unsigned long long &INPUT($*1_ltype temp)
172{
173 temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);
174 $1 = &temp;
175}
176
177// OUTPUT typemaps. These typemaps are used for parameters that
178// are output only. The output value is appended to the result as
179// a list element.
180
181/*
182The following methods can be applied to turn a pointer into an "output"
183value. When calling a function, no input value would be given for
184a parameter, but an output value would be returned. In the case of
185multiple output values, they are returned in the form of a Tcl list.
186
187 int *OUTPUT
188 short *OUTPUT
189 long *OUTPUT
190 long long *OUTPUT
191 unsigned int *OUTPUT
192 unsigned short *OUTPUT
193 unsigned long *OUTPUT
194 unsigned long long *OUTPUT
195 unsigned char *OUTPUT
196 bool *OUTPUT
197 float *OUTPUT
198 double *OUTPUT
199
200For example, suppose you were trying to wrap the modf() function in the
201C math library which splits x into integral and fractional parts (and
202returns the integer part in one of its parameters).K:
203
204 double modf(double x, double *ip);
205
206You could wrap it with SWIG as follows :
207
208 %include typemaps.i
209 double modf(double x, double *OUTPUT);
210
211or you can use the %apply directive :
212
213 %include typemaps.i
214 %apply double *OUTPUT { double *ip };
215 double modf(double x, double *ip);
216
217The Tcl output of the function would be a list containing both
218output values.
219
220*/
221
222%typemap(in,numinputs=0) int *OUTPUT(int temp),
223 short *OUTPUT(short temp),
224 long *OUTPUT(long temp),
225 unsigned int *OUTPUT(unsigned int temp),
226 unsigned short *OUTPUT(unsigned short temp),
227 unsigned long *OUTPUT(unsigned long temp),
228 unsigned char *OUTPUT(unsigned char temp),
229 signed char *OUTPUT(signed char temp),
230 bool *OUTPUT(bool temp),
231 float *OUTPUT(float temp),
232 double *OUTPUT(double temp),
233 long long *OUTPUT($*1_ltype temp),
234 unsigned long long *OUTPUT($*1_ltype temp),
235 int &OUTPUT(int temp),
236 short &OUTPUT(short temp),
237 long &OUTPUT(long temp),
238 unsigned int &OUTPUT(unsigned int temp),
239 unsigned short &OUTPUT(unsigned short temp),
240 unsigned long &OUTPUT(unsigned long temp),
241 signed char &OUTPUT(signed char temp),
242 bool &OUTPUT(bool temp),
243 unsigned char &OUTPUT(unsigned char temp),
244 float &OUTPUT(float temp),
245 double &OUTPUT(double temp),
246 long long &OUTPUT($*1_ltype temp),
247 unsigned long long &OUTPUT($*1_ltype temp)
248"$1 = &temp;";
249
250%typemap(argout) int *OUTPUT, int &OUTPUT,
251 short *OUTPUT, short &OUTPUT,
252 long *OUTPUT, long &OUTPUT,
253 unsigned int *OUTPUT, unsigned int &OUTPUT,
254 unsigned short *OUTPUT, unsigned short &OUTPUT,
255 unsigned long *OUTPUT, unsigned long &OUTPUT,
256 unsigned char *OUTPUT, unsigned char &OUTPUT,
257 signed char *OUTPUT, signed char &OUTPUT,
258 bool *OUTPUT, bool &OUTPUT
259{
260 Tcl_Obj *o;
261 o = Tcl_NewIntObj((int) *($1));
262 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
263}
264
265%typemap(argout) float *OUTPUT, float &OUTPUT,
266 double *OUTPUT, double &OUTPUT
267{
268 Tcl_Obj *o;
269 o = Tcl_NewDoubleObj((double) *($1));
270 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
271}
272
273%typemap(argout) long long *OUTPUT, long long &OUTPUT
274{
275 char temp[256];
276 Tcl_Obj *o;
277 sprintf(temp,"%lld",(long long)*($1));
278 o = Tcl_NewStringObj(temp,-1);
279 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
280}
281
282%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT
283{
284 char temp[256];
285 Tcl_Obj *o;
286 sprintf(temp,"%llu",(unsigned long long)*($1));
287 o = Tcl_NewStringObj(temp,-1);
288 Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
289}
290
291// INOUT
292// Mappings for an argument that is both an input and output
293// parameter
294
295/*
296The following methods can be applied to make a function parameter both
297an input and output value. This combines the behavior of both the
298"INPUT" and "OUTPUT" methods described earlier. Output values are
299returned in the form of a Tcl list.
300
301 int *INOUT
302 short *INOUT
303 long *INOUT
304 long long *INOUT
305 unsigned int *INOUT
306 unsigned short *INOUT
307 unsigned long *INOUT
308 unsigned long long *INOUT
309 unsigned char *INOUT
310 bool *INOUT
311 float *INOUT
312 double *INOUT
313
314For example, suppose you were trying to wrap the following function :
315
316 void neg(double *x) {
317 *x = -(*x);
318 }
319
320You could wrap it with SWIG as follows :
321
322 %include typemaps.i
323 void neg(double *INOUT);
324
325or you can use the %apply directive :
326
327 %include typemaps.i
328 %apply double *INOUT { double *x };
329 void neg(double *x);
330
331Unlike C, this mapping does not directly modify the input value (since
332this makes no sense in Tcl). Rather, the modified input value shows
333up as the return value of the function. Thus, to apply this function
334to a Tcl variable you might do this :
335
336 set x [neg $x]
337
338*/
339
340
341%typemap(in) int *INOUT = int *INPUT;
342%typemap(in) short *INOUT = short *INPUT;
343%typemap(in) long *INOUT = long *INPUT;
344%typemap(in) unsigned int *INOUT = unsigned int *INPUT;
345%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
346%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
347%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
348%typemap(in) signed char *INOUT = signed char *INPUT;
349%typemap(in) bool *INOUT = bool *INPUT;
350%typemap(in) float *INOUT = float *INPUT;
351%typemap(in) double *INOUT = double *INPUT;
352%typemap(in) long long *INOUT = long long *INPUT;
353%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
354
355%typemap(in) int &INOUT = int &INPUT;
356%typemap(in) short &INOUT = short &INPUT;
357%typemap(in) long &INOUT = long &INPUT;
358%typemap(in) unsigned int &INOUT = unsigned int &INPUT;
359%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
360%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
361%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
362%typemap(in) signed char &INOUT = signed char &INPUT;
363%typemap(in) bool &INOUT = bool &INPUT;
364%typemap(in) float &INOUT = float &INPUT;
365%typemap(in) double &INOUT = double &INPUT;
366%typemap(in) long long &INOUT = long long &INPUT;
367%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
368
369%typemap(argout) int *INOUT = int *OUTPUT;
370%typemap(argout) short *INOUT = short *OUTPUT;
371%typemap(argout) long *INOUT = long *OUTPUT;
372%typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT;
373%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
374%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
375%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
376%typemap(argout) signed char *INOUT = signed char *OUTPUT;
377%typemap(argout) bool *INOUT = bool *OUTPUT;
378%typemap(argout) float *INOUT = float *OUTPUT;
379%typemap(argout) double *INOUT = double *OUTPUT;
380%typemap(argout) long long *INOUT = long long *OUTPUT;
381%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
382
383%typemap(argout) int &INOUT = int &OUTPUT;
384%typemap(argout) short &INOUT = short &OUTPUT;
385%typemap(argout) long &INOUT = long &OUTPUT;
386%typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT;
387%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
388%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
389%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
390%typemap(argout) signed char &INOUT = signed char &OUTPUT;
391%typemap(argout) bool &INOUT = bool &OUTPUT;
392%typemap(argout) float &INOUT = float &OUTPUT;
393%typemap(argout) double &INOUT = double &OUTPUT;
394%typemap(argout) long long &INOUT = long long &OUTPUT;
395%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
396
397// --------------------------------------------------------------------
398// Special types
399// --------------------------------------------------------------------
400
401// If interp * appears as a function argument, we ignore it and get
402// it from the wrapper function.
403
404/*
405The typemaps.i library also provides the following mappings :
406
407Tcl_Interp *interp
408
409 Passes the current Tcl_Interp value directly to a C function.
410 This can be used to work with existing wrapper functions or
411 if you just need the interp value for some reason. When used,
412 the 'interp' parameter becomes hidden in the Tcl interface--that
413 is, you don't specify it explicitly. SWIG fills in its value
414 automatically.
415
416int Tcl_Result
417
418 Makes the integer return code of a function the return value
419 of a SWIG generated wrapper function. For example :
420
421 int foo() {
422 ... do stuff ...
423 return TCL_OK;
424 }
425
426 could be wrapped as follows :
427
428 %include typemaps.i
429 %apply int Tcl_Result { int foo };
430 int foo();
431
432*/
433
434%typemap(in,numinputs=0) Tcl_Interp *interp {
435 $1 = interp;
436}
437
438// If return code is a Tcl_Result, simply pass it on
439
440%typemap(out) int Tcl_Result {
441 return $1;
442}
443
444/* Overloading information */
445
446%typemap(typecheck) double *INPUT = double;
447%typemap(typecheck) bool *INPUT = bool;
448%typemap(typecheck) signed char *INPUT = signed char;
449%typemap(typecheck) unsigned char *INPUT = unsigned char;
450%typemap(typecheck) unsigned long *INPUT = unsigned long;
451%typemap(typecheck) unsigned short *INPUT = unsigned short;
452%typemap(typecheck) unsigned int *INPUT = unsigned int;
453%typemap(typecheck) long *INPUT = long;
454%typemap(typecheck) short *INPUT = short;
455%typemap(typecheck) int *INPUT = int;
456%typemap(typecheck) float *INPUT = float;
457%typemap(typecheck) long long *INPUT = long long;
458%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
459
460%typemap(typecheck) double &INPUT = double;
461%typemap(typecheck) bool &INPUT = bool;
462%typemap(typecheck) signed char &INPUT = signed char;
463%typemap(typecheck) unsigned char &INPUT = unsigned char;
464%typemap(typecheck) unsigned long &INPUT = unsigned long;
465%typemap(typecheck) unsigned short &INPUT = unsigned short;
466%typemap(typecheck) unsigned int &INPUT = unsigned int;
467%typemap(typecheck) long &INPUT = long;
468%typemap(typecheck) short &INPUT = short;
469%typemap(typecheck) int &INPUT = int;
470%typemap(typecheck) float &INPUT = float;
471%typemap(typecheck) long long &INPUT = long long;
472%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
473
474%typemap(typecheck) double *INOUT = double;
475%typemap(typecheck) bool *INOUT = bool;
476%typemap(typecheck) signed char *INOUT = signed char;
477%typemap(typecheck) unsigned char *INOUT = unsigned char;
478%typemap(typecheck) unsigned long *INOUT = unsigned long;
479%typemap(typecheck) unsigned short *INOUT = unsigned short;
480%typemap(typecheck) unsigned int *INOUT = unsigned int;
481%typemap(typecheck) long *INOUT = long;
482%typemap(typecheck) short *INOUT = short;
483%typemap(typecheck) int *INOUT = int;
484%typemap(typecheck) float *INOUT = float;
485%typemap(typecheck) long long *INOUT = long long;
486%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
487
488%typemap(typecheck) double &INOUT = double;
489%typemap(typecheck) bool &INOUT = bool;
490%typemap(typecheck) signed char &INOUT = signed char;
491%typemap(typecheck) unsigned char &INOUT = unsigned char;
492%typemap(typecheck) unsigned long &INOUT = unsigned long;
493%typemap(typecheck) unsigned short &INOUT = unsigned short;
494%typemap(typecheck) unsigned int &INOUT = unsigned int;
495%typemap(typecheck) long &INOUT = long;
496%typemap(typecheck) short &INOUT = short;
497%typemap(typecheck) int &INOUT = int;
498%typemap(typecheck) float &INOUT = float;
499%typemap(typecheck) long long &INOUT = long long;
500%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
501
502
503
504
505
506
507