source: webkit/trunk/Source/JavaScriptCore/create-symbol-table-index.py@ 184636

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