aasmtai.pas 63 KB

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