cgobj.pas 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Member of the Free Pascal development team
  5. This unit implements the basic code generator object
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {# @abstract(Abstract code generator unit)
  20. Abstreact code generator unit. This contains the base class
  21. to implement for all new supported processors.
  22. WARNING: None of the routines implemented in these modules,
  23. or their descendants, should use the temp. allocator, as
  24. these routines may be called inside genentrycode, and the
  25. stack frame is already setup!
  26. }
  27. unit cgobj;
  28. {$i fpcdefs.inc}
  29. interface
  30. uses
  31. {$ifdef delphi}
  32. dmisc,
  33. {$endif}
  34. cclasses,
  35. cpubase,cpuinfo,cgbase,
  36. aasmbase,aasmtai,aasmcpu,
  37. symconst,symbase,symtype,symdef,symtable,rgobj
  38. ;
  39. type
  40. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  41. {# @abstract(Abstract code generator)
  42. This class implements an abstract instruction generator. Some of
  43. the methods of this class are generic, while others must
  44. be overriden for all new processors which will be supported
  45. by Free Pascal. For 32-bit processors, the base class
  46. sould be @link(tcg64f32) and not @var(tcg).
  47. }
  48. tcg = class
  49. alignment : talignment;
  50. t_times:cardinal;
  51. {************************************************}
  52. { basic routines }
  53. constructor create;
  54. {# Initialize the register allocators needed for the codegenerator.}
  55. procedure init_register_allocators;virtual;abstract;
  56. {# Clean up the register allocators needed for the codegenerator.}
  57. procedure done_register_allocators;virtual;abstract;
  58. {# Gets a register suitable to do integer operations on.}
  59. function getintregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  60. {# Gets a register suitable to do integer operations on.}
  61. function getaddressregister(list:Taasmoutput):Tregister;virtual;
  62. function getfpuregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  63. function getmmregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  64. function getflagregister(list:Taasmoutput;size:Tcgsize):Tregister;virtual;abstract;
  65. {Does the generic cg need SIMD registers, like getmmxregister? Or should
  66. the cpu specific child cg object have such a method?}
  67. procedure ungetregister(list:Taasmoutput;r:Tregister);virtual;abstract;
  68. procedure ungetreference(list:Taasmoutput;const r:Treference);virtual;
  69. procedure add_move_instruction(instr:Taicpu);virtual;abstract;
  70. function uses_registers(rt:Tregistertype):boolean;virtual;abstract;
  71. {# Get a specific register.}
  72. procedure getexplicitregister(list:Taasmoutput;r:Tregister);virtual;abstract;
  73. {# Get multiple registers specified.}
  74. procedure allocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;abstract;
  75. {# Free multiple registers specified.}
  76. procedure deallocexplicitregisters(list:Taasmoutput;rt:Tregistertype;r:Tcpuregisterset);virtual;abstract;
  77. procedure do_register_allocation(list:Taasmoutput;headertai:tai);virtual;abstract;
  78. function makeregsize(reg:Tregister;size:Tcgsize):Tregister;
  79. {# Returns the tcgsize corresponding with the size of reg.}
  80. class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
  81. {# Emit a label to the instruction stream. }
  82. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  83. {# Allocates register r by inserting a pai_realloc record }
  84. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  85. {# Deallocates register r by inserting a pa_regdealloc record}
  86. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  87. {# Pass a parameter, which is located in a register, to a routine.
  88. This routine should push/send the parameter to the routine, as
  89. required by the specific processor ABI and routine modifiers.
  90. This must be overriden for each CPU target.
  91. @param(size size of the operand in the register)
  92. @param(r register source of the operand)
  93. @param(locpara where the parameter will be stored)
  94. }
  95. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);virtual;
  96. {# Pass a parameter, which is a constant, to a routine.
  97. A generic version is provided. This routine should
  98. be overriden for optimization purposes if the cpu
  99. permits directly sending this type of parameter.
  100. @param(size size of the operand in constant)
  101. @param(a value of constant to send)
  102. @param(locpara where the parameter will be stored)
  103. }
  104. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);virtual;
  105. {# Pass the value of a parameter, which is located in memory, to a routine.
  106. A generic version is provided. This routine should
  107. be overriden for optimization purposes if the cpu
  108. permits directly sending this type of parameter.
  109. @param(size size of the operand in constant)
  110. @param(r Memory reference of value to send)
  111. @param(locpara where the parameter will be stored)
  112. }
  113. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);virtual;
  114. {# Pass the value of a parameter, which can be located either in a register or memory location,
  115. to a routine.
  116. A generic version is provided.
  117. @param(l location of the operand to send)
  118. @param(nr parameter number (starting from one) of routine (from left to right))
  119. @param(locpara where the parameter will be stored)
  120. }
  121. procedure a_param_loc(list : taasmoutput;const l : tlocation;const locpara : tparalocation);
  122. {# Pass the address of a reference to a routine. This routine
  123. will calculate the address of the reference, and pass this
  124. calculated address as a parameter.
  125. A generic version is provided. This routine should
  126. be overriden for optimization purposes if the cpu
  127. permits directly sending this type of parameter.
  128. @param(r reference to get address from)
  129. @param(nr parameter number (starting from one) of routine (from left to right))
  130. }
  131. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);virtual;
  132. { Copies a whole memory block to the stack, the locpara must be a memory location }
  133. procedure a_param_copy_ref(list : taasmoutput;size : qword;const r : treference;const locpara : tparalocation);
  134. { Remarks:
  135. * If a method specifies a size you have only to take care
  136. of that number of bits, i.e. load_const_reg with OP_8 must
  137. only load the lower 8 bit of the specified register
  138. the rest of the register can be undefined
  139. if necessary the compiler will call a method
  140. to zero or sign extend the register
  141. * The a_load_XX_XX with OP_64 needn't to be
  142. implemented for 32 bit
  143. processors, the code generator takes care of that
  144. * the addr size is for work with the natural pointer
  145. size
  146. * the procedures without fpu/mm are only for integer usage
  147. * normally the first location is the source and the
  148. second the destination
  149. }
  150. { Copy a parameter to a (temporary) reference }
  151. procedure a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);virtual;
  152. { Copy a parameter to a register }
  153. procedure a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);virtual;
  154. {# Emits instruction to call the method specified by symbol name.
  155. This routine must be overriden for each new target cpu.
  156. There is no a_call_ref because loading the reference will use
  157. a temp register on most cpu's resulting in conflicts with the
  158. registers used for the parameters (PFV)
  159. }
  160. procedure a_call_name(list : taasmoutput;const s : string);virtual; abstract;
  161. procedure a_call_reg(list : taasmoutput;reg : tregister);virtual;abstract;
  162. { move instructions }
  163. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);virtual; abstract;
  164. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);virtual;
  165. procedure a_load_const_loc(list : taasmoutput;a : aword;const loc : tlocation);
  166. procedure a_load_reg_ref(list : taasmoutput;fromsize,tosize : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  167. procedure a_load_reg_reg(list : taasmoutput;fromsize,tosize : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  168. procedure a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  169. procedure a_load_ref_reg(list : taasmoutput;fromsize,tosize : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  170. procedure a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);virtual;
  171. procedure a_load_loc_reg(list : taasmoutput;tosize: tcgsize; const loc: tlocation; reg : tregister);
  172. procedure a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  173. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  174. { fpu move instructions }
  175. procedure a_loadfpu_reg_reg(list: taasmoutput; size:tcgsize; reg1, reg2: tregister); virtual; abstract;
  176. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  177. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  178. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  179. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  180. procedure a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);virtual;
  181. procedure a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);virtual;
  182. { vector register move instructions }
  183. procedure a_loadmm_reg_reg(list: taasmoutput; fromsize, tosize : tcgsize;reg1, reg2: tregister;shuffle : pmmshuffle); virtual; abstract;
  184. procedure a_loadmm_ref_reg(list: taasmoutput; fromsize, tosize : tcgsize;const ref: treference; reg: tregister;shuffle : pmmshuffle); virtual; abstract;
  185. procedure a_loadmm_reg_ref(list: taasmoutput; fromsize, tosize : tcgsize;reg: tregister; const ref: treference;shuffle : pmmshuffle); virtual; abstract;
  186. procedure a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  187. procedure a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  188. procedure a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  189. procedure a_parammm_ref(list: taasmoutput; size: tcgsize; ref: treference;const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  190. procedure a_parammm_loc(list: taasmoutput; loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle); virtual;
  191. { basic arithmetic operations }
  192. { note: for operators which require only one argument (not, neg), use }
  193. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  194. { that in this case the *second* operand is used as both source and }
  195. { destination (JM) }
  196. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; reg: TRegister); virtual; abstract;
  197. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); virtual;
  198. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  199. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  200. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  201. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  202. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  203. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  204. { trinary operations for processors that support them, 'emulated' }
  205. { on others. None with "ref" arguments since I don't think there }
  206. { are any processors that support it (JM) }
  207. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  208. size: tcgsize; a: aword; src, dst: tregister); virtual;
  209. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  210. size: tcgsize; src1, src2, dst: tregister); virtual;
  211. { comparison operations }
  212. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  213. l : tasmlabel);virtual; abstract;
  214. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  215. l : tasmlabel); virtual;
  216. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aword; const loc: tlocation;
  217. l : tasmlabel);
  218. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  219. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  220. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  221. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  222. l : tasmlabel);
  223. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  224. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  225. {# Depending on the value to check in the flags, either sets the register reg to one (if the flag is set)
  226. or zero (if the flag is cleared). The size parameter indicates the destination size register.
  227. }
  228. procedure g_flags2reg(list: taasmoutput; size: TCgSize; const f: tresflags; reg: TRegister); virtual; abstract;
  229. procedure g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference); virtual;
  230. {
  231. This routine tries to optimize the const_reg opcode, and should be
  232. called at the start of a_op_const_reg. It returns the actual opcode
  233. to emit, and the constant value to emit. If this routine returns
  234. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  235. @param(op The opcode to emit, returns the opcode which must be emitted)
  236. @param(a The constant which should be emitted, returns the constant which must
  237. be emitted)
  238. @param(reg The register to emit the opcode with, returns the register with
  239. which the opcode will be emitted)
  240. }
  241. function optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg: tregister): boolean;virtual;
  242. {#
  243. This routine is used in exception management nodes. It should
  244. save the exception reason currently in the FUNCTION_RETURN_REG. The
  245. save should be done either to a temp (pointed to by href).
  246. or on the stack (pushing the value on the stack).
  247. The size of the value to save is OS_S32. The default version
  248. saves the exception reason to a temp. memory area.
  249. }
  250. procedure g_exception_reason_save(list : taasmoutput; const href : treference);virtual;
  251. {#
  252. This routine is used in exception management nodes. It should
  253. save the exception reason constant. The
  254. save should be done either to a temp (pointed to by href).
  255. or on the stack (pushing the value on the stack).
  256. The size of the value to save is OS_S32. The default version
  257. saves the exception reason to a temp. memory area.
  258. }
  259. procedure g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);virtual;
  260. {#
  261. This routine is used in exception management nodes. It should
  262. load the exception reason to the FUNCTION_RETURN_REG. The saved value
  263. should either be in the temp. area (pointed to by href , href should
  264. *NOT* be freed) or on the stack (the value should be popped).
  265. The size of the value to save is OS_S32. The default version
  266. saves the exception reason to a temp. memory area.
  267. }
  268. procedure g_exception_reason_load(list : taasmoutput; const href : treference);virtual;
  269. procedure g_maybe_testself(list : taasmoutput;reg:tregister);
  270. procedure g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  271. {# This should emit the opcode to copy len bytes from the source
  272. to destination, if loadref is true, it assumes that it first must load
  273. the source address from the memory location where
  274. source points to.
  275. It must be overriden for each new target processor.
  276. @param(source Source reference of copy)
  277. @param(dest Destination reference of copy)
  278. @param(delsource Indicates if the source reference's resources should be freed)
  279. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  280. }
  281. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);virtual; abstract;
  282. {# This should emit the opcode to a shortrstring from the source
  283. to destination, if loadref is true, it assumes that it first must load
  284. the source address from the memory location where
  285. source points to.
  286. @param(source Source reference of copy)
  287. @param(dest Destination reference of copy)
  288. @param(delsource Indicates if the source reference's resources should be freed)
  289. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  290. }
  291. procedure g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  292. procedure g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  293. procedure g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  294. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  295. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  296. {# Emits the call to the stack checking routine of
  297. the runtime library. The default behavior
  298. does not need to be modified, as it is generic
  299. for all platforms.
  300. @param(stackframesize Number of bytes which will be allocated on the stack)
  301. }
  302. procedure g_stackcheck(list : taasmoutput;stackframesize : longint);virtual;
  303. {# Generates range checking code. It is to note
  304. that this routine does not need to be overriden,
  305. as it takes care of everything.
  306. @param(p Node which contains the value to check)
  307. @param(todef Type definition of node to range check)
  308. }
  309. procedure g_rangecheck(list: taasmoutput; const l:tlocation; fromdef,todef: tdef); virtual;
  310. {# Generates overflow checking code for a node }
  311. procedure g_overflowcheck(list: taasmoutput; const l:tlocation; def:tdef); virtual; abstract;
  312. procedure g_copyvaluepara_openarray(list : taasmoutput;const ref, lenref:treference;elesize:aword);virtual;abstract;
  313. procedure g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);virtual;
  314. {# Emits instructions which should be emitted when entering
  315. a routine declared as @var(interrupt). The default
  316. behavior does nothing, should be overriden as required.
  317. }
  318. procedure g_interrupt_stackframe_entry(list : taasmoutput);virtual;
  319. {# Emits instructions which should be emitted when exiting
  320. a routine declared as @var(interrupt). The default
  321. behavior does nothing, should be overriden as required.
  322. }
  323. procedure g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);virtual;
  324. {# Emits instructions when compilation is done in profile
  325. mode (this is set as a command line option). The default
  326. behavior does nothing, should be overriden as required.
  327. }
  328. procedure g_profilecode(list : taasmoutput);virtual;
  329. {# Emits instruction for allocating @var(size) bytes at the stackpointer
  330. @param(size Number of bytes to allocate)
  331. }
  332. procedure g_stackpointer_alloc(list : taasmoutput;size : longint);virtual; abstract;
  333. {# Emits instruction for allocating the locals in entry
  334. code of a routine. This is one of the first
  335. routine called in @var(genentrycode).
  336. @param(localsize Number of bytes to allocate as locals)
  337. }
  338. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);virtual; abstract;
  339. {# Emits instructiona for restoring the frame pointer
  340. at routine exit. For some processors, this routine
  341. may do nothing at all.
  342. }
  343. procedure g_restore_frame_pointer(list : taasmoutput);virtual; abstract;
  344. {# Emits instructions for returning from a subroutine.
  345. Should also restore the stack.
  346. @param(parasize Number of bytes of parameters to deallocate from stack)
  347. }
  348. procedure g_return_from_proc(list : taasmoutput;parasize : aword);virtual; abstract;
  349. {# This routine is called when generating the code for the entry point
  350. of a routine. It should save all registers which are not used in this
  351. routine, and which should be declared as saved in the std_saved_registers
  352. set.
  353. This routine is mainly used when linking to code which is generated
  354. by ABI-compliant compilers (like GCC), to make sure that the reserved
  355. registers of that ABI are not clobbered.
  356. @param(usedinproc Registers which are used in the code of this routine)
  357. }
  358. procedure g_save_standard_registers(list:Taasmoutput);virtual;abstract;
  359. {# This routine is called when generating the code for the exit point
  360. of a routine. It should restore all registers which were previously
  361. saved in @var(g_save_standard_registers).
  362. @param(usedinproc Registers which are used in the code of this routine)
  363. }
  364. procedure g_restore_standard_registers(list:Taasmoutput);virtual;abstract;
  365. procedure g_save_all_registers(list : taasmoutput);virtual;abstract;
  366. procedure g_restore_all_registers(list : taasmoutput;accused,acchiused:boolean);virtual;abstract;
  367. end;
  368. {# @abstract(Abstract code generator for 64 Bit operations)
  369. This class implements an abstract code generator class
  370. for 64 Bit operations.
  371. }
  372. tcg64 = class
  373. { Allocates 64 Bit register r by inserting a pai_realloc record }
  374. procedure a_reg_alloc(list : taasmoutput;r : tregister64);virtual;abstract;
  375. { Deallocates 64 Bit register r by inserting a pa_regdealloc record}
  376. procedure a_reg_dealloc(list : taasmoutput;r : tregister64);virtual;abstract;
  377. procedure a_load64_const_ref(list : taasmoutput;value : qword;const ref : treference);virtual;abstract;
  378. procedure a_load64_reg_ref(list : taasmoutput;reg : tregister64;const ref : treference);virtual;abstract;
  379. procedure a_load64_ref_reg(list : taasmoutput;const ref : treference;reg : tregister64;delete : boolean);virtual;abstract;
  380. procedure a_load64_reg_reg(list : taasmoutput;regsrc,regdst : tregister64;delete : boolean);virtual;abstract;
  381. procedure a_load64_const_reg(list : taasmoutput;value : qword;reg : tregister64);virtual;abstract;
  382. procedure a_load64_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister64;delete : boolean);virtual;abstract;
  383. procedure a_load64_loc_ref(list : taasmoutput;const l : tlocation;const ref : treference);virtual;abstract;
  384. procedure a_load64_const_loc(list : taasmoutput;value : qword;const l : tlocation);virtual;abstract;
  385. procedure a_load64_reg_loc(list : taasmoutput;reg : tregister64;const l : tlocation);virtual;abstract;
  386. procedure a_load64high_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  387. procedure a_load64low_reg_ref(list : taasmoutput;reg : tregister;const ref : treference);virtual;abstract;
  388. procedure a_load64high_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  389. procedure a_load64low_ref_reg(list : taasmoutput;const ref : treference;reg : tregister);virtual;abstract;
  390. procedure a_load64high_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  391. procedure a_load64low_loc_reg(list : taasmoutput;const l : tlocation;reg : tregister);virtual;abstract;
  392. procedure a_op64_ref_reg(list : taasmoutput;op:TOpCG;const ref : treference;reg : tregister64);virtual;abstract;
  393. procedure a_op64_reg_reg(list : taasmoutput;op:TOpCG;regsrc,regdst : tregister64);virtual;abstract;
  394. procedure a_op64_reg_ref(list : taasmoutput;op:TOpCG;regsrc : tregister64;const ref : treference);virtual;abstract;
  395. procedure a_op64_const_reg(list : taasmoutput;op:TOpCG;value : qword;regdst : tregister64);virtual;abstract;
  396. procedure a_op64_const_ref(list : taasmoutput;op:TOpCG;value : qword;const ref : treference);virtual;abstract;
  397. procedure a_op64_const_loc(list : taasmoutput;op:TOpCG;value : qword;const l: tlocation);virtual;abstract;
  398. procedure a_op64_reg_loc(list : taasmoutput;op:TOpCG;reg : tregister64;const l : tlocation);virtual;abstract;
  399. procedure a_op64_loc_reg(list : taasmoutput;op:TOpCG;const l : tlocation;reg64 : tregister64);virtual;abstract;
  400. procedure a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword;regsrc,regdst : tregister64);virtual;
  401. procedure a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);virtual;
  402. procedure a_param64_reg(list : taasmoutput;reg64 : tregister64;const loc : tparalocation);virtual;abstract;
  403. procedure a_param64_const(list : taasmoutput;value : qword;const loc : tparalocation);virtual;abstract;
  404. procedure a_param64_ref(list : taasmoutput;const r : treference;const loc : tparalocation);virtual;abstract;
  405. procedure a_param64_loc(list : taasmoutput;const l : tlocation;const loc : tparalocation);virtual;abstract;
  406. {
  407. This routine tries to optimize the const_reg opcode, and should be
  408. called at the start of a_op64_const_reg. It returns the actual opcode
  409. to emit, and the constant value to emit. If this routine returns
  410. TRUE, @var(no) instruction should be emitted (.eg : imul reg by 1 )
  411. @param(op The opcode to emit, returns the opcode which must be emitted)
  412. @param(a The constant which should be emitted, returns the constant which must
  413. be emitted)
  414. @param(reg The register to emit the opcode with, returns the register with
  415. which the opcode will be emitted)
  416. }
  417. function optimize64_op_const_reg(list: taasmoutput; var op: topcg; var a : qword; var reg: tregister64): boolean;virtual;abstract;
  418. { override to catch 64bit rangechecks }
  419. procedure g_rangecheck64(list: taasmoutput; const l:tlocation; fromdef,todef: tdef);virtual;abstract;
  420. end;
  421. { trerefence handling }
  422. {# Clear to zero a treference }
  423. procedure reference_reset(var ref : treference);
  424. {# Clear to zero a treference, and set is base address
  425. to base register.
  426. }
  427. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  428. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  429. procedure reference_release(list: taasmoutput; const ref : treference);
  430. { This routine verifies if two references are the same, and
  431. if so, returns TRUE, otherwise returns false.
  432. }
  433. function references_equal(sref : treference;dref : treference) : boolean;
  434. { tlocation handling }
  435. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  436. procedure location_release(list: taasmoutput; const l : tlocation);
  437. procedure location_freetemp(list: taasmoutput; const l : tlocation);
  438. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  439. procedure location_swap(var destloc,sourceloc : tlocation);
  440. var
  441. {# Main code generator class }
  442. cg : tcg;
  443. {# Code generator class for all operations working with 64-Bit operands }
  444. cg64 : tcg64;
  445. implementation
  446. uses
  447. globals,globtype,options,systems,
  448. verbose,defutil,paramgr,
  449. tgobj,cutils;
  450. const
  451. { Please leave this here, this module should NOT use
  452. exprasmlist, the lists are always passed as arguments.
  453. Declaring it as string here results in an error when compiling (PFV) }
  454. exprasmlist = 'error';
  455. {*****************************************************************************
  456. basic functionallity
  457. ******************************************************************************}
  458. constructor tcg.create;
  459. begin
  460. end;
  461. function Tcg.makeregsize(reg:Tregister;size:Tcgsize):Tregister;
  462. var subreg:Tsubregister;
  463. begin
  464. subreg:=cgsize2subreg(size);
  465. result:=reg;
  466. setsubreg(result,subreg);
  467. end;
  468. function tcg.getaddressregister(list:Taasmoutput):Tregister;
  469. begin
  470. result:=getintregister(list,OS_ADDR);
  471. end;
  472. procedure tcg.ungetreference(list:Taasmoutput;const r:Treference);
  473. begin
  474. if r.base<>NR_NO then
  475. ungetregister(list,r.base);
  476. end;
  477. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  478. begin
  479. list.concat(tai_regalloc.alloc(r));
  480. end;
  481. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  482. begin
  483. list.concat(tai_regalloc.dealloc(r));
  484. end;
  485. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  486. begin
  487. list.concat(tai_label.create(l));
  488. end;
  489. {*****************************************************************************
  490. for better code generation these methods should be overridden
  491. ******************************************************************************}
  492. procedure tcg.a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;const locpara : tparalocation);
  493. var
  494. ref : treference;
  495. begin
  496. case locpara.loc of
  497. LOC_REGISTER,LOC_CREGISTER:
  498. a_load_reg_reg(list,size,locpara.size,r,locpara.register);
  499. LOC_REFERENCE,LOC_CREFERENCE:
  500. begin
  501. reference_reset(ref);
  502. ref.base:=locpara.reference.index;
  503. ref.offset:=locpara.reference.offset;
  504. a_load_reg_ref(list,size,size,r,ref);
  505. end
  506. else
  507. internalerror(2002071004);
  508. end;
  509. end;
  510. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aword;const locpara : tparalocation);
  511. var
  512. hr : tregister;
  513. begin
  514. hr:=getintregister(list,size);
  515. a_load_const_reg(list,size,a,hr);
  516. ungetregister(list,hr);
  517. a_param_reg(list,size,hr,locpara);
  518. end;
  519. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;const locpara : tparalocation);
  520. var
  521. hr : tregister;
  522. begin
  523. hr:=getintregister(list,size);
  524. a_load_ref_reg(list,size,size,r,hr);
  525. ungetregister(list,hr);
  526. a_param_reg(list,size,hr,locpara);
  527. end;
  528. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;const locpara : tparalocation);
  529. begin
  530. case l.loc of
  531. LOC_REGISTER,
  532. LOC_CREGISTER :
  533. a_param_reg(list,l.size,l.register,locpara);
  534. LOC_CONSTANT :
  535. a_param_const(list,l.size,l.value,locpara);
  536. LOC_CREFERENCE,
  537. LOC_REFERENCE :
  538. a_param_ref(list,l.size,l.reference,locpara);
  539. else
  540. internalerror(2002032211);
  541. end;
  542. end;
  543. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;const locpara : tparalocation);
  544. var
  545. hr : tregister;
  546. begin
  547. hr:=getaddressregister(list);
  548. a_loadaddr_ref_reg(list,r,hr);
  549. ungetregister(list,hr);
  550. a_param_reg(list,OS_ADDR,hr,locpara);
  551. end;
  552. procedure tcg.a_param_copy_ref(list : taasmoutput;size : qword;const r : treference;const locpara : tparalocation);
  553. var
  554. ref : treference;
  555. begin
  556. if not(locpara.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  557. internalerror(2003010901);
  558. reference_reset_base(ref,locpara.reference.index,locpara.reference.offset);
  559. g_concatcopy(list,r,ref,size,false,false);
  560. end;
  561. procedure tcg.a_loadany_param_ref(list : taasmoutput;const locpara : tparalocation;const ref:treference;shuffle : pmmshuffle);
  562. begin
  563. case locpara.loc of
  564. LOC_CREGISTER,
  565. LOC_REGISTER:
  566. begin
  567. if (locpara.size in [OS_S64,OS_64]) then
  568. begin
  569. {$ifdef cpu64bit}
  570. ungetregisterint(list,locpara.register64);
  571. {$else cpu64bit}
  572. getexplicitregister(list,locpara.registerlow);
  573. getexplicitregister(list,locpara.registerhigh);
  574. ungetregister(list,locpara.registerlow);
  575. ungetregister(list,locpara.registerhigh);
  576. {$endif cpu64bit}
  577. cg64.a_load64_reg_ref(list,locpara.register64,ref)
  578. end
  579. else
  580. begin
  581. getexplicitregister(list,locpara.register);
  582. ungetregister(list,locpara.register);
  583. a_load_reg_ref(list,locpara.size,locpara.size,locpara.register,ref);
  584. end;
  585. end;
  586. LOC_MMREGISTER,
  587. LOC_CMMREGISTER:
  588. begin
  589. getexplicitregister(list,locpara.register);
  590. ungetregister(list,locpara.register);
  591. a_loadmm_reg_ref(list,locpara.size,locpara.size,locpara.register,ref,shuffle);
  592. end;
  593. LOC_FPUREGISTER,
  594. LOC_CFPUREGISTER:
  595. begin
  596. getexplicitregister(list,locpara.register);
  597. ungetregister(list,locpara.register);
  598. a_loadfpu_reg_ref(list,locpara.size,locpara.register,ref);
  599. end;
  600. else
  601. internalerror(2002081302);
  602. end;
  603. end;
  604. procedure tcg.a_loadany_param_reg(list : taasmoutput;const locpara : tparalocation;const reg:tregister;shuffle : pmmshuffle);
  605. var
  606. href : treference;
  607. begin
  608. case locpara.loc of
  609. LOC_CREGISTER,
  610. LOC_REGISTER:
  611. begin
  612. if not(locpara.size in [OS_S64,OS_64]) then
  613. begin
  614. getexplicitregister(list,locpara.register);
  615. ungetregister(list,locpara.register);
  616. getexplicitregister(list,reg);
  617. a_load_reg_reg(list,locpara.size,locpara.size,locpara.register,reg)
  618. end
  619. else
  620. internalerror(2003053011);
  621. end;
  622. LOC_CFPUREGISTER,
  623. LOC_FPUREGISTER:
  624. begin
  625. getexplicitregister(list,locpara.register);
  626. ungetregister(list,locpara.register);
  627. getexplicitregister(list,reg);
  628. a_loadfpu_reg_reg(list,locpara.size,locpara.register,reg);
  629. end;
  630. LOC_MMREGISTER,
  631. LOC_CMMREGISTER:
  632. begin
  633. getexplicitregister(list,locpara.register);
  634. ungetregister(list,locpara.register);
  635. getexplicitregister(list,reg);
  636. a_loadmm_reg_reg(list,locpara.size,locpara.size,locpara.register,reg,shuffle);
  637. end;
  638. LOC_REFERENCE,
  639. LOC_CREFERENCE:
  640. begin
  641. reference_reset_base(href,locpara.reference.index,locpara.reference.offset);
  642. getexplicitregister(list,reg);
  643. a_load_ref_reg(list,locpara.size,locpara.size,href,reg);
  644. end;
  645. else
  646. internalerror(2003053010);
  647. end
  648. end;
  649. {****************************************************************************
  650. some generic implementations
  651. ****************************************************************************}
  652. procedure tcg.a_load_ref_ref(list : taasmoutput;fromsize,tosize : tcgsize;const sref : treference;const dref : treference);
  653. var
  654. tmpreg: tregister;
  655. begin
  656. { verify if we have the same reference }
  657. if references_equal(sref,dref) then
  658. exit;
  659. tmpreg:=getintregister(list,tosize);
  660. a_load_ref_reg(list,fromsize,tosize,sref,tmpreg);
  661. a_load_reg_ref(list,tosize,tosize,tmpreg,dref);
  662. ungetregister(list,tmpreg);
  663. end;
  664. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);
  665. var
  666. tmpreg: tregister;
  667. begin
  668. tmpreg:=getintregister(list,size);
  669. a_load_const_reg(list,size,a,tmpreg);
  670. a_load_reg_ref(list,size,size,tmpreg,ref);
  671. ungetregister(list,tmpreg);
  672. end;
  673. procedure tcg.a_load_const_loc(list : taasmoutput;a : aword;const loc: tlocation);
  674. begin
  675. case loc.loc of
  676. LOC_REFERENCE,LOC_CREFERENCE:
  677. a_load_const_ref(list,loc.size,a,loc.reference);
  678. LOC_REGISTER,LOC_CREGISTER:
  679. a_load_const_reg(list,loc.size,a,loc.register);
  680. else
  681. internalerror(200203272);
  682. end;
  683. end;
  684. procedure tcg.a_load_reg_loc(list : taasmoutput;fromsize : tcgsize;reg : tregister;const loc: tlocation);
  685. begin
  686. case loc.loc of
  687. LOC_REFERENCE,LOC_CREFERENCE:
  688. a_load_reg_ref(list,fromsize,loc.size,reg,loc.reference);
  689. LOC_REGISTER,LOC_CREGISTER:
  690. a_load_reg_reg(list,fromsize,loc.size,reg,loc.register);
  691. else
  692. internalerror(200203271);
  693. end;
  694. end;
  695. procedure tcg.a_load_loc_reg(list : taasmoutput; tosize: tcgsize; const loc: tlocation; reg : tregister);
  696. begin
  697. case loc.loc of
  698. LOC_REFERENCE,LOC_CREFERENCE:
  699. a_load_ref_reg(list,loc.size,tosize,loc.reference,reg);
  700. LOC_REGISTER,LOC_CREGISTER:
  701. a_load_reg_reg(list,loc.size,tosize,loc.register,reg);
  702. LOC_CONSTANT:
  703. a_load_const_reg(list,tosize,loc.value,reg);
  704. else
  705. internalerror(200109092);
  706. end;
  707. end;
  708. procedure tcg.a_load_loc_ref(list : taasmoutput;tosize: tcgsize; const loc: tlocation; const ref : treference);
  709. begin
  710. case loc.loc of
  711. LOC_REFERENCE,LOC_CREFERENCE:
  712. a_load_ref_ref(list,loc.size,tosize,loc.reference,ref);
  713. LOC_REGISTER,LOC_CREGISTER:
  714. a_load_reg_ref(list,loc.size,tosize,loc.register,ref);
  715. LOC_CONSTANT:
  716. a_load_const_ref(list,tosize,loc.value,ref);
  717. else
  718. internalerror(200109302);
  719. end;
  720. end;
  721. function tcg.optimize_op_const_reg(list: taasmoutput; var op: topcg; var a : aword; var reg:tregister): boolean;
  722. var
  723. powerval : longint;
  724. begin
  725. optimize_op_const_reg := false;
  726. case op of
  727. { or with zero returns same result }
  728. OP_OR : if a = 0 then optimize_op_const_reg := true;
  729. { and with max returns same result }
  730. OP_AND : if (a = high(a)) then optimize_op_const_reg := true;
  731. { division by 1 returns result }
  732. OP_DIV :
  733. begin
  734. if a = 1 then
  735. optimize_op_const_reg := true
  736. else if ispowerof2(int64(a), powerval) then
  737. begin
  738. a := powerval;
  739. op:= OP_SHR;
  740. end;
  741. exit;
  742. end;
  743. OP_IDIV:
  744. begin
  745. if a = 1 then
  746. optimize_op_const_reg := true
  747. else if ispowerof2(int64(a), powerval) then
  748. begin
  749. a := powerval;
  750. op:= OP_SAR;
  751. end;
  752. exit;
  753. end;
  754. OP_MUL,OP_IMUL:
  755. begin
  756. if a = 1 then
  757. optimize_op_const_reg := true
  758. else if ispowerof2(int64(a), powerval) then
  759. begin
  760. a := powerval;
  761. op:= OP_SHL;
  762. end;
  763. exit;
  764. end;
  765. OP_SAR,OP_SHL,OP_SHR:
  766. begin
  767. if a = 0 then
  768. optimize_op_const_reg := true;
  769. exit;
  770. end;
  771. end;
  772. end;
  773. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  774. begin
  775. case loc.loc of
  776. LOC_REFERENCE, LOC_CREFERENCE:
  777. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  778. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  779. a_loadfpu_reg_reg(list,loc.size,loc.register,reg);
  780. else
  781. internalerror(200203301);
  782. end;
  783. end;
  784. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  785. begin
  786. case loc.loc of
  787. LOC_REFERENCE, LOC_CREFERENCE:
  788. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  789. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  790. a_loadfpu_reg_reg(list,size,reg,loc.register);
  791. else
  792. internalerror(48991);
  793. end;
  794. end;
  795. procedure tcg.a_paramfpu_reg(list : taasmoutput;size : tcgsize;const r : tregister;const locpara : tparalocation);
  796. var
  797. ref : treference;
  798. begin
  799. case locpara.loc of
  800. LOC_FPUREGISTER,LOC_CFPUREGISTER:
  801. a_loadfpu_reg_reg(list,size,r,locpara.register);
  802. LOC_REFERENCE,LOC_CREFERENCE:
  803. begin
  804. reference_reset(ref);
  805. ref.base:=locpara.reference.index;
  806. ref.offset:=locpara.reference.offset;
  807. a_loadfpu_reg_ref(list,size,r,ref);
  808. end
  809. else
  810. internalerror(2002071004);
  811. end;
  812. end;
  813. procedure tcg.a_paramfpu_ref(list : taasmoutput;size : tcgsize;const ref : treference;const locpara : tparalocation);
  814. var
  815. hr : tregister;
  816. begin
  817. hr:=getfpuregister(list,size);
  818. a_loadfpu_ref_reg(list,size,ref,hr);
  819. a_paramfpu_reg(list,size,hr,locpara);
  820. ungetregister(list,hr);
  821. end;
  822. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  823. var
  824. tmpreg: tregister;
  825. begin
  826. tmpreg:=getintregister(list,size);
  827. a_load_ref_reg(list,size,size,ref,tmpreg);
  828. a_op_const_reg(list,op,size,a,tmpreg);
  829. a_load_reg_ref(list,size,size,tmpreg,ref);
  830. ungetregister(list,tmpreg);
  831. end;
  832. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  833. begin
  834. case loc.loc of
  835. LOC_REGISTER, LOC_CREGISTER:
  836. a_op_const_reg(list,op,loc.size,a,loc.register);
  837. LOC_REFERENCE, LOC_CREFERENCE:
  838. a_op_const_ref(list,op,loc.size,a,loc.reference);
  839. else
  840. internalerror(200109061);
  841. end;
  842. end;
  843. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  844. var
  845. tmpreg: tregister;
  846. begin
  847. tmpreg:=getintregister(list,size);
  848. a_load_ref_reg(list,size,size,ref,tmpreg);
  849. a_op_reg_reg(list,op,size,reg,tmpreg);
  850. a_load_reg_ref(list,size,size,tmpreg,ref);
  851. ungetregister(list,tmpreg);
  852. end;
  853. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  854. var
  855. tmpreg: tregister;
  856. begin
  857. case op of
  858. OP_NOT,OP_NEG:
  859. { handle it as "load ref,reg; op reg" }
  860. begin
  861. a_load_ref_reg(list,size,size,ref,reg);
  862. a_op_reg_reg(list,op,size,reg,reg);
  863. end;
  864. else
  865. begin
  866. tmpreg:=getintregister(list,size);
  867. a_load_ref_reg(list,size,size,ref,tmpreg);
  868. a_op_reg_reg(list,op,size,tmpreg,reg);
  869. ungetregister(list,tmpreg);
  870. end;
  871. end;
  872. end;
  873. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  874. begin
  875. case loc.loc of
  876. LOC_REGISTER, LOC_CREGISTER:
  877. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  878. LOC_REFERENCE, LOC_CREFERENCE:
  879. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  880. else
  881. internalerror(200109061);
  882. end;
  883. end;
  884. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  885. var
  886. tmpreg: tregister;
  887. begin
  888. case loc.loc of
  889. LOC_REGISTER,LOC_CREGISTER:
  890. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  891. LOC_REFERENCE,LOC_CREFERENCE:
  892. begin
  893. tmpreg:=getintregister(list,loc.size);
  894. a_load_ref_reg(list,loc.size,loc.size,ref,tmpreg);
  895. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  896. ungetregister(list,tmpreg);
  897. end;
  898. else
  899. internalerror(200109061);
  900. end;
  901. end;
  902. procedure Tcg.a_op_const_reg_reg(list:Taasmoutput;op:Topcg;size:Tcgsize;
  903. a:aword;src,dst:Tregister);
  904. begin
  905. a_load_reg_reg(list,size,size,src,dst);
  906. a_op_const_reg(list,op,size,a,dst);
  907. end;
  908. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  909. size: tcgsize; src1, src2, dst: tregister);
  910. var
  911. tmpreg: tregister;
  912. begin
  913. if (dst<>src1) then
  914. begin
  915. a_load_reg_reg(list,size,size,src2,dst);
  916. a_op_reg_reg(list,op,size,src1,dst);
  917. end
  918. else
  919. begin
  920. tmpreg:=cg.getintregister(list,size);
  921. a_load_reg_reg(list,size,size,src2,tmpreg);
  922. a_op_reg_reg(list,op,size,src1,tmpreg);
  923. a_load_reg_reg(list,size,size,tmpreg,dst);
  924. ungetregister(list,tmpreg);
  925. end;
  926. end;
  927. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  928. l : tasmlabel);
  929. var
  930. tmpreg: tregister;
  931. begin
  932. tmpreg:=getintregister(list,size);
  933. a_load_ref_reg(list,size,size,ref,tmpreg);
  934. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  935. ungetregister(list,tmpreg);
  936. end;
  937. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const loc : tlocation;
  938. l : tasmlabel);
  939. begin
  940. case loc.loc of
  941. LOC_REGISTER,LOC_CREGISTER:
  942. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  943. LOC_REFERENCE,LOC_CREFERENCE:
  944. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  945. else
  946. internalerror(200109061);
  947. end;
  948. end;
  949. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  950. var
  951. tmpreg: tregister;
  952. begin
  953. tmpreg:=getintregister(list,size);
  954. a_load_ref_reg(list,size,size,ref,tmpreg);
  955. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  956. ungetregister(list,tmpreg);
  957. end;
  958. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  959. begin
  960. case loc.loc of
  961. LOC_REGISTER,
  962. LOC_CREGISTER:
  963. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  964. LOC_REFERENCE,
  965. LOC_CREFERENCE :
  966. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  967. LOC_CONSTANT:
  968. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  969. else
  970. internalerror(200203231);
  971. end;
  972. end;
  973. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  974. l : tasmlabel);
  975. var
  976. tmpreg: tregister;
  977. begin
  978. case loc.loc of
  979. LOC_REGISTER,LOC_CREGISTER:
  980. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  981. LOC_REFERENCE,LOC_CREFERENCE:
  982. begin
  983. tmpreg:=getintregister(list,size);
  984. a_load_ref_reg(list,size,size,loc.reference,tmpreg);
  985. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  986. ungetregister(list,tmpreg);
  987. end
  988. else
  989. internalerror(200109061);
  990. end;
  991. end;
  992. procedure tcg.a_loadmm_loc_reg(list: taasmoutput; size: tcgsize; const loc: tlocation; const reg: tregister;shuffle : pmmshuffle);
  993. begin
  994. case loc.loc of
  995. LOC_MMREGISTER,LOC_CMMREGISTER:
  996. a_loadmm_reg_reg(list,loc.size,size,loc.register,reg,shuffle);
  997. LOC_REFERENCE,LOC_CREFERENCE:
  998. a_loadmm_ref_reg(list,loc.size,size,loc.reference,reg,shuffle);
  999. else
  1000. internalerror(200310121);
  1001. end;
  1002. end;
  1003. procedure tcg.a_loadmm_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation;shuffle : pmmshuffle);
  1004. var
  1005. tmpreg: tregister;
  1006. begin
  1007. case loc.loc of
  1008. LOC_MMREGISTER,LOC_CMMREGISTER:
  1009. a_loadmm_reg_reg(list,size,loc.size,reg,loc.register,shuffle);
  1010. LOC_REFERENCE,LOC_CREFERENCE:
  1011. a_loadmm_reg_ref(list,size,loc.size,reg,loc.reference,shuffle);
  1012. else
  1013. internalerror(200310122);
  1014. end;
  1015. end;
  1016. procedure tcg.a_parammm_reg(list: taasmoutput; size: tcgsize; reg: tregister;const locpara : tparalocation;shuffle : pmmshuffle);
  1017. var
  1018. ref : treference;
  1019. begin
  1020. case locpara.loc of
  1021. LOC_MMREGISTER,LOC_CMMREGISTER:
  1022. a_loadmm_reg_reg(list,size,locpara.size,reg,locpara.register,shuffle);
  1023. LOC_REFERENCE,LOC_CREFERENCE:
  1024. begin
  1025. reference_reset(ref);
  1026. ref.base:=locpara.reference.index;
  1027. ref.offset:=locpara.reference.offset;
  1028. a_loadmm_reg_ref(list,size,locpara.size,reg,ref,shuffle);
  1029. end
  1030. else
  1031. internalerror(200310123);
  1032. end;
  1033. end;
  1034. procedure tcg.a_parammm_ref(list: taasmoutput; size: tcgsize; ref: treference;const locpara : tparalocation;shuffle : pmmshuffle);
  1035. var
  1036. hr : tregister;
  1037. hs : tmmshuffle;
  1038. begin
  1039. hr:=getmmregister(list,locpara.size);
  1040. a_loadmm_ref_reg(list,size,locpara.size,ref,hr,shuffle);
  1041. if realshuffle(shuffle) then
  1042. begin
  1043. hs:=shuffle^;
  1044. removeshuffles(hs);
  1045. a_parammm_reg(list,locpara.size,hr,locpara,@hs);
  1046. end
  1047. else
  1048. a_parammm_reg(list,locpara.size,hr,locpara,shuffle);
  1049. ungetregister(list,hr);
  1050. end;
  1051. procedure tcg.a_parammm_loc(list: taasmoutput; loc: tlocation; const locpara : tparalocation;shuffle : pmmshuffle);
  1052. begin
  1053. case loc.loc of
  1054. LOC_MMREGISTER,LOC_CMMREGISTER:
  1055. a_parammm_reg(list,loc.size,loc.register,locpara,shuffle);
  1056. LOC_REFERENCE,LOC_CREFERENCE:
  1057. a_parammm_ref(list,loc.size,loc.reference,locpara,shuffle);
  1058. else
  1059. internalerror(200310123);
  1060. end;
  1061. end;
  1062. class function tcg.reg_cgsize(const reg: tregister) : tcgsize;
  1063. begin
  1064. reg_cgsize := OS_INT;
  1065. end;
  1066. procedure tcg.g_copyshortstring(list : taasmoutput;const source,dest : treference;len:byte;delsource,loadref : boolean);
  1067. var
  1068. paraloc1,paraloc2,paraloc3 : tparalocation;
  1069. begin
  1070. {$ifdef FPC}
  1071. {$warning FIX ME!}
  1072. {$endif}
  1073. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1074. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1075. paraloc3:=paramanager.getintparaloc(pocall_default,3);
  1076. paramanager.allocparaloc(list,paraloc3);
  1077. a_paramaddr_ref(list,dest,paraloc3);
  1078. paramanager.allocparaloc(list,paraloc2);
  1079. if loadref then
  1080. a_param_ref(list,OS_ADDR,source,paraloc2)
  1081. else
  1082. a_paramaddr_ref(list,source,paraloc2);
  1083. if delsource then
  1084. reference_release(list,source);
  1085. paramanager.allocparaloc(list,paraloc1);
  1086. a_param_const(list,OS_INT,len,paraloc1);
  1087. paramanager.freeparaloc(list,paraloc3);
  1088. paramanager.freeparaloc(list,paraloc2);
  1089. paramanager.freeparaloc(list,paraloc1);
  1090. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1091. a_call_name(list,'FPC_SHORTSTR_ASSIGN');
  1092. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1093. end;
  1094. procedure tcg.g_incrrefcount(list : taasmoutput;t: tdef; const ref: treference;loadref : boolean);
  1095. var
  1096. href : treference;
  1097. incrfunc : string;
  1098. paraloc1,paraloc2 : tparalocation;
  1099. begin
  1100. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1101. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1102. { These functions should not change the registers (they use
  1103. the saveregister proc directive }
  1104. if is_interfacecom(t) then
  1105. incrfunc:='FPC_INTF_INCR_REF'
  1106. else if is_ansistring(t) then
  1107. incrfunc:='FPC_ANSISTR_INCR_REF'
  1108. else if is_widestring(t) then
  1109. incrfunc:='FPC_WIDESTR_INCR_REF'
  1110. else if is_dynamic_array(t) then
  1111. incrfunc:='FPC_DYNARRAY_INCR_REF'
  1112. else
  1113. incrfunc:='';
  1114. { call the special incr function or the generic addref }
  1115. if incrfunc<>'' then
  1116. begin
  1117. { these functions get the pointer by value }
  1118. paramanager.allocparaloc(list,paraloc1);
  1119. a_param_ref(list,OS_ADDR,ref,paraloc1);
  1120. paramanager.freeparaloc(list,paraloc1);
  1121. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1122. a_call_name(list,incrfunc);
  1123. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1124. end
  1125. else
  1126. begin
  1127. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1128. paramanager.allocparaloc(list,paraloc2);
  1129. a_paramaddr_ref(list,href,paraloc2);
  1130. paramanager.allocparaloc(list,paraloc1);
  1131. if loadref then
  1132. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1133. else
  1134. a_paramaddr_ref(list,ref,paraloc1);
  1135. paramanager.freeparaloc(list,paraloc1);
  1136. paramanager.freeparaloc(list,paraloc2);
  1137. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1138. a_call_name(list,'FPC_ADDREF');
  1139. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1140. end;
  1141. end;
  1142. procedure tcg.g_decrrefcount(list : taasmoutput;t: tdef; const ref: treference; loadref:boolean);
  1143. var
  1144. href : treference;
  1145. decrfunc : string;
  1146. needrtti : boolean;
  1147. paraloc1,paraloc2 : tparalocation;
  1148. begin
  1149. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1150. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1151. needrtti:=false;
  1152. if is_interfacecom(t) then
  1153. decrfunc:='FPC_INTF_DECR_REF'
  1154. else if is_ansistring(t) then
  1155. decrfunc:='FPC_ANSISTR_DECR_REF'
  1156. else if is_widestring(t) then
  1157. decrfunc:='FPC_WIDESTR_DECR_REF'
  1158. else if is_dynamic_array(t) then
  1159. begin
  1160. decrfunc:='FPC_DYNARRAY_DECR_REF';
  1161. needrtti:=true;
  1162. end
  1163. else
  1164. decrfunc:='';
  1165. { call the special decr function or the generic decref }
  1166. if decrfunc<>'' then
  1167. begin
  1168. if needrtti then
  1169. begin
  1170. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1171. paramanager.allocparaloc(list,paraloc2);
  1172. a_paramaddr_ref(list,href,paraloc2);
  1173. end;
  1174. paramanager.allocparaloc(list,paraloc1);
  1175. if loadref then
  1176. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1177. else
  1178. a_paramaddr_ref(list,ref,paraloc1);
  1179. paramanager.freeparaloc(list,paraloc1);
  1180. if needrtti then
  1181. paramanager.freeparaloc(list,paraloc2);
  1182. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1183. a_call_name(list,decrfunc);
  1184. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1185. end
  1186. else
  1187. begin
  1188. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1189. paramanager.allocparaloc(list,paraloc2);
  1190. a_paramaddr_ref(list,href,paraloc2);
  1191. paramanager.allocparaloc(list,paraloc1);
  1192. if loadref then
  1193. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1194. else
  1195. a_paramaddr_ref(list,ref,paraloc1);
  1196. paramanager.freeparaloc(list,paraloc1);
  1197. paramanager.freeparaloc(list,paraloc2);
  1198. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1199. a_call_name(list,'FPC_DECREF');
  1200. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1201. end;
  1202. end;
  1203. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1204. var
  1205. href : treference;
  1206. paraloc1,paraloc2 : tparalocation;
  1207. begin
  1208. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1209. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1210. if is_ansistring(t) or
  1211. is_widestring(t) or
  1212. is_interfacecom(t) then
  1213. a_load_const_ref(list,OS_ADDR,0,ref)
  1214. else
  1215. begin
  1216. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1217. paramanager.allocparaloc(list,paraloc2);
  1218. a_paramaddr_ref(list,href,paraloc2);
  1219. paramanager.allocparaloc(list,paraloc1);
  1220. if loadref then
  1221. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1222. else
  1223. a_paramaddr_ref(list,ref,paraloc1);
  1224. paramanager.freeparaloc(list,paraloc1);
  1225. paramanager.freeparaloc(list,paraloc2);
  1226. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1227. a_call_name(list,'FPC_INITIALIZE');
  1228. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1229. end;
  1230. end;
  1231. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;loadref : boolean);
  1232. var
  1233. href : treference;
  1234. paraloc1,paraloc2 : tparalocation;
  1235. begin
  1236. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1237. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1238. if is_ansistring(t) or
  1239. is_widestring(t) or
  1240. is_interfacecom(t) then
  1241. g_decrrefcount(list,t,ref,loadref)
  1242. else
  1243. begin
  1244. reference_reset_symbol(href,tstoreddef(t).get_rtti_label(initrtti),0);
  1245. paramanager.allocparaloc(list,paraloc2);
  1246. a_paramaddr_ref(list,href,paraloc2);
  1247. paramanager.allocparaloc(list,paraloc1);
  1248. if loadref then
  1249. a_param_ref(list,OS_ADDR,ref,paraloc1)
  1250. else
  1251. a_paramaddr_ref(list,ref,paraloc1);
  1252. paramanager.freeparaloc(list,paraloc1);
  1253. paramanager.freeparaloc(list,paraloc2);
  1254. allocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1255. a_call_name(list,'FPC_FINALIZE');
  1256. deallocexplicitregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
  1257. end;
  1258. end;
  1259. procedure tcg.g_rangecheck(list: taasmoutput; const l:tlocation;fromdef,todef: tdef);
  1260. { generate range checking code for the value at location p. The type }
  1261. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1262. { is the original type used at that location. When both defs are equal }
  1263. { the check is also insert (needed for succ,pref,inc,dec) }
  1264. const
  1265. {$ifdef ver1_0}
  1266. awordsignedmax=high(longint);
  1267. {$else}
  1268. awordsignedmax=high(aword) div 2;
  1269. {$endif}
  1270. var
  1271. neglabel : tasmlabel;
  1272. hreg : tregister;
  1273. lto,hto,
  1274. lfrom,hfrom : TConstExprInt;
  1275. from_signed: boolean;
  1276. begin
  1277. { range checking on and range checkable value? }
  1278. if not(cs_check_range in aktlocalswitches) or
  1279. not(fromdef.deftype in [orddef,enumdef,arraydef]) then
  1280. exit;
  1281. if is_64bit(fromdef) or is_64bit(todef) then
  1282. begin
  1283. cg64.g_rangecheck64(list,l,fromdef,todef);
  1284. exit;
  1285. end;
  1286. { only check when assigning to scalar, subranges are different, }
  1287. { when todef=fromdef then the check is always generated }
  1288. getrange(fromdef,lfrom,hfrom);
  1289. getrange(todef,lto,hto);
  1290. { no range check if from and to are equal and are both longint/dword }
  1291. { (if we have a 32bit processor) or int64/qword, since such }
  1292. { operations can at most cause overflows (JM) }
  1293. { Note that these checks are mostly processor independent, they only }
  1294. { have to be changed once we introduce 64bit subrange types }
  1295. if (fromdef = todef) and
  1296. (fromdef.deftype=orddef) and
  1297. (((sizeof(aword) = 4) and
  1298. (((torddef(fromdef).typ = s32bit) and
  1299. (lfrom = low(longint)) and
  1300. (hfrom = high(longint))) or
  1301. ((torddef(fromdef).typ = u32bit) and
  1302. (lfrom = low(cardinal)) and
  1303. (hfrom = high(cardinal)))))) then
  1304. exit;
  1305. if todef<>fromdef then
  1306. begin
  1307. { if the from-range falls completely in the to-range, no check }
  1308. { is necessary }
  1309. if (lto<=lfrom) and (hto>=hfrom) then
  1310. exit;
  1311. end;
  1312. { generate the rangecheck code for the def where we are going to }
  1313. { store the result }
  1314. { use the trick that }
  1315. { a <= x <= b <=> 0 <= x-a <= b-a <=> unsigned(x-a) <= unsigned(b-a) }
  1316. { To be able to do that, we have to make sure however that either }
  1317. { fromdef and todef are both signed or unsigned, or that we leave }
  1318. { the parts < 0 and > maxlongint out }
  1319. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1320. from_signed := is_signed(fromdef);
  1321. if from_signed xor is_signed(todef) then
  1322. if from_signed then
  1323. { from is signed, to is unsigned }
  1324. begin
  1325. { if high(from) < 0 -> always range error }
  1326. if (hfrom < 0) or
  1327. { if low(to) > maxlongint also range error }
  1328. (lto > awordsignedmax) then
  1329. begin
  1330. a_call_name(list,'FPC_RANGEERROR');
  1331. exit
  1332. end;
  1333. { from is signed and to is unsigned -> when looking at from }
  1334. { as an unsigned value, it must be < maxlongint (otherwise }
  1335. { it's negative, which is invalid since "to" is unsigned) }
  1336. if hto > awordsignedmax then
  1337. hto := awordsignedmax;
  1338. end
  1339. else
  1340. { from is unsigned, to is signed }
  1341. begin
  1342. if (lfrom > awordsignedmax) or
  1343. (hto < 0) then
  1344. begin
  1345. a_call_name(list,'FPC_RANGEERROR');
  1346. exit
  1347. end;
  1348. { from is unsigned and to is signed -> when looking at to }
  1349. { as an unsigned value, it must be >= 0 (since negative }
  1350. { values are the same as values > maxlongint) }
  1351. if lto < 0 then
  1352. lto := 0;
  1353. end;
  1354. hreg:=getintregister(list,OS_INT);
  1355. a_load_loc_reg(list,OS_INT,l,hreg);
  1356. a_op_const_reg(list,OP_SUB,OS_INT,aword(lto),hreg);
  1357. objectlibrary.getlabel(neglabel);
  1358. a_cmp_const_reg_label(list,OS_INT,OC_BE,aword(hto-lto),hreg,neglabel);
  1359. { !!! should happen right after the compare (JM) }
  1360. ungetregister(list,hreg);
  1361. a_call_name(list,'FPC_RANGEERROR');
  1362. a_label(list,neglabel);
  1363. end;
  1364. procedure tcg.g_stackcheck(list : taasmoutput;stackframesize : longint);
  1365. var
  1366. paraloc1 : tparalocation;
  1367. begin
  1368. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1369. paramanager.allocparaloc(list,paraloc1);
  1370. a_param_const(list,OS_32,stackframesize,paraloc1);
  1371. paramanager.freeparaloc(list,paraloc1);
  1372. { No register saving needed, saveregisters is used }
  1373. a_call_name(list,'FPC_STACKCHECK');
  1374. end;
  1375. procedure tcg.g_flags2ref(list: taasmoutput; size: TCgSize; const f: tresflags; const ref:TReference);
  1376. var
  1377. tmpreg : tregister;
  1378. begin
  1379. tmpreg:=getintregister(list,size);
  1380. g_flags2reg(list,size,f,tmpreg);
  1381. a_load_reg_ref(list,size,size,tmpreg,ref);
  1382. ungetregister(list,tmpreg);
  1383. end;
  1384. procedure tcg.g_maybe_testself(list : taasmoutput;reg:tregister);
  1385. var
  1386. OKLabel : tasmlabel;
  1387. paraloc1 : tparalocation;
  1388. begin
  1389. if (cs_check_object in aktlocalswitches) or
  1390. (cs_check_range in aktlocalswitches) then
  1391. begin
  1392. objectlibrary.getlabel(oklabel);
  1393. a_cmp_const_reg_label(list,OS_ADDR,OC_NE,0,reg,oklabel);
  1394. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1395. paramanager.allocparaloc(list,paraloc1);
  1396. a_param_const(list,OS_INT,210,paraloc1);
  1397. paramanager.freeparaloc(list,paraloc1);
  1398. a_call_name(list,'FPC_HANDLEERROR');
  1399. a_label(list,oklabel);
  1400. end;
  1401. end;
  1402. procedure tcg.g_maybe_testvmt(list : taasmoutput;reg:tregister;objdef:tobjectdef);
  1403. var
  1404. hrefvmt : treference;
  1405. paraloc1,paraloc2 : tparalocation;
  1406. begin
  1407. paraloc1:=paramanager.getintparaloc(pocall_default,1);
  1408. paraloc2:=paramanager.getintparaloc(pocall_default,2);
  1409. if (cs_check_object in aktlocalswitches) then
  1410. begin
  1411. reference_reset_symbol(hrefvmt,objectlibrary.newasmsymboldata(objdef.vmt_mangledname),0);
  1412. paramanager.allocparaloc(list,paraloc2);
  1413. a_paramaddr_ref(list,hrefvmt,paraloc2);
  1414. paramanager.allocparaloc(list,paraloc1);
  1415. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1416. paramanager.freeparaloc(list,paraloc1);
  1417. paramanager.freeparaloc(list,paraloc2);
  1418. { No register saving needed, saveregisters is used }
  1419. a_call_name(list,'FPC_CHECK_OBJECT_EXT');
  1420. end
  1421. else
  1422. if (cs_check_range in aktlocalswitches) then
  1423. begin
  1424. paramanager.allocparaloc(list,paraloc1);
  1425. a_param_reg(list,OS_ADDR,reg,paraloc1);
  1426. paramanager.freeparaloc(list,paraloc1);
  1427. { No register saving needed, saveregisters is used }
  1428. a_call_name(list,'FPC_CHECK_OBJECT');
  1429. end;
  1430. end;
  1431. {*****************************************************************************
  1432. Entry/Exit Code Functions
  1433. *****************************************************************************}
  1434. procedure tcg.g_releasevaluepara_openarray(list : taasmoutput;const ref:treference);
  1435. begin
  1436. end;
  1437. procedure tcg.g_interrupt_stackframe_entry(list : taasmoutput);
  1438. begin
  1439. end;
  1440. procedure tcg.g_interrupt_stackframe_exit(list : taasmoutput;accused,acchiused:boolean);
  1441. begin
  1442. end;
  1443. procedure tcg.g_profilecode(list : taasmoutput);
  1444. begin
  1445. end;
  1446. procedure tcg.g_exception_reason_save(list : taasmoutput; const href : treference);
  1447. begin
  1448. a_load_reg_ref(list, OS_S32, OS_32, NR_FUNCTION_RETURN_REG, href);
  1449. end;
  1450. procedure tcg.g_exception_reason_save_const(list : taasmoutput; const href : treference; a: aword);
  1451. begin
  1452. a_load_const_ref(list, OS_S32, a, href);
  1453. end;
  1454. procedure tcg.g_exception_reason_load(list : taasmoutput; const href : treference);
  1455. begin
  1456. a_load_ref_reg(list, OS_S32, OS_S32, href, NR_FUNCTION_RETURN_REG);
  1457. end;
  1458. {*****************************************************************************
  1459. TCG64
  1460. *****************************************************************************}
  1461. procedure tcg64.a_op64_const_reg_reg(list: taasmoutput;op:TOpCG;value : qword; regsrc,regdst : tregister64);
  1462. begin
  1463. a_load64_reg_reg(list,regsrc,regdst,false);
  1464. a_op64_const_reg(list,op,value,regdst);
  1465. end;
  1466. procedure tcg64.a_op64_reg_reg_reg(list: taasmoutput;op:TOpCG;regsrc1,regsrc2,regdst : tregister64);
  1467. begin
  1468. a_load64_reg_reg(list,regsrc2,regdst,false);
  1469. a_op64_reg_reg(list,op,regsrc1,regdst);
  1470. end;
  1471. {****************************************************************************
  1472. TReference
  1473. ****************************************************************************}
  1474. procedure reference_reset(var ref : treference);
  1475. begin
  1476. FillChar(ref,sizeof(treference),0);
  1477. {$ifdef arm}
  1478. ref.signindex:=1;
  1479. {$endif arm}
  1480. end;
  1481. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  1482. begin
  1483. reference_reset(ref);
  1484. ref.base:=base;
  1485. ref.offset:=offset;
  1486. end;
  1487. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  1488. begin
  1489. reference_reset(ref);
  1490. ref.symbol:=sym;
  1491. ref.offset:=offset;
  1492. end;
  1493. procedure reference_release(list: taasmoutput; const ref : treference);
  1494. begin
  1495. cg.ungetreference(list,ref);
  1496. end;
  1497. function references_equal(sref : treference;dref : treference):boolean;
  1498. begin
  1499. references_equal:=CompareByte(sref,dref,sizeof(treference))=0;
  1500. end;
  1501. {****************************************************************************
  1502. TLocation
  1503. ****************************************************************************}
  1504. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  1505. begin
  1506. FillChar(l,sizeof(tlocation),0);
  1507. l.loc:=lt;
  1508. l.size:=lsize;
  1509. {$ifdef arm}
  1510. if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  1511. l.reference.signindex:=1;
  1512. {$endif arm}
  1513. end;
  1514. procedure location_release(list: taasmoutput; const l : tlocation);
  1515. begin
  1516. case l.loc of
  1517. LOC_REGISTER,LOC_CREGISTER :
  1518. begin
  1519. cg.ungetregister(list,l.register);
  1520. if l.size in [OS_64,OS_S64] then
  1521. cg.ungetregister(list,l.registerhigh);
  1522. end;
  1523. LOC_FPUREGISTER,LOC_CFPUREGISTER :
  1524. cg.ungetregister(list,l.register);
  1525. LOC_CREFERENCE,LOC_REFERENCE :
  1526. cg.ungetreference(list, l.reference);
  1527. end;
  1528. end;
  1529. procedure location_freetemp(list:taasmoutput; const l : tlocation);
  1530. begin
  1531. if (l.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  1532. tg.ungetiftemp(list,l.reference);
  1533. end;
  1534. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  1535. begin
  1536. destloc:=sourceloc;
  1537. end;
  1538. procedure location_swap(var destloc,sourceloc : tlocation);
  1539. var
  1540. swapl : tlocation;
  1541. begin
  1542. swapl := destloc;
  1543. destloc := sourceloc;
  1544. sourceloc := swapl;
  1545. end;
  1546. initialization
  1547. ;
  1548. finalization
  1549. cg.free;
  1550. cg64.free;
  1551. end.
  1552. {
  1553. $Log$
  1554. Revision 1.134 2003-11-05 23:05:13 florian
  1555. * elesize of g_copyvaluepara_openarray changed
  1556. + g_releaesvaluepara_openarray added
  1557. Revision 1.133 2003/10/19 01:34:30 florian
  1558. * some ppc stuff fixed
  1559. * memory leak fixed
  1560. Revision 1.132 2003/10/17 15:25:18 florian
  1561. * fixed more ppc stuff
  1562. Revision 1.131 2003/10/17 14:38:32 peter
  1563. * 64k registers supported
  1564. * fixed some memory leaks
  1565. Revision 1.130 2003/10/13 01:23:13 florian
  1566. * some ideas for mm support implemented
  1567. Revision 1.129 2003/10/11 16:06:42 florian
  1568. * fixed some MMX<->SSE
  1569. * started to fix ppc, needs an overhaul
  1570. + stabs info improve for spilling, not sure if it works correctly/completly
  1571. - MMX_SUPPORT removed from Makefile.fpc
  1572. Revision 1.128 2003/10/10 17:48:13 peter
  1573. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  1574. * tregisteralloctor renamed to trgobj
  1575. * removed rgobj from a lot of units
  1576. * moved location_* and reference_* to cgobj
  1577. * first things for mmx register allocation
  1578. Revision 1.127 2003/10/09 21:31:37 daniel
  1579. * Register allocator splitted, ans abstract now
  1580. Revision 1.126 2003/10/01 20:34:48 peter
  1581. * procinfo unit contains tprocinfo
  1582. * cginfo renamed to cgbase
  1583. * moved cgmessage to verbose
  1584. * fixed ppc and sparc compiles
  1585. Revision 1.125 2003/09/28 17:55:03 peter
  1586. * parent framepointer changed to hidden parameter
  1587. * tloadparentfpnode added
  1588. Revision 1.124 2003/09/28 13:40:13 peter
  1589. * a_call_ref removed
  1590. Revision 1.123 2003/09/25 21:26:24 peter
  1591. * remove obsolete tparalocation.sp_fixup
  1592. Revision 1.122 2003/09/23 20:37:16 peter
  1593. * fpc_check_object(_ext) has saveregisters and doesn't need
  1594. saving of registers
  1595. Revision 1.121 2003/09/10 08:31:47 marco
  1596. * Patch from Peter for paraloc
  1597. Revision 1.120 2003/09/09 20:59:27 daniel
  1598. * Adding register allocation order
  1599. Revision 1.119 2003/09/07 22:09:34 peter
  1600. * preparations for different default calling conventions
  1601. * various RA fixes
  1602. Revision 1.118 2003/09/03 15:55:00 peter
  1603. * NEWRA branch merged
  1604. Revision 1.117 2003/09/03 11:18:36 florian
  1605. * fixed arm concatcopy
  1606. + arm support in the common compiler sources added
  1607. * moved some generic cg code around
  1608. + tfputype added
  1609. * ...
  1610. Revision 1.116.2.4 2003/08/29 17:28:59 peter
  1611. * next batch of updates
  1612. Revision 1.116.2.3 2003/08/28 18:35:07 peter
  1613. * tregister changed to cardinal
  1614. Revision 1.116.2.2 2003/08/27 20:23:55 peter
  1615. * remove old ra code
  1616. Revision 1.116.2.1 2003/08/27 19:55:54 peter
  1617. * first tregister patch
  1618. Revision 1.116 2003/08/17 16:59:20 jonas
  1619. * fixed regvars so they work with newra (at least for ppc)
  1620. * fixed some volatile register bugs
  1621. + -dnotranslation option for -dnewra, which causes the registers not to
  1622. be translated from virtual to normal registers. Requires support in
  1623. the assembler writer as well, which is only implemented in aggas/
  1624. agppcgas currently
  1625. Revision 1.115 2003/07/23 11:01:14 jonas
  1626. * several rg.allocexplicitregistersint/rg.deallocexplicitregistersint
  1627. pairs round calls to helpers
  1628. Revision 1.114 2003/07/06 17:58:22 peter
  1629. * framepointer fixes for sparc
  1630. * parent framepointer code more generic
  1631. Revision 1.113 2003/07/02 22:18:04 peter
  1632. * paraloc splitted in callerparaloc,calleeparaloc
  1633. * sparc calling convention updates
  1634. Revision 1.112 2003/06/13 21:19:30 peter
  1635. * current_procdef removed, use current_procinfo.procdef instead
  1636. Revision 1.111 2003/06/12 21:11:10 peter
  1637. * ungetregisterfpu gets size parameter
  1638. Revision 1.110 2003/06/12 16:43:07 peter
  1639. * newra compiles for sparc
  1640. Revision 1.109 2003/06/07 18:57:04 jonas
  1641. + added freeintparaloc
  1642. * ppc get/freeintparaloc now check whether the parameter regs are
  1643. properly allocated/deallocated (and get an extra list para)
  1644. * ppc a_call_* now internalerrors if pi_do_call is not yet set
  1645. * fixed lot of missing pi_do_call's
  1646. Revision 1.108 2003/06/06 14:43:02 peter
  1647. * g_copyopenarrayvalue gets length reference
  1648. * don't copy open arrays for cdecl
  1649. Revision 1.107 2003/06/03 21:11:09 peter
  1650. * cg.a_load_* get a from and to size specifier
  1651. * makeregsize only accepts newregister
  1652. * i386 uses generic tcgnotnode,tcgunaryminus
  1653. Revision 1.106 2003/06/03 13:01:59 daniel
  1654. * Register allocator finished
  1655. Revision 1.105 2003/06/01 21:38:06 peter
  1656. * getregisterfpu size parameter added
  1657. * op_const_reg size parameter added
  1658. * sparc updates
  1659. Revision 1.104 2003/06/01 01:02:39 peter
  1660. * generic a_call_ref
  1661. Revision 1.103 2003/05/30 23:57:08 peter
  1662. * more sparc cleanup
  1663. * accumulator removed, splitted in function_return_reg (called) and
  1664. function_result_reg (caller)
  1665. Revision 1.102 2003/05/30 23:49:18 jonas
  1666. * a_load_loc_reg now has an extra size parameter for the destination
  1667. register (properly fixes what I worked around in revision 1.106 of
  1668. ncgutil.pas)
  1669. Revision 1.101 2003/05/30 21:40:00 jonas
  1670. * fixed bug in a_load_loc_ref (the source instead of dest size was passed
  1671. to a_load_reg_ref in case of a register)
  1672. Revision 1.100 2003/05/30 12:36:13 jonas
  1673. * use as little different registers on the ppc until newra is released,
  1674. since every used register must be saved
  1675. Revision 1.99 2003/05/23 14:27:35 peter
  1676. * remove some unit dependencies
  1677. * current_procinfo changes to store more info
  1678. Revision 1.98 2003/05/15 18:58:53 peter
  1679. * removed selfpointer_offset, vmtpointer_offset
  1680. * tvarsym.adjusted_address
  1681. * address in localsymtable is now in the real direction
  1682. * removed some obsolete globals
  1683. Revision 1.97 2003/05/13 19:14:41 peter
  1684. * failn removed
  1685. * inherited result code check moven to pexpr
  1686. Revision 1.96 2003/05/11 21:37:03 peter
  1687. * moved implicit exception frame from ncgutil to psub
  1688. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1689. Revision 1.95 2003/05/09 17:47:02 peter
  1690. * self moved to hidden parameter
  1691. * removed hdisposen,hnewn,selfn
  1692. Revision 1.94 2003/05/01 12:23:46 jonas
  1693. * fix for op_reg_reg_reg in case the destination is the same as the first
  1694. source register
  1695. Revision 1.93 2003/04/29 07:28:52 michael
  1696. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1697. Revision 1.92 2003/04/27 11:21:32 peter
  1698. * aktprocdef renamed to current_procinfo.procdef
  1699. * procinfo renamed to current_procinfo
  1700. * procinfo will now be stored in current_module so it can be
  1701. cleaned up properly
  1702. * gen_main_procsym changed to create_main_proc and release_main_proc
  1703. to also generate a tprocinfo structure
  1704. * fixed unit implicit initfinal
  1705. Revision 1.91 2003/04/27 07:29:50 peter
  1706. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1707. a new procdef declaration
  1708. * aktprocsym removed
  1709. * lexlevel removed, use symtable.symtablelevel instead
  1710. * implicit init/final code uses the normal genentry/genexit
  1711. * funcret state checking updated for new funcret handling
  1712. Revision 1.90 2003/04/26 20:57:17 florian
  1713. * fixed para locations of fpc_class_new helper call
  1714. Revision 1.89 2003/04/26 17:21:08 florian
  1715. * fixed passing of fpu values by fpu register
  1716. Revision 1.88 2003/04/23 20:16:03 peter
  1717. + added currency support based on int64
  1718. + is_64bit for use in cg units instead of is_64bitint
  1719. * removed cgmessage from n386add, replace with internalerrors
  1720. Revision 1.87 2003/04/23 14:42:07 daniel
  1721. * Further register allocator work. Compiler now smaller with new
  1722. allocator than without.
  1723. * Somebody forgot to adjust ppu version number
  1724. Revision 1.86 2003/04/23 13:20:34 peter
  1725. * fix self passing to fpc_help_fail
  1726. Revision 1.85 2003/04/23 12:35:34 florian
  1727. * fixed several issues with powerpc
  1728. + applied a patch from Jonas for nested function calls (PowerPC only)
  1729. * ...
  1730. Revision 1.84 2003/04/22 14:33:38 peter
  1731. * removed some notes/hints
  1732. Revision 1.83 2003/04/22 13:47:08 peter
  1733. * fixed C style array of const
  1734. * fixed C array passing
  1735. * fixed left to right with high parameters
  1736. Revision 1.82 2003/04/22 10:09:34 daniel
  1737. + Implemented the actual register allocator
  1738. + Scratch registers unavailable when new register allocator used
  1739. + maybe_save/maybe_restore unavailable when new register allocator used
  1740. Revision 1.81 2003/04/06 21:11:23 olle
  1741. * changed newasmsymbol to newasmsymboldata for data symbols
  1742. Revision 1.80 2003/03/28 19:16:56 peter
  1743. * generic constructor working for i386
  1744. * remove fixed self register
  1745. * esi added as address register for i386
  1746. Revision 1.79 2003/03/22 18:07:18 jonas
  1747. + add used scratch registers to usedintbyproc for non-i386
  1748. Revision 1.78 2003/03/11 21:46:24 jonas
  1749. * lots of new regallocator fixes, both in generic and ppc-specific code
  1750. (ppc compiler still can't compile the linux system unit though)
  1751. Revision 1.77 2003/02/19 22:00:14 daniel
  1752. * Code generator converted to new register notation
  1753. - Horribily outdated todo.txt removed
  1754. Revision 1.76 2003/01/31 22:47:48 peter
  1755. * maybe_testself now really uses the passed register
  1756. Revision 1.75 2003/01/30 21:46:35 peter
  1757. * maybe_testvmt added
  1758. Revision 1.74 2003/01/17 12:45:40 daniel
  1759. * Fixed internalerror 200301081 problem
  1760. Revision 1.73 2003/01/13 14:54:34 daniel
  1761. * Further work to convert codegenerator register convention;
  1762. internalerror bug fixed.
  1763. Revision 1.72 2003/01/09 22:00:53 florian
  1764. * fixed some PowerPC issues
  1765. Revision 1.71 2003/01/09 20:41:10 florian
  1766. * fixed broken PowerPC compiler
  1767. Revision 1.70 2003/01/08 18:43:56 daniel
  1768. * Tregister changed into a record
  1769. Revision 1.69 2002/12/24 15:56:50 peter
  1770. * stackpointer_alloc added for adjusting ESP. Win32 needs
  1771. this for the pageprotection
  1772. Revision 1.68 2002/12/20 18:14:04 peter
  1773. * removed some runerror and writeln
  1774. Revision 1.67 2002/12/14 15:02:03 carl
  1775. * maxoperands -> max_operands (for portability in rautils.pas)
  1776. * fix some range-check errors with loadconst
  1777. + add ncgadd unit to m68k
  1778. * some bugfix of a_param_reg with LOC_CREFERENCE
  1779. Revision 1.66 2002/11/25 17:43:16 peter
  1780. * splitted defbase in defutil,symutil,defcmp
  1781. * merged isconvertable and is_equal into compare_defs(_ext)
  1782. * made operator search faster by walking the list only once
  1783. Revision 1.65 2002/11/17 16:27:31 carl
  1784. * document flags2reg
  1785. Revision 1.64 2002/11/16 17:06:28 peter
  1786. * return error 210 for failed self test
  1787. Revision 1.63 2002/11/15 01:58:46 peter
  1788. * merged changes from 1.0.7 up to 04-11
  1789. - -V option for generating bug report tracing
  1790. - more tracing for option parsing
  1791. - errors for cdecl and high()
  1792. - win32 import stabs
  1793. - win32 records<=8 are returned in eax:edx (turned off by default)
  1794. - heaptrc update
  1795. - more info for temp management in .s file with EXTDEBUG
  1796. Revision 1.62 2002/10/16 19:01:43 peter
  1797. + $IMPLICITEXCEPTIONS switch to turn on/off generation of the
  1798. implicit exception frames for procedures with initialized variables
  1799. and for constructors. The default is on for compatibility
  1800. Revision 1.61 2002/10/05 12:43:23 carl
  1801. * fixes for Delphi 6 compilation
  1802. (warning : Some features do not work under Delphi)
  1803. Revision 1.60 2002/10/02 18:20:52 peter
  1804. * Copy() is now internal syssym that calls compilerprocs
  1805. Revision 1.59 2002/09/17 18:54:02 jonas
  1806. * a_load_reg_reg() now has two size parameters: source and dest. This
  1807. allows some optimizations on architectures that don't encode the
  1808. register size in the register name.
  1809. Revision 1.58 2002/09/09 19:29:29 peter
  1810. * fixed dynarr_decr_ref call
  1811. Revision 1.57 2002/09/07 15:25:01 peter
  1812. * old logs removed and tabs fixed
  1813. Revision 1.56 2002/09/01 21:04:47 florian
  1814. * several powerpc related stuff fixed
  1815. Revision 1.55 2002/09/01 17:05:43 florian
  1816. + added abstract tcg.g_removevaluepara_openarray
  1817. Revision 1.54 2002/09/01 12:09:27 peter
  1818. + a_call_reg, a_call_loc added
  1819. * removed exprasmlist references
  1820. Revision 1.53 2002/08/19 18:17:48 carl
  1821. + optimize64_op_const_reg implemented (optimizes 64-bit constant opcodes)
  1822. * more fixes to m68k for 64-bit operations
  1823. Revision 1.52 2002/08/17 22:09:43 florian
  1824. * result type handling in tcgcal.pass_2 overhauled
  1825. * better tnode.dowrite
  1826. * some ppc stuff fixed
  1827. Revision 1.51 2002/08/17 09:23:33 florian
  1828. * first part of procinfo rewrite
  1829. Revision 1.50 2002/08/16 14:24:57 carl
  1830. * issameref() to test if two references are the same (then emit no opcodes)
  1831. + ret_in_reg to replace ret_in_acc
  1832. (fix some register allocation bugs at the same time)
  1833. + save_std_register now has an extra parameter which is the
  1834. usedinproc registers
  1835. Revision 1.49 2002/08/15 08:13:54 carl
  1836. - a_load_sym_ofs_reg removed
  1837. * loadvmt now calls loadaddr_ref_reg instead
  1838. Revision 1.48 2002/08/14 19:26:02 carl
  1839. + routine to optimize opcodes with constants
  1840. Revision 1.47 2002/08/11 14:32:26 peter
  1841. * renamed current_library to objectlibrary
  1842. Revision 1.46 2002/08/11 13:24:11 peter
  1843. * saving of asmsymbols in ppu supported
  1844. * asmsymbollist global is removed and moved into a new class
  1845. tasmlibrarydata that will hold the info of a .a file which
  1846. corresponds with a single module. Added librarydata to tmodule
  1847. to keep the library info stored for the module. In the future the
  1848. objectfiles will also be stored to the tasmlibrarydata class
  1849. * all getlabel/newasmsymbol and friends are moved to the new class
  1850. Revision 1.45 2002/08/10 17:15:20 jonas
  1851. * register parameters are now LOC_CREGISTER instead of LOC_REGISTER
  1852. Revision 1.44 2002/08/09 19:10:05 carl
  1853. - moved new_exception and free_exception to ncgutils
  1854. Revision 1.43 2002/08/05 18:27:48 carl
  1855. + more more more documentation
  1856. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1857. Revision 1.42 2002/08/04 19:08:21 carl
  1858. + added generic exception support (still does not work!)
  1859. + more documentation
  1860. Revision 1.41 2002/07/30 20:50:43 florian
  1861. * the code generator knows now if parameters are in registers
  1862. Revision 1.40 2002/07/29 21:16:02 florian
  1863. * some more ppc fixes
  1864. Revision 1.39 2002/07/28 15:56:00 jonas
  1865. + tcg64.a_op64_const_reg_reg() and tcg64.a_op64_reg_reg_reg() methods +
  1866. generic implementation
  1867. Revision 1.38 2002/07/27 19:53:51 jonas
  1868. + generic implementation of tcg.g_flags2ref()
  1869. * tcg.flags2xxx() now also needs a size parameter
  1870. Revision 1.37 2002/07/20 11:57:53 florian
  1871. * types.pas renamed to defbase.pas because D6 contains a types
  1872. unit so this would conflicts if D6 programms are compiled
  1873. + Willamette/SSE2 instructions to assembler added
  1874. }