hlcgcpu.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. hlcgx86;
  26. type
  27. thlcgcpu = class(thlcgx86)
  28. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  29. end;
  30. implementation
  31. uses
  32. globtype,globals,verbose,
  33. fmodule,systems,
  34. aasmbase,aasmtai,aasmcpu,
  35. symconst,
  36. hlcgobj,
  37. cgbase,cgutils,cgobj,cpubase,cgcpu,cpupi;
  38. procedure thlcgcpu.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  39. var
  40. make_global : boolean;
  41. href : treference;
  42. sym : tasmsymbol;
  43. r : treference;
  44. begin
  45. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  46. Internalerror(200006137);
  47. if not assigned(procdef.struct) or
  48. (procdef.procoptions*[po_classmethod, po_staticmethod,
  49. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  50. Internalerror(200006138);
  51. if procdef.owner.symtabletype<>ObjectSymtable then
  52. Internalerror(200109191);
  53. make_global:=false;
  54. if (not current_module.is_unit) or create_smartlink or
  55. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  56. make_global:=true;
  57. if make_global then
  58. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
  59. else
  60. List.concat(Tai_symbol.Createname_hidden(labelname,AT_FUNCTION,0,procdef));
  61. { set param1 interface to self }
  62. g_adjust_self_value(list,procdef,ioffset);
  63. if (po_virtualmethod in procdef.procoptions) and
  64. not is_objectpascal_helper(procdef.struct) then
  65. begin
  66. if (procdef.extnumber=$ffff) then
  67. Internalerror(200006139);
  68. { load vmt from first paramter }
  69. { win64 uses a different abi }
  70. if x86_64_use_ms_abi(procdef.proccalloption) then
  71. reference_reset_base(href,voidpointertype,NR_RCX,0,ctempposinvalid,sizeof(pint),[])
  72. else
  73. reference_reset_base(href,voidpointertype,NR_RDI,0,ctempposinvalid,sizeof(pint),[]);
  74. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_RAX);
  75. { jmp *vmtoffs(%eax) ; method offs }
  76. reference_reset_base(href,voidpointertype,NR_RAX,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber),ctempposinvalid,sizeof(pint),[]);
  77. list.concat(taicpu.op_ref(A_JMP,S_Q,href));
  78. end
  79. else
  80. begin
  81. sym:=current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION);
  82. reference_reset_symbol(r,sym,0,sizeof(pint),[]);
  83. if (cs_create_pic in current_settings.moduleswitches) and
  84. { darwin/x86_64's assembler doesn't want @PLT after call symbols }
  85. not(target_info.system in systems_darwin) then
  86. r.refaddr:=addr_pic
  87. else
  88. r.refaddr:=addr_full;
  89. list.concat(taicpu.op_ref(A_JMP,S_NO,r));
  90. end;
  91. List.concat(Tai_symbol_end.Createname(labelname));
  92. end;
  93. procedure create_hlcodegen_cpu;
  94. begin
  95. hlcg:=thlcgcpu.create;
  96. create_codegen;
  97. end;
  98. begin
  99. chlcgobj:=thlcgcpu;
  100. create_hlcodegen:=@create_hlcodegen_cpu;
  101. end.