Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1 @@
file:../../src/wasm/OWNERS

View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
# Copyright 2019 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found
# in the LICENSE file.
import argparse
import io
import sys
from wasm import *
FUNCTION_SECTION_ID = 3
def parse_args():
parser = argparse.ArgumentParser(\
description="Inject compilation hints into a Wasm module.")
parser.add_argument("-i", "--in-wasm-file", \
type=str, \
help="original wasm module")
parser.add_argument("-o", "--out-wasm-file", \
type=str, \
help="wasm module with injected hints")
parser.add_argument("-x", "--hints-file", \
type=str, required=True, \
help="binary hints file to be injected as a custom section " + \
"'compilationHints'")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
in_wasm_file = args.in_wasm_file if args.in_wasm_file else sys.stdin.fileno()
out_wasm_file = args.out_wasm_file if args.out_wasm_file else sys.stdout.fileno()
hints_bs = open(args.hints_file, "rb").read()
with io.open(in_wasm_file, "rb") as fin:
with io.open(out_wasm_file, "wb") as fout:
magic_number, bs = read_magic_number(fin);
fout.write(bs)
version, bs = read_version(fin);
fout.write(bs)
num_declared_functions = None
while True:
id, bs = read_varuintN(fin)
fout.write(bs)
if id is None:
break
payload_length, bs = read_varuintN(fin)
fout.write(bs)
# Peek into function section for upcoming validity check.
if id == FUNCTION_SECTION_ID:
num_declared_functions, bs = peek_varuintN(fin)
bs = fin.read(payload_length)
fout.write(bs)
# Instert hint section after function section.
if id == FUNCTION_SECTION_ID:
assert len(hints_bs) == num_declared_functions, "unexpected number of hints"
write_compilation_hints_section(fout, hints_bs)

View File

@ -0,0 +1,48 @@
#!/usr/bin/env python3
# Copyright 2019 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found
# in the LICENSE file.
from __future__ import print_function
import argparse
import io
import sys
from wasm import *
def parse_args():
parser = argparse.ArgumentParser(\
description="Read compilation hints from Wasm module.")
parser.add_argument("in_wasm_file", \
type=str, \
help="wasm module")
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
in_wasm_file = args.in_wasm_file if args.in_wasm_file else sys.stdin.fileno()
with io.open(in_wasm_file, "rb") as fin:
read_magic_number(fin);
read_version(fin);
while True:
id, bs = read_varuintN(fin)
if id is None:
break
payload_length, bs = read_varuintN(fin)
if id == CUSTOM_SECTION_ID:
section_name_length, section_name_length_bs = read_varuintN(fin)
section_name_bs = fin.read(section_name_length)
if section_name_bs == "compilationHints":
num_hints, bs = read_varuintN(fin)
print("Custom section compilationHints with ", num_hints, "hints:")
for i in range(num_hints):
hint, bs = read_uint8(fin)
print(i, " ", hex(hint))
else:
remaining_length = payload_length \
- len(section_name_length_bs) \
- len(section_name_bs)
fin.read()
else:
fin.read(payload_length)

View File

@ -0,0 +1,103 @@
#!/usr/bin/env python3
# Copyright 2019 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found
# in the LICENSE file.
CUSTOM_SECTION_ID = 0
FUNCTION_SECTION_ID = 3
def peek_uint8(fin):
bs = fin.peek(1)[:1]
if len(bs) != 1:
return None, bs
return ord(bs[0]), bs
def read_uint8(fin):
value, bs = peek_uint8(fin)
fin.read(len(bs))
return value, bs
def peek_uint32(fin):
bs = fin.peek(4)[:4]
if len(bs) != 4:
return None, bs
return ord(bs[0]) | ord(bs[1]) << 8 | ord(bs[2]) << 16 | ord(bs[3]) << 24, bs
def read_uint32(fin):
value, bs = peek_uint32(fin)
fin.read(len(bs))
return value, bs
def peek_varuintN(fin):
value = 0
shift = 0
n = 1
while True:
bs = fin.peek(n)[:n]
if len(bs) < n:
return None, bs
b = ord(bs[-1])
value |= (b & 0x7F) << shift;
if (b & 0x80) == 0x00:
return value, bs
shift += 7;
n += 1
def read_varuintN(fin):
value, bs = peek_varuintN(fin)
fin.read(len(bs))
return value, bs
def to_varuintN(value):
bs = ""
while True:
b = value & 0x7F
value >>= 7
if (value != 0x00):
b |= 0x80
bs += chr(b)
if value == 0x00:
return bs
def write_varuintN(value, fout):
bs = to_varuintN(value)
fout.write(bs)
return bs
def peek_magic_number(fin, expected_magic_number=0x6d736100):
magic_number, bs = peek_uint32(fin)
assert magic_number == expected_magic_number, "unexpected magic number"
return magic_number, bs
def read_magic_number(fin, expected_magic_number=0x6d736100):
magic_number, bs = peek_magic_number(fin, expected_magic_number)
fin.read(len(bs))
return magic_number, bs
def peek_version(fin, expected_version=1):
version, bs = peek_uint32(fin)
assert version == expected_version, "unexpected version"
return version, bs
def read_version(fin, expected_version=1):
version, bs = peek_version(fin, expected_version)
fin.read(len(bs))
return version, bs
def write_custom_section(fout, section_name_bs, payload_bs):
section_name_length_bs = to_varuintN(len(section_name_bs))
payload_length_bs = to_varuintN(len(section_name_bs) \
+ len(section_name_length_bs) + len(payload_bs))
section_id_bs = to_varuintN(CUSTOM_SECTION_ID)
fout.write(section_id_bs)
fout.write(payload_length_bs)
fout.write(section_name_length_bs)
fout.write(section_name_bs)
fout.write(payload_bs)
def write_compilation_hints_section(fout, hints_bs):
num_compilation_hints_bs = to_varuintN(len(hints_bs))
section_name_bs = b"compilationHints"
payload_bs = num_compilation_hints_bs + hints_bs
write_custom_section(fout, section_name_bs, payload_bs)