#!/usr/bin/env python3 # # Copyright 2020 WebAssembly Community Group participants # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import argparse import json import io import os import struct import sys import find_exe from utils import ChangeDir, Error, Executable import utils F32_INF = 0x7f800000 F32_NEG_INF = 0xff800000 F32_NEG_ZERO = 0x80000000 F32_SIGN_BIT = F32_NEG_ZERO F32_SIG_MASK = 0x7fffff F32_QUIET_NAN_TAG = 0x400000 F64_INF = 0x7ff0000000000000 F64_NEG_INF = 0xfff0000000000000 F64_NEG_ZERO = 0x8000000000000000 F64_SIGN_BIT = F64_NEG_ZERO F64_SIG_MASK = 0xfffffffffffff F64_QUIET_NAN_TAG = 0x8000000000000 def EscapeWasmString(s): result = '' for c in s: if c == 34: result += '\\"' elif c == 92: result += '\\\\' elif 32 <= c < 127: result += chr(c) else: result += '\\%02x' % c return result def IsNaNF32(f32_bits): return (F32_INF < f32_bits < F32_NEG_ZERO) or (f32_bits > F32_NEG_INF) def ReinterpretF32(f32_bits): return struct.unpack(' F64_NEG_INF) def ReinterpretF64(f64_bits): return struct.unpack('