|
@@ -64,7 +64,7 @@ Unit rawasmtext;
|
|
procedure HandleInstruction;
|
|
procedure HandleInstruction;
|
|
procedure HandleFoldedInstruction;
|
|
procedure HandleFoldedInstruction;
|
|
function HandlePlainInstruction: TWasmInstruction;
|
|
function HandlePlainInstruction: TWasmInstruction;
|
|
- procedure HandleBlockInstruction;virtual;abstract;
|
|
|
|
|
|
+ procedure HandleBlockInstruction;
|
|
public
|
|
public
|
|
function Assemble: tlinkedlist;override;
|
|
function Assemble: tlinkedlist;override;
|
|
end;
|
|
end;
|
|
@@ -543,6 +543,8 @@ Unit rawasmtext;
|
|
|
|
|
|
|
|
|
|
procedure twasmreader.HandleInstruction;
|
|
procedure twasmreader.HandleInstruction;
|
|
|
|
+ var
|
|
|
|
+ instr: TWasmInstruction;
|
|
begin
|
|
begin
|
|
case actasmtoken of
|
|
case actasmtoken of
|
|
AS_LPAREN:
|
|
AS_LPAREN:
|
|
@@ -558,11 +560,14 @@ Unit rawasmtext;
|
|
a_if:
|
|
a_if:
|
|
HandleBlockInstruction;
|
|
HandleBlockInstruction;
|
|
else
|
|
else
|
|
- HandlePlainInstruction;
|
|
|
|
|
|
+ begin
|
|
|
|
+ instr:=HandlePlainInstruction;
|
|
|
|
+ instr.ConcatInstruction(curlist);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
else
|
|
else
|
|
- {error};
|
|
|
|
|
|
+ internalerror(2024071603);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -574,6 +579,7 @@ Unit rawasmtext;
|
|
instr: TWasmInstruction;
|
|
instr: TWasmInstruction;
|
|
tmpS: string;
|
|
tmpS: string;
|
|
begin
|
|
begin
|
|
|
|
+ instr:=nil;
|
|
//Consume(AS_LPAREN);
|
|
//Consume(AS_LPAREN);
|
|
case actasmtoken of
|
|
case actasmtoken of
|
|
AS_OPCODE:
|
|
AS_OPCODE:
|
|
@@ -690,8 +696,16 @@ Unit rawasmtext;
|
|
end;
|
|
end;
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
- HandlePlainInstruction;
|
|
|
|
- {todo: parse next folded instructions, insert plain instruction after these}
|
|
|
|
|
|
+ instr:=HandlePlainInstruction;
|
|
|
|
+ while actasmtoken<>AS_RPAREN do
|
|
|
|
+ begin
|
|
|
|
+ Consume(AS_LPAREN);
|
|
|
|
+ HandleFoldedInstruction;
|
|
|
|
+ end;
|
|
|
|
+ instr.ConcatInstruction(curlist);
|
|
|
|
+ instr.Free;
|
|
|
|
+ instr:=nil;
|
|
|
|
+ Consume(AS_RPAREN);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -710,7 +724,7 @@ Unit rawasmtext;
|
|
result:=TWasmInstruction.create(TWasmOperand);
|
|
result:=TWasmInstruction.create(TWasmOperand);
|
|
result.opcode:=actopcode;
|
|
result.opcode:=actopcode;
|
|
Consume(AS_OPCODE);
|
|
Consume(AS_OPCODE);
|
|
- case actopcode of
|
|
|
|
|
|
+ case result.opcode of
|
|
{ instructions, which require 0 operands }
|
|
{ instructions, which require 0 operands }
|
|
a_nop,
|
|
a_nop,
|
|
a_unreachable,
|
|
a_unreachable,
|
|
@@ -776,6 +790,7 @@ Unit rawasmtext;
|
|
begin
|
|
begin
|
|
if actasmtoken=AS_INTNUM then
|
|
if actasmtoken=AS_INTNUM then
|
|
begin
|
|
begin
|
|
|
|
+ result.ops:=1;
|
|
result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
result.operands[1].opr.val:=actinttoken;
|
|
result.operands[1].opr.val:=actinttoken;
|
|
Consume(AS_INTNUM);
|
|
Consume(AS_INTNUM);
|
|
@@ -795,12 +810,14 @@ Unit rawasmtext;
|
|
case actasmtoken of
|
|
case actasmtoken of
|
|
AS_INTNUM:
|
|
AS_INTNUM:
|
|
begin
|
|
begin
|
|
|
|
+ result.ops:=1;
|
|
result.operands[1].opr.typ:=OPR_FLOATCONSTANT;
|
|
result.operands[1].opr.typ:=OPR_FLOATCONSTANT;
|
|
result.operands[1].opr.floatval:=actinttoken;
|
|
result.operands[1].opr.floatval:=actinttoken;
|
|
Consume(AS_INTNUM);
|
|
Consume(AS_INTNUM);
|
|
end;
|
|
end;
|
|
AS_REALNUM:
|
|
AS_REALNUM:
|
|
begin
|
|
begin
|
|
|
|
+ result.ops:=1;
|
|
result.operands[1].opr.typ:=OPR_FLOATCONSTANT;
|
|
result.operands[1].opr.typ:=OPR_FLOATCONSTANT;
|
|
result.operands[1].opr.floatval:=actfloattoken;
|
|
result.operands[1].opr.floatval:=actfloattoken;
|
|
Consume(AS_REALNUM);
|
|
Consume(AS_REALNUM);
|
|
@@ -840,15 +857,82 @@ Unit rawasmtext;
|
|
a_i64_store32:
|
|
a_i64_store32:
|
|
begin
|
|
begin
|
|
{ TODO: parse the optional memarg operand }
|
|
{ TODO: parse the optional memarg operand }
|
|
|
|
+ result.ops:=1;
|
|
result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
result.operands[1].opr.val:=0;
|
|
result.operands[1].opr.val:=0;
|
|
end;
|
|
end;
|
|
|
|
+
|
|
|
|
+ { instructions that take a local variable parameter (or index) }
|
|
|
|
+ a_local_get,
|
|
|
|
+ a_local_set,
|
|
|
|
+ a_local_tee:
|
|
|
|
+ case actasmtoken of
|
|
|
|
+ AS_INTNUM:
|
|
|
|
+ begin
|
|
|
|
+ result.ops:=1;
|
|
|
|
+ result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
|
|
+ result.operands[1].opr.val:=actinttoken;
|
|
|
|
+ Consume(AS_INTNUM);
|
|
|
|
+ end;
|
|
|
|
+ {TODO:AS_ID}
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ { error: expected integer }
|
|
|
|
+ result.Free;
|
|
|
|
+ result:=nil;
|
|
|
|
+ Consume(AS_INTNUM);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+ a_global_get,
|
|
|
|
+ a_global_set:
|
|
|
|
+ case actasmtoken of
|
|
|
|
+ AS_INTNUM:
|
|
|
|
+ begin
|
|
|
|
+ result.ops:=1;
|
|
|
|
+ result.operands[1].opr.typ:=OPR_CONSTANT;
|
|
|
|
+ result.operands[1].opr.val:=actinttoken;
|
|
|
|
+ Consume(AS_INTNUM);
|
|
|
|
+ end;
|
|
|
|
+ {TODO:AS_ID}
|
|
|
|
+ else
|
|
|
|
+ begin
|
|
|
|
+ { error: expected integer }
|
|
|
|
+ result.Free;
|
|
|
|
+ result:=nil;
|
|
|
|
+ Consume(AS_INTNUM);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
else
|
|
else
|
|
internalerror(2024071401);
|
|
internalerror(2024071401);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
else
|
|
else
|
|
- {error};
|
|
|
|
|
|
+ internalerror(2024071604);
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ procedure twasmreader.HandleBlockInstruction;
|
|
|
|
+ var
|
|
|
|
+ instr: TWasmInstruction;
|
|
|
|
+ begin
|
|
|
|
+ if actasmtoken<>AS_OPCODE then
|
|
|
|
+ internalerror(2024071601);
|
|
|
|
+ case actopcode of
|
|
|
|
+ a_if,
|
|
|
|
+ a_block,
|
|
|
|
+ a_loop:
|
|
|
|
+ begin
|
|
|
|
+ instr:=TWasmInstruction.create(TWasmOperand);
|
|
|
|
+ instr.opcode:=actopcode;
|
|
|
|
+ Consume(AS_OPCODE);
|
|
|
|
+ {TODO: implement the rest}
|
|
|
|
+ internalerror(2024071699);
|
|
|
|
+ end;
|
|
|
|
+ else
|
|
|
|
+ internalerror(2024071602);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -877,6 +961,9 @@ Unit rawasmtext;
|
|
case actasmtoken of
|
|
case actasmtoken of
|
|
AS_END:
|
|
AS_END:
|
|
break; { end assembly block }
|
|
break; { end assembly block }
|
|
|
|
+ AS_OPCODE,
|
|
|
|
+ AS_LPAREN:
|
|
|
|
+ HandleInstruction;
|
|
else
|
|
else
|
|
begin
|
|
begin
|
|
Consume(actasmtoken);
|
|
Consume(actasmtoken);
|