llvmpi.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {
  2. Copyright (c) 2016 by Jonas Maebe
  3. Information about the current procedure that is being compiled
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit llvmpi;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. aasmbase,
  23. procinfo,
  24. cpupi,
  25. aasmllvm;
  26. type
  27. tllvmprocinfo = class(tcpuprocinfo)
  28. private
  29. fexceptlabelstack: tfplist;
  30. flandingpadstack: tfplist;
  31. public
  32. constructor create(aparent: tprocinfo); override;
  33. destructor destroy; override;
  34. procedure pushexceptlabel(lab: TAsmLabel);
  35. { returns true if there no more landing pads on the stack }
  36. function popexceptlabel(lab: TAsmLabel): boolean;
  37. function CurrExceptLabel: TAsmLabel;
  38. procedure pushlandingpad(pad: taillvm);
  39. procedure poppad;
  40. function currlandingpad: taillvm;
  41. end;
  42. implementation
  43. uses
  44. globtype,globals,verbose,systems,
  45. symtable;
  46. constructor tllvmprocinfo.create(aparent: tprocinfo);
  47. begin
  48. inherited;
  49. fexceptlabelstack:=tfplist.create;
  50. flandingpadstack:=tfplist.create;
  51. end;
  52. destructor tllvmprocinfo.destroy;
  53. begin
  54. if fexceptlabelstack.Count<>0 then
  55. Internalerror(2016121301);
  56. fexceptlabelstack.free;
  57. if flandingpadstack.Count<>0 then
  58. internalerror(2018051901);
  59. flandingpadstack.free;
  60. inherited;
  61. end;
  62. procedure tllvmprocinfo.pushexceptlabel(lab: TAsmLabel);
  63. begin
  64. fexceptlabelstack.add(lab);
  65. end;
  66. function tllvmprocinfo.popexceptlabel(lab: TAsmLabel): boolean;
  67. begin
  68. if CurrExceptLabel<>lab then
  69. internalerror(2016121302);
  70. fexceptlabelstack.count:=fexceptlabelstack.count-1;
  71. result:=fexceptlabelstack.count=0;
  72. end;
  73. function tllvmprocinfo.CurrExceptLabel: TAsmLabel; inline;
  74. begin
  75. result:=TAsmLabel(fexceptlabelstack.last);
  76. if not assigned(result) then
  77. internalerror(2016121703);
  78. end;
  79. procedure tllvmprocinfo.pushlandingpad(pad: taillvm);
  80. begin
  81. flandingpadstack.add(pad);
  82. end;
  83. procedure tllvmprocinfo.poppad;
  84. begin
  85. if flandingpadstack.Count=0 then
  86. internalerror(2018051902);
  87. flandingpadstack.Count:=flandingpadstack.Count-1;
  88. end;
  89. function tllvmprocinfo.currlandingpad: taillvm;
  90. begin
  91. if flandingpadstack.Count=0 then
  92. internalerror(2018051903);
  93. result:=taillvm(flandingpadstack.last);
  94. end;
  95. begin
  96. if not assigned(cprocinfo) then
  97. begin
  98. writeln('Internalerror 2018052005');
  99. halt(1);
  100. end;
  101. cprocinfo:=tllvmprocinfo;
  102. end.