# 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 generates jit/LIROpsGenerated.h (list of LIR instructions) # from LIROps.yaml.
import io from itertools import groupby from operator import itemgetter
import buildconfig import yaml from mozbuild.preprocessor import Preprocessor
HEADER_TEMPLATE = """\
/* 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/. */
#ifndef %(includeguard)s #define %(includeguard)s
/* This file is generated by jit/GenerateLIRFiles.py. Do not edit! */
%(contents)s
#endif // %(includeguard)s """
def load_yaml(yaml_path): # First invoke preprocessor.py so that we can use #ifdef JS_SIMULATOR in # the YAML file.
pp = Preprocessor()
pp.context.update(buildconfig.defines["ALLDEFINES"])
pp.out = io.StringIO()
pp.do_filter("substitution")
pp.do_include(yaml_path)
contents = pp.out.getvalue() return yaml.safe_load(contents)
# Generate the index expression for a BoxedValue operand. # # The expression has the form |num_operands + index * BOX_PIECES|, with zero # terms being omitted. def make_boxed_index(index, reg_operands):
num_operands = len(reg_operands)
expr = [] if num_operands:
expr.append(f"{num_operands}") if index:
expr.append(f"{index} * BOX_PIECES") return" + ".join(expr) if expr else"0"
# Generate the index expression for an Int64 operand. # # The expression has the form # |num_operands + num_value_operands * BOX_PIECES + index * INT64_PIECES|, with # zero terms being omitted. def make_int64_index(index, reg_operands, value_operands):
num_operands = len(reg_operands)
num_value_operands = len(value_operands)
expr = [] if num_operands:
expr.append(f"{num_operands}") if num_value_operands:
expr.append(f"{num_value_operands} * BOX_PIECES") if index:
expr.append(f"{index} * INT64_PIECES") return" + ".join(expr) if expr else"0"
def gen_operands(operands, defer_init): # Group operands by operand type.
sorted_operands = {
k: [op for op, _ in v] for k, v in groupby(sorted(operands.items(), key=itemgetter(1)), itemgetter(1))
}
# Exactly three operand types are supported: WordSized, BoxedValue, and Int64. if len(sorted_operands) > 3: raise Exception("Invalid operand type: " + str(sorted_operands.keys()))
# Parameters for the class constructor.
params = []
# Initializer instructions for constructor body.
initializers = []
# Getter definitions.
getters = []
# Setter definitions.
setters = []
# Constructor parameters are generated in the order defined in the YAML file. ifnot defer_init: for operand, op_type in operands.items():
params.append(f"const {operand_types[op_type]}& {operand}")
# First initialize all word-sized operands. for index, operand in enumerate(reg_operands):
cap_operand = operand[0].upper() + operand[1:]
index_value = cap_operand + "Index"
init_expr = f"setOperand({index_value}, {operand});"
def gen_successors(successors): # Parameters for the class constructor.
params = []
# Initializer instructions for constructor body.
initializers = []
# Getter definitions.
getters = []
for index, successor in enumerate(successors or []):
params.append(f"MBasicBlock* {successor}")
initializers.append(f"setSuccessor({index}, {successor});")
getters.append(
f"MBasicBlock* {successor}() const {{ return getSuccessor({index}); }}"
)
return (params, initializers, getters)
def gen_lir_class(
name,
result_type,
successors,
operands,
arguments,
num_temps,
num_temps64,
call_instruction,
mir_op,
extra_name,
defer_init,
): """Generates class definition for a single LIR opcode."""
class_name = "L" + name
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 und die Messung sind noch experimentell.