Imported Upstream version 3.2.2
[debian/gnuradio] / gr-trellis / src / lib / generate_trellis.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2006,2007 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 build_utils import expand_template, copyright, open_and_log_name
24 from build_utils_codes import *
25 import re
26
27 # regular blocks
28
29 other_roots = [
30     'trellis_encoder_XX',
31     'trellis_metrics_X',
32     'trellis_viterbi_X',
33     'trellis_viterbi_combined_XX',
34     ]
35
36 other_signatures = (
37     ['bb','bs','bi','ss','si','ii'],
38     ['s','i','f','c'],
39     ['b','s','i'],
40     ['sb','ss','si','ib','is','ii','fb','fs','fi','cb','cs','ci'],
41     )
42
43
44 def is_byte (code3):
45     if i_code (code3) == 'b' or o_code (code3) == 'b':
46         return '1'
47     else:
48         return '0'
49
50
51 def is_short (code3):
52     if i_code (code3) == 's' or o_code (code3) == 's':
53         return '1'
54     else:
55         return '0'
56
57
58 def is_int (code3):
59     if i_code (code3) == 'i' or o_code (code3) == 'i':
60         return '1'
61     else:
62         return '0'
63
64
65 def is_float (code3):
66     if i_code (code3) == 'f' or o_code (code3) == 'f':
67         return '1'
68     else:
69         return '0'
70
71
72 def is_complex (code3):
73     if i_code (code3) == 'c' or o_code (code3) == 'c':
74         return '1'
75     else:
76         return '0'
77
78
79 def standard_dict (name, code3):
80     d = {}
81     d['NAME'] = name
82     d['GUARD_NAME'] = 'INCLUDED_%s_H' % name.upper ()
83     d['BASE_NAME'] = re.sub ('^trellis_', '', name)
84     d['SPTR_NAME'] = '%s_sptr' % name
85     d['WARNING'] = 'WARNING: this file is machine generated.  Edits will be over written'
86     d['COPYRIGHT'] = copyright
87     d['TYPE'] = i_type (code3)
88     d['I_TYPE'] = i_type (code3)
89     d['O_TYPE'] = o_type (code3)
90     d['TAP_TYPE'] = tap_type (code3)
91     d['IS_BYTE'] = is_byte (code3)
92     d['IS_SHORT'] = is_short (code3)
93     d['IS_INT'] = is_int (code3)
94     d['IS_FLOAT'] = is_float (code3)
95     d['IS_COMPLEX'] = is_complex (code3)
96     return d
97
98
99 def expand_h_cc_i (root, sig):
100     # root looks like 'gr_vector_sink_X'
101     name = re.sub ('X+', sig, root)
102     d = standard_dict (name, sig)
103     expand_template (d, root + '.h.t')
104     expand_template (d, root + '.cc.t')
105     expand_template (d, root + '.i.t')
106
107
108 def generate ():
109     i=0
110     for r in other_roots :
111         for s in other_signatures[i]:
112             expand_h_cc_i (r, s)
113         i=i+1
114
115
116 if __name__ == '__main__':
117     generate ()