Skip to content

Commit c0d206f

Browse files
committed
trying again
1 parent fbce899 commit c0d206f

File tree

3 files changed

+185
-174
lines changed

3 files changed

+185
-174
lines changed

lib/parse/assembly/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,20 @@ export class Parser {
7575
this.module = new Module(buf);
7676
}
7777

78-
parseString(): String {
79-
return String.fromUTF8(this.buf.off,this.buf.readVaruint(32));
80-
}
78+
/** Reads a LEB128-encoded signed integer from memory. */
79+
function readVarint(size: u32): i32 {
80+
var val: u32 = 0;
81+
var shl: u32 = 0;
82+
var byt: u32;
83+
var pos = off;
84+
do {
85+
byt = load<u8>(pos++);
86+
val |= (byt & 0x7F) << shl;
87+
shl += 7;
88+
} while (byt & 0x80);
89+
off = pos;
90+
return select<u32>(val | (~0 << shl), val, shl < size && (byt & 0x40) != 0);
91+
}
8192

8293
readVaruint(len: usize): u32 {
8394
return this.buf.readVaruint(len);

lib/parse/assembly/module/instructions/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Opcode
55
} from "../../src/common";
66

7-
import {Buffer} from "../buffer";
7+
import {readVaruint, readUint} from "..";
88

99

