File: create.py

package info (click to toggle)
tinyssh 20250501-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,388 kB
  • sloc: ansic: 20,245; sh: 1,582; python: 1,449; makefile: 913
file content (117 lines) | stat: -rwxr-xr-x 2,679 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/env python3

vars = 'k','l','p','q','r','s','x','y','z'

with open('version') as f:
  version = f.read().strip()

# ===== top

csh = f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */

#ifndef crypto_intN_h
#define crypto_intN_h

#include <inttypes.h>
#define crypto_intN intN_t
#define crypto_intN_unsigned uintN_t

#define crypto_intN_optblocker namespace_intN_optblocker
extern volatile crypto_intN crypto_intN_optblocker;

'''

cuh = f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */

#ifndef crypto_uintN_h
#define crypto_uintN_h

#include <inttypes.h>
#define crypto_uintN uintN_t
#define crypto_uintN_signed intN_t

#define crypto_uintN_signed_optblocker namespace_uintN_signed_optblocker
extern volatile crypto_uintN_signed crypto_uintN_signed_optblocker;

'''

# ===== functions

functions = []

with open('functions') as f:
  which,fun = 'both',None
  for line in f:
    if fun is None:
      if line.startswith('#'): continue
      if line.strip() == '': continue
      if line.strip() == 'SIGNED:':
        which = 'signed'
        continue
      if line.strip() == 'UNSIGNED:':
        which = 'unsigned'
        continue
      fun = ''
    fun += line
    if line.strip() == '}':
      functions += [(which,fun)]
      which,fun = 'both',None

for which,fun in functions:
  if which in ('both','signed'):
    data = fun
    data = data.replace('TYPE','crypto_intN')
    data = data.replace('UNSIGNED','crypto_intN_unsigned')
    data = data.replace('SIGNED','crypto_intN')
    for v in vars:
      data = data.replace(v.upper(),'crypto_intN_'+v)
    csh += '__attribute__((unused))\n'
    csh += 'static inline\n'
    csh += data
    csh += '\n'

  if which in ('both','unsigned'):
    data = fun
    data = data.replace('TYPE','crypto_uintN')
    data = data.replace('UNSIGNED','crypto_uintN')
    data = data.replace('SIGNED','crypto_uintN_signed')
    for v in vars:
      data = data.replace(v.upper(),'crypto_uintN_'+v)
    cuh += '__attribute__((unused))\n'
    cuh += 'static inline\n'
    cuh += data
    cuh += '\n'

# ===== bottom

csh += '''#endif
'''

cuh += '''#endif
'''

# ===== ship it

with open('crypto_intN.h','w') as f:
  f.write(csh)

with open('crypto_uintN.h','w') as f:
  f.write(cuh)

with open('intN_optblocker.c','w') as f:
  f.write(f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#include "crypto_intN.h"

volatile crypto_intN crypto_intN_optblocker = 0;
''')

with open('uintN_optblocker.c','w') as f:
  f.write(f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#include "crypto_uintN.h"

volatile crypto_uintN_signed crypto_uintN_signed_optblocker = 0;
''')