cgobj.pas 89 KB

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