source: webkit/trunk/Source/JavaScriptCore/build-symbol-table-index.py@ 184871

Last change on this file since 184871 was 184636, checked in by Csaba Osztrogonác, 10 years ago

[JSC] Add missing copyrights and licenses for some scripts
https://bugs.webkit.org/show_bug.cgi?id=145044

Reviewed by Darin Adler.

  • build-symbol-table-index.py:
  • create-llvm-ir-from-source-file.py:
  • create-symbol-table-index.py:
  • Property svn:executable set to *
File size: 4.4 KB
Line 
1#!/usr/bin/python
2
3# Copyright (C) 2014 Apple Inc. All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# 2. Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution.
13#
14# THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26import glob
27import os
28import subprocess
29import sys
30from sets import Set
31from operator import itemgetter
32
33
34current_arch = sys.argv[1]
35
36print("Building Index Table")
37
38if current_arch not in ("x86_64", "arm64"):
39 sys.exit()
40
41bitcode_file_original_directory = os.path.join(os.getenv("TARGET_TEMP_DIR"), "Objects-" + os.getenv("CURRENT_VARIANT"), current_arch)
42
43if not os.path.isdir(bitcode_file_original_directory):
44 print("Failed to build index table at " + bitcode_file_original_directory)
45 sys.exit()
46
47framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch)
48
49
50symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl")
51
52symbol_table = {}
53
54symbol_table_is_out_of_date = False
55
56symbol_table_modification_time = 0
57
58if os.path.isfile(symbol_table_location):
59 symbol_table_modification_time = os.path.getmtime(symbol_table_location)
60
61file_suffix = "bc"
62file_suffix_length = len(file_suffix)
63
64tested_symbols_location = "./tested-symbols.symlst"
65include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
66
67tested_symbols = Set([])
68
69if os.path.isfile(tested_symbols_location):
70 with open(tested_symbols_location, 'r') as file:
71 print("Loading tested symbols")
72 for line in file:
73 tested_symbols.add(line[:-1])
74
75print ("Original directory: " + bitcode_file_original_directory)
76
77for bitcode_file in glob.iglob(os.path.join(framework_directory, "*." + file_suffix)):
78 bitcode_basename = os.path.basename(bitcode_file)
79 bitcode_file_original = os.path.join(bitcode_file_original_directory, bitcode_basename[:-file_suffix_length] + "o")
80 if os.path.getmtime(bitcode_file_original) < symbol_table_modification_time:
81 continue
82
83 symbol_table_is_out_of_date = True
84
85 print("Appending symbols from " + bitcode_basename)
86 lines = subprocess.check_output(["nm", "-U", "-j", bitcode_file]).splitlines()
87
88 for symbol in lines:
89 if symbol[:2] == "__" and symbol[-3:] != ".eh" and symbol in tested_symbols:
90 symbol_table[symbol[1:]] = bitcode_basename
91
92if not symbol_table_is_out_of_date:
93 sys.exit()
94
95if os.path.isfile(symbol_table_location):
96 with open(symbol_table_location, 'r') as file:
97 print("Loading symbol table")
98 for line in file:
99 symbol, _, location = line[:-1].partition(" ")
100 # don't overwrite new symbols with old locations
101 if not symbol in symbol_table:
102 symbol_table[symbol] = location
103
104symbol_list = symbol_table.items()
105
106print("Writing symbol table: " + symbol_table_location)
107print("Writing inline file: " + include_symbol_table_location)
108
109with open(symbol_table_location, "w") as symbol_file:
110 with open(include_symbol_table_location, "w") as include_file:
111 include_file.write("#define FOR_EACH_LIBRARY_SYMBOL(macro)")
112 for symbol, location in symbol_list:
113 symbol_file.write("{} {}\n".format(symbol, location))
114 include_file.write(" \\\nmacro(\"{}\", \"{}\")".format(symbol, location))
115 include_file.write("\n")
116print("Done")
Note: See TracBrowser for help on using the repository browser.