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
import re
import sys
FILENAME = "src/runtime.cc"
FUNCTION = re.compile("^RUNTIME_FUNCTION\(Runtime_(\w+)")
FUNCTIONEND = "}\n"
MACRO = re.compile(r"^#define ([^ ]+)\(([^)]*)\) *([^\\]*)\\?\n$")
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",
]
FILENAME = "src/runtime.h"
LISTHEAD = re.compile(r"#define\s+(\w+LIST\w*)\((\w+)\)")
LISTBODY = re.compile(r".*\\$")
BLACKLIST = ['INLINE_FUNCTION_LIST']
class Function(object):
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):
self.name = match.group(1)
self.args = [s.strip() for s in match.group(2).split(",")]
self.lines = []
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 = []
def FindLists(filename):
lists = []
current_list = []
mode = "SEARCHING"
with open(filename, "r") as f:
found_macro = None
for line in f:
if found_macro is not None:
found_macro.AddLine(line)
if not line.endswith("\\\n"):
found_macro.Finalize()
found_macro = None
continue
match = MACRO.match(line)
if match:
found_macro = Macro(match)
if found_macro.name in EXPAND_MACROS:
found_macros[found_macro.name] = found_macro
else:
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
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 = []
expanded_lines = ReadFileAndExpandMacros(FILENAME)
function = None
partial_line = ""
for line in expanded_lines:
# Multi-line definition support, ignoring macros.
if line.startswith("RUNTIME_FUNCTION") and not line.endswith("{\n"):
if line.endswith("\\\n"): continue
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
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
......
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