diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/jit/GenerateOpcodeFiles.py | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit/GenerateOpcodeFiles.py')
-rw-r--r-- | js/src/jit/GenerateOpcodeFiles.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/js/src/jit/GenerateOpcodeFiles.py b/js/src/jit/GenerateOpcodeFiles.py new file mode 100644 index 0000000000..be41361d78 --- /dev/null +++ b/js/src/jit/GenerateOpcodeFiles.py @@ -0,0 +1,66 @@ +# 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/LOpcodesGenerated.h (list of LIR instructions) and +# jit/MOpcodesGenerated.h (list of MIR instructions) from MIR.h and LIR files. + +import re + +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/GenerateOpcodeFiles.py. Do not edit! */ + +#define %(listname)s(_) \\ +%(ops)s + +#endif // %(includeguard)s +""" + + +def get_opcodes(inputs, pat): + # Preserve the original order. Use a set to detect duplicates. + ops = [] + ops_set = set() + for inputfile in inputs: + for line in open(inputfile): + match = pat.match(line) + if match: + op = match.group("name") + if op in ops_set: + raise Exception("Duplicate opcode {} in {}".format(op, inputfile)) + ops.append(op) + ops_set.add(op) + assert len(ops) == len(ops_set) + return ops + + +def generate_header(c_out, inputs, pat, includeguard, listname): + ops = get_opcodes(inputs, pat) + ops_string = "\\\n".join(["_(" + op + ")" for op in ops]) + c_out.write( + HEADER_TEMPLATE + % { + "ops": ops_string, + "includeguard": includeguard, + "listname": listname, + } + ) + + +def generate_mir_header(c_out, *inputs): + pat = re.compile( + r"^\s*INSTRUCTION_HEADER(_WITHOUT_TYPEPOLICY)?\((?P<name>\w+)\);?$" + ) + generate_header(c_out, inputs, pat, "jit_MOpcodesGenerated_h", "MIR_OPCODE_LIST") + + +def generate_lir_header(c_out, *inputs): + pat = re.compile(r"^\s*LIR_HEADER\((?P<name>\w+)\);?$") + generate_header(c_out, inputs, pat, "jit_LOpcodesGenerated_h", "LIR_OPCODE_LIST") |