import buildconfig import six 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 wasm/GenerateBuiltinModules.py. Do not edit! */
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 = six.StringIO()
pp.do_filter("substitution")
pp.do_include(yaml_path)
contents = pp.out.getvalue() return yaml.safe_load(contents)
def cppBool(v): if v: return"true" return"false"
def specTypeToMIRType(specType): if specType == "i32"or specType == "i64"or specType == "f32"or specType == "f64": return f"ValType::{specType}().toMIRType()" if (
specType == "externref" or specType == "anyref" or specType == "funcref" or specType == "exnref" or isinstance(specType, dict)
): return"MIRType::WasmAnyRef" raise ValueError()
def specHeapTypeToTypeCode(specHeapType): if specHeapType == "func": return"Func" if specHeapType == "any": return"Any" if specHeapType == "extern": return"Extern" if specHeapType == "exn": return"Exn" if specHeapType == "array": return"Array" if specHeapType == "struct": return"Struct" raise ValueError()
def main(c_out, yaml_path):
data = load_yaml(yaml_path)
# Iterate for all defined builtin methods
contents = "#define FOR_EACH_BUILTIN_MODULE_FUNC(M) \\\n" for i in range(len(data)):
op = data[i]
sa = op["symbolic_address"]
inlineOp = "BuiltinInlineOp::None" if"inline_op"in op:
inlineOp = f"BuiltinInlineOp::{op['inline_op']}"
contents += (
f" M({op['op']}, \"{op['export']}\", "
f"{sa['name']}, {sa['type']}, {op['entry']}, {cppBool(op['uses_memory'])}, {inlineOp}, {i})\\\n"
)
contents += "\n"
for op in data: # Define DECLARE_BUILTIN_MODULE_FUNC_PARAM_VALTYPES_<op> as: # `{ValType::I32, ValType::I32, ...}`.
valTypes = ", ".join(specTypeToValType(p) for p in op["params"])
contents += (
f"#define DECLARE_BUILTIN_MODULE_FUNC_PARAM_VALTYPES_{op['op']} "
f"{{{valTypes}}}\n"
)
# Define DECLARE_BUILTIN_MODULE_FUNC_PARAM_MIRTYPES_<op> as: # `<num_types>, {MIRType::Pointer, _I32, ..., MIRType::Pointer, _END}`.
num_types = len(op["params"]) + 1
mir_types = "{MIRType::Pointer"
mir_types += "".join(", " + specTypeToMIRType(p) for p in op["params"]) if op["uses_memory"]:
mir_types += ", MIRType::Pointer"
num_types += 1 # Add the end marker
mir_types += ", MIRType::None}"
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.