[PowerPC] Do not use vectors to codegen bswap with Altivec turned off
[llvm-core.git] / tools / llvm-shlib / gen-msvc-exports.py
blob6f0a6786d34fb35492d3fab060dd8d560923f2be
1 #===- gen-msvc-exports.py - Generate C API export file -------*- python -*--===#
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
8 #===------------------------------------------------------------------------===#
10 # Generate an export file from a list of given LIB files. This only exports symbols
11 # that start with LLVM, so it only exports the LLVM C API.
13 # To have CMake run this, set LLVM_BUILD_LLVM_C_DYLIB to on while
14 # building on Windows.
16 # To run manually, build LLVM with Visual Studio, use a Command prompt
17 # to navigate to the directory with the .lib files (Debug\lib etc). Then run
18 # python C:\Path\To\gen-msvc-exports.py --nm ..\bin\llvm-nm.exe LLVM*.lib
20 # If you're generating a 32 bit DLL, use the `--underscore` flag.
21 # If you want to use a different `llvm-nm` executable, pass the path
22 # with the `--nm` flag.
24 # You can use the --output flag to set the name of the export file.
26 #===------------------------------------------------------------------------===#
27 from tempfile import mkstemp
28 from contextlib import contextmanager
29 from subprocess import check_call
30 import argparse
31 import os
32 import re
35 _UNDERSCORE_REGEX = {
36 False: re.compile(r"^\w+\s+T\s+(LLVM.*)$"),
37 True: re.compile(r"^\w+\s+T\s+_(LLVM.*)$")
41 @contextmanager
42 def removing(path):
43 try:
44 yield path
45 finally:
46 os.unlink(path)
49 def touch_tempfile(*args, **kwargs):
50 fd, name = mkstemp(*args, **kwargs)
51 os.close(fd)
52 return name
55 def gen_llvm_c_export(output, underscore, libs, nm):
56 """Generate the export file for the LLVM-C DLL.
58 Run `nm` for each lib in `libs`, and output an export file
59 to `output`. If `underscore` is true, symbols will
60 be assumed to be prefixed with an underscore.
61 """
62 with removing(touch_tempfile(prefix='dumpout', suffix='.txt')) as dumpout:
64 # Get the right regex.
65 p = _UNDERSCORE_REGEX[underscore]
67 with open(output, 'w+t') as output_f:
69 # For each lib get the LLVM* functions it exports.
70 for lib in libs:
71 # Call dumpbin.
72 with open(dumpout, 'w+t') as dumpout_f:
73 check_call([nm, '-g', lib], stdout=dumpout_f)
75 # Get the matching lines.
76 with open(dumpout) as dumpbin:
77 for line in dumpbin:
78 m = p.match(line)
79 if m is not None:
80 output_f.write(m.group(1) + '\n')
83 def main():
84 parser = argparse.ArgumentParser('gen-msvc-exports')
86 parser.add_argument(
87 '-o', '--output', help='output filename', default='LLVM-C.exports'
89 parser.add_argument('-u', '--underscore',
90 help='labels are prefixed with an underscore (use for 32 bit DLLs)',
91 action='store_true'
93 parser.add_argument(
94 '--nm', help='path to the llvm-nm executable', default='llvm-nm'
96 parser.add_argument(
97 'libs', metavar='LIBS', nargs='+', help='list of libraries to generate export from'
100 ns = parser.parse_args()
102 gen_llvm_c_export(ns.output, ns.underscore, ns.libs, ns.nm)
105 if __name__ == '__main__':
106 main()