Debian Codegraph @

gcc/ada/xspack.py

raw
1 #! /usr/bin/env python
2
3 # #
4 # GNAT COMPILER COMPONENTS #
5 # #
6 # X S P A C K #
7 # #
8 # Copyright (C) 2001-2024, Free Software Foundation, Inc. #
9 # #
10 # GNAT is free software; you can redistribute it and/or modify it under #
11 # terms of the GNU General Public License as published by the Free Soft- #
12 # ware Foundation; either version 3, or (at your option) any later ver- #
13 # sion. GNAT is distributed in the hope that it will be useful, but WITH- #
14 # OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
15 # or FITNESS FOR A PARTICULAR PURPOSE. #
16 # #
17 # As a special exception under Section 7 of GPL version 3, you are granted #
18 # additional permissions described in the GCC Runtime Library Exception, #
19 # version 3.1, as published by the Free Software Foundation. #
20 # #
21 # You should have received a copy of the GNU General Public License and #
22 # a copy of the GCC Runtime Library Exception along with this program; #
23 # see the files COPYING3 and COPYING.RUNTIME respectively. If not, see #
24 # <http://www.gnu.org/licenses/>. #
25 # #
26 # GNAT was originally developed by the GNAT team at New York University. #
27 # Extensive contributions were provided by Ada Core Technologies Inc. #
28
29 # xspack
30
31 # Generate s-pack*.{ads,adb} from templates s-pack.ads.tmpl and s-pack.adb.tmpl
32
33 tmpl_base = "s-pack.ad%c.tmpl"
34
35
36 def read_template(part):
37 return open(tmpl_base % part).readlines()
38
39
40 def output(pkg, bits, part):
41 global tmpl
42
43 bits_str_pad = "%02d" % bits
44 if bits > 99:
45 bits_str_dbl = "1 %d %d" % ((bits / 10) % 10, bits % 10)
46 else:
47 bits_str_dbl = "%d %d " % (bits / 10, bits % 10)
48 bits_str = "%d" % bits
49
50 out = open(pkg % (bits, part), 'w')
51 skip = False
52
53 for line in tmpl[part]:
54 if line.find('@even') == 0 and bits % 2 == 1:
55 skip = True
56 if line.find('@/even') == 0:
57 skip = False
58 if line[0] != '@' and not skip:
59 line = line.replace('@@', bits_str_pad)
60 line = line.replace('@ @ ', bits_str_dbl)
61 line = line.replace('@', bits_str)
62 out.write(line)
63
64
65 parts = ['s', 'b']
66 tmpl = {}
67
68 for part in parts:
69 tmpl[part] = read_template(part)
70
71 for bits in range(1, 128):
72 if bits & (bits - 1) == 0:
73 # Power of two: no package generated
74 continue
75
76 if bits > 99:
77 pkg_base = "s-pack%3d.ad%c"
78 else:
79 pkg_base = "s-pack%02d.ad%c"
80
81 for part in parts:
82 output(pkg_base, bits, part)