aasmtai.pas 68 KB

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