1#!/usr/bin/env python 2 3# Copyright 2019 the V8 project authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be found 5# in the LICENSE file. 6 7from __future__ import print_function 8import argparse 9import io 10import sys 11 12from wasm import * 13 14def parse_args(): 15 parser = argparse.ArgumentParser(\ 16 description="Read compilation hints from Wasm module.") 17 parser.add_argument("in_wasm_file", \ 18 type=str, \ 19 help="wasm module") 20 return parser.parse_args() 21 22if __name__ == "__main__": 23 args = parse_args() 24 in_wasm_file = args.in_wasm_file if args.in_wasm_file else sys.stdin.fileno() 25 with io.open(in_wasm_file, "rb") as fin: 26 read_magic_number(fin); 27 read_version(fin); 28 while True: 29 id, bs = read_varuintN(fin) 30 if id == None: 31 break 32 payload_length, bs = read_varuintN(fin) 33 if id == CUSTOM_SECTION_ID: 34 section_name_length, section_name_length_bs = read_varuintN(fin) 35 section_name_bs = fin.read(section_name_length) 36 if section_name_bs == "compilationHints": 37 num_hints, bs = read_varuintN(fin) 38 print("Custom section compilationHints with ", num_hints, "hints:") 39 for i in range(num_hints): 40 hint, bs = read_uint8(fin) 41 print(i, " ", hex(hint)) 42 else: 43 remaining_length = payload_length \ 44 - len(section_name_length_bs) \ 45 - len(section_name_bs) 46 fin.read() 47 else: 48 fin.read(payload_length) 49