wasmbindebug.pas 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. { This file is part of wasmbin - a collection of WebAssembly binary utils.
  2. Copyright (C) 2019, 2020 Dmitry Boyarintsev <[email protected]>
  3. Copyright (C) 2020 by the Free Pascal development team
  4. This source is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 2 of the License, or (at your option)
  7. any later version.
  8. This code is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. details.
  12. A copy of the GNU General Public License is available on the World Wide Web
  13. at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by writing
  14. to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  15. Boston, MA 02110-1335, USA.
  16. }
  17. unit wasmbindebug;
  18. {$mode objfpc}{$H+}
  19. interface
  20. uses
  21. Classes, SysUtils, wasmbin, lebutils;
  22. procedure DumpTypes(sr: TStream);
  23. procedure ReadFuncTypesArray(src: TStream; var arr: TFuncTypeArray);
  24. procedure ReadFuncType(src: TStream; var ft: TFuncType);
  25. implementation
  26. procedure DumpTypes(sr: TStream);
  27. var
  28. ar : TFuncTypeArray;
  29. i : integer;
  30. j : integer;
  31. begin
  32. ReadFuncTypesArray(sr, ar);
  33. for i:=0 to length(ar.funTypes)-1 do begin
  34. write('#',i);
  35. writeln;
  36. write(' params:');
  37. for j:=0 to length(ar.funTypes[i].param)-1 do
  38. write(' ', ValTypeToStr(ar.funTypes[i].param[j]));
  39. writeln;
  40. write(' result:');
  41. for j:=0 to length(ar.funTypes[i].result)-1 do
  42. write(' ', ValTypeToStr(ar.funTypes[i].result[j]));
  43. writeln;
  44. end;
  45. end;
  46. procedure ReadFuncType(src: TStream; var ft: TFuncType);
  47. var
  48. c: integer;
  49. begin
  50. // vector of t1
  51. c:=ReadU(src);
  52. SetLength(ft.param, c);
  53. src.Read(ft.param[0], c);
  54. // vector of t2
  55. c:=ReadU(src);
  56. SetLength(ft.result, c);
  57. src.Read(ft.result[0], c);
  58. end;
  59. procedure ReadFuncTypesArray(src: TStream; var arr: TFuncTypeArray);
  60. var
  61. cnt : integer;
  62. i : Integer;
  63. begin
  64. cnt := ReadU(src);
  65. SetLength(arr.funTypes, cnt);
  66. for i:=0 to cnt-1 do begin
  67. if src.ReadByte = func_type then
  68. ReadFuncType(src, arr.funTypes[i]);
  69. end;
  70. end;
  71. end.