2
0

wasmdef.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. unit wasmdef;
  2. {$i fpcdefs.inc}
  3. interface
  4. uses
  5. symtype, symdef, symconst, constexp
  6. ,defutil;
  7. { returns whether a def is emulated using an implicit pointer type on the
  8. WebAssembly target (e.g., records, regular arrays, ...) }
  9. function wasmimplicitpointertype(def: tdef): boolean;
  10. function get_para_push_size(def: tdef): tdef;
  11. implementation
  12. function get_para_push_size(def: tdef): tdef;
  13. begin
  14. result:=def;
  15. if def.typ=orddef then
  16. case torddef(def).ordtype of
  17. u8bit,uchar:
  18. if torddef(def).high>127 then
  19. result:=s8inttype;
  20. u16bit:
  21. begin
  22. if torddef(def).high>32767 then
  23. result:=s16inttype;
  24. end
  25. else
  26. ;
  27. end;
  28. end;
  29. function wasmimplicitpointertype(def: tdef): boolean;
  30. begin
  31. case def.typ of
  32. arraydef:
  33. result:=(tarraydef(def).highrange>=tarraydef(def).lowrange) or
  34. is_open_array(def) or
  35. is_array_of_const(def) or
  36. is_array_constructor(def);
  37. filedef,
  38. recorddef,
  39. setdef:
  40. result:=true;
  41. objectdef:
  42. result:=is_object(def);
  43. stringdef :
  44. result:=tstringdef(def).stringtype in [st_shortstring,st_longstring];
  45. procvardef:
  46. result:=not tprocvardef(def).is_addressonly;
  47. else
  48. result:=false;
  49. end;
  50. end;
  51. end.