aasmtai.pas 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  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. { Type of asmlists. The order is important for the layout of the
  519. information in the .o file. The stabs for the types must be defined
  520. before they can be referenced and therefor they need to be written
  521. first (PFV) }
  522. Tasmlist=(al_typestabs,
  523. al_code,
  524. al_bss,
  525. al_data,
  526. al_rodata,
  527. al_typedconsts,
  528. al_rotypedconsts,
  529. al_threadvars,
  530. al_withdebug,
  531. al_imports,
  532. al_exports,
  533. al_resources,
  534. al_rtti,
  535. al_dwarf,
  536. al_picdata,
  537. al_resourcestrings);
  538. const
  539. TasmlistStr : array[tasmlist] of string[24] =(
  540. 'al_typestabs',
  541. 'al_code',
  542. 'al_bss',
  543. 'al_data',
  544. 'al_rodata',
  545. 'al_typedconsts',
  546. 'al_rotypedconsts',
  547. 'al_threadvars',
  548. 'al_withdebug',
  549. 'al_imports',
  550. 'al_exports',
  551. 'al_resources',
  552. 'al_rtti',
  553. 'al_dwarf',
  554. 'al_picdata',
  555. 'al_resourcestrings');
  556. var
  557. { array with all class types for tais }
  558. aiclass : taiclassarray;
  559. { Current expression list }
  560. exprasmlist : taasmoutput;
  561. { labels for BREAK and CONTINUE }
  562. aktbreaklabel,aktcontinuelabel : tasmlabel;
  563. { label when the result is true or false }
  564. truelabel,falselabel : tasmlabel;
  565. { hook to notify uses of registers }
  566. add_reg_instruction_hook : tadd_reg_instruction_proc;
  567. asmlist:array[Tasmlist] of Taasmoutput;
  568. cai_align : tai_align_class;
  569. cai_cpu : tai_cpu_class;
  570. function use_smartlink_section:boolean;
  571. function maybe_smartlink_symbol:boolean;
  572. procedure maybe_new_object_file(list:taasmoutput);
  573. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  574. function ppuloadai(ppufile:tcompilerppufile):tai;
  575. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  576. implementation
  577. uses
  578. strings,
  579. verbose;
  580. const
  581. pputaimarker = 254;
  582. {****************************************************************************
  583. Helpers
  584. ****************************************************************************}
  585. function ppuloadai(ppufile:tcompilerppufile):tai;
  586. var
  587. b : byte;
  588. t : taitype;
  589. begin
  590. { marker }
  591. b:=ppufile.getbyte;
  592. if b<>pputaimarker then
  593. internalerror(200208181);
  594. { load nodetype }
  595. t:=taitype(ppufile.getbyte);
  596. if t<>ait_none then
  597. begin
  598. if t>high(taitype) then
  599. internalerror(200208182);
  600. if not assigned(aiclass[t]) then
  601. internalerror(200208183);
  602. {writeln('taiload: ',taitypestr[t]);}
  603. { generate tai of the correct class }
  604. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  605. end
  606. else
  607. ppuloadai:=nil;
  608. end;
  609. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  610. begin
  611. { marker, read by ppuloadnode }
  612. ppufile.putbyte(pputaimarker);
  613. if assigned(n) then
  614. begin
  615. { type, read by ppuloadnode }
  616. ppufile.putbyte(byte(n.typ));
  617. {writeln('taiwrite: ',taitypestr[n.typ]);}
  618. n.ppuwrite(ppufile);
  619. end
  620. else
  621. ppufile.putbyte(byte(ait_none));
  622. end;
  623. function use_smartlink_section:boolean;
  624. begin
  625. result:=(af_smartlink_sections in target_asm.flags) and
  626. (tf_smartlink_sections in target_info.flags) and
  627. not(cs_debuginfo in aktmoduleswitches);
  628. end;
  629. function maybe_smartlink_symbol:boolean;
  630. begin
  631. result:=(cs_create_smart in aktmoduleswitches) or
  632. use_smartlink_section;
  633. end;
  634. procedure maybe_new_object_file(list:taasmoutput);
  635. begin
  636. if (cs_create_smart in aktmoduleswitches) and
  637. (not use_smartlink_section) then
  638. list.concat(tai_cutobject.create);
  639. end;
  640. procedure new_section(list:taasmoutput;Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  641. begin
  642. list.concat(tai_section.create(Asectype,Aname,Aalign));
  643. list.concat(cai_align.create(Aalign));
  644. end;
  645. {****************************************************************************
  646. TAI
  647. ****************************************************************************}
  648. constructor tai.Create;
  649. begin
  650. {$ifndef NOOPT}
  651. optinfo:=nil;
  652. {$endif NOOPT}
  653. end;
  654. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  655. begin
  656. typ:=t;
  657. {$ifndef NOOPT}
  658. optinfo:=nil;
  659. {$endif}
  660. end;
  661. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  662. begin
  663. end;
  664. procedure tai.buildderefimpl;
  665. begin
  666. end;
  667. procedure tai.derefimpl;
  668. begin
  669. end;
  670. {****************************************************************************
  671. TAILINEINFO
  672. ****************************************************************************}
  673. constructor tailineinfo.create;
  674. begin
  675. inherited create;
  676. if not(inlining_procedure and
  677. (cs_gdb_valgrind in aktglobalswitches)) then
  678. fileinfo:=aktfilepos;
  679. end;
  680. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  681. begin
  682. inherited ppuload(t,ppufile);
  683. ppufile.getposinfo(fileinfo);
  684. end;
  685. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  686. begin
  687. inherited ppuwrite(ppufile);
  688. ppufile.putposinfo(fileinfo);
  689. end;
  690. {****************************************************************************
  691. TAI_SIMPLE
  692. ****************************************************************************}
  693. constructor tai_simple.create(_typ : taitype);
  694. begin
  695. inherited create;
  696. typ:=_typ;
  697. end;
  698. {****************************************************************************
  699. TAI_SECTION
  700. ****************************************************************************}
  701. constructor tai_section.Create(Asectype:TAsmSectionType;Aname:string;Aalign:byte);
  702. begin
  703. inherited Create;
  704. typ:=ait_section;
  705. sectype:=asectype;
  706. secalign:=Aalign;
  707. name:=stringdup(Aname);
  708. sec:=nil;
  709. end;
  710. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  711. begin
  712. inherited ppuload(t,ppufile);
  713. sectype:=tasmsectiontype(ppufile.getbyte);
  714. secalign:=ppufile.getbyte;
  715. name:=stringdup(ppufile.getstring);
  716. sec:=nil;
  717. end;
  718. destructor tai_section.Destroy;
  719. begin
  720. stringdispose(name);
  721. end;
  722. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  723. begin
  724. inherited ppuwrite(ppufile);
  725. ppufile.putbyte(byte(sectype));
  726. ppufile.putbyte(secalign);
  727. ppufile.putstring(name^);
  728. end;
  729. {****************************************************************************
  730. TAI_DATABLOCK
  731. ****************************************************************************}
  732. constructor tai_datablock.Create(const _name : string;_size : longint);
  733. begin
  734. inherited Create;
  735. typ:=ait_datablock;
  736. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,AT_DATA);
  737. { keep things aligned }
  738. if _size<=0 then
  739. _size:=4;
  740. size:=_size;
  741. is_global:=false;
  742. end;
  743. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  744. begin
  745. inherited Create;
  746. typ:=ait_datablock;
  747. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_DATA);
  748. { keep things aligned }
  749. if _size<=0 then
  750. _size:=4;
  751. size:=_size;
  752. is_global:=true;
  753. end;
  754. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  755. begin
  756. inherited Create;
  757. sym:=ppufile.getasmsymbol;
  758. size:=ppufile.getlongint;
  759. is_global:=boolean(ppufile.getbyte);
  760. end;
  761. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  762. begin
  763. inherited ppuwrite(ppufile);
  764. ppufile.putasmsymbol(sym);
  765. ppufile.putlongint(size);
  766. ppufile.putbyte(byte(is_global));
  767. end;
  768. procedure tai_datablock.derefimpl;
  769. begin
  770. objectlibrary.DerefAsmsymbol(sym);
  771. end;
  772. {****************************************************************************
  773. TAI_SYMBOL
  774. ****************************************************************************}
  775. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  776. begin
  777. inherited Create;
  778. typ:=ait_symbol;
  779. sym:=_sym;
  780. size:=siz;
  781. sym.defbind:=AB_LOCAL;
  782. is_global:=false;
  783. end;
  784. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  785. begin
  786. inherited Create;
  787. typ:=ait_symbol;
  788. sym:=_sym;
  789. size:=siz;
  790. sym.defbind:=AB_GLOBAL;
  791. is_global:=true;
  792. end;
  793. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  794. begin
  795. inherited Create;
  796. typ:=ait_symbol;
  797. sym:=objectlibrary.newasmsymbol(_name,AB_LOCAL,_symtyp);
  798. size:=siz;
  799. is_global:=false;
  800. end;
  801. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  802. begin
  803. inherited Create;
  804. typ:=ait_symbol;
  805. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,_symtyp);
  806. size:=siz;
  807. is_global:=true;
  808. end;
  809. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  810. begin
  811. inherited ppuload(t,ppufile);
  812. sym:=ppufile.getasmsymbol;
  813. size:=ppufile.getlongint;
  814. is_global:=boolean(ppufile.getbyte);
  815. end;
  816. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  817. begin
  818. inherited ppuwrite(ppufile);
  819. ppufile.putasmsymbol(sym);
  820. ppufile.putlongint(size);
  821. ppufile.putbyte(byte(is_global));
  822. end;
  823. procedure tai_symbol.derefimpl;
  824. begin
  825. objectlibrary.DerefAsmsymbol(sym);
  826. end;
  827. {****************************************************************************
  828. TAI_SYMBOL_END
  829. ****************************************************************************}
  830. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  831. begin
  832. inherited Create;
  833. typ:=ait_symbol_end;
  834. sym:=_sym;
  835. end;
  836. constructor tai_symbol_end.Createname(const _name : string);
  837. begin
  838. inherited Create;
  839. typ:=ait_symbol_end;
  840. sym:=objectlibrary.newasmsymbol(_name,AB_GLOBAL,AT_NONE);
  841. end;
  842. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  843. begin
  844. inherited ppuload(t,ppufile);
  845. sym:=ppufile.getasmsymbol;
  846. end;
  847. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  848. begin
  849. inherited ppuwrite(ppufile);
  850. ppufile.putasmsymbol(sym);
  851. end;
  852. procedure tai_symbol_end.derefimpl;
  853. begin
  854. objectlibrary.DerefAsmsymbol(sym);
  855. end;
  856. {****************************************************************************
  857. TAI_CONST
  858. ****************************************************************************}
  859. constructor tai_const.Create(_typ:taitype;_value : int64);
  860. begin
  861. inherited Create;
  862. typ:=_typ;
  863. value:=_value;
  864. sym:=nil;
  865. endsym:=nil;
  866. end;
  867. constructor tai_const.Create_128bit(_value : int64);
  868. begin
  869. inherited Create;
  870. typ:=ait_const_128bit;
  871. value:=_value;
  872. sym:=nil;
  873. endsym:=nil;
  874. end;
  875. constructor tai_const.Create_64bit(_value : int64);
  876. begin
  877. inherited Create;
  878. typ:=ait_const_64bit;
  879. value:=_value;
  880. sym:=nil;
  881. endsym:=nil;
  882. end;
  883. constructor tai_const.Create_32bit(_value : longint);
  884. begin
  885. inherited Create;
  886. typ:=ait_const_32bit;
  887. value:=_value;
  888. sym:=nil;
  889. endsym:=nil;
  890. end;
  891. constructor tai_const.Create_16bit(_value : word);
  892. begin
  893. inherited Create;
  894. typ:=ait_const_16bit;
  895. value:=_value;
  896. sym:=nil;
  897. endsym:=nil;
  898. end;
  899. constructor tai_const.Create_8bit(_value : byte);
  900. begin
  901. inherited Create;
  902. typ:=ait_const_8bit;
  903. value:=_value;
  904. sym:=nil;
  905. endsym:=nil;
  906. end;
  907. constructor tai_const.Create_sleb128bit(_value : int64);
  908. begin
  909. inherited Create;
  910. typ:=ait_const_sleb128bit;
  911. value:=_value;
  912. sym:=nil;
  913. endsym:=nil;
  914. end;
  915. constructor tai_const.Create_uleb128bit(_value : qword);
  916. begin
  917. inherited Create;
  918. typ:=ait_const_uleb128bit;
  919. value:=int64(_value);
  920. sym:=nil;
  921. endsym:=nil;
  922. end;
  923. constructor tai_const.Create_aint(_value : aint);
  924. begin
  925. inherited Create;
  926. typ:=ait_const_aint;
  927. value:=_value;
  928. sym:=nil;
  929. endsym:=nil;
  930. end;
  931. constructor tai_const.Create_sym(_sym:tasmsymbol);
  932. begin
  933. inherited Create;
  934. typ:=ait_const_ptr;
  935. { sym is allowed to be nil, this is used to write nil pointers }
  936. sym:=_sym;
  937. endsym:=nil;
  938. value:=0;
  939. { update sym info }
  940. if assigned(sym) then
  941. sym.increfs;
  942. end;
  943. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  944. begin
  945. inherited Create;
  946. typ:=ait_const_ptr;
  947. if not assigned(_sym) then
  948. internalerror(200404121);
  949. sym:=_sym;
  950. endsym:=nil;
  951. value:=ofs;
  952. { update sym info }
  953. sym.increfs;
  954. end;
  955. constructor tai_const.Create_rel_sym(_typ:taitype;_sym,_endsym:tasmsymbol);
  956. begin
  957. inherited Create;
  958. typ:=_typ;
  959. sym:=_sym;
  960. endsym:=_endsym;
  961. value:=0;
  962. { update sym info }
  963. sym.increfs;
  964. endsym.increfs;
  965. end;
  966. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  967. begin
  968. inherited Create;
  969. typ:=ait_const_rva_symbol;
  970. sym:=_sym;
  971. endsym:=nil;
  972. value:=0;
  973. { update sym info }
  974. sym.increfs;
  975. end;
  976. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  977. begin
  978. inherited Create;
  979. typ:=ait_const_indirect_symbol;
  980. sym:=_sym;
  981. endsym:=nil;
  982. value:=0;
  983. { update sym info }
  984. sym.increfs;
  985. end;
  986. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  987. begin
  988. inherited Create;
  989. typ:=ait_const_ptr;
  990. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,_symtyp);
  991. endsym:=nil;
  992. value:=ofs;
  993. { update sym info }
  994. sym.increfs;
  995. end;
  996. constructor tai_const.Createname_rva(const name:string);
  997. begin
  998. inherited Create;
  999. typ:=ait_const_rva_symbol;
  1000. sym:=objectlibrary.newasmsymbol(name,AB_EXTERNAL,AT_FUNCTION);
  1001. endsym:=nil;
  1002. value:=0;
  1003. { update sym info }
  1004. sym.increfs;
  1005. end;
  1006. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1007. begin
  1008. inherited ppuload(t,ppufile);
  1009. sym:=ppufile.getasmsymbol;
  1010. endsym:=ppufile.getasmsymbol;
  1011. value:=ppufile.getint64;
  1012. end;
  1013. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1014. begin
  1015. inherited ppuwrite(ppufile);
  1016. ppufile.putasmsymbol(sym);
  1017. ppufile.putasmsymbol(endsym);
  1018. ppufile.putint64(value);
  1019. end;
  1020. procedure tai_const.derefimpl;
  1021. begin
  1022. objectlibrary.DerefAsmsymbol(sym);
  1023. objectlibrary.DerefAsmsymbol(endsym);
  1024. end;
  1025. function tai_const.getcopy:tlinkedlistitem;
  1026. begin
  1027. getcopy:=inherited getcopy;
  1028. { we need to increase the reference number }
  1029. sym.increfs;
  1030. if assigned(endsym) then
  1031. endsym.increfs;
  1032. end;
  1033. function tai_const.size:longint;
  1034. begin
  1035. case typ of
  1036. ait_const_8bit :
  1037. result:=1;
  1038. ait_const_16bit :
  1039. result:=2;
  1040. ait_const_32bit :
  1041. result:=4;
  1042. ait_const_64bit :
  1043. result:=8;
  1044. ait_const_indirect_symbol,
  1045. ait_const_rva_symbol :
  1046. result:=sizeof(aint);
  1047. end;
  1048. end;
  1049. {****************************************************************************
  1050. TAI_real_32bit
  1051. ****************************************************************************}
  1052. constructor tai_real_32bit.Create(_value : ts32real);
  1053. begin
  1054. inherited Create;
  1055. typ:=ait_real_32bit;
  1056. value:=_value;
  1057. end;
  1058. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1059. begin
  1060. inherited ppuload(t,ppufile);
  1061. value:=ppufile.getreal;
  1062. end;
  1063. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1064. begin
  1065. inherited ppuwrite(ppufile);
  1066. ppufile.putreal(value);
  1067. end;
  1068. {****************************************************************************
  1069. TAI_real_64bit
  1070. ****************************************************************************}
  1071. constructor tai_real_64bit.Create(_value : ts64real);
  1072. begin
  1073. inherited Create;
  1074. typ:=ait_real_64bit;
  1075. value:=_value;
  1076. end;
  1077. {$ifdef ARM}
  1078. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1079. begin
  1080. inherited Create;
  1081. typ:=ait_real_64bit;
  1082. value:=_value;
  1083. formatoptions:=fo_hiloswapped;
  1084. end;
  1085. {$endif ARM}
  1086. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1087. begin
  1088. inherited ppuload(t,ppufile);
  1089. value:=ppufile.getreal;
  1090. {$ifdef ARM}
  1091. formatoptions:=tformatoptions(ppufile.getbyte);
  1092. {$endif ARM}
  1093. end;
  1094. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1095. begin
  1096. inherited ppuwrite(ppufile);
  1097. ppufile.putreal(value);
  1098. {$ifdef ARM}
  1099. ppufile.putbyte(byte(formatoptions));
  1100. {$endif ARM}
  1101. end;
  1102. {****************************************************************************
  1103. TAI_real_80bit
  1104. ****************************************************************************}
  1105. constructor tai_real_80bit.Create(_value : ts80real);
  1106. begin
  1107. inherited Create;
  1108. typ:=ait_real_80bit;
  1109. value:=_value;
  1110. end;
  1111. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1112. begin
  1113. inherited ppuload(t,ppufile);
  1114. value:=ppufile.getreal;
  1115. end;
  1116. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1117. begin
  1118. inherited ppuwrite(ppufile);
  1119. ppufile.putreal(value);
  1120. end;
  1121. {****************************************************************************
  1122. TAI_real_80bit
  1123. ****************************************************************************}
  1124. constructor tai_real_128bit.Create(_value : ts128real);
  1125. begin
  1126. inherited Create;
  1127. typ:=ait_real_128bit;
  1128. value:=_value;
  1129. end;
  1130. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1131. begin
  1132. inherited ppuload(t,ppufile);
  1133. value:=ppufile.getreal;
  1134. end;
  1135. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1136. begin
  1137. inherited ppuwrite(ppufile);
  1138. ppufile.putreal(value);
  1139. end;
  1140. {****************************************************************************
  1141. Tai_comp_64bit
  1142. ****************************************************************************}
  1143. constructor tai_comp_64bit.Create(_value : ts64comp);
  1144. begin
  1145. inherited Create;
  1146. typ:=ait_comp_64bit;
  1147. value:=_value;
  1148. end;
  1149. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1150. begin
  1151. inherited ppuload(t,ppufile);
  1152. ppufile.putdata(value,sizeof(value));
  1153. end;
  1154. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1155. begin
  1156. inherited ppuwrite(ppufile);
  1157. ppufile.getdata(value,sizeof(value));
  1158. end;
  1159. {****************************************************************************
  1160. TAI_STRING
  1161. ****************************************************************************}
  1162. constructor tai_string.Create(const _str : string);
  1163. begin
  1164. inherited Create;
  1165. typ:=ait_string;
  1166. len:=length(_str);
  1167. getmem(str,len+1);
  1168. strpcopy(str,_str);
  1169. end;
  1170. constructor tai_string.Create_pchar(_str : pchar);
  1171. begin
  1172. inherited Create;
  1173. typ:=ait_string;
  1174. str:=_str;
  1175. len:=strlen(_str);
  1176. end;
  1177. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  1178. begin
  1179. inherited Create;
  1180. typ:=ait_string;
  1181. str:=_str;
  1182. len:=length;
  1183. end;
  1184. destructor tai_string.destroy;
  1185. begin
  1186. { you can have #0 inside the strings so }
  1187. if str<>nil then
  1188. freemem(str,len+1);
  1189. inherited Destroy;
  1190. end;
  1191. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1192. begin
  1193. inherited ppuload(t,ppufile);
  1194. len:=ppufile.getlongint;
  1195. getmem(str,len+1);
  1196. ppufile.getdata(str^,len);
  1197. str[len]:=#0;
  1198. end;
  1199. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1200. begin
  1201. inherited ppuwrite(ppufile);
  1202. ppufile.putlongint(len);
  1203. ppufile.putdata(str^,len);
  1204. end;
  1205. function tai_string.getcopy : tlinkedlistitem;
  1206. var
  1207. p : tlinkedlistitem;
  1208. begin
  1209. p:=inherited getcopy;
  1210. getmem(tai_string(p).str,len+1);
  1211. move(str^,tai_string(p).str^,len+1);
  1212. getcopy:=p;
  1213. end;
  1214. {****************************************************************************
  1215. TAI_LABEL
  1216. ****************************************************************************}
  1217. constructor tai_label.create(_l : tasmlabel);
  1218. begin
  1219. inherited Create;
  1220. typ:=ait_label;
  1221. l:=_l;
  1222. l.is_set:=true;
  1223. is_global:=(l.defbind=AB_GLOBAL);
  1224. end;
  1225. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1226. begin
  1227. inherited ppuload(t,ppufile);
  1228. l:=tasmlabel(ppufile.getasmsymbol);
  1229. is_global:=boolean(ppufile.getbyte);
  1230. end;
  1231. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1232. begin
  1233. inherited ppuwrite(ppufile);
  1234. ppufile.putasmsymbol(l);
  1235. ppufile.putbyte(byte(is_global));
  1236. end;
  1237. procedure tai_label.derefimpl;
  1238. begin
  1239. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  1240. l.is_set:=true;
  1241. end;
  1242. {****************************************************************************
  1243. TAI_DIRECT
  1244. ****************************************************************************}
  1245. constructor tai_direct.Create(_str : pchar);
  1246. begin
  1247. inherited Create;
  1248. typ:=ait_direct;
  1249. str:=_str;
  1250. end;
  1251. destructor tai_direct.destroy;
  1252. begin
  1253. strdispose(str);
  1254. inherited Destroy;
  1255. end;
  1256. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  1257. var
  1258. len : longint;
  1259. begin
  1260. inherited ppuload(t,ppufile);
  1261. len:=ppufile.getlongint;
  1262. getmem(str,len+1);
  1263. ppufile.getdata(str^,len);
  1264. str[len]:=#0;
  1265. end;
  1266. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  1267. var
  1268. len : longint;
  1269. begin
  1270. inherited ppuwrite(ppufile);
  1271. len:=strlen(str);
  1272. ppufile.putlongint(len);
  1273. ppufile.putdata(str^,len);
  1274. end;
  1275. function tai_direct.getcopy : tlinkedlistitem;
  1276. var
  1277. p : tlinkedlistitem;
  1278. begin
  1279. p:=inherited getcopy;
  1280. getmem(tai_direct(p).str,strlen(str)+1);
  1281. move(str^,tai_direct(p).str^,strlen(str)+1);
  1282. getcopy:=p;
  1283. end;
  1284. {****************************************************************************
  1285. tai_comment comment to be inserted in the assembler file
  1286. ****************************************************************************}
  1287. constructor tai_comment.Create(_str : pchar);
  1288. begin
  1289. inherited Create;
  1290. typ:=ait_comment;
  1291. str:=_str;
  1292. end;
  1293. destructor tai_comment.destroy;
  1294. begin
  1295. strdispose(str);
  1296. inherited Destroy;
  1297. end;
  1298. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1299. var
  1300. len : longint;
  1301. begin
  1302. inherited ppuload(t,ppufile);
  1303. len:=ppufile.getlongint;
  1304. getmem(str,len+1);
  1305. ppufile.getdata(str^,len);
  1306. str[len]:=#0;
  1307. end;
  1308. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1309. var
  1310. len : longint;
  1311. begin
  1312. inherited ppuwrite(ppufile);
  1313. len:=strlen(str);
  1314. ppufile.putlongint(len);
  1315. ppufile.putdata(str^,len);
  1316. end;
  1317. function tai_comment.getcopy : tlinkedlistitem;
  1318. var
  1319. p : tlinkedlistitem;
  1320. begin
  1321. p:=inherited getcopy;
  1322. getmem(tai_comment(p).str,strlen(str)+1);
  1323. move(str^,tai_comment(p).str^,strlen(str)+1);
  1324. getcopy:=p;
  1325. end;
  1326. {****************************************************************************
  1327. TAI_CUTOBJECT
  1328. ****************************************************************************}
  1329. constructor tai_cutobject.Create;
  1330. begin
  1331. inherited Create;
  1332. typ:=ait_cutobject;
  1333. place:=cut_normal;
  1334. end;
  1335. constructor tai_cutobject.Create_begin;
  1336. begin
  1337. inherited Create;
  1338. typ:=ait_cutobject;
  1339. place:=cut_begin;
  1340. end;
  1341. constructor tai_cutobject.Create_end;
  1342. begin
  1343. inherited Create;
  1344. typ:=ait_cutobject;
  1345. place:=cut_end;
  1346. end;
  1347. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1348. begin
  1349. inherited ppuload(t,ppufile);
  1350. place:=TCutPlace(ppufile.getbyte);
  1351. end;
  1352. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1353. begin
  1354. inherited ppuwrite(ppufile);
  1355. ppufile.putbyte(byte(place));
  1356. end;
  1357. {****************************************************************************
  1358. Tai_Marker
  1359. ****************************************************************************}
  1360. constructor Tai_Marker.Create(_Kind: TMarker);
  1361. begin
  1362. Inherited Create;
  1363. typ := ait_marker;
  1364. Kind := _Kind;
  1365. end;
  1366. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1367. begin
  1368. inherited ppuload(t,ppufile);
  1369. kind:=TMarker(ppufile.getbyte);
  1370. end;
  1371. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1372. begin
  1373. inherited ppuwrite(ppufile);
  1374. ppufile.putbyte(byte(kind));
  1375. end;
  1376. {*****************************************************************************
  1377. tai_tempalloc
  1378. *****************************************************************************}
  1379. constructor tai_tempalloc.alloc(pos,size:longint);
  1380. begin
  1381. inherited Create;
  1382. typ:=ait_tempalloc;
  1383. allocation:=true;
  1384. temppos:=pos;
  1385. tempsize:=size;
  1386. {$ifdef EXTDEBUG}
  1387. problem:=nil;
  1388. {$endif EXTDEBUG}
  1389. end;
  1390. destructor tai_tempalloc.destroy;
  1391. begin
  1392. {$ifdef EXTDEBUG}
  1393. stringdispose(problem);
  1394. {$endif EXTDEBUG}
  1395. inherited destroy;
  1396. end;
  1397. constructor tai_tempalloc.dealloc(pos,size:longint);
  1398. begin
  1399. inherited Create;
  1400. typ:=ait_tempalloc;
  1401. allocation:=false;
  1402. temppos:=pos;
  1403. tempsize:=size;
  1404. {$ifdef EXTDEBUG}
  1405. problem:=nil;
  1406. {$endif EXTDEBUG}
  1407. end;
  1408. {$ifdef EXTDEBUG}
  1409. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1410. begin
  1411. inherited Create;
  1412. typ:=ait_tempalloc;
  1413. allocation:=false;
  1414. temppos:=pos;
  1415. tempsize:=size;
  1416. problem:=stringdup(st);
  1417. end;
  1418. {$endif EXTDEBUG}
  1419. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1420. begin
  1421. inherited ppuload(t,ppufile);
  1422. temppos:=ppufile.getlongint;
  1423. tempsize:=ppufile.getlongint;
  1424. allocation:=boolean(ppufile.getbyte);
  1425. {$ifdef EXTDEBUG}
  1426. problem:=nil;
  1427. {$endif EXTDEBUG}
  1428. end;
  1429. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1430. begin
  1431. inherited ppuwrite(ppufile);
  1432. ppufile.putlongint(temppos);
  1433. ppufile.putlongint(tempsize);
  1434. ppufile.putbyte(byte(allocation));
  1435. end;
  1436. {*****************************************************************************
  1437. tai_regalloc
  1438. *****************************************************************************}
  1439. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1440. begin
  1441. inherited create;
  1442. typ:=ait_regalloc;
  1443. ratype:=ra_alloc;
  1444. reg:=r;
  1445. { ainstr must be an instruction }
  1446. if assigned(ainstr) and
  1447. (ainstr.typ<>ait_instruction) then
  1448. internalerror(200411011);
  1449. instr:=ainstr;
  1450. end;
  1451. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1452. begin
  1453. inherited create;
  1454. typ:=ait_regalloc;
  1455. ratype:=ra_dealloc;
  1456. reg:=r;
  1457. { ainstr must be an instruction }
  1458. if assigned(ainstr) and
  1459. (ainstr.typ<>ait_instruction) then
  1460. internalerror(200411012);
  1461. instr:=ainstr;
  1462. end;
  1463. constructor tai_regalloc.sync(r : tregister);
  1464. begin
  1465. inherited create;
  1466. typ:=ait_regalloc;
  1467. ratype:=ra_sync;
  1468. reg:=r;
  1469. end;
  1470. constructor tai_regalloc.resize(r : tregister);
  1471. begin
  1472. inherited create;
  1473. typ:=ait_regalloc;
  1474. ratype:=ra_resize;
  1475. reg:=r;
  1476. end;
  1477. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1478. begin
  1479. inherited ppuload(t,ppufile);
  1480. ppufile.getdata(reg,sizeof(Tregister));
  1481. ratype:=tregalloctype(ppufile.getbyte);
  1482. end;
  1483. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1484. begin
  1485. inherited ppuwrite(ppufile);
  1486. ppufile.putdata(reg,sizeof(Tregister));
  1487. ppufile.putbyte(byte(ratype));
  1488. end;
  1489. {*****************************************************************************
  1490. TaiInstruction
  1491. *****************************************************************************}
  1492. constructor tai_cpu_abstract.Create(op : tasmop);
  1493. begin
  1494. inherited create;
  1495. typ:=ait_instruction;
  1496. is_jmp:=false;
  1497. opcode:=op;
  1498. ops:=0;
  1499. fillchar(condition,sizeof(condition),0);
  1500. fillchar(oper,sizeof(oper),0);
  1501. end;
  1502. destructor tai_cpu_abstract.Destroy;
  1503. var
  1504. i : integer;
  1505. begin
  1506. for i:=0 to opercnt-1 do
  1507. begin
  1508. clearop(i);
  1509. dispose(oper[i]);
  1510. end;
  1511. inherited destroy;
  1512. end;
  1513. { ---------------------------------------------------------------------
  1514. Loading of operands.
  1515. ---------------------------------------------------------------------}
  1516. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1517. begin
  1518. while (opers>opercnt) do
  1519. begin
  1520. new(oper[opercnt]);
  1521. fillchar(oper[opercnt]^,sizeof(toper),0);
  1522. inc(opercnt);
  1523. end;
  1524. end;
  1525. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1526. begin
  1527. allocate_oper(opidx+1);
  1528. with oper[opidx]^ do
  1529. begin
  1530. if typ<>top_const then
  1531. clearop(opidx);
  1532. val:=l;
  1533. typ:=top_const;
  1534. end;
  1535. end;
  1536. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1537. var
  1538. r : treference;
  1539. begin
  1540. reference_reset_symbol(r,s,sofs);
  1541. r.refaddr:=addr_full;
  1542. loadref(opidx,r);
  1543. end;
  1544. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  1545. begin
  1546. if not assigned(s) then
  1547. internalerror(200204251);
  1548. allocate_oper(opidx+1);
  1549. with oper[opidx]^ do
  1550. begin
  1551. if typ<>top_local then
  1552. begin
  1553. clearop(opidx);
  1554. new(localoper);
  1555. end;
  1556. with oper[opidx]^.localoper^ do
  1557. begin
  1558. localsym:=s;
  1559. localsymofs:=sofs;
  1560. localindexreg:=indexreg;
  1561. localscale:=scale;
  1562. localgetoffset:=getoffset;
  1563. localforceref:=forceref;
  1564. end;
  1565. typ:=top_local;
  1566. end;
  1567. end;
  1568. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1569. begin
  1570. allocate_oper(opidx+1);
  1571. with oper[opidx]^ do
  1572. begin
  1573. if typ<>top_ref then
  1574. begin
  1575. clearop(opidx);
  1576. new(ref);
  1577. end;
  1578. ref^:=r;
  1579. {$ifdef x86}
  1580. { We allow this exception for x86, since overloading this would be
  1581. too much of a a speed penalty}
  1582. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1583. segprefix:=ref^.segment;
  1584. {$endif}
  1585. {$ifdef extdebug}
  1586. if (cs_create_pic in aktmoduleswitches) and
  1587. assigned(r.symbol) and
  1588. (r.refaddr=addr_no) then
  1589. internalerror(200502052);
  1590. {$endif}
  1591. typ:=top_ref;
  1592. if assigned(add_reg_instruction_hook) then
  1593. begin
  1594. add_reg_instruction_hook(self,ref^.base);
  1595. add_reg_instruction_hook(self,ref^.index);
  1596. end;
  1597. { mark symbol as used }
  1598. if assigned(ref^.symbol) then
  1599. ref^.symbol.increfs;
  1600. end;
  1601. end;
  1602. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1603. begin
  1604. allocate_oper(opidx+1);
  1605. with oper[opidx]^ do
  1606. begin
  1607. if typ<>top_reg then
  1608. clearop(opidx);
  1609. reg:=r;
  1610. typ:=top_reg;
  1611. end;
  1612. if assigned(add_reg_instruction_hook) then
  1613. add_reg_instruction_hook(self,r);
  1614. {$ifdef ARM}
  1615. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1616. Due to speed considerations we don't use a virtual overridden method here.
  1617. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1618. problems with iregs getting r15.
  1619. }
  1620. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1621. {$endif ARM}
  1622. end;
  1623. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1624. begin
  1625. allocate_oper(opidx+1);
  1626. clearop(opidx);
  1627. oper[opidx]^:=o;
  1628. { copy also the reference }
  1629. with oper[opidx]^ do
  1630. begin
  1631. case typ of
  1632. top_reg:
  1633. begin
  1634. if assigned(add_reg_instruction_hook) then
  1635. add_reg_instruction_hook(self,reg);
  1636. end;
  1637. top_ref:
  1638. begin
  1639. new(ref);
  1640. ref^:=o.ref^;
  1641. if assigned(add_reg_instruction_hook) then
  1642. begin
  1643. add_reg_instruction_hook(self,ref^.base);
  1644. add_reg_instruction_hook(self,ref^.index);
  1645. end;
  1646. end;
  1647. {$ifdef ARM}
  1648. top_shifterop:
  1649. begin
  1650. new(shifterop);
  1651. shifterop^:=o.shifterop^;
  1652. if assigned(add_reg_instruction_hook) then
  1653. add_reg_instruction_hook(self,shifterop^.rs);
  1654. end;
  1655. {$endif ARM}
  1656. end;
  1657. end;
  1658. end;
  1659. procedure tai_cpu_abstract.clearop(opidx:longint);
  1660. begin
  1661. with oper[opidx]^ do
  1662. begin
  1663. case typ of
  1664. top_ref:
  1665. dispose(ref);
  1666. top_local:
  1667. dispose(localoper);
  1668. {$ifdef ARM}
  1669. top_shifterop:
  1670. dispose(shifterop);
  1671. top_regset:
  1672. dispose(regset);
  1673. {$endif ARM}
  1674. end;
  1675. typ:=top_none;
  1676. end;
  1677. end;
  1678. { ---------------------------------------------------------------------
  1679. Miscellaneous methods.
  1680. ---------------------------------------------------------------------}
  1681. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1682. begin
  1683. condition:=c;
  1684. end;
  1685. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1686. var
  1687. i : longint;
  1688. p : tai_cpu_abstract;
  1689. begin
  1690. p:=tai_cpu_abstract(inherited getcopy);
  1691. { make a copy of the references }
  1692. p.opercnt:=0;
  1693. p.allocate_oper(ops);
  1694. for i:=0 to ops-1 do
  1695. begin
  1696. p.oper[i]^:=oper[i]^;
  1697. case oper[i]^.typ of
  1698. top_local :
  1699. begin
  1700. new(p.oper[i]^.localoper);
  1701. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1702. end;
  1703. top_ref :
  1704. begin
  1705. new(p.oper[i]^.ref);
  1706. p.oper[i]^.ref^:=oper[i]^.ref^;
  1707. end;
  1708. {$ifdef ARM}
  1709. top_shifterop:
  1710. begin
  1711. new(p.oper[i]^.shifterop);
  1712. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1713. end;
  1714. {$endif ARM}
  1715. end;
  1716. end;
  1717. getcopy:=p;
  1718. end;
  1719. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1720. begin
  1721. { When the generic RA is used this needs to be overriden, we don't use
  1722. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1723. when tai_cpu is created (PFV) }
  1724. internalerror(200404091);
  1725. end;
  1726. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1727. begin
  1728. internalerror(200404091);
  1729. end;
  1730. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  1731. begin
  1732. result := operand_read;
  1733. end;
  1734. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1735. var
  1736. i : integer;
  1737. begin
  1738. inherited ppuload(t,ppufile);
  1739. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1740. ppufile.getdata(condition,sizeof(tasmcond));
  1741. allocate_oper(ppufile.getbyte);
  1742. for i:=0 to ops-1 do
  1743. ppuloadoper(ppufile,oper[i]^);
  1744. opcode:=tasmop(ppufile.getword);
  1745. {$ifdef x86}
  1746. ppufile.getdata(segprefix,sizeof(Tregister));
  1747. {$endif x86}
  1748. is_jmp:=boolean(ppufile.getbyte);
  1749. end;
  1750. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1751. var
  1752. i : integer;
  1753. begin
  1754. inherited ppuwrite(ppufile);
  1755. ppufile.putdata(condition,sizeof(tasmcond));
  1756. ppufile.putbyte(ops);
  1757. for i:=0 to ops-1 do
  1758. ppuwriteoper(ppufile,oper[i]^);
  1759. ppufile.putword(word(opcode));
  1760. {$ifdef x86}
  1761. ppufile.putdata(segprefix,sizeof(Tregister));
  1762. {$endif x86}
  1763. ppufile.putbyte(byte(is_jmp));
  1764. end;
  1765. procedure tai_cpu_abstract.buildderefimpl;
  1766. var
  1767. i : integer;
  1768. begin
  1769. for i:=0 to ops-1 do
  1770. ppubuildderefimploper(oper[i]^);
  1771. end;
  1772. procedure tai_cpu_abstract.derefimpl;
  1773. var
  1774. i : integer;
  1775. begin
  1776. for i:=0 to ops-1 do
  1777. ppuderefoper(oper[i]^);
  1778. end;
  1779. {****************************************************************************
  1780. tai_align_abstract
  1781. ****************************************************************************}
  1782. constructor tai_align_abstract.Create(b: byte);
  1783. begin
  1784. inherited Create;
  1785. typ:=ait_align;
  1786. if b in [1,2,4,8,16,32] then
  1787. aligntype := b
  1788. else
  1789. aligntype := 1;
  1790. fillsize:=0;
  1791. fillop:=0;
  1792. use_op:=false;
  1793. end;
  1794. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1795. begin
  1796. inherited Create;
  1797. typ:=ait_align;
  1798. if b in [1,2,4,8,16,32] then
  1799. aligntype := b
  1800. else
  1801. aligntype := 1;
  1802. fillsize:=0;
  1803. fillop:=_op;
  1804. use_op:=true;
  1805. end;
  1806. constructor tai_align_abstract.Create_zeros(b: byte);
  1807. begin
  1808. inherited Create;
  1809. typ:=ait_align;
  1810. if b in [1,2,4,8,16,32] then
  1811. aligntype := b
  1812. else
  1813. aligntype := 1;
  1814. use_op:=true;
  1815. fillsize:=0;
  1816. fillop:=0;
  1817. end;
  1818. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1819. begin
  1820. if fillsize>sizeof(buf) then
  1821. internalerror(200404293);
  1822. fillchar(buf,high(buf),fillop);
  1823. calculatefillbuf:=pchar(@buf);
  1824. end;
  1825. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1826. begin
  1827. inherited ppuload(t,ppufile);
  1828. aligntype:=ppufile.getbyte;
  1829. fillsize:=0;
  1830. fillop:=ppufile.getbyte;
  1831. use_op:=boolean(ppufile.getbyte);
  1832. end;
  1833. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1834. begin
  1835. inherited ppuwrite(ppufile);
  1836. ppufile.putbyte(aligntype);
  1837. ppufile.putbyte(fillop);
  1838. ppufile.putbyte(byte(use_op));
  1839. end;
  1840. {*****************************************************************************
  1841. TAAsmOutput
  1842. *****************************************************************************}
  1843. constructor taasmoutput.create;
  1844. begin
  1845. inherited create;
  1846. { make sure the optimizer won't remove the first tai of this list}
  1847. insert(tai_marker.create(marker_blockstart));
  1848. end;
  1849. function taasmoutput.empty : boolean;
  1850. begin
  1851. { there is always a marker_blockstart available,
  1852. see taasmoutput.create }
  1853. result:=(count<=1);
  1854. end;
  1855. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1856. var
  1857. hp : tlinkedlistitem;
  1858. begin
  1859. getlasttaifilepos := nil;
  1860. if assigned(last) then
  1861. begin
  1862. { find the last file information record }
  1863. if not (tai(last).typ in SkipLineInfo) then
  1864. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1865. else
  1866. { go through list backwards to find the first entry
  1867. with line information
  1868. }
  1869. begin
  1870. hp:=tai(last);
  1871. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1872. hp:=hp.Previous;
  1873. { found entry }
  1874. if assigned(hp) then
  1875. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1876. end;
  1877. end;
  1878. end;
  1879. procedure Taasmoutput.InsertAfter(Item,Loc : TLinkedListItem);
  1880. begin
  1881. { This is not possible because it is not sure that the
  1882. tai at Loc has taifileinfo as parent }
  1883. {if assigned(Loc) then
  1884. tailineinfo(Item).fileinfo:=tailineinfo(Loc).fileinfo;}
  1885. inherited InsertAfter(Item,Loc);
  1886. end;
  1887. begin
  1888. cai_cpu:=tai_cpu_abstract;
  1889. cai_align:=tai_align_abstract;
  1890. end.