Commit 134bba49 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Use runtime.h to look for runtime function names.

R=jkummerow@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24201 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c87651f0
...@@ -8,135 +8,53 @@ import os ...@@ -8,135 +8,53 @@ import os
import re import re
import sys import sys
FILENAME = "src/runtime.cc" FILENAME = "src/runtime.h"
FUNCTION = re.compile("^RUNTIME_FUNCTION\(Runtime_(\w+)") LISTHEAD = re.compile(r"#define\s+(\w+LIST\w*)\((\w+)\)")
FUNCTIONEND = "}\n" LISTBODY = re.compile(r".*\\$")
MACRO = re.compile(r"^#define ([^ ]+)\(([^)]*)\) *([^\\]*)\\?\n$") BLACKLIST = ['INLINE_FUNCTION_LIST']
FIRST_WORD = re.compile("^\s*(.*?)[\s({\[]")
# Expand these macros, they define further runtime functions.
EXPAND_MACROS = [
"BUFFER_VIEW_GETTER",
"DATA_VIEW_GETTER",
"DATA_VIEW_SETTER",
"ELEMENTS_KIND_CHECK_RUNTIME_FUNCTION",
"FIXED_TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION",
"RUNTIME_UNARY_MATH",
"TYPED_ARRAYS_CHECK_RUNTIME_FUNCTION",
]
class Function(object): class Function(object):
def __init__(self, match): def __init__(self, match):
self.name = match.group(1) 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)
class Macro(object):
def __init__(self, match): def FindLists(filename):
self.name = match.group(1) lists = []
self.args = [s.strip() for s in match.group(2).split(",")] current_list = []
self.lines = [] mode = "SEARCHING"
self.indentation = 0
self.AddLine(match.group(3))
def AddLine(self, line):
if not line: return
if not self.lines:
# This is the first line, detect indentation.
self.indentation = len(line) - len(line.lstrip())
line = line.rstrip("\\\n ")
if not line: return
assert len(line[:self.indentation].strip()) == 0, \
("expected whitespace: '%s', full line: '%s'" %
(line[:self.indentation], line))
line = line[self.indentation:]
if not line: return
self.lines.append(line + "\n")
def Finalize(self):
for arg in self.args:
pattern = re.compile(r"(##|\b)%s(##|\b)" % arg)
for i in range(len(self.lines)):
self.lines[i] = re.sub(pattern, "%%(%s)s" % arg, self.lines[i])
def FillIn(self, arg_values):
filler = {}
assert len(arg_values) == len(self.args)
for i in range(len(self.args)):
filler[self.args[i]] = arg_values[i]
result = []
for line in self.lines:
result.append(line % filler)
return result
def ReadFileAndExpandMacros(filename):
found_macros = {}
expanded_lines = []
with open(filename, "r") as f: with open(filename, "r") as f:
found_macro = None
for line in f: for line in f:
if found_macro is not None: if mode == "SEARCHING":
found_macro.AddLine(line) match = LISTHEAD.match(line)
if not line.endswith("\\\n"): if match and match.group(1) not in BLACKLIST:
found_macro.Finalize() mode = "APPENDING"
found_macro = None current_list.append(line)
continue else:
current_list.append(line)
match = MACRO.match(line) match = LISTBODY.match(line)
if match: if not match:
found_macro = Macro(match) mode = "SEARCHING"
if found_macro.name in EXPAND_MACROS: lists.append(current_list)
found_macros[found_macro.name] = found_macro current_list = []
else: return lists
found_macro = None
continue
match = FIRST_WORD.match(line)
if match:
first_word = match.group(1)
if first_word in found_macros:
MACRO_CALL = re.compile("%s\(([^)]*)\)" % first_word)
match = MACRO_CALL.match(line)
assert match
args = [s.strip() for s in match.group(1).split(",")]
expanded_lines += found_macros[first_word].FillIn(args)
continue
expanded_lines.append(line)
return expanded_lines
# Detects runtime functions by parsing FILENAME. # Detects runtime functions by parsing FILENAME.
def FindRuntimeFunctions(): def FindRuntimeFunctions():
functions = [] functions = []
expanded_lines = ReadFileAndExpandMacros(FILENAME) lists = FindLists(FILENAME)
function = None for list in lists:
partial_line = "" function_re = ListMacroRe(list)
for line in expanded_lines: for line in list:
# Multi-line definition support, ignoring macros. match = function_re.match(line)
if line.startswith("RUNTIME_FUNCTION") and not line.endswith("{\n"): if match:
if line.endswith("\\\n"): continue functions.append(Function(match))
partial_line = line.rstrip()
continue
if partial_line:
partial_line += " " + line.strip()
if partial_line.endswith("{"):
line = partial_line
partial_line = ""
else:
continue
match = FUNCTION.match(line)
if match:
function = Function(match)
continue
if function is None: continue
if line == FUNCTIONEND:
if function is not None:
functions.append(function)
function = None
return functions return functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment