hlcgobj.pas 104 KB

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