aasmtai.pas 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements an abstract asmoutput class for all processor types
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { @abstract(This unit implements an abstract asm output class for all processor types)
  19. This unit implements an abstract assembler output class for all processors, these
  20. are then overriden for each assembler writer to actually write the data in these
  21. classes to an assembler file.
  22. }
  23. unit aasmtai;
  24. {$i fpcdefs.inc}
  25. interface
  26. uses
  27. cutils,cclasses,
  28. globtype,globals,systems,
  29. cpuinfo,cpubase,
  30. cgbase,cgutils,
  31. symtype,
  32. aasmbase;
  33. type
  34. taitype = (
  35. ait_none,
  36. ait_align,
  37. ait_section,
  38. ait_comment,
  39. ait_direct,
  40. ait_string,
  41. ait_instruction,
  42. ait_datablock,
  43. ait_symbol,
  44. ait_symbol_end, { needed to calc the size of a symbol }
  45. ait_label,
  46. { the const_xx must be below each other so it can be used as
  47. array index }
  48. ait_const_128bit,
  49. ait_const_64bit,
  50. ait_const_32bit,
  51. ait_const_16bit,
  52. ait_const_8bit,
  53. ait_const_sleb128bit,
  54. ait_const_uleb128bit,
  55. ait_const_rva_symbol, { win32 only }
  56. ait_const_indirect_symbol, { darwin only }
  57. ait_real_32bit,
  58. ait_real_64bit,
  59. ait_real_80bit,
  60. ait_comp_64bit,
  61. ait_real_128bit,
  62. {$ifdef GDB}
  63. ait_stabn,
  64. ait_stabs,
  65. ait_force_line,
  66. ait_stab_function_name,
  67. {$endif GDB}
  68. {$ifdef alpha}
  69. { the follow is for the DEC Alpha }
  70. ait_frame,
  71. ait_ent,
  72. {$endif alpha}
  73. {$ifdef ia64}
  74. ait_bundle,
  75. ait_stop,
  76. {$endif ia64}
  77. {$ifdef m68k}
  78. ait_labeled_instruction,
  79. {$endif m68k}
  80. { used to split into tiny assembler files }
  81. ait_cutobject,
  82. ait_regalloc,
  83. ait_tempalloc,
  84. { used to mark assembler blocks and inlined functions }
  85. ait_marker,
  86. { special symbol for darwin pic code }
  87. ait_non_lazy_symbol_pointer
  88. );
  89. const
  90. {$ifdef cpu64bit}
  91. ait_const_aint = ait_const_64bit;
  92. ait_const_ptr = ait_const_64bit;
  93. {$else cpu64bit}
  94. ait_const_aint = ait_const_32bit;
  95. ait_const_ptr = ait_const_32bit;
  96. {$endif cpu64bit}
  97. taitypestr : array[taitype] of string[24] = (
  98. '<none>',
  99. 'align',
  100. 'section',
  101. 'comment',
  102. 'direct',
  103. 'string',
  104. 'instruction',
  105. 'datablock',
  106. 'symbol',
  107. 'symbol_end',
  108. 'label',
  109. 'const_128bit',
  110. 'const_64bit',
  111. 'const_32bit',
  112. 'const_16bit',
  113. 'const_8bit',
  114. 'const_sleb128bit',
  115. 'const_uleb128bit',
  116. 'const_rva_symbol',
  117. 'const_indirect_symbol',
  118. 'real_32bit',
  119. 'real_64bit',
  120. 'real_80bit',
  121. 'comp_64bit',
  122. 'real_128bit',
  123. {$ifdef GDB}
  124. 'stabn',
  125. 'stabs',
  126. 'force_line',
  127. 'stab_funcname',
  128. {$endif GDB}
  129. {$ifdef alpha}
  130. { the follow is for the DEC Alpha }
  131. 'frame',
  132. 'ent',
  133. {$endif alpha}
  134. {$ifdef ia64}
  135. 'bundle',
  136. 'stop',
  137. {$endif ia64}
  138. {$ifdef m68k}
  139. 'labeled_instr',
  140. {$endif m68k}
  141. 'cut',
  142. 'regalloc',
  143. 'tempalloc',
  144. 'marker',
  145. 'non_lazy_symbol_pointer'
  146. );
  147. type
  148. { Types of operand }
  149. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local,
  150. { ARM only }
  151. top_regset,
  152. top_shifterop,
  153. { m68k only }
  154. top_reglist);
  155. { kinds of operations that an instruction can perform on an operand }
  156. topertype = (operand_read,operand_write,operand_readwrite);
  157. tlocaloper = record
  158. localsym : pointer;
  159. localsymderef : tderef;
  160. localsymofs : longint;
  161. localindexreg : tregister;
  162. localscale : byte;
  163. localgetoffset : boolean
  164. end;
  165. plocaloper = ^tlocaloper;
  166. { please keep the size of this record <=12 bytes and keep it properly aligned }
  167. toper = record
  168. ot : longint;
  169. case typ : toptype of
  170. top_none : ();
  171. top_reg : (reg:tregister);
  172. top_ref : (ref:preference);
  173. top_const : (val:aint);
  174. top_bool : (b:boolean);
  175. { local varsym that will be inserted in pass_2 }
  176. top_local : (localoper:plocaloper);
  177. {$ifdef arm}
  178. top_regset : (regset:^tcpuregisterset);
  179. top_shifterop : (shifterop : pshifterop);
  180. {$endif arm}
  181. {$ifdef m68k}
  182. top_regset : (regset:^tcpuregisterset);
  183. {$endif m68k}
  184. end;
  185. poper=^toper;
  186. { ait_* types which don't result in executable code or which don't influence }
  187. { the way the program runs/behaves, but which may be encountered by the }
  188. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  189. { a new ait type! }
  190. const
  191. SkipInstr = [ait_comment, ait_symbol,ait_section
  192. {$ifdef GDB}
  193. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  194. {$endif GDB}
  195. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  196. { ait_* types which do not have line information (and hence which are of type
  197. tai, otherwise, they are of type tailineinfo }
  198. SkipLineInfo =[ait_label,
  199. ait_regalloc,ait_tempalloc,
  200. {$ifdef GDB}
  201. ait_stabn,ait_stabs,ait_stab_function_name,
  202. {$endif GDB}
  203. ait_cutobject,ait_marker,ait_align,ait_section,ait_comment,
  204. ait_const_8bit,ait_const_16bit,ait_const_32bit,ait_const_64bit,ait_const_128bit,
  205. ait_const_sleb128bit,ait_const_uleb128bit,
  206. ait_const_rva_symbol,ait_const_indirect_symbol,
  207. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  208. ait_non_lazy_symbol_pointer
  209. ];
  210. type
  211. { cut type, required for alphanumeric ordering of the assembler filenames }
  212. TCutPlace=(cut_normal,cut_begin,cut_end);
  213. TRegAllocType = (ra_alloc,ra_dealloc,ra_resize);
  214. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  215. AsmBlockStart,AsmBlockEnd,
  216. InlineStart,InlineEnd,marker_blockstart,
  217. marker_position);
  218. { Buffer type used for alignment }
  219. tfillbuffer = array[0..63] of char;
  220. Tspill_temp_list=array[tsuperregister] of Treference;
  221. { abstract assembler item }
  222. tai = class(TLinkedListItem)
  223. {$ifndef NOOPT}
  224. { pointer to record with optimizer info about this tai object }
  225. optinfo : pointer;
  226. {$endif NOOPT}
  227. typ : taitype;
  228. constructor Create;
  229. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  230. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  231. procedure buildderefimpl;virtual;
  232. procedure derefimpl;virtual;
  233. end;
  234. { abstract assembler item with line information }
  235. tailineinfo = class(tai)
  236. fileinfo : tfileposinfo;
  237. constructor Create;
  238. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  239. procedure ppuwrite(ppufile:tcompilerppufile);override;
  240. end;
  241. tai_simple = class(tai)
  242. constructor create(_typ : taitype);
  243. end;
  244. taiclass = class of tai;
  245. taiclassarray = array[taitype] of taiclass;
  246. { Generates an assembler string }
  247. tai_string = class(tailineinfo)
  248. str : pchar;
  249. { extra len so the string can contain an \0 }
  250. len : longint;
  251. constructor Create(const _str : string);
  252. constructor Create_pchar(_str : pchar);
  253. constructor Create_length_pchar(_str : pchar;length : longint);
  254. destructor Destroy;override;
  255. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  256. procedure ppuwrite(ppufile:tcompilerppufile);override;
  257. function getcopy:tlinkedlistitem;override;
  258. end;
  259. { Generates a common label }
  260. tai_symbol = class(tailineinfo)
  261. is_global : boolean;
  262. sym : tasmsymbol;
  263. size : longint;
  264. constructor Create(_sym:tasmsymbol;siz:longint);
  265. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  266. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  267. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  268. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;
  270. procedure derefimpl;override;
  271. end;
  272. tai_symbol_end = class(tailineinfo)
  273. sym : tasmsymbol;
  274. constructor Create(_sym:tasmsymbol);
  275. constructor Createname(const _name : string);
  276. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  277. procedure ppuwrite(ppufile:tcompilerppufile);override;
  278. procedure derefimpl;override;
  279. end;
  280. { Generates an assembler label }
  281. tai_label = class(tai)
  282. is_global : boolean;
  283. l : tasmlabel;
  284. constructor Create(_l : tasmlabel);
  285. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure derefimpl;override;
  288. end;
  289. { Directly output data to final assembler file }
  290. tai_direct = class(tailineinfo)
  291. str : pchar;
  292. constructor Create(_str : pchar);
  293. destructor Destroy; override;
  294. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. function getcopy:tlinkedlistitem;override;
  297. end;
  298. { Generates an assembler comment }
  299. tai_comment = class(tai)
  300. str : pchar;
  301. constructor Create(_str : pchar);
  302. destructor Destroy; override;
  303. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  304. procedure ppuwrite(ppufile:tcompilerppufile);override;
  305. function getcopy:tlinkedlistitem;override;
  306. end;
  307. { Generates a section / segment directive }
  308. tai_section = class(tai)
  309. sectype : TAsmSectionType;
  310. secalign : byte;
  311. name : pstring;
  312. sec : TAsmSection; { used in binary writer }
  313. constructor Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  314. destructor Destroy;override;
  315. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  316. procedure ppuwrite(ppufile:tcompilerppufile);override;
  317. end;
  318. { Generates an uninitializised data block }
  319. tai_datablock = class(tailineinfo)
  320. is_global : boolean;
  321. sym : tasmsymbol;
  322. size : longint;
  323. constructor Create(const _name : string;_size : longint);
  324. constructor Create_global(const _name : string;_size : longint);
  325. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  326. procedure ppuwrite(ppufile:tcompilerppufile);override;
  327. procedure derefimpl;override;
  328. end;
  329. { Generates an integer const }
  330. tai_const = class(tai)
  331. sym,
  332. endsym : tasmsymbol;
  333. value : int64;
  334. { we use for the 128bit int64/qword for now because I can't imagine a
  335. case where we need 128 bit now (FK) }
  336. constructor Create(_typ:taitype;_value : int64);
  337. constructor Create_128bit(_value : int64);
  338. constructor Create_64bit(_value : int64);
  339. constructor Create_32bit(_value : longint);
  340. constructor Create_16bit(_value : word);
  341. constructor Create_8bit(_value : byte);
  342. constructor Create_sleb128bit(_value : int64);
  343. constructor Create_uleb128bit(_value : qword);
  344. constructor Create_aint(_value : aint);
  345. constructor Create_sym(_sym:tasmsymbol);
  346. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  347. constructor Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  348. constructor Create_rva_sym(_sym:tasmsymbol);
  349. constructor Create_indirect_sym(_sym:tasmsymbol);
  350. constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  351. constructor Createname_rva(const name:string);
  352. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  353. procedure ppuwrite(ppufile:tcompilerppufile);override;
  354. procedure derefimpl;override;
  355. function getcopy:tlinkedlistitem;override;
  356. function size:longint;
  357. end;
  358. { Generates a single float (32 bit real) }
  359. tai_real_32bit = class(tai)
  360. value : ts32real;
  361. constructor Create(_value : ts32real);
  362. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  363. procedure ppuwrite(ppufile:tcompilerppufile);override;
  364. end;
  365. tformatoptions = (fo_none,fo_hiloswapped);
  366. { Generates a double float (64 bit real) }
  367. tai_real_64bit = class(tai)
  368. value : ts64real;
  369. {$ifdef ARM}
  370. formatoptions : tformatoptions;
  371. constructor Create_hiloswapped(_value : ts64real);
  372. {$endif ARM}
  373. constructor Create(_value : ts64real);
  374. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  375. procedure ppuwrite(ppufile:tcompilerppufile);override;
  376. end;
  377. { Generates an extended float (80 bit real) }
  378. tai_real_80bit = class(tai)
  379. value : ts80real;
  380. constructor Create(_value : ts80real);
  381. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  382. procedure ppuwrite(ppufile:tcompilerppufile);override;
  383. end;
  384. { Generates an float128 (128 bit real) }
  385. tai_real_128bit = class(tai)
  386. value : ts128real;
  387. constructor Create(_value : ts128real);
  388. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  389. procedure ppuwrite(ppufile:tcompilerppufile);override;
  390. end;
  391. { Generates a comp int (integer over 64 bits)
  392. This is Intel 80x86 specific, and is not
  393. really supported on other processors.
  394. }
  395. tai_comp_64bit = class(tai)
  396. value : ts64comp;
  397. constructor Create(_value : ts64comp);
  398. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  399. procedure ppuwrite(ppufile:tcompilerppufile);override;
  400. end;
  401. { Insert a cut to split assembler into several smaller files }
  402. tai_cutobject = class(tai)
  403. place : tcutplace;
  404. constructor Create;
  405. constructor Create_begin;
  406. constructor Create_end;
  407. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  408. procedure ppuwrite(ppufile:tcompilerppufile);override;
  409. end;
  410. { Insert a marker for assembler and inline blocks }
  411. tai_marker = class(tai)
  412. Kind: TMarker;
  413. Constructor Create(_Kind: TMarker);
  414. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  415. procedure ppuwrite(ppufile:tcompilerppufile);override;
  416. end;
  417. tai_tempalloc = class(tai)
  418. allocation : boolean;
  419. {$ifdef EXTDEBUG}
  420. problem : pstring;
  421. {$endif EXTDEBUG}
  422. temppos,
  423. tempsize : longint;
  424. constructor alloc(pos,size:longint);
  425. constructor dealloc(pos,size:longint);
  426. {$ifdef EXTDEBUG}
  427. constructor allocinfo(pos,size:longint;const st:string);
  428. {$endif EXTDEBUG}
  429. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  430. destructor destroy;override;
  431. procedure ppuwrite(ppufile:tcompilerppufile);override;
  432. end;
  433. tai_regalloc = class(tai)
  434. reg : tregister;
  435. ratype : TRegAllocType;
  436. constructor alloc(r : tregister);
  437. constructor dealloc(r : tregister);
  438. constructor resize(r : tregister);
  439. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  440. procedure ppuwrite(ppufile:tcompilerppufile);override;
  441. end;
  442. Taasmoutput=class;
  443. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  444. Trggetproc=procedure(list:Taasmoutput;position:Tai;subreg:Tsubregister;var result:Tregister) of object;
  445. Trgungetproc=procedure(list:Taasmoutput;position:Tai;r:Tregister) of object;
  446. { Class template for assembler instructions
  447. }
  448. tai_cpu_abstract = class(tailineinfo)
  449. protected
  450. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  451. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  452. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  453. procedure ppuderefoper(var o:toper);virtual;abstract;
  454. public
  455. { Condition flags for instruction }
  456. condition : TAsmCond;
  457. { Number of operands to instruction }
  458. ops : byte;
  459. { Number of allocate oper structures }
  460. opercnt : byte;
  461. { Operands of instruction }
  462. oper : array[0..max_operands-1] of poper;
  463. { Actual opcode of instruction }
  464. opcode : tasmop;
  465. {$ifdef x86}
  466. segprefix : tregister;
  467. {$endif x86}
  468. { true if instruction is a jmp }
  469. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  470. Constructor Create(op : tasmop);virtual;
  471. Destructor Destroy;override;
  472. function getcopy:TLinkedListItem;override;
  473. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  474. procedure ppuwrite(ppufile:tcompilerppufile);override;
  475. procedure buildderefimpl;override;
  476. procedure derefimpl;override;
  477. procedure SetCondition(const c:TAsmCond);
  478. procedure allocate_oper(opers:longint);
  479. procedure loadconst(opidx:longint;l:aint);
  480. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  481. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  482. procedure loadref(opidx:longint;const r:treference);
  483. procedure loadreg(opidx:longint;r:tregister);
  484. procedure loadoper(opidx:longint;o:toper);
  485. procedure clearop(opidx:longint);
  486. { register allocator }
  487. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  488. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  489. end;
  490. tai_cpu_class = class of tai_cpu_abstract;
  491. { alignment for operator }
  492. tai_align_abstract = class(tai)
  493. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  494. fillsize : byte; { real size to fill }
  495. fillop : byte; { value to fill with - optional }
  496. use_op : boolean;
  497. constructor Create(b:byte);virtual;
  498. constructor Create_op(b: byte; _op: byte);virtual;
  499. constructor Create_zeros(b:byte);
  500. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  501. procedure ppuwrite(ppufile:tcompilerppufile);override;
  502. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  503. end;
  504. tai_align_class = class of tai_align_abstract;
  505. taasmoutput = class(tlinkedlist)
  506. constructor create;
  507. function empty : boolean;
  508. function getlasttaifilepos : pfileposinfo;
  509. procedure InsertAfter(Item,Loc : TLinkedListItem);override;
  510. end;
  511. var
  512. { array with all class types for tais }
  513. aiclass : taiclassarray;
  514. { Current expression list }
  515. exprasmlist : taasmoutput;
  516. { labels for BREAK and CONTINUE }
  517. aktbreaklabel,aktcontinuelabel : tasmlabel;
  518. { label when the result is true or false }
  519. truelabel,falselabel : tasmlabel;
  520. { hook to notify uses of registers }
  521. add_reg_instruction_hook : tadd_reg_instruction_proc;
  522. { default lists }
  523. datasegment,codesegment,bsssegment,
  524. debuglist,withdebuglist,consts,
  525. importssection,exportssection,
  526. resourcesection,rttilist,
  527. dwarflist,
  528. { data used by pic code }
  529. picdata,
  530. resourcestringlist : taasmoutput;
  531. cai_align : tai_align_class;
  532. cai_cpu : tai_cpu_class;
  533. function use_smartlink_section:boolean;
  534. function maybe_smartlink_symbol:boolean;
  535. procedure maybe_new_object_file(list:taasmoutput);
  536. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  537. function ppuloadai(ppufile:tcompilerppufile):tai;
  538. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  539. implementation
  540. uses
  541. {$ifdef delphi}
  542. sysutils,
  543. {$else}
  544. strings,
  545. {$endif}
  546. verbose;
  547. const
  548. pputaimarker = 254;
  549. {****************************************************************************
  550. Helpers
  551. ****************************************************************************}
  552. function ppuloadai(ppufile:tcompilerppufile):tai;
  553. var
  554. b : byte;
  555. t : taitype;
  556. begin
  557. { marker }
  558. b:=ppufile.getbyte;
  559. if b<>pputaimarker then
  560. internalerror(200208181);
  561. { load nodetype }
  562. t:=taitype(ppufile.getbyte);
  563. if t<>ait_none then
  564. begin
  565. if t>high(taitype) then
  566. internalerror(200208182);
  567. if not assigned(aiclass[t]) then
  568. internalerror(200208183);
  569. {writeln('taiload: ',taitypestr[t]);}
  570. { generate tai of the correct class }
  571. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  572. end
  573. else
  574. ppuloadai:=nil;
  575. end;
  576. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  577. begin
  578. { marker, read by ppuloadnode }
  579. ppufile.putbyte(pputaimarker);
  580. if assigned(n) then
  581. begin
  582. { type, read by ppuloadnode }
  583. ppufile.putbyte(byte(n.typ));
  584. {writeln('taiwrite: ',taitypestr[n.typ]);}
  585. n.ppuwrite(ppufile);
  586. end
  587. else
  588. ppufile.putbyte(byte(ait_none));
  589. end;
  590. function use_smartlink_section:boolean;
  591. begin
  592. result:=(af_smartlink_sections in target_asm.flags) and
  593. (tf_smartlink_sections in target_info.flags) and
  594. not(cs_debuginfo in aktmoduleswitches);
  595. end;
  596. function maybe_smartlink_symbol:boolean;
  597. begin
  598. result:=(cs_create_smart in aktmoduleswitches) or
  599. use_smartlink_section;
  600. end;
  601. procedure maybe_new_object_file(list:taasmoutput);
  602. begin
  603. if (cs_create_smart in aktmoduleswitches) and
  604. (not use_smartlink_section) then
  605. list.concat(tai_cutobject.create);
  606. end;
  607. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  608. begin
  609. list.concat(tai_section.create(Asectype,Aname,Aalign));
  610. list.concat(cai_align.create(Aalign));
  611. end;
  612. {****************************************************************************
  613. TAI
  614. ****************************************************************************}
  615. constructor tai.Create;
  616. begin
  617. {$ifndef NOOPT}
  618. optinfo:=nil;
  619. {$endif NOOPT}
  620. end;
  621. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  622. begin
  623. typ:=t;
  624. {$ifndef NOOPT}
  625. optinfo:=nil;
  626. {$endif}
  627. end;
  628. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  629. begin
  630. end;
  631. procedure tai.buildderefimpl;
  632. begin
  633. end;
  634. procedure tai.derefimpl;
  635. begin
  636. end;
  637. {****************************************************************************
  638. TAILINEINFO
  639. ****************************************************************************}
  640. constructor tailineinfo.create;
  641. begin
  642. inherited create;
  643. if not(inlining_procedure and
  644. (cs_gdb_valgrind in aktglobalswitches)) then
  645. fileinfo:=aktfilepos;
  646. end;
  647. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  648. begin
  649. inherited ppuload(t,ppufile);
  650. ppufile.getposinfo(fileinfo);
  651. end;
  652. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  653. begin
  654. inherited ppuwrite(ppufile);
  655. ppufile.putposinfo(fileinfo);
  656. end;
  657. {****************************************************************************
  658. TAI_SIMPLE
  659. ****************************************************************************}
  660. constructor tai_simple.create(_typ : taitype);
  661. begin
  662. inherited create;
  663. typ:=_typ;
  664. end;
  665. {****************************************************************************
  666. TAI_SECTION
  667. ****************************************************************************}
  668. constructor tai_section.Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  669. begin
  670. inherited Create;
  671. typ:=ait_section;
  672. sectype:=asectype;
  673. secalign:=Aalign;
  674. name:=stringdup(Aname);
  675. sec:=nil;
  676. end;
  677. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  678. begin
  679. inherited ppuload(t,ppufile);
  680. sectype:=tasmsectiontype(ppufile.getbyte);
  681. secalign:=ppufile.getbyte;
  682. name:=stringdup(ppufile.getstring);
  683. sec:=nil;
  684. end;
  685. destructor tai_section.Destroy;
  686. begin
  687. stringdispose(name);
  688. end;
  689. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  690. begin
  691. inherited ppuwrite(ppufile);
  692. ppufile.putbyte(byte(sectype));
  693. ppufile.putbyte(secalign);
  694. ppufile.putstring(name^);
  695. end;
  696. {****************************************************************************
  697. TAI_DATABLOCK
  698. ****************************************************************************}
  699. constructor tai_datablock.Create(const _name : string;_size : longint);
  700. begin
  701. inherited Create;
  702. typ:=ait_datablock;
  703. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
  704. { keep things aligned }
  705. if _size<=0 then
  706. _size:=4;
  707. size:=_size;
  708. is_global:=false;
  709. end;
  710. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  711. begin
  712. inherited Create;
  713. typ:=ait_datablock;
  714. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
  715. { keep things aligned }
  716. if _size<=0 then
  717. _size:=4;
  718. size:=_size;
  719. is_global:=true;
  720. end;
  721. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  722. begin
  723. inherited Create;
  724. sym:=ppufile.getasmsymbol;
  725. size:=ppufile.getlongint;
  726. is_global:=boolean(ppufile.getbyte);
  727. end;
  728. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  729. begin
  730. inherited ppuwrite(ppufile);
  731. ppufile.putasmsymbol(sym);
  732. ppufile.putlongint(size);
  733. ppufile.putbyte(byte(is_global));
  734. end;
  735. procedure tai_datablock.derefimpl;
  736. begin
  737. objectlibrary.DerefAsmsymbol(sym);
  738. end;
  739. {****************************************************************************
  740. TAI_SYMBOL
  741. ****************************************************************************}
  742. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  743. begin
  744. inherited Create;
  745. typ:=ait_symbol;
  746. sym:=_sym;
  747. size:=siz;
  748. sym.defbind:=AB_LOCAL;
  749. is_global:=false;
  750. end;
  751. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  752. begin
  753. inherited Create;
  754. typ:=ait_symbol;
  755. sym:=_sym;
  756. size:=siz;
  757. sym.defbind:=AB_GLOBAL;
  758. is_global:=true;
  759. end;
  760. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  761. begin
  762. inherited Create;
  763. typ:=ait_symbol;
  764. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
  765. size:=siz;
  766. is_global:=false;
  767. end;
  768. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  769. begin
  770. inherited Create;
  771. typ:=ait_symbol;
  772. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
  773. size:=siz;
  774. is_global:=true;
  775. end;
  776. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  777. begin
  778. inherited ppuload(t,ppufile);
  779. sym:=ppufile.getasmsymbol;
  780. size:=ppufile.getlongint;
  781. is_global:=boolean(ppufile.getbyte);
  782. end;
  783. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  784. begin
  785. inherited ppuwrite(ppufile);
  786. ppufile.putasmsymbol(sym);
  787. ppufile.putlongint(size);
  788. ppufile.putbyte(byte(is_global));
  789. end;
  790. procedure tai_symbol.derefimpl;
  791. begin
  792. objectlibrary.DerefAsmsymbol(sym);
  793. end;
  794. {****************************************************************************
  795. TAI_SYMBOL_END
  796. ****************************************************************************}
  797. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  798. begin
  799. inherited Create;
  800. typ:=ait_symbol_end;
  801. sym:=_sym;
  802. end;
  803. constructor tai_symbol_end.Createname(const _name : string);
  804. begin
  805. inherited Create;
  806. typ:=ait_symbol_end;
  807. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
  808. end;
  809. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  810. begin
  811. inherited ppuload(t,ppufile);
  812. sym:=ppufile.getasmsymbol;
  813. end;
  814. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  815. begin
  816. inherited ppuwrite(ppufile);
  817. ppufile.putasmsymbol(sym);
  818. end;
  819. procedure tai_symbol_end.derefimpl;
  820. begin
  821. objectlibrary.DerefAsmsymbol(sym);
  822. end;
  823. {****************************************************************************
  824. TAI_CONST
  825. ****************************************************************************}
  826. constructor tai_const.Create(_typ:taitype;_value : int64);
  827. begin
  828. inherited Create;
  829. typ:=_typ;
  830. value:=_value;
  831. sym:=nil;
  832. endsym:=nil;
  833. end;
  834. constructor tai_const.Create_128bit(_value : int64);
  835. begin
  836. inherited Create;
  837. typ:=ait_const_128bit;
  838. value:=_value;
  839. sym:=nil;
  840. endsym:=nil;
  841. end;
  842. constructor tai_const.Create_64bit(_value : int64);
  843. begin
  844. inherited Create;
  845. typ:=ait_const_64bit;
  846. value:=_value;
  847. sym:=nil;
  848. endsym:=nil;
  849. end;
  850. constructor tai_const.Create_32bit(_value : longint);
  851. begin
  852. inherited Create;
  853. typ:=ait_const_32bit;
  854. value:=_value;
  855. sym:=nil;
  856. endsym:=nil;
  857. end;
  858. constructor tai_const.Create_16bit(_value : word);
  859. begin
  860. inherited Create;
  861. typ:=ait_const_16bit;
  862. value:=_value;
  863. sym:=nil;
  864. endsym:=nil;
  865. end;
  866. constructor tai_const.Create_8bit(_value : byte);
  867. begin
  868. inherited Create;
  869. typ:=ait_const_8bit;
  870. value:=_value;
  871. sym:=nil;
  872. endsym:=nil;
  873. end;
  874. constructor tai_const.Create_sleb128bit(_value : int64);
  875. begin
  876. inherited Create;
  877. typ:=ait_const_sleb128bit;
  878. value:=_value;
  879. sym:=nil;
  880. endsym:=nil;
  881. end;
  882. constructor tai_const.Create_uleb128bit(_value : qword);
  883. begin
  884. inherited Create;
  885. typ:=ait_const_uleb128bit;
  886. value:=int64(_value);
  887. sym:=nil;
  888. endsym:=nil;
  889. end;
  890. constructor tai_const.Create_aint(_value : aint);
  891. begin
  892. inherited Create;
  893. typ:=ait_const_aint;
  894. value:=_value;
  895. sym:=nil;
  896. endsym:=nil;
  897. end;
  898. constructor tai_const.Create_sym(_sym:tasmsymbol);
  899. begin
  900. inherited Create;
  901. typ:=ait_const_ptr;
  902. { sym is allowed to be nil, this is used to write nil pointers }
  903. sym:=_sym;
  904. endsym:=nil;
  905. value:=0;
  906. { update sym info }
  907. if assigned(sym) then
  908. sym.increfs;
  909. end;
  910. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  911. begin
  912. inherited Create;
  913. typ:=ait_const_ptr;
  914. if not assigned(_sym) then
  915. internalerror(200404121);
  916. sym:=_sym;
  917. endsym:=nil;
  918. value:=ofs;
  919. { update sym info }
  920. sym.increfs;
  921. end;
  922. constructor tai_const.Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  923. begin
  924. inherited Create;
  925. typ:=_typ;
  926. sym:=_sym;
  927. endsym:=_endsym;
  928. value:=0;
  929. { update sym info }
  930. sym.increfs;
  931. endsym.increfs;
  932. end;
  933. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  934. begin
  935. inherited Create;
  936. typ:=ait_const_rva_symbol;
  937. sym:=_sym;
  938. endsym:=nil;
  939. value:=0;
  940. { update sym info }
  941. sym.increfs;
  942. end;
  943. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  944. begin
  945. inherited Create;
  946. typ:=ait_const_indirect_symbol;
  947. sym:=_sym;
  948. endsym:=nil;
  949. value:=0;
  950. { update sym info }
  951. sym.increfs;
  952. end;
  953. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  954. begin
  955. inherited Create;
  956. typ:=ait_const_ptr;
  957. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
  958. endsym:=nil;
  959. value:=ofs;
  960. { update sym info }
  961. sym.increfs;
  962. end;
  963. constructor tai_const.Createname_rva(const name:string);
  964. begin
  965. inherited Create;
  966. typ:=ait_const_rva_symbol;
  967. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
  968. endsym:=nil;
  969. value:=0;
  970. { update sym info }
  971. sym.increfs;
  972. end;
  973. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  974. begin
  975. inherited ppuload(t,ppufile);
  976. sym:=ppufile.getasmsymbol;
  977. endsym:=ppufile.getasmsymbol;
  978. value:=ppufile.getint64;
  979. end;
  980. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  981. begin
  982. inherited ppuwrite(ppufile);
  983. ppufile.putasmsymbol(sym);
  984. ppufile.putasmsymbol(endsym);
  985. ppufile.putint64(value);
  986. end;
  987. procedure tai_const.derefimpl;
  988. begin
  989. objectlibrary.DerefAsmsymbol(sym);
  990. objectlibrary.DerefAsmsymbol(endsym);
  991. end;
  992. function tai_const.getcopy:tlinkedlistitem;
  993. begin
  994. getcopy:=inherited getcopy;
  995. { we need to increase the reference number }
  996. sym.increfs;
  997. if assigned(endsym) then
  998. endsym.increfs;
  999. end;
  1000. function tai_const.size:longint;
  1001. begin
  1002. case typ of
  1003. ait_const_8bit :
  1004. result:=1;
  1005. ait_const_16bit :
  1006. result:=2;
  1007. ait_const_32bit :
  1008. result:=4;
  1009. ait_const_64bit :
  1010. result:=8;
  1011. ait_const_indirect_symbol,
  1012. ait_const_rva_symbol :
  1013. result:=sizeof(aint);
  1014. end;
  1015. end;
  1016. {****************************************************************************
  1017. TAI_real_32bit
  1018. ****************************************************************************}
  1019. constructor tai_real_32bit.Create(_value : ts32real);
  1020. begin
  1021. inherited Create;
  1022. typ:=ait_real_32bit;
  1023. value:=_value;
  1024. end;
  1025. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1026. begin
  1027. inherited ppuload(t,ppufile);
  1028. value:=ppufile.getreal;
  1029. end;
  1030. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1031. begin
  1032. inherited ppuwrite(ppufile);
  1033. ppufile.putreal(value);
  1034. end;
  1035. {****************************************************************************
  1036. TAI_real_64bit
  1037. ****************************************************************************}
  1038. constructor tai_real_64bit.Create(_value : ts64real);
  1039. begin
  1040. inherited Create;
  1041. typ:=ait_real_64bit;
  1042. value:=_value;
  1043. end;
  1044. {$ifdef ARM}
  1045. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1046. begin
  1047. inherited Create;
  1048. typ:=ait_real_64bit;
  1049. value:=_value;
  1050. formatoptions:=fo_hiloswapped;
  1051. end;
  1052. {$endif ARM}
  1053. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1054. begin
  1055. inherited ppuload(t,ppufile);
  1056. value:=ppufile.getreal;
  1057. {$ifdef ARM}
  1058. formatoptions:=tformatoptions(ppufile.getbyte);
  1059. {$endif ARM}
  1060. end;
  1061. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1062. begin
  1063. inherited ppuwrite(ppufile);
  1064. ppufile.putreal(value);
  1065. {$ifdef ARM}
  1066. ppufile.putbyte(byte(formatoptions));
  1067. {$endif ARM}
  1068. end;
  1069. {****************************************************************************
  1070. TAI_real_80bit
  1071. ****************************************************************************}
  1072. constructor tai_real_80bit.Create(_value : ts80real);
  1073. begin
  1074. inherited Create;
  1075. typ:=ait_real_80bit;
  1076. value:=_value;
  1077. end;
  1078. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1079. begin
  1080. inherited ppuload(t,ppufile);
  1081. value:=ppufile.getreal;
  1082. end;
  1083. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1084. begin
  1085. inherited ppuwrite(ppufile);
  1086. ppufile.putreal(value);
  1087. end;
  1088. {****************************************************************************
  1089. TAI_real_80bit
  1090. ****************************************************************************}
  1091. constructor tai_real_128bit.Create(_value : ts128real);
  1092. begin
  1093. inherited Create;
  1094. typ:=ait_real_128bit;
  1095. value:=_value;
  1096. end;
  1097. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1098. begin
  1099. inherited ppuload(t,ppufile);
  1100. value:=ppufile.getreal;
  1101. end;
  1102. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1103. begin
  1104. inherited ppuwrite(ppufile);
  1105. ppufile.putreal(value);
  1106. end;
  1107. {****************************************************************************
  1108. Tai_comp_64bit
  1109. ****************************************************************************}
  1110. constructor tai_comp_64bit.Create(_value : ts64comp);
  1111. begin
  1112. inherited Create;
  1113. typ:=ait_comp_64bit;
  1114. value:=_value;
  1115. end;
  1116. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1117. begin
  1118. inherited ppuload(t,ppufile);
  1119. ppufile.putdata(value,sizeof(value));
  1120. end;
  1121. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1122. begin
  1123. inherited ppuwrite(ppufile);
  1124. ppufile.getdata(value,sizeof(value));
  1125. end;
  1126. {****************************************************************************
  1127. TAI_STRING
  1128. ****************************************************************************}
  1129. constructor tai_string.Create(const _str : string);
  1130. begin
  1131. inherited Create;
  1132. typ:=ait_string;
  1133. len:=length(_str);
  1134. getmem(str,len+1);
  1135. strpcopy(str,_str);
  1136. end;
  1137. constructor tai_string.Create_pchar(_str : pchar);
  1138. begin
  1139. inherited Create;
  1140. typ:=ait_string;
  1141. str:=_str;
  1142. len:=strlen(_str);
  1143. end;
  1144. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  1145. begin
  1146. inherited Create;
  1147. typ:=ait_string;
  1148. str:=_str;
  1149. len:=length;
  1150. end;
  1151. destructor tai_string.destroy;
  1152. begin
  1153. { you can have #0 inside the strings so }
  1154. if str<>nil then
  1155. freemem(str,len+1);
  1156. inherited Destroy;
  1157. end;
  1158. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1159. begin
  1160. inherited ppuload(t,ppufile);
  1161. len:=ppufile.getlongint;
  1162. getmem(str,len+1);
  1163. ppufile.getdata(str^,len);
  1164. str[len]:=#0;
  1165. end;
  1166. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1167. begin
  1168. inherited ppuwrite(ppufile);
  1169. ppufile.putlongint(len);
  1170. ppufile.putdata(str^,len);
  1171. end;
  1172. function tai_string.getcopy : tlinkedlistitem;
  1173. var
  1174. p : tlinkedlistitem;
  1175. begin
  1176. p:=inherited getcopy;
  1177. getmem(tai_string(p).str,len+1);
  1178. move(str^,tai_string(p).str^,len+1);
  1179. getcopy:=p;
  1180. end;
  1181. {****************************************************************************
  1182. TAI_LABEL
  1183. ****************************************************************************}
  1184. constructor tai_label.create(_l : tasmlabel);
  1185. begin
  1186. inherited Create;
  1187. typ:=ait_label;
  1188. l:=_l;
  1189. l.is_set:=true;
  1190. is_global:=(l.defbind=AB_GLOBAL);
  1191. end;
  1192. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1193. begin
  1194. inherited ppuload(t,ppufile);
  1195. l:=tasmlabel(ppufile.getasmsymbol);
  1196. is_global:=boolean(ppufile.getbyte);
  1197. end;
  1198. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1199. begin
  1200. inherited ppuwrite(ppufile);
  1201. ppufile.putasmsymbol(l);
  1202. ppufile.putbyte(byte(is_global));
  1203. end;
  1204. procedure tai_label.derefimpl;
  1205. begin
  1206. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1207. l.is_set:=true;
  1208. end;
  1209. {****************************************************************************
  1210. TAI_DIRECT
  1211. ****************************************************************************}
  1212. constructor tai_direct.Create(_str : pchar);
  1213. begin
  1214. inherited Create;
  1215. typ:=ait_direct;
  1216. str:=_str;
  1217. end;
  1218. destructor tai_direct.destroy;
  1219. begin
  1220. strdispose(str);
  1221. inherited Destroy;
  1222. end;
  1223. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1224. var
  1225. len : longint;
  1226. begin
  1227. inherited ppuload(t,ppufile);
  1228. len:=ppufile.getlongint;
  1229. getmem(str,len+1);
  1230. ppufile.getdata(str^,len);
  1231. str[len]:=#0;
  1232. end;
  1233. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1234. var
  1235. len : longint;
  1236. begin
  1237. inherited ppuwrite(ppufile);
  1238. len:=strlen(str);
  1239. ppufile.putlongint(len);
  1240. ppufile.putdata(str^,len);
  1241. end;
  1242. function tai_direct.getcopy : tlinkedlistitem;
  1243. var
  1244. p : tlinkedlistitem;
  1245. begin
  1246. p:=inherited getcopy;
  1247. getmem(tai_direct(p).str,strlen(str)+1);
  1248. move(str^,tai_direct(p).str^,strlen(str)+1);
  1249. getcopy:=p;
  1250. end;
  1251. {****************************************************************************
  1252. tai_comment comment to be inserted in the assembler file
  1253. ****************************************************************************}
  1254. constructor tai_comment.Create(_str : pchar);
  1255. begin
  1256. inherited Create;
  1257. typ:=ait_comment;
  1258. str:=_str;
  1259. end;
  1260. destructor tai_comment.destroy;
  1261. begin
  1262. strdispose(str);
  1263. inherited Destroy;
  1264. end;
  1265. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1266. var
  1267. len : longint;
  1268. begin
  1269. inherited ppuload(t,ppufile);
  1270. len:=ppufile.getlongint;
  1271. getmem(str,len+1);
  1272. ppufile.getdata(str^,len);
  1273. str[len]:=#0;
  1274. end;
  1275. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1276. var
  1277. len : longint;
  1278. begin
  1279. inherited ppuwrite(ppufile);
  1280. len:=strlen(str);
  1281. ppufile.putlongint(len);
  1282. ppufile.putdata(str^,len);
  1283. end;
  1284. function tai_comment.getcopy : tlinkedlistitem;
  1285. var
  1286. p : tlinkedlistitem;
  1287. begin
  1288. p:=inherited getcopy;
  1289. getmem(tai_comment(p).str,strlen(str)+1);
  1290. move(str^,tai_comment(p).str^,strlen(str)+1);
  1291. getcopy:=p;
  1292. end;
  1293. {****************************************************************************
  1294. TAI_CUTOBJECT
  1295. ****************************************************************************}
  1296. constructor tai_cutobject.Create;
  1297. begin
  1298. inherited Create;
  1299. typ:=ait_cutobject;
  1300. place:=cut_normal;
  1301. end;
  1302. constructor tai_cutobject.Create_begin;
  1303. begin
  1304. inherited Create;
  1305. typ:=ait_cutobject;
  1306. place:=cut_begin;
  1307. end;
  1308. constructor tai_cutobject.Create_end;
  1309. begin
  1310. inherited Create;
  1311. typ:=ait_cutobject;
  1312. place:=cut_end;
  1313. end;
  1314. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1315. begin
  1316. inherited ppuload(t,ppufile);
  1317. place:=TCutPlace(ppufile.getbyte);
  1318. end;
  1319. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1320. begin
  1321. inherited ppuwrite(ppufile);
  1322. ppufile.putbyte(byte(place));
  1323. end;
  1324. {****************************************************************************
  1325. Tai_Marker
  1326. ****************************************************************************}
  1327. constructor Tai_Marker.Create(_Kind: TMarker);
  1328. begin
  1329. Inherited Create;
  1330. typ := ait_marker;
  1331. Kind := _Kind;
  1332. end;
  1333. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1334. begin
  1335. inherited ppuload(t,ppufile);
  1336. kind:=TMarker(ppufile.getbyte);
  1337. end;
  1338. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1339. begin
  1340. inherited ppuwrite(ppufile);
  1341. ppufile.putbyte(byte(kind));
  1342. end;
  1343. {*****************************************************************************
  1344. tai_tempalloc
  1345. *****************************************************************************}
  1346. constructor tai_tempalloc.alloc(pos,size:longint);
  1347. begin
  1348. inherited Create;
  1349. typ:=ait_tempalloc;
  1350. allocation:=true;
  1351. temppos:=pos;
  1352. tempsize:=size;
  1353. {$ifdef EXTDEBUG}
  1354. problem:=nil;
  1355. {$endif EXTDEBUG}
  1356. end;
  1357. destructor tai_tempalloc.destroy;
  1358. begin
  1359. {$ifdef EXTDEBUG}
  1360. stringdispose(problem);
  1361. {$endif EXTDEBUG}
  1362. inherited destroy;
  1363. end;
  1364. constructor tai_tempalloc.dealloc(pos,size:longint);
  1365. begin
  1366. inherited Create;
  1367. typ:=ait_tempalloc;
  1368. allocation:=false;
  1369. temppos:=pos;
  1370. tempsize:=size;
  1371. {$ifdef EXTDEBUG}
  1372. problem:=nil;
  1373. {$endif EXTDEBUG}
  1374. end;
  1375. {$ifdef EXTDEBUG}
  1376. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1377. begin
  1378. inherited Create;
  1379. typ:=ait_tempalloc;
  1380. allocation:=false;
  1381. temppos:=pos;
  1382. tempsize:=size;
  1383. problem:=stringdup(st);
  1384. end;
  1385. {$endif EXTDEBUG}
  1386. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1387. begin
  1388. inherited ppuload(t,ppufile);
  1389. temppos:=ppufile.getlongint;
  1390. tempsize:=ppufile.getlongint;
  1391. allocation:=boolean(ppufile.getbyte);
  1392. {$ifdef EXTDEBUG}
  1393. problem:=nil;
  1394. {$endif EXTDEBUG}
  1395. end;
  1396. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1397. begin
  1398. inherited ppuwrite(ppufile);
  1399. ppufile.putlongint(temppos);
  1400. ppufile.putlongint(tempsize);
  1401. ppufile.putbyte(byte(allocation));
  1402. end;
  1403. {*****************************************************************************
  1404. tai_regalloc
  1405. *****************************************************************************}
  1406. constructor tai_regalloc.alloc(r : tregister);
  1407. begin
  1408. inherited create;
  1409. typ:=ait_regalloc;
  1410. ratype:=ra_alloc;
  1411. reg:=r;
  1412. end;
  1413. constructor tai_regalloc.dealloc(r : tregister);
  1414. begin
  1415. inherited create;
  1416. typ:=ait_regalloc;
  1417. ratype:=ra_dealloc;
  1418. reg:=r;
  1419. end;
  1420. constructor tai_regalloc.resize(r : tregister);
  1421. begin
  1422. inherited create;
  1423. typ:=ait_regalloc;
  1424. ratype:=ra_resize;
  1425. reg:=r;
  1426. end;
  1427. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1428. begin
  1429. inherited ppuload(t,ppufile);
  1430. ppufile.getdata(reg,sizeof(Tregister));
  1431. ratype:=tregalloctype(ppufile.getbyte);
  1432. end;
  1433. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1434. begin
  1435. inherited ppuwrite(ppufile);
  1436. ppufile.putdata(reg,sizeof(Tregister));
  1437. ppufile.putbyte(byte(ratype));
  1438. end;
  1439. {*****************************************************************************
  1440. TaiInstruction
  1441. *****************************************************************************}
  1442. constructor tai_cpu_abstract.Create(op : tasmop);
  1443. begin
  1444. inherited create;
  1445. typ:=ait_instruction;
  1446. is_jmp:=false;
  1447. opcode:=op;
  1448. ops:=0;
  1449. fillchar(condition,sizeof(condition),0);
  1450. fillchar(oper,sizeof(oper),0);
  1451. end;
  1452. destructor tai_cpu_abstract.Destroy;
  1453. var
  1454. i : integer;
  1455. begin
  1456. for i:=0 to opercnt-1 do
  1457. begin
  1458. clearop(i);
  1459. dispose(oper[i]);
  1460. end;
  1461. inherited destroy;
  1462. end;
  1463. { ---------------------------------------------------------------------
  1464. Loading of operands.
  1465. ---------------------------------------------------------------------}
  1466. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1467. begin
  1468. while (opers>opercnt) do
  1469. begin
  1470. new(oper[opercnt]);
  1471. fillchar(oper[opercnt]^,sizeof(toper),0);
  1472. inc(opercnt);
  1473. end;
  1474. end;
  1475. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1476. begin
  1477. allocate_oper(opidx+1);
  1478. with oper[opidx]^ do
  1479. begin
  1480. if typ<>top_const then
  1481. clearop(opidx);
  1482. val:=l;
  1483. typ:=top_const;
  1484. end;
  1485. end;
  1486. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1487. var
  1488. r : treference;
  1489. begin
  1490. reference_reset_symbol(r,s,sofs);
  1491. r.refaddr:=addr_full;
  1492. loadref(opidx,r);
  1493. end;
  1494. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset:boolean);
  1495. begin
  1496. if not assigned(s) then
  1497. internalerror(200204251);
  1498. allocate_oper(opidx+1);
  1499. with oper[opidx]^ do
  1500. begin
  1501. if typ<>top_local then
  1502. begin
  1503. clearop(opidx);
  1504. new(localoper);
  1505. end;
  1506. with oper[opidx]^.localoper^ do
  1507. begin
  1508. localsym:=s;
  1509. localsymofs:=sofs;
  1510. localindexreg:=indexreg;
  1511. localscale:=scale;
  1512. localgetoffset:=getoffset;
  1513. end;
  1514. typ:=top_local;
  1515. end;
  1516. end;
  1517. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1518. begin
  1519. allocate_oper(opidx+1);
  1520. with oper[opidx]^ do
  1521. begin
  1522. if typ<>top_ref then
  1523. begin
  1524. clearop(opidx);
  1525. new(ref);
  1526. end;
  1527. ref^:=r;
  1528. {$ifdef x86}
  1529. { We allow this exception for x86, since overloading this would be
  1530. too much of a a speed penalty}
  1531. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1532. segprefix:=ref^.segment;
  1533. {$endif}
  1534. typ:=top_ref;
  1535. if assigned(add_reg_instruction_hook) then
  1536. begin
  1537. add_reg_instruction_hook(self,ref^.base);
  1538. add_reg_instruction_hook(self,ref^.index);
  1539. end;
  1540. { mark symbol as used }
  1541. if assigned(ref^.symbol) then
  1542. ref^.symbol.increfs;
  1543. end;
  1544. end;
  1545. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1546. begin
  1547. allocate_oper(opidx+1);
  1548. with oper[opidx]^ do
  1549. begin
  1550. if typ<>top_reg then
  1551. clearop(opidx);
  1552. reg:=r;
  1553. typ:=top_reg;
  1554. end;
  1555. if assigned(add_reg_instruction_hook) then
  1556. add_reg_instruction_hook(self,r);
  1557. {$ifdef ARM}
  1558. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1559. Due to speed considerations we don't use a virtual overridden method here.
  1560. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1561. problems with iregs getting r15.
  1562. }
  1563. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1564. {$endif ARM}
  1565. end;
  1566. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1567. begin
  1568. allocate_oper(opidx+1);
  1569. clearop(opidx);
  1570. oper[opidx]^:=o;
  1571. { copy also the reference }
  1572. with oper[opidx]^ do
  1573. begin
  1574. case typ of
  1575. top_reg:
  1576. begin
  1577. if assigned(add_reg_instruction_hook) then
  1578. add_reg_instruction_hook(self,reg);
  1579. end;
  1580. top_ref:
  1581. begin
  1582. new(ref);
  1583. ref^:=o.ref^;
  1584. if assigned(add_reg_instruction_hook) then
  1585. begin
  1586. add_reg_instruction_hook(self,ref^.base);
  1587. add_reg_instruction_hook(self,ref^.index);
  1588. end;
  1589. end;
  1590. {$ifdef ARM}
  1591. top_shifterop:
  1592. begin
  1593. new(shifterop);
  1594. shifterop^:=o.shifterop^;
  1595. if assigned(add_reg_instruction_hook) then
  1596. add_reg_instruction_hook(self,shifterop^.rs);
  1597. end;
  1598. {$endif ARM}
  1599. end;
  1600. end;
  1601. end;
  1602. procedure tai_cpu_abstract.clearop(opidx:longint);
  1603. begin
  1604. with oper[opidx]^ do
  1605. begin
  1606. case typ of
  1607. top_ref:
  1608. dispose(ref);
  1609. top_local:
  1610. dispose(localoper);
  1611. {$ifdef ARM}
  1612. top_shifterop:
  1613. dispose(shifterop);
  1614. top_regset:
  1615. dispose(regset);
  1616. {$endif ARM}
  1617. end;
  1618. typ:=top_none;
  1619. end;
  1620. end;
  1621. { ---------------------------------------------------------------------
  1622. Miscellaneous methods.
  1623. ---------------------------------------------------------------------}
  1624. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1625. begin
  1626. condition:=c;
  1627. end;
  1628. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1629. var
  1630. i : longint;
  1631. p : tai_cpu_abstract;
  1632. begin
  1633. p:=tai_cpu_abstract(inherited getcopy);
  1634. { make a copy of the references }
  1635. p.opercnt:=0;
  1636. p.allocate_oper(ops);
  1637. for i:=0 to ops-1 do
  1638. begin
  1639. p.oper[i]^:=oper[i]^;
  1640. case oper[i]^.typ of
  1641. top_local :
  1642. begin
  1643. new(p.oper[i]^.localoper);
  1644. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1645. end;
  1646. top_ref :
  1647. begin
  1648. new(p.oper[i]^.ref);
  1649. p.oper[i]^.ref^:=oper[i]^.ref^;
  1650. end;
  1651. {$ifdef ARM}
  1652. top_shifterop:
  1653. begin
  1654. new(p.oper[i]^.shifterop);
  1655. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1656. end;
  1657. {$endif ARM}
  1658. end;
  1659. end;
  1660. getcopy:=p;
  1661. end;
  1662. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1663. begin
  1664. { When the generic RA is used this needs to be overriden, we don't use
  1665. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1666. when tai_cpu is created (PFV) }
  1667. internalerror(200404091);
  1668. end;
  1669. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1670. begin
  1671. internalerror(200404091);
  1672. end;
  1673. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1674. var
  1675. i : integer;
  1676. begin
  1677. inherited ppuload(t,ppufile);
  1678. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1679. ppufile.getdata(condition,sizeof(tasmcond));
  1680. allocate_oper(ppufile.getbyte);
  1681. for i:=0 to ops-1 do
  1682. ppuloadoper(ppufile,oper[i]^);
  1683. opcode:=tasmop(ppufile.getword);
  1684. {$ifdef x86}
  1685. ppufile.getdata(segprefix,sizeof(Tregister));
  1686. {$endif x86}
  1687. is_jmp:=boolean(ppufile.getbyte);
  1688. end;
  1689. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1690. var
  1691. i : integer;
  1692. begin
  1693. inherited ppuwrite(ppufile);
  1694. ppufile.putdata(condition,sizeof(tasmcond));
  1695. ppufile.putbyte(ops);
  1696. for i:=0 to ops-1 do
  1697. ppuwriteoper(ppufile,oper[i]^);
  1698. ppufile.putword(word(opcode));
  1699. {$ifdef x86}
  1700. ppufile.putdata(segprefix,sizeof(Tregister));
  1701. {$endif x86}
  1702. ppufile.putbyte(byte(is_jmp));
  1703. end;
  1704. procedure tai_cpu_abstract.buildderefimpl;
  1705. var
  1706. i : integer;
  1707. begin
  1708. for i:=0 to ops-1 do
  1709. ppubuildderefimploper(oper[i]^);
  1710. end;
  1711. procedure tai_cpu_abstract.derefimpl;
  1712. var
  1713. i : integer;
  1714. begin
  1715. for i:=0 to ops-1 do
  1716. ppuderefoper(oper[i]^);
  1717. end;
  1718. {****************************************************************************
  1719. tai_align_abstract
  1720. ****************************************************************************}
  1721. constructor tai_align_abstract.Create(b: byte);
  1722. begin
  1723. inherited Create;
  1724. typ:=ait_align;
  1725. if b in [1,2,4,8,16,32] then
  1726. aligntype := b
  1727. else
  1728. aligntype := 1;
  1729. fillsize:=0;
  1730. fillop:=0;
  1731. use_op:=false;
  1732. end;
  1733. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1734. begin
  1735. inherited Create;
  1736. typ:=ait_align;
  1737. if b in [1,2,4,8,16,32] then
  1738. aligntype := b
  1739. else
  1740. aligntype := 1;
  1741. fillsize:=0;
  1742. fillop:=_op;
  1743. use_op:=true;
  1744. end;
  1745. constructor tai_align_abstract.Create_zeros(b: byte);
  1746. begin
  1747. inherited Create;
  1748. typ:=ait_align;
  1749. if b in [1,2,4,8,16,32] then
  1750. aligntype := b
  1751. else
  1752. aligntype := 1;
  1753. use_op:=true;
  1754. fillsize:=0;
  1755. fillop:=0;
  1756. end;
  1757. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1758. begin
  1759. if fillsize>sizeof(buf) then
  1760. internalerror(200404293);
  1761. fillchar(buf,high(buf),fillop);
  1762. calculatefillbuf:=pchar(@buf);
  1763. end;
  1764. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1765. begin
  1766. inherited ppuload(t,ppufile);
  1767. aligntype:=ppufile.getbyte;
  1768. fillsize:=0;
  1769. fillop:=ppufile.getbyte;
  1770. use_op:=boolean(ppufile.getbyte);
  1771. end;
  1772. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1773. begin
  1774. inherited ppuwrite(ppufile);
  1775. ppufile.putbyte(aligntype);
  1776. ppufile.putbyte(fillop);
  1777. ppufile.putbyte(byte(use_op));
  1778. end;
  1779. {*****************************************************************************
  1780. TAAsmOutput
  1781. *****************************************************************************}
  1782. constructor taasmoutput.create;
  1783. begin
  1784. inherited create;
  1785. { make sure the optimizer won't remove the first tai of this list}
  1786. insert(tai_marker.create(marker_blockstart));
  1787. end;
  1788. function taasmoutput.empty : boolean;
  1789. begin
  1790. { there is always a marker_blockstart available,
  1791. see taasmoutput.create }
  1792. result:=(count<=1);
  1793. end;
  1794. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1795. var
  1796. hp : tlinkedlistitem;
  1797. begin
  1798. getlasttaifilepos := nil;
  1799. if assigned(last) then
  1800. begin
  1801. { find the last file information record }
  1802. if not (tai(last).typ in SkipLineInfo) then
  1803. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1804. else
  1805. { go through list backwards to find the first entry
  1806. with line information
  1807. }
  1808. begin
  1809. hp:=tai(last);
  1810. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1811. hp:=hp.Previous;
  1812. { found entry }
  1813. if assigned(hp) then
  1814. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1815. end;
  1816. end;
  1817. end;
  1818. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1819. begin
  1820. { This is not possible because it is not sure that the
  1821. tai at Loc has taifileinfo as parent }
  1822. {if assigned(Loc) then
  1823. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1824. inherited InsertAfter(Item,Loc);
  1825. end;
  1826. begin
  1827. cai_cpu:=tai_cpu_abstract;
  1828. cai_align:=tai_align_abstract;
  1829. end.
  1830. {
  1831. $Log$
  1832. Revision 1.88 2004-08-15 13:30:18 florian
  1833. * fixed alignment of variant records
  1834. * more alignment problems fixed
  1835. Revision 1.87 2004/08/14 14:50:42 florian
  1836. * fixed several sparc alignment issues
  1837. + Jonas' inline node patch; non functional yet
  1838. Revision 1.86 2004/06/20 08:55:28 florian
  1839. * logs truncated
  1840. Revision 1.85 2004/06/16 20:07:06 florian
  1841. * dwarf branch merged
  1842. Revision 1.84 2004/05/23 14:31:05 peter
  1843. * ignore marker block when checking for empty list
  1844. Revision 1.83 2004/05/22 23:34:27 peter
  1845. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  1846. Revision 1.82 2004/04/12 18:59:32 florian
  1847. * small x86_64 fixes
  1848. Revision 1.81.2.14 2004/06/13 10:51:16 florian
  1849. * fixed several register allocator problems (sparc/arm)
  1850. }