4 from mozbuild
.preprocessor
import Preprocessor
7 /* This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 #ifndef %(includeguard)s
12 #define %(includeguard)s
14 /* This file is generated by wasm/GenerateBuiltinModules.py. Do not edit! */
18 #endif // %(includeguard)s
22 def generate_header(c_out
, includeguard
, contents
):
26 "includeguard": includeguard
,
32 def load_yaml(yaml_path
):
33 # First invoke preprocessor.py so that we can use #ifdef JS_SIMULATOR in
36 pp
.context
.update(buildconfig
.defines
["ALLDEFINES"])
37 pp
.out
= six
.StringIO()
38 pp
.do_filter("substitution")
39 pp
.do_include(yaml_path
)
40 contents
= pp
.out
.getvalue()
41 return yaml
.safe_load(contents
)
50 def main(c_out
, yaml_path
):
51 data
= load_yaml(yaml_path
)
53 # Iterate for all defined builtin methods
54 contents
= "#define FOR_EACH_BUILTIN_MODULE_FUNC(M) \\\n"
55 for i
in range(len(data
)):
57 sa
= op
["symbolic_address"]
59 f
" M({op['op']}, \"{op['export']}\", "
60 f
"{sa['name']}, {sa['type']}, {op['entry']}, {cppBool(op['uses_memory'])}, {i})\\\n"
65 # Define DECLARE_BUILTIN_MODULE_FUNC_PARAM_VALTYPES_<op> as:
66 # `{ValType::I32, ValType::I32, ...}`.
68 f
"#define DECLARE_BUILTIN_MODULE_FUNC_PARAM_VALTYPES_{op['op']} "
69 f
"{{{', '.join(op['params'])}}}\n"
72 # Define DECLARE_BUILTIN_MODULE_FUNC_PARAM_SASTYPES_<op> as:
73 # `<num_types>, {_PTR, _I32, ..., _PTR, _END}`.
74 num_types
= len(op
["params"]) + 1
76 f
"{{_PTR{''.join(', ' + (p + '.toMIRType()') for p in op['params'])}"
81 sas_types
+= ", _END}"
83 contents
+= f
"#define DECLARE_BUILTIN_MODULE_FUNC_PARAM_SASTYPES_{op['op']} {num_types}, {sas_types}\n"
88 result_valtype
= f
"Some({op['result']})\n"
89 result_sastype
= f
"{op['result']}.toMIRType()\n"
91 result_valtype
= "Nothing()"
92 result_sastype
= "_VOID"
93 contents
+= f
"#define DECLARE_BUILTIN_MODULE_FUNC_RESULT_VALTYPE_{op['op']} {result_valtype}\n"
94 contents
+= f
"#define DECLARE_BUILTIN_MODULE_FUNC_RESULT_SASTYPE_{op['op']} {result_sastype}\n"
95 contents
+= f
"#define DECLARE_BUILTIN_MODULE_FUNC_FAILMODE_{op['op']} _{op['fail_mode']}\n"
97 generate_header(c_out
, "wasm_WasmBuiltinModuleGenerated_h", contents
)