Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / filter / generate_gr_fir_util.py
1 #!/bin/env python
2 #
3 # Copyright 2003,2009 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 3, 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     if not out:
48         return
49     out.write (copyright)
50
51     out.write (
52 '''
53 /*
54  * WARNING: This file is automatically generated by
55  * generate_gr_fir_util.py.
56  *
57  * Any changes made to this file will be overwritten.
58  */
59
60 #ifndef INCLUDED_GR_FIR_UTIL_H
61 #define INCLUDED_GR_FIR_UTIL_H
62
63 /*!
64  * \\brief routines to create gr_fir_XXX's
65  *
66  * This class handles selecting the fastest version of the finite
67  * implulse response filter available for your platform.  This
68  * interface should be used by the rest of the system for creating
69  * gr_fir_XXX's.
70  *
71  * The trailing suffix has the form _IOT where I codes the input type,
72  * O codes the output type, and T codes the tap type.
73  * I,O,T are elements of the set 's' (short), 'f' (float), 'c' (gr_complex), 
74  * 'i' (short)
75  */
76
77 #include <gr_types.h>
78
79 ''')
80    
81     for sig in fir_signatures:
82        out.write ('class gr_fir_%s;\n' % sig);
83
84     out.write ('\n// structures returned by get_gr_fir_XXX_info methods\n\n')
85
86     for sig in fir_signatures:
87         make_info_struct (out, sig)
88
89     out.write ('''
90 struct gr_fir_util {
91
92   // create a fast version of gr_fir_XXX.
93
94 ''')
95     
96     for sig in fir_signatures:
97         make_create (out, sig)
98
99     out.write ('''
100   // Get information about all gr_fir_XXX implementations.
101   // This is useful for benchmarking, testing, etc without having to
102   // know a priori what's linked into this image
103   //
104   // The caller must pass in a valid pointer to a vector.
105   // The vector will be filled with structs describing the
106   // available implementations.
107
108 ''')
109
110     for sig in fir_signatures:
111         make_info (out, sig)
112
113     out.write ('''
114 };
115
116 #endif /* INCLUDED_GR_FIR_UTIL_H */
117 ''')
118     out.close ()
119
120
121 # ----------------------------------------------------------------
122
123 def make_constructor_cc (out, sig):
124     out.write (
125 '''
126 gr_fir_%s *
127 gr_fir_util::create_gr_fir_%s (const std::vector<%s> &taps)
128 {
129   return gr_fir_sysconfig_singleton()->create_gr_fir_%s (taps);
130 }
131 ''' % (sig, sig, tap_type (sig), sig))
132
133
134 def make_info_cc (out, sig):
135     out.write (
136 '''
137 void
138 gr_fir_util::get_gr_fir_%s_info (std::vector<gr_fir_%s_info> *info)
139 {
140   gr_fir_sysconfig_singleton()->get_gr_fir_%s_info (info);
141 }
142 ''' % (sig, sig, sig))
143
144     
145 def make_gr_fir_util_cc ():
146     out = open_and_log_name ('gr_fir_util.cc', 'w')
147     if not out:
148         return
149     out.write (copyright)
150     out.write ('''
151
152 #ifdef HAVE_CONFIG_H
153 #include <config.h>
154 #endif
155 #include <gr_fir_util.h>
156 #include <gr_fir_sysconfig.h>
157
158 //
159 // There's no problem that can't be solved by the addition of
160 // another layer of indirection...
161 //
162
163 // --- constructors ---
164
165 ''')
166
167     for sig in fir_signatures:
168         make_constructor_cc (out, sig)
169
170     out.write ('''
171 // --- info gatherers ---
172
173 ''')
174     
175     for sig in fir_signatures:
176         make_info_cc (out, sig)
177
178     out.close ()    
179     
180
181 # ----------------------------------------------------------------
182
183 def generate ():
184     make_gr_fir_util_h ()
185     make_gr_fir_util_cc ()
186
187 if __name__ == '__main__':
188     generate ()
189