Browse Source

[PATCH 037/188] adding wattest

From f06b8396f0412a30a07da5a449ee54924d9e586e Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Wed, 20 Nov 2019 00:32:46 -0500

git-svn-id: branches/wasm@46033 -
nickysn 5 years ago
parent
commit
03657fa9a7
3 changed files with 116 additions and 0 deletions
  1. 2 0
      .gitattributes
  2. 59 0
      utils/wasmbin/wattest.lpi
  3. 55 0
      utils/wasmbin/wattest.lpr

+ 2 - 0
.gitattributes

@@ -18990,3 +18990,5 @@ utils/wasmbin/wasmtool.lpi svneol=native#text/plain
 utils/wasmbin/wasmtool.lpr svneol=native#text/plain
 utils/wasmbin/wasmtool.lpr svneol=native#text/plain
 utils/wasmbin/wasmtoolutils.pas svneol=native#text/plain
 utils/wasmbin/wasmtoolutils.pas svneol=native#text/plain
 utils/wasmbin/watparser.pas svneol=native#text/plain
 utils/wasmbin/watparser.pas svneol=native#text/plain
+utils/wasmbin/wattest.lpi svneol=native#text/plain
+utils/wasmbin/wattest.lpr svneol=native#text/plain

+ 59 - 0
utils/wasmbin/wattest.lpi

@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="12"/>
+    <PathDelim Value="\"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasTitleStatement Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <Title Value="wattest"/>
+      <UseAppBundle Value="False"/>
+      <ResourceType Value="res"/>
+    </General>
+    <BuildModes>
+      <Item Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+      <UseFileFilters Value="True"/>
+    </PublishOptions>
+    <RunParams>
+      <FormatVersion Value="2"/>
+      <Modes Count="0"/>
+    </RunParams>
+    <Units>
+      <Unit>
+        <Filename Value="wattest.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <PathDelim Value="\"/>
+    <Target>
+      <Filename Value="wattest"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 55 - 0
utils/wasmbin/wattest.lpr

@@ -0,0 +1,55 @@
+program wattest;
+
+{$mode objfpc}{$H+}
+
+uses
+  SysUtils, Classes, watparser;
+
+procedure Traverse(p: TWatScanner);
+begin
+  while p.Next do begin
+    write(p.token,' ', p.resText);
+    if p.token = weInstr then
+      write('; inst = $', IntToHex(p.instrCode,2))
+    else if p.token = weError then begin
+      writeln('offset = ',p.ofs,' ',p.resText);
+      break;
+    end;
+    writeln;
+  end;
+end;
+
+procedure Run(const fn: string);
+var
+  st : TFileStream;
+  s  : string;
+  p  : TWatScanner;
+begin
+  st := TFileStream.Create(fn, fmOpenRead or fmShareDenyNone);
+  p := TWatScanner.Create;
+  try
+    SetLength(s, st.Size);
+    if length(s)>0 then st.Read(s[1], length(s));
+    p.SetSource(s);
+    Traverse(p);
+  finally
+    p.Free;
+    st.Free;
+  end;
+end;
+
+var
+  fn : string;
+begin
+  if ParamCount=0 then begin
+    writeln('please sepcify the input .wat file');
+    exit;
+  end;
+  fn:=ParamStr(1);
+  if not FileExists(fn) then begin
+    writeln('file doesn''t exist: ', fn);
+    exit;
+  end;
+  Run(fn);
+end.
+