aasmtai.pas 93 KB

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