Assemble kernel on the client #1

Merged
cdo merged 72 commits from client-side-assembler into main 2026-03-18 15:21:33 +00:00
Showing only changes of commit 1105daaad0 - Show all commits

38
asm.js
View File

@@ -712,7 +712,7 @@ export class Assembler {
action_append(action) {
const code = action.opcode != undefined
? [ action.opcode ]
? [ action.opcode ].flat()
: this.leb128(action.literal);
this.funcs[this.current_func].body.push(...code);
}
@@ -799,7 +799,7 @@ export class Assembler {
const data = this.data.at(-1).data;
const value = action.value != null
? action.value
: this.le_bytes(this.lookup_def(action.symbol), action.size);
: this.le(this.lookup_def(action.symbol), action.size);
data.push(...value);
this.pos.addr += action.size;
}
@@ -871,17 +871,33 @@ export class Assembler {
return this.defs[symbol];
}
le_bytes(value, count) {
le(value, count) {
let bytes = []
while (value != 0 && bytes.length < count) {
while (value != 0) {
bytes.push(value & 0xff);
value >>= 8;
}
if (count != undefined) {
while (bytes.length < count)
bytes.push(0);
}
return bytes;
}
leb128(x) {
const orig = x;
const bytes = [];
while (true) {
const b = x & 0x7f;
x >>= 7;
if (x == 0 && (b & 0x40) == 0 || x == -1 && (b & 0x40) != 0) {
bytes.push(b);
return bytes;
}
bytes.push(b | 0x80);
}
}
wasm_section_type() {
const funcs = Object.values(this.funcs);
if (funcs.length == 0) return null;
@@ -1022,18 +1038,4 @@ export class Assembler {
else
return [ flags, init ];
}
leb128(x) {
const orig = x;
const bytes = [];
while (true) {
const b = x & 0x7f;
x >>= 7;
if (x == 0 && (b & 0x40) == 0 || x == -1 && (b & 0x40) != 0) {
bytes.push(b);
return bytes;
}
bytes.push(b | 0x80);
}
}
}