hlcgcpu.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. aasmdata,
  24. symdef,
  25. hlcg2ll;
  26. type
  27. thlcgcpu = class(thlcg2ll)
  28. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  29. end;
  30. procedure create_hlcodegen;
  31. implementation
  32. uses
  33. globtype,verbose,
  34. fmodule,
  35. aasmbase,aasmtai,aasmcpu,
  36. symconst,
  37. hlcgobj,
  38. cgbase, cgutils, cgobj, cpubase, cgcpu;
  39. procedure thlcgcpu.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  40. procedure getselftoa0(offs:longint);
  41. var
  42. href : treference;
  43. selfoffsetfromsp : longint;
  44. begin
  45. { move.l offset(%sp),%a0 }
  46. { framepointer is pushed for nested procs }
  47. if procdef.parast.symtablelevel>normal_function_level then
  48. selfoffsetfromsp:=sizeof(aint)
  49. else
  50. selfoffsetfromsp:=0;
  51. reference_reset_base(href, voidstackpointertype, NR_SP,selfoffsetfromsp+offs,4);
  52. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_A0);
  53. end;
  54. procedure loadvmttoa0;
  55. var
  56. href : treference;
  57. begin
  58. { move.l (%a0),%a0 ; load vmt}
  59. reference_reset_base(href, voidpointertype, NR_A0,0,4);
  60. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_A0);
  61. end;
  62. procedure op_ona0methodaddr;
  63. var
  64. href : treference;
  65. begin
  66. if (procdef.extnumber=$ffff) then
  67. Internalerror(2013100701);
  68. reference_reset_base(href,voidpointertype,NR_A0,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber),4);
  69. list.concat(taicpu.op_ref_reg(A_MOVE,S_L,href,NR_A0));
  70. reference_reset_base(href,voidpointertype,NR_A0,0,4);
  71. list.concat(taicpu.op_ref(A_JMP,S_NO,href));
  72. end;
  73. var
  74. make_global : boolean;
  75. begin
  76. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  77. Internalerror(200006137);
  78. if not assigned(procdef.struct) or
  79. (procdef.procoptions*[po_classmethod, po_staticmethod,
  80. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  81. Internalerror(200006138);
  82. if procdef.owner.symtabletype<>ObjectSymtable then
  83. Internalerror(200109191);
  84. make_global:=false;
  85. if (not current_module.is_unit) or
  86. create_smartlink or
  87. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  88. make_global:=true;
  89. if make_global then
  90. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0))
  91. else
  92. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0));
  93. { set param1 interface to self }
  94. g_adjust_self_value(list,procdef,ioffset);
  95. { case 4 }
  96. if (po_virtualmethod in procdef.procoptions) and
  97. not is_objectpascal_helper(procdef.struct) then
  98. begin
  99. getselftoa0(4);
  100. loadvmttoa0;
  101. op_ona0methodaddr;
  102. end
  103. { case 0 }
  104. else
  105. list.concat(taicpu.op_sym(A_JMP,S_NO,current_asmdata.RefAsmSymbol(procdef.mangledname)));
  106. List.concat(Tai_symbol_end.Createname(labelname));
  107. end;
  108. procedure create_hlcodegen;
  109. begin
  110. hlcg:=thlcgcpu.create;
  111. create_codegen;
  112. end;
  113. begin
  114. chlcgobj:=thlcgcpu;
  115. end.