예제 #1
0
 def parse_signed_leb128(self, width):
     value, count = leb128.read_signed(self.view, width)
     self._advance(count)
     return value
예제 #2
0
 def parse_value_type(data):
     value, count = leb128.read_signed(data, 7)
     assert value in LanguageType.value_types
     return value, count
예제 #3
0
파일: test.py 프로젝트: tvanslyke/wasm-cpp
    else:
        return '1' + '0' * len(bitstr)


def leb128_sint_encode(num):
    enc = []
    is_negative = num < 0
    size = num.bit_length()
    more = True
    while more:
        byte = num & 0b0111_1111
        num >>= 7
        # if is_negative:
        # 	num |= (0x0111_1111) << (size - 7)
        done = (num == 0) and (not bool(byte & 0b0100_0000))
        done = done or ((num == -1) and (bool(byte & 0b0100_0000)))
        if done:
            more = False
        else:
            byte |= 0b1000_0000
        enc.append(byte)
    return bytes(bytearray(enc))


for i in tqdm(range(-100_000_000, 0)):
    enc = leb128_sint_encode(i)
    dec = leb128.read_signed(enc, 32)[0]
    if i != dec:
        print(i, dec)
        assert False
예제 #4
0
 def parse_block_type(data):
     value, count = leb128.read_signed(data, 7)
     assert (not (value in LanguageType.value_types)) or (
         value == LanguageType.block)
     return value, count