Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/simde_update.py
6174 views
1
#!/usr/bin/env python3
2
# Copyright 2020 The Emscripten Authors. All rights reserved.
3
# Emscripten is available under two separate licenses, the MIT license and the
4
# University of Illinois/NCSA Open Source License. Both these licenses can be
5
# found in the LICENSE file.
6
7
"""Updates the arm_neon.h header taken from SIMDe
8
(https://github.com/simd-everywhere/simde) in system/include/neon
9
"""
10
11
import os
12
import re
13
import subprocess
14
import sys
15
from os import path
16
17
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
18
__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))
19
sys.path.insert(0, __rootdir__)
20
21
from tools.shared import get_emscripten_temp_dir
22
23
tmpdir = get_emscripten_temp_dir()
24
emdir = __rootdir__
25
26
27
def main():
28
if len(sys.argv) == 2:
29
simde_dir = sys.argv[1]
30
elif len(sys.argv) == 1:
31
simde_dir = None
32
else:
33
print('''USAGE:
34
./simde_update.py [SIMDE_REPO_DIRECTORY]''')
35
36
if not simde_dir:
37
os.mkdir(path.join(tmpdir, "simde"))
38
os.system("git clone [email protected]:simd-everywhere/simde " + path.join(tmpdir, "simde"))
39
simde_dir = path.join(tmpdir, "simde")
40
41
else:
42
print("Using provided repository without updating [make sure it's up to date!]")
43
44
try:
45
neon_h_buf = subprocess.check_output(
46
[path.join(simde_dir, "amalgamate.py"), path.join(simde_dir, "simde", "arm", "neon.h")],
47
text=True)
48
except subprocess.CalledProcessError as e:
49
print("amalgamate.py returned error: " + str(e))
50
return 1
51
52
try:
53
os.mkdir(path.join(emdir, "system", "include", "compat"))
54
except FileExistsError:
55
if not path.isdir(path.join(emdir, "system", "include", "compat")):
56
print("system/include/compat exists and is not a directory, exiting...")
57
return 1
58
59
SIMDE_FILE_HEADER_RE = r'^(/\* :: )(Begin |End )[^ ]+/(simde/simde/[^ ]+ :: \*/$)'
60
# Replace file headers, which contain tmp directory names and changes every time we
61
# update simde, causing a larger diff than necessary.
62
neon_h_buf = re.sub(SIMDE_FILE_HEADER_RE, r'\1\2\3', neon_h_buf, count=0, flags=re.MULTILINE)
63
64
line_to_prefix = "# define HEDLEY_EMSCRIPTEN_VERSION HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_MAJOR__, __EMSCRIPTEN_MINOR__, __EMSCRIPTEN_TINY__)\n"
65
line_to_insert = "#include <emscripten/version.h>\n"
66
try:
67
insert_location = neon_h_buf.index(line_to_prefix)
68
except ValueError:
69
print(f"Error looking for place to insert {line_to_insert[:-1]!r}. Please update 'line_to_prefix' in simde_update.py.")
70
return 1
71
neon_h_buf = neon_h_buf[:insert_location] + line_to_insert + neon_h_buf[insert_location:]
72
73
with open(path.join(emdir, "system", "include", "compat", "arm_neon.h"), "w+") as f:
74
try:
75
f.write("#define SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES\n")
76
f.write("#define SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES\n")
77
f.write("#define SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES\n")
78
f.write(neon_h_buf)
79
f.write("#undef SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES\n")
80
f.write("#undef SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES\n")
81
f.write("#undef SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES\n")
82
except Exception:
83
print("error writing 'system/include/compat/arm_neon.h'")
84
return 1
85
print("'system/include/compat/arm_neon.h' updated")
86
87
return 0
88
89
90
if __name__ == '__main__':
91
sys.exit(main())
92
93