Quelle check_macroassembler_style.py
Sprache: Python
# vim: set ts=8 sts=4 et sw=4 tw=99: # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
# ---------------------------------------------------------------------------- # This script checks that SpiderMonkey MacroAssembler methods are properly # annotated. # # The MacroAssembler has one interface for all platforms, but it might have one # definition per platform. The code of the MacroAssembler use a macro to # annotate the method declarations, in order to delete the function if it is not # present on the current platform, and also to locate the files in which the # methods are defined. # # This script scans the MacroAssembler.h header, for method declarations. # It also scans MacroAssembler-/arch/.cpp, MacroAssembler-/arch/-inl.h, and # MacroAssembler-inl.h for method definitions. The result of both scans are # uniformized, and compared, to determine if the MacroAssembler.h header as # proper methods annotations. # ----------------------------------------------------------------------------
inlinePrefx = "" if inline:
inlinePrefx = "inline "
signatures = [{"arch": a, "sig": inlinePrefx + signature} for a in archs]
return signatures
file_suffixes = set(
[
a.replace("_", "-") for a in all_architecture_names.union(all_shared_architecture_names).union(
all_unsupported_architectures_names
)
]
)
# Raise an error if the check_macroassembler_style macro is used # across namespaces / classes scopes. if braces_depth < 0: raise"check_macroassembler_style annotations are not well scoped."
# If the current line contains an opening curly brace, check if # this line combines with the previous one can be identified as a # MacroAssembler function signature. if open_curly_brace != -1 and was_braces_depth == 0:
lines = lines + line[:open_curly_brace] if"MacroAssembler::"in lines:
signatures.extend(get_normalized_signatures(lines, fileAnnot))
lines = "" continue
# We do not aggregate any lines if we are scanning lines which are # in-between a set of curly braces. if braces_depth > 0: continue if was_braces_depth != 0:
line = line[line.rfind("}") + 1 :]
# This logic is used to remove template instantiation, static # variable definitions and function declaration from the next # function definition.
last_semi_colon = line.rfind(";") if last_semi_colon != -1:
lines = ""
line = line[last_semi_colon + 1 :]
# Aggregate lines of non-braced text, which corresponds to the space # where we are expecting to find function definitions.
lines = lines + line
return signatures
def get_macroassembler_declaration(filename):
style_section = False
lines = ""
signatures = [] with open(filename, encoding="utf-8") as f: for line in f: if"//{{{ check_macroassembler_decl_style"in line:
style_section = True elif"//}}} check_macroassembler_decl_style"in line:
style_section = False ifnot style_section: continue
# Ignore preprocessor directives. if line.startswith("#"): continue
line = re.sub(r"//.*", "", line) if len(line.strip()) == 0 or"public:"in line or"private:"in line:
lines = "" continue
lines = lines + line
# Continue until we have a complete declaration if";"notin lines: continue
# Skip member declarations: which are lines ending with a # semi-colon without any list of arguments. if")"notin lines:
lines = "" continue
def append_signatures(d, sigs): for s in sigs: if s["sig"] notin d:
d[s["sig"]] = []
d[s["sig"]].append(s["arch"]) return d
def generate_file_content(signatures):
output = [] for s in sorted(signatures.keys()):
archs = set(sorted(signatures[s]))
archs -= all_unsupported_architectures_names if len(archs.symmetric_difference(architecture_independent)) == 0:
output.append(s + ";\n") if s.startswith("inline"): # TODO, bug 1432600: This is mistaken for OOL_IN_HEADER # functions. (Such annotation is already removed by the time # this function sees the signature here.)
output.append(" is defined in MacroAssembler-inl.h\n") else:
output.append(" is defined in MacroAssembler.cpp\n") else: if len(archs.symmetric_difference(all_architecture_names)) == 0:
output.append(s + " PER_ARCH;\n") elif len(archs.symmetric_difference(all_shared_architecture_names)) == 0:
output.append(s + " PER_SHARED_ARCH;\n") else:
output.append(s + " DEFINED_ON(" + ", ".join(sorted(archs)) + ");\n") for a in sorted(archs):
a = a.replace("_", "-")
masm = "%s/MacroAssembler-%s" % (a, a) if s.startswith("inline"):
output.append(" is defined in %s-inl.h\n" % masm) else:
output.append(" is defined in %s.cpp\n" % masm) return output
def check_style(): # We read from the header file the signature of each function.
decls = dict() # type: dict(signature => ['x86', 'x64'])
# We infer from each file the signature of each MacroAssembler function.
defs = dict() # type: dict(signature => ['x86', 'x64'])
root_dir = os.path.join("js", "src", "jit") for dirpath, dirnames, filenames in os.walk(root_dir): for filename in filenames: if"MacroAssembler"notin filename: continue
ifnot decls ornot defs: raise Exception("Did not find any definitions or declarations")
# Compare declarations and definitions output.
difflines = difflib.unified_diff(
generate_file_content(decls),
generate_file_content(defs),
fromfile="check_macroassembler_style.py declared syntax",
tofile="check_macroassembler_style.py found definitions",
)
ok = True for diffline in difflines:
ok = False
print(diffline, end="") return ok
def main():
ok = check_style()
if ok:
print("TEST-PASS | check_macroassembler_style.py | ok") else:
print( "TEST-UNEXPECTED-FAIL | check_macroassembler_style.py | actual output does not match expected output; diff is above"# noqa: E501
)
sys.exit(0 if ok else 1)
if __name__ == "__main__":
main()
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.