1010
// export function parseExpr(): Instruction[] {
@@ -23,8 +23,8 @@ export class Instruction {
2323
constructor(public opcode: Opcode){
2424
}
2525

26-
static parse(buf: Buffer): Instruction {
27-
let byte: u8 = changetype<u8>(buf.readUint<u8>());
26+
static parse(): Instruction {
27+
let byte: u8 = changetype<u8>(readUint<u8>());
2828
switch(byte){
2929
case Opcode.unreachable:
3030
case Opcode.nop:
@@ -39,7 +39,7 @@ export class Instruction {
3939
case Opcode.return_:
4040
case Opcode.call:
4141
case Opcode.call_indirect: {
42-
return ControlInstruction.parse(byte);
42+
return new ControlInstruction(byte);
4343
}
4444
case Opcode.drop:
4545
case Opcode.select:

lib/parse/src/common.ts

Lines changed: 167 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -50,178 +50,178 @@ export const MAX_ELEMS = 0xffffffff;
5050

5151
/** WebAssembly opcodes. */
5252
export enum Opcode { // just a few of these are actually used
53-
unreachable = 0x00,
54-
nop = 0x01,
55-
block = 0x02,
56-
loop = 0x03,
57-
if_ = 0x04,
58-
else_ = 0x05,
53+
// unreachable = 0x00,
54+
// nop = 0x01,
55+
// block = 0x02,
56+
// loop = 0x03,
57+
// if_ = 0x04,
58+
// else_ = 0x05,
5959
end = 0x0b,
60-
br = 0x0c,
61-
br_if = 0x0d,
62-
br_table = 0x0e,
63-
return_ = 0x0f,
64-
call = 0x10,
65-
call_indirect = 0x11,
66-
drop = 0x1a,
67-
select = 0x1b,
68-
get_local = 0x20,
69-
set_local = 0x21,
70-
tee_local = 0x22,
60+
// br = 0x0c,
61+
// br_if = 0x0d,
62+
// br_table = 0x0e,
63+
// return_ = 0x0f,
64+
// call = 0x10,
65+
// call_indirect = 0x11,
66+
// drop = 0x1a,
67+
// select = 0x1b,
68+
// get_local = 0x20,
69+
// set_local = 0x21,
70+
// tee_local = 0x22,
7171
get_global = 0x23,
72-
set_global = 0x24,
73-
i32_load = 0x28,
74-
i64_load = 0x29,
75-
f32_load = 0x2a,
76-
f64_load = 0x2b,
77-
i32_load8_s = 0x2c,
78-
i32_load8_u = 0x2d,
79-
i32_load16_s = 0x2e,
80-
i32_load16_u = 0x2f,
81-
i64_load8_s = 0x30,
82-
i64_load8_u = 0x31,
83-
i64_load16_s = 0x32,
84-
i64_load16_u = 0x33,
85-
i64_load32_s = 0x34,
86-
i64_load32_u = 0x35,
87-
i32_store = 0x36,
88-
i64_store = 0x37,
89-
f32_store = 0x38,
90-
f64_store = 0x39,
91-
i32_store8 = 0x3a,
92-
i32_store16 = 0x3b,
93-
i64_store8 = 0x3c,
94-
i64_store16 = 0x3d,
95-
i64_store32 = 0x3e,
96-
current_memory = 0x3f,
97-
grow_memory = 0x40,
72+
// set_global = 0x24,
73+
// i32_load = 0x28,
74+
// i64_load = 0x29,
75+
// f32_load = 0x2a,
76+
// f64_load = 0x2b,
77+
// i32_load8_s = 0x2c,
78+
// i32_load8_u = 0x2d,
79+
// i32_load16_s = 0x2e,
80+
// i32_load16_u = 0x2f,
81+
// i64_load8_s = 0x30,
82+
// i64_load8_u = 0x31,
83+
// i64_load16_s = 0x32,
84+
// i64_load16_u = 0x33,
85+
// i64_load32_s = 0x34,
86+
// i64_load32_u = 0x35,
87+
// i32_store = 0x36,
88+
// i64_store = 0x37,
89+
// f32_store = 0x38,
90+
// f64_store = 0x39,
91+
// i32_store8 = 0x3a,
92+
// i32_store16 = 0x3b,
93+
// i64_store8 = 0x3c,
94+
// i64_store16 = 0x3d,
95+
// i64_store32 = 0x3e,
96+
// current_memory = 0x3f,
97+
// grow_memory = 0x40,
9898
i32_const = 0x41,
9999
i64_const = 0x42,
100100
f32_const = 0x43,
101-
f64_const = 0x44,
102-
i32_eqz = 0x45,
103-
i32_eq = 0x46,
104-
i32_ne = 0x47,
105-
i32_lt_s = 0x48,
106-
i32_lt_u = 0x49,
107-
i32_gt_s = 0x4a,
108-
i32_gt_u = 0x4b,
109-
i32_le_s = 0x4c,
110-
i32_le_u = 0x4d,
111-
i32_ge_s = 0x4e,
112-
i32_ge_u = 0x4f,
113-
i64_eqz = 0x50,
114-
i64_eq = 0x51,
115-
i64_ne = 0x52,
116-
i64_lt_s = 0x53,
117-
i64_lt_u = 0x54,
118-
i64_gt_s = 0x55,
119-
i64_gt_u = 0x56,
120-
i64_le_s = 0x57,
121-
i64_le_u = 0x58,
122-
i64_ge_s = 0x59,
123-
i64_ge_u = 0x5a,
124-
f32_eq = 0x5b,
125-
f32_ne = 0x5c,
126-
f32_lt = 0x5d,
127-
f32_gt = 0x5e,
128-
f32_le = 0x5f,
129-
f32_ge = 0x60,
130-
f64_eq = 0x61,
131-
f64_ne = 0x62,
132-
f64_lt = 0x63,
133-
f64_gt = 0x64,
134-
f64_le = 0x65,
135-
f64_ge = 0x66,
136-
i32_clz = 0x67,
137-
i32_ctz = 0x68,
138-
i32_popcnt = 0x69,
139-
i32_add = 0x6a,
140-
i32_sub = 0x6b,
141-
i32_mul = 0x6c,
142-
i32_div_s = 0x6d,
143-
i32_div_u = 0x6e,
144-
i32_rem_s = 0x6f,
145-
i32_rem_u = 0x70,
146-
i32_and = 0x71,
147-
i32_or = 0x72,
148-
i32_xor = 0x73,
149-
i32_shl = 0x74,
150-
i32_shr_s = 0x75,
151-
i32_shr_u = 0x76,
152-
i32_rotl = 0x77,
153-
i32_rotr = 0x78,
154-
i64_clz = 0x79,
155-
i64_ctz = 0x7a,
156-
i64_popcnt = 0x7b,
157-
i64_add = 0x7c,
158-
i64_sub = 0x7d,
159-
i64_mul = 0x7e,
160-
i64_div_s = 0x7f,
161-
i64_div_u = 0x80,
162-
i64_rem_s = 0x81,
163-
i64_rem_u = 0x82,
164-
i64_and = 0x83,
165-
i64_or = 0x84,
166-
i64_xor = 0x85,
167-
i64_shl = 0x86,
168-
i64_shr_s = 0x87,
169-
i64_shr_u = 0x88,
170-
i64_rotl = 0x89,
171-
i64_rotr = 0x8a,
172-
f32_abs = 0x8b,
173-
f32_neg = 0x8c,
174-
f32_ceil = 0x8d,
175-
f32_floor = 0x8e,
176-
f32_trunc = 0x8f,
177-
f32_nearest = 0x90,
178-
f32_sqrt = 0x91,
179-
f32_add = 0x92,
180-
f32_sub = 0x93,
181-
f32_mul = 0x94,
182-
f32_div = 0x95,
183-
f32_min = 0x96,
184-
f32_max = 0x97,
185-
f32_copysign = 0x98,
186-
f64_abs = 0x99,
187-
f64_neg = 0x9a,
188-
f64_ceil = 0x9b,
189-
f64_floor = 0x9c,
190-
f64_trunc = 0x9d,
191-
f64_nearest = 0x9e,
192-
f64_sqrt = 0x9f,
193-
f64_add = 0xa0,
194-
f64_sub = 0xa1,
195-
f64_mul = 0xa2,
196-
f64_div = 0xa3,
197-
f64_min = 0xa4,
198-
f64_max = 0xa5,
199-
f64_copysign = 0xa6,
200-
i32_wrap_i64 = 0xa7,
201-
i32_trunc_s_f32 = 0xa8,
202-
i32_trunc_u_f32 = 0xa9,
203-
i32_trunc_s_f64 = 0xaa,
204-
i32_trunc_u_f64 = 0xab,
205-
i64_extend_s_i32 = 0xac,
206-
i64_extend_u_i32 = 0xad,
207-
i64_trunc_s_f32 = 0xae,
208-
i64_trunc_u_f32 = 0xaf,
209-
i64_trunc_s_f64 = 0xb0,
210-
i64_trunc_u_f64 = 0xb1,
211-
f32_convert_s_i32 = 0xb2,
212-
f32_convert_u_i32 = 0xb3,
213-
f32_convert_s_i64 = 0xb4,
214-
f32_convert_u_i64 = 0xb5,
215-
f32_demote_f64 = 0xb6,
216-
f64_convert_s_i32 = 0xb7,
217-
f64_convert_u_i32 = 0xb8,
218-
f64_convert_s_i64 = 0xb9,
219-
f64_convert_u_i64 = 0xba,
220-
f64_promote_f32 = 0xbb,
221-
i32_reinterpret_f32 = 0xbc,
222-
i64_reinterpret_f64 = 0xbd,
223-
f32_reinterpret_i32 = 0xbe,
224-
f64_reinterpret_i64 = 0xbf
101+
f64_const = 0x44
102+
// i32_eqz = 0x45,
103+
// i32_eq = 0x46,
104+
// i32_ne = 0x47,
105+
// i32_lt_s = 0x48,
106+
// i32_lt_u = 0x49,
107+
// i32_gt_s = 0x4a,
108+
// i32_gt_u = 0x4b,
109+
// i32_le_s = 0x4c,
110+
// i32_le_u = 0x4d,
111+
// i32_ge_s = 0x4e,
112+
// i32_ge_u = 0x4f,
113+
// i64_eqz = 0x50,
114+
// i64_eq = 0x51,
115+
// i64_ne = 0x52,
116+
// i64_lt_s = 0x53,
117+
// i64_lt_u = 0x54,
118+
// i64_gt_s = 0x55,
119+
// i64_gt_u = 0x56,
120+
// i64_le_s = 0x57,
121+
// i64_le_u = 0x58,
122+
// i64_ge_s = 0x59,
123+
// i64_ge_u = 0x5a,
124+
// f32_eq = 0x5b,
125+
// f32_ne = 0x5c,
126+
// f32_lt = 0x5d,
127+
// f32_gt = 0x5e,
128+
// f32_le = 0x5f,
129+
// f32_ge = 0x60,
130+
// f64_eq = 0x61,
131+
// f64_ne = 0x62,
132+
// f64_lt = 0x63,
133+
// f64_gt = 0x64,
134+
// f64_le = 0x65,
135+
// f64_ge = 0x66,
136+
// i32_clz = 0x67,
137+
// i32_ctz = 0x68,
138+
// i32_popcnt = 0x69,
139+
// i32_add = 0x6a,
140+
// i32_sub = 0x6b,
141+
// i32_mul = 0x6c,
142+
// i32_div_s = 0x6d,
143+
// i32_div_u = 0x6e,
144+
// i32_rem_s = 0x6f,
145+
// i32_rem_u = 0x70,
146+
// i32_and = 0x71,
147+
// i32_or = 0x72,
148+
// i32_xor = 0x73,
149+
// i32_shl = 0x74,
150+
// i32_shr_s = 0x75,
151+
// i32_shr_u = 0x76,
152+
// i32_rotl = 0x77,
153+
// i32_rotr = 0x78,
154+
// i64_clz = 0x79,
155+
// i64_ctz = 0x7a,
156+
// i64_popcnt = 0x7b,
157+
// i64_add = 0x7c,
158+
// i64_sub = 0x7d,
159+
// i64_mul = 0x7e,
160+
// i64_div_s = 0x7f,
161+
// i64_div_u = 0x80,
162+
// i64_rem_s = 0x81,
163+
// i64_rem_u = 0x82,
164+
// i64_and = 0x83,
165+
// i64_or = 0x84,
166+
// i64_xor = 0x85,
167+
// i64_shl = 0x86,
168+
// i64_shr_s = 0x87,
169+
// i64_shr_u = 0x88,
170+
// i64_rotl = 0x89,
171+
// i64_rotr = 0x8a,
172+
// f32_abs = 0x8b,
173+
// f32_neg = 0x8c,
174+
// f32_ceil = 0x8d,
175+
// f32_floor = 0x8e,
176+
// f32_trunc = 0x8f,
177+
// f32_nearest = 0x90,
178+
// f32_sqrt = 0x91,
179+
// f32_add = 0x92,
180+
// f32_sub = 0x93,
181+
// f32_mul = 0x94,
182+
// f32_div = 0x95,
183+
// f32_min = 0x96,
184+
// f32_max = 0x97,
185+
// f32_copysign = 0x98,
186+
// f64_abs = 0x99,
187+
// f64_neg = 0x9a,
188+
// f64_ceil = 0x9b,
189+
// f64_floor = 0x9c,
190+
// f64_trunc = 0x9d,
191+
// f64_nearest = 0x9e,
192+
// f64_sqrt = 0x9f,
193+
// f64_add = 0xa0,
194+
// f64_sub = 0xa1,
195+
// f64_mul = 0xa2,
196+
// f64_div = 0xa3,
197+
// f64_min = 0xa4,
198+
// f64_max = 0xa5,
199+
// f64_copysign = 0xa6,
200+
// i32_wrap_i64 = 0xa7,
201+
// i32_trunc_s_f32 = 0xa8,
202+
// i32_trunc_u_f32 = 0xa9,
203+
// i32_trunc_s_f64 = 0xaa,
204+
// i32_trunc_u_f64 = 0xab,
205+
// i64_extend_s_i32 = 0xac,
206+
// i64_extend_u_i32 = 0xad,
207+
// i64_trunc_s_f32 = 0xae,
208+
// i64_trunc_u_f32 = 0xaf,
209+
// i64_trunc_s_f64 = 0xb0,
210+
// i64_trunc_u_f64 = 0xb1,
211+
// f32_convert_s_i32 = 0xb2,
212+
// f32_convert_u_i32 = 0xb3,
213+
// f32_convert_s_i64 = 0xb4,
214+
// f32_convert_u_i64 = 0xb5,
215+
// f32_demote_f64 = 0xb6,
216+
// f64_convert_s_i32 = 0xb7,
217+
// f64_convert_u_i32 = 0xb8,
218+
// f64_convert_s_i64 = 0xb9,
219+
// f64_convert_u_i64 = 0xba,
220+
// f64_promote_f32 = 0xbb,
221+
// i32_reinterpret_f32 = 0xbc,
222+
// i64_reinterpret_f64 = 0xbd,
223+
// f32_reinterpret_i32 = 0xbe,
224+
// f64_reinterpret_i64 = 0xbf
225225
}
226226

227227
export declare function parse(p: any): number;

0 commit comments

Comments
 (0)