aasmtai.pas 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188
  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 overridden 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. {$ifdef jvm}
  33. ,widestr
  34. {$endif jvm}
  35. ;
  36. type
  37. { keep the number of elements in this enumeration less or equal than 32 as long
  38. as FPC knows only 4 byte and 32 byte sets (FK) }
  39. taitype = (
  40. ait_none,
  41. ait_align,
  42. ait_section,
  43. ait_comment,
  44. ait_string,
  45. ait_instruction,
  46. ait_datablock,
  47. ait_symbol,
  48. { needed to calc the size of a symbol }
  49. ait_symbol_end,
  50. ait_directive,
  51. ait_label,
  52. ait_const,
  53. ait_real_32bit,
  54. ait_real_64bit,
  55. ait_real_80bit,
  56. ait_comp_64bit,
  57. ait_real_128bit,
  58. ait_stab,
  59. ait_force_line,
  60. ait_function_name,
  61. {$ifdef alpha}
  62. { the follow is for the DEC Alpha }
  63. ait_frame,
  64. {$endif alpha}
  65. {$ifdef ia64}
  66. ait_bundle,
  67. ait_stop,
  68. {$endif ia64}
  69. {$ifdef m68k}
  70. ait_labeled_instruction,
  71. {$endif m68k}
  72. {$ifdef arm}
  73. ait_thumb_set,
  74. {$endif arm}
  75. ait_set,
  76. ait_weak,
  77. { used to split into tiny assembler files }
  78. ait_cutobject,
  79. ait_regalloc,
  80. ait_tempalloc,
  81. { used to mark assembler blocks and inlined functions }
  82. ait_marker,
  83. { used to describe a new location of a variable }
  84. ait_varloc,
  85. {$ifdef JVM}
  86. { JVM only }
  87. ait_jvar, { debug information for a local variable }
  88. ait_jcatch, { exception catch clause }
  89. {$endif JVM}
  90. { SEH directives used in ARM,MIPS and x86_64 COFF targets }
  91. ait_seh_directive
  92. );
  93. taiconst_type = (
  94. aitconst_128bit,
  95. aitconst_64bit,
  96. aitconst_32bit,
  97. aitconst_16bit,
  98. aitconst_8bit,
  99. aitconst_sleb128bit,
  100. aitconst_uleb128bit,
  101. { win32 only }
  102. aitconst_rva_symbol,
  103. aitconst_secrel32_symbol,
  104. { darwin only }
  105. { From gcc/config/darwin.c (darwin_asm_output_dwarf_delta):
  106. ***
  107. Output a difference of two labels that will be an assembly time
  108. constant if the two labels are local. (.long lab1-lab2 will be
  109. very different if lab1 is at the boundary between two sections; it
  110. will be relocated according to the second section, not the first,
  111. so one ends up with a difference between labels in different
  112. sections, which is bad in the dwarf2 eh context for instance.)
  113. ***
  114. We cannot use this everywhere, because older versions of the
  115. darwin assembler don't support the construct used for these
  116. relsyms (nor do they support dwarf, for that matter)
  117. }
  118. aitconst_darwin_dwarf_delta64,
  119. aitconst_darwin_dwarf_delta32,
  120. { ARM Thumb-2 only }
  121. aitconst_half16bit, { used for table jumps. The actual value is the 16bit value shifted left once }
  122. { for use by dwarf debugger information }
  123. aitconst_16bit_unaligned,
  124. aitconst_32bit_unaligned,
  125. aitconst_64bit_unaligned,
  126. { i8086 far pointer; emits: 'DW symbol, SEG symbol' }
  127. aitconst_farptr,
  128. { offset of symbol's GOT slot in GOT }
  129. aitconst_got,
  130. { offset of symbol itself from GOT }
  131. aitconst_gotoff_symbol
  132. );
  133. const
  134. {$if defined(cpu64bitaddr)}
  135. aitconst_ptr = aitconst_64bit;
  136. aitconst_ptr_unaligned = aitconst_64bit_unaligned;
  137. {$elseif defined(cpu32bitaddr)}
  138. aitconst_ptr = aitconst_32bit;
  139. aitconst_ptr_unaligned = aitconst_32bit_unaligned;
  140. {$elseif defined(cpu16bitaddr)}
  141. aitconst_ptr = aitconst_16bit;
  142. aitconst_ptr_unaligned = aitconst_16bit_unaligned;
  143. {$endif}
  144. {$if defined(cpu64bitalu)}
  145. aitconst_aint = aitconst_64bit;
  146. {$elseif defined(cpu32bitalu)}
  147. aitconst_aint = aitconst_32bit;
  148. {$elseif defined(cpu16bitalu)}
  149. aitconst_aint = aitconst_16bit;
  150. {$elseif defined(cpu8bitalu)}
  151. aitconst_aint = aitconst_8bit;
  152. {$endif}
  153. taitypestr : array[taitype] of string[24] = (
  154. '<none>',
  155. 'align',
  156. 'section',
  157. 'comment',
  158. 'string',
  159. 'instruction',
  160. 'datablock',
  161. 'symbol',
  162. 'symbol_end',
  163. 'symbol_directive',
  164. 'label',
  165. 'const',
  166. 'real_32bit',
  167. 'real_64bit',
  168. 'real_80bit',
  169. 'comp_64bit',
  170. 'real_128bit',
  171. 'stab',
  172. 'force_line',
  173. 'function_name',
  174. {$ifdef alpha}
  175. { the follow is for the DEC Alpha }
  176. 'frame',
  177. {$endif alpha}
  178. {$ifdef ia64}
  179. 'bundle',
  180. 'stop',
  181. {$endif ia64}
  182. {$ifdef m68k}
  183. 'labeled_instr',
  184. {$endif m68k}
  185. {$ifdef arm}
  186. 'thumb_set',
  187. {$endif arm}
  188. 'set',
  189. 'weak',
  190. 'cut',
  191. 'regalloc',
  192. 'tempalloc',
  193. 'marker',
  194. 'varloc',
  195. {$ifdef JVM}
  196. 'jvar',
  197. 'jcatch',
  198. {$endif JVM}
  199. 'seh_directive'
  200. );
  201. type
  202. { Types of operand }
  203. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
  204. {$ifdef arm}
  205. { ARM only }
  206. ,top_regset
  207. ,top_conditioncode
  208. ,top_modeflags
  209. ,top_specialreg
  210. {$endif arm}
  211. {$if defined(arm) or defined(aarch64)}
  212. ,top_shifterop
  213. {$endif defined(arm) or defined(aarch64)}
  214. {$ifdef m68k}
  215. { m68k only }
  216. ,top_regset
  217. {$endif m68k}
  218. {$ifdef jvm}
  219. { jvm only}
  220. ,top_single
  221. ,top_double
  222. ,top_string
  223. ,top_wstring
  224. {$endif jvm}
  225. );
  226. { kinds of operations that an instruction can perform on an operand }
  227. topertype = (operand_read,operand_write,operand_readwrite);
  228. tlocaloper = record
  229. localsym : pointer;
  230. localsymderef : tderef;
  231. localsymofs : longint;
  232. localindexreg : tregister;
  233. localscale : byte;
  234. localgetoffset,
  235. localforceref : boolean
  236. end;
  237. plocaloper = ^tlocaloper;
  238. { please keep the size of this record <=12 bytes and keep it properly aligned }
  239. toper = record
  240. ot : longint;
  241. case typ : toptype of
  242. top_none : ();
  243. top_reg : (reg:tregister);
  244. top_ref : (ref:preference);
  245. top_const : (val:tcgint);
  246. top_bool : (b:boolean);
  247. { local varsym that will be inserted in pass_generate_code }
  248. top_local : (localoper:plocaloper);
  249. {$ifdef arm}
  250. top_regset : (regset:^tcpuregisterset; regtyp: tregistertype; subreg: tsubregister; usermode: boolean);
  251. top_conditioncode : (cc : TAsmCond);
  252. top_modeflags : (modeflags : tcpumodeflags);
  253. top_specialreg : (specialreg:tregister; specialflags:tspecialregflags);
  254. {$endif arm}
  255. {$if defined(arm) or defined(aarch64)}
  256. top_shifterop : (shifterop : pshifterop);
  257. {$endif defined(arm) or defined(aarch64)}
  258. {$ifdef m68k}
  259. top_regset : (dataregset,addrregset,fpuregset:^tcpuregisterset);
  260. {$endif m68k}
  261. {$ifdef jvm}
  262. top_single : (sval:single);
  263. top_double : (dval:double);
  264. top_string : (pcvallen: aint; pcval: pchar);
  265. top_wstring : (pwstrval: pcompilerwidestring);
  266. {$endif jvm}
  267. end;
  268. poper=^toper;
  269. const
  270. { ait_* types which don't result in executable code or which don't influence
  271. the way the program runs/behaves, but which may be encountered by the
  272. optimizer (= if it's sometimes added to the exprasm list). Update if you add
  273. a new ait type! }
  274. SkipInstr = [ait_comment, ait_symbol,ait_section
  275. ,ait_stab, ait_function_name, ait_force_line
  276. ,ait_regalloc, ait_tempalloc, ait_symbol_end
  277. ,ait_directive
  278. ,ait_varloc,
  279. {$ifdef JVM}
  280. ait_jvar, ait_jcatch,
  281. {$endif JVM}
  282. ait_seh_directive];
  283. { ait_* types which do not have line information (and hence which are of type
  284. tai, otherwise, they are of type tailineinfo }
  285. SkipLineInfo =[ait_label,
  286. ait_regalloc,ait_tempalloc,
  287. ait_stab,ait_function_name,
  288. ait_cutobject,ait_marker,ait_varloc,ait_align,ait_section,ait_comment,
  289. ait_const,ait_directive,
  290. {$ifdef arm}
  291. ait_thumb_set,
  292. {$endif arm}
  293. ait_set,ait_weak,
  294. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  295. ait_symbol,
  296. {$ifdef JVM}
  297. ait_jvar, ait_jcatch,
  298. {$endif JVM}
  299. ait_seh_directive
  300. ];
  301. type
  302. { cut type, required for alphanumeric ordering of the assembler filenames }
  303. TCutPlace=(cut_normal,cut_begin,cut_end);
  304. TAsmMarker = (
  305. mark_NoPropInfoStart,mark_NoPropInfoEnd,
  306. mark_AsmBlockStart,mark_AsmBlockEnd,
  307. mark_NoLineInfoStart,mark_NoLineInfoEnd,mark_BlockStart,
  308. mark_Position
  309. );
  310. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);
  311. TStabType = (stab_stabs,stab_stabn,stab_stabd,
  312. { AIX/XCOFF stab types }
  313. stab_stabx,
  314. { begin/end include file }
  315. stabx_bi,stabx_ei,
  316. { begin/end function }
  317. stabx_bf, stabx_ef,
  318. { begin/end static data block }
  319. stabx_bs, stabx_es,
  320. { line spec, function start/end label }
  321. stabx_line, stabx_function);
  322. TAsmDirective=(
  323. asd_indirect_symbol,
  324. asd_extern,asd_nasm_import, asd_toc_entry,
  325. asd_reference,asd_no_dead_strip,asd_weak_reference,asd_lazy_reference,
  326. asd_weak_definition,
  327. { for Jasmin }
  328. asd_jclass,asd_jinterface,asd_jsuper,asd_jfield,asd_jlimit,asd_jline,
  329. { .ent/.end for MIPS and Alpha }
  330. asd_ent,asd_ent_end,
  331. { .thumb_func for ARM }
  332. asd_thumb_func
  333. );
  334. TAsmSehDirective=(
  335. ash_proc,ash_endproc,
  336. ash_endprologue,ash_handler,ash_handlerdata,
  337. ash_eh,ash_32,ash_no32,
  338. ash_setframe,ash_stackalloc,ash_pushreg,
  339. ash_savereg,ash_savexmm,ash_pushframe
  340. );
  341. const
  342. regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
  343. tempallocstr : array[boolean] of string[10]=('released','allocated');
  344. stabtypestr : array[TStabType] of string[8]=(
  345. 'stabs','stabn','stabd',
  346. 'stabx',
  347. 'bi','ei',
  348. 'bf','ef',
  349. 'bs','es',
  350. 'line','function');
  351. directivestr : array[TAsmDirective] of string[23]=(
  352. 'indirect_symbol',
  353. 'extern','nasm_import', 'tc', 'reference',
  354. 'no_dead_strip','weak_reference','lazy_reference','weak_definition',
  355. { for Jasmin }
  356. 'class','interface','super','field','limit','line',
  357. { .ent/.end for MIPS and Alpha }
  358. 'ent','end',
  359. { .thumb_func for ARM }
  360. 'thumb_func'
  361. );
  362. sehdirectivestr : array[TAsmSehDirective] of string[16]=(
  363. '.seh_proc','.seh_endproc',
  364. '.seh_endprologue','.seh_handler','.seh_handlerdata',
  365. '.seh_eh','.seh_32','seh_no32',
  366. '.seh_setframe','.seh_stackalloc','.seh_pushreg',
  367. '.seh_savereg','.seh_savexmm','.seh_pushframe'
  368. );
  369. type
  370. { abstract assembler item }
  371. tai = class(TLinkedListItem)
  372. {$ifndef NOOPT}
  373. { pointer to record with optimizer info about this tai object }
  374. optinfo : pointer;
  375. {$endif NOOPT}
  376. typ : taitype;
  377. constructor Create;
  378. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  379. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  380. procedure buildderefimpl;virtual;
  381. procedure derefimpl;virtual;
  382. end;
  383. { abstract assembler item with line information }
  384. tailineinfo = class(tai)
  385. fileinfo : tfileposinfo;
  386. constructor Create;
  387. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  388. procedure ppuwrite(ppufile:tcompilerppufile);override;
  389. end;
  390. tai_simple = class(tai)
  391. constructor create(_typ : taitype);
  392. end;
  393. taiclass = class of tai;
  394. taiclassarray = array[taitype] of taiclass;
  395. { Generates an assembler string }
  396. tai_string = class(tailineinfo)
  397. str : pchar;
  398. { extra len so the string can contain an \0 }
  399. len : longint;
  400. constructor Create(const _str : string);
  401. constructor Create_pchar(_str : pchar;length : longint);
  402. destructor Destroy;override;
  403. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  404. procedure ppuwrite(ppufile:tcompilerppufile);override;
  405. function getcopy:tlinkedlistitem;override;
  406. end;
  407. { Generates a common label }
  408. tai_symbol = class(tai)
  409. sym : tasmsymbol;
  410. value : puint;
  411. size : longint;
  412. is_global,
  413. has_value : boolean;
  414. constructor Create(_sym:tasmsymbol;siz:longint);
  415. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  416. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  417. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  418. constructor Createname_global_value(const _name : string;_symtyp:Tasmsymtype;siz:longint;val:ptruint);
  419. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  420. procedure ppuwrite(ppufile:tcompilerppufile);override;
  421. procedure derefimpl;override;
  422. end;
  423. tai_symbol_end = class(tailineinfo)
  424. sym : tasmsymbol;
  425. constructor Create(_sym:tasmsymbol);
  426. constructor Createname(const _name : string);
  427. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  428. procedure ppuwrite(ppufile:tcompilerppufile);override;
  429. procedure derefimpl;override;
  430. end;
  431. tai_directive = class(tailineinfo)
  432. name : ansistring;
  433. directive : TAsmDirective;
  434. constructor Create(_directive:TAsmDirective;const _name:ansistring);
  435. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  436. procedure ppuwrite(ppufile:tcompilerppufile);override;
  437. end;
  438. { Generates an assembler label }
  439. tai_label = class(tai)
  440. labsym : tasmlabel;
  441. {$ifdef arm}
  442. { set to true when the label has been moved by insertpcrelativedata to the correct location
  443. so one label can be used multiple times }
  444. moved : boolean;
  445. { true, if a label has been already inserted, this is important for arm thumb where no negative
  446. pc relative offsets are allowed }
  447. inserted : boolean;
  448. {$endif arm}
  449. constructor Create(_labsym : tasmlabel);
  450. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  451. procedure ppuwrite(ppufile:tcompilerppufile);override;
  452. procedure derefimpl;override;
  453. end;
  454. { Generates an assembler comment }
  455. tai_comment = class(tai)
  456. str : pchar;
  457. constructor Create(_str : pchar);
  458. destructor Destroy; override;
  459. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  460. procedure ppuwrite(ppufile:tcompilerppufile);override;
  461. function getcopy:tlinkedlistitem;override;
  462. end;
  463. { Generates a section / segment directive }
  464. tai_section = class(tai)
  465. sectype : TAsmSectiontype;
  466. secorder : TasmSectionorder;
  467. secalign : byte;
  468. name : pshortstring;
  469. sec : TObjSection; { used in binary writer }
  470. destructor Destroy;override;
  471. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  472. procedure ppuwrite(ppufile:tcompilerppufile);override;
  473. {$push}{$warnings off}
  474. private
  475. { this constructor is made private on purpose }
  476. { because sections should be created via new_section() }
  477. constructor Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  478. {$pop}
  479. end;
  480. { Generates an uninitializised data block }
  481. tai_datablock = class(tailineinfo)
  482. is_global : boolean;
  483. sym : tasmsymbol;
  484. size : asizeint;
  485. constructor Create(const _name : string;_size : aint);
  486. constructor Create_global(const _name : string;_size : asizeint);
  487. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  488. procedure ppuwrite(ppufile:tcompilerppufile);override;
  489. procedure derefimpl;override;
  490. end;
  491. { Generates an integer const }
  492. { tai_const }
  493. tai_const = class(tai)
  494. sym,
  495. endsym : tasmsymbol;
  496. { if symbols and offset are provided the symofs is used,
  497. the value is calculated during assembling }
  498. symofs,
  499. value : int64;
  500. consttype : taiconst_type;
  501. { we use for the 128bit int64/qword for now because I can't imagine a
  502. case where we need 128 bit now (FK) }
  503. constructor Create(_typ:taiconst_type;_value : int64);
  504. constructor Create_128bit(_value : int64);
  505. constructor Create_64bit(_value : int64);
  506. constructor Create_32bit(_value : longint);
  507. constructor Create_16bit(_value : word);
  508. constructor Create_64bit_unaligned(_value : int64);
  509. constructor Create_32bit_unaligned(_value : longint);
  510. constructor Create_16bit_unaligned(_value : word);
  511. constructor Create_8bit(_value : byte);
  512. constructor Create_char(size: integer; _value: dword);
  513. constructor Create_sleb128bit(_value : int64);
  514. constructor Create_uleb128bit(_value : qword);
  515. constructor Create_aint(_value : aint);
  516. constructor Create_pint(_value : pint);
  517. constructor Create_pint_unaligned(_value : pint);
  518. constructor Create_sym(_sym:tasmsymbol);
  519. {$ifdef i8086}
  520. constructor Create_sym_near(_sym:tasmsymbol);
  521. constructor Create_sym_far(_sym:tasmsymbol);
  522. {$endif i8086}
  523. constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  524. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  525. constructor Create_type_sym_offset(_typ:taiconst_type;_sym:tasmsymbol;ofs:aint);
  526. constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  527. constructor Create_rel_sym_offset(_typ : taiconst_type; _sym,_endsym : tasmsymbol; _ofs : int64);
  528. constructor Create_rva_sym(_sym:tasmsymbol);
  529. constructor Createname(const name:string;ofs:aint);
  530. constructor Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  531. constructor Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
  532. constructor Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:aint);
  533. constructor Create_nil_codeptr;
  534. constructor Create_nil_dataptr;
  535. constructor Create_int_codeptr(_value: int64);
  536. constructor Create_int_dataptr(_value: int64);
  537. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  538. procedure ppuwrite(ppufile:tcompilerppufile);override;
  539. procedure derefimpl;override;
  540. function getcopy:tlinkedlistitem;override;
  541. function size:longint;
  542. end;
  543. { Generates a single float (32 bit real) }
  544. tai_real_32bit = class(tai)
  545. value : ts32real;
  546. constructor Create(_value : ts32real);
  547. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  548. procedure ppuwrite(ppufile:tcompilerppufile);override;
  549. end;
  550. tformatoptions = (fo_none,fo_hiloswapped);
  551. { Generates a double float (64 bit real) }
  552. tai_real_64bit = class(tai)
  553. value : ts64real;
  554. {$ifdef ARM}
  555. formatoptions : tformatoptions;
  556. constructor Create_hiloswapped(_value : ts64real);
  557. {$endif ARM}
  558. constructor Create(_value : ts64real);
  559. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  560. procedure ppuwrite(ppufile:tcompilerppufile);override;
  561. end;
  562. { Generates an extended float (80 bit real) }
  563. tai_real_80bit = class(tai)
  564. value : ts80real;
  565. savesize : byte;
  566. constructor Create(_value : ts80real; _savesize: byte);
  567. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  568. procedure ppuwrite(ppufile:tcompilerppufile);override;
  569. end;
  570. { Generates an float128 (128 bit real) }
  571. tai_real_128bit = class(tai)
  572. value : ts128real;
  573. constructor Create(_value : ts128real);
  574. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  575. procedure ppuwrite(ppufile:tcompilerppufile);override;
  576. end;
  577. { Generates a comp int (integer over 64 bits)
  578. This is Intel 80x86 specific, and is not
  579. really supported on other processors.
  580. }
  581. tai_comp_64bit = class(tai)
  582. value : ts64comp;
  583. constructor Create(_value : ts64comp);
  584. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  585. procedure ppuwrite(ppufile:tcompilerppufile);override;
  586. end;
  587. { tai_stab }
  588. tai_stab = class(tai)
  589. str : pchar;
  590. stabtype : TStabType;
  591. constructor Create(_stabtype:TStabType;_str : pchar);
  592. constructor Create_str(_stabtype:TStabType;const s:string);
  593. constructor create_ansistr(_stabtype: TStabType; const s: ansistring);
  594. destructor Destroy;override;
  595. end;
  596. tai_force_line = class(tailineinfo)
  597. constructor Create;
  598. end;
  599. tai_function_name = class(tai)
  600. funcname : pshortstring;
  601. constructor create(const s:string);
  602. destructor destroy;override;
  603. end;
  604. { Insert a cut to split assembler into several smaller files }
  605. tai_cutobject = class(tai)
  606. place : tcutplace;
  607. constructor Create;
  608. constructor Create_begin;
  609. constructor Create_end;
  610. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  611. procedure ppuwrite(ppufile:tcompilerppufile);override;
  612. end;
  613. { Insert a marker for assembler and inline blocks }
  614. tai_marker = class(tai)
  615. Kind: TAsmMarker;
  616. Constructor Create(_Kind: TAsmMarker);
  617. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  618. procedure ppuwrite(ppufile:tcompilerppufile);override;
  619. end;
  620. tai_tempalloc = class(tai)
  621. allocation : boolean;
  622. {$ifdef EXTDEBUG}
  623. problem : pshortstring;
  624. {$endif EXTDEBUG}
  625. temppos,
  626. tempsize : longint;
  627. constructor alloc(pos,size:longint);
  628. constructor dealloc(pos,size:longint);
  629. {$ifdef EXTDEBUG}
  630. constructor allocinfo(pos,size:longint;const st:string);
  631. {$endif EXTDEBUG}
  632. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  633. destructor destroy;override;
  634. procedure ppuwrite(ppufile:tcompilerppufile);override;
  635. end;
  636. tai_regalloc = class(tai)
  637. reg : tregister;
  638. ratype : TRegAllocType;
  639. { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
  640. keep : boolean;
  641. { reg(de)alloc belongs to this instruction, this
  642. is only used for automatic inserted (de)alloc for
  643. imaginary register and required for spilling code }
  644. instr : tai;
  645. constructor alloc(r : tregister;ainstr:tai);
  646. constructor dealloc(r : tregister;ainstr:tai);
  647. constructor sync(r : tregister);
  648. constructor resize(r : tregister);
  649. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  650. procedure ppuwrite(ppufile:tcompilerppufile);override;
  651. end;
  652. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  653. { Class template for assembler instructions
  654. }
  655. tai_cpu_abstract = class(tailineinfo)
  656. protected
  657. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
  658. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
  659. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  660. procedure ppuderefoper(var o:toper);virtual;abstract;
  661. public
  662. { Condition flags for instruction }
  663. condition : TAsmCond;
  664. { Number of operands to instruction }
  665. ops : byte;
  666. { Number of allocate oper structures }
  667. opercnt : byte;
  668. { Operands of instruction }
  669. oper : array[0..max_operands-1] of poper;
  670. { Actual opcode of instruction }
  671. opcode : tasmop;
  672. {$ifdef x86}
  673. segprefix : tregister;
  674. {$endif x86}
  675. { true if instruction is a jmp }
  676. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  677. Constructor Create(op : tasmop);virtual;
  678. Destructor Destroy;override;
  679. function getcopy:TLinkedListItem;override;
  680. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  681. procedure ppuwrite(ppufile:tcompilerppufile);override;
  682. procedure buildderefimpl;override;
  683. procedure derefimpl;override;
  684. procedure SetCondition(const c:TAsmCond);
  685. procedure allocate_oper(opers:longint);
  686. procedure loadconst(opidx:longint;l:aint);
  687. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  688. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  689. procedure loadref(opidx:longint;const r:treference);
  690. procedure loadreg(opidx:longint;r:tregister);
  691. procedure loadoper(opidx:longint;o:toper);
  692. procedure clearop(opidx:longint);
  693. procedure freeop(opidx:longint);
  694. { register allocator }
  695. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  696. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  697. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  698. function Pass1(objdata:TObjData):longint;virtual;
  699. procedure Pass2(objdata:TObjData);virtual;
  700. procedure resetpass1; virtual;
  701. procedure resetpass2; virtual;
  702. end;
  703. tai_cpu_class = class of tai_cpu_abstract;
  704. { Buffer type used for alignment }
  705. tfillbuffer = array[0..63] of char;
  706. { alignment for operator }
  707. tai_align_abstract = class(tai)
  708. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  709. fillsize : byte; { real size to fill }
  710. fillop : byte; { value to fill with - optional }
  711. use_op : boolean;
  712. constructor Create(b:byte);virtual;
  713. constructor Create_op(b: byte; _op: byte);virtual;
  714. constructor Create_zeros(b:byte);
  715. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  716. procedure ppuwrite(ppufile:tcompilerppufile);override;
  717. function calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;virtual;
  718. end;
  719. tai_align_class = class of tai_align_abstract;
  720. tai_varloc = class(tai)
  721. oldlocation,
  722. oldlocationhi,
  723. newlocation,
  724. newlocationhi : tregister;
  725. varsym : tsym;
  726. constructor create(sym : tsym;loc : tregister);
  727. constructor create64(sym : tsym;loc,lochi : tregister);
  728. {$ifdef cpu64bitalu}
  729. constructor create128(sym : tsym;loc,lochi : tregister);
  730. {$endif cpu64bitalu}
  731. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  732. procedure ppuwrite(ppufile:tcompilerppufile);override;
  733. procedure buildderefimpl;override;
  734. procedure derefimpl;override;
  735. end;
  736. TSehDirectiveDatatype=(sd_none,sd_string,sd_reg,sd_offset,sd_regoffset);
  737. TSehDirectiveData=record
  738. case typ: TSehDirectiveDatatype of
  739. sd_none: ();
  740. sd_string: (name:pshortstring;flags:byte);
  741. sd_reg,sd_offset,sd_regoffset: (reg:TRegister;offset:dword);
  742. end;
  743. tai_seh_directive = class(tai)
  744. kind: TAsmSehDirective;
  745. data: TSehDirectiveData;
  746. constructor create(_kind:TAsmSehDirective);
  747. constructor create_name(_kind:TAsmSehDirective;const _name: string);
  748. constructor create_reg(_kind:TAsmSehDirective;r:TRegister);
  749. constructor create_offset(_kind:TAsmSehDirective;ofs:dword);
  750. constructor create_reg_offset(_kind:TAsmSehDirective;r:TRegister;ofs:dword);
  751. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  752. destructor destroy;override;
  753. procedure ppuwrite(ppufile:tcompilerppufile);override;
  754. procedure generate_code(objdata:TObjData);virtual;
  755. property datatype: TSehDirectiveDatatype read data.typ;
  756. end;
  757. tai_seh_directive_class=class of tai_seh_directive;
  758. {$ifdef JVM}
  759. { JVM variable live range description }
  760. tai_jvar = class(tai)
  761. stackslot: longint;
  762. desc: pshortstring;
  763. startlab,stoplab: tasmsymbol;
  764. constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  765. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  766. procedure ppuwrite(ppufile:tcompilerppufile);override;
  767. destructor destroy;override;
  768. end;
  769. tai_jvar_class = class of tai_jvar;
  770. { JVM exception catch description }
  771. tai_jcatch = class(tai)
  772. name: pshortstring;
  773. startlab,stoplab,handlerlab: tasmsymbol;
  774. constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  775. destructor destroy;override;
  776. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  777. procedure ppuwrite(ppufile:tcompilerppufile);override;
  778. end;
  779. tai_jcatch_class = class of tai_jcatch;
  780. {$endif JVM}
  781. tai_set = class(tai)
  782. sym,
  783. value: pshortstring;
  784. constructor create(const asym, avalue: string);
  785. destructor destroy;override;
  786. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  787. procedure ppuwrite(ppufile:tcompilerppufile);override;
  788. end;
  789. {$ifdef arm}
  790. tai_thumb_set = class(tai_set)
  791. constructor create(const asym, avalue: string);
  792. end;
  793. {$endif arm}
  794. tai_weak = class(tai)
  795. sym: pshortstring;
  796. constructor create(const asym: string);
  797. destructor destroy;override;
  798. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  799. procedure ppuwrite(ppufile:tcompilerppufile);override;
  800. end;
  801. var
  802. { array with all class types for tais }
  803. aiclass : taiclassarray;
  804. { target specific tais, possibly overwritten in target specific aasmcpu }
  805. cai_align : tai_align_class = tai_align_abstract;
  806. cai_cpu : tai_cpu_class = tai_cpu_abstract;
  807. cai_seh_directive: tai_seh_directive_class = tai_seh_directive;
  808. { hook to notify uses of registers }
  809. add_reg_instruction_hook : tadd_reg_instruction_proc;
  810. procedure maybe_new_object_file(list:TAsmList);
  811. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  812. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  813. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  814. procedure section_symbol_end(list:TAsmList;const Aname:string);
  815. function ppuloadai(ppufile:tcompilerppufile):tai;
  816. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  817. implementation
  818. uses
  819. SysUtils,
  820. verbose,
  821. globals;
  822. const
  823. pputaimarker = 254;
  824. {****************************************************************************
  825. Helpers
  826. ****************************************************************************}
  827. procedure maybe_new_object_file(list:TAsmList);
  828. begin
  829. if create_smartlink_library then
  830. list.concat(tai_cutobject.create);
  831. end;
  832. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  833. begin
  834. list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
  835. list.concat(cai_align.create(Aalign));
  836. end;
  837. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  838. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  839. begin
  840. maybe_new_object_file(list);
  841. new_section(list,Asectype,Aname,Aalign);
  842. if Aglobal or
  843. create_smartlink then
  844. list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
  845. else
  846. list.concat(tai_symbol.createname(Aname,Asymtyp,0));
  847. end;
  848. procedure section_symbol_end(list:TAsmList;const Aname:string);
  849. begin
  850. list.concat(tai_symbol_end.createname(Aname));
  851. end;
  852. function ppuloadai(ppufile:tcompilerppufile):tai;
  853. var
  854. b : byte;
  855. t : taitype;
  856. begin
  857. { marker }
  858. b:=ppufile.getbyte;
  859. if b<>pputaimarker then
  860. internalerror(200208181);
  861. { load nodetype }
  862. t:=taitype(ppufile.getbyte);
  863. if t<>ait_none then
  864. begin
  865. if t>high(taitype) then
  866. internalerror(200208182);
  867. if not assigned(aiclass[t]) then
  868. internalerror(200208183);
  869. {writeln('taiload: ',taitypestr[t]);}
  870. { generate tai of the correct class }
  871. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  872. end
  873. else
  874. ppuloadai:=nil;
  875. end;
  876. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  877. begin
  878. { marker, read by ppuloadnode }
  879. ppufile.putbyte(pputaimarker);
  880. if assigned(n) then
  881. begin
  882. { type, read by ppuloadnode }
  883. ppufile.putbyte(byte(n.typ));
  884. {writeln('taiwrite: ',taitypestr[n.typ]);}
  885. n.ppuwrite(ppufile);
  886. end
  887. else
  888. ppufile.putbyte(byte(ait_none));
  889. end;
  890. constructor tai_weak.create(const asym: string);
  891. begin
  892. inherited create;
  893. typ:=ait_weak;
  894. sym:=stringdup(asym);
  895. end;
  896. destructor tai_weak.destroy;
  897. begin
  898. stringdispose(sym);
  899. inherited destroy;
  900. end;
  901. constructor tai_weak.ppuload(t: taitype; ppufile: tcompilerppufile);
  902. begin
  903. inherited ppuload(t,ppufile);
  904. sym:=stringdup(ppufile.getstring);
  905. end;
  906. procedure tai_weak.ppuwrite(ppufile: tcompilerppufile);
  907. begin
  908. inherited ppuwrite(ppufile);
  909. ppufile.putstring(sym^);
  910. end;
  911. {$ifdef arm}
  912. constructor tai_thumb_set.create(const asym, avalue: string);
  913. begin
  914. inherited create(asym, avalue);
  915. typ:=ait_thumb_set;
  916. end;
  917. {$endif arm}
  918. constructor tai_set.create(const asym, avalue: string);
  919. begin
  920. inherited create;
  921. typ:=ait_set;
  922. sym:=stringdup(asym);
  923. value:=stringdup(avalue);
  924. end;
  925. destructor tai_set.destroy;
  926. begin
  927. stringdispose(sym);
  928. stringdispose(value);
  929. inherited destroy;
  930. end;
  931. constructor tai_set.ppuload(t: taitype; ppufile: tcompilerppufile);
  932. begin
  933. inherited ppuload(t,ppufile);
  934. sym:=stringdup(ppufile.getstring);
  935. value:=stringdup(ppufile.getstring);
  936. end;
  937. procedure tai_set.ppuwrite(ppufile: tcompilerppufile);
  938. begin
  939. inherited ppuwrite(ppufile);
  940. ppufile.putstring(sym^);
  941. ppufile.putstring(value^);
  942. end;
  943. constructor tai_varloc.create(sym: tsym; loc: tregister);
  944. begin
  945. inherited Create;
  946. typ:=ait_varloc;
  947. newlocation:=loc;
  948. newlocationhi:=NR_NO;
  949. varsym:=sym;
  950. oldlocationhi:=NR_NO;
  951. end;
  952. constructor tai_varloc.create64(sym: tsym; loc, lochi: tregister);
  953. begin
  954. inherited Create;
  955. typ:=ait_varloc;
  956. newlocation:=loc;
  957. newlocationhi:=lochi;
  958. varsym:=sym;
  959. end;
  960. {$ifdef cpu64bitalu}
  961. constructor tai_varloc.create128(sym: tsym; loc, lochi: tregister);
  962. begin
  963. inherited Create;
  964. typ:=ait_varloc;
  965. newlocation:=loc;
  966. newlocationhi:=lochi;
  967. varsym:=sym;
  968. end;
  969. {$endif cpu64bitalu}
  970. constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
  971. begin
  972. inherited ppuload(t, ppufile);
  973. end;
  974. procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
  975. begin
  976. inherited ppuwrite(ppufile);
  977. end;
  978. procedure tai_varloc.buildderefimpl;
  979. begin
  980. inherited buildderefimpl;
  981. end;
  982. procedure tai_varloc.derefimpl;
  983. begin
  984. inherited derefimpl;
  985. end;
  986. {****************************************************************************
  987. TAI
  988. ****************************************************************************}
  989. constructor tai.Create;
  990. begin
  991. {$ifndef NOOPT}
  992. optinfo:=nil;
  993. {$endif NOOPT}
  994. end;
  995. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  996. begin
  997. typ:=t;
  998. {$ifndef NOOPT}
  999. optinfo:=nil;
  1000. {$endif}
  1001. end;
  1002. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  1003. begin
  1004. end;
  1005. procedure tai.buildderefimpl;
  1006. begin
  1007. end;
  1008. procedure tai.derefimpl;
  1009. begin
  1010. end;
  1011. {****************************************************************************
  1012. TAILINEINFO
  1013. ****************************************************************************}
  1014. constructor tailineinfo.create;
  1015. begin
  1016. inherited create;
  1017. fileinfo:=current_filepos;
  1018. end;
  1019. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  1020. begin
  1021. inherited ppuload(t,ppufile);
  1022. ppufile.getposinfo(fileinfo);
  1023. end;
  1024. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  1025. begin
  1026. inherited ppuwrite(ppufile);
  1027. ppufile.putposinfo(fileinfo);
  1028. end;
  1029. {****************************************************************************
  1030. TAI_SIMPLE
  1031. ****************************************************************************}
  1032. constructor tai_simple.create(_typ : taitype);
  1033. begin
  1034. inherited create;
  1035. typ:=_typ;
  1036. end;
  1037. {****************************************************************************
  1038. TAI_SECTION
  1039. ****************************************************************************}
  1040. constructor tai_section.Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  1041. begin
  1042. inherited Create;
  1043. typ:=ait_section;
  1044. sectype:=asectype;
  1045. secalign:=Aalign;
  1046. secorder:=Asecorder;
  1047. name:=stringdup(Aname);
  1048. sec:=nil;
  1049. end;
  1050. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  1051. begin
  1052. inherited ppuload(t,ppufile);
  1053. sectype:=TAsmSectiontype(ppufile.getbyte);
  1054. secalign:=ppufile.getbyte;
  1055. name:=stringdup(ppufile.getstring);
  1056. sec:=nil;
  1057. end;
  1058. destructor tai_section.Destroy;
  1059. begin
  1060. stringdispose(name);
  1061. end;
  1062. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  1063. begin
  1064. inherited ppuwrite(ppufile);
  1065. ppufile.putbyte(byte(sectype));
  1066. ppufile.putbyte(secalign);
  1067. ppufile.putstring(name^);
  1068. end;
  1069. {****************************************************************************
  1070. TAI_DATABLOCK
  1071. ****************************************************************************}
  1072. constructor tai_datablock.Create(const _name : string;_size : aint);
  1073. begin
  1074. inherited Create;
  1075. typ:=ait_datablock;
  1076. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
  1077. { keep things aligned }
  1078. if _size<=0 then
  1079. _size:=sizeof(aint);
  1080. size:=_size;
  1081. is_global:=false;
  1082. end;
  1083. constructor tai_datablock.Create_global(const _name : string;_size : asizeint);
  1084. begin
  1085. inherited Create;
  1086. typ:=ait_datablock;
  1087. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
  1088. { keep things aligned }
  1089. if _size<=0 then
  1090. _size:=sizeof(aint);
  1091. size:=_size;
  1092. is_global:=true;
  1093. end;
  1094. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  1095. begin
  1096. inherited Create;
  1097. sym:=ppufile.getasmsymbol;
  1098. size:=ppufile.getaint;
  1099. is_global:=boolean(ppufile.getbyte);
  1100. end;
  1101. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  1102. begin
  1103. inherited ppuwrite(ppufile);
  1104. ppufile.putasmsymbol(sym);
  1105. ppufile.putaint(size);
  1106. ppufile.putbyte(byte(is_global));
  1107. end;
  1108. procedure tai_datablock.derefimpl;
  1109. begin
  1110. end;
  1111. {****************************************************************************
  1112. TAI_SYMBOL
  1113. ****************************************************************************}
  1114. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  1115. begin
  1116. inherited Create;
  1117. typ:=ait_symbol;
  1118. sym:=_sym;
  1119. size:=siz;
  1120. { don't redefine global/external symbols as local, as code to access
  1121. such symbols is different on some platforms }
  1122. if not(sym.bind in [AB_NONE,AB_LOCAL]) then
  1123. internalerror(2013081601);
  1124. sym.bind:=AB_LOCAL;
  1125. is_global:=false;
  1126. end;
  1127. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  1128. begin
  1129. inherited Create;
  1130. typ:=ait_symbol;
  1131. sym:=_sym;
  1132. size:=siz;
  1133. { don't override PRIVATE_EXTERN with GLOBAL }
  1134. if not(sym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]) then
  1135. sym.bind:=AB_GLOBAL;
  1136. is_global:=true;
  1137. end;
  1138. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  1139. begin
  1140. inherited Create;
  1141. typ:=ait_symbol;
  1142. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
  1143. size:=siz;
  1144. is_global:=false;
  1145. end;
  1146. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  1147. begin
  1148. inherited Create;
  1149. typ:=ait_symbol;
  1150. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
  1151. size:=siz;
  1152. is_global:=true;
  1153. end;
  1154. constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint);
  1155. begin
  1156. Createname_global(_name,_symtyp,siz);
  1157. value:=val;
  1158. has_value:=true;
  1159. end;
  1160. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  1161. begin
  1162. inherited ppuload(t,ppufile);
  1163. sym:=ppufile.getasmsymbol;
  1164. size:=ppufile.getlongint;
  1165. is_global:=boolean(ppufile.getbyte);
  1166. end;
  1167. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  1168. begin
  1169. inherited ppuwrite(ppufile);
  1170. ppufile.putasmsymbol(sym);
  1171. ppufile.putlongint(size);
  1172. ppufile.putbyte(byte(is_global));
  1173. end;
  1174. procedure tai_symbol.derefimpl;
  1175. begin
  1176. end;
  1177. {****************************************************************************
  1178. TAI_SYMBOL_END
  1179. ****************************************************************************}
  1180. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  1181. begin
  1182. inherited Create;
  1183. typ:=ait_symbol_end;
  1184. sym:=_sym;
  1185. end;
  1186. constructor tai_symbol_end.Createname(const _name : string);
  1187. begin
  1188. inherited Create;
  1189. typ:=ait_symbol_end;
  1190. sym:=current_asmdata.GetAsmSymbol(_name);
  1191. if not assigned(sym) then
  1192. internalerror(2013080301);
  1193. end;
  1194. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  1195. begin
  1196. inherited ppuload(t,ppufile);
  1197. sym:=ppufile.getasmsymbol;
  1198. end;
  1199. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  1200. begin
  1201. inherited ppuwrite(ppufile);
  1202. ppufile.putasmsymbol(sym);
  1203. end;
  1204. procedure tai_symbol_end.derefimpl;
  1205. begin
  1206. end;
  1207. {****************************************************************************
  1208. TAI_SYMBOL_END
  1209. ****************************************************************************}
  1210. constructor tai_directive.Create(_directive:TAsmDirective;const _name:ansistring);
  1211. begin
  1212. inherited Create;
  1213. typ:=ait_directive;
  1214. name:=_name;
  1215. directive:=_directive;
  1216. end;
  1217. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  1218. begin
  1219. inherited ppuload(t,ppufile);
  1220. name:=ppufile.getansistring;
  1221. directive:=TAsmDirective(ppufile.getbyte);
  1222. end;
  1223. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  1224. begin
  1225. inherited ppuwrite(ppufile);
  1226. ppufile.putansistring(name);
  1227. ppufile.putbyte(byte(directive));
  1228. end;
  1229. {****************************************************************************
  1230. TAI_CONST
  1231. ****************************************************************************}
  1232. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  1233. begin
  1234. inherited Create;
  1235. typ:=ait_const;
  1236. consttype:=_typ;
  1237. value:=_value;
  1238. sym:=nil;
  1239. endsym:=nil;
  1240. end;
  1241. constructor tai_const.Create_128bit(_value : int64);
  1242. begin
  1243. inherited Create;
  1244. typ:=ait_const;
  1245. consttype:=aitconst_128bit;
  1246. value:=_value;
  1247. sym:=nil;
  1248. endsym:=nil;
  1249. end;
  1250. constructor tai_const.Create_64bit(_value : int64);
  1251. begin
  1252. inherited Create;
  1253. typ:=ait_const;
  1254. consttype:=aitconst_64bit;
  1255. value:=_value;
  1256. sym:=nil;
  1257. endsym:=nil;
  1258. end;
  1259. constructor tai_const.Create_32bit(_value : longint);
  1260. begin
  1261. inherited Create;
  1262. typ:=ait_const;
  1263. consttype:=aitconst_32bit;
  1264. value:=_value;
  1265. sym:=nil;
  1266. endsym:=nil;
  1267. end;
  1268. constructor tai_const.Create_16bit(_value : word);
  1269. begin
  1270. inherited Create;
  1271. typ:=ait_const;
  1272. consttype:=aitconst_16bit;
  1273. value:=_value;
  1274. sym:=nil;
  1275. endsym:=nil;
  1276. end;
  1277. constructor tai_const.Create_64bit_unaligned(_value : int64);
  1278. begin
  1279. inherited Create;
  1280. typ:=ait_const;
  1281. consttype:=aitconst_64bit_unaligned;
  1282. value:=_value;
  1283. sym:=nil;
  1284. endsym:=nil;
  1285. end;
  1286. constructor tai_const.Create_32bit_unaligned(_value : longint);
  1287. begin
  1288. inherited Create;
  1289. typ:=ait_const;
  1290. consttype:=aitconst_32bit_unaligned;
  1291. value:=_value;
  1292. sym:=nil;
  1293. endsym:=nil;
  1294. end;
  1295. constructor tai_const.Create_16bit_unaligned(_value : word);
  1296. begin
  1297. inherited Create;
  1298. typ:=ait_const;
  1299. consttype:=aitconst_16bit_unaligned;
  1300. value:=_value;
  1301. sym:=nil;
  1302. endsym:=nil;
  1303. end;
  1304. constructor tai_const.Create_8bit(_value : byte);
  1305. begin
  1306. inherited Create;
  1307. typ:=ait_const;
  1308. consttype:=aitconst_8bit;
  1309. value:=_value;
  1310. sym:=nil;
  1311. endsym:=nil;
  1312. end;
  1313. constructor tai_const.Create_char(size: integer; _value: dword);
  1314. begin
  1315. inherited Create;
  1316. typ:=ait_const;
  1317. case size of
  1318. 1:
  1319. begin
  1320. consttype:=aitconst_8bit;
  1321. value:=byte(_value)
  1322. end;
  1323. 2:
  1324. begin
  1325. consttype:=aitconst_16bit;
  1326. value:=word(_value)
  1327. end
  1328. else
  1329. InternalError(2010030701)
  1330. end
  1331. end;
  1332. constructor tai_const.Create_sleb128bit(_value : int64);
  1333. begin
  1334. inherited Create;
  1335. typ:=ait_const;
  1336. consttype:=aitconst_sleb128bit;
  1337. value:=_value;
  1338. sym:=nil;
  1339. endsym:=nil;
  1340. end;
  1341. constructor tai_const.Create_uleb128bit(_value : qword);
  1342. begin
  1343. inherited Create;
  1344. typ:=ait_const;
  1345. consttype:=aitconst_uleb128bit;
  1346. value:=int64(_value);
  1347. sym:=nil;
  1348. endsym:=nil;
  1349. end;
  1350. constructor tai_const.Create_aint(_value : aint);
  1351. begin
  1352. inherited Create;
  1353. typ:=ait_const;
  1354. consttype:=aitconst_aint;
  1355. value:=_value;
  1356. sym:=nil;
  1357. endsym:=nil;
  1358. end;
  1359. constructor tai_const.Create_pint(_value : pint);
  1360. begin
  1361. inherited Create;
  1362. typ:=ait_const;
  1363. consttype:=aitconst_ptr;
  1364. value:=_value;
  1365. sym:=nil;
  1366. endsym:=nil;
  1367. end;
  1368. constructor tai_const.Create_pint_unaligned(_value: pint);
  1369. begin
  1370. inherited Create;
  1371. typ:=ait_const;
  1372. consttype:=aitconst_ptr_unaligned;
  1373. value:=_value;
  1374. sym:=nil;
  1375. endsym:=nil;
  1376. end;
  1377. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  1378. begin
  1379. inherited Create;
  1380. typ:=ait_const;
  1381. consttype:=_typ;
  1382. sym:=_sym;
  1383. endsym:=nil;
  1384. value:=0;
  1385. { update sym info }
  1386. if assigned(sym) then
  1387. sym.increfs;
  1388. end;
  1389. constructor tai_const.Create_sym(_sym:tasmsymbol);
  1390. begin
  1391. self.create_sym_offset(_sym,0);
  1392. end;
  1393. {$ifdef i8086}
  1394. constructor tai_const.Create_sym_near(_sym: tasmsymbol);
  1395. begin
  1396. self.create_sym(_sym);
  1397. consttype:=aitconst_ptr;
  1398. end;
  1399. constructor tai_const.Create_sym_far(_sym: tasmsymbol);
  1400. begin
  1401. self.create_sym(_sym);
  1402. consttype:=aitconst_farptr;
  1403. end;
  1404. {$endif i8086}
  1405. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  1406. begin
  1407. inherited Create;
  1408. typ:=ait_const;
  1409. {$ifdef i8086}
  1410. if assigned(_sym) and (_sym.typ=AT_DATA) then
  1411. begin
  1412. if current_settings.x86memorymodel in x86_far_data_models then
  1413. consttype:=aitconst_farptr
  1414. else
  1415. consttype:=aitconst_ptr;
  1416. end
  1417. else
  1418. begin
  1419. if current_settings.x86memorymodel in x86_far_code_models then
  1420. consttype:=aitconst_farptr
  1421. else
  1422. consttype:=aitconst_ptr;
  1423. end;
  1424. {$else i8086}
  1425. consttype:=aitconst_ptr;
  1426. {$endif i8086}
  1427. { sym is allowed to be nil, this is used to write nil pointers }
  1428. sym:=_sym;
  1429. endsym:=nil;
  1430. { store the original offset in symofs so that we can recalculate the
  1431. value field in the assembler }
  1432. symofs:=ofs;
  1433. value:=ofs;
  1434. { update sym info }
  1435. if assigned(sym) then
  1436. sym.increfs;
  1437. end;
  1438. constructor tai_const.Create_type_sym_offset(_typ : taiconst_type;_sym : tasmsymbol; ofs : aint);
  1439. begin
  1440. inherited Create;
  1441. typ:=ait_const;
  1442. consttype:=_typ;
  1443. { sym is allowed to be nil, this is used to write nil pointers }
  1444. sym:=_sym;
  1445. endsym:=nil;
  1446. { store the original offset in symofs so that we can recalculate the
  1447. value field in the assembler }
  1448. symofs:=ofs;
  1449. value:=ofs;
  1450. { update sym info }
  1451. if assigned(sym) then
  1452. sym.increfs;
  1453. end;
  1454. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  1455. begin
  1456. self.create_sym_offset(_sym,0);
  1457. consttype:=_typ;
  1458. endsym:=_endsym;
  1459. endsym.increfs;
  1460. end;
  1461. constructor tai_const.Create_rel_sym_offset(_typ: taiconst_type; _sym,_endsym: tasmsymbol; _ofs: int64);
  1462. begin
  1463. self.create_sym_offset(_sym,_ofs);
  1464. consttype:=_typ;
  1465. endsym:=_endsym;
  1466. endsym.increfs;
  1467. end;
  1468. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  1469. begin
  1470. self.create_sym_offset(_sym,0);
  1471. consttype:=aitconst_rva_symbol;
  1472. end;
  1473. constructor tai_const.Createname(const name:string;ofs:aint);
  1474. begin
  1475. self.Createname(name,AT_NONE,ofs);
  1476. end;
  1477. constructor tai_const.Createname(const name:string;_symtyp:Tasmsymtype;ofs:aint);
  1478. begin
  1479. self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
  1480. end;
  1481. constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
  1482. begin
  1483. self.Create_type_name(_typ,name,AT_NONE,ofs);
  1484. end;
  1485. constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;_symtyp:Tasmsymtype;ofs:aint);
  1486. begin
  1487. self.create_sym_offset(current_asmdata.RefAsmSymbol(name,_symtyp),ofs);
  1488. consttype:=_typ;
  1489. end;
  1490. constructor tai_const.Create_nil_codeptr;
  1491. begin
  1492. self.Create_int_codeptr(0);
  1493. end;
  1494. constructor tai_const.Create_nil_dataptr;
  1495. begin
  1496. self.Create_int_dataptr(0);
  1497. end;
  1498. constructor tai_const.Create_int_codeptr(_value: int64);
  1499. begin
  1500. inherited Create;
  1501. typ:=ait_const;
  1502. {$ifdef i8086}
  1503. if current_settings.x86memorymodel in x86_far_code_models then
  1504. consttype:=aitconst_farptr
  1505. else
  1506. {$endif i8086}
  1507. consttype:=aitconst_ptr;
  1508. sym:=nil;
  1509. endsym:=nil;
  1510. symofs:=0;
  1511. value:=_value;
  1512. end;
  1513. constructor tai_const.Create_int_dataptr(_value: int64);
  1514. begin
  1515. inherited Create;
  1516. typ:=ait_const;
  1517. {$ifdef i8086}
  1518. if current_settings.x86memorymodel in x86_far_data_models then
  1519. consttype:=aitconst_farptr
  1520. else
  1521. {$endif i8086}
  1522. consttype:=aitconst_ptr;
  1523. sym:=nil;
  1524. endsym:=nil;
  1525. symofs:=0;
  1526. value:=_value;
  1527. end;
  1528. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1529. begin
  1530. inherited ppuload(t,ppufile);
  1531. consttype:=taiconst_type(ppufile.getbyte);
  1532. sym:=ppufile.getasmsymbol;
  1533. endsym:=ppufile.getasmsymbol;
  1534. value:=ppufile.getint64;
  1535. end;
  1536. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1537. begin
  1538. inherited ppuwrite(ppufile);
  1539. ppufile.putbyte(byte(consttype));
  1540. ppufile.putasmsymbol(sym);
  1541. ppufile.putasmsymbol(endsym);
  1542. ppufile.putint64(value);
  1543. end;
  1544. procedure tai_const.derefimpl;
  1545. begin
  1546. end;
  1547. function tai_const.getcopy:tlinkedlistitem;
  1548. begin
  1549. getcopy:=inherited getcopy;
  1550. { we need to increase the reference number }
  1551. if assigned(sym) then
  1552. sym.increfs;
  1553. if assigned(endsym) then
  1554. endsym.increfs;
  1555. end;
  1556. function tai_const.size:longint;
  1557. begin
  1558. case consttype of
  1559. aitconst_8bit :
  1560. result:=1;
  1561. aitconst_16bit,aitconst_16bit_unaligned :
  1562. result:=2;
  1563. aitconst_32bit,aitconst_darwin_dwarf_delta32,
  1564. aitconst_32bit_unaligned:
  1565. result:=4;
  1566. aitconst_64bit,aitconst_darwin_dwarf_delta64,
  1567. aitconst_64bit_unaligned:
  1568. result:=8;
  1569. aitconst_secrel32_symbol,
  1570. aitconst_rva_symbol :
  1571. if target_info.system=system_x86_64_win64 then
  1572. result:=sizeof(longint)
  1573. else
  1574. result:=sizeof(pint);
  1575. aitconst_uleb128bit :
  1576. result:=LengthUleb128(qword(value));
  1577. aitconst_sleb128bit :
  1578. result:=LengthSleb128(value);
  1579. aitconst_half16bit:
  1580. result:=2;
  1581. aitconst_gotoff_symbol:
  1582. result:=4;
  1583. else
  1584. internalerror(200603253);
  1585. end;
  1586. end;
  1587. {****************************************************************************
  1588. TAI_real_32bit
  1589. ****************************************************************************}
  1590. constructor tai_real_32bit.Create(_value : ts32real);
  1591. begin
  1592. inherited Create;
  1593. typ:=ait_real_32bit;
  1594. value:=_value;
  1595. end;
  1596. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1597. begin
  1598. inherited ppuload(t,ppufile);
  1599. value:=ppufile.getreal;
  1600. end;
  1601. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1602. begin
  1603. inherited ppuwrite(ppufile);
  1604. ppufile.putreal(value);
  1605. end;
  1606. {****************************************************************************
  1607. TAI_real_64bit
  1608. ****************************************************************************}
  1609. constructor tai_real_64bit.Create(_value : ts64real);
  1610. begin
  1611. inherited Create;
  1612. typ:=ait_real_64bit;
  1613. value:=_value;
  1614. end;
  1615. {$ifdef ARM}
  1616. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1617. begin
  1618. inherited Create;
  1619. typ:=ait_real_64bit;
  1620. value:=_value;
  1621. formatoptions:=fo_hiloswapped;
  1622. end;
  1623. {$endif ARM}
  1624. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1625. begin
  1626. inherited ppuload(t,ppufile);
  1627. value:=ppufile.getreal;
  1628. {$ifdef ARM}
  1629. formatoptions:=tformatoptions(ppufile.getbyte);
  1630. {$endif ARM}
  1631. end;
  1632. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1633. begin
  1634. inherited ppuwrite(ppufile);
  1635. ppufile.putreal(value);
  1636. {$ifdef ARM}
  1637. ppufile.putbyte(byte(formatoptions));
  1638. {$endif ARM}
  1639. end;
  1640. {****************************************************************************
  1641. TAI_real_80bit
  1642. ****************************************************************************}
  1643. constructor tai_real_80bit.Create(_value : ts80real; _savesize: byte);
  1644. begin
  1645. inherited Create;
  1646. typ:=ait_real_80bit;
  1647. value:=_value;
  1648. savesize:=_savesize;
  1649. end;
  1650. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1651. begin
  1652. inherited ppuload(t,ppufile);
  1653. value:=ppufile.getreal;
  1654. savesize:=ppufile.getbyte;
  1655. end;
  1656. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1657. begin
  1658. inherited ppuwrite(ppufile);
  1659. ppufile.putreal(value);
  1660. ppufile.putbyte(savesize);
  1661. end;
  1662. {****************************************************************************
  1663. TAI_real_80bit
  1664. ****************************************************************************}
  1665. constructor tai_real_128bit.Create(_value : ts128real);
  1666. begin
  1667. inherited Create;
  1668. typ:=ait_real_128bit;
  1669. value:=_value;
  1670. end;
  1671. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1672. begin
  1673. inherited ppuload(t,ppufile);
  1674. value:=ppufile.getreal;
  1675. end;
  1676. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1677. begin
  1678. inherited ppuwrite(ppufile);
  1679. ppufile.putreal(value);
  1680. end;
  1681. {****************************************************************************
  1682. Tai_comp_64bit
  1683. ****************************************************************************}
  1684. constructor tai_comp_64bit.Create(_value : ts64comp);
  1685. begin
  1686. inherited Create;
  1687. typ:=ait_comp_64bit;
  1688. value:=_value;
  1689. end;
  1690. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1691. begin
  1692. inherited ppuload(t,ppufile);
  1693. ppufile.putdata(value,sizeof(value));
  1694. end;
  1695. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1696. begin
  1697. inherited ppuwrite(ppufile);
  1698. ppufile.getdata(value,sizeof(value));
  1699. end;
  1700. {****************************************************************************
  1701. TAI_STRING
  1702. ****************************************************************************}
  1703. constructor tai_string.Create(const _str : string);
  1704. begin
  1705. inherited Create;
  1706. typ:=ait_string;
  1707. len:=length(_str);
  1708. getmem(str,len+1);
  1709. move(_str[1],str^,len);
  1710. str[len]:=#0;
  1711. end;
  1712. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1713. begin
  1714. inherited Create;
  1715. typ:=ait_string;
  1716. str:=_str;
  1717. len:=length;
  1718. end;
  1719. destructor tai_string.destroy;
  1720. begin
  1721. if str<>nil then
  1722. freemem(str);
  1723. inherited Destroy;
  1724. end;
  1725. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1726. begin
  1727. inherited ppuload(t,ppufile);
  1728. len:=ppufile.getlongint;
  1729. getmem(str,len);
  1730. ppufile.getdata(str^,len);
  1731. end;
  1732. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1733. begin
  1734. inherited ppuwrite(ppufile);
  1735. ppufile.putlongint(len);
  1736. ppufile.putdata(str^,len);
  1737. end;
  1738. function tai_string.getcopy : tlinkedlistitem;
  1739. var
  1740. p : tlinkedlistitem;
  1741. begin
  1742. p:=inherited getcopy;
  1743. getmem(tai_string(p).str,len);
  1744. move(str^,tai_string(p).str^,len);
  1745. getcopy:=p;
  1746. end;
  1747. {****************************************************************************
  1748. TAI_LABEL
  1749. ****************************************************************************}
  1750. constructor tai_label.Create(_labsym : tasmlabel);
  1751. begin
  1752. inherited Create;
  1753. typ:=ait_label;
  1754. labsym:=_labsym;
  1755. labsym.is_set:=true;
  1756. end;
  1757. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1758. begin
  1759. inherited ppuload(t,ppufile);
  1760. labsym:=tasmlabel(ppufile.getasmsymbol);
  1761. ppufile.getbyte; { was is_global flag, now unused }
  1762. end;
  1763. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1764. begin
  1765. inherited ppuwrite(ppufile);
  1766. ppufile.putasmsymbol(labsym);
  1767. ppufile.putbyte(0); { was is_global flag, now unused }
  1768. end;
  1769. procedure tai_label.derefimpl;
  1770. begin
  1771. labsym.is_set:=true;
  1772. end;
  1773. {****************************************************************************
  1774. tai_comment comment to be inserted in the assembler file
  1775. ****************************************************************************}
  1776. constructor tai_comment.Create(_str : pchar);
  1777. begin
  1778. inherited Create;
  1779. typ:=ait_comment;
  1780. str:=_str;
  1781. end;
  1782. destructor tai_comment.destroy;
  1783. begin
  1784. freemem(str);
  1785. inherited Destroy;
  1786. end;
  1787. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1788. var
  1789. len : longint;
  1790. begin
  1791. inherited ppuload(t,ppufile);
  1792. len:=ppufile.getlongint;
  1793. getmem(str,len+1);
  1794. ppufile.getdata(str^,len);
  1795. str[len]:=#0;
  1796. end;
  1797. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1798. var
  1799. len : longint;
  1800. begin
  1801. inherited ppuwrite(ppufile);
  1802. len:=strlen(str);
  1803. ppufile.putlongint(len);
  1804. ppufile.putdata(str^,len);
  1805. end;
  1806. function tai_comment.getcopy : tlinkedlistitem;
  1807. var
  1808. p : tlinkedlistitem;
  1809. begin
  1810. p:=inherited getcopy;
  1811. getmem(tai_comment(p).str,strlen(str)+1);
  1812. move(str^,tai_comment(p).str^,strlen(str)+1);
  1813. getcopy:=p;
  1814. end;
  1815. {****************************************************************************
  1816. TAI_STABS
  1817. ****************************************************************************}
  1818. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  1819. begin
  1820. inherited create;
  1821. typ:=ait_stab;
  1822. str:=_str;
  1823. stabtype:=_stabtype;
  1824. end;
  1825. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  1826. begin
  1827. self.create(_stabtype,strpnew(s));
  1828. end;
  1829. constructor tai_stab.create_ansistr(_stabtype:TStabType;const s:ansistring);
  1830. begin
  1831. inherited create;
  1832. typ:=ait_stab;
  1833. stabtype:=_stabtype;
  1834. getmem(str,length(s)+1);
  1835. if length(s)>0 then
  1836. move(s[1],str^,length(s)+1)
  1837. else
  1838. str^:=#0;
  1839. end;
  1840. destructor tai_stab.destroy;
  1841. begin
  1842. freemem(str);
  1843. inherited destroy;
  1844. end;
  1845. {****************************************************************************
  1846. TAI_FORCE_LINE
  1847. ****************************************************************************}
  1848. constructor tai_force_line.create;
  1849. begin
  1850. inherited create;
  1851. typ:=ait_force_line;
  1852. end;
  1853. {****************************************************************************
  1854. TAI_FUNCTION_NAME
  1855. ****************************************************************************}
  1856. constructor tai_function_name.create(const s:string);
  1857. begin
  1858. inherited create;
  1859. typ:=ait_function_name;
  1860. funcname:=stringdup(s);
  1861. end;
  1862. destructor tai_function_name.destroy;
  1863. begin
  1864. stringdispose(funcname);
  1865. inherited destroy;
  1866. end;
  1867. {****************************************************************************
  1868. TAI_CUTOBJECT
  1869. ****************************************************************************}
  1870. constructor tai_cutobject.Create;
  1871. begin
  1872. inherited Create;
  1873. typ:=ait_cutobject;
  1874. place:=cut_normal;
  1875. end;
  1876. constructor tai_cutobject.Create_begin;
  1877. begin
  1878. inherited Create;
  1879. typ:=ait_cutobject;
  1880. place:=cut_begin;
  1881. end;
  1882. constructor tai_cutobject.Create_end;
  1883. begin
  1884. inherited Create;
  1885. typ:=ait_cutobject;
  1886. place:=cut_end;
  1887. end;
  1888. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1889. begin
  1890. inherited ppuload(t,ppufile);
  1891. place:=TCutPlace(ppufile.getbyte);
  1892. end;
  1893. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1894. begin
  1895. inherited ppuwrite(ppufile);
  1896. ppufile.putbyte(byte(place));
  1897. end;
  1898. {****************************************************************************
  1899. Tai_Marker
  1900. ****************************************************************************}
  1901. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1902. begin
  1903. Inherited Create;
  1904. typ := ait_marker;
  1905. Kind := _Kind;
  1906. end;
  1907. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1908. begin
  1909. inherited ppuload(t,ppufile);
  1910. kind:=TAsmMarker(ppufile.getbyte);
  1911. end;
  1912. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1913. begin
  1914. inherited ppuwrite(ppufile);
  1915. ppufile.putbyte(byte(kind));
  1916. end;
  1917. {*****************************************************************************
  1918. tai_tempalloc
  1919. *****************************************************************************}
  1920. constructor tai_tempalloc.alloc(pos,size:longint);
  1921. begin
  1922. inherited Create;
  1923. typ:=ait_tempalloc;
  1924. allocation:=true;
  1925. temppos:=pos;
  1926. tempsize:=size;
  1927. {$ifdef EXTDEBUG}
  1928. problem:=nil;
  1929. {$endif EXTDEBUG}
  1930. end;
  1931. destructor tai_tempalloc.destroy;
  1932. begin
  1933. {$ifdef EXTDEBUG}
  1934. stringdispose(problem);
  1935. {$endif EXTDEBUG}
  1936. inherited destroy;
  1937. end;
  1938. constructor tai_tempalloc.dealloc(pos,size:longint);
  1939. begin
  1940. inherited Create;
  1941. typ:=ait_tempalloc;
  1942. allocation:=false;
  1943. temppos:=pos;
  1944. tempsize:=size;
  1945. {$ifdef EXTDEBUG}
  1946. problem:=nil;
  1947. {$endif EXTDEBUG}
  1948. end;
  1949. {$ifdef EXTDEBUG}
  1950. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1951. begin
  1952. inherited Create;
  1953. typ:=ait_tempalloc;
  1954. allocation:=false;
  1955. temppos:=pos;
  1956. tempsize:=size;
  1957. problem:=stringdup(st);
  1958. end;
  1959. {$endif EXTDEBUG}
  1960. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1961. begin
  1962. inherited ppuload(t,ppufile);
  1963. temppos:=ppufile.getlongint;
  1964. tempsize:=ppufile.getlongint;
  1965. allocation:=boolean(ppufile.getbyte);
  1966. {$ifdef EXTDEBUG}
  1967. problem:=nil;
  1968. {$endif EXTDEBUG}
  1969. end;
  1970. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1971. begin
  1972. inherited ppuwrite(ppufile);
  1973. ppufile.putlongint(temppos);
  1974. ppufile.putlongint(tempsize);
  1975. ppufile.putbyte(byte(allocation));
  1976. end;
  1977. {*****************************************************************************
  1978. tai_regalloc
  1979. *****************************************************************************}
  1980. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1981. begin
  1982. inherited create;
  1983. typ:=ait_regalloc;
  1984. ratype:=ra_alloc;
  1985. reg:=r;
  1986. { ainstr must be an instruction }
  1987. if assigned(ainstr) and
  1988. (ainstr.typ<>ait_instruction) then
  1989. internalerror(200411011);
  1990. instr:=ainstr;
  1991. end;
  1992. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1993. begin
  1994. inherited create;
  1995. typ:=ait_regalloc;
  1996. ratype:=ra_dealloc;
  1997. reg:=r;
  1998. { ainstr must be an instruction }
  1999. if assigned(ainstr) and
  2000. (ainstr.typ<>ait_instruction) then
  2001. internalerror(200411012);
  2002. instr:=ainstr;
  2003. end;
  2004. constructor tai_regalloc.sync(r : tregister);
  2005. begin
  2006. inherited create;
  2007. typ:=ait_regalloc;
  2008. ratype:=ra_sync;
  2009. reg:=r;
  2010. end;
  2011. constructor tai_regalloc.resize(r : tregister);
  2012. begin
  2013. inherited create;
  2014. typ:=ait_regalloc;
  2015. ratype:=ra_resize;
  2016. reg:=r;
  2017. end;
  2018. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  2019. begin
  2020. inherited ppuload(t,ppufile);
  2021. ppufile.getdata(reg,sizeof(Tregister));
  2022. ratype:=tregalloctype(ppufile.getbyte);
  2023. keep:=boolean(ppufile.getbyte);
  2024. end;
  2025. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  2026. begin
  2027. inherited ppuwrite(ppufile);
  2028. ppufile.putdata(reg,sizeof(Tregister));
  2029. ppufile.putbyte(byte(ratype));
  2030. ppufile.putbyte(byte(keep));
  2031. end;
  2032. {*****************************************************************************
  2033. TaiInstruction
  2034. *****************************************************************************}
  2035. constructor tai_cpu_abstract.Create(op : tasmop);
  2036. begin
  2037. inherited create;
  2038. typ:=ait_instruction;
  2039. is_jmp:=false;
  2040. opcode:=op;
  2041. ops:=0;
  2042. end;
  2043. destructor tai_cpu_abstract.Destroy;
  2044. var
  2045. i : integer;
  2046. begin
  2047. for i:=0 to opercnt-1 do
  2048. freeop(i);
  2049. inherited destroy;
  2050. end;
  2051. { ---------------------------------------------------------------------
  2052. Loading of operands.
  2053. ---------------------------------------------------------------------}
  2054. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  2055. begin
  2056. while (opers>opercnt) do
  2057. begin
  2058. new(oper[opercnt]);
  2059. fillchar(oper[opercnt]^,sizeof(toper),0);
  2060. inc(opercnt);
  2061. end;
  2062. end;
  2063. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  2064. begin
  2065. allocate_oper(opidx+1);
  2066. with oper[opidx]^ do
  2067. begin
  2068. if typ<>top_const then
  2069. clearop(opidx);
  2070. val:=l;
  2071. typ:=top_const;
  2072. end;
  2073. end;
  2074. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  2075. var
  2076. r : treference;
  2077. begin
  2078. reference_reset_symbol(r,s,sofs,1);
  2079. r.refaddr:=addr_full;
  2080. loadref(opidx,r);
  2081. end;
  2082. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  2083. begin
  2084. if not assigned(s) then
  2085. internalerror(200204251);
  2086. allocate_oper(opidx+1);
  2087. with oper[opidx]^ do
  2088. begin
  2089. if typ<>top_local then
  2090. begin
  2091. clearop(opidx);
  2092. new(localoper);
  2093. end;
  2094. with oper[opidx]^.localoper^ do
  2095. begin
  2096. localsym:=s;
  2097. localsymofs:=sofs;
  2098. localindexreg:=indexreg;
  2099. localscale:=scale;
  2100. localgetoffset:=getoffset;
  2101. localforceref:=forceref;
  2102. end;
  2103. typ:=top_local;
  2104. end;
  2105. end;
  2106. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  2107. begin
  2108. allocate_oper(opidx+1);
  2109. with oper[opidx]^ do
  2110. begin
  2111. if typ<>top_ref then
  2112. begin
  2113. clearop(opidx);
  2114. new(ref);
  2115. end;
  2116. ref^:=r;
  2117. {$ifdef x86}
  2118. { We allow this exception for x86, since overloading this would be
  2119. too much of a a speed penalty}
  2120. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2121. segprefix:=ref^.segment;
  2122. {$endif}
  2123. if (cs_create_pic in current_settings.moduleswitches) and
  2124. assigned(r.symbol) and
  2125. not assigned(r.relsymbol) and
  2126. (r.refaddr=addr_no)
  2127. {$ifdef ARM}
  2128. and not(r.base=NR_R15)
  2129. {$endif ARM}
  2130. then
  2131. internalerror(200502052);
  2132. typ:=top_ref;
  2133. if assigned(add_reg_instruction_hook) then
  2134. begin
  2135. add_reg_instruction_hook(self,ref^.base);
  2136. add_reg_instruction_hook(self,ref^.index);
  2137. end;
  2138. { mark symbol as used }
  2139. if assigned(ref^.symbol) then
  2140. ref^.symbol.increfs;
  2141. if assigned(ref^.relsymbol) then
  2142. ref^.relsymbol.increfs;
  2143. end;
  2144. end;
  2145. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  2146. begin
  2147. allocate_oper(opidx+1);
  2148. with oper[opidx]^ do
  2149. begin
  2150. if typ<>top_reg then
  2151. clearop(opidx);
  2152. reg:=r;
  2153. typ:=top_reg;
  2154. end;
  2155. if assigned(add_reg_instruction_hook) then
  2156. add_reg_instruction_hook(self,r);
  2157. {$ifdef ARM}
  2158. { R15 is the PC on the ARM thus moves to R15 are jumps.
  2159. Due to speed considerations we don't use a virtual overridden method here.
  2160. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  2161. problems with iregs getting r15.
  2162. }
  2163. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  2164. {$endif ARM}
  2165. end;
  2166. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  2167. begin
  2168. allocate_oper(opidx+1);
  2169. clearop(opidx);
  2170. oper[opidx]^:=o;
  2171. { copy also the reference }
  2172. with oper[opidx]^ do
  2173. begin
  2174. case typ of
  2175. top_reg:
  2176. begin
  2177. if assigned(add_reg_instruction_hook) then
  2178. add_reg_instruction_hook(self,reg);
  2179. end;
  2180. top_ref:
  2181. begin
  2182. new(ref);
  2183. ref^:=o.ref^;
  2184. {$ifdef x86}
  2185. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2186. segprefix:=ref^.segment;
  2187. {$endif x86}
  2188. if assigned(add_reg_instruction_hook) then
  2189. begin
  2190. add_reg_instruction_hook(self,ref^.base);
  2191. add_reg_instruction_hook(self,ref^.index);
  2192. end;
  2193. end;
  2194. {$ifdef ARM}
  2195. top_shifterop:
  2196. begin
  2197. new(shifterop);
  2198. shifterop^:=o.shifterop^;
  2199. if assigned(add_reg_instruction_hook) then
  2200. add_reg_instruction_hook(self,shifterop^.rs);
  2201. end;
  2202. {$endif ARM}
  2203. end;
  2204. end;
  2205. end;
  2206. procedure tai_cpu_abstract.clearop(opidx:longint);
  2207. begin
  2208. with oper[opidx]^ do
  2209. begin
  2210. case typ of
  2211. top_ref:
  2212. dispose(ref);
  2213. top_local:
  2214. dispose(localoper);
  2215. {$ifdef ARM}
  2216. top_shifterop:
  2217. dispose(shifterop);
  2218. top_regset:
  2219. dispose(regset);
  2220. {$endif ARM}
  2221. {$ifdef m68k}
  2222. top_regset:
  2223. begin
  2224. dispose(dataregset);
  2225. dispose(addrregset);
  2226. dispose(fpuregset);
  2227. end;
  2228. {$endif m68k}
  2229. {$ifdef jvm}
  2230. top_string:
  2231. freemem(pcval);
  2232. top_wstring:
  2233. donewidestring(pwstrval);
  2234. {$endif jvm}
  2235. end;
  2236. typ:=top_none;
  2237. end;
  2238. end;
  2239. procedure tai_cpu_abstract.freeop(opidx:longint);
  2240. begin
  2241. clearop(opidx);
  2242. dispose(oper[opidx]);
  2243. end;
  2244. { ---------------------------------------------------------------------
  2245. Miscellaneous methods.
  2246. ---------------------------------------------------------------------}
  2247. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  2248. begin
  2249. condition:=c;
  2250. end;
  2251. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  2252. var
  2253. i : longint;
  2254. p : tai_cpu_abstract;
  2255. begin
  2256. p:=tai_cpu_abstract(inherited getcopy);
  2257. { make a copy of the references }
  2258. p.opercnt:=0;
  2259. p.allocate_oper(ops);
  2260. for i:=0 to ops-1 do
  2261. begin
  2262. p.oper[i]^:=oper[i]^;
  2263. case oper[i]^.typ of
  2264. top_local :
  2265. begin
  2266. new(p.oper[i]^.localoper);
  2267. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  2268. end;
  2269. top_ref :
  2270. begin
  2271. new(p.oper[i]^.ref);
  2272. p.oper[i]^.ref^:=oper[i]^.ref^;
  2273. end;
  2274. {$ifdef ARM}
  2275. top_shifterop:
  2276. begin
  2277. new(p.oper[i]^.shifterop);
  2278. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  2279. end;
  2280. {$endif ARM}
  2281. end;
  2282. end;
  2283. getcopy:=p;
  2284. end;
  2285. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  2286. begin
  2287. { When the generic RA is used this needs to be overridden, we don't use
  2288. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  2289. when tai_cpu is created (PFV) }
  2290. internalerror(2004040901);
  2291. result:=false;
  2292. end;
  2293. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  2294. begin
  2295. internalerror(2004040902);
  2296. result:=operand_readwrite;
  2297. end;
  2298. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  2299. begin
  2300. result := operand_read;
  2301. end;
  2302. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2303. var
  2304. i : integer;
  2305. begin
  2306. inherited ppuload(t,ppufile);
  2307. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  2308. ppufile.getdata(condition,sizeof(tasmcond));
  2309. allocate_oper(ppufile.getbyte);
  2310. for i:=0 to ops-1 do
  2311. ppuloadoper(ppufile,oper[i]^);
  2312. opcode:=tasmop(ppufile.getword);
  2313. {$ifdef x86}
  2314. ppufile.getdata(segprefix,sizeof(Tregister));
  2315. {$endif x86}
  2316. is_jmp:=boolean(ppufile.getbyte);
  2317. end;
  2318. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  2319. var
  2320. i : integer;
  2321. begin
  2322. inherited ppuwrite(ppufile);
  2323. ppufile.putdata(condition,sizeof(tasmcond));
  2324. ppufile.putbyte(ops);
  2325. for i:=0 to ops-1 do
  2326. ppuwriteoper(ppufile,oper[i]^);
  2327. ppufile.putword(word(opcode));
  2328. {$ifdef x86}
  2329. ppufile.putdata(segprefix,sizeof(Tregister));
  2330. {$endif x86}
  2331. ppufile.putbyte(byte(is_jmp));
  2332. end;
  2333. procedure tai_cpu_abstract.buildderefimpl;
  2334. var
  2335. i : integer;
  2336. begin
  2337. for i:=0 to ops-1 do
  2338. ppubuildderefimploper(oper[i]^);
  2339. end;
  2340. procedure tai_cpu_abstract.derefimpl;
  2341. var
  2342. i : integer;
  2343. begin
  2344. for i:=0 to ops-1 do
  2345. ppuderefoper(oper[i]^);
  2346. end;
  2347. procedure tai_cpu_abstract.resetpass1;
  2348. begin
  2349. end;
  2350. procedure tai_cpu_abstract.resetpass2;
  2351. begin
  2352. end;
  2353. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  2354. begin
  2355. result:=0;
  2356. end;
  2357. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  2358. begin
  2359. end;
  2360. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  2361. begin
  2362. o.typ:=toptype(ppufile.getbyte);
  2363. o.ot:=ppufile.getlongint;
  2364. case o.typ of
  2365. top_reg :
  2366. ppufile.getdata(o.reg,sizeof(Tregister));
  2367. top_ref :
  2368. begin
  2369. new(o.ref);
  2370. {$ifdef x86}
  2371. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  2372. {$endif x86}
  2373. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  2374. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  2375. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2376. o.ref^.scalefactor:=ppufile.getbyte;
  2377. o.ref^.offset:=ppufile.getaint;
  2378. o.ref^.symbol:=ppufile.getasmsymbol;
  2379. o.ref^.relsymbol:=ppufile.getasmsymbol;
  2380. end;
  2381. top_const :
  2382. o.val:=ppufile.getaint;
  2383. top_local :
  2384. begin
  2385. new(o.localoper);
  2386. with o.localoper^ do
  2387. begin
  2388. ppufile.getderef(localsymderef);
  2389. localsymofs:=ppufile.getaint;
  2390. localindexreg:=tregister(ppufile.getlongint);
  2391. localscale:=ppufile.getbyte;
  2392. localgetoffset:=(ppufile.getbyte<>0);
  2393. end;
  2394. end;
  2395. else
  2396. internalerror(2007010210);
  2397. end;
  2398. end;
  2399. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  2400. begin
  2401. ppufile.putbyte(byte(o.typ));
  2402. ppufile.putlongint(o.ot);
  2403. case o.typ of
  2404. top_reg :
  2405. ppufile.putdata(o.reg,sizeof(Tregister));
  2406. top_ref :
  2407. begin
  2408. {$ifdef x86}
  2409. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  2410. {$endif x86}
  2411. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  2412. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  2413. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2414. ppufile.putbyte(o.ref^.scalefactor);
  2415. ppufile.putaint(o.ref^.offset);
  2416. ppufile.putasmsymbol(o.ref^.symbol);
  2417. ppufile.putasmsymbol(o.ref^.relsymbol);
  2418. end;
  2419. top_const :
  2420. ppufile.putaint(o.val);
  2421. top_local :
  2422. begin
  2423. with o.localoper^ do
  2424. begin
  2425. ppufile.putderef(localsymderef);
  2426. ppufile.putaint(localsymofs);
  2427. ppufile.putlongint(longint(localindexreg));
  2428. ppufile.putbyte(localscale);
  2429. ppufile.putbyte(byte(localgetoffset));
  2430. end;
  2431. end;
  2432. else
  2433. internalerror(2007010211);
  2434. end;
  2435. end;
  2436. {****************************************************************************
  2437. tai_align_abstract
  2438. ****************************************************************************}
  2439. constructor tai_align_abstract.Create(b: byte);
  2440. begin
  2441. inherited Create;
  2442. typ:=ait_align;
  2443. {$ifdef EXTDEBUG}
  2444. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  2445. internalerror(200709191);
  2446. {$endif EXTDEBUG}
  2447. if b in [1,2,4,8,16,32] then
  2448. aligntype := b
  2449. else
  2450. aligntype := 1;
  2451. fillsize:=0;
  2452. fillop:=0;
  2453. use_op:=false;
  2454. end;
  2455. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  2456. begin
  2457. inherited Create;
  2458. typ:=ait_align;
  2459. if b in [1,2,4,8,16,32] then
  2460. aligntype := b
  2461. else
  2462. aligntype := 1;
  2463. fillsize:=0;
  2464. fillop:=_op;
  2465. use_op:=true;
  2466. end;
  2467. constructor tai_align_abstract.Create_zeros(b: byte);
  2468. begin
  2469. inherited Create;
  2470. typ:=ait_align;
  2471. if b in [1,2,4,8,16,32] then
  2472. aligntype := b
  2473. else
  2474. aligntype := 1;
  2475. use_op:=true;
  2476. fillsize:=0;
  2477. fillop:=0;
  2478. end;
  2479. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
  2480. begin
  2481. if fillsize>sizeof(buf) then
  2482. internalerror(200404293);
  2483. fillchar(buf,high(buf),fillop);
  2484. calculatefillbuf:=pchar(@buf);
  2485. end;
  2486. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2487. begin
  2488. inherited ppuload(t,ppufile);
  2489. aligntype:=ppufile.getbyte;
  2490. fillsize:=0;
  2491. fillop:=ppufile.getbyte;
  2492. use_op:=boolean(ppufile.getbyte);
  2493. end;
  2494. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  2495. begin
  2496. inherited ppuwrite(ppufile);
  2497. ppufile.putbyte(aligntype);
  2498. ppufile.putbyte(fillop);
  2499. ppufile.putbyte(byte(use_op));
  2500. end;
  2501. {****************************************************************************
  2502. tai_seh_directive
  2503. ****************************************************************************}
  2504. const
  2505. datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
  2506. sd_string, { proc }
  2507. sd_none, { endproc }
  2508. sd_none, { endprologue }
  2509. sd_string, { handler }
  2510. sd_none, { handlerdata }
  2511. sd_none,sd_none,sd_none, { eh, 32, no32 }
  2512. sd_regoffset, { setframe }
  2513. sd_offset, { stackalloc }
  2514. sd_reg, { pushreg }
  2515. sd_regoffset, { savereg }
  2516. sd_regoffset, { savexmm }
  2517. sd_none { pushframe }
  2518. );
  2519. constructor tai_seh_directive.create(_kind:TAsmSehDirective);
  2520. begin
  2521. inherited Create;
  2522. typ:=ait_seh_directive;
  2523. kind:=_kind;
  2524. data.typ:=datatypemap[_kind];
  2525. end;
  2526. constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
  2527. begin
  2528. create(_kind);
  2529. data.name:=stringdup(_name);
  2530. end;
  2531. constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
  2532. begin
  2533. create(_kind);
  2534. data.reg:=r;
  2535. end;
  2536. constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
  2537. begin
  2538. create(_kind);
  2539. data.offset:=ofs;
  2540. end;
  2541. constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
  2542. r:TRegister;ofs:dword);
  2543. begin
  2544. create(_kind);
  2545. data.offset:=ofs;
  2546. data.reg:=r;
  2547. end;
  2548. constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  2549. begin
  2550. inherited ppuload(t, ppufile);
  2551. kind:=TAsmSehDirective(ppufile.getbyte);
  2552. data.typ:=datatypemap[kind];
  2553. case data.typ of
  2554. sd_none: ;
  2555. sd_string:
  2556. begin
  2557. data.name:=stringdup(ppufile.getstring);
  2558. data.flags:=ppufile.getbyte;
  2559. end;
  2560. sd_reg,sd_offset,sd_regoffset:
  2561. begin
  2562. ppufile.getdata(data.reg,sizeof(TRegister));
  2563. data.offset:=ppufile.getdword;
  2564. end;
  2565. else
  2566. InternalError(2011091201);
  2567. end;
  2568. end;
  2569. destructor tai_seh_directive.destroy;
  2570. begin
  2571. if data.typ=sd_string then
  2572. stringdispose(data.name);
  2573. inherited destroy;
  2574. end;
  2575. procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
  2576. begin
  2577. inherited ppuwrite(ppufile);
  2578. ppufile.putbyte(ord(kind));
  2579. case data.typ of
  2580. sd_none: ;
  2581. sd_string:
  2582. begin
  2583. ppufile.putstring(data.name^);
  2584. ppufile.putbyte(data.flags);
  2585. end;
  2586. sd_reg,sd_offset,sd_regoffset:
  2587. begin
  2588. ppufile.putdata(data.reg,sizeof(TRegister));
  2589. ppufile.putdword(data.offset);
  2590. end;
  2591. else
  2592. InternalError(2011091202);
  2593. end;
  2594. end;
  2595. procedure tai_seh_directive.generate_code(objdata:TObjData);
  2596. begin
  2597. end;
  2598. {$ifdef JVM}
  2599. {****************************************************************************
  2600. tai_jvar
  2601. ****************************************************************************}
  2602. constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  2603. begin
  2604. Inherited create;
  2605. typ:=ait_jvar;
  2606. stackslot:=_stackslot;
  2607. desc:=stringdup(_desc);
  2608. startlab:=_startlab;
  2609. stoplab:=_stoplab;
  2610. end;
  2611. constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
  2612. begin
  2613. inherited ppuload(t, ppufile);
  2614. stackslot:=ppufile.getlongint;
  2615. desc:=stringdup(ppufile.getstring);
  2616. startlab:=ppufile.getasmsymbol;
  2617. stoplab:=ppufile.getasmsymbol;
  2618. end;
  2619. procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
  2620. begin
  2621. inherited ppuwrite(ppufile);
  2622. ppufile.putlongint(stackslot);
  2623. ppufile.putstring(desc^);
  2624. ppufile.putasmsymbol(startlab);
  2625. ppufile.putasmsymbol(stoplab);
  2626. end;
  2627. destructor tai_jvar.destroy;
  2628. begin
  2629. stringdispose(desc);
  2630. inherited destroy;
  2631. end;
  2632. {****************************************************************************
  2633. tai_jcatch
  2634. ****************************************************************************}
  2635. constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  2636. begin
  2637. Inherited create;
  2638. typ:=ait_jcatch;
  2639. name:=stringdup(_name);
  2640. startlab:=_startlab;
  2641. startlab.increfs;
  2642. stoplab:=_stoplab;
  2643. stoplab.increfs;
  2644. handlerlab:=_handlerlab;
  2645. handlerlab.increfs;
  2646. end;
  2647. destructor tai_jcatch.destroy;
  2648. begin
  2649. stringdispose(name);
  2650. inherited destroy;
  2651. end;
  2652. constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
  2653. begin
  2654. inherited ppuload(t, ppufile);
  2655. name:=stringdup(ppufile.getstring);
  2656. startlab:=ppufile.getasmsymbol;
  2657. startlab.increfs;
  2658. stoplab:=ppufile.getasmsymbol;
  2659. stoplab.increfs;
  2660. handlerlab:=ppufile.getasmsymbol;
  2661. handlerlab.increfs;
  2662. end;
  2663. procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
  2664. begin
  2665. inherited ppuwrite(ppufile);
  2666. ppufile.putstring(name^);
  2667. ppufile.putasmsymbol(startlab);
  2668. ppufile.putasmsymbol(stoplab);
  2669. ppufile.putasmsymbol(handlerlab);
  2670. end;
  2671. {$endif JVM}
  2672. begin
  2673. {$push}{$warnings off}
  2674. { taitype should fit into a 4 byte set for speed reasons }
  2675. if ord(high(taitype))>31 then
  2676. internalerror(201108181);
  2677. {$pop}
  2678. end.