From 0ff587582b9e70dacb6a83cc6da21c7ec7c43bbf Mon Sep 17 00:00:00 2001 From: nickysn Date: Mon, 3 Aug 2020 13:01:19 +0000 Subject: [PATCH] [PATCH 126/188] adding data entity parsing From e996d96b6bf876611f7803f5e3367cae8a35c010 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev Date: Mon, 23 Mar 2020 16:23:09 -0400 git-svn-id: branches/wasm@46122 - --- utils/wasmbin/watparser.pas | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/utils/wasmbin/watparser.pas b/utils/wasmbin/watparser.pas index 9c61721a3b..fa11bbfba4 100644 --- a/utils/wasmbin/watparser.pas +++ b/utils/wasmbin/watparser.pas @@ -347,6 +347,35 @@ begin ConsumeToken(sc, weCloseBrace); end; +procedure ParseData(sc: TWatScanner; dst: TWasmData); +var + l : integer; +begin + if sc.token=weData then sc.Next; + + //id (if not exists, should be zero) + if sc.token in [weIdent, weNumber] then + ParseId(sc, dst.id); + + // offset (if not exist, should be zero) + if (sc.token = weOpenBrace) then begin + sc.Next; + ParseInstrList(sc, dst.StartOffset); + ConsumeToken(sc, weCloseBrace); + end; + + // data (if not exist, then blank) + if sc.token = weString then begin + l := length(sc.resText); + SetLength(dst.databuf, l); + if l>0 then + Move(sc.resText[1], dst.databuf[0], l); + sc.Next; + end; + + ConsumeToken(sc, weCloseBrace); +end; + procedure ParseMemory(sc: TWatScanner; dst: TWasmMemory); begin if sc.token=weMemory then sc.Next; @@ -476,7 +505,6 @@ begin end; weMemory: begin - writeln('trying to parse memory'); m:=dst.AddMemory; symlist.ToLinkInfo(f.LinkInfo); symlist.Clear; @@ -487,6 +515,10 @@ begin ParseExport(sc, dst.AddExport); symlist.Clear; end; + weData:begin + ParseData(sc, dst.AddData); + symlist.Clear; + end; else ErrorExpectButFound(sc, 'func', TokenStr[sc.token]); end;