aasmtai.pas 92 KB

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