11cb0ef41Sopenharmony_ci#!/usr/bin/env python 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci# Copyright 2019 the V8 project authors. All rights reserved. 41cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be found 51cb0ef41Sopenharmony_ci# in the LICENSE file. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cifrom __future__ import print_function 81cb0ef41Sopenharmony_ciimport argparse 91cb0ef41Sopenharmony_ciimport io 101cb0ef41Sopenharmony_ciimport sys 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cifrom wasm import * 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cidef parse_args(): 151cb0ef41Sopenharmony_ci parser = argparse.ArgumentParser(\ 161cb0ef41Sopenharmony_ci description="Read compilation hints from Wasm module.") 171cb0ef41Sopenharmony_ci parser.add_argument("in_wasm_file", \ 181cb0ef41Sopenharmony_ci type=str, \ 191cb0ef41Sopenharmony_ci help="wasm module") 201cb0ef41Sopenharmony_ci return parser.parse_args() 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciif __name__ == "__main__": 231cb0ef41Sopenharmony_ci args = parse_args() 241cb0ef41Sopenharmony_ci in_wasm_file = args.in_wasm_file if args.in_wasm_file else sys.stdin.fileno() 251cb0ef41Sopenharmony_ci with io.open(in_wasm_file, "rb") as fin: 261cb0ef41Sopenharmony_ci read_magic_number(fin); 271cb0ef41Sopenharmony_ci read_version(fin); 281cb0ef41Sopenharmony_ci while True: 291cb0ef41Sopenharmony_ci id, bs = read_varuintN(fin) 301cb0ef41Sopenharmony_ci if id == None: 311cb0ef41Sopenharmony_ci break 321cb0ef41Sopenharmony_ci payload_length, bs = read_varuintN(fin) 331cb0ef41Sopenharmony_ci if id == CUSTOM_SECTION_ID: 341cb0ef41Sopenharmony_ci section_name_length, section_name_length_bs = read_varuintN(fin) 351cb0ef41Sopenharmony_ci section_name_bs = fin.read(section_name_length) 361cb0ef41Sopenharmony_ci if section_name_bs == "compilationHints": 371cb0ef41Sopenharmony_ci num_hints, bs = read_varuintN(fin) 381cb0ef41Sopenharmony_ci print("Custom section compilationHints with ", num_hints, "hints:") 391cb0ef41Sopenharmony_ci for i in range(num_hints): 401cb0ef41Sopenharmony_ci hint, bs = read_uint8(fin) 411cb0ef41Sopenharmony_ci print(i, " ", hex(hint)) 421cb0ef41Sopenharmony_ci else: 431cb0ef41Sopenharmony_ci remaining_length = payload_length \ 441cb0ef41Sopenharmony_ci - len(section_name_length_bs) \ 451cb0ef41Sopenharmony_ci - len(section_name_bs) 461cb0ef41Sopenharmony_ci fin.read() 471cb0ef41Sopenharmony_ci else: 481cb0ef41Sopenharmony_ci fin.read(payload_length) 49