Browse Source

[PATCH 060/188] adding a traverse command

From 925d019b817d2d8b154d237370fffa2b924f5c6d Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Tue, 3 Mar 2020 10:32:33 -0500

git-svn-id: branches/wasm@46056 -
nickysn 5 years ago
parent
commit
45ca2127d7
1 changed files with 32 additions and 8 deletions
  1. 32 8
      utils/wasmbin/wattest.lpr

+ 32 - 8
utils/wasmbin/wattest.lpr

@@ -31,7 +31,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure Run(const fn: string);
+procedure Run(const fn: string; const doTraverse: Boolean);
 var
 var
   st : TFileStream;
   st : TFileStream;
   s  : string;
   s  : string;
@@ -45,7 +45,10 @@ begin
     SetLength(s, st.Size);
     SetLength(s, st.Size);
     if length(s)>0 then st.Read(s[1], length(s));
     if length(s)>0 then st.Read(s[1], length(s));
     p.SetSource(s);
     p.SetSource(s);
-    //Traverse(p);
+    if doTraverse then begin
+      Traverse(p);
+      Exit;
+    end;
     m := TWasmModule.Create;
     m := TWasmModule.Create;
     try
     try
       if not ParseModule(p, m, err) then
       if not ParseModule(p, m, err) then
@@ -62,19 +65,40 @@ begin
 end;
 end;
 
 
 var
 var
-  fn : string;
+  gFn      : string;
+  gCommand : string = '';
+
+procedure ParseParams;
+var
+  i : integer;
+  s : string;
+begin
+  i:=1;
+  while i<=ParamCount do begin
+    s := ParamStr(i);
+    if (s<>'') and (s[1]='-') then
+      gCommand:=AnsiLowerCase(s)
+    else
+      gFn := s;
+    inc(i);
+  end;
+end;
+
 begin
 begin
-  if ParamCount=0 then begin
+  ParseParams;
+  if (gFn='') then begin
     writeln('please sepcify the input .wat file');
     writeln('please sepcify the input .wat file');
+    writeln('other use:');
+    writeln(' -compile  %inpfn%');
+    writeln(' -traverse %inpfn%');
     exit;
     exit;
   end;
   end;
-  fn:=ParamStr(1);
-  if not FileExists(fn) then begin
-    writeln('file doesn''t exist: ', fn);
+  if not FileExists(gFn) then begin
+    writeln('file doesn''t exist: ', gFn);
     exit;
     exit;
   end;
   end;
   try
   try
-    Run(fn);
+    Run(gFn, gCommand = '-traverse');
   except
   except
     on e: exception do
     on e: exception do
       writeln(e.message);
       writeln(e.message);