with open(paths['Opcodes.h'], 'r') as f: for line in f:
line = line.strip()
if line.startswith('IF_RECORD_TUPLE('): # Ignore Record and Tuple opcodes continue
if line.startswith('MACRO(') and','in line:
line = line[5:] if line.endswith(' \\'):
line = line[:-2] assert line.endswith(')')
opcodes.append((" " * 16) + line + ",")
return opcodes
def extract_opcode_flags(paths):
pat = re.compile(r'(JOF_[A-Z0-9_]+)\s=\s([^,]+),\s*/\*\s*(.*?)\s*\*/',
re.DOTALL)
flags = []
with open(paths['BytecodeFormatFlags.h'], 'r') as f:
content = f.read()
for m in pat.finditer(content):
name = m.group(1)
value = m.group(2)
comment = m.group(3)
def extract_symbols():
pat = re.compile(r'MACRO\((.+)\)')
ty = 'SymbolCode'
variants = []
i = 0
found = False
state = 'before' with open(paths['Symbol.h'], 'r') as f: for line in f: if'enum class SymbolCode : uint32_t {'in line:
found = True
if state == 'before': if'JS_FOR_EACH_WELL_KNOWN_SYMBOL'in line:
state = 'macro' elif state == 'macro':
m = pat.search(line) if m:
sym = m.group(1)
sym = sym[0].upper() + sym[1:]
variants.append((sym, i))
i += 1
ifnot line.strip().endswith('\\'):
state = 'after'
ifnot found:
print('SymbolCode : uint32_t is not found',
file=sys.stderr)
sys.exit(1)
def extract_source_notes():
pat = re.compile(r'M\((.+),(.+),(.+)\)')
ty = 'SrcNoteType'
variants = []
i = 0
found = False
state = 'before' with open(paths['SourceNotes.h'], 'r') as f: for line in f: if'enum class SrcNoteType : uint8_t {'in line:
found = True
if state == 'before': if'FOR_EACH_SRC_NOTE_TYPE'in line:
state = 'macro' elif state == 'macro':
m = pat.search(line) if m:
variants.append((m.group(1), i))
i += 1
ifnot line.strip().endswith('\\'):
state = 'after'
ifnot found:
print('SrcNoteType : uint8_t is not found',
file=sys.stderr)
sys.exit(1)
with open(path, 'r') as in_f: with open(tmppath, 'w') as out_f:
state = 'normal' for line in in_f: if'@@@@ BEGIN OPCODES @@@@'in line:
state = 'opcodes'
out_f.write(line)
format_opcodes(out_f, opcodes) elif'@@@@ END OPCODES @@@@'in line: assert state == 'opcodes'
state = 'normal'
out_f.write(line) elif'@@@@ BEGIN FLAGS @@@@'in line:
state = 'flags'
out_f.write(line)
format_opcode_flags(out_f, flags) elif'@@@@ END FLAGS @@@@'in line: assert state == 'flags'
state = 'normal'
out_f.write(line) elif state == 'normal':
out_f.write(line) assert state == 'normal'
for operand in opcode.operands_array:
tmp = operand.split(' ')
ty = tmp[0]
name = to_snake_case(tmp[1])
if ty in size_types:
ty = size_types[ty] elif ty == 'double':
ty = 'f64' elif ty in copied_types: pass else:
print(f'Unsupported operand type {ty}', file=sys.stderr)
sys.exit(1)
if'JOF_ATOM'in opcode.format_: assert ty == 'u32'
ty = 'GCThingIndex'
if'JOF_STRING'in opcode.format_: assert ty == 'u32'
ty = 'GCThingIndex'
if'JOF_ICINDEX'in opcode.format_ or'JOF_LOOPHEAD'in opcode.format_: if ty == 'u32'and name == 'ic_index':
ty = 'IcIndex'
name = '' else: assert'JOF_LOOPHEAD'in opcode.format_ and name == 'depth_hint'
# FIXME: Stronger typing for Opcode::CheckIsObj kind parameter.
params.append((ty, name))
return params
def generate_types(out_f, types): for ty in types:
variants = [] for variant, i in types[ty]['variants']: if types[ty]['dead']:
variants.append(dedent(f"""\ #[allow(dead_code)] """))
for (ty, name) in params: if ty in types:
size_ty = types[ty]['size']
out_f.write(dedent(f"""\
self.write_{size_ty}({name} as {size_ty}); """)) else:
out_f.write(dedent(f"""\
self.write_{to_snake_case(ty)}({name}); """))
out_f.write(dedent(f"""\
}}
"""))
def get_filtered_opcodes():
sys.path.append(vm_dir) from jsopcode import get_opcodes
with open(path, 'r') as in_f: with open(tmppath, 'w') as out_f:
state = 'normal' for line in in_f: if'@@@@ BEGIN METHODS @@@@'in line:
state = 'methods'
out_f.write(line)
generate_emit_methods(out_f, opcodes, types) elif'@@@@ END METHODS @@@@'in line: assert state == 'methods'
state = 'normal'
out_f.write(line) elif'@@@@ BEGIN TYPES @@@@'in line:
state = 'types'
out_f.write(line)
generate_types(out_f, types) elif'@@@@ END TYPES @@@@'in line: assert state == 'types'
state = 'normal'
out_f.write(line) elif state == 'normal':
out_f.write(line) assert state == 'normal'
with open(path, 'r') as in_f: with open(tmppath, 'w') as out_f:
state = 'normal' for line in in_f: if'@@@@ BEGIN TYPES @@@@'in line:
state = 'types'
out_f.write(line)
generate_types(out_f, types)
format_function_flags(out_f, flags) elif'@@@@ END TYPES @@@@'in line: assert state == 'types'
state = 'normal'
out_f.write(line) elif state == 'normal':
out_f.write(line) assert state == 'normal'
with open(path, 'r') as in_f: with open(tmppath, 'w') as out_f:
state = 'normal' for line in in_f: if'@@@@ BEGIN TYPES @@@@'in line:
state = 'types'
out_f.write(line)
generate_types(out_f, types) elif'@@@@ END TYPES @@@@'in line: assert state == 'types'
state = 'normal'
out_f.write(line) elif state == 'normal':
out_f.write(line) assert state == 'normal'
os.replace(tmppath, path)
rustfmt(path)
def copy_input(paths): for name, path in paths.items():
shutil.copyfile(path,
os.path.join(copy_dir, 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.