Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / share / swig / 1.3.26 / perl5 / typemaps.i
CommitLineData
920dae64
AT
1//
2// SWIG Typemap library
3// Dave Beazley
4// May 5, 1997
5//
6// Perl5 implementation
7//
8// This library provides standard typemaps for modifying SWIG's behavior.
9// With enough entries in this file, I hope that very few people actually
10// ever need to write a typemap.
11//
12
13/*
14The SWIG typemap library provides a language independent mechanism for
15supporting output arguments, input values, and other C function
16calling mechanisms. The primary use of the library is to provide a
17better interface to certain C function--especially those involving
18pointers.
19*/
20
21// INPUT typemaps.
22// These remap a C pointer to be an "INPUT" value which is passed by value
23// instead of reference.
24
25
26/*
27The following methods can be applied to turn a pointer into a simple
28"input" value. That is, instead of passing a pointer to an object,
29you would use a real value instead.
30
31 int *INPUT
32 short *INPUT
33 long *INPUT
34 long long *INPUT
35 unsigned int *INPUT
36 unsigned short *INPUT
37 unsigned long *INPUT
38 unsigned long long *INPUT
39 unsigned char *INPUT
40 bool *INPUT
41 float *INPUT
42 double *INPUT
43
44To use these, suppose you had a C function like this :
45
46 double fadd(double *a, double *b) {
47 return *a+*b;
48 }
49
50You could wrap it with SWIG as follows :
51
52 %include typemaps.i
53 double fadd(double *INPUT, double *INPUT);
54
55or you can use the %apply directive :
56
57 %include typemaps.i
58 %apply double *INPUT { double *a, double *b };
59 double fadd(double *a, double *b);
60
61*/
62
63%define INPUT_TYPEMAP(type, converter)
64%typemap(in) type *INPUT(type temp), type &INPUT(type temp) {
65 temp = (type) converter($input);
66 $1 = &temp;
67}
68%typemap(typecheck) type *INPUT = type;
69%typemap(typecheck) type &INPUT = type;
70%enddef
71
72INPUT_TYPEMAP(float, SvNV);
73INPUT_TYPEMAP(double, SvNV);
74INPUT_TYPEMAP(int, SvIV);
75INPUT_TYPEMAP(long, SvIV);
76INPUT_TYPEMAP(short, SvIV);
77INPUT_TYPEMAP(signed char, SvIV);
78INPUT_TYPEMAP(unsigned int, SvUV);
79INPUT_TYPEMAP(unsigned long, SvUV);
80INPUT_TYPEMAP(unsigned short, SvUV);
81INPUT_TYPEMAP(unsigned char, SvUV);
82
83%typemap(in) bool *INPUT(bool temp), bool &INPUT(bool temp) {
84 temp = SvIV($input) ? true : false;
85 $1 = &temp;
86}
87%typemap(typecheck) bool *INPUT = bool;
88%typemap(typecheck) bool &INPUT = bool;
89
90%typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) {
91 temp = strtoll(SvPV($input,PL_na), 0, 0);
92 $1 = &temp;
93}
94%typemap(typecheck) long long *INPUT = long long;
95%typemap(typecheck) long long &INPUT = long long;
96
97%typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) {
98 temp = strtoull(SvPV($input,PL_na), 0, 0);
99 $1 = &temp;
100}
101%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
102%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
103
104
105#undef INPUT_TYPEMAP
106
107// OUTPUT typemaps. These typemaps are used for parameters that
108// are output only. The output value is appended to the result as
109// a list element.
110
111/*
112The following methods can be applied to turn a pointer into an "output"
113value. When calling a function, no input value would be given for
114a parameter, but an output value would be returned. In the case of
115multiple output values, functions will return a Perl array.
116
117 int *OUTPUT
118 short *OUTPUT
119 long *OUTPUT
120 long long *OUTPUT
121 unsigned int *OUTPUT
122 unsigned short *OUTPUT
123 unsigned long *OUTPUT
124 unsigned long long *OUTPUT
125 unsigned char *OUTPUT
126 bool *OUTPUT
127 float *OUTPUT
128 double *OUTPUT
129
130For example, suppose you were trying to wrap the modf() function in the
131C math library which splits x into integral and fractional parts (and
132returns the integer part in one of its parameters).:
133
134 double modf(double x, double *ip);
135
136You could wrap it with SWIG as follows :
137
138 %include typemaps.i
139 double modf(double x, double *OUTPUT);
140
141or you can use the %apply directive :
142
143 %include typemaps.i
144 %apply double *OUTPUT { double *ip };
145 double modf(double x, double *ip);
146
147The Perl output of the function would be an array containing both
148output values.
149
150*/
151
152// Force the argument to be ignored.
153
154%typemap(in,numinputs=0) int *OUTPUT(int temp), int &OUTPUT(int temp),
155 short *OUTPUT(short temp), short &OUTPUT(short temp),
156 long *OUTPUT(long temp), long &OUTPUT(long temp),
157 unsigned int *OUTPUT(unsigned int temp), unsigned int &OUTPUT(unsigned int temp),
158 unsigned short *OUTPUT(unsigned short temp), unsigned short &OUTPUT(unsigned short temp),
159 unsigned long *OUTPUT(unsigned long temp), unsigned long &OUTPUT(unsigned long temp),
160 unsigned char *OUTPUT(unsigned char temp), unsigned char &OUTPUT(unsigned char temp),
161 signed char *OUTPUT(signed char temp), signed char &OUTPUT(signed char temp),
162 bool *OUTPUT(bool temp), bool &OUTPUT(bool temp),
163 float *OUTPUT(float temp), float &OUTPUT(float temp),
164 double *OUTPUT(double temp), double &OUTPUT(double temp),
165 long long *OUTPUT($*1_ltype temp), long long &OUTPUT($*1_ltype temp),
166 unsigned long long *OUTPUT($*1_ltype temp), unsigned long long &OUTPUT($*1_ltype temp)
167"$1 = &temp;";
168
169%typemap(argout) int *OUTPUT, int &OUTPUT,
170 short *OUTPUT, short &OUTPUT,
171 long *OUTPUT, long &OUTPUT,
172 signed char *OUTPUT, signed char &OUTPUT,
173 bool *OUTPUT, bool &OUTPUT
174{
175 if (argvi >= items) {
176 EXTEND(sp,1);
177 }
178 $result = sv_newmortal();
179 sv_setiv($result,(IV) *($1));
180 argvi++;
181}
182
183%typemap(argout) unsigned int *OUTPUT, unsigned int &OUTPUT,
184 unsigned short *OUTPUT, unsigned short &OUTPUT,
185 unsigned long *OUTPUT, unsigned long &OUTPUT,
186 unsigned char *OUTPUT, unsigned char &OUTPUT
187{
188 if (argvi >= items) {
189 EXTEND(sp,1);
190 }
191 $result = sv_newmortal();
192 sv_setuv($result,(UV) *($1));
193 argvi++;
194}
195
196
197
198%typemap(argout) float *OUTPUT, float &OUTPUT,
199 double *OUTPUT, double &OUTPUT
200{
201 if (argvi >= items) {
202 EXTEND(sp,1);
203 }
204 $result = sv_newmortal();
205 sv_setnv($result,(double) *($1));
206 argvi++;
207}
208
209%typemap(argout) long long *OUTPUT, long long &OUTPUT {
210 char temp[256];
211 if (argvi >= items) {
212 EXTEND(sp,1);
213 }
214 sprintf(temp,"%lld", (long long)*($1));
215 $result = sv_newmortal();
216 sv_setpv($result,temp);
217 argvi++;
218}
219
220%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT {
221 char temp[256];
222 if (argvi >= items) {
223 EXTEND(sp,1);
224 }
225 sprintf(temp,"%llu", (unsigned long long)*($1));
226 $result = sv_newmortal();
227 sv_setpv($result,temp);
228 argvi++;
229}
230
231// INOUT
232// Mappings for an argument that is both an input and output
233// parameter
234
235/*
236The following methods can be applied to make a function parameter both
237an input and output value. This combines the behavior of both the
238"INPUT" and "OUTPUT" methods described earlier. Output values are
239returned in the form of a Perl array.
240
241 int *INOUT
242 short *INOUT
243 long *INOUT
244 long long *INOUT
245 unsigned int *INOUT
246 unsigned short *INOUT
247 unsigned long *INOUT
248 unsigned long long *INOUT
249 unsigned char *INOUT
250 bool *INOUT
251 float *INOUT
252 double *INOUT
253
254For example, suppose you were trying to wrap the following function :
255
256 void neg(double *x) {
257 *x = -(*x);
258 }
259
260You could wrap it with SWIG as follows :
261
262 %include typemaps.i
263 void neg(double *INOUT);
264
265or you can use the %apply directive :
266
267 %include typemaps.i
268 %apply double *INOUT { double *x };
269 void neg(double *x);
270
271Unlike C, this mapping does not directly modify the input value.
272Rather, the modified input value shows up as the return value of the
273function. Thus, to apply this function to a Perl variable you might
274do this :
275
276 $x = neg($x);
277
278*/
279
280%typemap(in) int *INOUT = int *INPUT;
281%typemap(in) short *INOUT = short *INPUT;
282%typemap(in) long *INOUT = long *INPUT;
283%typemap(in) unsigned *INOUT = unsigned *INPUT;
284%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
285%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
286%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
287%typemap(in) signed char *INOUT = signed char *INPUT;
288%typemap(in) bool *INOUT = bool *INPUT;
289%typemap(in) float *INOUT = float *INPUT;
290%typemap(in) double *INOUT = double *INPUT;
291%typemap(in) long long *INOUT = long long *INPUT;
292%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
293
294%typemap(in) int &INOUT = int &INPUT;
295%typemap(in) short &INOUT = short &INPUT;
296%typemap(in) long &INOUT = long &INPUT;
297%typemap(in) unsigned &INOUT = unsigned &INPUT;
298%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
299%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
300%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
301%typemap(in) signed char &INOUT = signed char &INPUT;
302%typemap(in) bool &INOUT = bool &INPUT;
303%typemap(in) float &INOUT = float &INPUT;
304%typemap(in) double &INOUT = double &INPUT;
305%typemap(in) long long &INOUT = long long &INPUT;
306%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
307
308
309%typemap(argout) int *INOUT = int *OUTPUT;
310%typemap(argout) short *INOUT = short *OUTPUT;
311%typemap(argout) long *INOUT = long *OUTPUT;
312%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
313%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
314%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
315%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
316%typemap(argout) signed char *INOUT = signed char *OUTPUT;
317%typemap(argout) bool *INOUT = bool *OUTPUT;
318%typemap(argout) float *INOUT = float *OUTPUT;
319%typemap(argout) double *INOUT = double *OUTPUT;
320%typemap(argout) long long *INOUT = long long *OUTPUT;
321%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
322
323
324%typemap(argout) int &INOUT = int &OUTPUT;
325%typemap(argout) short &INOUT = short &OUTPUT;
326%typemap(argout) long &INOUT = long &OUTPUT;
327%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
328%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
329%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
330%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
331%typemap(argout) signed char &INOUT = signed char &OUTPUT;
332%typemap(argout) bool &INOUT = bool &OUTPUT;
333%typemap(argout) float &INOUT = float &OUTPUT;
334%typemap(argout) double &INOUT = double &OUTPUT;
335%typemap(argout) long long &INOUT = long long &OUTPUT;
336%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
337
338// REFERENCE
339// Accept Perl references as pointers
340
341/*
342The following methods make Perl references work like simple C
343pointers. References can only be used for simple input/output
344values, not C arrays however. It should also be noted that
345REFERENCES are specific to Perl and not supported in other
346scripting languages at this time.
347
348 int *REFERENCE
349 short *REFERENCE
350 long *REFERENCE
351 unsigned int *REFERENCE
352 unsigned short *REFERENCE
353 unsigned long *REFERENCE
354 unsigned char *REFERENCE
355 float *REFERENCE
356 double *REFERENCE
357
358For example, suppose you were trying to wrap the following function :
359
360 void neg(double *x) {
361 *x = -(*x);
362 }
363
364You could wrap it with SWIG as follows :
365
366 %include typemaps.i
367 void neg(double *REFERENCE);
368
369or you can use the %apply directive :
370
371 %include typemaps.i
372 %apply double *REFERENCE { double *x };
373 void neg(double *x);
374
375Unlike the INOUT mapping described previous, this approach directly
376modifies the value of a Perl reference. Thus, you could use it
377as follows :
378
379 $x = 3;
380 neg(\$x);
381 print "$x\n"; # Should print out -3.
382
383*/
384
385%typemap(in) double *REFERENCE (double dvalue), double &REFERENCE(double dvalue)
386{
387 SV *tempsv;
388 if (!SvROK($input)) {
389 SWIG_croak("expected a reference");
390 }
391 tempsv = SvRV($input);
392 if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
393 printf("Received %d\n", SvTYPE(tempsv));
394 SWIG_croak("Expected a double reference.");
395 }
396 dvalue = SvNV(tempsv);
397 $1 = &dvalue;
398}
399
400%typemap(in) float *REFERENCE (float dvalue), float &REFERENCE(float dvalue)
401{
402 SV *tempsv;
403 if (!SvROK($input)) {
404 SWIG_croak("expected a reference");
405 }
406 tempsv = SvRV($input);
407 if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
408 SWIG_croak("expected a double reference");
409 }
410 dvalue = (float) SvNV(tempsv);
411 $1 = &dvalue;
412}
413
414%typemap(in) int *REFERENCE (int dvalue), int &REFERENCE (int dvalue)
415{
416 SV *tempsv;
417 if (!SvROK($input)) {
418 SWIG_croak("expected a reference");
419 }
420 tempsv = SvRV($input);
421 if (!SvIOK(tempsv)) {
422 SWIG_croak("expected a integer reference");
423 }
424 dvalue = SvIV(tempsv);
425 $1 = &dvalue;
426}
427
428%typemap(in) short *REFERENCE (short dvalue), short &REFERENCE(short dvalue)
429{
430 SV *tempsv;
431 if (!SvROK($input)) {
432 SWIG_croak("expected a reference");
433 }
434 tempsv = SvRV($input);
435 if (!SvIOK(tempsv)) {
436 SWIG_croak("expected a integer reference");
437 }
438 dvalue = (short) SvIV(tempsv);
439 $1 = &dvalue;
440}
441%typemap(in) long *REFERENCE (long dvalue), long &REFERENCE(long dvalue)
442{
443 SV *tempsv;
444 if (!SvROK($input)) {
445 SWIG_croak("expected a reference");
446 }
447 tempsv = SvRV($input);
448 if (!SvIOK(tempsv)) {
449 SWIG_croak("expected a integer reference");
450 }
451 dvalue = (long) SvIV(tempsv);
452 $1 = &dvalue;
453}
454%typemap(in) unsigned int *REFERENCE (unsigned int dvalue), unsigned int &REFERENCE(unsigned int dvalue)
455{
456 SV *tempsv;
457 if (!SvROK($input)) {
458 SWIG_croak("expected a reference");
459 }
460 tempsv = SvRV($input);
461 if (!SvIOK(tempsv)) {
462 SWIG_croak("expected a integer reference");
463 }
464 dvalue = (unsigned int) SvUV(tempsv);
465 $1 = &dvalue;
466}
467%typemap(in) unsigned short *REFERENCE (unsigned short dvalue), unsigned short &REFERENCE(unsigned short dvalue)
468{
469 SV *tempsv;
470 if (!SvROK($input)) {
471 SWIG_croak("expected a reference");
472 }
473 tempsv = SvRV($input);
474 if (!SvIOK(tempsv)) {
475 SWIG_croak("expected a integer reference");
476 }
477 dvalue = (unsigned short) SvUV(tempsv);
478 $1 = &dvalue;
479}
480%typemap(in) unsigned long *REFERENCE (unsigned long dvalue), unsigned long &REFERENCE(unsigned long dvalue)
481{
482 SV *tempsv;
483 if (!SvROK($input)) {
484 SWIG_croak("expected a reference");
485 }
486 tempsv = SvRV($input);
487 if (!SvIOK(tempsv)) {
488 SWIG_croak("expected a integer reference");
489 }
490 dvalue = (unsigned long) SvUV(tempsv);
491 $1 = &dvalue;
492}
493
494%typemap(in) unsigned char *REFERENCE (unsigned char dvalue), unsigned char &REFERENCE(unsigned char dvalue)
495{
496 SV *tempsv;
497 if (!SvROK($input)) {
498 SWIG_croak("expected a reference");
499 }
500 tempsv = SvRV($input);
501 if (!SvIOK(tempsv)) {
502 SWIG_croak("expected a integer reference");
503 }
504 dvalue = (unsigned char) SvUV(tempsv);
505 $1 = &dvalue;
506}
507
508%typemap(in) signed char *REFERENCE (signed char dvalue), signed char &REFERENCE(signed char dvalue)
509{
510 SV *tempsv;
511 if (!SvROK($input)) {
512 SWIG_croak("expected a reference");
513 }
514 tempsv = SvRV($input);
515 if (!SvIOK(tempsv)) {
516 SWIG_croak("expected a integer reference");
517 }
518 dvalue = (signed char) SvIV(tempsv);
519 $1 = &dvalue;
520}
521
522%typemap(in) bool *REFERENCE (bool dvalue), bool &REFERENCE(bool dvalue)
523{
524 SV *tempsv;
525 if (!SvROK($input)) {
526 SWIG_croak("expected a reference");
527 }
528 tempsv = SvRV($input);
529 if (!SvIOK(tempsv)) {
530 SWIG_croak("expected a integer reference");
531 }
532 dvalue = (bool) SvIV(tempsv);
533 $1 = &dvalue;
534}
535
536%typemap(argout) double *REFERENCE, double &REFERENCE,
537 float *REFERENCE, float &REFERENCE
538{
539 SV *tempsv;
540 tempsv = SvRV($arg);
541 if (!$1) SWIG_croak("expected a reference");
542 sv_setnv(tempsv, (double) *$1);
543}
544
545%typemap(argout) int *REFERENCE, int &REFERENCE,
546 short *REFERENCE, short &REFERENCE,
547 long *REFERENCE, long &REFERENCE,
548 signed char *REFERENCE, unsigned char &REFERENCE,
549 bool *REFERENCE, bool &REFERENCE
550{
551 SV *tempsv;
552 tempsv = SvRV($input);
553 if (!$1) SWIG_croak("expected a reference");
554 sv_setiv(tempsv, (IV) *$1);
555}
556
557%typemap(argout) unsigned int *REFERENCE, unsigned int &REFERENCE,
558 unsigned short *REFERENCE, unsigned short &REFERENCE,
559 unsigned long *REFERENCE, unsigned long &REFERENCE,
560 unsigned char *REFERENCE, unsigned char &REFERENCE
561{
562 SV *tempsv;
563 tempsv = SvRV($input);
564 if (!$1) SWIG_croak("expected a reference");
565 sv_setuv(tempsv, (UV) *$1);
566}
567
568/* Overloading information */
569
570%typemap(typecheck) double *INOUT = double;
571%typemap(typecheck) bool *INOUT = bool;
572%typemap(typecheck) signed char *INOUT = signed char;
573%typemap(typecheck) unsigned char *INOUT = unsigned char;
574%typemap(typecheck) unsigned long *INOUT = unsigned long;
575%typemap(typecheck) unsigned short *INOUT = unsigned short;
576%typemap(typecheck) unsigned int *INOUT = unsigned int;
577%typemap(typecheck) long *INOUT = long;
578%typemap(typecheck) short *INOUT = short;
579%typemap(typecheck) int *INOUT = int;
580%typemap(typecheck) float *INOUT = float;
581%typemap(typecheck) long long *INOUT = long long;
582%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
583
584%typemap(typecheck) double &INOUT = double;
585%typemap(typecheck) bool &INOUT = bool;
586%typemap(typecheck) signed char &INOUT = signed char;
587%typemap(typecheck) unsigned char &INOUT = unsigned char;
588%typemap(typecheck) unsigned long &INOUT = unsigned long;
589%typemap(typecheck) unsigned short &INOUT = unsigned short;
590%typemap(typecheck) unsigned int &INOUT = unsigned int;
591%typemap(typecheck) long &INOUT = long;
592%typemap(typecheck) short &INOUT = short;
593%typemap(typecheck) int &INOUT = int;
594%typemap(typecheck) float &INOUT = float;
595%typemap(typecheck) long long &INOUT = long long;
596%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
597