1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#!/usr/bin/env python
#
# Copyright 2006 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
"""
Generate code for uniform numeric vectors
"""
import re, os, os.path
unv_types = (
('u8', 'uint8_t'),
('s8', 'int8_t'),
('u16', 'uint16_t'),
('s16', 'int16_t'),
('u32', 'uint32_t'),
('s32', 'int32_t'),
('u64', 'uint64_t'),
('s64', 'int64_t'),
('f32', 'float'),
('f64', 'double'),
('c32', 'std::complex<float>'),
('c64', 'std::complex<double>')
)
header = """\
/* -*- c++ -*- */
/*
* Copyright 2006 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
"""
guard_tail = """
#endif
"""
includes = """
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <vector>
#include <pmt.h>
#include "pmt_int.h"
"""
qa_includes = """
#include <qa_pmt_unv.h>
#include <cppunit/TestAssert.h>
#include <pmt.h>
#include <stdio.h>
"""
# set srcdir to the directory that contains Makefile.am
try:
srcdir = os.environ['srcdir']
except KeyError, e:
srcdir = "."
srcdir = srcdir + '/'
def open_src (name, mode):
global srcdir
return open(os.path.join (srcdir, name), mode)
def guard_name(filename):
return 'INCLUDED_' + re.sub('\.', '_', filename.upper())
def guard_head(filename):
guard = guard_name(filename)
return """
#ifndef %s
#define %s
""" % (guard, guard)
def do_substitution (d, input, out_file):
def repl (match_obj):
key = match_obj.group (1)
# print key
return d[key]
out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, input)
out_file.write (out)
def generate_h():
template = open_src('unv_template.h.t', 'r').read()
output_filename = 'pmt_unv_int.h'
output = open(output_filename, 'w')
output.write(header)
output.write(guard_head(output_filename))
for tag, typ in unv_types:
d = { 'TAG' : tag, 'TYPE' : typ }
do_substitution(d, template, output)
output.write(guard_tail)
def generate_cc():
template = open_src('unv_template.cc.t', 'r').read()
output = open('pmt_unv.cc', 'w')
output.write(header)
output.write(includes)
for tag, typ in unv_types:
d = { 'TAG' : tag, 'TYPE' : typ }
do_substitution(d, template, output)
def generate_qa_h():
output_filename = 'qa_pmt_unv.h'
output = open(output_filename, 'w')
output.write(header)
output.write(guard_head(output_filename))
output.write('''
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/TestCase.h>
class qa_pmt_unv : public CppUnit::TestCase {
CPPUNIT_TEST_SUITE(qa_pmt_unv);
''')
for tag, typ in unv_types:
output.write(' CPPUNIT_TEST(test_%svector);\n' % (tag,))
output.write('''\
CPPUNIT_TEST_SUITE_END();
private:
''')
for tag, typ in unv_types:
output.write(' void test_%svector();\n' % (tag,))
output.write('};\n')
output.write(guard_tail)
def generate_qa_cc():
template = open_src('unv_qa_template.cc.t', 'r').read()
output = open('qa_pmt_unv.cc', 'w')
output.write(header)
output.write(qa_includes)
for tag, typ in unv_types:
d = { 'TAG' : tag, 'TYPE' : typ }
do_substitution(d, template, output)
def main():
generate_h()
generate_cc()
generate_qa_h()
generate_qa_cc()
if __name__ == '__main__':
main()
|