Browse Source

[PATCH 167/188] binary writing for alignment

From ae1bf5c39b7258fe244391400a65cfd84c1ef12f Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Fri, 27 Mar 2020 11:34:02 -0400

git-svn-id: branches/wasm@46163 -
nickysn 5 years ago
parent
commit
8030e5f439
1 changed files with 24 additions and 0 deletions
  1. 24 0
      utils/wasmbin/wasmbinwriter.pas

+ 24 - 0
utils/wasmbin/wasmbinwriter.pas

@@ -624,6 +624,21 @@ begin
   if Result then WriteU32(dst, u32);
   if Result then WriteU32(dst, u32);
 end;
 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;
 function WriteI64Operand(dst: TStream; const operand: string): Boolean;
 var
 var
   err : integer;
   err : integer;
@@ -675,6 +690,8 @@ var
   ci  : TWasmInstr;
   ci  : TWasmInstr;
   idx : integer;
   idx : integer;
   rt  : Byte;
   rt  : Byte;
+  mm  : Integer;
+  err : Integer;
 begin
 begin
   for i:=0 to list.Count-1 do begin
   for i:=0 to list.Count-1 do begin
     ci :=list[i];
     ci :=list[i];
@@ -741,6 +758,13 @@ begin
 
 
       ipZero:
       ipZero:
         dst.WriteByte(0);
         dst.WriteByte(0);
+
+      ipOfsAlign: begin
+        // align
+        WriteAlign(dst, ci.alignText);
+        // offset
+        WriteI32Operand(dst, ci.offsetText);
+      end;
     end;
     end;
   end;
   end;
 end;
 end;