hlcgcpu.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. symtype,symdef,parabase,
  25. cgbase,cgutils,
  26. hlcgobj, hlcgx86;
  27. type
  28. thlcgcpu = class(thlcgx86)
  29. protected
  30. procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint); override;
  31. public
  32. procedure g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister); override;
  33. procedure g_releasevaluepara_openarray(list: TAsmList; arrdef: tarraydef; const l: tlocation); override;
  34. end;
  35. procedure create_hlcodegen;
  36. implementation
  37. uses
  38. globtype,verbose,
  39. paramgr,
  40. cpubase,tgobj,cgobj,cgcpu;
  41. { thlcgcpu }
  42. procedure thlcgcpu.gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint);
  43. var
  44. locsize : tcgsize;
  45. tmploc : tlocation;
  46. href : treference;
  47. stacksize : longint;
  48. begin
  49. if not(l.size in [OS_32,OS_S32,OS_64,OS_S64,OS_128,OS_S128]) then
  50. locsize:=l.size
  51. else
  52. locsize:=int_float_cgsize(tcgsize2size[l.size]);
  53. case l.loc of
  54. LOC_FPUREGISTER,
  55. LOC_CFPUREGISTER:
  56. begin
  57. case cgpara.location^.loc of
  58. LOC_REFERENCE:
  59. begin
  60. stacksize:=align(locintsize,cgpara.alignment);
  61. if (not paramanager.use_fixed_stack) and
  62. (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
  63. begin
  64. cg.g_stackpointer_alloc(list,stacksize);
  65. reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
  66. end
  67. else
  68. reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  69. cg.a_loadfpu_reg_ref(list,locsize,locsize,l.register,href);
  70. end;
  71. LOC_FPUREGISTER:
  72. begin
  73. cg.a_loadfpu_reg_reg(list,locsize,cgpara.location^.size,l.register,cgpara.location^.register);
  74. end;
  75. { can happen if a record with only 1 "single field" is
  76. returned in a floating point register and then is directly
  77. passed to a regcall parameter }
  78. LOC_REGISTER:
  79. begin
  80. tmploc:=l;
  81. location_force_mem(list,tmploc,size);
  82. case locsize of
  83. OS_F32:
  84. tmploc.size:=OS_32;
  85. OS_F64:
  86. tmploc.size:=OS_64;
  87. else
  88. internalerror(2010053116);
  89. end;
  90. cg.a_load_loc_cgpara(list,tmploc,cgpara);
  91. location_freetemp(list,tmploc);
  92. end
  93. else
  94. internalerror(2010053003);
  95. end;
  96. end;
  97. LOC_MMREGISTER,
  98. LOC_CMMREGISTER:
  99. begin
  100. case cgpara.location^.loc of
  101. LOC_REFERENCE:
  102. begin
  103. { can't use TCGSize2Size[l.size], because the size of an
  104. 80 bit extended parameter can be either 10 or 12 bytes }
  105. stacksize:=align(locintsize,cgpara.alignment);
  106. if (not paramanager.use_fixed_stack) and
  107. (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
  108. begin
  109. cg.g_stackpointer_alloc(list,stacksize);
  110. reference_reset_base(href,voidstackpointertype,NR_STACK_POINTER_REG,0,voidstackpointertype.size);
  111. end
  112. else
  113. reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  114. cg.a_loadmm_reg_ref(list,locsize,locsize,l.register,href,mms_movescalar);
  115. end;
  116. LOC_FPUREGISTER:
  117. begin
  118. tmploc:=l;
  119. location_force_mem(list,tmploc,size);
  120. cg.a_loadfpu_ref_cgpara(list,tmploc.size,tmploc.reference,cgpara);
  121. location_freetemp(list,tmploc);
  122. end;
  123. else
  124. internalerror(2010053004);
  125. end;
  126. end;
  127. LOC_REFERENCE,
  128. LOC_CREFERENCE :
  129. begin
  130. case cgpara.location^.loc of
  131. LOC_REFERENCE:
  132. begin
  133. stacksize:=align(locintsize,cgpara.alignment);
  134. if (not paramanager.use_fixed_stack) and
  135. (cgpara.location^.reference.index=NR_STACK_POINTER_REG) then
  136. cg.a_load_ref_cgpara(list,locsize,l.reference,cgpara)
  137. else
  138. begin
  139. reference_reset_base(href,voidstackpointertype,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  140. cg.g_concatcopy(list,l.reference,href,stacksize);
  141. end;
  142. end;
  143. LOC_FPUREGISTER:
  144. begin
  145. cg.a_loadfpu_ref_cgpara(list,locsize,l.reference,cgpara);
  146. end;
  147. else
  148. internalerror(2010053005);
  149. end;
  150. end;
  151. else
  152. internalerror(2002042430);
  153. end;
  154. end;
  155. procedure thlcgcpu.g_copyvaluepara_openarray(list: TAsmList; const ref: treference; const lenloc: tlocation; arrdef: tarraydef; destreg: tregister);
  156. begin
  157. if paramanager.use_fixed_stack then
  158. begin
  159. inherited;
  160. exit;
  161. end;
  162. tcg386(cg).g_copyvaluepara_openarray(list,ref,lenloc,arrdef.elesize,destreg);
  163. end;
  164. procedure thlcgcpu.g_releasevaluepara_openarray(list: TAsmList; arrdef: tarraydef; const l: tlocation);
  165. begin
  166. if paramanager.use_fixed_stack then
  167. begin
  168. inherited;
  169. exit;
  170. end;
  171. tcg386(cg).g_releasevaluepara_openarray(list,l);
  172. end;
  173. procedure create_hlcodegen;
  174. begin
  175. hlcg:=thlcgcpu.create;
  176. create_codegen;
  177. end;
  178. end.