-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmake_libcontext.py
More file actions
executable file
·106 lines (77 loc) · 3.56 KB
/
make_libcontext.py
File metadata and controls
executable file
·106 lines (77 loc) · 3.56 KB
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
#!/usr/bin/python
import re
files = [
["jump_i386_ms_pe_gas.S", "windows_i386", "gcc"],
["make_i386_ms_pe_gas.S", "windows_i386", "gcc"],
["jump_x86_64_ms_pe_gas.S", "windows_x86_64", "gcc"],
["make_x86_64_ms_pe_gas.S", "windows_x86_64", "gcc"],
["jump_i386_sysv_elf_gas.S", "linux_i386", "gcc"],
["make_i386_sysv_elf_gas.S", "linux_i386", "gcc"],
["jump_x86_64_sysv_elf_gas.S", "linux_x86_64", "gcc"],
["make_x86_64_sysv_elf_gas.S", "linux_x86_64", "gcc"],
["jump_x86_64_sysv_macho_gas.S", "apple_x86_64", "gcc"],
["make_x86_64_sysv_macho_gas.S", "apple_x86_64", "gcc"],
["jump_i386_sysv_macho_gas.S", "apple_i386", "gcc"],
["make_i386_sysv_macho_gas.S", "apple_i386", "gcc"],
["jump_arm_aapcs_elf_gas.S", "linux_arm32", "gcc"],
["make_arm_aapcs_elf_gas.S", "linux_arm32", "gcc"],
["jump_arm64_aapcs_elf_gas.S", "linux_arm64", "gcc"],
["make_arm64_aapcs_elf_gas.S", "linux_arm64", "gcc"]
#["jump_arm_aapcs_elf_gas.S", "linux_arm", "gcc"],
#["jump_arm_aapcs_macho_gas.S", "apple_arm", "gcc"],
#["jump_ppc32_sysv_elf_gas.S", "linux_ppc32", "gcc"],
#["jump_ppc32_sysv_macho_gas.S", "apple_ppc32", "gcc"],
#["jump_ppc64_sysv_elf_gas.S", "linux_ppc64", "gcc"],
#["jump_ppc64_sysv_macho_gas.S", "apple_ppc64", "gcc"],
#["jump_x86_64_sysv_macho_gas.S", "apple_x86_64", "gcc"],
#["make_arm_aapcs_elf_gas.S", "linux_arm", "gcc"],
#["make_arm_aapcs_macho_gas.S", "apple_arm", "gcc"],
#["make_ppc32_sysv_elf_gas.S", "linux_ppc32", "gcc"],
#["make_ppc32_sysv_macho_gas.S", "apple_ppc32", "gcc"],
#["make_ppc64_sysv_elf_gas.S", "linux_ppc64", "gcc"],
#["make_ppc64_sysv_macho_gas.S", "apple_ppc64", "gcc"],
];
def removeCCppComment( text ) :
def blotOutNonNewlines( strIn ) : # Return a string containing only the newline chars contained in strIn
return "" + ("\n" * strIn.count('\n'))
def replacer( match ) :
s = match.group(0)
if s.startswith('/'): # Matched string is //...EOL or /*...*/ ==> Blot out all non-newline chars
return blotOutNonNewlines(s)
else: # Matched string is '...' or "..." ==> Keep unchanged
return s
pattern = re.compile(
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE
)
return re.sub(pattern, replacer, text)
ignore_tokens = [".file"]
f_out=open("libcontext.cpp","w")
f_out.write("/*\n")
f_out.write("\n")
f_out.write(" auto-generated file, do not modify!\n");
f_out.write(" libcontext - a slightly more portable version of boost::context\n");
f_out.write(" Copyright Martin Husemann 2013.\n");
f_out.write(" Copyright Oliver Kowalke 2009.\n");
f_out.write(" Copyright Sergue E. Leontiev 2013\n");
f_out.write(" Copyright Thomas Sailer 2013.\n");
f_out.write(" Minor modifications by Tomasz Wlostowski 2016.\n");
f_out.write("\n")
f_out.write(" Distributed under the Boost Software License, Version 1.0.\n");
f_out.write(" (See accompanying file LICENSE_1_0.txt or copy at\n");
f_out.write(" http://www.boost.org/LICENSE_1_0.txt)\n");
f_out.write("\n")
f_out.write("*/\n");
f_out.write("#include \"libcontext.h\"\n")
for [f_name, platform, compiler] in files:
f_out.write("#if defined(LIBCONTEXT_PLATFORM_%s) && defined(LIBCONTEXT_COMPILER_%s)\n" %( platform, compiler ))
f_out.write("__asm (\n")
for l in removeCCppComment (open(f_name).read()).split('\n'):
tokens = l.split()
if len(tokens) > 0 and tokens[0] not in ignore_tokens:
f_out.write("\"%s\\n\"\n"%l.replace('"','\\"'))
# f_out.write(l)
f_out.write(");\n\n");
# f_out.write(t)
f_out.write("#endif\n\n")
f_out.close()