wasmdef.pas 1.4 KB

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