hlcgcpu.pas 7.1 KB

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