llvmpi.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. procedure setup_eh; override;
  42. procedure finish_eh; override;
  43. end;
  44. implementation
  45. uses
  46. globtype,globals,verbose,systems,
  47. symconst,symtable;
  48. constructor tllvmprocinfo.create(aparent: tprocinfo);
  49. begin
  50. inherited;
  51. fexceptlabelstack:=tfplist.create;
  52. flandingpadstack:=tfplist.create;
  53. end;
  54. destructor tllvmprocinfo.destroy;
  55. begin
  56. if fexceptlabelstack.Count<>0 then
  57. Internalerror(2016121301);
  58. fexceptlabelstack.free;
  59. if flandingpadstack.Count<>0 then
  60. internalerror(2018051901);
  61. flandingpadstack.free;
  62. inherited;
  63. end;
  64. procedure tllvmprocinfo.pushexceptlabel(lab: TAsmLabel);
  65. begin
  66. fexceptlabelstack.add(lab);
  67. end;
  68. function tllvmprocinfo.popexceptlabel(lab: TAsmLabel): boolean;
  69. begin
  70. if CurrExceptLabel<>lab then
  71. internalerror(2016121302);
  72. fexceptlabelstack.count:=fexceptlabelstack.count-1;
  73. result:=fexceptlabelstack.count=0;
  74. end;
  75. function tllvmprocinfo.CurrExceptLabel: TAsmLabel; inline;
  76. begin
  77. result:=TAsmLabel(fexceptlabelstack.last);
  78. if not assigned(result) then
  79. internalerror(2016121703);
  80. end;
  81. procedure tllvmprocinfo.pushlandingpad(pad: taillvm);
  82. begin
  83. flandingpadstack.add(pad);
  84. end;
  85. procedure tllvmprocinfo.poppad;
  86. begin
  87. if flandingpadstack.Count=0 then
  88. internalerror(2018051902);
  89. flandingpadstack.Count:=flandingpadstack.Count-1;
  90. end;
  91. function tllvmprocinfo.currlandingpad: taillvm;
  92. begin
  93. if flandingpadstack.Count=0 then
  94. internalerror(2018051903);
  95. result:=taillvm(flandingpadstack.last);
  96. end;
  97. procedure tllvmprocinfo.setup_eh;
  98. begin
  99. if po_assembler in procdef.procoptions then
  100. inherited;
  101. end;
  102. procedure tllvmprocinfo.finish_eh;
  103. begin
  104. if po_assembler in procdef.procoptions then
  105. inherited;
  106. end;
  107. begin
  108. if not assigned(cprocinfo) then
  109. begin
  110. writeln('Internalerror 2018052005');
  111. halt(1);
  112. end;
  113. cprocinfo:=tllvmprocinfo;
  114. end.