aasmtai.pas 67 KB

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