diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2016-09-07 22:34:53 +0700 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2016-10-23 07:38:15 +0000 |
commit | 6908fa783d85ef4391755757bf4856a2d5ba860c (patch) | |
tree | 10c94c8661d0b5fa65ad02b0c37edc474423e708 /utils | |
parent | d2d9760c08f35a231d32f0ebeb73b2927e5573b3 (diff) |
utils/conv_gen.py: improve output formatting
To keep the generated tables readable, line with should be limited.
So, now there are the following limitations:
- _print_term(): up to 12 numbers per line,
- _print_puncture(): up to 12 numbers per line,
- _print_x(): up to 4 blocks per line.
Change-Id: I95256c4ad402a3c088bdb6c5a5cda8b17c31881c
Diffstat (limited to 'utils')
-rw-r--r-- | utils/conv_gen.py | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/utils/conv_gen.py b/utils/conv_gen.py index 38ea63b5..715a1462 100644 --- a/utils/conv_gen.py +++ b/utils/conv_gen.py @@ -129,17 +129,22 @@ class ConvolutionalCode(object): return ns, nb def _print_term(self, fi, num_states, pack = False): - d = [] + items = [] + for state in range(num_states): if pack: x = pack(self.next_term_output(state)) else: x = self.next_term_state(state) - d.append("%d, " % x) - print >>fi, "\t%s" % ''.join(d) + items.append(x) + + # Up to 12 numbers should be placed per line + print_formatted(items, "%3d, ", 12, fi) def _print_x(self, fi, num_states, pack = False): + items = [] + for state in range(num_states): if pack: x0 = pack(self.next_output(state, 0)) @@ -148,7 +153,14 @@ class ConvolutionalCode(object): x0 = self.next_state(state, 0) x1 = self.next_state(state, 1) - print >>fi, "\t{ %2d, %2d }," % (x0, x1) + items.append((x0, x1)) + + # Up to 4 blocks should be placed per line + print_formatted(items, "{ %2d, %2d }, ", 4, fi) + + def _print_puncture(self, fi): + # Up to 12 numbers should be placed per line + print_formatted(self.puncture, "%3d, ", 12, fi) def gen_tables(self, pref, fi): pack = lambda n: \ @@ -175,8 +187,7 @@ class ConvolutionalCode(object): if len(self.puncture): print >>fi, "\nstatic const int %s_puncture[] = {" % self.name - for p in self.puncture: - print >>fi, "\t%d," % p + self._print_puncture(fi) print >>fi, "};" # Write description as a multi-line comment @@ -207,6 +218,21 @@ def combine(src, sel, nb): fn_xor = lambda x, y: x ^ y return reduce(fn_xor, [(x >> n) & 1 for n in range(nb)]) +def print_formatted(items, format, count, fi): + counter = 0 + + # Print initial indent + fi.write("\t") + + for item in items: + if counter > 0 and counter % count == 0: + fi.write("\n\t") + + fi.write(format % item) + counter += 1 + + fi.write("\n") + # Polynomials according to 3GPP TS 05.03 Annex B G0 = poly(0, 3, 4) G1 = poly(0, 1, 3, 4) |