aasmtai.pas 91 KB

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