hlcgobj.pas 101 KB

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