aasmtai.pas 67 KB

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