cgobj.pas 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  1. {
  2. Copyright (c) 1998-2005 by Florian Klaempfl
  3. Member of the Free Pascal development team
  4. This unit implements the basic 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. Abstreact code generator unit. This contains the base class
  20. to implement for all new supported processors.
  21. WARNING: None of the routines implemented in these modules,
  22. or their descendants, should use the temp. allocator, as
  23. these routines may be called inside genentrycode, and the
  24. stack frame is already setup!
  25. }
  26. unit cgobj;
  27. {$i fpcdefs.inc}
  28. interface
  29. uses
  30. cclasses,globtype,
  31. cpubase,cgbase,cgutils,parabase,
  32. aasmbase,aasmtai,aasmcpu,
  33. symconst,symbase,symtype,symdef,symtable,rgobj
  34. ;
  35. type
  36. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  37. {# @abstract(Abstract code generator)
  38. This class implements an abstract instruction generator. Some of
  39. the methods of this class are generic, while others must
  40. be overriden for all new processors which will be supported
  41. by Free Pascal. For 32-bit processors, the base class
  42. sould be @link(tcg64f32) and not @var(tcg).
  43. }
  44. tcg = class
  45. public
  46. alignment : talignment;
  47. rg : array[tregistertype] of trgobj;
  48. t_times : longint;
  49. {$ifdef flowgraph}
  50. aktflownode:word;
  51. {$endif}
  52. {************************************************}
  53. { basic routines }
  54. constructor create;
  55. {# Initialize the register allocators needed for the codegenerator.}
  56. procedure init_register_allocators;virtual;
  57. {# Clean up the register allocators needed for the codegenerator.}
  58. procedure done_register_allocators;virtual;
  59. {$ifdef flowgraph}
  60. procedure init_flowgraph;
  61. procedure done_flowgraph;
  62. {$endif}
  63. {# Gets a register suitable to do integer operations on.}
  64. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  65. {# Gets a register suitable to do integer operations on.}
  66. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  67. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  68. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;
  69. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  70. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  71. the cpu specific child cg object have such a method?}
  72. procedure add_reg_instruction(instr:Tai;r:tregister);virtual;
  73. procedure add_move_instruction(instr:Taicpu);virtual;
  74. function uses_registers(rt:Tregistertype):boolean;virtual;
  75. {# Get a specific register.}
  76. procedure getcpuregister(list:Taasmoutput;r:Tregister);virtual;
  77. procedure ungetcpuregister(list:Taasmoutput;r:Tregister);virtual;
  78. {# Get multiple registers specified.}
  79. procedure alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  80. {# Free multiple registers specified.}
  81. procedure dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;
  82. procedure allocallcpuregisters(list:Taasmoutput);virtual;
  83. procedure deallocallcpuregisters(list:Taasmoutput);virtual;
  84. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;
  85. function makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  86. {# Emit a label to the instruction stream. }
  87. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  88. {# Allocates register r by inserting a pai_realloc record }
  89. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  90. {# Deallocates register r by inserting a pa_regdealloc record}
  91. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  92. { Synchronize register, make sure it is still valid }
  93. procedure a_reg_sync(list : taasmoutput;r : tregister);
  94. {# Pass a parameter, which is located in a register, to a routine.
  95. This routine should push/send the parameter to the routine, as
  96. required by the specific processor ABI and routine modifiers.
  97. This must be overriden for each CPU target.
  98. @param(size size of the operand in the register)
  99. @param(r register source of the operand)
  100. @param(cgpara where the parameter will be stored)
  101. }
  102. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);virtual;
  103. {# Pass a parameter, which is a constant, to a routine.
  104. A generic version is provided. This routine should
  105. be overriden for optimization purposes if the cpu
  106. permits directly sending this type of parameter.
  107. @param(size size of the operand in constant)
  108. @param(a value of constant to send)
  109. @param(cgpara where the parameter will be stored)
  110. }
  111. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);virtual;
  112. {# Pass the value of a parameter, which is located in memory, to a routine.
  113. A generic version is provided. This routine should
  114. be overriden for optimization purposes if the cpu
  115. permits directly sending this type of parameter.
  116. @param(size size of the operand in constant)
  117. @param(r Memory reference of value to send)
  118. @param(cgpara where the parameter will be stored)
  119. }
  120. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);virtual;
  121. {# Pass the value of a parameter, which can be located either in a register or memory location,
  122. to a routine.
  123. A generic version is provided.
  124. @param(l location of the operand to send)
  125. @param(nr parameter number (starting from one) of routine (from left to right))
  126. @param(cgpara where the parameter will be stored)
  127. }
  128. procedure a_param_loc(list : taasmoutput;const l : tlocation;const cgpara : TCGPara);
  129. {# Pass the address of a reference to a routine. This routine
  130. will calculate the address of the reference, and pass this
  131. calculated address as a parameter.
  132. A generic version is provided. This routine should
  133. be overriden for optimization purposes if the cpu
  134. permits directly sending this type of parameter.
  135. @param(r reference to get address from)
  136. @param(nr parameter number (starting from one) of routine (from left to right))
  137. }
  138. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);virtual;
  139. { Remarks:
  140. * If a method specifies a size you have only to take care
  141. of that number of bits, i.e. load_const_reg with OP_8 must
  142. only load the lower 8 bit of the specified register
  143. the rest of the register can be undefined
  144. if necessary the compiler will call a method
  145. to zero or sign extend the register
  146. * The a_load_XX_XX with OP_64 needn't to be
  147. implemented for 32 bit
  148. processors, the code generator takes care of that
  149. * the addr size is for work with the natural pointer
  150. size
  151. * the procedures without fpu/mm are only for integer usage
  152. * normally the first location is the source and the
  153. second the destination
  154. }
  155. {# Emits instruction to call the method specified by symbol name.
  156. This routine must be overriden for each new target cpu.
  157. There is no a_call_ref because loading the reference will use
  158. a temp register on most cpu's resulting in conflicts with the
  159. registers used for the parameters (PFV)
  160. }
  161. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  162. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual;abstract;
  163. { move instructions }
  164. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aint;register : tregister);virtual; abstract;
  165. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);virtual;
  166. procedure a_load_const_loc(list : taasmoutput;a : aint;const loc : tlocation);
  167. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  168. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  169. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  170. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  171. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  172. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  173. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  174. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  175. { fpu move instructions }
  176. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  177. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  178. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  179. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  180. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  181. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);virtual;
  182. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);virtual;
  183. { vector register move instructions }
  184. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  185. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  186. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  187. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  188. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  189. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  190. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  191. procedure a_parammm_loc(list: taasmoutput; const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle); virtual;
  192. procedure a_opmm_reg_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;src,dst: tregister;shuffle : pmmshuffle); virtual;abstract;
  193. procedure a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual;
  194. procedure a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle); virtual;
  195. procedure a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister;const ref: treference; shuffle : pmmshuffle); virtual;
  196. { basic arithmetic operations }
  197. { note: for operators which require only one argument (not, neg), use }
  198. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  199. { that in this case the *second* operand is used as both source and }
  200. { destination (JM) }
  201. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; reg: TRegister); virtual; abstract;
  202. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: Aint; const ref: TReference); virtual;
  203. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: Aint; const loc: tlocation);
  204. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  205. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  206. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  207. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  208. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  209. { trinary operations for processors that support them, 'emulated' }
  210. { on others. None with "ref" arguments since I don't think there }
  211. { are any processors that support it (JM) }
  212. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister); virtual;
  213. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister); virtual;
  214. procedure a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  215. procedure a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation); virtual;
  216. { comparison operations }
  217. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
  218. l : tasmlabel);virtual; abstract;
  219. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  220. l : tasmlabel); virtual;
  221. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aint; const loc: tlocation;
  222. l : tasmlabel);
  223. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  224. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  225. procedure a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg : tregister; const ref: treference; l : tasmlabel); virtual;
  226. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  227. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  228. l : tasmlabel);
  229. procedure a_jmp_name(list : taasmoutput;const s : string); virtual; abstract;
  230. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  231. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  232. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  233. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  234. }
  235. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  236. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  237. {
  238. This routine tries to optimize the const_reg opcode, and should be
  239. called at the start of a_op_const_reg. It returns the actual opcode
  240. to emit, and the constant value to emit. If this routine returns
  241. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  242. @param(op The opcode to emit, returns the opcode which must be emitted)
  243. @param(a The constant which should be emitted, returns the constant which must
  244. be emitted)
  245. @param(reg The register to emit the opcode with, returns the register with
  246. which the opcode will be emitted)
  247. }
  248. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg: tregister): boolean;virtual;
  249. {#
  250. This routine is used in exception management nodes. It should
  251. save the exception reason currently in the FUNCTION_RETURN_REG. The
  252. save should be done either to a temp (pointed to by href).
  253. or on the stack (pushing the value on the stack).
  254. The size of the value to save is OS_S32. The default version
  255. saves the exception reason to a temp. memory area.
  256. }
  257. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  258. {#
  259. This routine is used in exception management nodes. It should
  260. save the exception reason constant. The
  261. save should be done either to a temp (pointed to by href).
  262. or on the stack (pushing the value on the stack).
  263. The size of the value to save is OS_S32. The default version
  264. saves the exception reason to a temp. memory area.
  265. }
  266. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);virtual;
  267. {#
  268. This routine is used in exception management nodes. It should
  269. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  270. should either be in the temp. area (pointed to by href , href should
  271. *NOT* be freed) or on the stack (the value should be popped).
  272. The size of the value to save is OS_S32. The default version
  273. saves the exception reason to a temp. memory area.
  274. }
  275. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  276. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  277. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  278. {# This should emit the opcode to copy len bytes from the source
  279. to destination.
  280. It must be overriden for each new target processor.
  281. @param(source Source reference of copy)
  282. @param(dest Destination reference of copy)
  283. }
  284. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aint);virtual; abstract;
  285. {# This should emit the opcode to copy len bytes from the an unaligned source
  286. to destination.
  287. It must be overriden for each new target processor.
  288. @param(source Source reference of copy)
  289. @param(dest Destination reference of copy)
  290. }
  291. procedure g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);virtual;
  292. {# This should emit the opcode to a shortrstring from the source
  293. to destination.
  294. @param(source Source reference of copy)
  295. @param(dest Destination reference of copy)
  296. }
  297. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  298. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  299. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  300. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  301. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  302. {# Generates range checking code. It is to note
  303. that this routine does not need to be overriden,
  304. as it takes care of everything.
  305. @param(p Node which contains the value to check)
  306. @param(todef Type definition of node to range check)
  307. }
  308. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  309. {# Generates overflow checking code for a node }
  310. procedure g_overflowcheck(list: taasmoutput; const Loc:tlocation; def:tdef); virtual;abstract;
  311. procedure g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);virtual;
  312. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);virtual;
  313. procedure g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);virtual;
  314. {# Emits instructions when compilation is done in profile
  315. mode (this is set as a command line option). The default
  316. behavior does nothing, should be overriden as required.
  317. }
  318. procedure g_profilecode(list : taasmoutput);virtual;
  319. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  320. @param(size Number of bytes to allocate)
  321. }
  322. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  323. {# Emits instruction for allocating the locals in entry
  324. code of a routine. This is one of the first
  325. routine called in @var(genentrycode).
  326. @param(localsize Number of bytes to allocate as locals)
  327. }
  328. procedure g_proc_entry(list : taasmoutput;localsize : longint;nostackframe:boolean);virtual; abstract;
  329. {# Emits instructions for returning from a subroutine.
  330. Should also restore the framepointer and stack.
  331. @param(parasize Number of bytes of parameters to deallocate from stack)
  332. }
  333. procedure g_proc_exit(list : taasmoutput;parasize:longint;nostackframe:boolean);virtual;abstract;
  334. {# This routine is called when generating the code for the entry point
  335. of a routine. It should save all registers which are not used in this
  336. routine, and which should be declared as saved in the std_saved_registers
  337. set.
  338. This routine is mainly used when linking to code which is generated
  339. by ABI-compliant compilers (like GCC), to make sure that the reserved
  340. registers of that ABI are not clobbered.
  341. @param(usedinproc Registers which are used in the code of this routine)
  342. }
  343. procedure g_save_standard_registers(list:Taasmoutput);virtual;
  344. {# This routine is called when generating the code for the exit point
  345. of a routine. It should restore all registers which were previously
  346. saved in @var(g_save_standard_registers).
  347. @param(usedinproc Registers which are used in the code of this routine)
  348. }
  349. procedure g_restore_standard_registers(list:Taasmoutput);virtual;
  350. procedure g_intf_wrapper(list: TAAsmoutput; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
  351. procedure g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);virtual;
  352. end;
  353. {$ifndef cpu64bit}
  354. {# @abstract(Abstract code generator for 64 Bit operations)
  355. This class implements an abstract code generator class
  356. for 64 Bit operations.
  357. }
  358. tcg64 = class
  359. procedure a_load64_const_ref(list : taasmoutput;value : int64;const ref : treference);virtual;abstract;
  360. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  361. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64);virtual;abstract;
  362. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64);virtual;abstract;
  363. procedure a_load64_const_reg(list : taasmoutput;value : int64;reg : tregister64);virtual;abstract;
  364. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64);virtual;abstract;
  365. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  366. procedure a_load64_const_loc(list : taasmoutput;value : int64;const l : tlocation);virtual;abstract;
  367. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  368. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  369. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  370. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  371. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  372. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  373. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  374. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const ref : treference;reg : tregister64);virtual;abstract;
  375. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc,regdst : tregister64);virtual;abstract;
  376. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;size : tcgsize;regsrc : tregister64;const ref : treference);virtual;abstract;
  377. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;regdst : tregister64);virtual;abstract;
  378. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const ref : treference);virtual;abstract;
  379. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;size : tcgsize;value : int64;const l: tlocation);virtual;abstract;
  380. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;size : tcgsize;reg : tregister64;const l : tlocation);virtual;abstract;
  381. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;size : tcgsize;const l : tlocation;reg64 : tregister64);virtual;abstract;
  382. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64);virtual;
  383. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);virtual;
  384. procedure a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  385. procedure a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);virtual;
  386. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : TCGPara);virtual;abstract;
  387. procedure a_param64_const(list : taasmoutput;value : int64;const loc : TCGPara);virtual;abstract;
  388. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : TCGPara);virtual;abstract;
  389. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : TCGPara);virtual;abstract;
  390. {
  391. This routine tries to optimize the const_reg opcode, and should be
  392. called at the start of a_op64_const_reg. It returns the actual opcode
  393. to emit, and the constant value to emit. If this routine returns
  394. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  395. @param(op The opcode to emit, returns the opcode which must be emitted)
  396. @param(a The constant which should be emitted, returns the constant which must
  397. be emitted)
  398. @param(reg The register to emit the opcode with, returns the register with
  399. which the opcode will be emitted)
  400. }
  401. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : int64; var reg: tregister64): boolean;virtual;abstract;
  402. { override to catch 64bit rangechecks }
  403. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  404. end;
  405. {$endif cpu64bit}
  406. var
  407. {# Main code generator class }
  408. cg : tcg;
  409. {$ifndef cpu64bit}
  410. {# Code generator class for all operations working with 64-Bit operands }
  411. cg64 : tcg64;
  412. {$endif cpu64bit}
  413. implementation
  414. uses
  415. globals,options,systems,
  416. verbose,defutil,paramgr,symsym,
  417. tgobj,cutils,procinfo;
  418. const
  419. { Please leave this here, this module should NOT use
  420. exprasmlist, the lists are always passed as arguments.
  421. Declaring it as string here results in an error when compiling (PFV) }
  422. exprasmlist = 'error';
  423. {*****************************************************************************
  424. basic functionallity
  425. ******************************************************************************}
  426. constructor tcg.create;
  427. begin
  428. end;
  429. {*****************************************************************************
  430. register allocation
  431. ******************************************************************************}
  432. procedure tcg.init_register_allocators;
  433. begin
  434. fillchar(rg,sizeof(rg),0);
  435. add_reg_instruction_hook:=@add_reg_instruction;
  436. end;
  437. procedure tcg.done_register_allocators;
  438. begin
  439. { Safety }
  440. fillchar(rg,sizeof(rg),0);
  441. add_reg_instruction_hook:=nil;
  442. end;
  443. {$ifdef flowgraph}
  444. procedure Tcg.init_flowgraph;
  445. begin
  446. aktflownode:=0;
  447. end;
  448. procedure Tcg.done_flowgraph;
  449. begin
  450. end;
  451. {$endif}
  452. function tcg.getintregister(list:Taasmoutput;size:Tcgsize):Tregister;
  453. begin
  454. if not assigned(rg[R_INTREGISTER]) then
  455. internalerror(200312122);
  456. result:=rg[R_INTREGISTER].getregister(list,cgsize2subreg(size));
  457. end;
  458. function tcg.getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;
  459. begin
  460. if not assigned(rg[R_FPUREGISTER]) then
  461. internalerror(200312123);
  462. result:=rg[R_FPUREGISTER].getregister(list,cgsize2subreg(size));
  463. end;
  464. function tcg.getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;
  465. begin
  466. if not assigned(rg[R_MMREGISTER]) then
  467. internalerror(2003121214);
  468. result:=rg[R_MMREGISTER].getregister(list,cgsize2subreg(size));
  469. end;
  470. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  471. begin
  472. if assigned(rg[R_ADDRESSREGISTER]) then
  473. result:=rg[R_ADDRESSREGISTER].getregister(list,R_SUBWHOLE)
  474. else
  475. begin
  476. if not assigned(rg[R_INTREGISTER]) then
  477. internalerror(200312121);
  478. result:=rg[R_INTREGISTER].getregister(list,R_SUBWHOLE);
  479. end;
  480. end;
  481. function Tcg.makeregsize(list:Taasmoutput;reg:Tregister;size:Tcgsize):Tregister;
  482. var
  483. subreg:Tsubregister;
  484. begin
  485. subreg:=cgsize2subreg(size);
  486. result:=reg;
  487. setsubreg(result,subreg);
  488. { notify RA }
  489. if result<>reg then
  490. list.concat(tai_regalloc.resize(result));
  491. end;
  492. procedure tcg.getcpuregister(list:Taasmoutput;r:Tregister);
  493. begin
  494. if not assigned(rg[getregtype(r)]) then
  495. internalerror(200312125);
  496. rg[getregtype(r)].getcpuregister(list,r);
  497. end;
  498. procedure tcg.ungetcpuregister(list:Taasmoutput;r:Tregister);
  499. begin
  500. if not assigned(rg[getregtype(r)]) then
  501. internalerror(200312126);
  502. rg[getregtype(r)].ungetcpuregister(list,r);
  503. end;
  504. procedure tcg.alloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  505. begin
  506. if assigned(rg[rt]) then
  507. rg[rt].alloccpuregisters(list,r)
  508. else
  509. internalerror(200310092);
  510. end;
  511. procedure tcg.allocallcpuregisters(list:Taasmoutput);
  512. begin
  513. alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  514. alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  515. alloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  516. end;
  517. procedure tcg.dealloccpuregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);
  518. begin
  519. if assigned(rg[rt]) then
  520. rg[rt].dealloccpuregisters(list,r)
  521. else
  522. internalerror(200310093);
  523. end;
  524. procedure tcg.deallocallcpuregisters(list:Taasmoutput);
  525. begin
  526. dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  527. dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
  528. dealloccpuregisters(list,R_MMREGISTER,paramanager.get_volatile_registers_mm(pocall_default));
  529. end;
  530. function tcg.uses_registers(rt:Tregistertype):boolean;
  531. begin
  532. if assigned(rg[rt]) then
  533. result:=rg[rt].uses_registers
  534. else
  535. result:=false;
  536. end;
  537. procedure tcg.add_reg_instruction(instr:Tai;r:tregister);
  538. var
  539. rt : tregistertype;
  540. begin
  541. rt:=getregtype(r);
  542. { Only add it when a register allocator is configured.
  543. No IE can be generated, because the VMT is written
  544. without a valid rg[] }
  545. if assigned(rg[rt]) then
  546. rg[rt].add_reg_instruction(instr,r);
  547. end;
  548. procedure tcg.add_move_instruction(instr:Taicpu);
  549. var
  550. rt : tregistertype;
  551. begin
  552. rt:=getregtype(instr.oper[O_MOV_SOURCE]^.reg);
  553. if assigned(rg[rt]) then
  554. rg[rt].add_move_instruction(instr)
  555. else
  556. internalerror(200310095);
  557. end;
  558. procedure tcg.do_register_allocation(list:Taasmoutput;headertai:tai);
  559. var
  560. rt : tregistertype;
  561. begin
  562. for rt:=R_FPUREGISTER to R_SPECIALREGISTER do
  563. begin
  564. if assigned(rg[rt]) then
  565. rg[rt].do_register_allocation(list,headertai);
  566. end;
  567. { running the other register allocator passes could require addition int/addr. registers
  568. when spilling so run int/addr register allocation at the end }
  569. if assigned(rg[R_INTREGISTER]) then
  570. rg[R_INTREGISTER].do_register_allocation(list,headertai);
  571. if assigned(rg[R_ADDRESSREGISTER]) then
  572. rg[R_ADDRESSREGISTER].do_register_allocation(list,headertai);
  573. end;
  574. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  575. begin
  576. list.concat(tai_regalloc.alloc(r,nil));
  577. end;
  578. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  579. begin
  580. list.concat(tai_regalloc.dealloc(r,nil));
  581. end;
  582. procedure tcg.a_reg_sync(list : taasmoutput;r : tregister);
  583. var
  584. instr : tai;
  585. begin
  586. instr:=tai_regalloc.sync(r);
  587. list.concat(instr);
  588. add_reg_instruction(instr,r);
  589. end;
  590. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  591. begin
  592. list.concat(tai_label.create(l));
  593. end;
  594. {*****************************************************************************
  595. for better code generation these methods should be overridden
  596. ******************************************************************************}
  597. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const cgpara : TCGPara);
  598. var
  599. ref : treference;
  600. begin
  601. cgpara.check_simple_location;
  602. case cgpara.location^.loc of
  603. LOC_REGISTER,LOC_CREGISTER:
  604. a_load_reg_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  605. LOC_REFERENCE,LOC_CREFERENCE:
  606. begin
  607. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  608. a_load_reg_ref(list,size,cgpara.location^.size,r,ref);
  609. end
  610. else
  611. internalerror(2002071004);
  612. end;
  613. end;
  614. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aint;const cgpara : TCGPara);
  615. var
  616. ref : treference;
  617. begin
  618. cgpara.check_simple_location;
  619. case cgpara.location^.loc of
  620. LOC_REGISTER,LOC_CREGISTER:
  621. a_load_const_reg(list,cgpara.location^.size,a,cgpara.location^.register);
  622. LOC_REFERENCE,LOC_CREFERENCE:
  623. begin
  624. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  625. a_load_const_ref(list,cgpara.location^.size,a,ref);
  626. end
  627. else
  628. internalerror(2002071004);
  629. end;
  630. end;
  631. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const cgpara : TCGPara);
  632. var
  633. ref : treference;
  634. begin
  635. cgpara.check_simple_location;
  636. case cgpara.location^.loc of
  637. LOC_REGISTER,LOC_CREGISTER:
  638. a_load_ref_reg(list,size,cgpara.location^.size,r,cgpara.location^.register);
  639. LOC_REFERENCE,LOC_CREFERENCE:
  640. begin
  641. reference_reset(ref);
  642. ref.base:=cgpara.location^.reference.index;
  643. ref.offset:=cgpara.location^.reference.offset;
  644. { use concatcopy, because it can also be a float which fails when
  645. load_ref_ref is used }
  646. g_concatcopy(list,r,ref,tcgsize2size[size]);
  647. end
  648. else
  649. internalerror(2002071004);
  650. end;
  651. end;
  652. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const cgpara : TCGPara);
  653. begin
  654. case l.loc of
  655. LOC_REGISTER,
  656. LOC_CREGISTER :
  657. a_param_reg(list,l.size,l.register,cgpara);
  658. LOC_CONSTANT :
  659. a_param_const(list,l.size,l.value,cgpara);
  660. LOC_CREFERENCE,
  661. LOC_REFERENCE :
  662. a_param_ref(list,l.size,l.reference,cgpara);
  663. else
  664. internalerror(2002032211);
  665. end;
  666. end;
  667. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const cgpara : TCGPara);
  668. var
  669. hr : tregister;
  670. begin
  671. cgpara.check_simple_location;
  672. hr:=getaddressregister(list);
  673. a_loadaddr_ref_reg(list,r,hr);
  674. a_param_reg(list,OS_ADDR,hr,cgpara);
  675. end;
  676. {****************************************************************************
  677. some generic implementations
  678. ****************************************************************************}
  679. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  680. var
  681. tmpreg: tregister;
  682. begin
  683. { verify if we have the same reference }
  684. if references_equal(sref,dref) then
  685. exit;
  686. tmpreg:=getintregister(list,tosize);
  687. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  688. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  689. end;
  690. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aint;const ref : treference);
  691. var
  692. tmpreg: tregister;
  693. begin
  694. tmpreg:=getintregister(list,size);
  695. a_load_const_reg(list,size,a,tmpreg);
  696. a_load_reg_ref(list,size,size,tmpreg,ref);
  697. end;
  698. procedure tcg.a_load_const_loc(list : taasmoutput;a : aint;const loc: tlocation);
  699. begin
  700. case loc.loc of
  701. LOC_REFERENCE,LOC_CREFERENCE:
  702. a_load_const_ref(list,loc.size,a,loc.reference);
  703. LOC_REGISTER,LOC_CREGISTER:
  704. a_load_const_reg(list,loc.size,a,loc.register);
  705. else
  706. internalerror(200203272);
  707. end;
  708. end;
  709. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  710. begin
  711. case loc.loc of
  712. LOC_REFERENCE,LOC_CREFERENCE:
  713. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  714. LOC_REGISTER,LOC_CREGISTER:
  715. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  716. else
  717. internalerror(200203271);
  718. end;
  719. end;
  720. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  721. begin
  722. case loc.loc of
  723. LOC_REFERENCE,LOC_CREFERENCE:
  724. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  725. LOC_REGISTER,LOC_CREGISTER:
  726. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  727. LOC_CONSTANT:
  728. a_load_const_reg(list,tosize,loc.value,reg);
  729. else
  730. internalerror(200109092);
  731. end;
  732. end;
  733. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  734. begin
  735. case loc.loc of
  736. LOC_REFERENCE,LOC_CREFERENCE:
  737. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  738. LOC_REGISTER,LOC_CREGISTER:
  739. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  740. LOC_CONSTANT:
  741. a_load_const_ref(list,tosize,loc.value,ref);
  742. else
  743. internalerror(200109302);
  744. end;
  745. end;
  746. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aint; var reg:tregister): boolean;
  747. var
  748. powerval : longint;
  749. begin
  750. optimize_op_const_reg := false;
  751. case op of
  752. { or with zero returns same result }
  753. OP_OR : if a = 0 then optimize_op_const_reg := true;
  754. { and with max returns same result }
  755. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  756. { division by 1 returns result }
  757. OP_DIV :
  758. begin
  759. if a = 1 then
  760. optimize_op_const_reg := true
  761. else if ispowerof2(int64(a), powerval) then
  762. begin
  763. a := powerval;
  764. op:= OP_SHR;
  765. end;
  766. exit;
  767. end;
  768. OP_IDIV:
  769. begin
  770. if a = 1 then
  771. optimize_op_const_reg := true
  772. else if ispowerof2(int64(a), powerval) then
  773. begin
  774. a := powerval;
  775. op:= OP_SAR;
  776. end;
  777. exit;
  778. end;
  779. OP_MUL,OP_IMUL:
  780. begin
  781. if a = 1 then
  782. optimize_op_const_reg := true
  783. else if ispowerof2(int64(a), powerval) then
  784. begin
  785. a := powerval;
  786. op:= OP_SHL;
  787. end;
  788. exit;
  789. end;
  790. OP_SAR,OP_SHL,OP_SHR:
  791. begin
  792. if a = 0 then
  793. optimize_op_const_reg := true;
  794. exit;
  795. end;
  796. end;
  797. end;
  798. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  799. begin
  800. case loc.loc of
  801. LOC_REFERENCE, LOC_CREFERENCE:
  802. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  803. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  804. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  805. else
  806. internalerror(200203301);
  807. end;
  808. end;
  809. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  810. begin
  811. case loc.loc of
  812. LOC_REFERENCE, LOC_CREFERENCE:
  813. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  814. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  815. a_loadfpu_reg_reg(list,size,reg,loc.register);
  816. else
  817. internalerror(48991);
  818. end;
  819. end;
  820. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const cgpara : TCGPara);
  821. var
  822. ref : treference;
  823. begin
  824. cgpara.check_simple_location;
  825. case cgpara.location^.loc of
  826. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  827. a_loadfpu_reg_reg(list,size,r,cgpara.location^.register);
  828. LOC_REFERENCE,LOC_CREFERENCE:
  829. begin
  830. reference_reset_base(ref,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  831. a_loadfpu_reg_ref(list,size,r,ref);
  832. end
  833. else
  834. internalerror(2002071004);
  835. end;
  836. end;
  837. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const cgpara : TCGPara);
  838. var
  839. href : treference;
  840. begin
  841. cgpara.check_simple_location;
  842. case cgpara.location^.loc of
  843. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  844. a_loadfpu_ref_reg(list,size,ref,cgpara.location^.register);
  845. LOC_REFERENCE,LOC_CREFERENCE:
  846. begin
  847. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  848. { concatcopy should choose the best way to copy the data }
  849. g_concatcopy(list,ref,href,tcgsize2size[size]);
  850. end
  851. else
  852. internalerror(200402201);
  853. end;
  854. end;
  855. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: aint; const ref: TReference);
  856. var
  857. tmpreg : tregister;
  858. begin
  859. tmpreg:=getintregister(list,size);
  860. a_load_ref_reg(list,size,size,ref,tmpreg);
  861. a_op_const_reg(list,op,size,a,tmpreg);
  862. a_load_reg_ref(list,size,size,tmpreg,ref);
  863. end;
  864. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: aint; const loc: tlocation);
  865. begin
  866. case loc.loc of
  867. LOC_REGISTER, LOC_CREGISTER:
  868. a_op_const_reg(list,op,loc.size,a,loc.register);
  869. LOC_REFERENCE, LOC_CREFERENCE:
  870. a_op_const_ref(list,op,loc.size,a,loc.reference);
  871. else
  872. internalerror(200109061);
  873. end;
  874. end;
  875. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  876. var
  877. tmpreg : tregister;
  878. begin
  879. tmpreg:=getintregister(list,size);
  880. a_load_ref_reg(list,size,size,ref,tmpreg);
  881. a_op_reg_reg(list,op,size,reg,tmpreg);
  882. a_load_reg_ref(list,size,size,tmpreg,ref);
  883. end;
  884. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  885. var
  886. tmpreg: tregister;
  887. begin
  888. case op of
  889. OP_NOT,OP_NEG:
  890. { handle it as "load ref,reg; op reg" }
  891. begin
  892. a_load_ref_reg(list,size,size,ref,reg);
  893. a_op_reg_reg(list,op,size,reg,reg);
  894. end;
  895. else
  896. begin
  897. tmpreg:=getintregister(list,size);
  898. a_load_ref_reg(list,size,size,ref,tmpreg);
  899. a_op_reg_reg(list,op,size,tmpreg,reg);
  900. end;
  901. end;
  902. end;
  903. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  904. begin
  905. case loc.loc of
  906. LOC_REGISTER, LOC_CREGISTER:
  907. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  908. LOC_REFERENCE, LOC_CREFERENCE:
  909. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  910. else
  911. internalerror(200109061);
  912. end;
  913. end;
  914. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  915. var
  916. tmpreg: tregister;
  917. begin
  918. case loc.loc of
  919. LOC_REGISTER,LOC_CREGISTER:
  920. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  921. LOC_REFERENCE,LOC_CREFERENCE:
  922. begin
  923. tmpreg:=getintregister(list,loc.size);
  924. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  925. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  926. end;
  927. else
  928. internalerror(200109061);
  929. end;
  930. end;
  931. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  932. a:aint;src,dst:Tregister);
  933. begin
  934. a_load_reg_reg(list,size,size,src,dst);
  935. a_op_const_reg(list,op,size,a,dst);
  936. end;
  937. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  938. size: tcgsize; src1, src2, dst: tregister);
  939. var
  940. tmpreg: tregister;
  941. begin
  942. if (dst<>src1) then
  943. begin
  944. a_load_reg_reg(list,size,size,src2,dst);
  945. a_op_reg_reg(list,op,size,src1,dst);
  946. end
  947. else
  948. begin
  949. tmpreg:=getintregister(list,size);
  950. a_load_reg_reg(list,size,size,src2,tmpreg);
  951. a_op_reg_reg(list,op,size,src1,tmpreg);
  952. a_load_reg_reg(list,size,size,tmpreg,dst);
  953. end;
  954. end;
  955. procedure tcg.a_op_const_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; a: aint; src, dst: tregister;setflags : boolean;var ovloc : tlocation);
  956. begin
  957. a_op_const_reg_reg(list,op,size,a,src,dst);
  958. ovloc.loc:=LOC_VOID;
  959. end;
  960. procedure tcg.a_op_reg_reg_reg_checkoverflow(list: taasmoutput; op: TOpCg; size: tcgsize; src1, src2, dst: tregister;setflags : boolean;var ovloc : tlocation);
  961. begin
  962. a_op_reg_reg_reg(list,op,size,src1,src2,dst);
  963. ovloc.loc:=LOC_VOID;
  964. end;
  965. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
  966. l : tasmlabel);
  967. var
  968. tmpreg: tregister;
  969. begin
  970. tmpreg:=getintregister(list,size);
  971. a_load_ref_reg(list,size,size,ref,tmpreg);
  972. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  973. end;
  974. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
  975. l : tasmlabel);
  976. begin
  977. case loc.loc of
  978. LOC_REGISTER,LOC_CREGISTER:
  979. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  980. LOC_REFERENCE,LOC_CREFERENCE:
  981. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  982. else
  983. internalerror(200109061);
  984. end;
  985. end;
  986. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  987. var
  988. tmpreg: tregister;
  989. begin
  990. tmpreg:=getintregister(list,size);
  991. a_load_ref_reg(list,size,size,ref,tmpreg);
  992. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  993. end;
  994. procedure tcg.a_cmp_reg_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; reg : tregister; const ref: treference; l : tasmlabel);
  995. var
  996. tmpreg: tregister;
  997. begin
  998. tmpreg:=getintregister(list,size);
  999. a_load_ref_reg(list,size,size,ref,tmpreg);
  1000. a_cmp_reg_reg_label(list,size,cmp_op,reg,tmpreg,l);
  1001. end;
  1002. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1003. begin
  1004. case loc.loc of
  1005. LOC_REGISTER,
  1006. LOC_CREGISTER:
  1007. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1008. LOC_REFERENCE,
  1009. LOC_CREFERENCE :
  1010. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1011. LOC_CONSTANT:
  1012. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1013. else
  1014. internalerror(200203231);
  1015. end;
  1016. end;
  1017. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1018. l : tasmlabel);
  1019. var
  1020. tmpreg: tregister;
  1021. begin
  1022. case loc.loc of
  1023. LOC_REGISTER,LOC_CREGISTER:
  1024. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1025. LOC_REFERENCE,LOC_CREFERENCE:
  1026. begin
  1027. tmpreg:=getintregister(list,size);
  1028. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  1029. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1030. end
  1031. else
  1032. internalerror(200109061);
  1033. end;
  1034. end;
  1035. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  1036. begin
  1037. case loc.loc of
  1038. LOC_MMREGISTER,LOC_CMMREGISTER:
  1039. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  1040. LOC_REFERENCE,LOC_CREFERENCE:
  1041. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  1042. else
  1043. internalerror(200310121);
  1044. end;
  1045. end;
  1046. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1047. begin
  1048. case loc.loc of
  1049. LOC_MMREGISTER,LOC_CMMREGISTER:
  1050. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1051. LOC_REFERENCE,LOC_CREFERENCE:
  1052. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1053. else
  1054. internalerror(200310122);
  1055. end;
  1056. end;
  1057. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const cgpara : TCGPara;shuffle : pmmshuffle);
  1058. var
  1059. href : treference;
  1060. begin
  1061. cgpara.check_simple_location;
  1062. case cgpara.location^.loc of
  1063. LOC_MMREGISTER,LOC_CMMREGISTER:
  1064. a_loadmm_reg_reg(list,size,cgpara.location^.size,reg,cgpara.location^.register,shuffle);
  1065. LOC_REFERENCE,LOC_CREFERENCE:
  1066. begin
  1067. reference_reset_base(href,cgpara.location^.reference.index,cgpara.location^.reference.offset);
  1068. a_loadmm_reg_ref(list,size,cgpara.location^.size,reg,href,shuffle);
  1069. end
  1070. else
  1071. internalerror(200310123);
  1072. end;
  1073. end;
  1074. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize;const ref: treference;const cgpara : TCGPara;shuffle : pmmshuffle);
  1075. var
  1076. hr : tregister;
  1077. hs : tmmshuffle;
  1078. begin
  1079. cgpara.check_simple_location;
  1080. hr:=getmmregister(list,cgpara.location^.size);
  1081. a_loadmm_ref_reg(list,size,cgpara.location^.size,ref,hr,shuffle);
  1082. if realshuffle(shuffle) then
  1083. begin
  1084. hs:=shuffle^;
  1085. removeshuffles(hs);
  1086. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,@hs);
  1087. end
  1088. else
  1089. a_parammm_reg(list,cgpara.location^.size,hr,cgpara,shuffle);
  1090. end;
  1091. procedure tcg.a_parammm_loc(list: taasmoutput;const loc: tlocation; const cgpara : TCGPara;shuffle : pmmshuffle);
  1092. begin
  1093. case loc.loc of
  1094. LOC_MMREGISTER,LOC_CMMREGISTER:
  1095. a_parammm_reg(list,loc.size,loc.register,cgpara,shuffle);
  1096. LOC_REFERENCE,LOC_CREFERENCE:
  1097. a_parammm_ref(list,loc.size,loc.reference,cgpara,shuffle);
  1098. else
  1099. internalerror(200310123);
  1100. end;
  1101. end;
  1102. procedure tcg.a_opmm_ref_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle);
  1103. var
  1104. hr : tregister;
  1105. hs : tmmshuffle;
  1106. begin
  1107. hr:=getmmregister(list,size);
  1108. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1109. if realshuffle(shuffle) then
  1110. begin
  1111. hs:=shuffle^;
  1112. removeshuffles(hs);
  1113. a_opmm_reg_reg(list,op,size,hr,reg,@hs);
  1114. end
  1115. else
  1116. a_opmm_reg_reg(list,op,size,hr,reg,shuffle);
  1117. end;
  1118. procedure tcg.a_opmm_reg_ref(list: taasmoutput; Op: TOpCG; size : tcgsize;reg: tregister; const ref: treference; shuffle : pmmshuffle);
  1119. var
  1120. hr : tregister;
  1121. hs : tmmshuffle;
  1122. begin
  1123. hr:=getmmregister(list,size);
  1124. a_loadmm_ref_reg(list,size,size,ref,hr,shuffle);
  1125. if realshuffle(shuffle) then
  1126. begin
  1127. hs:=shuffle^;
  1128. removeshuffles(hs);
  1129. a_opmm_reg_reg(list,op,size,reg,hr,@hs);
  1130. a_loadmm_reg_ref(list,size,size,hr,ref,@hs);
  1131. end
  1132. else
  1133. begin
  1134. a_opmm_reg_reg(list,op,size,reg,hr,shuffle);
  1135. a_loadmm_reg_ref(list,size,size,hr,ref,shuffle);
  1136. end;
  1137. end;
  1138. procedure tcg.a_opmm_loc_reg(list: taasmoutput; Op: TOpCG; size : tcgsize;const loc: tlocation; reg: tregister;shuffle : pmmshuffle);
  1139. begin
  1140. case loc.loc of
  1141. LOC_CMMREGISTER,LOC_MMREGISTER:
  1142. a_opmm_reg_reg(list,op,size,loc.register,reg,shuffle);
  1143. LOC_CREFERENCE,LOC_REFERENCE:
  1144. a_opmm_ref_reg(list,op,size,loc.reference,reg,shuffle);
  1145. else
  1146. internalerror(200312232);
  1147. end;
  1148. end;
  1149. procedure tcg.g_concatcopy_unaligned(list : taasmoutput;const source,dest : treference;len : aint);
  1150. begin
  1151. g_concatcopy(list,source,dest,len);
  1152. end;
  1153. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte);
  1154. var
  1155. cgpara1,cgpara2,cgpara3 : TCGPara;
  1156. begin
  1157. cgpara1.init;
  1158. cgpara2.init;
  1159. cgpara3.init;
  1160. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1161. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1162. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1163. paramanager.allocparaloc(list,cgpara3);
  1164. a_paramaddr_ref(list,dest,cgpara3);
  1165. paramanager.allocparaloc(list,cgpara2);
  1166. a_paramaddr_ref(list,source,cgpara2);
  1167. paramanager.allocparaloc(list,cgpara1);
  1168. a_param_const(list,OS_INT,len,cgpara1);
  1169. paramanager.freeparaloc(list,cgpara3);
  1170. paramanager.freeparaloc(list,cgpara2);
  1171. paramanager.freeparaloc(list,cgpara1);
  1172. allocallcpuregisters(list);
  1173. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1174. deallocallcpuregisters(list);
  1175. cgpara3.done;
  1176. cgpara2.done;
  1177. cgpara1.done;
  1178. end;
  1179. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1180. var
  1181. href : treference;
  1182. incrfunc : string;
  1183. cgpara1,cgpara2 : TCGPara;
  1184. begin
  1185. cgpara1.init;
  1186. cgpara2.init;
  1187. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1188. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1189. if is_interfacecom(t) then
  1190. incrfunc:='FPC_INTF_INCR_REF'
  1191. else if is_ansistring(t) then
  1192. {$ifdef ansistring_bits}
  1193. begin
  1194. case Tstringdef(t).string_typ of
  1195. st_ansistring16:
  1196. incrfunc:='FPC_ANSISTR16_INCR_REF';
  1197. st_ansistring32:
  1198. incrfunc:='FPC_ANSISTR32_INCR_REF';
  1199. st_ansistring64:
  1200. incrfunc:='FPC_ANSISTR64_INCR_REF';
  1201. end;
  1202. end
  1203. {$else}
  1204. incrfunc:='FPC_ANSISTR_INCR_REF'
  1205. {$endif}
  1206. else if is_widestring(t) then
  1207. incrfunc:='FPC_WIDESTR_INCR_REF'
  1208. else if is_dynamic_array(t) then
  1209. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1210. else
  1211. incrfunc:='';
  1212. { call the special incr function or the generic addref }
  1213. if incrfunc<>'' then
  1214. begin
  1215. paramanager.allocparaloc(list,cgpara1);
  1216. { these functions get the pointer by value }
  1217. a_param_ref(list,OS_ADDR,ref,cgpara1);
  1218. paramanager.freeparaloc(list,cgpara1);
  1219. allocallcpuregisters(list);
  1220. a_call_name(list,incrfunc);
  1221. deallocallcpuregisters(list);
  1222. end
  1223. else
  1224. begin
  1225. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1226. paramanager.allocparaloc(list,cgpara2);
  1227. a_paramaddr_ref(list,href,cgpara2);
  1228. paramanager.allocparaloc(list,cgpara1);
  1229. a_paramaddr_ref(list,ref,cgpara1);
  1230. paramanager.freeparaloc(list,cgpara1);
  1231. paramanager.freeparaloc(list,cgpara2);
  1232. allocallcpuregisters(list);
  1233. a_call_name(list,'FPC_ADDREF');
  1234. deallocallcpuregisters(list);
  1235. end;
  1236. cgpara2.done;
  1237. cgpara1.done;
  1238. end;
  1239. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference);
  1240. var
  1241. href : treference;
  1242. decrfunc : string;
  1243. needrtti : boolean;
  1244. cgpara1,cgpara2 : TCGPara;
  1245. begin
  1246. cgpara1.init;
  1247. cgpara2.init;
  1248. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1249. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1250. needrtti:=false;
  1251. if is_interfacecom(t) then
  1252. decrfunc:='FPC_INTF_DECR_REF'
  1253. else if is_ansistring(t) then
  1254. {$ifdef ansistring_bits}
  1255. begin
  1256. case Tstringdef(t).string_typ of
  1257. st_ansistring16:
  1258. decrfunc:='FPC_ANSISTR16_DECR_REF';
  1259. st_ansistring32:
  1260. decrfunc:='FPC_ANSISTR32_DECR_REF';
  1261. st_ansistring64:
  1262. decrfunc:='FPC_ANSISTR64_DECR_REF';
  1263. end;
  1264. end
  1265. {$else}
  1266. decrfunc:='FPC_ANSISTR_DECR_REF'
  1267. {$endif}
  1268. else if is_widestring(t) then
  1269. decrfunc:='FPC_WIDESTR_DECR_REF'
  1270. else if is_dynamic_array(t) then
  1271. begin
  1272. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1273. needrtti:=true;
  1274. end
  1275. else
  1276. decrfunc:='';
  1277. { call the special decr function or the generic decref }
  1278. if decrfunc<>'' then
  1279. begin
  1280. if needrtti then
  1281. begin
  1282. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1283. paramanager.allocparaloc(list,cgpara2);
  1284. a_paramaddr_ref(list,href,cgpara2);
  1285. end;
  1286. paramanager.allocparaloc(list,cgpara1);
  1287. a_paramaddr_ref(list,ref,cgpara1);
  1288. paramanager.freeparaloc(list,cgpara1);
  1289. if needrtti then
  1290. paramanager.freeparaloc(list,cgpara2);
  1291. allocallcpuregisters(list);
  1292. a_call_name(list,decrfunc);
  1293. deallocallcpuregisters(list);
  1294. end
  1295. else
  1296. begin
  1297. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1298. paramanager.allocparaloc(list,cgpara2);
  1299. a_paramaddr_ref(list,href,cgpara2);
  1300. paramanager.allocparaloc(list,cgpara1);
  1301. a_paramaddr_ref(list,ref,cgpara1);
  1302. paramanager.freeparaloc(list,cgpara1);
  1303. paramanager.freeparaloc(list,cgpara2);
  1304. allocallcpuregisters(list);
  1305. a_call_name(list,'FPC_DECREF');
  1306. deallocallcpuregisters(list);
  1307. end;
  1308. cgpara2.done;
  1309. cgpara1.done;
  1310. end;
  1311. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference);
  1312. var
  1313. href : treference;
  1314. cgpara1,cgpara2 : TCGPara;
  1315. begin
  1316. cgpara1.init;
  1317. cgpara2.init;
  1318. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1319. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1320. if is_ansistring(t) or
  1321. is_widestring(t) or
  1322. is_interfacecom(t) or
  1323. is_dynamic_array(t) then
  1324. a_load_const_ref(list,OS_ADDR,0,ref)
  1325. else
  1326. begin
  1327. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1328. paramanager.allocparaloc(list,cgpara2);
  1329. a_paramaddr_ref(list,href,cgpara2);
  1330. paramanager.allocparaloc(list,cgpara1);
  1331. a_paramaddr_ref(list,ref,cgpara1);
  1332. paramanager.freeparaloc(list,cgpara1);
  1333. paramanager.freeparaloc(list,cgpara2);
  1334. allocallcpuregisters(list);
  1335. a_call_name(list,'FPC_INITIALIZE');
  1336. deallocallcpuregisters(list);
  1337. end;
  1338. cgpara1.done;
  1339. cgpara2.done;
  1340. end;
  1341. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference);
  1342. var
  1343. href : treference;
  1344. cgpara1,cgpara2 : TCGPara;
  1345. begin
  1346. cgpara1.init;
  1347. cgpara2.init;
  1348. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1349. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1350. if is_ansistring(t) or
  1351. is_widestring(t) or
  1352. is_interfacecom(t) then
  1353. begin
  1354. g_decrrefcount(list,t,ref);
  1355. a_load_const_ref(list,OS_ADDR,0,ref);
  1356. end
  1357. else
  1358. begin
  1359. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1360. paramanager.allocparaloc(list,cgpara2);
  1361. a_paramaddr_ref(list,href,cgpara2);
  1362. paramanager.allocparaloc(list,cgpara1);
  1363. a_paramaddr_ref(list,ref,cgpara1);
  1364. paramanager.freeparaloc(list,cgpara1);
  1365. paramanager.freeparaloc(list,cgpara2);
  1366. allocallcpuregisters(list);
  1367. a_call_name(list,'FPC_FINALIZE');
  1368. deallocallcpuregisters(list);
  1369. end;
  1370. cgpara1.done;
  1371. cgpara2.done;
  1372. end;
  1373. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1374. { generate range checking code for the value at location p. The type }
  1375. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1376. { is the original type used at that location. When both defs are equal }
  1377. { the check is also insert (needed for succ,pref,inc,dec) }
  1378. {$ifndef ver1_0}
  1379. const
  1380. aintmax=high(aint);
  1381. {$endif}
  1382. var
  1383. neglabel : tasmlabel;
  1384. hreg : tregister;
  1385. lto,hto,
  1386. lfrom,hfrom : TConstExprInt;
  1387. from_signed: boolean;
  1388. {$ifdef ver1_0}
  1389. aintmax : aint;
  1390. {$endif ver1_0}
  1391. begin
  1392. {$ifdef ver1_0}
  1393. {$ifdef cpu64bit}
  1394. { this is required to prevent incorrect code }
  1395. aintmax:=$7fffffff;
  1396. aintmax:=int64(aintmax shl 16) or int64($ffff);
  1397. aintmax:=int64(aintmax shl 16) or int64($ffff);
  1398. {$else cpu64bit}
  1399. aintmax:=high(aint);
  1400. {$endif cpu64bit}
  1401. {$endif}
  1402. { range checking on and range checkable value? }
  1403. if not(cs_check_range in aktlocalswitches) or
  1404. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1405. exit;
  1406. {$ifndef cpu64bit}
  1407. { handle 64bit rangechecks separate for 32bit processors }
  1408. if is_64bit(fromdef) or is_64bit(todef) then
  1409. begin
  1410. cg64.g_rangecheck64(list,l,fromdef,todef);
  1411. exit;
  1412. end;
  1413. {$endif cpu64bit}
  1414. { only check when assigning to scalar, subranges are different, }
  1415. { when todef=fromdef then the check is always generated }
  1416. getrange(fromdef,lfrom,hfrom);
  1417. getrange(todef,lto,hto);
  1418. from_signed := is_signed(fromdef);
  1419. { no range check if from and to are equal and are both longint/dword }
  1420. { (if we have a 32bit processor) or int64/qword, since such }
  1421. { operations can at most cause overflows (JM) }
  1422. { Note that these checks are mostly processor independent, they only }
  1423. { have to be changed once we introduce 64bit subrange types }
  1424. {$ifdef cpu64bit}
  1425. if (fromdef = todef) and
  1426. (fromdef.deftype=orddef) and
  1427. (((((torddef(fromdef).typ = s64bit) and
  1428. (lfrom = low(int64)) and
  1429. (hfrom = high(int64))) or
  1430. ((torddef(fromdef).typ = u64bit) and
  1431. (lfrom = low(qword)) and
  1432. (hfrom = high(qword)))))) then
  1433. exit;
  1434. {$else cpu64bit}
  1435. if (fromdef = todef) and
  1436. (fromdef.deftype=orddef) and
  1437. (((((torddef(fromdef).typ = s32bit) and
  1438. (lfrom = low(longint)) and
  1439. (hfrom = high(longint))) or
  1440. ((torddef(fromdef).typ = u32bit) and
  1441. (lfrom = low(cardinal)) and
  1442. (hfrom = high(cardinal)))))) then
  1443. exit;
  1444. {$endif cpu64bit}
  1445. { if the from-range falls completely in the to-range, no check }
  1446. { is necessary. Don't do this conversion for the largest unsigned type }
  1447. if (todef<>fromdef) and
  1448. (from_signed or (hfrom>=0)) and
  1449. (lto<=lfrom) and (hto>=hfrom) then
  1450. exit;
  1451. { generate the rangecheck code for the def where we are going to }
  1452. { store the result }
  1453. { use the trick that }
  1454. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1455. { To be able to do that, we have to make sure however that either }
  1456. { fromdef and todef are both signed or unsigned, or that we leave }
  1457. { the parts < 0 and > maxlongint out }
  1458. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1459. if from_signed xor is_signed(todef) then
  1460. begin
  1461. if from_signed then
  1462. { from is signed, to is unsigned }
  1463. begin
  1464. { if high(from) < 0 -> always range error }
  1465. if (hfrom < 0) or
  1466. { if low(to) > maxlongint also range error }
  1467. (lto > aintmax) then
  1468. begin
  1469. a_call_name(list,'FPC_RANGEERROR');
  1470. exit
  1471. end;
  1472. { from is signed and to is unsigned -> when looking at to }
  1473. { as an signed value, it must be < maxaint (otherwise }
  1474. { it will become negative, which is invalid since "to" is unsigned) }
  1475. if hto > aintmax then
  1476. hto := aintmax;
  1477. end
  1478. else
  1479. { from is unsigned, to is signed }
  1480. begin
  1481. if (lfrom > aintmax) or
  1482. (hto < 0) then
  1483. begin
  1484. a_call_name(list,'FPC_RANGEERROR');
  1485. exit
  1486. end;
  1487. { from is unsigned and to is signed -> when looking at to }
  1488. { as an unsigned value, it must be >= 0 (since negative }
  1489. { values are the same as values > maxlongint) }
  1490. if lto < 0 then
  1491. lto := 0;
  1492. end;
  1493. end;
  1494. hreg:=getintregister(list,OS_INT);
  1495. a_load_loc_reg(list,OS_INT,l,hreg);
  1496. a_op_const_reg(list,OP_SUB,OS_INT,aint(lto),hreg);
  1497. objectlibrary.getlabel(neglabel);
  1498. {
  1499. if from_signed then
  1500. a_cmp_const_reg_label(list,OS_INT,OC_GTE,aint(hto-lto),hreg,neglabel)
  1501. else
  1502. }
  1503. {$ifdef cpu64bit}
  1504. if qword(hto-lto)>qword(aintmax) then
  1505. a_cmp_const_reg_label(list,OS_INT,OC_BE,aintmax,hreg,neglabel)
  1506. else
  1507. {$endif cpu64bit}
  1508. a_cmp_const_reg_label(list,OS_INT,OC_BE,aint(hto-lto),hreg,neglabel);
  1509. a_call_name(list,'FPC_RANGEERROR');
  1510. a_label(list,neglabel);
  1511. end;
  1512. procedure tcg.g_overflowCheck_loc(List:TAasmOutput;const Loc:TLocation;def:TDef;ovloc : tlocation);
  1513. begin
  1514. g_overflowCheck(list,loc,def);
  1515. end;
  1516. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1517. var
  1518. tmpreg : tregister;
  1519. begin
  1520. tmpreg:=getintregister(list,size);
  1521. g_flags2reg(list,size,f,tmpreg);
  1522. a_load_reg_ref(list,size,size,tmpreg,ref);
  1523. end;
  1524. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1525. var
  1526. OKLabel : tasmlabel;
  1527. cgpara1 : TCGPara;
  1528. begin
  1529. if (cs_check_object in aktlocalswitches) or
  1530. (cs_check_range in aktlocalswitches) then
  1531. begin
  1532. objectlibrary.getlabel(oklabel);
  1533. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1534. cgpara1.init;
  1535. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1536. paramanager.allocparaloc(list,cgpara1);
  1537. a_param_const(list,OS_INT,210,cgpara1);
  1538. paramanager.freeparaloc(list,cgpara1);
  1539. a_call_name(list,'FPC_HANDLEERROR');
  1540. a_label(list,oklabel);
  1541. cgpara1.done;
  1542. end;
  1543. end;
  1544. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1545. var
  1546. hrefvmt : treference;
  1547. cgpara1,cgpara2 : TCGPara;
  1548. begin
  1549. cgpara1.init;
  1550. cgpara2.init;
  1551. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1552. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1553. if (cs_check_object in aktlocalswitches) then
  1554. begin
  1555. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymbol(objdef.vmt_mangledname,AB_EXTERNAL,AT_DATA),0);
  1556. paramanager.allocparaloc(list,cgpara2);
  1557. a_paramaddr_ref(list,hrefvmt,cgpara2);
  1558. paramanager.allocparaloc(list,cgpara1);
  1559. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1560. paramanager.freeparaloc(list,cgpara1);
  1561. paramanager.freeparaloc(list,cgpara2);
  1562. allocallcpuregisters(list);
  1563. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1564. deallocallcpuregisters(list);
  1565. end
  1566. else
  1567. if (cs_check_range in aktlocalswitches) then
  1568. begin
  1569. paramanager.allocparaloc(list,cgpara1);
  1570. a_param_reg(list,OS_ADDR,reg,cgpara1);
  1571. paramanager.freeparaloc(list,cgpara1);
  1572. allocallcpuregisters(list);
  1573. a_call_name(list,'FPC_CHECK_OBJECT');
  1574. deallocallcpuregisters(list);
  1575. end;
  1576. cgpara1.done;
  1577. cgpara2.done;
  1578. end;
  1579. {*****************************************************************************
  1580. Entry/Exit Code Functions
  1581. *****************************************************************************}
  1582. procedure tcg.g_copyvaluepara_openarray(list : taasmoutput;const ref:treference;const lenloc:tlocation;elesize:aint;destreg:tregister);
  1583. var
  1584. sizereg,sourcereg,lenreg : tregister;
  1585. cgpara1,cgpara2,cgpara3 : TCGPara;
  1586. begin
  1587. { because some abis don't support dynamic stack allocation properly
  1588. open array value parameters are copied onto the heap
  1589. }
  1590. { calculate necessary memory }
  1591. { read/write operations on one register make the life of the register allocator hard }
  1592. if not(lenloc.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1593. begin
  1594. lenreg:=getintregister(list,OS_INT);
  1595. a_load_loc_reg(list,OS_INT,lenloc,lenreg);
  1596. end
  1597. else
  1598. lenreg:=lenloc.register;
  1599. sizereg:=getintregister(list,OS_INT);
  1600. a_op_const_reg_reg(list,OP_ADD,OS_INT,1,lenreg,sizereg);
  1601. a_op_const_reg(list,OP_IMUL,OS_INT,elesize,sizereg);
  1602. { load source }
  1603. sourcereg:=getaddressregister(list);
  1604. a_loadaddr_ref_reg(list,ref,sourcereg);
  1605. { do getmem call }
  1606. cgpara1.init;
  1607. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1608. paramanager.allocparaloc(list,cgpara1);
  1609. a_param_reg(list,OS_INT,sizereg,cgpara1);
  1610. paramanager.freeparaloc(list,cgpara1);
  1611. allocallcpuregisters(list);
  1612. a_call_name(list,'FPC_GETMEM');
  1613. deallocallcpuregisters(list);
  1614. cgpara1.done;
  1615. { return the new address }
  1616. a_load_reg_reg(list,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,destreg);
  1617. { do move call }
  1618. cgpara1.init;
  1619. cgpara2.init;
  1620. cgpara3.init;
  1621. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1622. paramanager.getintparaloc(pocall_default,2,cgpara2);
  1623. paramanager.getintparaloc(pocall_default,3,cgpara3);
  1624. { load size }
  1625. paramanager.allocparaloc(list,cgpara3);
  1626. a_param_reg(list,OS_INT,sizereg,cgpara3);
  1627. { load destination }
  1628. paramanager.allocparaloc(list,cgpara2);
  1629. a_param_reg(list,OS_ADDR,destreg,cgpara2);
  1630. { load source }
  1631. paramanager.allocparaloc(list,cgpara1);
  1632. a_param_reg(list,OS_ADDR,sourcereg,cgpara1);
  1633. paramanager.freeparaloc(list,cgpara3);
  1634. paramanager.freeparaloc(list,cgpara2);
  1635. paramanager.freeparaloc(list,cgpara1);
  1636. allocallcpuregisters(list);
  1637. a_call_name(list,'FPC_MOVE');
  1638. deallocallcpuregisters(list);
  1639. cgpara3.done;
  1640. cgpara2.done;
  1641. cgpara1.done;
  1642. end;
  1643. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const l:tlocation);
  1644. var
  1645. cgpara1 : TCGPara;
  1646. begin
  1647. { do move call }
  1648. cgpara1.init;
  1649. paramanager.getintparaloc(pocall_default,1,cgpara1);
  1650. { load source }
  1651. paramanager.allocparaloc(list,cgpara1);
  1652. a_param_loc(list,l,cgpara1);
  1653. paramanager.freeparaloc(list,cgpara1);
  1654. allocallcpuregisters(list);
  1655. a_call_name(list,'FPC_FREEMEM');
  1656. deallocallcpuregisters(list);
  1657. cgpara1.done;
  1658. end;
  1659. procedure tcg.g_save_standard_registers(list:Taasmoutput);
  1660. var
  1661. href : treference;
  1662. size : longint;
  1663. r : integer;
  1664. begin
  1665. { Get temp }
  1666. size:=0;
  1667. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1668. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1669. inc(size,sizeof(aint));
  1670. if size>0 then
  1671. begin
  1672. tg.GetTemp(list,size,tt_noreuse,current_procinfo.save_regs_ref);
  1673. { Copy registers to temp }
  1674. href:=current_procinfo.save_regs_ref;
  1675. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1676. begin
  1677. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1678. begin
  1679. a_load_reg_ref(list,OS_ADDR,OS_ADDR,newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE),href);
  1680. inc(href.offset,sizeof(aint));
  1681. end;
  1682. include(rg[R_INTREGISTER].preserved_by_proc,saved_standard_registers[r]);
  1683. end;
  1684. end;
  1685. end;
  1686. procedure tcg.g_restore_standard_registers(list:Taasmoutput);
  1687. var
  1688. href : treference;
  1689. r : integer;
  1690. hreg : tregister;
  1691. begin
  1692. { Copy registers from temp }
  1693. href:=current_procinfo.save_regs_ref;
  1694. for r:=low(saved_standard_registers) to high(saved_standard_registers) do
  1695. if saved_standard_registers[r] in rg[R_INTREGISTER].used_in_proc then
  1696. begin
  1697. hreg:=newreg(R_INTREGISTER,saved_standard_registers[r],R_SUBWHOLE);
  1698. { Allocate register so the optimizer does remove the load }
  1699. a_reg_alloc(list,hreg);
  1700. a_load_ref_reg(list,OS_ADDR,OS_ADDR,href,hreg);
  1701. inc(href.offset,sizeof(aint));
  1702. end;
  1703. tg.UnGetTemp(list,current_procinfo.save_regs_ref);
  1704. end;
  1705. procedure tcg.g_profilecode(list : taasmoutput);
  1706. begin
  1707. end;
  1708. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1709. begin
  1710. a_load_reg_ref(list, OS_INT, OS_INT, NR_FUNCTION_RESULT_REG, href);
  1711. end;
  1712. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aint);
  1713. begin
  1714. a_load_const_ref(list, OS_INT, a, href);
  1715. end;
  1716. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1717. begin
  1718. a_load_ref_reg(list, OS_INT, OS_INT, href, NR_FUNCTION_RESULT_REG);
  1719. end;
  1720. procedure tcg.g_adjust_self_value(list:taasmoutput;procdef: tprocdef;ioffset: aint);
  1721. var
  1722. hsym : tsym;
  1723. href : treference;
  1724. paraloc : tcgparalocation;
  1725. begin
  1726. { calculate the parameter info for the procdef }
  1727. if not procdef.has_paraloc_info then
  1728. begin
  1729. procdef.requiredargarea:=paramanager.create_paraloc_info(procdef,callerside);
  1730. procdef.has_paraloc_info:=true;
  1731. end;
  1732. hsym:=tsym(procdef.parast.search('self'));
  1733. if not(assigned(hsym) and
  1734. (hsym.typ=paravarsym)) then
  1735. internalerror(200305251);
  1736. paraloc:=tparavarsym(hsym).paraloc[callerside].location^;
  1737. case paraloc.loc of
  1738. LOC_REGISTER:
  1739. cg.a_op_const_reg(list,OP_SUB,paraloc.size,ioffset,paraloc.register);
  1740. LOC_REFERENCE:
  1741. begin
  1742. { offset in the wrapper needs to be adjusted for the stored
  1743. return address }
  1744. reference_reset_base(href,paraloc.reference.index,paraloc.reference.offset+sizeof(aint));
  1745. cg.a_op_const_ref(list,OP_SUB,paraloc.size,ioffset,href);
  1746. end
  1747. else
  1748. internalerror(200309189);
  1749. end;
  1750. end;
  1751. {*****************************************************************************
  1752. TCG64
  1753. *****************************************************************************}
  1754. {$ifndef cpu64bit}
  1755. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64; regsrc,regdst : tregister64);
  1756. begin
  1757. a_load64_reg_reg(list,regsrc,regdst);
  1758. a_op64_const_reg(list,op,size,value,regdst);
  1759. end;
  1760. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64);
  1761. var
  1762. tmpreg64 : tregister64;
  1763. begin
  1764. { when src1=dst then we need to first create a temp to prevent
  1765. overwriting src1 with src2 }
  1766. if (regsrc1.reghi=regdst.reghi) or
  1767. (regsrc1.reglo=regdst.reghi) or
  1768. (regsrc1.reghi=regdst.reglo) or
  1769. (regsrc1.reglo=regdst.reglo) then
  1770. begin
  1771. tmpreg64.reglo:=cg.getintregister(list,OS_32);
  1772. tmpreg64.reghi:=cg.getintregister(list,OS_32);
  1773. a_load64_reg_reg(list,regsrc2,tmpreg64);
  1774. a_op64_reg_reg(list,op,size,regsrc1,tmpreg64);
  1775. a_load64_reg_reg(list,tmpreg64,regdst);
  1776. end
  1777. else
  1778. begin
  1779. a_load64_reg_reg(list,regsrc2,regdst);
  1780. a_op64_reg_reg(list,op,size,regsrc1,regdst);
  1781. end;
  1782. end;
  1783. procedure tcg64.a_op64_const_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;value : int64;regsrc,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1784. begin
  1785. a_op64_const_reg_reg(list,op,size,value,regsrc,regdst);
  1786. ovloc.loc:=LOC_VOID;
  1787. end;
  1788. procedure tcg64.a_op64_reg_reg_reg_checkoverflow(list: taasmoutput;op:TOpCG;size : tcgsize;regsrc1,regsrc2,regdst : tregister64;setflags : boolean;var ovloc : tlocation);
  1789. begin
  1790. a_op64_reg_reg_reg(list,op,size,regsrc1,regsrc2,regdst);
  1791. ovloc.loc:=LOC_VOID;
  1792. end;
  1793. {$endif cpu64bit}
  1794. initialization
  1795. ;
  1796. finalization
  1797. cg.free;
  1798. {$ifndef cpu64bit}
  1799. cg64.free;
  1800. {$endif cpu64bit}
  1801. end.