v8/tools/check-name-clashes.py
bmeurer 022ea7e057 [turbofan] Unify Math.floor / Math.ceil optimization.
Provide an intrinsic %MathFloor / %_MathFloor that is used to optimize
both Math.ceil and Math.floor, and use the JS inlining mechanism to
inline Math.ceil into TurboFan code. Although we need to touch code
outside of TurboFan to make this work, this does not affect the way we
handle Math.ceil and/or Math.floor in CrankShaft, because for CrankShaft
the old-style builtin function id based inlining still kicks in first.

Once this solution is stabilized, we can use it for Math.floor as well.
And once that is settled, we can establish it as the unified way to
inline builtins, and get rid of the specialized builtin function id
based inlining at some point.

Note that "builtin" applies to basically every piece of internal
JavaScript/intrinsics based code, so this also applies to the yet to be
defined JavaScript based code stubs and handlers.

BUG=v8:3953
LOG=n
R=yangguo@chromium.org,svenpanne@chromium.org

Review URL: https://codereview.chromium.org/990963003

Cr-Commit-Position: refs/heads/master@{#27086}
2015-03-10 08:42:53 +00:00

120 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright 2014 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import js2c
import os
import re
import sys
FILENAME = "src/runtime/runtime.h"
LISTHEAD = re.compile(r"#define\s+(\w+LIST\w*)\((\w+)\)")
LISTBODY = re.compile(r".*\\$")
BLACKLIST = ['INLINE_FUNCTION_LIST', 'INLINE_OPTIMIZED_FUNCTION_LIST']
class Function(object):
def __init__(self, match):
self.name = match.group(1).strip()
def ListMacroRe(list):
macro = LISTHEAD.match(list[0]).group(2)
re_string = "\s*%s\((\w+)" % macro
return re.compile(re_string)
def FindLists(filename):
lists = []
current_list = []
mode = "SEARCHING"
with open(filename, "r") as f:
for line in f:
if mode == "SEARCHING":
match = LISTHEAD.match(line)
if match and match.group(1) not in BLACKLIST:
mode = "APPENDING"
current_list.append(line)
else:
current_list.append(line)
match = LISTBODY.match(line)
if not match:
mode = "SEARCHING"
lists.append(current_list)
current_list = []
return lists
# Detects runtime functions by parsing FILENAME.
def FindRuntimeFunctions():
functions = []
lists = FindLists(FILENAME)
for list in lists:
function_re = ListMacroRe(list)
for line in list:
match = function_re.match(line)
if match:
functions.append(Function(match))
return functions
class Builtin(object):
def __init__(self, match):
self.name = match.group(1)
def FindJSNatives():
PATH = "src"
fileslist = []
for (root, dirs, files) in os.walk(PATH):
for f in files:
if f.endswith(".js"):
fileslist.append(os.path.join(root, f))
natives = []
regexp = re.compile("^function (\w+)\s*\((.*?)\) {")
matches = 0
for filename in fileslist:
with open(filename, "r") as f:
file_contents = f.read()
file_contents = js2c.ExpandInlineMacros(file_contents)
lines = file_contents.split("\n")
partial_line = ""
for line in lines:
if line.startswith("function") and not '{' in line:
partial_line += line.rstrip()
continue
if partial_line:
partial_line += " " + line.strip()
if '{' in line:
line = partial_line
partial_line = ""
else:
continue
match = regexp.match(line)
if match:
natives.append(Builtin(match))
return natives
def Main():
functions = FindRuntimeFunctions()
natives = FindJSNatives()
errors = 0
runtime_map = {}
for f in functions:
runtime_map[f.name] = 1
for b in natives:
if b.name in runtime_map:
print("JS_Native/Runtime_Function name clash: %s" % b.name)
errors += 1
if errors > 0:
return 1
print("Runtime/Natives name clashes: checked %d/%d functions, all good." %
(len(functions), len(natives)))
return 0
if __name__ == "__main__":
sys.exit(Main())