hlcgcpu.pas 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit contains routines to create a pass-through high-level code
  5. generator. This is used by most regular code generators.
  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 hlcgcpu;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. symtype,
  24. aasmdata,
  25. symdef,
  26. cgbase,cgutils,
  27. hlcgobj, hlcg2ll;
  28. type
  29. thlcgxtensa = class(thlcg2ll)
  30. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  31. procedure record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList);override;
  32. end;
  33. implementation
  34. uses
  35. verbose,globtype,fmodule,
  36. aasmbase,aasmtai,
  37. symconst,symsym,defutil,
  38. cpubase,aasmcpu,parabase,
  39. procinfo,
  40. cgobj,cgcpu;
  41. procedure create_hlcodegen_cpu;
  42. begin
  43. hlcg:=thlcgxtensa.create;
  44. create_codegen;
  45. end;
  46. procedure thlcgxtensa.g_intf_wrapper(list : TAsmList; procdef : tprocdef;
  47. const labelname : string; ioffset : longint);
  48. var
  49. make_global : boolean;
  50. tmpref : treference;
  51. l : TAsmLabel;
  52. begin
  53. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  54. Internalerror(200006137);
  55. if not assigned(procdef.struct) or
  56. (procdef.procoptions*[po_classmethod, po_staticmethod,
  57. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  58. Internalerror(200006138);
  59. if procdef.owner.symtabletype<>ObjectSymtable then
  60. Internalerror(200109191);
  61. make_global:=false;
  62. if (not current_module.is_unit) or
  63. create_smartlink or
  64. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  65. make_global:=true;
  66. if make_global then
  67. list.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
  68. else
  69. list.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
  70. { the wrapper might need aktlocaldata for the additional data to
  71. load the constant }
  72. current_procinfo:=cprocinfo.create(nil);
  73. { set param1 interface to self }
  74. g_adjust_self_value(list,procdef,ioffset);
  75. { case 4 }
  76. if (po_virtualmethod in procdef.procoptions) and
  77. not is_objectpascal_helper(procdef.struct) then
  78. begin
  79. // loadvmttor12;
  80. // op_onr12methodaddr;
  81. end
  82. else
  83. cg.a_jmp_name(list,procdef.mangledname);
  84. list.concatlist(current_procinfo.aktlocaldata);
  85. current_procinfo.Free;
  86. current_procinfo:=nil;
  87. list.concat(Tai_symbol_end.Createname(labelname));
  88. end;
  89. procedure thlcgxtensa.record_generated_code_for_procdef(pd : tprocdef; code,
  90. data : TAsmList);
  91. var
  92. alt : TAsmListType;
  93. begin
  94. { Xtensa needs the data before the subroutine }
  95. if assigned(data) and
  96. (not data.empty) then
  97. begin
  98. data.Concat(tai_align.Create(4));
  99. code.insertlist(data);
  100. end;
  101. inherited record_generated_code_for_procdef(pd,code,nil);
  102. end;
  103. begin
  104. chlcgobj:=thlcgxtensa;
  105. create_hlcodegen:=@create_hlcodegen_cpu;
  106. end.