cgobj.pas 78 KB

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