hlcgcpu.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. globtype,
  24. aasmdata,
  25. symdef,
  26. hlcg2ll,
  27. cgutils,
  28. tgobj;
  29. type
  30. thlcgcpu = class(thlcg2ll)
  31. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);override;
  32. procedure a_jmp_external_name(list: TAsmList; const externalname: TSymStr);override;
  33. {$ifdef SPARC64}
  34. procedure temp_to_ref(p: ptemprecord; out ref: treference);override;
  35. {$endif SPARC64}
  36. end;
  37. procedure create_hlcodegen;
  38. implementation
  39. uses
  40. verbose,fmodule,
  41. aasmbase,aasmtai,aasmcpu,
  42. parabase,
  43. symconst,symtype,symsym,
  44. cgbase,cgobj,hlcgobj,cpubase,cgcpu;
  45. procedure thlcgcpu.g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);
  46. var
  47. make_global : boolean;
  48. href : treference;
  49. hsym : tsym;
  50. paraloc : pcgparalocation;
  51. begin
  52. if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
  53. Internalerror(200006137);
  54. if not assigned(procdef.struct) or
  55. (procdef.procoptions*[po_classmethod, po_staticmethod,
  56. po_methodpointer, po_interrupt, po_iocheck]<>[]) then
  57. Internalerror(200006138);
  58. if procdef.owner.symtabletype<>ObjectSymtable then
  59. Internalerror(200109191);
  60. make_global:=false;
  61. if (not current_module.is_unit) or create_smartlink or
  62. (procdef.owner.defowner.owner.symtabletype=globalsymtable) then
  63. make_global:=true;
  64. if make_global then
  65. List.concat(Tai_symbol.Createname_global(labelname,AT_FUNCTION,0,procdef))
  66. else
  67. List.concat(Tai_symbol.Createname(labelname,AT_FUNCTION,0,procdef));
  68. { set param1 interface to self }
  69. procdef.init_paraloc_info(callerside);
  70. hsym:=tsym(procdef.parast.Find('self'));
  71. if not(assigned(hsym) and
  72. (hsym.typ=paravarsym)) then
  73. internalerror(2010103101);
  74. paraloc:=tparavarsym(hsym).paraloc[callerside].location;
  75. if assigned(paraloc^.next) then
  76. InternalError(2013020101);
  77. case paraloc^.loc of
  78. LOC_REGISTER:
  79. begin
  80. if ((ioffset>=simm13lo) and (ioffset<=simm13hi)) then
  81. cg.a_op_const_reg(list,OP_SUB,paraloc^.size,ioffset,paraloc^.register)
  82. else
  83. begin
  84. cg.a_load_const_reg(list,paraloc^.size,ioffset,NR_G1);
  85. cg.a_op_reg_reg(list,OP_SUB,paraloc^.size,NR_G1,paraloc^.register);
  86. end;
  87. end;
  88. else
  89. internalerror(2010103102);
  90. end;
  91. if (po_virtualmethod in procdef.procoptions) and
  92. not is_objectpascal_helper(procdef.struct) then
  93. begin
  94. if (procdef.extnumber=$ffff) then
  95. Internalerror(200006139);
  96. { load vmt }
  97. reference_reset_base(href,voidpointertype,paraloc^.register,0,sizeof(pint),[]);
  98. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_G1);
  99. { jmp to method }
  100. reference_reset_base(href,voidpointertype,NR_G1,tobjectdef(procdef.struct).vmtmethodoffset(procdef.extnumber),sizeof(pint),[]);
  101. cg.a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,NR_G1);
  102. list.concat(taicpu.op_reg(A_JMP,NR_G1));
  103. { Delay slot }
  104. list.Concat(TAiCpu.Op_none(A_NOP));
  105. end
  106. else
  107. a_jmp_external_name(list,procdef.mangledname);
  108. List.concat(Tai_symbol_end.Createname(labelname));
  109. end;
  110. procedure thlcgcpu.a_jmp_external_name(list: TAsmList; const externalname: TSymStr);
  111. begin
  112. { CALL overwrites %o7 with its own address, we use delay slot to restore it. }
  113. list.concat(taicpu.op_reg_reg(A_MOV,NR_O7,NR_G1));
  114. list.concat(taicpu.op_sym(A_CALL,current_asmdata.RefAsmSymbol(externalname,AT_FUNCTION)));
  115. list.concat(taicpu.op_reg_reg(A_MOV,NR_G1,NR_O7));
  116. end;
  117. {$ifdef SPARC64}
  118. procedure thlcgcpu.temp_to_ref(p : ptemprecord; out ref : treference);
  119. begin
  120. inherited;
  121. inc(ref.offset,STACK_BIAS);
  122. end;
  123. {$endif SPARC64}
  124. procedure create_hlcodegen;
  125. begin
  126. hlcg:=thlcgcpu.create;
  127. create_codegen;
  128. end;
  129. begin
  130. chlcgobj:=thlcgcpu;
  131. end.