hlcgobj.pas 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit implements the basic high level code generator object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {# @abstract(Abstract code generator unit)
  19. Abstract high level code generator unit. This contains the base class
  20. that either lowers most code to the regular code generator, or that
  21. has to be implemented/overridden for higher level targets (such as LLVM).
  22. }
  23. unit hlcgobj;
  24. {$i fpcdefs.inc}
  25. { define hlcginline}
  26. interface
  27. uses
  28. cclasses,globtype,constexp,
  29. cpubase,cgbase,cgutils,parabase,
  30. aasmbase,aasmtai,aasmdata,aasmcpu,
  31. symconst,symtype,symdef,rgobj,
  32. node
  33. ;
  34. type
  35. {# @abstract(Abstract high level code generator)
  36. This class implements an abstract instruction generator. All
  37. methods of this class are generic and are mapped to low level code
  38. generator methods by default. They have to be overridden for higher
  39. level targets
  40. }
  41. { thlcgobj }
  42. thlcgobj = class
  43. public
  44. {************************************************}
  45. { basic routines }
  46. constructor create;
  47. {# Initialize the register allocators needed for the codegenerator.}
  48. procedure init_register_allocators;virtual;
  49. {# Clean up the register allocators needed for the codegenerator.}
  50. procedure done_register_allocators;virtual;
  51. {# Set whether live_start or live_end should be updated when allocating registers, needed when e.g. generating initcode after the rest of the code. }
  52. procedure set_regalloc_live_range_direction(dir: TRADirection);virtual;
  53. {# Gets a register suitable to do integer operations on.}
  54. function getintregister(list:TAsmList;size:tdef):Tregister;virtual;
  55. {# Gets a register suitable to do integer operations on.}
  56. function getaddressregister(list:TAsmList;size:tdef):Tregister;virtual;
  57. function getfpuregister(list:TAsmList;size:tdef):Tregister;virtual;
  58. // we don't have high level defs yet that translate into all mm cgsizes
  59. // function getmmregister(list:TAsmList;size:tdef):Tregister;virtual;
  60. function getflagregister(list:TAsmList;size:tdef):Tregister;virtual;
  61. function getregisterfordef(list: TAsmList;size:tdef):Tregister;virtual;
  62. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  63. the cpu specific child cg object have such a method?}
  64. function uses_registers(rt:Tregistertype):boolean; inline;
  65. procedure do_register_allocation(list:TAsmList;headertai:tai); inline;
  66. procedure translate_register(var reg : tregister); inline;
  67. {# Emit a label to the instruction stream. }
  68. procedure a_label(list : TAsmList;l : tasmlabel); inline;
  69. {# Allocates register r by inserting a pai_realloc record }
  70. procedure a_reg_alloc(list : TAsmList;r : tregister); inline;
  71. {# Deallocates register r by inserting a pa_regdealloc record}
  72. procedure a_reg_dealloc(list : TAsmList;r : tregister); inline;
  73. { Synchronize register, make sure it is still valid }
  74. procedure a_reg_sync(list : TAsmList;r : tregister); inline;
  75. {# Pass a parameter, which is located in a register, to a routine.
  76. This routine should push/send the parameter to the routine, as
  77. required by the specific processor ABI and routine modifiers.
  78. It must generate register allocation information for the cgpara in
  79. case it consists of cpuregisters.
  80. @param(size size of the operand in the register)
  81. @param(r register source of the operand)
  82. @param(cgpara where the parameter will be stored)
  83. }
  84. procedure a_load_reg_cgpara(list : TAsmList;size : tdef;r : tregister;const cgpara : TCGPara);virtual;
  85. {# Pass a parameter, which is a constant, to a routine.
  86. A generic version is provided. This routine should
  87. be overridden for optimization purposes if the cpu
  88. permits directly sending this type of parameter.
  89. It must generate register allocation information for the cgpara in
  90. case it consists of cpuregisters.
  91. @param(size size of the operand in constant)
  92. @param(a value of constant to send)
  93. @param(cgpara where the parameter will be stored)
  94. }
  95. procedure a_load_const_cgpara(list : TAsmList;tosize : tdef;a : aint;const cgpara : TCGPara);virtual;
  96. {# Pass the value of a parameter, which is located in memory, to a routine.
  97. A generic version is provided. This routine should
  98. be overridden for optimization purposes if the cpu
  99. permits directly sending this type of parameter.
  100. It must generate register allocation information for the cgpara in
  101. case it consists of cpuregisters.
  102. @param(size size of the operand in constant)
  103. @param(r Memory reference of value to send)
  104. @param(cgpara where the parameter will be stored)
  105. }
  106. procedure a_load_ref_cgpara(list : TAsmList;size : tdef;const r : treference;const cgpara : TCGPara);virtual;
  107. {# Pass the value of a parameter, which can be located either in a register or memory location,
  108. to a routine.
  109. A generic version is provided.
  110. @param(l location of the operand to send)
  111. @param(nr parameter number (starting from one) of routine (from left to right))
  112. @param(cgpara where the parameter will be stored)
  113. }
  114. procedure a_load_loc_cgpara(list : TAsmList;size : tdef; const l : tlocation;const cgpara : TCGPara);virtual;
  115. {# Pass the address of a reference to a routine. This routine
  116. will calculate the address of the reference, and pass this
  117. calculated address as a parameter.
  118. It must generate register allocation information for the cgpara in
  119. case it consists of cpuregisters.
  120. A generic version is provided. This routine should
  121. be overridden for optimization purposes if the cpu
  122. permits directly sending this type of parameter.
  123. @param(fromsize type of the reference we are taking the address of)
  124. @param(tosize type of the pointer that we get as a result)
  125. @param(r reference to get address from)
  126. }
  127. procedure a_loadaddr_ref_cgpara(list : TAsmList;fromsize, tosize : tdef;const r : treference;const cgpara : TCGPara);virtual;
  128. { Remarks:
  129. * If a method specifies a size you have only to take care
  130. of that number of bits, i.e. load_const_reg with OP_8 must
  131. only load the lower 8 bit of the specified register
  132. the rest of the register can be undefined
  133. if necessary the compiler will call a method
  134. to zero or sign extend the register
  135. * The a_load_XX_XX with OP_64 needn't to be
  136. implemented for 32 bit
  137. processors, the code generator takes care of that
  138. * the addr size is for work with the natural pointer
  139. size
  140. * the procedures without fpu/mm are only for integer usage
  141. * normally the first location is the source and the
  142. second the destination
  143. }
  144. {# Emits instruction to call the method specified by symbol name.
  145. This routine must be overridden for each new target cpu.
  146. }
  147. procedure a_call_name(list : TAsmList;pd : tprocdef;const s : string; weak: boolean);virtual;abstract;
  148. procedure a_call_reg(list : TAsmList;pd : tabstractprocdef;reg : tregister);virtual;abstract;
  149. procedure a_call_ref(list : TAsmList;pd : tabstractprocdef;ref : treference);virtual;abstract;
  150. { same as a_call_name, might be overridden on certain architectures to emit
  151. static calls without usage of a got trampoline }
  152. procedure a_call_name_static(list : TAsmList;pd : tprocdef;const s : string);virtual;
  153. { same as a_call_name, might be overridden on certain architectures to emit
  154. special static calls for inherited methods }
  155. procedure a_call_name_inherited(list : TAsmList;pd : tprocdef;const s : string);virtual;
  156. { move instructions }
  157. procedure a_load_const_reg(list : TAsmList;tosize : tdef;a : aint;register : tregister);virtual;abstract;
  158. procedure a_load_const_ref(list : TAsmList;tosize : tdef;a : aint;const ref : treference);virtual;
  159. procedure a_load_const_loc(list : TAsmList;tosize : tdef;a : aint;const loc : tlocation);virtual;
  160. procedure a_load_reg_ref(list : TAsmList;fromsize, tosize : tdef;register : tregister;const ref : treference);virtual;abstract;
  161. procedure a_load_reg_ref_unaligned(list : TAsmList;fromsize, tosize : tdef;register : tregister;const ref : treference);virtual;
  162. procedure a_load_reg_reg(list : TAsmList;fromsize, tosize : tdef;reg1,reg2 : tregister);virtual;abstract;
  163. procedure a_load_reg_loc(list : TAsmList;fromsize, tosize : tdef;reg : tregister;const loc: tlocation);virtual;
  164. procedure a_load_ref_reg(list : TAsmList;fromsize, tosize : tdef;const ref : treference;register : tregister);virtual;abstract;
  165. procedure a_load_ref_reg_unaligned(list : TAsmList;fromsize, tosize : tdef;const ref : treference;register : tregister);virtual;
  166. procedure a_load_ref_ref(list : TAsmList;fromsize, tosize : tdef;const sref : treference;const dref : treference);virtual;
  167. procedure a_load_loc_reg(list : TAsmList;fromsize, tosize : tdef; const loc: tlocation; reg : tregister);virtual;
  168. procedure a_load_loc_ref(list : TAsmList;fromsize, tosize: tdef; const loc: tlocation; const ref : treference);virtual;
  169. procedure a_load_loc_subsetreg(list : TAsmList;fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sreg : tsubsetregister);virtual;
  170. procedure a_load_loc_subsetref(list : TAsmList;fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sref : tsubsetreference);virtual;
  171. procedure a_loadaddr_ref_reg(list : TAsmList;fromsize, tosize : tdef;const ref : treference;r : tregister);virtual;abstract;
  172. { The subset stuff still need a transformation to thlcgobj }
  173. procedure a_load_subsetreg_reg(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; destreg: tregister); virtual; abstract;
  174. procedure a_load_reg_subsetreg(list : TAsmList; fromsize, tosize, tosubsetsize: tdef; fromreg: tregister; const sreg: tsubsetregister); virtual; abstract;
  175. procedure a_load_subsetreg_subsetreg(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsreg, tosreg: tsubsetregister); virtual; abstract;
  176. procedure a_load_subsetreg_ref(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const destref: treference); virtual; abstract;
  177. procedure a_load_ref_subsetreg(list : TAsmList; fromsize, tosize,tosubsetsize: tdef; const fromref: treference; const sreg: tsubsetregister); virtual; abstract;
  178. procedure a_load_const_subsetreg(list: TAsmlist; tosize, tosubsetsize: tdef; a: aint; const sreg: tsubsetregister); virtual; abstract;
  179. procedure a_load_subsetreg_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const loc: tlocation); virtual;
  180. procedure a_load_subsetref_reg(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; destreg: tregister); virtual; abstract;
  181. procedure a_load_reg_subsetref(list : TAsmList; fromsize, tosubsetsize, tosize: tdef; fromreg: tregister; const sref: tsubsetreference); virtual; abstract;
  182. procedure a_load_subsetref_subsetref(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsref, tosref: tsubsetreference); virtual; abstract;
  183. procedure a_load_subsetref_ref(list : TAsmList; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const destref: treference); virtual; abstract;
  184. procedure a_load_ref_subsetref(list : TAsmList; fromsize, tosize, tosubsetsize: tdef; const fromref: treference; const sref: tsubsetreference); virtual; abstract;
  185. procedure a_load_const_subsetref(list: TAsmlist; tosize, tosubsetsize: tdef; a: aint; const sref: tsubsetreference); virtual; abstract;
  186. procedure a_load_subsetref_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const loc: tlocation); virtual;
  187. procedure a_load_subsetref_subsetreg(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsref: tsubsetreference; const tosreg: tsubsetregister); virtual; abstract;
  188. procedure a_load_subsetreg_subsetref(list: TAsmlist; fromsize, fromsubsetsize, tosize, tosubsetsize : tdef; const fromsreg: tsubsetregister; const tosref: tsubsetreference); virtual; abstract;
  189. { bit test instructions (still need transformation to thlcgobj) }
  190. procedure a_bit_test_reg_reg_reg(list : TAsmList; bitnumbersize,valuesize,destsize: tdef;bitnumber,value,destreg: tregister); virtual; abstract;
  191. procedure a_bit_test_const_ref_reg(list: TAsmList; fromsize, destsize: tdef; bitnumber: aint; const ref: treference; destreg: tregister); virtual; abstract;
  192. procedure a_bit_test_const_reg_reg(list: TAsmList; setregsize, destsize: tdef; bitnumber: aint; setreg, destreg: tregister); virtual; abstract;
  193. procedure a_bit_test_const_subsetreg_reg(list: TAsmList; fromsize, fromsubsetsize, destsize: tdef; bitnumber: aint; const setreg: tsubsetregister; destreg: tregister); virtual; abstract;
  194. procedure a_bit_test_reg_ref_reg(list: TAsmList; bitnumbersize, refsize, destsize: tdef; bitnumber: tregister; const ref: treference; destreg: tregister); virtual; abstract;
  195. procedure a_bit_test_reg_loc_reg(list: TAsmList; bitnumbersize, locsize, destsize: tdef; bitnumber: tregister; const loc: tlocation; destreg: tregister);virtual;
  196. procedure a_bit_test_const_loc_reg(list: TAsmList; locsize, destsize: tdef; bitnumber: aint; const loc: tlocation; destreg: tregister);virtual;
  197. { bit set/clear instructions (still need transformation to thlcgobj) }
  198. procedure a_bit_set_reg_reg(list : TAsmList; doset: boolean; bitnumbersize, destsize: tdef; bitnumber,dest: tregister); virtual; abstract;
  199. procedure a_bit_set_const_ref(list: TAsmList; doset: boolean;destsize: tdef; bitnumber: aint; const ref: treference); virtual; abstract;
  200. procedure a_bit_set_const_reg(list: TAsmList; doset: boolean; destsize: tdef; bitnumber: aint; destreg: tregister); virtual; abstract;
  201. procedure a_bit_set_const_subsetreg(list: TAsmList; doset: boolean; destsize, destsubsetsize: tdef; bitnumber: aint; const destreg: tsubsetregister); virtual; abstract;
  202. procedure a_bit_set_reg_ref(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const ref: treference); virtual; abstract;
  203. procedure a_bit_set_reg_loc(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const loc: tlocation);virtual;
  204. procedure a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);virtual;
  205. { bit scan instructions (still need transformation to thlcgobj) }
  206. procedure a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; size: tdef; src, dst: tregister); virtual; abstract;
  207. { fpu move instructions }
  208. procedure a_loadfpu_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister); virtual; abstract;
  209. procedure a_loadfpu_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister); virtual; abstract;
  210. procedure a_loadfpu_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference); virtual; abstract;
  211. procedure a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1,ref2: treference);virtual;
  212. procedure a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);virtual;
  213. procedure a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);virtual;
  214. procedure a_loadfpu_reg_cgpara(list : TAsmList;fromsize: tdef;const r : tregister;const cgpara : TCGPara);virtual;
  215. procedure a_loadfpu_ref_cgpara(list : TAsmList;fromsize : tdef;const ref : treference;const cgpara : TCGPara);virtual;
  216. { vector register move instructions }
  217. // we don't have high level defs yet that translate into all mm cgsizes
  218. {
  219. procedure a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef;reg1, reg2: tregister;shuffle : pmmshuffle); virtual;
  220. procedure a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  221. procedure a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual;
  222. procedure a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);virtual;
  223. procedure a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);virtual;
  224. procedure a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  225. procedure a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  226. procedure a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  227. procedure a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size : tdef;src,dst: tregister;shuffle : pmmshuffle); virtual;
  228. procedure a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size : tdef;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  229. procedure a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size : tdef;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  230. procedure a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size : tdef;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  231. }
  232. // we don't have high level defs yet that translate into all mm cgsizes
  233. // procedure a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize : tdef; intreg, mmreg: tregister; shuffle: pmmshuffle); virtual;
  234. // procedure a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize : tdef; mmreg, intreg: tregister; shuffle : pmmshuffle); virtual;
  235. { basic arithmetic operations }
  236. { note: for operators which require only one argument (not, neg), use }
  237. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  238. { that in this case the *second* operand is used as both source and }
  239. { destination (JM) }
  240. procedure a_op_const_reg(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; reg: TRegister); virtual; abstract;
  241. procedure a_op_const_ref(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference); virtual;
  242. procedure a_op_const_subsetreg(list : TAsmList; Op : TOpCG; size, subsetsize : tdef; a : aint; const sreg: tsubsetregister); virtual;
  243. procedure a_op_const_subsetref(list : TAsmList; Op : TOpCG; size, subsetsize : tdef; a : aint; const sref: tsubsetreference); virtual;
  244. procedure a_op_const_loc(list : TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);virtual;
  245. procedure a_op_reg_reg(list : TAsmList; Op: TOpCG; size: tdef; reg1, reg2: TRegister); virtual; abstract;
  246. procedure a_op_reg_ref(list : TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference); virtual;
  247. procedure a_op_ref_reg(list : TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister); virtual;
  248. procedure a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister); virtual;
  249. procedure a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference); virtual;
  250. procedure a_op_reg_loc(list : TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);virtual;
  251. procedure a_op_ref_loc(list : TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);virtual;
  252. { trinary operations for processors that support them, 'emulated' }
  253. { on others. None with "ref" arguments since I don't think there }
  254. { are any processors that support it (JM) }
  255. procedure a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister); virtual;
  256. procedure a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister); virtual;
  257. procedure a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  258. procedure a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  259. { comparison operations }
  260. procedure a_cmp_const_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp;a : aint;reg : tregister;
  261. l : tasmlabel);virtual;
  262. procedure a_cmp_const_ref_label(list : TAsmList;size : tdef;cmp_op : topcmp;a : aint;const ref : treference;
  263. l : tasmlabel); virtual;
  264. procedure a_cmp_const_loc_label(list: TAsmList; size: tdef;cmp_op: topcmp; a: aint; const loc: tlocation;
  265. l : tasmlabel);virtual;
  266. procedure a_cmp_reg_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  267. procedure a_cmp_ref_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  268. procedure a_cmp_reg_ref_label(list : TAsmList;size : tdef;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  269. procedure a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel); virtual;
  270. procedure a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel); virtual;
  271. procedure a_cmp_loc_reg_label(list : TAsmList;size : tdef;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);virtual;
  272. procedure a_cmp_reg_loc_label(list : TAsmList;size : tdef;cmp_op : topcmp; reg: tregister; const loc: tlocation; l : tasmlabel);virtual;
  273. procedure a_cmp_ref_loc_label(list: TAsmList; size: tdef;cmp_op: topcmp; const ref: treference; const loc: tlocation; l : tasmlabel);virtual;
  274. procedure a_jmp_always(list : TAsmList;l: tasmlabel); virtual;abstract;
  275. {$ifdef cpuflags}
  276. procedure a_jmp_flags(list : TAsmList;const f : TResFlags;l: tasmlabel); virtual; abstract;
  277. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  278. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  279. }
  280. procedure g_flags2reg(list: TAsmList; size: tdef; const f: tresflags; reg: TRegister); virtual; abstract;
  281. procedure g_flags2ref(list: TAsmList; size: tdef; const f: tresflags; const ref:TReference); virtual; abstract;
  282. {$endif cpuflags}
  283. // procedure g_maybe_testself(list : TAsmList;reg:tregister);
  284. // procedure g_maybe_testvmt(list : TAsmList;reg:tregister;objdef:tobjectdef);
  285. {# This should emit the opcode to copy len bytes from the source
  286. to destination.
  287. It must be overridden for each new target processor.
  288. @param(source Source reference of copy)
  289. @param(dest Destination reference of copy)
  290. }
  291. procedure g_concatcopy(list : TAsmList;size: tdef; const source,dest : treference);virtual;
  292. {# This should emit the opcode to copy len bytes from the an unaligned source
  293. to destination.
  294. It must be overridden for each new target processor.
  295. @param(source Source reference of copy)
  296. @param(dest Destination reference of copy)
  297. }
  298. procedure g_concatcopy_unaligned(list : TAsmList;size: tdef; const source,dest : treference);virtual;
  299. {# This should emit the opcode to a shortrstring from the source
  300. to destination.
  301. @param(source Source reference of copy)
  302. @param(dest Destination reference of copy)
  303. }
  304. procedure g_copyshortstring(list : TAsmList;const source,dest : treference;strdef:tstringdef);virtual;abstract;
  305. procedure g_copyvariant(list : TAsmList;const source,dest : treference;vardef:tvariantdef);virtual;abstract;
  306. procedure g_incrrefcount(list : TAsmList;t: tdef; const ref: treference);virtual;abstract;
  307. procedure g_decrrefcount(list : TAsmList;t: tdef; const ref: treference);virtual;abstract;
  308. procedure g_initialize(list : TAsmList;t : tdef;const ref : treference);virtual;abstract;
  309. procedure g_finalize(list : TAsmList;t : tdef;const ref : treference);virtual;abstract;
  310. procedure g_array_rtti_helper(list: TAsmList; t: tdef; const ref: treference; const highloc: tlocation;
  311. const name: string);virtual;abstract;
  312. {# Generates range checking code. It is to note
  313. that this routine does not need to be overridden,
  314. as it takes care of everything.
  315. @param(p Node which contains the value to check)
  316. @param(todef Type definition of node to range check)
  317. }
  318. procedure g_rangecheck(list: TAsmList; const l:tlocation; fromdef,todef: tdef); virtual;
  319. {# Generates overflow checking code for a node }
  320. procedure g_overflowcheck(list: TAsmList; const Loc:tlocation; def:tdef); virtual; abstract;
  321. procedure g_overflowCheck_loc(List:TAsmList;const Loc:TLocation;def:TDef;var ovloc : tlocation);virtual; abstract;
  322. procedure g_copyvaluepara_openarray(list : TAsmList;const ref:treference;const lenloc:tlocation;arrdef: tarraydef;destreg:tregister);virtual;abstract;
  323. procedure g_releasevaluepara_openarray(list : TAsmList;arrdef: tarraydef;const l:tlocation);virtual;abstract;
  324. {# Emits instructions when compilation is done in profile
  325. mode (this is set as a command line option). The default
  326. behavior does nothing, should be overridden as required.
  327. }
  328. procedure g_profilecode(list : TAsmList);virtual;
  329. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  330. @param(size Number of bytes to allocate)
  331. }
  332. procedure g_stackpointer_alloc(list : TAsmList;size : longint);virtual; abstract;
  333. {# Emits instruction for allocating the locals in entry
  334. code of a routine. This is one of the first
  335. routine called in @var(genentrycode).
  336. @param(localsize Number of bytes to allocate as locals)
  337. }
  338. procedure g_proc_entry(list : TAsmList;localsize : longint;nostackframe:boolean);virtual; abstract;
  339. {# Emits instructions for returning from a subroutine.
  340. Should also restore the framepointer and stack.
  341. @param(parasize Number of bytes of parameters to deallocate from stack)
  342. }
  343. procedure g_proc_exit(list : TAsmList;parasize:longint;nostackframe:boolean);virtual; abstract;
  344. procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);virtual; abstract;
  345. procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: aint);virtual; abstract;
  346. function g_indirect_sym_load(list:TAsmList;const symname: string; weak: boolean): tregister;virtual; abstract;
  347. { generate a stub which only purpose is to pass control the given external method,
  348. setting up any additional environment before doing so (if required).
  349. The default implementation issues a jump instruction to the external name. }
  350. // procedure g_external_wrapper(list : TAsmList; procdef: tprocdef; const externalname: string); virtual;
  351. { create "safe copy" of a tlocation that can be used later: all
  352. registers used in the tlocation are copied to new ones, so that
  353. even if the original ones change, things stay the same (except if
  354. the original location was already a register, then the register is
  355. kept). Must only be used on lvalue locations.
  356. It's intended as some kind of replacement for a_loadaddr_ref_reg()
  357. for targets without pointers. }
  358. procedure g_reference_loc(list: TAsmList; def: tdef; const fromloc: tlocation; out toloc: tlocation); virtual; abstract;
  359. { routines migrated from ncgutil }
  360. procedure location_force_reg(list:TAsmList;var l:tlocation;src_size,dst_size:tdef;maybeconst:boolean);virtual;
  361. procedure location_force_fpureg(list:TAsmList;var l: tlocation;size: tdef;maybeconst:boolean);virtual;
  362. procedure location_force_mem(list:TAsmList;var l:tlocation;size:tdef);virtual;
  363. // procedure location_force_mmregscalar(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  364. // procedure location_force_mmreg(list:TAsmList;var l: tlocation;size:tdef;maybeconst:boolean);virtual;abstract;
  365. { Retrieve the location of the data pointed to in location l, when the location is
  366. a register it is expected to contain the address of the data }
  367. procedure location_get_data_ref(list:TAsmList;def: tdef; const l:tlocation;var ref:treference;loadref:boolean; alignment: longint);virtual;
  368. procedure maketojumpbool(list:TAsmList; p : tnode);virtual;
  369. procedure gen_proc_symbol(list:TAsmList);virtual;
  370. procedure gen_proc_symbol_end(list:TAsmList);virtual;
  371. procedure gen_load_para_value(list:TAsmList);virtual;
  372. protected
  373. { helpers called by gen_load_para_value }
  374. procedure g_copyvalueparas(p:TObject;arg:pointer);virtual;
  375. procedure gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation;const cgpara: tcgpara;locintsize: longint);virtual;
  376. procedure init_paras(p:TObject;arg:pointer);
  377. protected
  378. { Some targets have to put "something" in the function result
  379. location if it's not initialised by the Pascal code, e.g.
  380. stack-based architectures. By default it does nothing }
  381. procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);virtual;
  382. public
  383. { load a tlocation into a cgpara }
  384. procedure gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);virtual;
  385. { load a cgpara into a tlocation }
  386. procedure gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);virtual;
  387. { load the function return value into the ABI-defined function return location }
  388. procedure gen_load_return_value(list:TAsmList);virtual;
  389. { extras refactored from other units }
  390. { queue the code/data generated for a procedure for writing out to
  391. the assembler/object file }
  392. procedure record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList); virtual;
  393. end;
  394. var
  395. {# Main high level code generator class }
  396. hlcg : thlcgobj;
  397. procedure destroy_hlcodegen;
  398. implementation
  399. uses
  400. globals,options,systems,
  401. fmodule,export,
  402. verbose,defutil,paramgr,symsym,
  403. ncon,
  404. cpuinfo,cgobj,tgobj,cutils,procinfo,
  405. ncgutil;
  406. procedure destroy_hlcodegen;
  407. begin
  408. hlcg.free;
  409. hlcg:=nil;
  410. end;
  411. { thlcgobj }
  412. constructor thlcgobj.create;
  413. begin
  414. end;
  415. procedure thlcgobj.init_register_allocators;
  416. begin
  417. cg.init_register_allocators;
  418. end;
  419. procedure thlcgobj.done_register_allocators;
  420. begin
  421. cg.done_register_allocators;
  422. end;
  423. procedure thlcgobj.set_regalloc_live_range_direction(dir: TRADirection);
  424. begin
  425. cg.set_regalloc_live_range_direction(dir);
  426. end;
  427. function thlcgobj.getintregister(list: TAsmList; size: tdef): Tregister;
  428. begin
  429. result:=cg.getintregister(list,def_cgsize(size));
  430. end;
  431. function thlcgobj.getaddressregister(list: TAsmList; size: tdef): Tregister;
  432. begin
  433. result:=cg.getaddressregister(list);
  434. end;
  435. function thlcgobj.getfpuregister(list: TAsmList; size: tdef): Tregister;
  436. begin
  437. result:=cg.getfpuregister(list,def_cgsize(size));
  438. end;
  439. (*
  440. function thlcgobj.getmmregister(list: TAsmList; size: tdef): Tregister;
  441. begin
  442. result:=cg.getmmregister(list,def_cgsize(size));
  443. end;
  444. *)
  445. function thlcgobj.getflagregister(list: TAsmList; size: tdef): Tregister;
  446. begin
  447. result:=cg.getflagregister(list,def_cgsize(size));
  448. end;
  449. function thlcgobj.getregisterfordef(list: TAsmList; size: tdef): Tregister;
  450. begin
  451. case def2regtyp(size) of
  452. R_INTREGISTER:
  453. result:=getintregister(list,size);
  454. R_ADDRESSREGISTER:
  455. result:=getaddressregister(list,size);
  456. R_FPUREGISTER:
  457. result:=getfpuregister(list,size);
  458. (*
  459. R_MMREGISTER:
  460. result:=getmmregister(list,size);
  461. *)
  462. else
  463. internalerror(2010122901);
  464. end;
  465. end;
  466. function thlcgobj.uses_registers(rt: Tregistertype): boolean;
  467. begin
  468. result:=cg.uses_registers(rt);
  469. end;
  470. procedure thlcgobj.do_register_allocation(list: TAsmList; headertai: tai);
  471. begin
  472. cg.do_register_allocation(list,headertai);
  473. end;
  474. procedure thlcgobj.translate_register(var reg: tregister);
  475. begin
  476. cg.translate_register(reg);
  477. end;
  478. procedure thlcgobj.a_label(list: TAsmList; l: tasmlabel); inline;
  479. begin
  480. cg.a_label(list,l);
  481. end;
  482. procedure thlcgobj.a_reg_alloc(list: TAsmList; r: tregister);
  483. begin
  484. cg.a_reg_alloc(list,r);
  485. end;
  486. procedure thlcgobj.a_reg_dealloc(list: TAsmList; r: tregister);
  487. begin
  488. cg.a_reg_dealloc(list,r);
  489. end;
  490. procedure thlcgobj.a_reg_sync(list: TAsmList; r: tregister);
  491. begin
  492. cg.a_reg_sync(list,r);
  493. end;
  494. procedure thlcgobj.a_load_reg_cgpara(list: TAsmList; size: tdef; r: tregister; const cgpara: TCGPara);
  495. var
  496. ref: treference;
  497. begin
  498. cgpara.check_simple_location;
  499. paramanager.alloccgpara(list,cgpara);
  500. case cgpara.location^.loc of
  501. LOC_REGISTER,LOC_CREGISTER:
  502. a_load_reg_reg(list,size,cgpara.def,r,cgpara.location^.register);
  503. LOC_REFERENCE,LOC_CREFERENCE:
  504. begin
  505. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  506. a_load_reg_ref(list,size,cgpara.def,r,ref);
  507. end;
  508. (*
  509. LOC_MMREGISTER,LOC_CMMREGISTER:
  510. a_loadmm_intreg_reg(list,size,cgpara.def,r,cgpara.location^.register,mms_movescalar);
  511. *)
  512. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  513. begin
  514. tg.gethltemp(list,size,size.size,tt_normal,ref);
  515. a_load_reg_ref(list,size,size,r,ref);
  516. a_loadfpu_ref_cgpara(list,size,ref,cgpara);
  517. tg.ungettemp(list,ref);
  518. end
  519. else
  520. internalerror(2010120415);
  521. end;
  522. end;
  523. procedure thlcgobj.a_load_const_cgpara(list: TAsmList; tosize: tdef; a: aint; const cgpara: TCGPara);
  524. var
  525. ref : treference;
  526. begin
  527. cgpara.check_simple_location;
  528. paramanager.alloccgpara(list,cgpara);
  529. case cgpara.location^.loc of
  530. LOC_REGISTER,LOC_CREGISTER:
  531. a_load_const_reg(list,cgpara.def,a,cgpara.location^.register);
  532. LOC_REFERENCE,LOC_CREFERENCE:
  533. begin
  534. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  535. a_load_const_ref(list,cgpara.def,a,ref);
  536. end
  537. else
  538. internalerror(2010120416);
  539. end;
  540. end;
  541. procedure thlcgobj.a_load_ref_cgpara(list: TAsmList; size: tdef; const r: treference; const cgpara: TCGPara);
  542. var
  543. ref: treference;
  544. begin
  545. cgpara.check_simple_location;
  546. paramanager.alloccgpara(list,cgpara);
  547. case cgpara.location^.loc of
  548. LOC_REGISTER,LOC_CREGISTER:
  549. a_load_ref_reg(list,size,cgpara.def,r,cgpara.location^.register);
  550. LOC_REFERENCE,LOC_CREFERENCE:
  551. begin
  552. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  553. a_load_ref_ref(list,size,cgpara.def,r,ref);
  554. end
  555. (*
  556. LOC_MMREGISTER,LOC_CMMREGISTER:
  557. begin
  558. case location^.size of
  559. OS_F32,
  560. OS_F64,
  561. OS_F128:
  562. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,mms_movescalar);
  563. OS_M8..OS_M128,
  564. OS_MS8..OS_MS128:
  565. a_loadmm_ref_reg(list,cgpara.def,cgpara.def,r,location^.register,nil);
  566. else
  567. internalerror(2010120417);
  568. end;
  569. end
  570. *)
  571. else
  572. internalerror(2010120418);
  573. end;
  574. end;
  575. procedure thlcgobj.a_load_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: TCGPara);
  576. begin
  577. case l.loc of
  578. LOC_REGISTER,
  579. LOC_CREGISTER :
  580. a_load_reg_cgpara(list,size,l.register,cgpara);
  581. LOC_CONSTANT :
  582. a_load_const_cgpara(list,size,l.value,cgpara);
  583. LOC_CREFERENCE,
  584. LOC_REFERENCE :
  585. a_load_ref_cgpara(list,size,l.reference,cgpara);
  586. else
  587. internalerror(2010120419);
  588. end;
  589. end;
  590. procedure thlcgobj.a_loadaddr_ref_cgpara(list: TAsmList; fromsize, tosize: tdef; const r: treference; const cgpara: TCGPara);
  591. var
  592. hr : tregister;
  593. begin
  594. cgpara.check_simple_location;
  595. if cgpara.location^.loc in [LOC_CREGISTER,LOC_REGISTER] then
  596. begin
  597. paramanager.allocparaloc(list,cgpara.location);
  598. a_loadaddr_ref_reg(list,fromsize,tosize,r,cgpara.location^.register)
  599. end
  600. else
  601. begin
  602. hr:=getaddressregister(list,tosize);
  603. a_loadaddr_ref_reg(list,fromsize,tosize,r,hr);
  604. a_load_reg_cgpara(list,tosize,hr,cgpara);
  605. end;
  606. end;
  607. procedure thlcgobj.a_call_name_static(list: TAsmList; pd: tprocdef; const s: string);
  608. begin
  609. a_call_name(list,pd,s,false);
  610. end;
  611. procedure thlcgobj.a_call_name_inherited(list: TAsmList; pd: tprocdef; const s: string);
  612. begin
  613. a_call_name(list,pd,s,false);
  614. end;
  615. procedure thlcgobj.a_load_const_ref(list: TAsmList; tosize: tdef; a: aint; const ref: treference);
  616. var
  617. tmpreg: tregister;
  618. begin
  619. tmpreg:=getintregister(list,tosize);
  620. a_load_const_reg(list,tosize,a,tmpreg);
  621. a_load_reg_ref(list,tosize,tosize,tmpreg,ref);
  622. end;
  623. procedure thlcgobj.a_load_const_loc(list: TAsmList; tosize: tdef; a: aint; const loc: tlocation);
  624. begin
  625. case loc.loc of
  626. LOC_REFERENCE,LOC_CREFERENCE:
  627. a_load_const_ref(list,tosize,a,loc.reference);
  628. LOC_REGISTER,LOC_CREGISTER:
  629. a_load_const_reg(list,tosize,a,loc.register);
  630. { we don't have enough type information to handle these here
  631. LOC_SUBSETREG,LOC_CSUBSETREG:
  632. a_load_const_subsetreg(list,loc.size,a,loc.sreg);
  633. LOC_SUBSETREF,LOC_CSUBSETREF:
  634. a_load_const_subsetref(list,loc.size,a,loc.sref);
  635. }
  636. else
  637. internalerror(2010120401);
  638. end;
  639. end;
  640. procedure thlcgobj.a_load_reg_ref_unaligned(list: TAsmList; fromsize, tosize: tdef; register: tregister; const ref: treference);
  641. begin
  642. a_load_reg_ref(list,fromsize,tosize,register,ref);
  643. end;
  644. procedure thlcgobj.a_load_reg_loc(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const loc: tlocation);
  645. begin
  646. case loc.loc of
  647. LOC_REFERENCE,LOC_CREFERENCE:
  648. a_load_reg_ref(list,fromsize,tosize,reg,loc.reference);
  649. LOC_REGISTER,LOC_CREGISTER:
  650. a_load_reg_reg(list,fromsize,tosize,reg,loc.register);
  651. { we don't have enough type information to handle these here
  652. LOC_SUBSETREG,LOC_CSUBSETREG:
  653. a_load_reg_subsetreg(list,fromsize,tosize,reg,loc.sreg);
  654. LOC_SUBSETREF,LOC_CSUBSETREF:
  655. a_load_reg_subsetref(list,fromsize,loc.size,reg,loc.sref);
  656. LOC_MMREGISTER,LOC_CMMREGISTER:
  657. a_loadmm_intreg_reg(list,fromsize,loc.size,reg,loc.register,mms_movescalar);
  658. }
  659. else
  660. internalerror(2010120402);
  661. end;
  662. end;
  663. procedure thlcgobj.a_load_ref_reg_unaligned(list: TAsmList; fromsize, tosize: tdef; const ref: treference; register: tregister);
  664. begin
  665. a_load_ref_reg(list,fromsize,tosize,ref,register);
  666. end;
  667. procedure thlcgobj.a_load_ref_ref(list: TAsmList; fromsize, tosize: tdef; const sref: treference; const dref: treference);
  668. var
  669. tmpreg: tregister;
  670. begin
  671. { verify if we have the same reference }
  672. if references_equal(sref,dref) then
  673. exit;
  674. tmpreg:=getintregister(list,tosize);
  675. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  676. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  677. end;
  678. procedure thlcgobj.a_load_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; reg: tregister);
  679. begin
  680. case loc.loc of
  681. LOC_REFERENCE,LOC_CREFERENCE:
  682. a_load_ref_reg(list,fromsize,tosize,loc.reference,reg);
  683. LOC_REGISTER,LOC_CREGISTER:
  684. a_load_reg_reg(list,fromsize,tosize,loc.register,reg);
  685. LOC_CONSTANT:
  686. a_load_const_reg(list,tosize,loc.value,reg);
  687. { we don't have enough type information to handle these here
  688. LOC_SUBSETREG,LOC_CSUBSETREG:
  689. a_load_subsetreg_reg(list,fromsize,tosize,loc.sreg,reg);
  690. LOC_SUBSETREF,LOC_CSUBSETREF:
  691. a_load_subsetref_reg(list,fromsize,tosize,loc.sref,reg);
  692. }
  693. else
  694. internalerror(2010120201);
  695. end;
  696. end;
  697. procedure thlcgobj.a_load_loc_ref(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const ref: treference);
  698. begin
  699. case loc.loc of
  700. LOC_REFERENCE,LOC_CREFERENCE:
  701. a_load_ref_ref(list,fromsize,tosize,loc.reference,ref);
  702. LOC_REGISTER,LOC_CREGISTER:
  703. a_load_reg_ref(list,fromsize,tosize,loc.register,ref);
  704. LOC_CONSTANT:
  705. a_load_const_ref(list,tosize,loc.value,ref);
  706. { we don't have enough type information to handle these here
  707. LOC_SUBSETREG,LOC_CSUBSETREG:
  708. a_load_subsetreg_ref(list,loc.size,tosize,loc.sreg,ref);
  709. LOC_SUBSETREF,LOC_CSUBSETREF:
  710. a_load_subsetref_ref(list,loc.size,tosize,loc.sref,ref);
  711. }
  712. else
  713. internalerror(2010120403);
  714. end;
  715. end;
  716. procedure thlcgobj.a_load_loc_subsetreg(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sreg: tsubsetregister);
  717. begin
  718. case loc.loc of
  719. LOC_REFERENCE,LOC_CREFERENCE:
  720. a_load_ref_subsetreg(list,fromsize,tosize,tosubsetsize,loc.reference,sreg);
  721. LOC_REGISTER,LOC_CREGISTER:
  722. a_load_reg_subsetreg(list,fromsize,tosize,tosubsetsize,loc.register,sreg);
  723. LOC_CONSTANT:
  724. a_load_const_subsetreg(list,tosize,tosubsetsize,loc.value,sreg);
  725. { we don't have enough type information to handle these here
  726. LOC_SUBSETREG,LOC_CSUBSETREG:
  727. a_load_subsetreg_subsetreg(list,loc.size,subsetsize,loc.sreg,sreg);
  728. LOC_SUBSETREF,LOC_CSUBSETREF:
  729. a_load_subsetref_subsetreg(list,loc.size,subsetsize,loc.sref,sreg);
  730. }
  731. else
  732. internalerror(2010120404);
  733. end;
  734. end;
  735. procedure thlcgobj.a_load_loc_subsetref(list: TAsmList; fromsize, tosize, tosubsetsize: tdef; const loc: tlocation; const sref: tsubsetreference);
  736. begin
  737. case loc.loc of
  738. LOC_REFERENCE,LOC_CREFERENCE:
  739. a_load_ref_subsetref(list,fromsize,tosize,tosubsetsize,loc.reference,sref);
  740. LOC_REGISTER,LOC_CREGISTER:
  741. a_load_reg_subsetref(list,fromsize,tosize,tosubsetsize,loc.register,sref);
  742. LOC_CONSTANT:
  743. a_load_const_subsetref(list,tosize,tosubsetsize,loc.value,sref);
  744. { we don't have enough type information to handle these here
  745. LOC_SUBSETREG,LOC_CSUBSETREG:
  746. a_load_subsetreg_subsetref(list,loc.size,subsetsize,loc.sreg,sref);
  747. LOC_SUBSETREF,LOC_CSUBSETREF:
  748. a_load_subsetref_subsetref(list,loc.size,subsetsize,loc.sref,sref);
  749. }
  750. else
  751. internalerror(2010120405);
  752. end;
  753. end;
  754. procedure thlcgobj.a_load_subsetreg_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sreg: tsubsetregister; const loc: tlocation);
  755. begin
  756. case loc.loc of
  757. LOC_REFERENCE,LOC_CREFERENCE:
  758. a_load_subsetreg_ref(list,fromsize,fromsubsetsize,tosize,sreg,loc.reference);
  759. LOC_REGISTER,LOC_CREGISTER:
  760. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,tosize,sreg,loc.register);
  761. { we don't have enough type information to handle these here
  762. LOC_SUBSETREG,LOC_CSUBSETREG:
  763. a_load_subsetreg_subsetreg(list,subsetsize,loc.size,sreg,loc.sreg);
  764. LOC_SUBSETREF,LOC_CSUBSETREF:
  765. a_load_subsetreg_subsetref(list,subsetsize,loc.size,sreg,loc.sref);
  766. }
  767. else
  768. internalerror(2010120406);
  769. end;
  770. end;
  771. procedure thlcgobj.a_load_subsetref_loc(list: TAsmlist; fromsize, fromsubsetsize, tosize: tdef; const sref: tsubsetreference; const loc: tlocation);
  772. begin
  773. case loc.loc of
  774. LOC_REFERENCE,LOC_CREFERENCE:
  775. a_load_subsetref_ref(list,fromsize,fromsubsetsize,tosize,sref,loc.reference);
  776. LOC_REGISTER,LOC_CREGISTER:
  777. a_load_subsetref_reg(list,fromsize,fromsubsetsize,tosize,sref,loc.register);
  778. { we don't have enough type information to handle these here
  779. LOC_SUBSETREG,LOC_CSUBSETREG:
  780. a_load_subsetref_subsetreg(list,subsetsize,loc.size,sref,loc.sreg);
  781. LOC_SUBSETREF,LOC_CSUBSETREF:
  782. a_load_subsetref_subsetref(list,subsetsize,loc.size,sref,loc.sref);
  783. }
  784. else
  785. internalerror(2010120407);
  786. end;
  787. end;
  788. procedure thlcgobj.a_bit_test_reg_loc_reg(list: TAsmList; bitnumbersize, locsize, destsize: tdef; bitnumber: tregister; const loc: tlocation; destreg: tregister);
  789. var
  790. tmpreg: tregister;
  791. begin
  792. case loc.loc of
  793. LOC_REFERENCE,LOC_CREFERENCE:
  794. a_bit_test_reg_ref_reg(list,bitnumbersize,locsize,destsize,bitnumber,loc.reference,destreg);
  795. LOC_REGISTER,LOC_CREGISTER,
  796. LOC_SUBSETREG,LOC_CSUBSETREG,
  797. LOC_CONSTANT:
  798. begin
  799. case loc.loc of
  800. LOC_REGISTER,LOC_CREGISTER:
  801. tmpreg:=loc.register;
  802. (* we don't have enough type information to handle this here
  803. LOC_SUBSETREG,LOC_CSUBSETREG:
  804. begin
  805. tmpreg:=getintregister(list,loc.size);
  806. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  807. end;
  808. *)
  809. LOC_CONSTANT:
  810. begin
  811. tmpreg:=getintregister(list,locsize);
  812. a_load_const_reg(list,locsize,loc.value,tmpreg);
  813. end;
  814. end;
  815. a_bit_test_reg_reg_reg(list,bitnumbersize,locsize,destsize,bitnumber,tmpreg,destreg);
  816. end;
  817. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  818. else
  819. internalerror(2010120411);
  820. end;
  821. end;
  822. procedure thlcgobj.a_bit_test_const_loc_reg(list: TAsmList; locsize, destsize: tdef; bitnumber: aint; const loc: tlocation; destreg: tregister);
  823. begin
  824. case loc.loc of
  825. LOC_REFERENCE,LOC_CREFERENCE:
  826. a_bit_test_const_ref_reg(list,locsize,destsize,bitnumber,loc.reference,destreg);
  827. LOC_REGISTER,LOC_CREGISTER:
  828. a_bit_test_const_reg_reg(list,locsize,destsize,bitnumber,loc.register,destreg);
  829. (* we don't have enough type information to handle this here
  830. LOC_SUBSETREG,LOC_CSUBSETREG:
  831. a_bit_test_const_subsetreg_reg(list,loc.size,destsize,bitnumber,loc.sreg,destreg);
  832. *)
  833. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  834. else
  835. internalerror(2010120410);
  836. end;
  837. end;
  838. procedure thlcgobj.a_bit_set_reg_loc(list: TAsmList; doset: boolean; fromsize, tosize: tdef; bitnumber: tregister; const loc: tlocation);
  839. begin
  840. case loc.loc of
  841. LOC_REFERENCE:
  842. a_bit_set_reg_ref(list,doset,fromsize,tosize,bitnumber,loc.reference);
  843. LOC_CREGISTER:
  844. a_bit_set_reg_reg(list,doset,fromsize,tosize,bitnumber,loc.register);
  845. (* we don't have enough type information to handle this here
  846. { e.g. a 2-byte set in a record regvar }
  847. LOC_CSUBSETREG:
  848. begin
  849. { hard to do in-place in a generic way, so operate on a copy }
  850. tmpreg:=getintregister(list,loc.size);
  851. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  852. a_bit_set_reg_reg(list,doset,bitnumbersize,loc.size,bitnumber,tmpreg);
  853. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  854. end;
  855. *)
  856. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  857. else
  858. internalerror(2010120408)
  859. end;
  860. end;
  861. procedure thlcgobj.a_bit_set_const_loc(list: TAsmList; doset: boolean; tosize: tdef; bitnumber: aint; const loc: tlocation);
  862. begin
  863. case loc.loc of
  864. LOC_REFERENCE:
  865. a_bit_set_const_ref(list,doset,tosize,bitnumber,loc.reference);
  866. LOC_CREGISTER:
  867. a_bit_set_const_reg(list,doset,tosize,bitnumber,loc.register);
  868. (* we don't have enough type information to handle this here
  869. LOC_CSUBSETREG:
  870. a_bit_set_const_subsetreg(list,doset,loc.size,bitnumber,loc.sreg);
  871. *)
  872. { LOC_SUBSETREF is not possible, because sets are not (yet) bitpacked }
  873. else
  874. internalerror(2010120409)
  875. end;
  876. end;
  877. procedure thlcgobj.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);
  878. var
  879. reg: tregister;
  880. regsize: tdef;
  881. begin
  882. if (fromsize.size>=tosize.size) then
  883. regsize:=fromsize
  884. else
  885. regsize:=tosize;
  886. reg:=getfpuregister(list,regsize);
  887. a_loadfpu_ref_reg(list,fromsize,regsize,ref1,reg);
  888. a_loadfpu_reg_ref(list,regsize,tosize,reg,ref2);
  889. end;
  890. procedure thlcgobj.a_loadfpu_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister);
  891. begin
  892. case loc.loc of
  893. LOC_REFERENCE, LOC_CREFERENCE:
  894. a_loadfpu_ref_reg(list,fromsize,tosize,loc.reference,reg);
  895. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  896. a_loadfpu_reg_reg(list,fromsize,tosize,loc.register,reg);
  897. else
  898. internalerror(2010120412);
  899. end;
  900. end;
  901. procedure thlcgobj.a_loadfpu_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation);
  902. begin
  903. case loc.loc of
  904. LOC_REFERENCE, LOC_CREFERENCE:
  905. a_loadfpu_reg_ref(list,fromsize,tosize,reg,loc.reference);
  906. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  907. a_loadfpu_reg_reg(list,fromsize,tosize,reg,loc.register);
  908. else
  909. internalerror(2010120413);
  910. end;
  911. end;
  912. procedure thlcgobj.a_loadfpu_reg_cgpara(list: TAsmList; fromsize: tdef; const r: tregister; const cgpara: TCGPara);
  913. var
  914. ref : treference;
  915. begin
  916. paramanager.alloccgpara(list,cgpara);
  917. case cgpara.location^.loc of
  918. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  919. begin
  920. cgpara.check_simple_location;
  921. a_loadfpu_reg_reg(list,fromsize,cgpara.def,r,cgpara.location^.register);
  922. end;
  923. LOC_REFERENCE,LOC_CREFERENCE:
  924. begin
  925. cgpara.check_simple_location;
  926. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  927. a_loadfpu_reg_ref(list,fromsize,cgpara.def,r,ref);
  928. end;
  929. LOC_REGISTER,LOC_CREGISTER:
  930. begin
  931. { paramfpu_ref does the check_simpe_location check here if necessary }
  932. tg.gethltemp(list,fromsize,fromsize.size,tt_normal,ref);
  933. a_loadfpu_reg_ref(list,fromsize,fromsize,r,ref);
  934. a_loadfpu_ref_cgpara(list,fromsize,ref,cgpara);
  935. tg.Ungettemp(list,ref);
  936. end;
  937. else
  938. internalerror(2010120422);
  939. end;
  940. end;
  941. procedure thlcgobj.a_loadfpu_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara);
  942. var
  943. href : treference;
  944. // hsize: tcgsize;
  945. begin
  946. case cgpara.location^.loc of
  947. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  948. begin
  949. cgpara.check_simple_location;
  950. paramanager.alloccgpara(list,cgpara);
  951. a_loadfpu_ref_reg(list,fromsize,cgpara.def,ref,cgpara.location^.register);
  952. end;
  953. LOC_REFERENCE,LOC_CREFERENCE:
  954. begin
  955. cgpara.check_simple_location;
  956. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  957. { concatcopy should choose the best way to copy the data }
  958. g_concatcopy(list,fromsize,ref,href);
  959. end;
  960. (* not yet supported
  961. LOC_REGISTER,LOC_CREGISTER:
  962. begin
  963. { force integer size }
  964. hsize:=int_cgsize(tcgsize2size[size]);
  965. {$ifndef cpu64bitalu}
  966. if (hsize in [OS_S64,OS_64]) then
  967. cg64.a_load64_ref_cgpara(list,ref,cgpara)
  968. else
  969. {$endif not cpu64bitalu}
  970. begin
  971. cgpara.check_simple_location;
  972. a_load_ref_cgpara(list,hsize,ref,cgpara)
  973. end;
  974. end
  975. *)
  976. else
  977. internalerror(2010120423);
  978. end;
  979. end;
  980. (*
  981. procedure thlcgobj.a_loadmm_reg_reg(list: TAsmList; fromsize, tosize: tdef; reg1, reg2: tregister; shuffle: pmmshuffle);
  982. begin
  983. cg.a_loadmm_reg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),reg1,reg2,shuffle);
  984. end;
  985. procedure thlcgobj.a_loadmm_ref_reg(list: TAsmList; fromsize, tosize: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  986. begin
  987. cg.a_loadmm_ref_reg(list,def_cgsize(fromsize),def_cgsize(tosize),ref,reg,shuffle);
  988. end;
  989. procedure thlcgobj.a_loadmm_reg_ref(list: TAsmList; fromsize, tosize: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  990. begin
  991. cg.a_loadmm_reg_ref(list,def_cgsize(fromsize),def_cgsize(tosize),reg,ref,shuffle);
  992. end;
  993. procedure thlcgobj.a_loadmm_loc_reg(list: TAsmList; fromsize, tosize: tdef; const loc: tlocation; const reg: tregister; shuffle: pmmshuffle);
  994. begin
  995. case loc.loc of
  996. LOC_MMREGISTER,LOC_CMMREGISTER:
  997. a_loadmm_reg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  998. LOC_REFERENCE,LOC_CREFERENCE:
  999. a_loadmm_ref_reg(list,fromsize,tosize,loc.reference,reg,shuffle);
  1000. LOC_REGISTER,LOC_CREGISTER:
  1001. a_loadmm_intreg_reg(list,fromsize,tosize,loc.register,reg,shuffle);
  1002. else
  1003. internalerror(2010120414);
  1004. end;
  1005. end;
  1006. procedure thlcgobj.a_loadmm_reg_loc(list: TAsmList; fromsize, tosize: tdef; const reg: tregister; const loc: tlocation; shuffle: pmmshuffle);
  1007. begin
  1008. case loc.loc of
  1009. LOC_MMREGISTER,LOC_CMMREGISTER:
  1010. a_loadmm_reg_reg(list,fromsize,tosize,reg,loc.register,shuffle);
  1011. LOC_REFERENCE,LOC_CREFERENCE:
  1012. a_loadmm_reg_ref(list,fromsize,tosize,reg,loc.reference,shuffle);
  1013. else
  1014. internalerror(2010120415);
  1015. end;
  1016. end;
  1017. procedure thlcgobj.a_loadmm_reg_cgpara(list: TAsmList; fromsize: tdef; reg: tregister; const cgpara: TCGPara; shuffle: pmmshuffle);
  1018. var
  1019. href : treference;
  1020. begin
  1021. cgpara.check_simple_location;
  1022. paramanager.alloccgpara(list,cgpara);
  1023. case cgpara.location^.loc of
  1024. LOC_MMREGISTER,LOC_CMMREGISTER:
  1025. a_loadmm_reg_reg(list,fromsize,cgpara.def,reg,cgpara.location^.register,shuffle);
  1026. LOC_REFERENCE,LOC_CREFERENCE:
  1027. begin
  1028. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset,cgpara.alignment);
  1029. a_loadmm_reg_ref(list,fromsize,cgpara.def,reg,href,shuffle);
  1030. end;
  1031. LOC_REGISTER,LOC_CREGISTER:
  1032. begin
  1033. if assigned(shuffle) and
  1034. not shufflescalar(shuffle) then
  1035. internalerror(2009112510);
  1036. a_loadmm_reg_intreg(list,deomsize,cgpara.def,reg,cgpara.location^.register,mms_movescalar);
  1037. end
  1038. else
  1039. internalerror(2010120427);
  1040. end;
  1041. end;
  1042. procedure thlcgobj.a_loadmm_ref_cgpara(list: TAsmList; fromsize: tdef; const ref: treference; const cgpara: TCGPara; shuffle: pmmshuffle);
  1043. var
  1044. hr : tregister;
  1045. hs : tmmshuffle;
  1046. begin
  1047. cgpara.check_simple_location;
  1048. hr:=cg.getmmregister(list,cgpara.size);
  1049. a_loadmm_ref_reg(list,deomsize,cgpara.def,ref,hr,shuffle);
  1050. if realshuffle(shuffle) then
  1051. begin
  1052. hs:=shuffle^;
  1053. removeshuffles(hs);
  1054. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,@hs);
  1055. end
  1056. else
  1057. a_loadmm_reg_cgpara(list,cgpara.def,hr,cgpara,shuffle);
  1058. end;
  1059. procedure thlcgobj.a_loadmm_loc_cgpara(list: TAsmList; fromsize: tdef; const loc: tlocation; const cgpara: TCGPara; shuffle: pmmshuffle);
  1060. begin
  1061. {$ifdef extdebug}
  1062. if def_cgsize(fromsize)<>loc.size then
  1063. internalerror(2010112105);
  1064. {$endif}
  1065. cg.a_loadmm_loc_cgpara(list,loc,cgpara,shuffle);
  1066. end;
  1067. procedure thlcgobj.a_opmm_reg_reg(list: TAsmList; Op: TOpCG; size: tdef; src, dst: tregister; shuffle: pmmshuffle);
  1068. begin
  1069. cg.a_opmm_reg_reg(list,op,def_cgsize(size),src,dst,shuffle);
  1070. end;
  1071. procedure thlcgobj.a_opmm_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: treference; reg: tregister; shuffle: pmmshuffle);
  1072. begin
  1073. cg.a_opmm_ref_reg(list,op,def_cgsize(size),ref,reg,shuffle)
  1074. end;
  1075. procedure thlcgobj.a_opmm_loc_reg(list: TAsmList; Op: TOpCG; size: tdef; const loc: tlocation; reg: tregister; shuffle: pmmshuffle);
  1076. begin
  1077. cg.a_opmm_loc_reg(list,op,def_cgsize(size),loc,reg,shuffle);
  1078. end;
  1079. procedure thlcgobj.a_opmm_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const ref: treference; shuffle: pmmshuffle);
  1080. begin
  1081. cg.a_opmm_reg_ref(list,op,def_cgsize(size),reg,ref,shuffle);
  1082. end;
  1083. *)
  1084. (*
  1085. procedure thlcgobj.a_loadmm_intreg_reg(list: TAsmList; fromsize, tosize: tdef; intreg, mmreg: tregister; shuffle: pmmshuffle);
  1086. begin
  1087. cg.a_loadmm_intreg_reg(list,def_cgsize(fromsize),def_cgsize(tosize),intreg,mmreg,shuffle);
  1088. end;
  1089. procedure thlcgobj.a_loadmm_reg_intreg(list: TAsmList; fromsize, tosize: tdef; mmreg, intreg: tregister; shuffle: pmmshuffle);
  1090. begin
  1091. cg.a_loadmm_reg_intreg(list,def_cgsize(fromsize),def_cgsize(tosize),mmreg,intreg,shuffle);
  1092. end;
  1093. *)
  1094. procedure thlcgobj.a_op_const_ref(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const ref: TReference);
  1095. var
  1096. tmpreg : tregister;
  1097. begin
  1098. tmpreg:=getintregister(list,size);
  1099. a_load_ref_reg(list,size,size,ref,tmpreg);
  1100. a_op_const_reg(list,op,size,a,tmpreg);
  1101. a_load_reg_ref(list,size,size,tmpreg,ref);
  1102. end;
  1103. procedure thlcgobj.a_op_const_subsetreg(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sreg: tsubsetregister);
  1104. var
  1105. tmpreg: tregister;
  1106. begin
  1107. tmpreg:=getintregister(list,size);
  1108. a_load_subsetreg_reg(list,size,subsetsize,size,sreg,tmpreg);
  1109. a_op_const_reg(list,op,size,a,tmpreg);
  1110. a_load_reg_subsetreg(list,size,size,subsetsize,tmpreg,sreg);
  1111. end;
  1112. procedure thlcgobj.a_op_const_subsetref(list: TAsmList; Op: TOpCG; size, subsetsize: tdef; a: aint; const sref: tsubsetreference);
  1113. var
  1114. tmpreg: tregister;
  1115. begin
  1116. tmpreg:=getintregister(list,size);
  1117. a_load_subsetref_reg(list,size,subsetsize,size,sref,tmpreg);
  1118. a_op_const_reg(list,op,size,a,tmpreg);
  1119. a_load_reg_subsetref(list,size,size,subsetsize,tmpreg,sref);
  1120. end;
  1121. procedure thlcgobj.a_op_const_loc(list: TAsmList; Op: TOpCG; size: tdef; a: Aint; const loc: tlocation);
  1122. begin
  1123. case loc.loc of
  1124. LOC_REGISTER, LOC_CREGISTER:
  1125. a_op_const_reg(list,op,size,a,loc.register);
  1126. LOC_REFERENCE, LOC_CREFERENCE:
  1127. a_op_const_ref(list,op,size,a,loc.reference);
  1128. { we don't have enough type information to handle these here
  1129. LOC_SUBSETREG, LOC_CSUBSETREG:
  1130. a_op_const_subsetreg(list,op,loc.size,loc.size,a,loc.sreg);
  1131. LOC_SUBSETREF, LOC_CSUBSETREF:
  1132. a_op_const_subsetref(list,op,loc.size,loc.size,a,loc.sref);
  1133. }
  1134. else
  1135. internalerror(2010120428);
  1136. end;
  1137. end;
  1138. procedure thlcgobj.a_op_reg_ref(list: TAsmList; Op: TOpCG; size: tdef; reg: TRegister; const ref: TReference);
  1139. var
  1140. tmpreg: tregister;
  1141. begin
  1142. case op of
  1143. OP_NOT,OP_NEG:
  1144. { handle it as "load ref,reg; op reg" }
  1145. begin
  1146. a_load_ref_reg(list,size,size,ref,reg);
  1147. a_op_reg_reg(list,op,size,reg,reg);
  1148. end;
  1149. else
  1150. begin
  1151. tmpreg:=getintregister(list,size);
  1152. a_load_ref_reg(list,size,size,ref,tmpreg);
  1153. a_op_reg_reg(list,op,size,tmpreg,reg);
  1154. end;
  1155. end;
  1156. end;
  1157. procedure thlcgobj.a_op_ref_reg(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; reg: TRegister);
  1158. var
  1159. tmpreg: tregister;
  1160. begin
  1161. case op of
  1162. OP_NOT,OP_NEG:
  1163. { handle it as "load ref,reg; op reg" }
  1164. begin
  1165. a_load_ref_reg(list,size,size,ref,reg);
  1166. a_op_reg_reg(list,op,size,reg,reg);
  1167. end;
  1168. else
  1169. begin
  1170. tmpreg:=getintregister(list,size);
  1171. a_load_ref_reg(list,size,size,ref,tmpreg);
  1172. a_op_reg_reg(list,op,size,tmpreg,reg);
  1173. end;
  1174. end;
  1175. end;
  1176. procedure thlcgobj.a_op_reg_subsetreg(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sreg: tsubsetregister);
  1177. var
  1178. tmpreg: tregister;
  1179. begin
  1180. tmpreg:=getintregister(list,opsize);
  1181. a_load_subsetreg_reg(list,destsize,destsubsetsize,opsize,sreg,tmpreg);
  1182. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1183. a_load_reg_subsetreg(list,opsize,destsize,destsubsetsize,tmpreg,sreg);
  1184. end;
  1185. procedure thlcgobj.a_op_reg_subsetref(list: TAsmList; Op: TOpCG; opsize, destsize, destsubsetsize: tdef; reg: TRegister; const sref: tsubsetreference);
  1186. var
  1187. tmpreg: tregister;
  1188. begin
  1189. tmpreg:=getintregister(list,opsize);
  1190. a_load_subsetref_reg(list,destsize,destsubsetsize,opsize,sref,tmpreg);
  1191. a_op_reg_reg(list,op,opsize,reg,tmpreg);
  1192. a_load_reg_subsetref(list,opsize,destsize,destsubsetsize,tmpreg,sref);
  1193. end;
  1194. procedure thlcgobj.a_op_reg_loc(list: TAsmList; Op: TOpCG; size: tdef; reg: tregister; const loc: tlocation);
  1195. begin
  1196. case loc.loc of
  1197. LOC_REGISTER, LOC_CREGISTER:
  1198. a_op_reg_reg(list,op,size,reg,loc.register);
  1199. LOC_REFERENCE, LOC_CREFERENCE:
  1200. a_op_reg_ref(list,op,size,reg,loc.reference);
  1201. { we don't have enough type information to handle these here
  1202. LOC_SUBSETREG, LOC_CSUBSETREG:
  1203. a_op_reg_subsetreg(list,op,loc.size,loc.size,reg,loc.sreg);
  1204. LOC_SUBSETREF, LOC_CSUBSETREF:
  1205. a_op_reg_subsetref(list,op,loc.size,loc.size,reg,loc.sref);
  1206. }
  1207. else
  1208. internalerror(2010120429);
  1209. end;
  1210. end;
  1211. procedure thlcgobj.a_op_ref_loc(list: TAsmList; Op: TOpCG; size: tdef; const ref: TReference; const loc: tlocation);
  1212. var
  1213. tmpreg: tregister;
  1214. begin
  1215. case loc.loc of
  1216. LOC_REGISTER,LOC_CREGISTER:
  1217. a_op_ref_reg(list,op,size,ref,loc.register);
  1218. LOC_REFERENCE,LOC_CREFERENCE:
  1219. begin
  1220. tmpreg:=getintregister(list,size);
  1221. a_load_ref_reg(list,size,size,ref,tmpreg);
  1222. a_op_reg_ref(list,op,size,tmpreg,loc.reference);
  1223. end;
  1224. { we don't have enough type information to handle these here
  1225. LOC_SUBSETREG, LOC_CSUBSETREG:
  1226. begin
  1227. tmpreg:=getintregister(list,loc.size);
  1228. a_load_subsetreg_reg(list,loc.size,loc.size,loc.sreg,tmpreg);
  1229. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1230. a_load_reg_subsetreg(list,loc.size,loc.size,tmpreg,loc.sreg);
  1231. end;
  1232. LOC_SUBSETREF, LOC_CSUBSETREF:
  1233. begin
  1234. tmpreg:=getintregister(list,loc.size);
  1235. a_load_subsetreF_reg(list,loc.size,loc.size,loc.sref,tmpreg);
  1236. a_op_ref_reg(list,op,loc.size,ref,tmpreg);
  1237. a_load_reg_subsetref(list,loc.size,loc.size,tmpreg,loc.sref);
  1238. end;
  1239. }
  1240. else
  1241. internalerror(2010120429);
  1242. end;
  1243. end;
  1244. procedure thlcgobj.a_op_const_reg_reg(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister);
  1245. begin
  1246. a_load_reg_reg(list,size,size,src,dst);
  1247. a_op_const_reg(list,op,size,a,dst);
  1248. end;
  1249. procedure thlcgobj.a_op_reg_reg_reg(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister);
  1250. var
  1251. tmpreg: tregister;
  1252. begin
  1253. if (dst<>src1) then
  1254. begin
  1255. a_load_reg_reg(list,size,size,src2,dst);
  1256. a_op_reg_reg(list,op,size,src1,dst);
  1257. end
  1258. else
  1259. begin
  1260. { can we do a direct operation on the target register ? }
  1261. if op in [OP_ADD,OP_MUL,OP_AND,OP_MOVE,OP_XOR,OP_IMUL,OP_OR] then
  1262. a_op_reg_reg(list,op,size,src2,dst)
  1263. else
  1264. begin
  1265. tmpreg:=getintregister(list,size);
  1266. a_load_reg_reg(list,size,size,src2,tmpreg);
  1267. a_op_reg_reg(list,op,size,src1,tmpreg);
  1268. a_load_reg_reg(list,size,size,tmpreg,dst);
  1269. end;
  1270. end;
  1271. end;
  1272. procedure thlcgobj.a_op_const_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; a: aint; src, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1273. begin
  1274. if not setflags then
  1275. a_op_const_reg_reg(list,op,size,a,src,dst)
  1276. else
  1277. internalerror(2010122910);
  1278. end;
  1279. procedure thlcgobj.a_op_reg_reg_reg_checkoverflow(list: TAsmList; op: TOpCg; size: tdef; src1, src2, dst: tregister; setflags: boolean; var ovloc: tlocation);
  1280. begin
  1281. if not setflags then
  1282. a_op_reg_reg_reg(list,op,size,src1,src2,dst)
  1283. else
  1284. internalerror(2010122911);
  1285. end;
  1286. procedure thlcgobj.a_cmp_const_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; reg: tregister; l: tasmlabel);
  1287. var
  1288. tmpreg: tregister;
  1289. begin
  1290. tmpreg:=getintregister(list,size);
  1291. a_load_const_reg(list,size,a,tmpreg);
  1292. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1293. end;
  1294. procedure thlcgobj.a_cmp_const_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const ref: treference; l: tasmlabel);
  1295. var
  1296. tmpreg: tregister;
  1297. begin
  1298. tmpreg:=getintregister(list,size);
  1299. a_load_ref_reg(list,size,size,ref,tmpreg);
  1300. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1301. end;
  1302. procedure thlcgobj.a_cmp_const_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; a: aint; const loc: tlocation; l: tasmlabel);
  1303. begin
  1304. case loc.loc of
  1305. LOC_REGISTER,LOC_CREGISTER:
  1306. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1307. LOC_REFERENCE,LOC_CREFERENCE:
  1308. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1309. { we don't have enough type information to handle these here
  1310. LOC_SUBSETREG, LOC_CSUBSETREG:
  1311. begin
  1312. tmpreg:=getintregister(list,size);
  1313. a_load_subsetreg_reg(list,loc.size,size,loc.sreg,tmpreg);
  1314. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1315. end;
  1316. LOC_SUBSETREF, LOC_CSUBSETREF:
  1317. begin
  1318. tmpreg:=getintregister(list,size);
  1319. a_load_subsetref_reg(list,loc.size,size,loc.sref,tmpreg);
  1320. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1321. end;
  1322. }
  1323. else
  1324. internalerror(2010120430);
  1325. end;
  1326. end;
  1327. procedure thlcgobj.a_cmp_ref_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; reg: tregister; l: tasmlabel);
  1328. var
  1329. tmpreg: tregister;
  1330. begin
  1331. tmpreg:=getintregister(list,size);
  1332. a_load_ref_reg(list,size,size,ref,tmpreg);
  1333. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1334. end;
  1335. procedure thlcgobj.a_cmp_reg_ref_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const ref: treference; l: tasmlabel);
  1336. var
  1337. tmpreg: tregister;
  1338. begin
  1339. tmpreg:=getintregister(list,size);
  1340. a_load_ref_reg(list,size,size,ref,tmpreg);
  1341. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1342. end;
  1343. procedure thlcgobj.a_cmp_subsetreg_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sreg: tsubsetregister; reg: tregister; l: tasmlabel);
  1344. var
  1345. tmpreg: tregister;
  1346. begin
  1347. tmpreg:=getintregister(list,cmpsize);
  1348. a_load_subsetreg_reg(list,fromsize,fromsubsetsize,cmpsize,sreg,tmpreg);
  1349. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1350. end;
  1351. procedure thlcgobj.a_cmp_subsetref_reg_label(list: TAsmList; fromsize, fromsubsetsize, cmpsize: tdef; cmp_op: topcmp; const sref: tsubsetreference; reg: tregister; l: tasmlabel);
  1352. var
  1353. tmpreg: tregister;
  1354. begin
  1355. tmpreg:=getintregister(list,cmpsize);
  1356. a_load_subsetref_reg(list,fromsize,fromsubsetsize,cmpsize,sref,tmpreg);
  1357. a_cmp_reg_reg_label(list,cmpsize,cmp_op,tmpreg,reg,l);
  1358. end;
  1359. procedure thlcgobj.a_cmp_loc_reg_label(list: TAsmList; size: tdef; cmp_op: topcmp; const loc: tlocation; reg: tregister; l: tasmlabel);
  1360. begin
  1361. case loc.loc of
  1362. LOC_REGISTER,
  1363. LOC_CREGISTER:
  1364. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1365. LOC_REFERENCE,
  1366. LOC_CREFERENCE :
  1367. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1368. LOC_CONSTANT:
  1369. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1370. { we don't have enough type information to handle these here
  1371. LOC_SUBSETREG,
  1372. LOC_CSUBSETREG:
  1373. a_cmp_subsetreg_reg_label(list,loc.size,size,cmp_op,loc.sreg,reg,l);
  1374. LOC_SUBSETREF,
  1375. LOC_CSUBSETREF:
  1376. a_cmp_subsetref_reg_label(list,loc.size,size,cmp_op,loc.sref,reg,l);
  1377. }
  1378. else
  1379. internalerror(2010120431);
  1380. end;
  1381. end;
  1382. procedure thlcgobj.a_cmp_reg_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; reg: tregister; const loc: tlocation; l: tasmlabel);
  1383. begin
  1384. a_cmp_loc_reg_label(list,size,swap_opcmp(cmp_op),loc,reg,l);
  1385. end;
  1386. procedure thlcgobj.a_cmp_ref_loc_label(list: TAsmList; size: tdef; cmp_op: topcmp; const ref: treference; const loc: tlocation; l: tasmlabel);
  1387. var
  1388. tmpreg: tregister;
  1389. begin
  1390. case loc.loc of
  1391. LOC_REGISTER,LOC_CREGISTER:
  1392. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1393. LOC_REFERENCE,LOC_CREFERENCE:
  1394. begin
  1395. tmpreg:=getintregister(list,size);
  1396. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1397. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1398. end;
  1399. LOC_CONSTANT:
  1400. begin
  1401. a_cmp_const_ref_label(list,size,swap_opcmp(cmp_op),loc.value,ref,l);
  1402. end
  1403. { we don't have enough type information to handle these here
  1404. LOC_SUBSETREG, LOC_CSUBSETREG:
  1405. begin
  1406. tmpreg:=getintregister(list, size);
  1407. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1408. a_cmp_subsetreg_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sreg,tmpreg,l);
  1409. end;
  1410. LOC_SUBSETREF, LOC_CSUBSETREF:
  1411. begin
  1412. tmpreg:=getintregister(list, size);
  1413. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1414. a_cmp_subsetref_reg_label(list,loc.size,size,swap_opcmp(cmp_op),loc.sref,tmpreg,l);
  1415. end;
  1416. }
  1417. else
  1418. internalerror(2010120432);
  1419. end;
  1420. end;
  1421. procedure thlcgobj.g_concatcopy(list: TAsmList; size: tdef; const source, dest: treference);
  1422. begin
  1423. {
  1424. if use_vectorfpu(size) then
  1425. a_loadmm_ref_ref()
  1426. else
  1427. }
  1428. if size.typ<>floatdef then
  1429. a_load_ref_ref(list,size,size,source,dest)
  1430. else
  1431. a_loadfpu_ref_ref(list,size,size,source,dest);
  1432. end;
  1433. procedure thlcgobj.g_concatcopy_unaligned(list: TAsmList; size: tdef; const source, dest: treference);
  1434. begin
  1435. g_concatcopy(list,size,source,dest);
  1436. end;
  1437. procedure thlcgobj.g_rangecheck(list: TAsmList; const l: tlocation; fromdef, todef: tdef);
  1438. begin
  1439. if not(cs_check_range in current_settings.localswitches) then
  1440. exit;
  1441. internalerror(2011010610);
  1442. end;
  1443. procedure thlcgobj.g_profilecode(list: TAsmList);
  1444. begin
  1445. end;
  1446. procedure thlcgobj.location_force_reg(list: TAsmList; var l: tlocation; src_size, dst_size: tdef; maybeconst: boolean);
  1447. var
  1448. hregister,
  1449. hregister2: tregister;
  1450. hl : tasmlabel;
  1451. oldloc : tlocation;
  1452. begin
  1453. oldloc:=l;
  1454. hregister:=getregisterfordef(list,dst_size);
  1455. { load value in new register }
  1456. case l.loc of
  1457. {$ifdef cpuflags}
  1458. LOC_FLAGS :
  1459. cg.g_flags2reg(list,def_cgsize(dst_size),l.resflags,hregister);
  1460. {$endif cpuflags}
  1461. LOC_JUMP :
  1462. begin
  1463. a_label(list,current_procinfo.CurrTrueLabel);
  1464. a_load_const_reg(list,dst_size,1,hregister);
  1465. current_asmdata.getjumplabel(hl);
  1466. a_jmp_always(list,hl);
  1467. a_label(list,current_procinfo.CurrFalseLabel);
  1468. a_load_const_reg(list,dst_size,0,hregister);
  1469. a_label(list,hl);
  1470. end;
  1471. else
  1472. begin
  1473. { load_loc_reg can only handle size >= l.size, when the
  1474. new size is smaller then we need to adjust the size
  1475. of the orignal and maybe recalculate l.register for i386 }
  1476. if (dst_size.size<src_size.size) then
  1477. begin
  1478. hregister2:=getregisterfordef(list,src_size);
  1479. { prevent problems with memory locations -- at this high
  1480. level we cannot twiddle with the reference offset, since
  1481. that may not mean anything (e.g., it refers to fixed-sized
  1482. stack slots on Java) }
  1483. a_load_loc_reg(list,src_size,src_size,l,hregister2);
  1484. a_load_reg_reg(list,src_size,dst_size,hregister2,hregister);
  1485. end
  1486. else
  1487. a_load_loc_reg(list,src_size,dst_size,l,hregister);
  1488. end;
  1489. end;
  1490. if (l.loc <> LOC_CREGISTER) or
  1491. not maybeconst then
  1492. location_reset(l,LOC_REGISTER,def_cgsize(dst_size))
  1493. else
  1494. location_reset(l,LOC_CREGISTER,def_cgsize(dst_size));
  1495. l.register:=hregister;
  1496. { Release temp if it was a reference }
  1497. if oldloc.loc=LOC_REFERENCE then
  1498. location_freetemp(list,oldloc);
  1499. end;
  1500. procedure thlcgobj.location_force_fpureg(list: TAsmList; var l: tlocation; size: tdef; maybeconst: boolean);
  1501. var
  1502. reg : tregister;
  1503. begin
  1504. if (l.loc<>LOC_FPUREGISTER) and
  1505. ((l.loc<>LOC_CFPUREGISTER) or (not maybeconst)) then
  1506. begin
  1507. { if it's in an mm register, store to memory first }
  1508. if (l.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  1509. internalerror(2011012903);
  1510. reg:=getfpuregister(list,size);
  1511. a_loadfpu_loc_reg(list,size,size,l,reg);
  1512. location_freetemp(list,l);
  1513. location_reset(l,LOC_FPUREGISTER,l.size);
  1514. l.register:=reg;
  1515. end;
  1516. end;
  1517. procedure thlcgobj.location_force_mem(list: TAsmList; var l: tlocation; size: tdef);
  1518. var
  1519. r : treference;
  1520. begin
  1521. case l.loc of
  1522. LOC_FPUREGISTER,
  1523. LOC_CFPUREGISTER :
  1524. begin
  1525. tg.gethltemp(list,size,size.size,tt_normal,r);
  1526. hlcg.a_loadfpu_reg_ref(list,size,size,l.register,r);
  1527. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1528. l.reference:=r;
  1529. end;
  1530. (*
  1531. LOC_MMREGISTER,
  1532. LOC_CMMREGISTER:
  1533. begin
  1534. tg.gethltemp(list,size,size.size,tt_normal,r);
  1535. cg.a_loadmm_reg_ref(list,l.size,l.size,l.register,r,mms_movescalar);
  1536. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1537. l.reference:=r;
  1538. end;
  1539. *)
  1540. LOC_CONSTANT,
  1541. LOC_REGISTER,
  1542. LOC_CREGISTER :
  1543. begin
  1544. tg.gethltemp(list,size,size.size,tt_normal,r);
  1545. hlcg.a_load_loc_ref(list,size,size,l,r);
  1546. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1547. l.reference:=r;
  1548. end;
  1549. (*
  1550. LOC_SUBSETREG,
  1551. LOC_CSUBSETREG,
  1552. LOC_SUBSETREF,
  1553. LOC_CSUBSETREF:
  1554. begin
  1555. tg.gethltemp(list,size,size.size,tt_normal,r);
  1556. cg.a_load_loc_ref(list,l.size,l,r);
  1557. location_reset_ref(l,LOC_REFERENCE,l.size,0);
  1558. l.reference:=r;
  1559. end;
  1560. *)
  1561. LOC_CREFERENCE,
  1562. LOC_REFERENCE : ;
  1563. else
  1564. internalerror(2011010304);
  1565. end;
  1566. end;
  1567. procedure thlcgobj.location_get_data_ref(list: TAsmList; def: tdef; const l: tlocation; var ref: treference; loadref: boolean; alignment: longint);
  1568. begin
  1569. case l.loc of
  1570. LOC_REGISTER,
  1571. LOC_CREGISTER :
  1572. begin
  1573. if not loadref then
  1574. internalerror(200410231);
  1575. reference_reset_base(ref,l.register,0,alignment);
  1576. end;
  1577. LOC_REFERENCE,
  1578. LOC_CREFERENCE :
  1579. begin
  1580. if loadref then
  1581. begin
  1582. reference_reset_base(ref,cg.getaddressregister(list),0,alignment);
  1583. { it's a pointer to def }
  1584. hlcg.a_load_ref_reg(list,voidpointertype,voidpointertype,l.reference,ref.base);
  1585. end
  1586. else
  1587. ref:=l.reference;
  1588. end;
  1589. else
  1590. internalerror(200309181);
  1591. end;
  1592. end;
  1593. procedure thlcgobj.maketojumpbool(list: TAsmList; p: tnode);
  1594. {
  1595. produces jumps to true respectively false labels using boolean expressions
  1596. depending on whether the loading of regvars is currently being
  1597. synchronized manually (such as in an if-node) or automatically (most of
  1598. the other cases where this procedure is called), loadregvars can be
  1599. "lr_load_regvars" or "lr_dont_load_regvars"
  1600. }
  1601. var
  1602. storepos : tfileposinfo;
  1603. begin
  1604. if nf_error in p.flags then
  1605. exit;
  1606. storepos:=current_filepos;
  1607. current_filepos:=p.fileinfo;
  1608. if is_boolean(p.resultdef) then
  1609. begin
  1610. if is_constboolnode(p) then
  1611. begin
  1612. if Tordconstnode(p).value.uvalue<>0 then
  1613. a_jmp_always(list,current_procinfo.CurrTrueLabel)
  1614. else
  1615. a_jmp_always(list,current_procinfo.CurrFalseLabel)
  1616. end
  1617. else
  1618. begin
  1619. case p.location.loc of
  1620. (*
  1621. LOC_SUBSETREG,LOC_CSUBSETREG,
  1622. LOC_SUBSETREF,LOC_CSUBSETREF:
  1623. begin
  1624. tmpreg := cg.getintregister(list,OS_INT);
  1625. cg.a_load_loc_reg(list,OS_INT,p.location,tmpreg);
  1626. cg.a_cmp_const_reg_label(list,OS_INT,OC_NE,0,tmpreg,current_procinfo.CurrTrueLabel);
  1627. cg.a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1628. end;
  1629. *)
  1630. LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE :
  1631. begin
  1632. a_cmp_const_loc_label(list,p.resultdef,OC_NE,0,p.location,current_procinfo.CurrTrueLabel);
  1633. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1634. end;
  1635. LOC_JUMP:
  1636. ;
  1637. {$ifdef cpuflags}
  1638. LOC_FLAGS :
  1639. begin
  1640. a_jmp_flags(list,p.location.resflags,current_procinfo.CurrTrueLabel);
  1641. a_jmp_always(list,current_procinfo.CurrFalseLabel);
  1642. end;
  1643. {$endif cpuflags}
  1644. else
  1645. begin
  1646. printnode(output,p);
  1647. internalerror(2011010418);
  1648. end;
  1649. end;
  1650. end;
  1651. end
  1652. else
  1653. internalerror(2011010419);
  1654. current_filepos:=storepos;
  1655. end;
  1656. procedure thlcgobj.gen_proc_symbol(list: TAsmList);
  1657. var
  1658. item,
  1659. previtem : TCmdStrListItem;
  1660. begin
  1661. previtem:=nil;
  1662. item := TCmdStrListItem(current_procinfo.procdef.aliasnames.first);
  1663. while assigned(item) do
  1664. begin
  1665. {$ifdef arm}
  1666. if current_settings.cputype in cpu_thumb2 then
  1667. list.concat(tai_thumb_func.create);
  1668. {$endif arm}
  1669. { "double link" all procedure entry symbols via .reference }
  1670. { directives on darwin, because otherwise the linker }
  1671. { sometimes strips the procedure if only on of the symbols }
  1672. { is referenced }
  1673. if assigned(previtem) and
  1674. (target_info.system in systems_darwin) then
  1675. list.concat(tai_directive.create(asd_reference,item.str));
  1676. if (cs_profile in current_settings.moduleswitches) or
  1677. (po_global in current_procinfo.procdef.procoptions) then
  1678. list.concat(Tai_symbol.createname_global(item.str,AT_FUNCTION,0))
  1679. else
  1680. list.concat(Tai_symbol.createname(item.str,AT_FUNCTION,0));
  1681. if assigned(previtem) and
  1682. (target_info.system in systems_darwin) then
  1683. list.concat(tai_directive.create(asd_reference,previtem.str));
  1684. if not(af_stabs_use_function_absolute_addresses in target_asm.flags) then
  1685. list.concat(Tai_function_name.create(item.str));
  1686. previtem:=item;
  1687. item := TCmdStrListItem(item.next);
  1688. end;
  1689. current_procinfo.procdef.procstarttai:=tai(list.last);
  1690. end;
  1691. procedure thlcgobj.gen_proc_symbol_end(list: TAsmList);
  1692. begin
  1693. list.concat(Tai_symbol_end.Createname(current_procinfo.procdef.mangledname));
  1694. current_procinfo.procdef.procendtai:=tai(list.last);
  1695. if (current_module.islibrary) then
  1696. if (current_procinfo.procdef.proctypeoption = potype_proginit) then
  1697. { setinitname may generate a new section -> don't add to the
  1698. current list, because we assume this remains a text section }
  1699. exportlib.setinitname(current_asmdata.AsmLists[al_exports],current_procinfo.procdef.mangledname);
  1700. if (current_procinfo.procdef.proctypeoption=potype_proginit) then
  1701. begin
  1702. if (target_info.system in (systems_darwin+[system_powerpc_macos])) and
  1703. not(current_module.islibrary) then
  1704. begin
  1705. new_section(list,sec_code,'',4);
  1706. list.concat(tai_symbol.createname_global(
  1707. target_info.cprefix+mainaliasname,AT_FUNCTION,0));
  1708. { keep argc, argv and envp properly on the stack }
  1709. cg.a_jmp_name(list,target_info.cprefix+'FPC_SYSTEMMAIN');
  1710. end;
  1711. end;
  1712. end;
  1713. { generates the code for incrementing the reference count of parameters and
  1714. initialize out parameters }
  1715. { generates the code for incrementing the reference count of parameters and
  1716. initialize out parameters }
  1717. procedure thlcgobj.init_paras(p:TObject;arg:pointer);
  1718. var
  1719. href : treference;
  1720. hsym : tparavarsym;
  1721. eldef : tdef;
  1722. list : TAsmList;
  1723. highloc : tlocation;
  1724. needs_inittable (*,
  1725. do_trashing *) : boolean;
  1726. begin
  1727. list:=TAsmList(arg);
  1728. if (tsym(p).typ=paravarsym) then
  1729. begin
  1730. needs_inittable:=is_managed_type(tparavarsym(p).vardef);
  1731. (*
  1732. do_trashing:=
  1733. (localvartrashing <> -1) and
  1734. (not assigned(tparavarsym(p).defaultconstsym)) and
  1735. not needs_inittable;
  1736. *)
  1737. case tparavarsym(p).varspez of
  1738. vs_value :
  1739. if needs_inittable then
  1740. begin
  1741. { variants are already handled by the call to fpc_variant_copy_overwrite if
  1742. they are passed by reference }
  1743. if not((tparavarsym(p).vardef.typ=variantdef) and
  1744. paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  1745. begin
  1746. location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,is_open_array(tparavarsym(p).vardef),sizeof(pint));
  1747. if is_open_array(tparavarsym(p).vardef) then
  1748. begin
  1749. if paramanager.push_high_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption) then
  1750. begin
  1751. hsym:=tparavarsym(tsym(p).owner.Find('high'+tsym(p).name));
  1752. if not assigned(hsym) then
  1753. internalerror(201003032);
  1754. highloc:=hsym.initialloc
  1755. end
  1756. else
  1757. highloc.loc:=LOC_INVALID;
  1758. { open arrays do not contain correct element count in their rtti,
  1759. the actual count must be passed separately. }
  1760. eldef:=tarraydef(tparavarsym(p).vardef).elementdef;
  1761. if not assigned(hsym) then
  1762. internalerror(201003031);
  1763. g_array_rtti_helper(list,eldef,href,highloc,'FPC_ADDREF_ARRAY');
  1764. end
  1765. else
  1766. g_incrrefcount(list,tparavarsym(p).vardef,href);
  1767. end;
  1768. end;
  1769. vs_out :
  1770. begin
  1771. if needs_inittable (*or
  1772. do_trashing*) then
  1773. begin
  1774. { we have no idea about the alignment at the callee side,
  1775. and the user also cannot specify "unaligned" here, so
  1776. assume worst case }
  1777. location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,true,1);
  1778. (*
  1779. if do_trashing and
  1780. { needs separate implementation to trash open arrays }
  1781. { since their size is only known at run time }
  1782. not is_special_array(tparavarsym(p).vardef) then
  1783. { may be an open string, even if is_open_string() returns }
  1784. { false (for some helpers in the system unit) }
  1785. if not is_shortstring(tparavarsym(p).vardef) then
  1786. trash_reference(list,href,tparavarsym(p).vardef.size)
  1787. else
  1788. trash_reference(list,href,2);
  1789. *)
  1790. if needs_inittable then
  1791. begin
  1792. if is_open_array(tparavarsym(p).vardef) then
  1793. begin
  1794. if paramanager.push_high_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption) then
  1795. begin
  1796. hsym:=tparavarsym(tsym(p).owner.Find('high'+tsym(p).name));
  1797. if not assigned(hsym) then
  1798. internalerror(201003032);
  1799. highloc:=hsym.initialloc
  1800. end
  1801. else
  1802. highloc.loc:=LOC_INVALID;
  1803. eldef:=tarraydef(tparavarsym(p).vardef).elementdef;
  1804. g_array_rtti_helper(list,eldef,href,highloc,'FPC_INITIALIZE_ARRAY');
  1805. end
  1806. else
  1807. g_initialize(list,tparavarsym(p).vardef,href);
  1808. end;
  1809. end;
  1810. end;
  1811. (*
  1812. else if do_trashing and
  1813. ([vo_is_funcret,vo_is_hidden_para] * tparavarsym(p).varoptions = [vo_is_funcret,vo_is_hidden_para]) then
  1814. begin
  1815. { should always have standard alignment. If a function is assigned
  1816. to a non-aligned variable, the optimisation to pass this variable
  1817. directly as hidden function result must/cannot be performed
  1818. (see tcallnode.funcret_can_be_reused)
  1819. }
  1820. location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,true,
  1821. used_align(tparavarsym(p).vardef.alignment,current_settings.alignment.localalignmin,current_settings.alignment.localalignmax));
  1822. { may be an open string, even if is_open_string() returns }
  1823. { false (for some helpers in the system unit) }
  1824. if not is_shortstring(tparavarsym(p).vardef) then
  1825. trash_reference(list,href,tparavarsym(p).vardef.size)
  1826. else
  1827. { an open string has at least size 2 }
  1828. trash_reference(list,href,2);
  1829. end
  1830. *)
  1831. end;
  1832. end;
  1833. end;
  1834. procedure thlcgobj.gen_load_para_value(list: TAsmList);
  1835. var
  1836. i: longint;
  1837. currpara: tparavarsym;
  1838. begin
  1839. if (po_assembler in current_procinfo.procdef.procoptions) then
  1840. exit;
  1841. { Copy parameters to local references/registers }
  1842. for i:=0 to current_procinfo.procdef.paras.count-1 do
  1843. begin
  1844. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  1845. gen_load_cgpara_loc(list,currpara.vardef,currpara.paraloc[calleeside],currpara.initialloc,paramanager.param_use_paraloc(currpara.paraloc[calleeside]));
  1846. end;
  1847. { generate copies of call by value parameters, must be done before
  1848. the initialization and body is parsed because the refcounts are
  1849. incremented using the local copies }
  1850. current_procinfo.procdef.parast.SymList.ForEachCall(@g_copyvalueparas,list);
  1851. if not(po_assembler in current_procinfo.procdef.procoptions) then
  1852. begin
  1853. { has to be done here rather than in gen_initialize_code, because
  1854. the initialisation code is generated a) later and b) with
  1855. rad_backwards, so the register allocator would generate
  1856. information as if this code comes before loading the parameters
  1857. from their original registers to their local location }
  1858. // if (localvartrashing <> -1) then
  1859. // current_procinfo.procdef.localst.SymList.ForEachCall(@trash_variable,list);
  1860. { initialize refcounted paras, and trash others. Needed here
  1861. instead of in gen_initialize_code, because when a reference is
  1862. intialised or trashed while the pointer to that reference is kept
  1863. in a regvar, we add a register move and that one again has to
  1864. come after the parameter loading code as far as the register
  1865. allocator is concerned }
  1866. current_procinfo.procdef.parast.SymList.ForEachCall(@init_paras,list);
  1867. end;
  1868. end;
  1869. procedure thlcgobj.g_copyvalueparas(p: TObject; arg: pointer);
  1870. var
  1871. href : treference;
  1872. hreg : tregister;
  1873. list : TAsmList;
  1874. hsym : tparavarsym;
  1875. l : longint;
  1876. highloc,
  1877. localcopyloc : tlocation;
  1878. begin
  1879. list:=TAsmList(arg);
  1880. if (tsym(p).typ=paravarsym) and
  1881. (tparavarsym(p).varspez=vs_value) and
  1882. (paramanager.push_addr_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption)) then
  1883. begin
  1884. { we have no idea about the alignment at the caller side }
  1885. location_get_data_ref(list,tparavarsym(p).vardef,tparavarsym(p).initialloc,href,true,1);
  1886. if is_open_array(tparavarsym(p).vardef) or
  1887. is_array_of_const(tparavarsym(p).vardef) then
  1888. begin
  1889. { cdecl functions don't have a high pointer so it is not possible to generate
  1890. a local copy }
  1891. if not(current_procinfo.procdef.proccalloption in cdecl_pocalls) then
  1892. begin
  1893. if paramanager.push_high_param(tparavarsym(p).varspez,tparavarsym(p).vardef,current_procinfo.procdef.proccalloption) then
  1894. begin
  1895. hsym:=tparavarsym(tsym(p).owner.Find('high'+tsym(p).name));
  1896. if not assigned(hsym) then
  1897. internalerror(2011020506);
  1898. highloc:=hsym.initialloc
  1899. end
  1900. else
  1901. highloc.loc:=LOC_INVALID;
  1902. hreg:=cg.getaddressregister(list);
  1903. if not is_packed_array(tparavarsym(p).vardef) then
  1904. g_copyvaluepara_openarray(list,href,highloc,tarraydef(tparavarsym(p).vardef),hreg)
  1905. else
  1906. internalerror(2011020507);
  1907. // cg.g_copyvaluepara_packedopenarray(list,href,hsym.intialloc,tarraydef(tparavarsym(p).vardef).elepackedbitsize,hreg);
  1908. a_load_reg_loc(list,tparavarsym(p).vardef,tparavarsym(p).vardef,hreg,tparavarsym(p).initialloc);
  1909. end;
  1910. end
  1911. else
  1912. begin
  1913. { Allocate space for the local copy }
  1914. l:=tparavarsym(p).getsize;
  1915. localcopyloc.loc:=LOC_REFERENCE;
  1916. localcopyloc.size:=int_cgsize(l);
  1917. tg.GetLocal(list,l,tparavarsym(p).vardef,localcopyloc.reference);
  1918. { Copy data }
  1919. if is_shortstring(tparavarsym(p).vardef) then
  1920. begin
  1921. { this code is only executed before the code for the body and the entry/exit code is generated
  1922. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  1923. }
  1924. include(current_procinfo.flags,pi_do_call);
  1925. g_copyshortstring(list,href,localcopyloc.reference,tstringdef(tparavarsym(p).vardef))
  1926. end
  1927. else if tparavarsym(p).vardef.typ=variantdef then
  1928. begin
  1929. { this code is only executed before the code for the body and the entry/exit code is generated
  1930. so we're allowed to include pi_do_call here; after pass1 is run, this isn't allowed anymore
  1931. }
  1932. include(current_procinfo.flags,pi_do_call);
  1933. g_copyvariant(list,href,localcopyloc.reference,tvariantdef(tparavarsym(p).vardef))
  1934. end
  1935. else
  1936. begin
  1937. { pass proper alignment info }
  1938. localcopyloc.reference.alignment:=tparavarsym(p).vardef.alignment;
  1939. g_concatcopy(list,tparavarsym(p).vardef,href,localcopyloc.reference);
  1940. end;
  1941. { update localloc of varsym }
  1942. tg.Ungetlocal(list,tparavarsym(p).localloc.reference);
  1943. tparavarsym(p).localloc:=localcopyloc;
  1944. tparavarsym(p).initialloc:=localcopyloc;
  1945. end;
  1946. end;
  1947. end;
  1948. procedure thlcgobj.gen_loadfpu_loc_cgpara(list: TAsmList; size: tdef; const l: tlocation; const cgpara: tcgpara; locintsize: longint);
  1949. begin
  1950. case l.loc of
  1951. (*
  1952. LOC_MMREGISTER,
  1953. LOC_CMMREGISTER:
  1954. case cgpara.location^.loc of
  1955. LOC_REFERENCE,
  1956. LOC_CREFERENCE,
  1957. LOC_MMREGISTER,
  1958. LOC_CMMREGISTER,
  1959. LOC_REGISTER,
  1960. LOC_CREGISTER :
  1961. cg.a_loadmm_reg_cgpara(list,locsize,l.register,cgpara,mms_movescalar);
  1962. LOC_FPUREGISTER,
  1963. LOC_CFPUREGISTER:
  1964. begin
  1965. tmploc:=l;
  1966. location_force_fpureg(list,tmploc,false);
  1967. cg.a_loadfpu_reg_cgpara(list,tmploc.size,tmploc.register,cgpara);
  1968. end;
  1969. else
  1970. internalerror(200204249);
  1971. end;
  1972. *)
  1973. LOC_FPUREGISTER,
  1974. LOC_CFPUREGISTER:
  1975. case cgpara.location^.loc of
  1976. (*
  1977. LOC_MMREGISTER,
  1978. LOC_CMMREGISTER:
  1979. begin
  1980. tmploc:=l;
  1981. location_force_mmregscalar(list,tmploc,false);
  1982. cg.a_loadmm_reg_cgpara(list,tmploc.size,tmploc.register,cgpara,mms_movescalar);
  1983. end;
  1984. *)
  1985. { Some targets pass floats in normal registers }
  1986. LOC_REGISTER,
  1987. LOC_CREGISTER,
  1988. LOC_REFERENCE,
  1989. LOC_CREFERENCE,
  1990. LOC_FPUREGISTER,
  1991. LOC_CFPUREGISTER:
  1992. hlcg.a_loadfpu_reg_cgpara(list,size,l.register,cgpara);
  1993. else
  1994. internalerror(2011010210);
  1995. end;
  1996. LOC_REFERENCE,
  1997. LOC_CREFERENCE:
  1998. case cgpara.location^.loc of
  1999. (*
  2000. LOC_MMREGISTER,
  2001. LOC_CMMREGISTER:
  2002. cg.a_loadmm_ref_cgpara(list,locsize,l.reference,cgpara,mms_movescalar);
  2003. *)
  2004. { Some targets pass floats in normal registers }
  2005. LOC_REGISTER,
  2006. LOC_CREGISTER,
  2007. LOC_REFERENCE,
  2008. LOC_CREFERENCE,
  2009. LOC_FPUREGISTER,
  2010. LOC_CFPUREGISTER:
  2011. hlcg.a_loadfpu_ref_cgpara(list,size,l.reference,cgpara);
  2012. else
  2013. internalerror(2011010211);
  2014. end;
  2015. LOC_REGISTER,
  2016. LOC_CREGISTER :
  2017. hlcg.a_load_loc_cgpara(list,size,l,cgpara);
  2018. else
  2019. internalerror(2011010212);
  2020. end;
  2021. end;
  2022. procedure thlcgobj.gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara);
  2023. begin
  2024. { do nothing by default }
  2025. end;
  2026. procedure thlcgobj.gen_load_loc_cgpara(list: TAsmList; vardef: tdef; const l: tlocation; const cgpara: tcgpara);
  2027. begin
  2028. { Handle Floating point types differently
  2029. This doesn't depend on emulator settings, emulator settings should
  2030. be handled by cpupara }
  2031. if (vardef.typ=floatdef) or
  2032. { some ABIs return certain records in an fpu register }
  2033. (l.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER]) or
  2034. (assigned(cgpara.location) and
  2035. (cgpara.Location^.loc in [LOC_FPUREGISTER,LOC_CFPUREGISTER])) then
  2036. begin
  2037. gen_loadfpu_loc_cgpara(list,vardef,l,cgpara,vardef.size);
  2038. exit;
  2039. end;
  2040. case l.loc of
  2041. LOC_CONSTANT,
  2042. LOC_REGISTER,
  2043. LOC_CREGISTER,
  2044. LOC_REFERENCE,
  2045. LOC_CREFERENCE :
  2046. begin
  2047. hlcg.a_load_loc_cgpara(list,vardef,l,cgpara);
  2048. end;
  2049. (*
  2050. LOC_MMREGISTER,
  2051. LOC_CMMREGISTER:
  2052. begin
  2053. case l.size of
  2054. OS_F32,
  2055. OS_F64:
  2056. cg.a_loadmm_loc_cgpara(list,l,cgpara,mms_movescalar);
  2057. else
  2058. cg.a_loadmm_loc_cgpara(list,l,cgpara,nil);
  2059. end;
  2060. end;
  2061. *)
  2062. else
  2063. internalerror(2011010213);
  2064. end;
  2065. end;
  2066. procedure thlcgobj.gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
  2067. var
  2068. href : treference;
  2069. begin
  2070. para.check_simple_location;
  2071. { skip e.g. empty records }
  2072. if (para.location^.loc = LOC_VOID) then
  2073. exit;
  2074. case destloc.loc of
  2075. LOC_REFERENCE :
  2076. begin
  2077. { If the parameter location is reused we don't need to copy
  2078. anything }
  2079. if not reusepara then
  2080. begin
  2081. reference_reset_base(href,para.location^.reference.index,para.location^.reference.offset,para.alignment);
  2082. a_load_ref_ref(list,para.def,para.def,href,destloc.reference);
  2083. end;
  2084. end;
  2085. { TODO other possible locations }
  2086. else
  2087. internalerror(2011010308);
  2088. end;
  2089. end;
  2090. procedure thlcgobj.gen_load_return_value(list: TAsmList);
  2091. var
  2092. ressym : tabstractnormalvarsym;
  2093. funcretloc : TCGPara;
  2094. begin
  2095. { Is the loading needed? }
  2096. if is_void(current_procinfo.procdef.returndef) or
  2097. (
  2098. (po_assembler in current_procinfo.procdef.procoptions) and
  2099. (not(assigned(current_procinfo.procdef.funcretsym)) or
  2100. (tabstractvarsym(current_procinfo.procdef.funcretsym).refs=0))
  2101. ) then
  2102. exit;
  2103. funcretloc:=current_procinfo.procdef.funcretloc[calleeside];
  2104. { constructors return self }
  2105. if (current_procinfo.procdef.proctypeoption=potype_constructor) then
  2106. ressym:=tabstractnormalvarsym(current_procinfo.procdef.parast.Find('self'))
  2107. else
  2108. ressym:=tabstractnormalvarsym(current_procinfo.procdef.funcretsym);
  2109. if (ressym.refs>0) or
  2110. is_managed_type(ressym.vardef) then
  2111. begin
  2112. { was: don't do anything if funcretloc.loc in [LOC_INVALID,LOC_REFERENCE] }
  2113. if not paramanager.ret_in_param(current_procinfo.procdef.returndef,current_procinfo.procdef.proccalloption) then
  2114. hlcg.gen_load_loc_cgpara(list,ressym.vardef,ressym.localloc,funcretloc);
  2115. end
  2116. else
  2117. gen_load_uninitialized_function_result(list,current_procinfo.procdef,ressym.vardef,funcretloc)
  2118. end;
  2119. procedure thlcgobj.record_generated_code_for_procdef(pd: tprocdef; code, data: TAsmList);
  2120. begin
  2121. { add the procedure to the al_procedures }
  2122. maybe_new_object_file(current_asmdata.asmlists[al_procedures]);
  2123. new_section(current_asmdata.asmlists[al_procedures],sec_code,lower(pd.mangledname),getprocalign);
  2124. current_asmdata.asmlists[al_procedures].concatlist(code);
  2125. { save local data (casetable) also in the same file }
  2126. if assigned(data) and
  2127. (not data.empty) then
  2128. current_asmdata.asmlists[al_procedures].concatlist(data);
  2129. end;
  2130. end.