-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpprof-cc.py
More file actions
executable file
·139 lines (109 loc) · 4.04 KB
/
pprof-cc.py
File metadata and controls
executable file
·139 lines (109 loc) · 4.04 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python2.7
import argparse
import os
import sys
import pprof
def parseArguments():
"""
:return:
"""
description = 'polly-profcc is a simple replacement for compiler drivers like ' \
'gcc, clang or icc.'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('files', nargs='*')
parser.add_argument('-o', dest='output',
help='the name of the output file',
required=False)
parser.add_argument('-include', action='append',
dest='extra_includes',
default=[],
help='implicit #include directives')
parser.add_argument('-I', action='append',
dest='incdirs',
default=[],
help='include search path')
parser.add_argument('-l', action='append',
dest='libraries',
default=[],
help='library flags to pass to the linker')
parser.add_argument('-L', action='append',
dest='librarypath',
default=[],
help='library paths to pass to the linker')
parser.add_argument('-S', action='store_true',
default='gnu89',
required=False)
parser.add_argument('-fPIC', action='store_true',
help='Position-Independent Code')
parser.add_argument('-fpic', action='store_true',
help='Position-Independent Code')
parser.add_argument('-prg', action='store_true',
help='Show the compilation progress')
parser.add_argument('-c', action='store_true',
help='compile and assemble, but do not link')
parser.add_argument('-commands', help='print command lines executed',
action='store_true')
parser.add_argument('-v', '--version', dest='version', action='store_true',
help='print version info')
arguments, argv = parser.parse_known_args()
if argv:
arguments.unknown_args = filter(lambda x: x[0] == '-', argv)
arguments.files = arguments.files + filter(lambda x: x[0] != '-', argv)
else:
arguments.unknown_args = []
return arguments
def compile_no_link(args, flags):
"""
:param args:
:param flags:
:return:
"""
includes = ['-include' + x for x in args.extra_includes] + \
['-I' + x for x in args.incdirs]
commandLine = [pprof.clang(), '-c', '-emit-llvm'] + includes
commandLine = commandLine + args.unknown_args + args.files
out = ''
if args.output:
out = args.output
elif args.c and len(args.files) == 1:
out = os.path.splitext(args.files[0])[0]
out = os.path.basename(out) + '.o'
if out:
commandLine = commandLine + ['-o', out]
pprof.log_exec(
args, commandLine, 'Creating BITCODE (unoptimized)', False)
commandLine = ['opt', out, '-o', out]
pprof.log_exec(args, commandLine, 'Creating bitcode', False)
return args.output
def print_version(args):
"""
:param args:
"""
pprof.log_exec(args, [pprof.GCC, '--version'],
'Version check pass-through', False)
def main():
"""
:return:
"""
args = parseArguments()
# PWN configure scripts:
if (args.version):
return print_version(args)
# Fortran
if sys.argv[0].endswith('fortran'):
pprof.FORTRAN = True
# C or C++?
if sys.argv[0].endswith('++'):
pprof.GCC = 'g++'
pprof.CLANG = 'clang++'
if args.c:
compile_no_link(args, [])
else:
ir = pprof.link_ir(args, None)
pprof.link(ir, args)
if __name__ == '__main__':
main()
# if pprof.FORTRAN:
# commandLine = ['gfortran', '-fplugin=/usr/lib64/llvm/dragonegg.so',
# '-fplugin-arg-dragonegg-emit-ir',
# '-S'] + args.unknown_args + args.files