Browse Source

[PATCH 147/188] giving an option not to write relocation information

From 407b608d27b470c208e30f55d8ea7dff5deedcc3 Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Wed, 25 Mar 2020 15:02:17 -0400

git-svn-id: branches/wasm@46143 -
nickysn 5 years ago
parent
commit
dd9cff6845
1 changed files with 25 additions and 13 deletions
  1. 25 13
      utils/wasmbin/wattest.lpr

+ 25 - 13
utils/wasmbin/wattest.lpr

@@ -19,20 +19,20 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure WriteBin(const fndst: string; m: TWasmModule);
+procedure WriteBin(const fndst: string; m: TWasmModule; WriteReloc: Boolean);
 var
 var
   f : TFileStream;
   f : TFileStream;
 begin
 begin
   f := TFileStream.Create(fndst, fmCreate);
   f := TFileStream.Create(fndst, fmCreate);
   try
   try
     Normalize(m);
     Normalize(m);
-    WriteModule(m, f, true, true);
+    WriteModule(m, f, WriteReloc, WriteReloc);
   finally
   finally
     f.Free;
     f.Free;
   end;
   end;
 end;
 end;
 
 
-procedure Run(const fn: string; const doTraverse: Boolean);
+procedure Run(const fn: string; const doTraverse: Boolean; doReloc: Boolean);
 var
 var
   st : TFileStream;
   st : TFileStream;
   s  : string;
   s  : string;
@@ -55,7 +55,7 @@ begin
       if not ParseModule(p, m, err) then
       if not ParseModule(p, m, err) then
         writeln('Error: ', err)
         writeln('Error: ', err)
       else
       else
-        WriteBin( ChangeFileExt(fn,'.wasm'), m);
+        WriteBin( ChangeFileExt(fn,'.wasm'), m, doReloc);
     finally
     finally
       m.Free;
       m.Free;
     end;
     end;
@@ -68,18 +68,24 @@ end;
 var
 var
   gFn      : string;
   gFn      : string;
   gCommand : string = '';
   gCommand : string = '';
+  gReloc   : Boolean = true;
+  gCatch   : Boolean = false;
 
 
 procedure ParseParams;
 procedure ParseParams;
 var
 var
   i : integer;
   i : integer;
   s : string;
   s : string;
+  ls : string;
 begin
 begin
   i:=1;
   i:=1;
   while i<=ParamCount do begin
   while i<=ParamCount do begin
     s := ParamStr(i);
     s := ParamStr(i);
-    if (s<>'') and (s[1]='-') then
-      gCommand:=AnsiLowerCase(s)
-    else
+    if (s<>'') and (s[1]='-') then begin
+      ls := AnsiLowerCase(s);
+      if ls = '-noreloc' then gReloc := false
+      else if ls = '-catch' then gCatch := true
+      else gCommand:=ls;
+    end else
       gFn := s;
       gFn := s;
     inc(i);
     inc(i);
   end;
   end;
@@ -91,6 +97,7 @@ begin
     writeln('please sepcify the input .wat file');
     writeln('please sepcify the input .wat file');
     writeln('other use:');
     writeln('other use:');
     writeln(' -compile  %inpfn%');
     writeln(' -compile  %inpfn%');
+    writeln('   -noreloc - prevents relocation information from being written');
     writeln(' -traverse %inpfn%');
     writeln(' -traverse %inpfn%');
     exit;
     exit;
   end;
   end;
@@ -98,11 +105,16 @@ begin
     writeln('file doesn''t exist: ', gFn);
     writeln('file doesn''t exist: ', gFn);
     exit;
     exit;
   end;
   end;
-  try
-    Run(gFn, gCommand = '-traverse');
-  except
-    on e: exception do
-      writeln(e.message);
-  end;
+
+  if gCatch then
+    try
+      Run(gFn, gCommand = '-traverse', gReloc);
+    except
+      on e: exception do
+        writeln(e.message);
+    end
+  else
+    Run(gFn, gCommand = '-traverse', gReloc);
+
 end.
 end.