From 8030e5f439eeabbe1b41e2256c93c259d84a358b Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 3 Aug 2020 13:01:58 +0000 Subject: [PATCH] [PATCH 167/188] binary writing for alignment From ae1bf5c39b7258fe244391400a65cfd84c1ef12f Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Fri, 27 Mar 2020 11:34:02 -0400 git-svn-id: branches/wasm@46163 - --- utils/wasmbin/wasmbinwriter.pas | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/utils/wasmbin/wasmbinwriter.pas b/utils/wasmbin/wasmbinwriter.pas index e4f01ae2f7..aa350f9bf2 100644 --- a/utils/wasmbin/wasmbinwriter.pas +++ b/utils/wasmbin/wasmbinwriter.pas @@ -624,6 +624,21 @@ begin if Result then WriteU32(dst, u32); end; +procedure WriteAlign(dst: TStream; const operand: string); +var + m : Integer; +begin + m := 0; + if (length(operand)=1) then + case operand[1] of + '1': m := 0; + '2': m := 1; + '4': m := 2; + '8': m := 3; + end; + WriteU32(dst, m); +end; + function WriteI64Operand(dst: TStream; const operand: string): Boolean; var err : integer; @@ -675,6 +690,8 @@ var ci : TWasmInstr; idx : integer; rt : Byte; + mm : Integer; + err : Integer; begin for i:=0 to list.Count-1 do begin ci :=list[i]; @@ -741,6 +758,13 @@ begin ipZero: dst.WriteByte(0); + + ipOfsAlign: begin + // align + WriteAlign(dst, ci.alignText); + // offset + WriteI32Operand(dst, ci.offsetText); + end; end; end; end;