cgobj.pas 85 KB

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