llvmcfi.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. {
  2. Copyright (c) 2019 by Jonas Maebe, member of the Free Pascal Compiler
  3. development team
  4. LLVM CFI wrapper: use native CFI instance for pure assembler routines,
  5. and dummy one for LLVM (the LLVM code generator will take care of CFI)
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit llvmcfi;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. aasmbase,
  24. aasmdata,
  25. cgbase;
  26. type
  27. tllvmcfi = class(TAsmCFI)
  28. constructor create; override;
  29. destructor destroy; override;
  30. procedure generate_code(list: TAsmList); override;
  31. procedure start_frame(list:TAsmList);override;
  32. procedure end_frame(list:TAsmList);override;
  33. procedure outmost_frame(list:TAsmList);override;
  34. procedure cfa_offset(list:TAsmList;reg:tregister;ofs:longint);override;
  35. procedure cfa_restore(list:TAsmList;reg:tregister);override;
  36. procedure cfa_def_cfa_register(list:TAsmList;reg:tregister);override;
  37. procedure cfa_def_cfa_offset(list:TAsmList;ofs:longint);override;
  38. function get_frame_start: TAsmLabel; override;
  39. function get_cfa_list: TAsmList; override;
  40. private
  41. fnativecfi: TAsmCFI;
  42. end;
  43. implementation
  44. uses
  45. symconst,
  46. procinfo;
  47. var
  48. nativecficlass: TAsmCFIClass;
  49. constructor tllvmcfi.create;
  50. begin
  51. inherited;
  52. fnativecfi:=nativecficlass.create;
  53. end;
  54. destructor tllvmcfi.destroy;
  55. begin
  56. fnativecfi.free;
  57. inherited destroy;
  58. end;
  59. procedure tllvmcfi.generate_code(list: TAsmList);
  60. begin
  61. fnativecfi.generate_code(list);
  62. end;
  63. procedure tllvmcfi.start_frame(list: TAsmList);
  64. begin
  65. if po_assembler in current_procinfo.procdef.procoptions then
  66. fnativecfi.start_frame(list);
  67. end;
  68. procedure tllvmcfi.end_frame(list: TAsmList);
  69. begin
  70. if po_assembler in current_procinfo.procdef.procoptions then
  71. fnativecfi.end_frame(list);
  72. end;
  73. procedure tllvmcfi.outmost_frame(list: TAsmList);
  74. begin
  75. if po_assembler in current_procinfo.procdef.procoptions then
  76. fnativecfi.outmost_frame(list);
  77. end;
  78. procedure tllvmcfi.cfa_offset(list: TAsmList; reg: tregister; ofs: longint);
  79. begin
  80. if po_assembler in current_procinfo.procdef.procoptions then
  81. fnativecfi.cfa_offset(list, reg, ofs);
  82. end;
  83. procedure tllvmcfi.cfa_restore(list: TAsmList; reg: tregister);
  84. begin
  85. if po_assembler in current_procinfo.procdef.procoptions then
  86. fnativecfi.cfa_restore(list, reg);
  87. end;
  88. procedure tllvmcfi.cfa_def_cfa_register(list: TAsmList; reg: tregister);
  89. begin
  90. if po_assembler in current_procinfo.procdef.procoptions then
  91. fnativecfi.cfa_def_cfa_register(list, reg);
  92. end;
  93. procedure tllvmcfi.cfa_def_cfa_offset(list: TAsmList; ofs: longint);
  94. begin
  95. if po_assembler in current_procinfo.procdef.procoptions then
  96. fnativecfi.cfa_def_cfa_offset(list, ofs);
  97. end;
  98. function tllvmcfi.get_frame_start: TAsmLabel;
  99. begin
  100. result:=fnativecfi.get_frame_start;
  101. end;
  102. function tllvmcfi.get_cfa_list: TAsmList;
  103. begin
  104. result:=fnativecfi.get_cfa_list;
  105. end;
  106. begin
  107. nativecficlass:=CAsmCFI;
  108. CAsmCFI:=tllvmcfi;
  109. end.