]> git.gag.com Git - debian/gnuradio/blob - pmt/src/lib/generate_unv.py
merged interim/pmt changes r2243:2248 into the trunk
[debian/gnuradio] / pmt / src / lib / generate_unv.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006 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., 59 Temple Place - Suite 330,
20 # Boston, MA 02111-1307, USA.
21
22
23 """
24 Generate code for uniform numeric vectors
25 """
26
27 import re, os, os.path
28
29
30 unv_types = (
31     ('u8', 'uint8_t'),
32     ('s8', 'int8_t'),
33     ('u16', 'uint16_t'),
34     ('s16', 'int16_t'),
35     ('u32', 'uint32_t'),
36     ('s32', 'int32_t'),
37     ('u64', 'uint64_t'),
38     ('s64', 'int64_t'),
39     ('f32', 'float'),
40     ('f64', 'double'),
41     ('c32', 'std::complex<float>'),
42     ('c64', 'std::complex<double>')
43     )
44
45 header = """\
46 /* -*- c++ -*- */
47 /*
48  * Copyright 2006 Free Software Foundation, Inc.
49  * 
50  * This file is part of GNU Radio
51  * 
52  * GNU Radio is free software; you can redistribute it and/or modify
53  * it under the terms of the GNU General Public License as published by
54  * the Free Software Foundation; either version 2, or (at your option)
55  * any later version.
56  * 
57  * GNU Radio is distributed in the hope that it will be useful,
58  * but WITHOUT ANY WARRANTY; without even the implied warranty of
59  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
60  * GNU General Public License for more details.
61  * 
62  * You should have received a copy of the GNU General Public License
63  * along with GNU Radio; see the file COPYING.  If not, write to
64  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
65  * Boston, MA 02111-1307, USA.
66  */
67 """
68
69 guard_head = """
70 #ifndef INCLUDED_PMT_UNV_INT_H
71 #define INCLUDED_PMT_UNV_INT_H
72 """
73
74 guard_tail = """
75 #endif
76 """
77
78 includes = """
79 #ifdef HAVE_CONFIG_H
80 #include <config.h>
81 #endif
82 #include <vector>
83 #include <pmt.h>
84 #include "pmt_int.h"
85
86 """
87
88
89 # set srcdir to the directory that contains Makefile.am
90 try:
91     srcdir = os.environ['srcdir']
92 except KeyError, e:
93     srcdir = "."
94 srcdir = srcdir + '/'
95
96
97 def open_src (name, mode):
98     global srcdir
99     return open(os.path.join (srcdir, name), mode)
100
101
102 def do_substitution (d, input, out_file):
103     def repl (match_obj):
104         key = match_obj.group (1)
105         # print key
106         return d[key]
107     
108     out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input)
109     out_file.write (out)
110
111
112 def generate_h():
113     template = open_src('unv_template.h.t', 'r').read()
114     output = open('pmt_unv_int.h', 'w')
115     output.write(header)
116     output.write(guard_head)
117     for tag, typ in unv_types:
118         d = { 'TAG' : tag, 'TYPE' : typ }
119         do_substitution(d, template, output)
120     output.write(guard_tail)
121
122
123 def generate_cc():
124     template = open_src('unv_template.cc.t', 'r').read()
125     output = open('pmt_unv.cc', 'w')
126     output.write(header)
127     output.write(includes)
128     for tag, typ in unv_types:
129         d = { 'TAG' : tag, 'TYPE' : typ }
130         do_substitution(d, template, output)
131
132
133 def main():
134     generate_h()
135     generate_cc()
136
137 if __name__ == '__main__':
138     main()