-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate_helpers.py
69 lines (56 loc) · 1.36 KB
/
generate_helpers.py
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
#===- generate_helpers.py - Runtime functions for use by generated code-----===#
#
# The LLVM Compiler Infrastructure
#
# This file is distributed under the University of Illinois Open Source
# License. See LICENSE.TXT for details.
#
#===------------------------------------------------------------------------===#
import sys
OPERATIONS = [
'Xchg',
'Add',
'Sub',
'And',
'Nand',
'Or',
'Xor',
'Max',
'Min',
'UMax',
'UMin',
]
def main():
if sys.argv[1] == '--ll-file':
print 'target triple = "i386-pc-linux-gnu"'
for op_name in OPERATIONS:
print """
define i32 @runtime_atomicrmw_i32_%(op_name)s(\
i32* inreg %%ptr, i32 inreg %%val) {
%%result = atomicrmw %(op_name_lc)s i32* %%ptr, i32 %%val seq_cst
ret i32 %%result
}\
""" % {'op_name': op_name,
'op_name_lc': op_name.lower()}
if sys.argv[1] == '--header-file':
print """
#ifndef RUNTIME_HELPERS_ATOMIC_H_
#define RUNTIME_HELPERS_ATOMIC_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
"""
for op_name in OPERATIONS:
# We don't need to declare arguments for this since we only call
# this from directly-generated code, not from C or C++.
print 'uint32_t runtime_atomicrmw_i32_%(op_name)s();' % {
'op_name': op_name}
print """
#ifdef __cplusplus
}
#endif
#endif\
"""
if __name__ == '__main__':
main()