cgobj.pas 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. }
  23. unit cgobj;
  24. {$i defines.inc}
  25. interface
  26. uses
  27. cclasses,aasm,symtable,
  28. cpuasm,cpubase,cpuinfo,
  29. cginfo,
  30. symconst,symbase,symtype,node;
  31. type
  32. talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
  33. {# @abstract(Abstract code generator)
  34. This class implements an abstract instruction generator. Some of
  35. the methods of this class are generic, while others must
  36. be overriden for all new processors which will be supported
  37. by Free Pascal. For 32-bit processors, the base class
  38. sould be @link(tcg64f32) and not @var(tcg).
  39. }
  40. tcg = class
  41. scratch_register_array_pointer : aword;
  42. {# List of currently unused scratch registers }
  43. unusedscratchregisters : tregisterset;
  44. alignment : talignment;
  45. {************************************************}
  46. { basic routines }
  47. constructor create;
  48. {# Emit a label to the instruction stream. }
  49. procedure a_label(list : taasmoutput;l : tasmlabel);virtual;
  50. {# Allocates register r by inserting a pai_realloc record }
  51. procedure a_reg_alloc(list : taasmoutput;r : tregister);
  52. {# Deallocates register r by inserting a pa_regdealloc record}
  53. procedure a_reg_dealloc(list : taasmoutput;r : tregister);
  54. {# @abstract(Returns a register for use as scratch register)
  55. This routine returns a register which can be used by
  56. the code generator as a scratch register. Since
  57. scratch_registers are scarce resources, the register
  58. should be freed by calling @link(get_scratch_reg) as
  59. soon as it is no longer required.
  60. }
  61. function get_scratch_reg(list : taasmoutput) : tregister;
  62. {# @abstract(Releases a scratch register)
  63. Releases a scratch register.
  64. This routine is used to free a register which
  65. was previously allocated using @link(get_scratch_reg).
  66. }
  67. procedure free_scratch_reg(list : taasmoutput;r : tregister);
  68. {************************************************}
  69. { code generation for subroutine entry/exit code }
  70. { initilizes data of type t }
  71. { if is_already_ref is true then the routines assumes }
  72. { that r points to the data to initialize }
  73. procedure g_initialize(list : taasmoutput;t : tdef;const ref : treference;is_already_ref : boolean);
  74. { finalizes data of type t }
  75. { if is_already_ref is true then the routines assumes }
  76. { that r points to the data to finalizes }
  77. procedure g_finalize(list : taasmoutput;t : tdef;const ref : treference;is_already_ref : boolean);
  78. { helper routines }
  79. procedure g_initialize_data(list : taasmoutput;p : tsym);
  80. procedure g_incr_data(list : taasmoutput;p : tsym);
  81. procedure g_finalize_data(list : taasmoutput;p : tnamedindexitem);
  82. procedure g_copyvalueparas(list : taasmoutput;p : tnamedindexitem);
  83. procedure g_finalizetempansistrings(list : taasmoutput);
  84. procedure g_entrycode(alist : TAAsmoutput;make_global:boolean;
  85. stackframe:longint;
  86. var parasize:longint;var nostackframe:boolean;
  87. inlined : boolean);
  88. procedure g_exitcode(list : taasmoutput;parasize : longint;
  89. nostackframe,inlined : boolean);
  90. { string helper routines }
  91. procedure g_decrstrref(list : taasmoutput;const ref : treference;t : tdef);
  92. procedure g_removetemps(list : taasmoutput;p : tlinkedlist);
  93. { passing parameters, per default the parameter is pushed }
  94. { nr gives the number of the parameter (enumerated from }
  95. { left to right), this allows to move the parameter to }
  96. { register, if the cpu supports register calling }
  97. { conventions }
  98. {# Pass a parameter, which is located in a register, to a routine.
  99. This routine should push/send the parameter to the routine, as
  100. required by the specific processor ABI. This must be overriden for
  101. each CPU target.
  102. @param(size size of the operand in the register)
  103. @param(r register source of the operand)
  104. @param(nr parameter number (starting from one) of routine (from left to right))
  105. }
  106. procedure a_param_reg(list : taasmoutput;size : tcgsize;r : tregister;nr : longint);virtual; abstract;
  107. {# Pass a parameter, which is a constant, to a routine.
  108. A generic version is provided.
  109. @param(size size of the operand in constant)
  110. @param(a value of constant to send)
  111. @param(nr parameter number (starting from one) of routine (from left to right))
  112. }
  113. procedure a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);virtual;
  114. {# Pass the value of a parameter, which is located in memory, to a routine.
  115. A generic version is provided.
  116. @param(size size of the operand in constant)
  117. @param(r Memory reference of value to send)
  118. @param(nr parameter number (starting from one) of routine (from left to right))
  119. }
  120. procedure a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);virtual;
  121. {# Pass the value of a parameter, which can be located either in a register or memory location,
  122. to a routine.
  123. A generic version is provided.
  124. @param(l location of the operand to send)
  125. @param(nr parameter number (starting from one) of routine (from left to right))
  126. }
  127. procedure a_param_loc(list : taasmoutput;const l : tlocation;nr : longint);
  128. {# Pass the address of a reference to a routine.
  129. A generic version is provided.
  130. @param(r reference to get address from)
  131. @param(nr parameter number (starting from one) of routine (from left to right))
  132. }
  133. procedure a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);virtual;
  134. {**********************************}
  135. { these methods must be overriden: }
  136. { Remarks:
  137. * If a method specifies a size you have only to take care
  138. of that number of bits, i.e. load_const_reg with OP_8 must
  139. only load the lower 8 bit of the specified register
  140. the rest of the register can be undefined
  141. if necessary the compiler will call a method
  142. to zero or sign extend the register
  143. * The a_load_XX_XX with OP_64 needn't to be
  144. implemented for 32 bit
  145. processors, the code generator takes care of that
  146. * the addr size is for work with the natural pointer
  147. size
  148. * the procedures without fpu/mm are only for integer usage
  149. * normally the first location is the source and the
  150. second the destination
  151. }
  152. {# Emits instruction to call the method specified by symbol name @var(s) with offset
  153. to symbol in @var(offset). This routine must be overriden for each new target cpu.
  154. }
  155. procedure a_call_name(list : taasmoutput;const s : string;
  156. offset : longint);virtual; abstract;
  157. { move instructions }
  158. procedure a_load_const_reg(list : taasmoutput;size : tcgsize;a : aword;register : tregister);virtual; abstract;
  159. procedure a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);virtual;
  160. procedure a_load_const_loc(list : taasmoutput;a : aword;const loc : tlocation);
  161. procedure a_load_reg_ref(list : taasmoutput;size : tcgsize;register : tregister;const ref : treference);virtual; abstract;
  162. procedure a_load_reg_reg(list : taasmoutput;size : tcgsize;reg1,reg2 : tregister);virtual; abstract;
  163. procedure a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  164. procedure a_load_ref_reg(list : taasmoutput;size : tcgsize;const ref : treference;register : tregister);virtual; abstract;
  165. procedure a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  166. procedure a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  167. procedure a_load_sym_ofs_reg(list: taasmoutput; const sym: tasmsymbol; ofs: longint; reg: tregister);virtual; abstract;
  168. { fpu move instructions }
  169. procedure a_loadfpu_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  170. procedure a_loadfpu_ref_reg(list: taasmoutput; size: tcgsize; const ref: treference; reg: tregister); virtual; abstract;
  171. procedure a_loadfpu_reg_ref(list: taasmoutput; size: tcgsize; reg: tregister; const ref: treference); virtual; abstract;
  172. procedure a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  173. procedure a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  174. { vector register move instructions }
  175. procedure a_loadmm_reg_reg(list: taasmoutput; reg1, reg2: tregister); virtual; abstract;
  176. procedure a_loadmm_ref_reg(list: taasmoutput; const ref: treference; reg: tregister); virtual; abstract;
  177. procedure a_loadmm_reg_ref(list: taasmoutput; reg: tregister; const ref: treference); virtual; abstract;
  178. { basic arithmetic operations }
  179. { note: for operators which require only one argument (not, neg), use }
  180. { the op_reg_reg, op_reg_ref or op_reg_loc methods and keep in mind }
  181. { that in this case the *second* operand is used as both source and }
  182. { destination (JM) }
  183. procedure a_op_const_reg(list : taasmoutput; Op: TOpCG; a: AWord; reg: TRegister); virtual; abstract;
  184. procedure a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference); virtual;
  185. procedure a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  186. procedure a_op_reg_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; reg1, reg2: TRegister); virtual; abstract;
  187. procedure a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; reg: TRegister; const ref: TReference); virtual;
  188. procedure a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister); virtual;
  189. procedure a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  190. procedure a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  191. { trinary operations for processors that support them, 'emulated' }
  192. { on others. None with "ref" arguments since I don't think there }
  193. { are any processors that support it (JM) }
  194. procedure a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  195. size: tcgsize; a: aword; src, dst: tregister); virtual;
  196. procedure a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  197. size: tcgsize; src1, src2, dst: tregister); virtual;
  198. { comparison operations }
  199. procedure a_cmp_const_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;reg : tregister;
  200. l : tasmlabel);virtual; abstract;
  201. procedure a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  202. l : tasmlabel); virtual;
  203. procedure a_cmp_const_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; a: aword; const loc: tlocation;
  204. l : tasmlabel);
  205. procedure a_cmp_reg_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;reg1,reg2 : tregister;l : tasmlabel); virtual; abstract;
  206. procedure a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel); virtual;
  207. procedure a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  208. procedure a_cmp_ref_loc_label(list: taasmoutput; size: tcgsize;cmp_op: topcmp; const ref: treference; const loc: tlocation;
  209. l : tasmlabel);
  210. procedure a_jmp_always(list : taasmoutput;l: tasmlabel); virtual; abstract;
  211. procedure a_jmp_flags(list : taasmoutput;const f : TResFlags;l: tasmlabel); virtual; abstract;
  212. procedure g_flags2reg(list: taasmoutput; const f: tresflags; reg: TRegister); virtual; abstract;
  213. procedure a_loadaddr_ref_reg(list : taasmoutput;const ref : treference;r : tregister);virtual; abstract;
  214. procedure g_stackframe_entry(list : taasmoutput;localsize : longint);virtual; abstract;
  215. { restores the frame pointer at procedure exit, for the }
  216. { i386 it generates a simple leave }
  217. procedure g_restore_frame_pointer(list : taasmoutput);virtual; abstract;
  218. { some processors like the PPC doesn't allow to change the stack in }
  219. { a procedure, so we need to maintain an extra stack for the }
  220. { result values of setjmp in exception code }
  221. { this two procedures are for pushing an exception value, }
  222. { they can use the scratch registers }
  223. procedure g_push_exception_value_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  224. procedure g_push_exception_value_const(list : taasmoutput;reg : tregister);virtual; abstract;
  225. { that procedure pops a exception value }
  226. procedure g_pop_exception_value_reg(list : taasmoutput;reg : tregister);virtual; abstract;
  227. procedure g_return_from_proc(list : taasmoutput;parasize : aword);virtual; abstract;
  228. {********************************************************}
  229. { these methods can be overriden for extra functionality }
  230. {# Emits instructions which should be emitted when entering
  231. a routine declared as @var(interrupt). The default
  232. behavior does nothing, should be overriden as required.
  233. }
  234. procedure g_interrupt_stackframe_entry(list : taasmoutput);virtual;
  235. {# Emits instructions which should be emitted when exiting
  236. a routine declared as @var(interrupt). The default
  237. behavior does nothing, should be overriden as required.
  238. }
  239. procedure g_interrupt_stackframe_exit(list : taasmoutput);virtual;
  240. {# Emits instructions when compilation is done in profile
  241. mode (this is set as a command line option). The default
  242. behavior does nothing, should be overriden as required.
  243. }
  244. procedure g_profilecode(list : taasmoutput);virtual;
  245. {# Emits the call to the stack checking routine of
  246. the runtime library. The default behavior
  247. does not need to be modified, as it is generic
  248. for all platforms.
  249. }
  250. procedure g_stackcheck(list : taasmoutput;stackframesize : longint);virtual;
  251. procedure g_maybe_loadself(list : taasmoutput);virtual; abstract;
  252. {# This should emit the opcode to copy len bytes from the source
  253. to destination, if loadref is true, it assumes that it first must load
  254. the source address from the memory location where
  255. source points to.
  256. It must be overriden for each new target processor.
  257. @param(source Source reference of copy)
  258. @param(dest Destination reference of copy)
  259. @param(delsource Indicates if the source reference's resources should be freed)
  260. @param(loadref Is the source reference a pointer to the actual source (TRUE), is it the actual source address (FALSE))
  261. }
  262. procedure g_concatcopy(list : taasmoutput;const source,dest : treference;len : aword;delsource,loadref : boolean);virtual; abstract;
  263. {# Generates range checking code. It is to note
  264. that this routine does not need to be overriden,
  265. as it takes care of everything.
  266. @param(p Node which contains the value to check)
  267. @param(todef Type definition of node to range check)
  268. }
  269. procedure g_rangecheck(list: taasmoutput; const p: tnode;
  270. const todef: tdef); virtual;
  271. { generates overflow checking code for a node }
  272. procedure g_overflowcheck(list: taasmoutput; const p: tnode); virtual; abstract;
  273. { returns the tcgsize corresponding with the size of reg }
  274. class function reg_cgsize(const reg: tregister) : tcgsize; virtual;
  275. end;
  276. var
  277. cg : tcg; { this is the main code generator class }
  278. implementation
  279. uses
  280. globals,globtype,options,systems,cgbase,
  281. verbose,types,tgobj,symdef,cga,tainst,rgobj;
  282. const
  283. max_scratch_regs = high(scratch_regs) - low(scratch_regs) + 1;
  284. {*****************************************************************************
  285. basic functionallity
  286. ******************************************************************************}
  287. constructor tcg.create;
  288. var
  289. i : longint;
  290. begin
  291. scratch_register_array_pointer:=1;
  292. for i:=low(scratch_regs) to high(scratch_regs) do
  293. include(unusedscratchregisters,scratch_regs[i]);
  294. end;
  295. procedure tcg.a_reg_alloc(list : taasmoutput;r : tregister);
  296. begin
  297. list.concat(tairegalloc.alloc(r));
  298. end;
  299. procedure tcg.a_reg_dealloc(list : taasmoutput;r : tregister);
  300. begin
  301. list.concat(tairegalloc.dealloc(r));
  302. end;
  303. procedure tcg.a_label(list : taasmoutput;l : tasmlabel);
  304. begin
  305. list.concat(tai_label.create(l));
  306. end;
  307. function tcg.get_scratch_reg(list : taasmoutput) : tregister;
  308. var
  309. r : tregister;
  310. i : longint;
  311. begin
  312. if unusedscratchregisters=[] then
  313. internalerror(68996);
  314. for i:=scratch_register_array_pointer to
  315. (scratch_register_array_pointer+max_scratch_regs-1) do
  316. if scratch_regs[(i mod max_scratch_regs)+1] in unusedscratchregisters then
  317. begin
  318. r:=scratch_regs[(i mod max_scratch_regs)+1];
  319. break;
  320. end;
  321. exclude(unusedscratchregisters,r);
  322. inc(scratch_register_array_pointer);
  323. if scratch_register_array_pointer>max_scratch_regs then
  324. scratch_register_array_pointer:=1;
  325. a_reg_alloc(list,r);
  326. get_scratch_reg:=r;
  327. end;
  328. procedure tcg.free_scratch_reg(list : taasmoutput;r : tregister);
  329. begin
  330. include(unusedscratchregisters,rg.makeregsize(r,OS_INT));
  331. a_reg_dealloc(list,r);
  332. end;
  333. {*****************************************************************************
  334. this methods must be overridden for extra functionality
  335. ******************************************************************************}
  336. procedure tcg.g_interrupt_stackframe_entry(list : taasmoutput);
  337. begin
  338. end;
  339. procedure tcg.g_interrupt_stackframe_exit(list : taasmoutput);
  340. begin
  341. end;
  342. procedure tcg.g_profilecode(list : taasmoutput);
  343. begin
  344. end;
  345. {*****************************************************************************
  346. for better code generation these methods should be overridden
  347. ******************************************************************************}
  348. procedure tcg.a_param_const(list : taasmoutput;size : tcgsize;a : aword;nr : longint);
  349. var
  350. hr : tregister;
  351. begin
  352. hr:=get_scratch_reg(list);
  353. a_load_const_reg(list,size,a,hr);
  354. a_param_reg(list,size,hr,nr);
  355. free_scratch_reg(list,hr);
  356. end;
  357. procedure tcg.a_param_ref(list : taasmoutput;size : tcgsize;const r : treference;nr : longint);
  358. var
  359. hr : tregister;
  360. begin
  361. hr:=get_scratch_reg(list);
  362. a_load_ref_reg(list,size,r,hr);
  363. a_param_reg(list,size,hr,nr);
  364. free_scratch_reg(list,hr);
  365. end;
  366. procedure tcg.a_param_loc(list : taasmoutput;const l:tlocation;nr : longint);
  367. begin
  368. case l.loc of
  369. LOC_REGISTER,
  370. LOC_CREGISTER :
  371. a_param_reg(list,l.size,l.register,nr);
  372. LOC_CONSTANT :
  373. a_param_const(list,l.size,l.value,nr);
  374. LOC_CREFERENCE,
  375. LOC_REFERENCE :
  376. a_param_ref(list,l.size,l.reference,nr);
  377. else
  378. internalerror(2002032211);
  379. end;
  380. end;
  381. procedure tcg.a_paramaddr_ref(list : taasmoutput;const r : treference;nr : longint);
  382. var
  383. hr : tregister;
  384. begin
  385. hr:=get_scratch_reg(list);
  386. a_loadaddr_ref_reg(list,r,hr);
  387. a_param_reg(list,OS_ADDR,hr,nr);
  388. free_scratch_reg(list,hr);
  389. end;
  390. procedure tcg.g_stackcheck(list : taasmoutput;stackframesize : longint);
  391. begin
  392. a_param_const(list,OS_32,stackframesize,1);
  393. a_call_name(list,'FPC_STACKCHECK',0);
  394. end;
  395. {*****************************************************************************
  396. String helper routines
  397. *****************************************************************************}
  398. procedure tcg.g_removetemps(list : taasmoutput;p : tlinkedlist);
  399. (*
  400. var
  401. hp : ptemptodestroy;
  402. pushedregs : tpushed;
  403. *)
  404. begin
  405. (*
  406. hp:=ptemptodestroy(p^.first);
  407. if not(assigned(hp)) then
  408. exit;
  409. tg.pushusedregisters(pushedregs,$ff);
  410. while assigned(hp) do
  411. begin
  412. if is_ansistring(hp^.typ) then
  413. begin
  414. g_decrstrref(list,hp^.address,hp^.typ);
  415. tg.ungetiftemp(hp^.address);
  416. end;
  417. hp:=ptemptodestroy(hp^.next);
  418. end;
  419. tg.popusedregisters(pushedregs);
  420. *)
  421. runerror(211);
  422. end;
  423. procedure tcg.g_decrstrref(list : taasmoutput;const ref : treference;t : tdef);
  424. { var
  425. pushedregs : tpushedsaved; }
  426. begin
  427. (*
  428. tg.pushusedregisters(pushedregs,$ff);
  429. a_param_ref_addr(list,ref,1);
  430. if is_ansistring(t) then
  431. a_call_name(list,'FPC_ANSISTR_DECR_REF',0)
  432. else if is_widestring(t) then
  433. a_call_name(list,'FPC_WIDESTR_DECR_REF',0)
  434. else internalerror(58993);
  435. tg.popusedregisters(pushedregs);
  436. *)
  437. runerror(211);
  438. end;
  439. {*****************************************************************************
  440. Code generation for subroutine entry- and exit code
  441. *****************************************************************************}
  442. { initilizes data of type t }
  443. { if is_already_ref is true then the routines assumes }
  444. { that r points to the data to initialize }
  445. procedure tcg.g_initialize(list : taasmoutput;t : tdef;const ref : treference;is_already_ref : boolean);
  446. { var
  447. hr : treference; }
  448. begin
  449. (*
  450. if is_ansistring(t) or
  451. is_widestring(t) then
  452. a_load_const_ref(list,OS_8,0,ref)
  453. else
  454. begin
  455. reset_reference(hr);
  456. hr.symbol:=t^.get_inittable_label;
  457. a_param_ref_addr(list,hr,2);
  458. if is_already_ref then
  459. a_param_ref(list,OS_ADDR,ref,1)
  460. else
  461. a_param_ref_addr(list,ref,1);
  462. a_call_name(list,'FPC_INITIALIZE',0);
  463. end;
  464. *)
  465. runerror(211);
  466. end;
  467. procedure tcg.g_finalize(list : taasmoutput;t : tdef;const ref : treference;is_already_ref : boolean);
  468. { var
  469. r : treference; }
  470. begin
  471. (*
  472. if is_ansistring(t) or
  473. is_widestring(t) then
  474. begin
  475. g_decrstrref(list,ref,t);
  476. end
  477. else
  478. begin
  479. reset_reference(r);
  480. r.symbol:=t^.get_inittable_label;
  481. a_param_ref_addr(list,r,2);
  482. if is_already_ref then
  483. a_paramaddr_ref(list,ref,1)
  484. else
  485. a_param_ref_addr(list,ref,1);
  486. a_call_name(list,'FPC_FINALIZE',0);
  487. end;
  488. *)
  489. runerror(211);
  490. end;
  491. { generates the code for initialisation of local data }
  492. procedure tcg.g_initialize_data(list : taasmoutput;p : tsym);
  493. { var
  494. hr : treference; }
  495. begin
  496. (*
  497. if (tsym(p)^.typ=varsym) and
  498. assigned(pvarsym(p)^.vartype.def) and
  499. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  500. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  501. pvarsym(p)^.vartype.def^.needs_inittable then
  502. begin
  503. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  504. reset_reference(hr);
  505. if tsym(p)^.owner^.symtabletype=localsymtable then
  506. begin
  507. hr.base:=procinfo^.framepointer;
  508. hr.offset:=-pvarsym(p)^.address;
  509. end
  510. else
  511. begin
  512. hr.symbol:=newasmsymbol(pvarsym(p)^.mangledname);
  513. end;
  514. g_initialize(list,pvarsym(p)^.vartype.def,hr,false);
  515. end;
  516. *)
  517. runerror(211);
  518. end;
  519. { generates the code for incrementing the reference count of parameters }
  520. procedure tcg.g_incr_data(list : taasmoutput;p : tsym);
  521. { var
  522. hr : treference; }
  523. begin
  524. (*
  525. if (tsym(p)^.typ=varsym) and
  526. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  527. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  528. pvarsym(p)^.vartype.def^.needs_inittable and
  529. ((pvarsym(p)^.varspez=vs_value)) then
  530. begin
  531. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  532. reset_reference(hr);
  533. hr.symbol:=pvarsym(p)^.vartype.def^.get_inittable_label;
  534. a_param_ref_addr(list,hr,2);
  535. reset_reference(hr);
  536. hr.base:=procinfo^.framepointer;
  537. hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
  538. a_param_ref_addr(list,hr,1);
  539. reset_reference(hr);
  540. a_call_name(list,'FPC_ADDREF',0);
  541. end;
  542. *)
  543. runerror(211);
  544. end;
  545. { generates the code for finalisation of local data }
  546. procedure tcg.g_finalize_data(list : taasmoutput;p : tnamedindexitem);
  547. { var
  548. hr : treference; }
  549. begin
  550. (*
  551. if (tsym(p)^.typ=varsym) and
  552. assigned(pvarsym(p)^.vartype.def) and
  553. not((pvarsym(p)^.vartype.def^.deftype=objectdef) and
  554. pobjectdef(pvarsym(p)^.vartype.def)^.is_class) and
  555. pvarsym(p)^.vartype.def^.needs_inittable then
  556. begin
  557. { not all kind of parameters need to be finalized }
  558. if (tsym(p)^.owner^.symtabletype=parasymtable) and
  559. ((pvarsym(p)^.varspez=vs_var) or
  560. (pvarsym(p)^.varspez=vs_const) { and
  561. (dont_copy_const_param(pvarsym(p)^.definition)) } ) then
  562. exit;
  563. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  564. reset_reference(hr);
  565. case tsym(p)^.owner^.symtabletype of
  566. localsymtable:
  567. begin
  568. hr.base:=procinfo^.framepointer;
  569. hr.offset:=-pvarsym(p)^.address;
  570. end;
  571. parasymtable:
  572. begin
  573. hr.base:=procinfo^.framepointer;
  574. hr.offset:=pvarsym(p)^.address+procinfo^.para_offset;
  575. end;
  576. else
  577. hr.symbol:=newasmsymbol(pvarsym(p)^.mangledname);
  578. end;
  579. g_finalize(list,pvarsym(p)^.vartype.def,hr,false);
  580. end;
  581. *)
  582. runerror(211);
  583. end;
  584. { generates the code to make local copies of the value parameters }
  585. procedure tcg.g_copyvalueparas(list : taasmoutput;p : tnamedindexitem);
  586. begin
  587. runerror(255);
  588. end;
  589. (*
  590. var
  591. _list : taasmoutput;
  592. { wrappers for the methods, because TP doesn't know procedures }
  593. { of objects }
  594. procedure _copyvalueparas(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  595. begin
  596. cg^.g_copyvalueparas(_list,s);
  597. end;
  598. *)
  599. procedure tcg.g_finalizetempansistrings(list : taasmoutput);
  600. (*
  601. var
  602. hp : ptemprecord;
  603. hr : treference;
  604. *)
  605. begin
  606. (*
  607. hp:=tg.templist;
  608. while assigned(hp) do
  609. begin
  610. if hp^.temptype in [tt_ansistring,tt_freeansistring] then
  611. begin
  612. procinfo^.flags:=procinfo^.flags or pi_needs_implicit_finally;
  613. reset_reference(hr);
  614. hr.base:=procinfo^.framepointer;
  615. hr.offset:=hp^.pos;
  616. a_param_ref_addr(list,hr,1);
  617. a_call_name(list,'FPC_ANSISTR_DECR_REF',0);
  618. end;
  619. hp:=hp^.next;
  620. end;
  621. *)
  622. runerror(211);
  623. end;
  624. (*
  625. procedure _finalize_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  626. begin
  627. cg^.g_finalize_data(_list,s);
  628. end;
  629. procedure _incr_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  630. begin
  631. cg^.g_incr_data(_list,tsym(s));
  632. end;
  633. procedure _initialize_data(s : tnamedindexitem);{$ifndef FPC}far;{$endif}
  634. begin
  635. cg^.g_initialize_data(_list,tsym(s));
  636. end;
  637. *)
  638. { generates the entry code for a procedure }
  639. procedure tcg.g_entrycode(alist : TAAsmoutput;make_global:boolean;
  640. stackframe:longint;
  641. var parasize:longint;var nostackframe:boolean;
  642. inlined : boolean);
  643. (*
  644. var
  645. hs : string;
  646. hp : pused_unit;
  647. initcode : taasmoutput;
  648. {$ifdef GDB}
  649. stab_function_name : Pai_stab_function_name;
  650. {$endif GDB}
  651. hr : treference;
  652. r : tregister;
  653. *)
  654. begin
  655. (*
  656. { Align }
  657. if (not inlined) then
  658. begin
  659. { gprof uses 16 byte granularity !! }
  660. if (cs_profile in aktmoduleswitches) then
  661. list^.insert(new(pai_align,init(16)))
  662. else
  663. if not(cs_littlesize in aktglobalswitches) then
  664. list^.insert(new(pai_align,init(4)));
  665. end;
  666. { save registers on cdecl }
  667. if (po_savestdregs in aktprocsym^.definition^.procoptions) then
  668. begin
  669. for r:=firstreg to lastreg do
  670. begin
  671. if (r in registers_saved_on_cdecl) then
  672. if (r in (tg.availabletempregsint+
  673. tg.availabletempregsfpu+
  674. tg.availabletempregsmm)) then
  675. begin
  676. if not(r in tg.usedinproc) then
  677. {!!!!!!!!!!!! a_push_reg(list,r) }
  678. end
  679. else
  680. {!!!!!!!! a_push_reg(list,r) };
  681. end;
  682. end;
  683. { omit stack frame ? }
  684. if not inlined then
  685. if procinfo^.framepointer=STACK_POINTER_REG then
  686. begin
  687. CGMessage(cg_d_stackframe_omited);
  688. nostackframe:=true;
  689. if (aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  690. parasize:=0
  691. else
  692. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo^.para_offset-pointersize;
  693. end
  694. else
  695. begin
  696. if (aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_proginit,potype_unitfinalize]) then
  697. parasize:=0
  698. else
  699. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo^.para_offset-pointersize*2;
  700. nostackframe:=false;
  701. if (po_interrupt in aktprocsym^.definition^.procoptions) then
  702. g_interrupt_stackframe_entry(list);
  703. g_stackframe_entry(list,stackframe);
  704. if (cs_check_stack in aktlocalswitches) and
  705. (tf_supports_stack_checking in target_info.flags) then
  706. g_stackcheck(@initcode,stackframe);
  707. end;
  708. if cs_profile in aktmoduleswitches then
  709. g_profilecode(@initcode);
  710. if (not inlined) and (aktprocsym^.definition^.proctypeoption in [potype_unitinit]) then
  711. begin
  712. { needs the target a console flags ? }
  713. if tf_needs_isconsole in target_info.flags then
  714. begin
  715. hr.symbol:=newasmsymbol('U_'+target_info.system_unit+'_ISCONSOLE');
  716. if apptype=at_cui then
  717. a_load_const_ref(list,OS_8,1,hr)
  718. else
  719. a_load_const_ref(list,OS_8,0,hr);
  720. dispose(hr.symbol,done);
  721. end;
  722. hp:=pused_unit(usedunits.first);
  723. while assigned(hp) do
  724. begin
  725. { call the unit init code and make it external }
  726. if (hp^.u^.flags and uf_init)<>0 then
  727. a_call_name(list,
  728. 'INIT$$'+hp^.u^.modulename^,0);
  729. hp:=Pused_unit(hp^.next);
  730. end;
  731. end;
  732. {$ifdef dummy}
  733. { a constructor needs a help procedure }
  734. if (aktprocsym^.definition^.options and poconstructor)<>0 then
  735. begin
  736. if procinfo^._class^.isclass then
  737. begin
  738. list^.concat(new(paicpu,op_sym(A_CALL,S_NO,newasmsymbol('FPC_NEW_CLASS'))));
  739. list^.concat(new(paicpu,op_cond_sym(A_Jcc,C_Z,S_NO,quickexitlabel)));
  740. end
  741. else
  742. begin
  743. {
  744. list^.insert(new(pai_labeled,init(A_JZ,quickexitlabel)));
  745. list^.insert(new(paicpu,op_csymbol(A_CALL,S_NO,
  746. newcsymbol('FPC_HELP_CONSTRUCTOR',0))));
  747. list^.insert(new(paicpu,op_const_reg(A_MOV,S_L,procinfo^._class^.vmt_offset,R_EDI)));
  748. concat_external('FPC_HELP_CONSTRUCTOR',EXT_NEAR);
  749. }
  750. end;
  751. end;
  752. {$endif dummy}
  753. {$ifdef GDB}
  754. if (cs_debuginfo in aktmoduleswitches) then
  755. list^.insert(new(pai_force_line,init));
  756. {$endif GDB}
  757. { initialize return value }
  758. if assigned(procinfo^.returntype.def) and
  759. is_ansistring(procinfo^.returntype.def) or
  760. is_widestring(procinfo^.returntype.def) then
  761. begin
  762. reset_reference(hr);
  763. hr.offset:=procinfo^.return_offset;
  764. hr.base:=procinfo^.framepointer;
  765. a_load_const_ref(list,OS_32,0,hr);
  766. end;
  767. _list:=list;
  768. { generate copies of call by value parameters }
  769. if (po_assembler in aktprocsym^.definition^.procoptions) then
  770. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_copyvalueparas);
  771. { initialisizes local data }
  772. aktprocsym^.definition^.localst^.foreach({$ifdef FPCPROCVAR}@{$endif}_initialize_data);
  773. { add a reference to all call by value/const parameters }
  774. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_incr_data);
  775. if (cs_profile in aktmoduleswitches) or
  776. (aktprocsym^.definition^.owner^.symtabletype=globalsymtable) or
  777. (assigned(procinfo^._class) and (procinfo^._class^.owner^.symtabletype=globalsymtable)) then
  778. make_global:=true;
  779. if not inlined then
  780. begin
  781. hs:=proc_names.get;
  782. {$ifdef GDB}
  783. if (cs_debuginfo in aktmoduleswitches) and target_os.use_function_relative_addresses then
  784. stab_function_name := new(pai_stab_function_name,init(strpnew(hs)));
  785. {$endif GDB}
  786. { insert the names for the procedure }
  787. while hs<>'' do
  788. begin
  789. if make_global then
  790. exprasmlist^.insert(new(pai_symbol,initname_global(hs,0)))
  791. else
  792. exprasmlist^.insert(new(pai_symbol,initname(hs,0)));
  793. {$ifdef GDB}
  794. if (cs_debuginfo in aktmoduleswitches) then
  795. begin
  796. if target_os.use_function_relative_addresses then
  797. list^.insert(new(pai_stab_function_name,init(strpnew(hs))));
  798. end;
  799. {$endif GDB}
  800. hs:=proc_names.get;
  801. end;
  802. end;
  803. {$ifdef GDB}
  804. if (not inlined) and (cs_debuginfo in aktmoduleswitches) then
  805. begin
  806. if target_os.use_function_relative_addresses then
  807. list^.insert(stab_function_name);
  808. if make_global or ((procinfo^.flags and pi_is_global) <> 0) then
  809. aktprocsym^.is_global := True;
  810. list^.insert(new(pai_stabs,init(aktprocsym^.stabstring)));
  811. aktprocsym^.isstabwritten:=true;
  812. end;
  813. {$endif GDB}
  814. *)
  815. runerror(211);
  816. end;
  817. procedure tcg.g_exitcode(list : taasmoutput;parasize:longint;nostackframe,inlined:boolean);
  818. (*
  819. var
  820. {$ifdef GDB}
  821. mangled_length : longint;
  822. p : pchar;
  823. {$endif GDB}
  824. nofinal,noreraiselabel : tasmlabel;
  825. hr : treference;
  826. r : tregister;
  827. *)
  828. begin
  829. (*
  830. if aktexitlabel^.is_used then
  831. list^.insert(new(pai_label,init(aktexitlabel)));
  832. { call the destructor help procedure }
  833. if (aktprocsym^.definition^.proctypeoption=potype_destructor) then
  834. begin
  835. if procinfo^._class^.is_class then
  836. a_call_name(list,'FPC_DISPOSE_CLASS',0)
  837. else
  838. begin
  839. if procinfo^._class^.needs_inittable then
  840. begin
  841. getlabel(nofinal);
  842. {!!!!!!!!!!
  843. reset_reference(hr);
  844. hr.base:=R_EBP;
  845. hr.offset:=8;
  846. a_cmp_reg_const_label(list,OS_ADDR,OZ_EQ,
  847. }
  848. reset_reference(hr);
  849. hr.symbol:=procinfo^._class^.get_inittable_label;
  850. a_paramaddr_ref(list,hr,2);
  851. a_param_reg(list,OS_ADDR,self_pointer_reg,1);
  852. a_call_name(list,'FPC_FINALIZE',0);
  853. a_label(list,nofinal);
  854. end;
  855. { vmt_offset_reg can be a scratch register, }
  856. { but it must be always the same }
  857. a_reg_alloc(list,vmt_offset_reg);
  858. a_load_const_reg(list,OS_32,procinfo^._class^.vmt_offset,vmt_offset_reg);
  859. a_call_name(list,'FPC_HELP_DESTRUCTOR',0);
  860. a_reg_dealloc(list,vmt_offset_reg);
  861. end;
  862. end;
  863. { finalize temporary data }
  864. g_finalizetempansistrings(list);
  865. _list:=list;
  866. { finalize local data }
  867. aktprocsym^.definition^.localst^.foreach({$ifdef FPCPROCVAR}@{$endif}_finalize_data);
  868. { finalize paras data }
  869. if assigned(aktprocsym^.definition^.parast) then
  870. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}_finalize_data);
  871. { do we need to handle exceptions because of ansi/widestrings ? }
  872. if (procinfo^.flags and pi_needs_implicit_finally)<>0 then
  873. begin
  874. getlabel(noreraiselabel);
  875. a_call_name(list,'FPC_POPADDRSTACK',0);
  876. a_reg_alloc(list,accumulator);
  877. g_pop_exception_value_reg(list,accumulator);
  878. a_cmp_const_reg_label(list,OS_32,OC_EQ,0,accumulator,noreraiselabel);
  879. a_reg_dealloc(list,accumulator);
  880. { must be the return value finalized before reraising the exception? }
  881. if (procinfo^.returntype.def<>tdef(voiddef)) and
  882. (procinfo^.returntype.def^.needs_inittable) and
  883. ((procinfo^.returntype.def^.deftype<>objectdef) or
  884. not(pobjectdef(procinfo^.returntype.def)^.is_class)) then
  885. begin
  886. reset_reference(hr);
  887. hr.offset:=procinfo^.return_offset;
  888. hr.base:=procinfo^.framepointer;
  889. g_finalize(list,procinfo^.returntype.def,hr,ret_in_param(procinfo^.returntype.def));
  890. end;
  891. a_call_name(list,'FPC_RERAISE',0);
  892. a_label(list,noreraiselabel);
  893. end;
  894. { call __EXIT for main program }
  895. if (not DLLsource) and (not inlined) and (aktprocsym^.definition^.proctypeoption=potype_proginit) then
  896. a_call_name(list,'FPC_DO_EXIT',0);
  897. { handle return value }
  898. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  899. if (aktprocsym^.definition^.proctypeoption<>potype_constructor) then
  900. { handle_return_value(inlined) }
  901. else
  902. begin
  903. { return self in EAX }
  904. a_label(list,quickexitlabel);
  905. a_reg_alloc(list,accumulator);
  906. a_load_reg_reg(list,OS_ADDR,self_pointer_reg,accumulator);
  907. a_reg_dealloc(list,self_pointer_reg);
  908. a_label(list,quickexitlabel);
  909. { we can't clear the zero flag because the Alpha }
  910. { for example doesn't have flags, we have to compare }
  911. { the accu. in the caller }
  912. end;
  913. { stabs uses the label also ! }
  914. if aktexit2label^.is_used or
  915. ((cs_debuginfo in aktmoduleswitches) and not inlined) then
  916. a_label(list,aktexit2label);
  917. {$ifdef dummy}
  918. { should we restore edi ? }
  919. { for all i386 gcc implementations }
  920. {!!!!!!!!!!! I don't know how to handle register saving yet }
  921. if (po_savestdregs in aktprocsym^.definition^.procoptions) then
  922. begin
  923. if (aktprocsym^.definition^.usedregisters and ($80 shr byte(R_EBX)))<>0 then
  924. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_EBX)));
  925. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_ESI)));
  926. exprasmlist^.concat(new(paicpu,op_reg(A_POP,S_L,R_EDI)));
  927. { here we could reset R_EBX
  928. but that is risky because it only works
  929. if genexitcode is called after genentrycode
  930. so lets skip this for the moment PM
  931. aktprocsym^.definition^.usedregisters:=
  932. aktprocsym^.definition^.usedregisters or not ($80 shr byte(R_EBX));
  933. }
  934. end;
  935. {$endif dummy}
  936. if not(nostackframe) and not inlined then
  937. g_restore_frame_pointer(list);
  938. { at last, the return is generated }
  939. if not inlined then
  940. if po_interrupt in aktprocsym^.definition^.procoptions then
  941. g_interrupt_stackframe_exit(list)
  942. else
  943. g_return_from_proc(list,parasize);
  944. list^.concat(new(pai_symbol_end,initname(aktprocsym^.definition^.mangledname)));
  945. {$ifdef GDB}
  946. if (cs_debuginfo in aktmoduleswitches) and not inlined then
  947. begin
  948. aktprocsym^.concatstabto(list);
  949. if assigned(procinfo^._class) then
  950. if (not assigned(procinfo^.parent) or
  951. not assigned(procinfo^.parent^._class)) then
  952. list^.concat(new(pai_stabs,init(strpnew(
  953. '"$t:v'+procinfo^._class^.numberstring+'",'+
  954. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.selfpointer_offset)))));
  955. {!!!!!!!!!!!!
  956. else
  957. list^.concat(new(pai_stabs,init(strpnew(
  958. '"$t:r'+procinfo^._class^.numberstring+'",'+
  959. tostr(N_RSYM)+',0,0,'+tostr(GDB_i386index[R_ESI])))));
  960. }
  961. if (tdef(aktprocsym^.definition^.rettype.def) <> tdef(voiddef)) then
  962. begin
  963. if ret_in_param(aktprocsym^.definition^.rettype.def) then
  964. list^.concat(new(pai_stabs,init(strpnew(
  965. '"'+aktprocsym^.name+':X*'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  966. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))))
  967. else
  968. list^.concat(new(pai_stabs,init(strpnew(
  969. '"'+aktprocsym^.name+':X'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  970. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))));
  971. if (m_result in aktmodeswitches) then
  972. if ret_in_param(aktprocsym^.definition^.rettype.def) then
  973. list^.concat(new(pai_stabs,init(strpnew(
  974. '"RESULT:X*'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  975. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))))
  976. else
  977. list^.concat(new(pai_stabs,init(strpnew(
  978. '"RESULT:X'+aktprocsym^.definition^.rettype.def^.numberstring+'",'+
  979. tostr(N_PSYM)+',0,0,'+tostr(procinfo^.return_offset)))));
  980. end;
  981. mangled_length:=length(aktprocsym^.definition^.mangledname);
  982. getmem(p,mangled_length+50);
  983. strpcopy(p,'192,0,0,');
  984. strpcopy(strend(p),aktprocsym^.definition^.mangledname);
  985. list^.concat(new(pai_stabn,init(strnew(p))));
  986. {list^.concat(new(pai_stabn,init(strpnew('192,0,0,'
  987. +aktprocsym^.definition^.mangledname))));
  988. p[0]:='2';p[1]:='2';p[2]:='4';
  989. strpcopy(strend(p),'_end');}
  990. freemem(p,mangled_length+50);
  991. list^.concat(new(pai_stabn,init(
  992. strpnew('224,0,0,'+aktexit2label^.name))));
  993. { strpnew('224,0,0,'
  994. +aktprocsym^.definition^.mangledname+'_end'))));}
  995. end;
  996. {$endif GDB}
  997. *)
  998. runerror(211);
  999. end;
  1000. {*****************************************************************************
  1001. some generic implementations
  1002. ****************************************************************************}
  1003. procedure tcg.a_load_const_ref(list : taasmoutput;size : tcgsize;a : aword;const ref : treference);
  1004. var
  1005. tmpreg: tregister;
  1006. begin
  1007. tmpreg := get_scratch_reg(list);
  1008. a_load_const_reg(list,size,a,tmpreg);
  1009. a_load_reg_ref(list,size,tmpreg,ref);
  1010. free_scratch_reg(list,tmpreg);
  1011. end;
  1012. procedure tcg.a_load_loc_reg(list : taasmoutput;const loc: tlocation; reg : tregister);
  1013. begin
  1014. case loc.loc of
  1015. LOC_REFERENCE,LOC_CREFERENCE:
  1016. a_load_ref_reg(list,loc.size,loc.reference,reg);
  1017. LOC_REGISTER,LOC_CREGISTER:
  1018. a_load_reg_reg(list,loc.size,loc.register,reg);
  1019. LOC_CONSTANT:
  1020. a_load_const_reg(list,loc.size,loc.value,reg);
  1021. else
  1022. internalerror(200109092);
  1023. end;
  1024. end;
  1025. procedure tcg.a_load_const_loc(list : taasmoutput;a : aword;const loc: tlocation);
  1026. begin
  1027. case loc.loc of
  1028. LOC_REFERENCE,LOC_CREFERENCE:
  1029. a_load_const_ref(list,loc.size,a,loc.reference);
  1030. LOC_REGISTER,LOC_CREGISTER:
  1031. a_load_const_reg(list,loc.size,a,loc.register);
  1032. else
  1033. internalerror(200203272);
  1034. end;
  1035. end;
  1036. procedure tcg.a_load_reg_loc(list : taasmoutput;size : tcgsize;reg : tregister;const loc: tlocation);
  1037. begin
  1038. case loc.loc of
  1039. LOC_REFERENCE,LOC_CREFERENCE:
  1040. a_load_reg_ref(list,size,reg,loc.reference);
  1041. LOC_REGISTER,LOC_CREGISTER:
  1042. a_load_reg_reg(list,size,reg,loc.register);
  1043. else
  1044. internalerror(200203271);
  1045. end;
  1046. end;
  1047. procedure tcg.a_load_loc_ref(list : taasmoutput;const loc: tlocation; const ref : treference);
  1048. var
  1049. tmpreg: tregister;
  1050. begin
  1051. case loc.loc of
  1052. LOC_REFERENCE,LOC_CREFERENCE:
  1053. begin
  1054. {$ifdef i386}
  1055. { the following is done with defines to avoid a speed penalty, }
  1056. { since all this is only necessary for the 80x86 (because EDI }
  1057. { doesn't have an 8bit component which is directly addressable) }
  1058. if loc.size in [OS_8,OS_S8] then
  1059. tmpreg := rg.getregisterint(exprasmlist)
  1060. else
  1061. {$endif i386}
  1062. tmpreg := get_scratch_reg(list);
  1063. tmpreg:=rg.makeregsize(tmpreg,loc.size);
  1064. a_load_ref_reg(list,loc.size,loc.reference,tmpreg);
  1065. a_load_reg_ref(list,loc.size,tmpreg,ref);
  1066. {$ifdef i386}
  1067. if loc.size in [OS_8,OS_S8] then
  1068. rg.ungetregister(exprasmlist,tmpreg)
  1069. else
  1070. {$endif i386}
  1071. free_scratch_reg(list,tmpreg);
  1072. end;
  1073. LOC_REGISTER,LOC_CREGISTER:
  1074. a_load_reg_ref(list,loc.size,loc.register,ref);
  1075. LOC_CONSTANT:
  1076. a_load_const_ref(list,loc.size,loc.value,ref);
  1077. else
  1078. internalerror(200109302);
  1079. end;
  1080. end;
  1081. procedure tcg.a_loadfpu_loc_reg(list: taasmoutput; const loc: tlocation; const reg: tregister);
  1082. begin
  1083. case loc.loc of
  1084. LOC_REFERENCE, LOC_CREFERENCE:
  1085. a_loadfpu_ref_reg(list,loc.size,loc.reference,reg);
  1086. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  1087. a_loadfpu_reg_reg(list,loc.register,reg);
  1088. else
  1089. internalerror(200203301);
  1090. end;
  1091. end;
  1092. procedure tcg.a_loadfpu_reg_loc(list: taasmoutput; size: tcgsize; const reg: tregister; const loc: tlocation);
  1093. begin
  1094. case loc.loc of
  1095. LOC_REFERENCE, LOC_CREFERENCE:
  1096. a_loadfpu_reg_ref(list,size,reg,loc.reference);
  1097. LOC_FPUREGISTER, LOC_CFPUREGISTER:
  1098. a_loadfpu_reg_reg(list,reg,loc.register);
  1099. else
  1100. internalerror(48991);
  1101. end;
  1102. end;
  1103. procedure tcg.a_op_const_ref(list : taasmoutput; Op: TOpCG; size: TCGSize; a: AWord; const ref: TReference);
  1104. var
  1105. tmpreg: tregister;
  1106. begin
  1107. tmpreg := get_scratch_reg(list);
  1108. a_load_ref_reg(list,size,ref,tmpreg);
  1109. a_op_const_reg(list,op,a,tmpreg);
  1110. a_load_reg_ref(list,size,tmpreg,ref);
  1111. free_scratch_reg(list,tmpreg);
  1112. end;
  1113. procedure tcg.a_op_const_loc(list : taasmoutput; Op: TOpCG; a: AWord; const loc: tlocation);
  1114. begin
  1115. case loc.loc of
  1116. LOC_REGISTER, LOC_CREGISTER:
  1117. a_op_const_reg(list,op,a,loc.register);
  1118. LOC_REFERENCE, LOC_CREFERENCE:
  1119. a_op_const_ref(list,op,loc.size,a,loc.reference);
  1120. else
  1121. internalerror(200109061);
  1122. end;
  1123. end;
  1124. procedure tcg.a_op_reg_ref(list : taasmoutput; Op: TOpCG; size: TCGSize;reg: TRegister; const ref: TReference);
  1125. var
  1126. tmpreg: tregister;
  1127. begin
  1128. tmpreg := get_scratch_reg(list);
  1129. a_load_ref_reg(list,size,ref,tmpreg);
  1130. a_op_reg_reg(list,op,size,reg,tmpreg);
  1131. a_load_reg_ref(list,size,tmpreg,ref);
  1132. free_scratch_reg(list,tmpreg);
  1133. end;
  1134. procedure tcg.a_op_ref_reg(list : taasmoutput; Op: TOpCG; size: TCGSize; const ref: TReference; reg: TRegister);
  1135. var
  1136. tmpreg: tregister;
  1137. begin
  1138. case op of
  1139. OP_NOT,OP_NEG:
  1140. { handle it as "load ref,reg; op reg" }
  1141. begin
  1142. a_load_ref_reg(list,size,ref,reg);
  1143. a_op_reg_reg(list,op,size,reg,reg);
  1144. end;
  1145. else
  1146. begin
  1147. tmpreg := get_scratch_reg(list);
  1148. a_load_ref_reg(list,size,ref,tmpreg);
  1149. a_op_reg_reg(list,op,size,tmpreg,reg);
  1150. free_scratch_reg(list,tmpreg);
  1151. end;
  1152. end;
  1153. end;
  1154. procedure tcg.a_op_reg_loc(list : taasmoutput; Op: TOpCG; reg: tregister; const loc: tlocation);
  1155. begin
  1156. case loc.loc of
  1157. LOC_REGISTER, LOC_CREGISTER:
  1158. a_op_reg_reg(list,op,loc.size,reg,loc.register);
  1159. LOC_REFERENCE, LOC_CREFERENCE:
  1160. a_op_reg_ref(list,op,loc.size,reg,loc.reference);
  1161. else
  1162. internalerror(200109061);
  1163. end;
  1164. end;
  1165. procedure tcg.a_op_ref_loc(list : taasmoutput; Op: TOpCG; const ref: TReference; const loc: tlocation);
  1166. var
  1167. tmpreg: tregister;
  1168. begin
  1169. case loc.loc of
  1170. LOC_REGISTER,LOC_CREGISTER:
  1171. a_op_ref_reg(list,op,loc.size,ref,loc.register);
  1172. LOC_REFERENCE,LOC_CREFERENCE:
  1173. begin
  1174. tmpreg := get_scratch_reg(list);
  1175. tmpreg:=rg.makeregsize(tmpreg,loc.size);
  1176. a_load_ref_reg(list,loc.size,ref,tmpreg);
  1177. a_op_reg_ref(list,op,loc.size,tmpreg,loc.reference);
  1178. free_scratch_reg(list,tmpreg);
  1179. end;
  1180. else
  1181. internalerror(200109061);
  1182. end;
  1183. end;
  1184. procedure tcg.a_op_const_reg_reg(list: taasmoutput; op: TOpCg;
  1185. size: tcgsize; a: aword; src, dst: tregister);
  1186. begin
  1187. a_load_reg_reg(list,size,src,dst);
  1188. a_op_const_reg(list,op,a,dst);
  1189. end;
  1190. procedure tcg.a_op_reg_reg_reg(list: taasmoutput; op: TOpCg;
  1191. size: tcgsize; src1, src2, dst: tregister);
  1192. begin
  1193. a_load_reg_reg(list,size,src2,dst);
  1194. a_op_reg_reg(list,op,size,src1,dst);
  1195. end;
  1196. procedure tcg.a_cmp_const_ref_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const ref : treference;
  1197. l : tasmlabel);
  1198. var
  1199. tmpreg: tregister;
  1200. begin
  1201. tmpreg := get_scratch_reg(list);
  1202. a_load_ref_reg(list,size,ref,tmpreg);
  1203. a_cmp_const_reg_label(list,size,cmp_op,a,tmpreg,l);
  1204. free_scratch_reg(list,tmpreg);
  1205. end;
  1206. procedure tcg.a_cmp_const_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;a : aword;const loc : tlocation;
  1207. l : tasmlabel);
  1208. begin
  1209. case loc.loc of
  1210. LOC_REGISTER,LOC_CREGISTER:
  1211. a_cmp_const_reg_label(list,size,cmp_op,a,loc.register,l);
  1212. LOC_REFERENCE,LOC_CREFERENCE:
  1213. a_cmp_const_ref_label(list,size,cmp_op,a,loc.reference,l);
  1214. else
  1215. internalerror(200109061);
  1216. end;
  1217. end;
  1218. procedure tcg.a_cmp_ref_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const ref: treference; reg : tregister; l : tasmlabel);
  1219. var
  1220. tmpreg: tregister;
  1221. begin
  1222. tmpreg := get_scratch_reg(list);
  1223. a_load_ref_reg(list,size,ref,tmpreg);
  1224. a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
  1225. free_scratch_reg(list,tmpreg);
  1226. end;
  1227. procedure tcg.a_cmp_loc_reg_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp; const loc: tlocation; reg : tregister; l : tasmlabel);
  1228. begin
  1229. case loc.loc of
  1230. LOC_REGISTER,
  1231. LOC_CREGISTER:
  1232. a_cmp_reg_reg_label(list,size,cmp_op,loc.register,reg,l);
  1233. LOC_REFERENCE,
  1234. LOC_CREFERENCE :
  1235. a_cmp_ref_reg_label(list,size,cmp_op,loc.reference,reg,l);
  1236. LOC_CONSTANT:
  1237. a_cmp_const_reg_label(list,size,cmp_op,loc.value,reg,l);
  1238. else
  1239. internalerror(200203231);
  1240. end;
  1241. end;
  1242. procedure tcg.a_cmp_ref_loc_label(list : taasmoutput;size : tcgsize;cmp_op : topcmp;const ref: treference;const loc : tlocation;
  1243. l : tasmlabel);
  1244. var
  1245. tmpreg: tregister;
  1246. begin
  1247. case loc.loc of
  1248. LOC_REGISTER,LOC_CREGISTER:
  1249. a_cmp_ref_reg_label(list,size,cmp_op,ref,loc.register,l);
  1250. LOC_REFERENCE,LOC_CREFERENCE:
  1251. begin
  1252. {$ifdef i386}
  1253. { the following is done with defines to avoid a speed penalty, }
  1254. { since all this is only necessary for the 80x86 (because EDI }
  1255. { doesn't have an 8bit component which is directly addressable) }
  1256. if size in [OS_8,OS_S8] then
  1257. tmpreg := rg.getregisterint(exprasmlist)
  1258. else
  1259. {$endif i386}
  1260. tmpreg := get_scratch_reg(list);
  1261. tmpreg := rg.makeregsize(tmpreg,size);
  1262. a_load_ref_reg(list,size,loc.reference,tmpreg);
  1263. a_cmp_ref_reg_label(list,size,cmp_op,ref,tmpreg,l);
  1264. {$ifdef i386}
  1265. if size in [OS_8,OS_S8] then
  1266. rg.ungetregister(exprasmlist,tmpreg)
  1267. else
  1268. {$endif i386}
  1269. free_scratch_reg(list,tmpreg);
  1270. end
  1271. else
  1272. internalerror(200109061);
  1273. end;
  1274. end;
  1275. procedure tcg.g_rangecheck(list: taasmoutput; const p: tnode;
  1276. const todef: tdef);
  1277. { generate range checking code for the value at location p. The type }
  1278. { type used is checked against todefs ranges. fromdef (p.resulttype.def) }
  1279. { is the original type used at that location. When both defs are equal }
  1280. { the check is also insert (needed for succ,pref,inc,dec) }
  1281. const
  1282. {$ifdef ver1_0}
  1283. awordsignedmax=high(longint);
  1284. {$else}
  1285. awordsignedmax=high(aword) div 2;
  1286. {$endif}
  1287. var
  1288. neglabel : tasmlabel;
  1289. hreg : tregister;
  1290. fromdef : tdef;
  1291. lto,hto,
  1292. lfrom,hfrom : TConstExprInt;
  1293. from_signed: boolean;
  1294. begin
  1295. { range checking on and range checkable value? }
  1296. if not(cs_check_range in aktlocalswitches) or
  1297. not(todef.deftype in [orddef,enumdef,arraydef]) then
  1298. exit;
  1299. { only check when assigning to scalar, subranges are different, }
  1300. { when todef=fromdef then the check is always generated }
  1301. fromdef:=p.resulttype.def;
  1302. getrange(p.resulttype.def,lfrom,hfrom);
  1303. getrange(todef,lto,hto);
  1304. { no range check if from and to are equal and are both longint/dword }
  1305. { (if we have a 32bit processor) or int64/qword, since such }
  1306. { operations can at most cause overflows (JM) }
  1307. { Note that these checks are mostly processor independent, they only }
  1308. { have to be changed once we introduce 64bit subrange types }
  1309. if (fromdef = todef) and
  1310. { then fromdef and todef can only be orddefs }
  1311. (((sizeof(aword) = 4) and
  1312. (((torddef(fromdef).typ = s32bit) and
  1313. (lfrom = low(longint)) and
  1314. (hfrom = high(longint))) or
  1315. ((torddef(fromdef).typ = u32bit) and
  1316. (lfrom = low(cardinal)) and
  1317. (hfrom = high(cardinal))))) or
  1318. is_64bitint(fromdef)) then
  1319. exit;
  1320. if todef<>fromdef then
  1321. begin
  1322. { if the from-range falls completely in the to-range, no check }
  1323. { is necessary }
  1324. if (lto<=lfrom) and (hto>=hfrom) then
  1325. exit;
  1326. end;
  1327. { generate the rangecheck code for the def where we are going to }
  1328. { store the result }
  1329. { use the trick that }
  1330. { a <= x <= b <=> 0 <= x-a <= b-a <=> cardinal(x-a) <= cardinal(b-a) }
  1331. { To be able to do that, we have to make sure however that either }
  1332. { fromdef and todef are both signed or unsigned, or that we leave }
  1333. { the parts < 0 and > maxlongint out }
  1334. { is_signed now also works for arrays (it checks the rangetype) (JM) }
  1335. from_signed := is_signed(fromdef);
  1336. if from_signed xor is_signed(todef) then
  1337. if from_signed then
  1338. { from is signed, to is unsigned }
  1339. begin
  1340. { if high(from) < 0 -> always range error }
  1341. if (hfrom < 0) or
  1342. { if low(to) > maxlongint also range error }
  1343. (lto > awordsignedmax) then
  1344. begin
  1345. a_call_name(list,'FPC_RANGEERROR',0);
  1346. exit
  1347. end;
  1348. { from is signed and to is unsigned -> when looking at from }
  1349. { as an unsigned value, it must be < maxlongint (otherwise }
  1350. { it's negative, which is invalid since "to" is unsigned) }
  1351. if hto > awordsignedmax then
  1352. hto := awordsignedmax;
  1353. end
  1354. else
  1355. { from is unsigned, to is signed }
  1356. begin
  1357. if (lfrom > awordsignedmax) or
  1358. (hto < 0) then
  1359. begin
  1360. a_call_name(list,'FPC_RANGEERROR',0);
  1361. exit
  1362. end;
  1363. { from is unsigned and to is signed -> when looking at to }
  1364. { as an unsigned value, it must be >= 0 (since negative }
  1365. { values are the same as values > maxlongint) }
  1366. if lto < 0 then
  1367. lto := 0;
  1368. end;
  1369. hreg := get_scratch_reg(list);
  1370. if (p.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1371. a_op_const_reg_reg(list,OP_SUB,def_cgsize(p.resulttype.def),
  1372. aword(longint(lto and $ffffffff)),p.location.register,hreg)
  1373. else
  1374. begin
  1375. a_load_ref_reg(list,def_cgsize(p.resulttype.def),
  1376. p.location.reference,hreg);
  1377. a_op_const_reg(list,OP_SUB,aword(longint(lto and $ffffffff)),hreg);
  1378. end;
  1379. getlabel(neglabel);
  1380. a_cmp_const_reg_label(list,OS_INT,OC_BE,aword(longint((hto-lto) and $ffffffff)),hreg,neglabel);
  1381. { !!! should happen right after the compare (JM) }
  1382. free_scratch_reg(list,hreg);
  1383. a_call_name(list,'FPC_RANGEERROR',0);
  1384. a_label(list,neglabel);
  1385. end;
  1386. function tcg.reg_cgsize(const reg: tregister) : tcgsize;
  1387. begin
  1388. reg_cgsize := OS_INT;
  1389. end;
  1390. finalization
  1391. cg.free;
  1392. end.
  1393. {
  1394. $Log$
  1395. Revision 1.17 2002-04-22 16:30:05 peter
  1396. * fixed @methodpointer
  1397. Revision 1.16 2002/04/21 15:25:30 carl
  1398. + a_jmp_cond -> a_jmp_always (a_jmp_cond is NOT portable)
  1399. + changeregsize -> rg.makeregsize
  1400. Revision 1.15 2002/04/20 21:32:23 carl
  1401. + generic FPC_CHECKPOINTER
  1402. + first parameter offset in stack now portable
  1403. * rename some constants
  1404. + move some cpu stuff to other units
  1405. - remove unused constents
  1406. * fix stacksize for some targets
  1407. * fix generic size problems which depend now on EXTEND_SIZE constant
  1408. Revision 1.14 2002/04/15 19:44:18 peter
  1409. * fixed stackcheck that would be called recursively when a stack
  1410. error was found
  1411. * generic changeregsize(reg,size) for i386 register resizing
  1412. * removed some more routines from cga unit
  1413. * fixed returnvalue handling
  1414. * fixed default stacksize of linux and go32v2, 8kb was a bit small :-)
  1415. Revision 1.13 2002/04/07 13:22:11 carl
  1416. + more documentation
  1417. Revision 1.12 2002/04/07 09:12:46 carl
  1418. + documentation
  1419. Revision 1.11 2002/04/06 18:10:42 jonas
  1420. * several powerpc-related additions and fixes
  1421. Revision 1.10 2002/04/04 19:05:54 peter
  1422. * removed unused units
  1423. * use tlocation.size in cg.a_*loc*() routines
  1424. Revision 1.9 2002/04/02 17:11:27 peter
  1425. * tlocation,treference update
  1426. * LOC_CONSTANT added for better constant handling
  1427. * secondadd splitted in multiple routines
  1428. * location_force_reg added for loading a location to a register
  1429. of a specified size
  1430. * secondassignment parses now first the right and then the left node
  1431. (this is compatible with Kylix). This saves a lot of push/pop especially
  1432. with string operations
  1433. * adapted some routines to use the new cg methods
  1434. Revision 1.8 2002/03/31 20:26:33 jonas
  1435. + a_loadfpu_* and a_loadmm_* methods in tcg
  1436. * register allocation is now handled by a class and is mostly processor
  1437. independent (+rgobj.pas and i386/rgcpu.pas)
  1438. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  1439. * some small improvements and fixes to the optimizer
  1440. * some register allocation fixes
  1441. * some fpuvaroffset fixes in the unary minus node
  1442. * push/popusedregisters is now called rg.save/restoreusedregisters and
  1443. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  1444. also better optimizable)
  1445. * fixed and optimized register saving/restoring for new/dispose nodes
  1446. * LOC_FPU locations now also require their "register" field to be set to
  1447. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  1448. - list field removed of the tnode class because it's not used currently
  1449. and can cause hard-to-find bugs
  1450. Revision 1.7 2002/03/04 19:10:11 peter
  1451. * removed compiler warnings
  1452. Revision 1.6 2001/12/30 17:24:48 jonas
  1453. * range checking is now processor independent (part in cgobj,
  1454. part in cg64f32) and should work correctly again (it needed
  1455. some changes after the changes of the low and high of
  1456. tordef's to int64)
  1457. * maketojumpbool() is now processor independent (in ncgutil)
  1458. * getregister32 is now called getregisterint
  1459. Revision 1.5 2001/12/29 15:28:58 jonas
  1460. * powerpc/cgcpu.pas compiles :)
  1461. * several powerpc-related fixes
  1462. * cpuasm unit is now based on common tainst unit
  1463. + nppcmat unit for powerpc (almost complete)
  1464. Revision 1.4 2001/09/30 21:26:42 peter
  1465. * removed obsolete newst defines
  1466. Revision 1.3 2001/09/30 16:17:17 jonas
  1467. * made most constant and mem handling processor independent
  1468. Revision 1.2 2001/09/28 20:39:32 jonas
  1469. * changed all flow control structures (except for exception handling
  1470. related things) to processor independent code (in new ncgflw unit)
  1471. + generic cgobj unit which contains lots of code generator helpers with
  1472. global "cg" class instance variable
  1473. + cgcpu unit for i386 (implements processor specific routines of the above
  1474. unit)
  1475. * updated cgbase and cpubase for the new code generator units
  1476. * include ncgflw unit in cpunode unit
  1477. Revision 1.5 2001/09/09 17:10:26 jonas
  1478. * some more things implemented
  1479. Revision 1.4 2001/09/06 15:25:55 jonas
  1480. * changed type of tcg from object to class -> abstract methods are now
  1481. a lot cleaner :)
  1482. + more updates: load_*_loc methods, op_*_* methods, g_flags2reg method
  1483. (if possible with geenric implementation and necessary ppc
  1484. implementations)
  1485. * worked a bit further on cgflw, now working on exitnode
  1486. Revision 1.3 2001/09/05 20:21:03 jonas
  1487. * new cgflow based on n386flw with all nodes until forn "translated"
  1488. + a_cmp_loc_*_label methods for tcg
  1489. + base implementatino for a_cmp_ref_*_label methods
  1490. * small bugfixes to powerpc cg
  1491. Revision 1.2 2001/08/26 13:37:04 florian
  1492. * some cg reorganisation
  1493. * some PPC updates
  1494. Revision 1.1 2000/07/13 06:30:07 michael
  1495. + Initial import
  1496. }