Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / filter / generate_gr_fir_util.py
1 #!/bin/env python
2 #
3 # Copyright 2003 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 from generate_utils import *
24
25 def make_info_struct (out, sig):
26     out.write (
27 '''
28 struct gr_fir_%s_info {
29   const char    *name;             // implementation name, e.g., "generic", "SSE", "3DNow!"
30   gr_fir_%s     *(*create)(const std::vector<%s> &taps);
31 };
32 ''' % (sig, sig, tap_type(sig)))
33
34 def make_create (out, sig):
35     out.write ('''  static gr_fir_%s *create_gr_fir_%s (const std::vector<%s> &taps);
36 ''' % (sig, sig, tap_type (sig)))
37     
38 def make_info (out, sig):
39     out.write ('''  static void get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info);
40 ''' % (sig, sig))
41     
42
43 # ----------------------------------------------------------------
44
45 def make_gr_fir_util_h ():
46     out = open_and_log_name ('gr_fir_util.h', 'w')
47     out.write (copyright)
48
49     out.write (
50 '''
51 /*
52  * WARNING: This file is automatically generated by
53  * generate_gr_fir_util.py.
54  *
55  * Any changes made to this file will be overwritten.
56  */
57
58 #ifndef INCLUDED_GR_FIR_UTIL_H
59 #define INCLUDED_GR_FIR_UTIL_H
60
61 /*!
62  * \\brief routines to create gr_fir_XXX's
63  *
64  * This class handles selecting the fastest version of the finite
65  * implulse response filter available for your platform.  This
66  * interface should be used by the rest of the system for creating
67  * gr_fir_XXX's.
68  *
69  * The trailing suffix has the form _IOT where I codes the input type,
70  * O codes the output type, and T codes the tap type.
71  * I,O,T are elements of the set 's' (short), 'f' (float), 'c' (gr_complex), 
72  * 'i' (short)
73  */
74
75 #include <gr_types.h>
76
77 ''')
78    
79     for sig in fir_signatures:
80        out.write ('class gr_fir_%s;\n' % sig);
81
82     out.write ('\n// structures returned by get_gr_fir_XXX_info methods\n\n')
83
84     for sig in fir_signatures:
85         make_info_struct (out, sig)
86
87     out.write ('''
88 struct gr_fir_util {
89
90   // create a fast version of gr_fir_XXX.
91
92 ''')
93     
94     for sig in fir_signatures:
95         make_create (out, sig)
96
97     out.write ('''
98   // Get information about all gr_fir_XXX implementations.
99   // This is useful for benchmarking, testing, etc without having to
100   // know a priori what's linked into this image
101   //
102   // The caller must pass in a valid pointer to a vector.
103   // The vector will be filled with structs describing the
104   // available implementations.
105
106 ''')
107
108     for sig in fir_signatures:
109         make_info (out, sig)
110
111     out.write ('''
112 };
113
114 #endif /* INCLUDED_GR_FIR_UTIL_H */
115 ''')
116     out.close ()
117
118
119 # ----------------------------------------------------------------
120
121 def make_constructor_cc (out, sig):
122     out.write (
123 '''
124 gr_fir_%s *
125 gr_fir_util::create_gr_fir_%s (const std::vector<%s> &taps)
126 {
127   return gr_fir_sysconfig_singleton()->create_gr_fir_%s (taps);
128 }
129 ''' % (sig, sig, tap_type (sig), sig))
130
131
132 def make_info_cc (out, sig):
133     out.write (
134 '''
135 void
136 gr_fir_util::get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info)
137 {
138   gr_fir_sysconfig_singleton()->get_gr_fir_%s_info (info);
139 }
140 ''' % (sig, sig, sig))
141
142     
143 def make_gr_fir_util_cc ():
144     out = open_and_log_name ('gr_fir_util.cc', 'w')
145     out.write (copyright)
146     out.write ('''
147
148 #ifdef HAVE_CONFIG_H
149 #include <config.h>
150 #endif
151 #include <gr_fir_util.h>
152 #include <gr_fir_sysconfig.h>
153
154 //
155 // There's no problem that can't be solved by the addition of
156 // another layer of indirection...
157 //
158
159 // --- constructors ---
160
161 ''')
162
163     for sig in fir_signatures:
164         make_constructor_cc (out, sig)
165
166     out.write ('''
167 // --- info gatherers ---
168
169 ''')
170     
171     for sig in fir_signatures:
172         make_info_cc (out, sig)
173
174     out.close ()    
175     
176
177 # ----------------------------------------------------------------
178
179 def generate ():
180     make_gr_fir_util_h ()
181     make_gr_fir_util_cc ()
182
183 if __name__ == '__main__':
184     generate ()
185