TIVI-153: Add as dependency for iputils
[profile/ivi/opensp.git] / instmac.pl
1 #! /bin/perl -w
2 #
3 # Copyright (c) 1999 Avi Kivity
4 # instmac.pl --  generate template instantiations
5 #                derived from James Clark's instmac.m4
6 #
7
8 $index = 0;
9 $func_index = 0;
10
11 sub header
12     {
13     print <<__HEADER__;
14 #ifdef SP_NAMESPACE
15 namespace SP_NAMESPACE {
16 #endif
17
18
19 #ifdef SP_NAMESPACE
20 }
21 #endif
22 __HEADER__
23     }
24
25 sub instantiate
26     {
27     my ($class) = @_;
28     print <<__INSTANTIATION__;
29 #ifdef __DECCXX
30 #pragma define_template $class
31 #else
32 #ifdef __xlC__
33 #pragma define($class)
34 #else
35 #ifdef SP_ANSI_CLASS_INST
36 template class $class;
37 #else
38 typedef $class Dummy_$index;
39 #endif
40 #endif
41 #endif
42 __INSTANTIATION__
43     ++$index;
44     }
45
46 sub func_instantiate
47     {
48     my ($a1, $a2, $a3, $a4) = @_;
49     print <<__FUNC_INSTANTIATION__;
50 #ifdef __GNUG__
51 template void $a1($a2, $a3, $a4);
52 #else
53 static
54 void  func_$func_index ($a2 arg1, $a3 arg2, $a4 arg3) {
55 (void)$a1(arg1, arg2, arg3);
56 }
57 #endif
58 __FUNC_INSTANTIATION__
59     ++$func_index;
60     }
61
62 header;
63 while (<ARGV>)
64     {
65     if (/^__instantiate\((.*)\)\s*$/)
66         {
67         $arg = $1;
68         $arg = $1 if /`(.*)'/;
69         instantiate $arg;
70         }
71     elsif (/^__instantiate\((.*)\)\s*$/)
72         {
73         die "instantiate_func3 found!";
74         }
75     else
76         {
77         print;
78         }
79     }