Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/maint/simde_update.py
4150 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
16
from os import path
17
18
__scriptdir__ = os.path.dirname(os.path.abspath(__file__))
19
__rootdir__ = os.path.dirname(os.path.dirname(__scriptdir__))
20
sys.path.insert(0, __rootdir__)
21
22
from tools.shared import get_emscripten_temp_dir
23
24
tmpdir = get_emscripten_temp_dir()
25
emdir = __rootdir__
26
27
28
def main():
29
if len(sys.argv) == 2:
30
simde_dir = sys.argv[1]
31
elif len(sys.argv) == 1:
32
simde_dir = None
33
else:
34
print('''USAGE:
35
./simde_update.py [SIMDE_REPO_DIRECTORY]''')
36
37
if not simde_dir:
38
os.mkdir(path.join(tmpdir, "simde"))
39
os.system("git clone [email protected]:simd-everywhere/simde " + path.join(tmpdir, "simde"))
40
simde_dir = path.join(tmpdir, "simde")
41
42
else:
43
print("Using provided repository without updating [make sure it's up to date!]")
44
45
try:
46
neon_h_buf = subprocess.check_output(
47
[path.join(simde_dir, "amalgamate.py"), path.join(simde_dir, "simde", "arm", "neon.h")],
48
text=True)
49
except subprocess.CalledProcessError as e:
50
print("amalgamate.py returned error: " + str(e))
51
return 1
52
53
try:
54
os.mkdir(path.join(emdir, "system", "include", "compat"))
55
except FileExistsError:
56
if not path.isdir(path.join(emdir, "system", "include", "compat")):
57
print("system/include/compat exists and is not a directory, exiting...")
58
return 1
59
60
SIMDE_FILE_HEADER_RE = r'^(/\* :: )(Begin |End )[^ ]+/(simde/simde/[^ ]+ :: \*/$)'
61
# Replace file headers, which contains tmp directory names and changes every time we
62
# update simde, causing a larger diff than necessary.
63
neon_h_buf = re.sub(SIMDE_FILE_HEADER_RE, r'\1\2\3', neon_h_buf, count=0, flags=re.MULTILINE)
64
65
line_to_prefix = "# define HEDLEY_EMSCRIPTEN_VERSION HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)\n"
66
line_to_insert = "#include <emscripten/version.h>\n"
67
try:
68
insert_location = neon_h_buf.index(line_to_prefix)
69
except ValueError:
70
print(f"Error looking for place to insert {line_to_insert[:-1]!r}. Please update 'line_to_prefix' in simde_update.py.")
71
return 1
72
neon_h_buf = neon_h_buf[:insert_location] + line_to_insert + neon_h_buf[insert_location:]
73
74
with open(path.join(emdir, "system", "include", "compat", "arm_neon.h"), "w+") as f:
75
try:
76
f.write("#define SIMDE_ARM_NEON_A32V7_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_A64V8_ENABLE_NATIVE_ALIASES\n")
81
except Exception:
82
print("error writing 'system/include/compat/arm_neon.h'")
83
return 1
84
print("'system/include/compat/arm_neon.h' updated")
85
86
return 0
87
88
89
if __name__ == '__main__':
90
sys.exit(main())
91
92