aasmtai.pas 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122
  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 Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
  531. constructor Create_nil_codeptr;
  532. constructor Create_nil_dataptr;
  533. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  534. procedure ppuwrite(ppufile:tcompilerppufile);override;
  535. procedure derefimpl;override;
  536. function getcopy:tlinkedlistitem;override;
  537. function size:longint;
  538. end;
  539. { Generates a single float (32 bit real) }
  540. tai_real_32bit = class(tai)
  541. value : ts32real;
  542. constructor Create(_value : ts32real);
  543. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  544. procedure ppuwrite(ppufile:tcompilerppufile);override;
  545. end;
  546. tformatoptions = (fo_none,fo_hiloswapped);
  547. { Generates a double float (64 bit real) }
  548. tai_real_64bit = class(tai)
  549. value : ts64real;
  550. {$ifdef ARM}
  551. formatoptions : tformatoptions;
  552. constructor Create_hiloswapped(_value : ts64real);
  553. {$endif ARM}
  554. constructor Create(_value : ts64real);
  555. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  556. procedure ppuwrite(ppufile:tcompilerppufile);override;
  557. end;
  558. { Generates an extended float (80 bit real) }
  559. tai_real_80bit = class(tai)
  560. value : ts80real;
  561. savesize : byte;
  562. constructor Create(_value : ts80real; _savesize: byte);
  563. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  564. procedure ppuwrite(ppufile:tcompilerppufile);override;
  565. end;
  566. { Generates an float128 (128 bit real) }
  567. tai_real_128bit = class(tai)
  568. value : ts128real;
  569. constructor Create(_value : ts128real);
  570. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  571. procedure ppuwrite(ppufile:tcompilerppufile);override;
  572. end;
  573. { Generates a comp int (integer over 64 bits)
  574. This is Intel 80x86 specific, and is not
  575. really supported on other processors.
  576. }
  577. tai_comp_64bit = class(tai)
  578. value : ts64comp;
  579. constructor Create(_value : ts64comp);
  580. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  581. procedure ppuwrite(ppufile:tcompilerppufile);override;
  582. end;
  583. { tai_stab }
  584. tai_stab = class(tai)
  585. str : pchar;
  586. stabtype : TStabType;
  587. constructor Create(_stabtype:TStabType;_str : pchar);
  588. constructor Create_str(_stabtype:TStabType;const s:string);
  589. constructor create_ansistr(_stabtype: TStabType; const s: ansistring);
  590. destructor Destroy;override;
  591. end;
  592. tai_force_line = class(tailineinfo)
  593. constructor Create;
  594. end;
  595. tai_function_name = class(tai)
  596. funcname : pshortstring;
  597. constructor create(const s:string);
  598. destructor destroy;override;
  599. end;
  600. { Insert a cut to split assembler into several smaller files }
  601. tai_cutobject = class(tai)
  602. place : tcutplace;
  603. constructor Create;
  604. constructor Create_begin;
  605. constructor Create_end;
  606. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  607. procedure ppuwrite(ppufile:tcompilerppufile);override;
  608. end;
  609. { Insert a marker for assembler and inline blocks }
  610. tai_marker = class(tai)
  611. Kind: TAsmMarker;
  612. Constructor Create(_Kind: TAsmMarker);
  613. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  614. procedure ppuwrite(ppufile:tcompilerppufile);override;
  615. end;
  616. tai_tempalloc = class(tai)
  617. allocation : boolean;
  618. {$ifdef EXTDEBUG}
  619. problem : pshortstring;
  620. {$endif EXTDEBUG}
  621. temppos,
  622. tempsize : longint;
  623. constructor alloc(pos,size:longint);
  624. constructor dealloc(pos,size:longint);
  625. {$ifdef EXTDEBUG}
  626. constructor allocinfo(pos,size:longint;const st:string);
  627. {$endif EXTDEBUG}
  628. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  629. destructor destroy;override;
  630. procedure ppuwrite(ppufile:tcompilerppufile);override;
  631. end;
  632. tai_regalloc = class(tai)
  633. reg : tregister;
  634. ratype : TRegAllocType;
  635. { tells BuildLabelTableAndFixRegAlloc that the deallocation should be kept }
  636. keep : boolean;
  637. { reg(de)alloc belongs to this instruction, this
  638. is only used for automatic inserted (de)alloc for
  639. imaginary register and required for spilling code }
  640. instr : tai;
  641. constructor alloc(r : tregister;ainstr:tai);
  642. constructor dealloc(r : tregister;ainstr:tai);
  643. constructor sync(r : tregister);
  644. constructor resize(r : tregister);
  645. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  646. procedure ppuwrite(ppufile:tcompilerppufile);override;
  647. end;
  648. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  649. { Class template for assembler instructions
  650. }
  651. tai_cpu_abstract = class(tailineinfo)
  652. protected
  653. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
  654. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
  655. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  656. procedure ppuderefoper(var o:toper);virtual;abstract;
  657. public
  658. { Condition flags for instruction }
  659. condition : TAsmCond;
  660. { Number of operands to instruction }
  661. ops : byte;
  662. { Number of allocate oper structures }
  663. opercnt : byte;
  664. { Operands of instruction }
  665. oper : array[0..max_operands-1] of poper;
  666. { Actual opcode of instruction }
  667. opcode : tasmop;
  668. {$ifdef x86}
  669. segprefix : tregister;
  670. {$endif x86}
  671. { true if instruction is a jmp }
  672. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  673. Constructor Create(op : tasmop);virtual;
  674. Destructor Destroy;override;
  675. function getcopy:TLinkedListItem;override;
  676. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  677. procedure ppuwrite(ppufile:tcompilerppufile);override;
  678. procedure buildderefimpl;override;
  679. procedure derefimpl;override;
  680. procedure SetCondition(const c:TAsmCond);
  681. procedure allocate_oper(opers:longint);
  682. procedure loadconst(opidx:longint;l:aint);
  683. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  684. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  685. procedure loadref(opidx:longint;const r:treference);
  686. procedure loadreg(opidx:longint;r:tregister);
  687. procedure loadoper(opidx:longint;o:toper);
  688. procedure clearop(opidx:longint);
  689. procedure freeop(opidx:longint);
  690. { register allocator }
  691. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  692. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  693. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  694. function Pass1(objdata:TObjData):longint;virtual;
  695. procedure Pass2(objdata:TObjData);virtual;
  696. procedure resetpass1; virtual;
  697. procedure resetpass2; virtual;
  698. end;
  699. tai_cpu_class = class of tai_cpu_abstract;
  700. { Buffer type used for alignment }
  701. tfillbuffer = array[0..63] of char;
  702. { alignment for operator }
  703. tai_align_abstract = class(tai)
  704. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  705. fillsize : byte; { real size to fill }
  706. fillop : byte; { value to fill with - optional }
  707. use_op : boolean;
  708. constructor Create(b:byte);virtual;
  709. constructor Create_op(b: byte; _op: byte);virtual;
  710. constructor Create_zeros(b:byte);
  711. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  712. procedure ppuwrite(ppufile:tcompilerppufile);override;
  713. function calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;virtual;
  714. end;
  715. tai_align_class = class of tai_align_abstract;
  716. tai_varloc = class(tai)
  717. oldlocation,
  718. oldlocationhi,
  719. newlocation,
  720. newlocationhi : tregister;
  721. varsym : tsym;
  722. constructor create(sym : tsym;loc : tregister);
  723. constructor create64(sym : tsym;loc,lochi : tregister);
  724. {$ifdef cpu64bitalu}
  725. constructor create128(sym : tsym;loc,lochi : tregister);
  726. {$endif cpu64bitalu}
  727. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  728. procedure ppuwrite(ppufile:tcompilerppufile);override;
  729. procedure buildderefimpl;override;
  730. procedure derefimpl;override;
  731. end;
  732. TSehDirectiveDatatype=(sd_none,sd_string,sd_reg,sd_offset,sd_regoffset);
  733. TSehDirectiveData=record
  734. case typ: TSehDirectiveDatatype of
  735. sd_none: ();
  736. sd_string: (name:pshortstring;flags:byte);
  737. sd_reg,sd_offset,sd_regoffset: (reg:TRegister;offset:dword);
  738. end;
  739. tai_seh_directive = class(tai)
  740. kind: TAsmSehDirective;
  741. data: TSehDirectiveData;
  742. constructor create(_kind:TAsmSehDirective);
  743. constructor create_name(_kind:TAsmSehDirective;const _name: string);
  744. constructor create_reg(_kind:TAsmSehDirective;r:TRegister);
  745. constructor create_offset(_kind:TAsmSehDirective;ofs:dword);
  746. constructor create_reg_offset(_kind:TAsmSehDirective;r:TRegister;ofs:dword);
  747. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  748. destructor destroy;override;
  749. procedure ppuwrite(ppufile:tcompilerppufile);override;
  750. procedure generate_code(objdata:TObjData);virtual;
  751. property datatype: TSehDirectiveDatatype read data.typ;
  752. end;
  753. tai_seh_directive_class=class of tai_seh_directive;
  754. {$ifdef JVM}
  755. { JVM variable live range description }
  756. tai_jvar = class(tai)
  757. stackslot: longint;
  758. desc: pshortstring;
  759. startlab,stoplab: tasmsymbol;
  760. constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  761. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  762. procedure ppuwrite(ppufile:tcompilerppufile);override;
  763. destructor destroy;override;
  764. end;
  765. tai_jvar_class = class of tai_jvar;
  766. { JVM exception catch description }
  767. tai_jcatch = class(tai)
  768. name: pshortstring;
  769. startlab,stoplab,handlerlab: tasmsymbol;
  770. constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  771. destructor destroy;override;
  772. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  773. procedure ppuwrite(ppufile:tcompilerppufile);override;
  774. end;
  775. tai_jcatch_class = class of tai_jcatch;
  776. {$endif JVM}
  777. tai_set = class(tai)
  778. sym,
  779. value: pshortstring;
  780. constructor create(const asym, avalue: string);
  781. destructor destroy;override;
  782. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  783. procedure ppuwrite(ppufile:tcompilerppufile);override;
  784. end;
  785. {$ifdef arm}
  786. tai_thumb_set = class(tai_set)
  787. constructor create(const asym, avalue: string);
  788. end;
  789. {$endif arm}
  790. tai_weak = class(tai)
  791. sym: pshortstring;
  792. constructor create(const asym: string);
  793. destructor destroy;override;
  794. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  795. procedure ppuwrite(ppufile:tcompilerppufile);override;
  796. end;
  797. var
  798. { array with all class types for tais }
  799. aiclass : taiclassarray;
  800. { target specific tais, possibly overwritten in target specific aasmcpu }
  801. cai_align : tai_align_class = tai_align_abstract;
  802. cai_cpu : tai_cpu_class = tai_cpu_abstract;
  803. cai_seh_directive: tai_seh_directive_class = tai_seh_directive;
  804. { hook to notify uses of registers }
  805. add_reg_instruction_hook : tadd_reg_instruction_proc;
  806. procedure maybe_new_object_file(list:TAsmList);
  807. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  808. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  809. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  810. procedure section_symbol_end(list:TAsmList;const Aname:string);
  811. function ppuloadai(ppufile:tcompilerppufile):tai;
  812. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  813. implementation
  814. uses
  815. SysUtils,
  816. verbose,
  817. globals;
  818. const
  819. pputaimarker = 254;
  820. {****************************************************************************
  821. Helpers
  822. ****************************************************************************}
  823. procedure maybe_new_object_file(list:TAsmList);
  824. begin
  825. if create_smartlink_library then
  826. list.concat(tai_cutobject.create);
  827. end;
  828. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  829. begin
  830. list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
  831. list.concat(cai_align.create(Aalign));
  832. end;
  833. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  834. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  835. begin
  836. maybe_new_object_file(list);
  837. new_section(list,Asectype,Aname,Aalign);
  838. if Aglobal or
  839. create_smartlink then
  840. list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
  841. else
  842. list.concat(tai_symbol.createname(Aname,Asymtyp,0));
  843. end;
  844. procedure section_symbol_end(list:TAsmList;const Aname:string);
  845. begin
  846. list.concat(tai_symbol_end.createname(Aname));
  847. end;
  848. function ppuloadai(ppufile:tcompilerppufile):tai;
  849. var
  850. b : byte;
  851. t : taitype;
  852. begin
  853. { marker }
  854. b:=ppufile.getbyte;
  855. if b<>pputaimarker then
  856. internalerror(200208181);
  857. { load nodetype }
  858. t:=taitype(ppufile.getbyte);
  859. if t<>ait_none then
  860. begin
  861. if t>high(taitype) then
  862. internalerror(200208182);
  863. if not assigned(aiclass[t]) then
  864. internalerror(200208183);
  865. {writeln('taiload: ',taitypestr[t]);}
  866. { generate tai of the correct class }
  867. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  868. end
  869. else
  870. ppuloadai:=nil;
  871. end;
  872. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  873. begin
  874. { marker, read by ppuloadnode }
  875. ppufile.putbyte(pputaimarker);
  876. if assigned(n) then
  877. begin
  878. { type, read by ppuloadnode }
  879. ppufile.putbyte(byte(n.typ));
  880. {writeln('taiwrite: ',taitypestr[n.typ]);}
  881. n.ppuwrite(ppufile);
  882. end
  883. else
  884. ppufile.putbyte(byte(ait_none));
  885. end;
  886. constructor tai_weak.create(const asym: string);
  887. begin
  888. inherited create;
  889. typ:=ait_weak;
  890. sym:=stringdup(asym);
  891. end;
  892. destructor tai_weak.destroy;
  893. begin
  894. stringdispose(sym);
  895. inherited destroy;
  896. end;
  897. constructor tai_weak.ppuload(t: taitype; ppufile: tcompilerppufile);
  898. begin
  899. inherited ppuload(t,ppufile);
  900. sym:=stringdup(ppufile.getstring);
  901. end;
  902. procedure tai_weak.ppuwrite(ppufile: tcompilerppufile);
  903. begin
  904. inherited ppuwrite(ppufile);
  905. ppufile.putstring(sym^);
  906. end;
  907. {$ifdef arm}
  908. constructor tai_thumb_set.create(const asym, avalue: string);
  909. begin
  910. inherited create(asym, avalue);
  911. typ:=ait_thumb_set;
  912. end;
  913. {$endif arm}
  914. constructor tai_set.create(const asym, avalue: string);
  915. begin
  916. inherited create;
  917. typ:=ait_set;
  918. sym:=stringdup(asym);
  919. value:=stringdup(avalue);
  920. end;
  921. destructor tai_set.destroy;
  922. begin
  923. stringdispose(sym);
  924. stringdispose(value);
  925. inherited destroy;
  926. end;
  927. constructor tai_set.ppuload(t: taitype; ppufile: tcompilerppufile);
  928. begin
  929. inherited ppuload(t,ppufile);
  930. sym:=stringdup(ppufile.getstring);
  931. value:=stringdup(ppufile.getstring);
  932. end;
  933. procedure tai_set.ppuwrite(ppufile: tcompilerppufile);
  934. begin
  935. inherited ppuwrite(ppufile);
  936. ppufile.putstring(sym^);
  937. ppufile.putstring(value^);
  938. end;
  939. constructor tai_varloc.create(sym: tsym; loc: tregister);
  940. begin
  941. inherited Create;
  942. typ:=ait_varloc;
  943. newlocation:=loc;
  944. newlocationhi:=NR_NO;
  945. varsym:=sym;
  946. oldlocationhi:=NR_NO;
  947. end;
  948. constructor tai_varloc.create64(sym: tsym; loc, lochi: tregister);
  949. begin
  950. inherited Create;
  951. typ:=ait_varloc;
  952. newlocation:=loc;
  953. newlocationhi:=lochi;
  954. varsym:=sym;
  955. end;
  956. {$ifdef cpu64bitalu}
  957. constructor tai_varloc.create128(sym: tsym; loc, lochi: tregister);
  958. begin
  959. inherited Create;
  960. typ:=ait_varloc;
  961. newlocation:=loc;
  962. newlocationhi:=lochi;
  963. varsym:=sym;
  964. end;
  965. {$endif cpu64bitalu}
  966. constructor tai_varloc.ppuload(t: taitype; ppufile: tcompilerppufile);
  967. begin
  968. inherited ppuload(t, ppufile);
  969. end;
  970. procedure tai_varloc.ppuwrite(ppufile: tcompilerppufile);
  971. begin
  972. inherited ppuwrite(ppufile);
  973. end;
  974. procedure tai_varloc.buildderefimpl;
  975. begin
  976. inherited buildderefimpl;
  977. end;
  978. procedure tai_varloc.derefimpl;
  979. begin
  980. inherited derefimpl;
  981. end;
  982. {****************************************************************************
  983. TAI
  984. ****************************************************************************}
  985. constructor tai.Create;
  986. begin
  987. {$ifndef NOOPT}
  988. optinfo:=nil;
  989. {$endif NOOPT}
  990. end;
  991. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  992. begin
  993. typ:=t;
  994. {$ifndef NOOPT}
  995. optinfo:=nil;
  996. {$endif}
  997. end;
  998. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  999. begin
  1000. end;
  1001. procedure tai.buildderefimpl;
  1002. begin
  1003. end;
  1004. procedure tai.derefimpl;
  1005. begin
  1006. end;
  1007. {****************************************************************************
  1008. TAILINEINFO
  1009. ****************************************************************************}
  1010. constructor tailineinfo.create;
  1011. begin
  1012. inherited create;
  1013. fileinfo:=current_filepos;
  1014. end;
  1015. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  1016. begin
  1017. inherited ppuload(t,ppufile);
  1018. ppufile.getposinfo(fileinfo);
  1019. end;
  1020. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  1021. begin
  1022. inherited ppuwrite(ppufile);
  1023. ppufile.putposinfo(fileinfo);
  1024. end;
  1025. {****************************************************************************
  1026. TAI_SIMPLE
  1027. ****************************************************************************}
  1028. constructor tai_simple.create(_typ : taitype);
  1029. begin
  1030. inherited create;
  1031. typ:=_typ;
  1032. end;
  1033. {****************************************************************************
  1034. TAI_SECTION
  1035. ****************************************************************************}
  1036. constructor tai_section.Create(Asectype:TAsmSectiontype;const Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  1037. begin
  1038. inherited Create;
  1039. typ:=ait_section;
  1040. sectype:=asectype;
  1041. secalign:=Aalign;
  1042. secorder:=Asecorder;
  1043. name:=stringdup(Aname);
  1044. sec:=nil;
  1045. end;
  1046. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  1047. begin
  1048. inherited ppuload(t,ppufile);
  1049. sectype:=TAsmSectiontype(ppufile.getbyte);
  1050. secalign:=ppufile.getbyte;
  1051. name:=stringdup(ppufile.getstring);
  1052. sec:=nil;
  1053. end;
  1054. destructor tai_section.Destroy;
  1055. begin
  1056. stringdispose(name);
  1057. end;
  1058. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  1059. begin
  1060. inherited ppuwrite(ppufile);
  1061. ppufile.putbyte(byte(sectype));
  1062. ppufile.putbyte(secalign);
  1063. ppufile.putstring(name^);
  1064. end;
  1065. {****************************************************************************
  1066. TAI_DATABLOCK
  1067. ****************************************************************************}
  1068. constructor tai_datablock.Create(const _name : string;_size : aint);
  1069. begin
  1070. inherited Create;
  1071. typ:=ait_datablock;
  1072. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
  1073. { keep things aligned }
  1074. if _size<=0 then
  1075. _size:=sizeof(aint);
  1076. size:=_size;
  1077. is_global:=false;
  1078. end;
  1079. constructor tai_datablock.Create_global(const _name : string;_size : asizeint);
  1080. begin
  1081. inherited Create;
  1082. typ:=ait_datablock;
  1083. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
  1084. { keep things aligned }
  1085. if _size<=0 then
  1086. _size:=sizeof(aint);
  1087. size:=_size;
  1088. is_global:=true;
  1089. end;
  1090. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  1091. begin
  1092. inherited Create;
  1093. sym:=ppufile.getasmsymbol;
  1094. size:=ppufile.getaint;
  1095. is_global:=boolean(ppufile.getbyte);
  1096. end;
  1097. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  1098. begin
  1099. inherited ppuwrite(ppufile);
  1100. ppufile.putasmsymbol(sym);
  1101. ppufile.putaint(size);
  1102. ppufile.putbyte(byte(is_global));
  1103. end;
  1104. procedure tai_datablock.derefimpl;
  1105. begin
  1106. end;
  1107. {****************************************************************************
  1108. TAI_SYMBOL
  1109. ****************************************************************************}
  1110. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  1111. begin
  1112. inherited Create;
  1113. typ:=ait_symbol;
  1114. sym:=_sym;
  1115. size:=siz;
  1116. sym.bind:=AB_LOCAL;
  1117. is_global:=false;
  1118. end;
  1119. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  1120. begin
  1121. inherited Create;
  1122. typ:=ait_symbol;
  1123. sym:=_sym;
  1124. size:=siz;
  1125. { don't override PRIVATE_EXTERN with GLOBAL }
  1126. if not(sym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]) then
  1127. sym.bind:=AB_GLOBAL;
  1128. is_global:=true;
  1129. end;
  1130. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  1131. begin
  1132. inherited Create;
  1133. typ:=ait_symbol;
  1134. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
  1135. size:=siz;
  1136. is_global:=false;
  1137. end;
  1138. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  1139. begin
  1140. inherited Create;
  1141. typ:=ait_symbol;
  1142. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
  1143. size:=siz;
  1144. is_global:=true;
  1145. end;
  1146. constructor tai_symbol.createname_global_value(const _name: string;_symtyp: tasmsymtype; siz: longint; val: ptruint);
  1147. begin
  1148. Createname_global(_name,_symtyp,siz);
  1149. value:=val;
  1150. has_value:=true;
  1151. end;
  1152. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  1153. begin
  1154. inherited ppuload(t,ppufile);
  1155. sym:=ppufile.getasmsymbol;
  1156. size:=ppufile.getlongint;
  1157. is_global:=boolean(ppufile.getbyte);
  1158. end;
  1159. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  1160. begin
  1161. inherited ppuwrite(ppufile);
  1162. ppufile.putasmsymbol(sym);
  1163. ppufile.putlongint(size);
  1164. ppufile.putbyte(byte(is_global));
  1165. end;
  1166. procedure tai_symbol.derefimpl;
  1167. begin
  1168. end;
  1169. {****************************************************************************
  1170. TAI_SYMBOL_END
  1171. ****************************************************************************}
  1172. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  1173. begin
  1174. inherited Create;
  1175. typ:=ait_symbol_end;
  1176. sym:=_sym;
  1177. end;
  1178. constructor tai_symbol_end.Createname(const _name : string);
  1179. begin
  1180. inherited Create;
  1181. typ:=ait_symbol_end;
  1182. sym:=current_asmdata.GetAsmSymbol(_name);
  1183. if not assigned(sym) then
  1184. internalerror(2013080301);
  1185. end;
  1186. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  1187. begin
  1188. inherited ppuload(t,ppufile);
  1189. sym:=ppufile.getasmsymbol;
  1190. end;
  1191. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  1192. begin
  1193. inherited ppuwrite(ppufile);
  1194. ppufile.putasmsymbol(sym);
  1195. end;
  1196. procedure tai_symbol_end.derefimpl;
  1197. begin
  1198. end;
  1199. {****************************************************************************
  1200. TAI_SYMBOL_END
  1201. ****************************************************************************}
  1202. constructor tai_directive.Create(_directive:TAsmDirective;const _name:ansistring);
  1203. begin
  1204. inherited Create;
  1205. typ:=ait_directive;
  1206. name:=_name;
  1207. directive:=_directive;
  1208. end;
  1209. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  1210. begin
  1211. inherited ppuload(t,ppufile);
  1212. name:=ppufile.getansistring;
  1213. directive:=TAsmDirective(ppufile.getbyte);
  1214. end;
  1215. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  1216. begin
  1217. inherited ppuwrite(ppufile);
  1218. ppufile.putansistring(name);
  1219. ppufile.putbyte(byte(directive));
  1220. end;
  1221. {****************************************************************************
  1222. TAI_ENT / TAI_ENT_END
  1223. ****************************************************************************}
  1224. Constructor tai_ent.Create (const ProcName : String);
  1225. begin
  1226. Inherited Create;
  1227. Name:=ProcName;
  1228. typ:=ait_ent;
  1229. end;
  1230. Constructor tai_ent_end.Create (const ProcName : String);
  1231. begin
  1232. Inherited Create;
  1233. Name:=ProcName;
  1234. typ:=ait_ent_end;
  1235. end;
  1236. {****************************************************************************
  1237. TAI_CONST
  1238. ****************************************************************************}
  1239. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  1240. begin
  1241. inherited Create;
  1242. typ:=ait_const;
  1243. consttype:=_typ;
  1244. value:=_value;
  1245. sym:=nil;
  1246. endsym:=nil;
  1247. end;
  1248. constructor tai_const.Create_128bit(_value : int64);
  1249. begin
  1250. inherited Create;
  1251. typ:=ait_const;
  1252. consttype:=aitconst_128bit;
  1253. value:=_value;
  1254. sym:=nil;
  1255. endsym:=nil;
  1256. end;
  1257. constructor tai_const.Create_64bit(_value : int64);
  1258. begin
  1259. inherited Create;
  1260. typ:=ait_const;
  1261. consttype:=aitconst_64bit;
  1262. value:=_value;
  1263. sym:=nil;
  1264. endsym:=nil;
  1265. end;
  1266. constructor tai_const.Create_32bit(_value : longint);
  1267. begin
  1268. inherited Create;
  1269. typ:=ait_const;
  1270. consttype:=aitconst_32bit;
  1271. value:=_value;
  1272. sym:=nil;
  1273. endsym:=nil;
  1274. end;
  1275. constructor tai_const.Create_16bit(_value : word);
  1276. begin
  1277. inherited Create;
  1278. typ:=ait_const;
  1279. consttype:=aitconst_16bit;
  1280. value:=_value;
  1281. sym:=nil;
  1282. endsym:=nil;
  1283. end;
  1284. constructor tai_const.Create_64bit_unaligned(_value : int64);
  1285. begin
  1286. inherited Create;
  1287. typ:=ait_const;
  1288. consttype:=aitconst_64bit_unaligned;
  1289. value:=_value;
  1290. sym:=nil;
  1291. endsym:=nil;
  1292. end;
  1293. constructor tai_const.Create_32bit_unaligned(_value : longint);
  1294. begin
  1295. inherited Create;
  1296. typ:=ait_const;
  1297. consttype:=aitconst_32bit_unaligned;
  1298. value:=_value;
  1299. sym:=nil;
  1300. endsym:=nil;
  1301. end;
  1302. constructor tai_const.Create_16bit_unaligned(_value : word);
  1303. begin
  1304. inherited Create;
  1305. typ:=ait_const;
  1306. consttype:=aitconst_16bit_unaligned;
  1307. value:=_value;
  1308. sym:=nil;
  1309. endsym:=nil;
  1310. end;
  1311. constructor tai_const.Create_8bit(_value : byte);
  1312. begin
  1313. inherited Create;
  1314. typ:=ait_const;
  1315. consttype:=aitconst_8bit;
  1316. value:=_value;
  1317. sym:=nil;
  1318. endsym:=nil;
  1319. end;
  1320. constructor tai_const.Create_char(size: integer; _value: dword);
  1321. begin
  1322. inherited Create;
  1323. typ:=ait_const;
  1324. case size of
  1325. 1:
  1326. begin
  1327. consttype:=aitconst_8bit;
  1328. value:=byte(_value)
  1329. end;
  1330. 2:
  1331. begin
  1332. consttype:=aitconst_16bit;
  1333. value:=word(_value)
  1334. end
  1335. else
  1336. InternalError(2010030701)
  1337. end
  1338. end;
  1339. constructor tai_const.Create_sleb128bit(_value : int64);
  1340. begin
  1341. inherited Create;
  1342. typ:=ait_const;
  1343. consttype:=aitconst_sleb128bit;
  1344. value:=_value;
  1345. sym:=nil;
  1346. endsym:=nil;
  1347. end;
  1348. constructor tai_const.Create_uleb128bit(_value : qword);
  1349. begin
  1350. inherited Create;
  1351. typ:=ait_const;
  1352. consttype:=aitconst_uleb128bit;
  1353. value:=int64(_value);
  1354. sym:=nil;
  1355. endsym:=nil;
  1356. end;
  1357. constructor tai_const.Create_aint(_value : aint);
  1358. begin
  1359. inherited Create;
  1360. typ:=ait_const;
  1361. consttype:=aitconst_aint;
  1362. value:=_value;
  1363. sym:=nil;
  1364. endsym:=nil;
  1365. end;
  1366. constructor tai_const.Create_pint(_value : pint);
  1367. begin
  1368. inherited Create;
  1369. typ:=ait_const;
  1370. consttype:=aitconst_ptr;
  1371. value:=_value;
  1372. sym:=nil;
  1373. endsym:=nil;
  1374. end;
  1375. constructor tai_const.Create_pint_unaligned(_value: pint);
  1376. begin
  1377. inherited Create;
  1378. typ:=ait_const;
  1379. consttype:=aitconst_ptr_unaligned;
  1380. value:=_value;
  1381. sym:=nil;
  1382. endsym:=nil;
  1383. end;
  1384. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  1385. begin
  1386. inherited Create;
  1387. typ:=ait_const;
  1388. consttype:=_typ;
  1389. sym:=_sym;
  1390. endsym:=nil;
  1391. value:=0;
  1392. { update sym info }
  1393. if assigned(sym) then
  1394. sym.increfs;
  1395. end;
  1396. constructor tai_const.Create_sym(_sym:tasmsymbol);
  1397. begin
  1398. self.create_sym_offset(_sym,0);
  1399. end;
  1400. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  1401. begin
  1402. inherited Create;
  1403. typ:=ait_const;
  1404. {$ifdef i8086}
  1405. if assigned(_sym) and (_sym.typ=AT_DATA) then
  1406. begin
  1407. if current_settings.x86memorymodel in x86_far_data_models then
  1408. consttype:=aitconst_farptr
  1409. else
  1410. consttype:=aitconst_ptr;
  1411. end
  1412. else
  1413. begin
  1414. if current_settings.x86memorymodel in x86_far_code_models then
  1415. consttype:=aitconst_farptr
  1416. else
  1417. consttype:=aitconst_ptr;
  1418. end;
  1419. {$else i8086}
  1420. consttype:=aitconst_ptr;
  1421. {$endif i8086}
  1422. { sym is allowed to be nil, this is used to write nil pointers }
  1423. sym:=_sym;
  1424. endsym:=nil;
  1425. { store the original offset in symofs so that we can recalculate the
  1426. value field in the assembler }
  1427. symofs:=ofs;
  1428. value:=ofs;
  1429. { update sym info }
  1430. if assigned(sym) then
  1431. sym.increfs;
  1432. end;
  1433. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  1434. begin
  1435. self.create_sym_offset(_sym,0);
  1436. consttype:=_typ;
  1437. endsym:=_endsym;
  1438. endsym.increfs;
  1439. end;
  1440. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  1441. begin
  1442. self.create_sym_offset(_sym,0);
  1443. consttype:=aitconst_rva_symbol;
  1444. end;
  1445. constructor tai_const.Createname(const name:string;ofs:aint);
  1446. begin
  1447. self.create_sym_offset(current_asmdata.RefAsmSymbol(name),ofs);
  1448. end;
  1449. constructor tai_const.Create_type_name(_typ:taiconst_type;const name:string;ofs:aint);
  1450. begin
  1451. self.create_sym_offset(current_asmdata.RefAsmSymbol(name),ofs);
  1452. consttype:=_typ;
  1453. end;
  1454. constructor tai_const.Create_nil_codeptr;
  1455. begin
  1456. inherited Create;
  1457. typ:=ait_const;
  1458. {$ifdef i8086}
  1459. if current_settings.x86memorymodel in x86_far_code_models then
  1460. consttype:=aitconst_farptr
  1461. else
  1462. {$endif i8086}
  1463. consttype:=aitconst_ptr;
  1464. sym:=nil;
  1465. endsym:=nil;
  1466. symofs:=0;
  1467. value:=0;
  1468. end;
  1469. constructor tai_const.Create_nil_dataptr;
  1470. begin
  1471. inherited Create;
  1472. typ:=ait_const;
  1473. {$ifdef i8086}
  1474. if current_settings.x86memorymodel in x86_far_data_models then
  1475. consttype:=aitconst_farptr
  1476. else
  1477. {$endif i8086}
  1478. consttype:=aitconst_ptr;
  1479. sym:=nil;
  1480. endsym:=nil;
  1481. symofs:=0;
  1482. value:=0;
  1483. end;
  1484. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1485. begin
  1486. inherited ppuload(t,ppufile);
  1487. consttype:=taiconst_type(ppufile.getbyte);
  1488. sym:=ppufile.getasmsymbol;
  1489. endsym:=ppufile.getasmsymbol;
  1490. value:=ppufile.getint64;
  1491. end;
  1492. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1493. begin
  1494. inherited ppuwrite(ppufile);
  1495. ppufile.putbyte(byte(consttype));
  1496. ppufile.putasmsymbol(sym);
  1497. ppufile.putasmsymbol(endsym);
  1498. ppufile.putint64(value);
  1499. end;
  1500. procedure tai_const.derefimpl;
  1501. begin
  1502. end;
  1503. function tai_const.getcopy:tlinkedlistitem;
  1504. begin
  1505. getcopy:=inherited getcopy;
  1506. { we need to increase the reference number }
  1507. if assigned(sym) then
  1508. sym.increfs;
  1509. if assigned(endsym) then
  1510. endsym.increfs;
  1511. end;
  1512. function tai_const.size:longint;
  1513. begin
  1514. case consttype of
  1515. aitconst_8bit :
  1516. result:=1;
  1517. aitconst_16bit,aitconst_16bit_unaligned :
  1518. result:=2;
  1519. aitconst_32bit,aitconst_darwin_dwarf_delta32,
  1520. aitconst_32bit_unaligned:
  1521. result:=4;
  1522. aitconst_64bit,aitconst_darwin_dwarf_delta64,
  1523. aitconst_64bit_unaligned:
  1524. result:=8;
  1525. aitconst_secrel32_symbol,
  1526. aitconst_rva_symbol :
  1527. if target_info.system=system_x86_64_win64 then
  1528. result:=sizeof(longint)
  1529. else
  1530. result:=sizeof(pint);
  1531. aitconst_uleb128bit :
  1532. result:=LengthUleb128(qword(value));
  1533. aitconst_sleb128bit :
  1534. result:=LengthSleb128(value);
  1535. aitconst_half16bit:
  1536. result:=2;
  1537. else
  1538. internalerror(200603253);
  1539. end;
  1540. end;
  1541. {****************************************************************************
  1542. TAI_real_32bit
  1543. ****************************************************************************}
  1544. constructor tai_real_32bit.Create(_value : ts32real);
  1545. begin
  1546. inherited Create;
  1547. typ:=ait_real_32bit;
  1548. value:=_value;
  1549. end;
  1550. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1551. begin
  1552. inherited ppuload(t,ppufile);
  1553. value:=ppufile.getreal;
  1554. end;
  1555. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1556. begin
  1557. inherited ppuwrite(ppufile);
  1558. ppufile.putreal(value);
  1559. end;
  1560. {****************************************************************************
  1561. TAI_real_64bit
  1562. ****************************************************************************}
  1563. constructor tai_real_64bit.Create(_value : ts64real);
  1564. begin
  1565. inherited Create;
  1566. typ:=ait_real_64bit;
  1567. value:=_value;
  1568. end;
  1569. {$ifdef ARM}
  1570. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1571. begin
  1572. inherited Create;
  1573. typ:=ait_real_64bit;
  1574. value:=_value;
  1575. formatoptions:=fo_hiloswapped;
  1576. end;
  1577. {$endif ARM}
  1578. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1579. begin
  1580. inherited ppuload(t,ppufile);
  1581. value:=ppufile.getreal;
  1582. {$ifdef ARM}
  1583. formatoptions:=tformatoptions(ppufile.getbyte);
  1584. {$endif ARM}
  1585. end;
  1586. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1587. begin
  1588. inherited ppuwrite(ppufile);
  1589. ppufile.putreal(value);
  1590. {$ifdef ARM}
  1591. ppufile.putbyte(byte(formatoptions));
  1592. {$endif ARM}
  1593. end;
  1594. {****************************************************************************
  1595. TAI_real_80bit
  1596. ****************************************************************************}
  1597. constructor tai_real_80bit.Create(_value : ts80real; _savesize: byte);
  1598. begin
  1599. inherited Create;
  1600. typ:=ait_real_80bit;
  1601. value:=_value;
  1602. savesize:=_savesize;
  1603. end;
  1604. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1605. begin
  1606. inherited ppuload(t,ppufile);
  1607. value:=ppufile.getreal;
  1608. savesize:=ppufile.getbyte;
  1609. end;
  1610. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1611. begin
  1612. inherited ppuwrite(ppufile);
  1613. ppufile.putreal(value);
  1614. ppufile.putbyte(savesize);
  1615. end;
  1616. {****************************************************************************
  1617. TAI_real_80bit
  1618. ****************************************************************************}
  1619. constructor tai_real_128bit.Create(_value : ts128real);
  1620. begin
  1621. inherited Create;
  1622. typ:=ait_real_128bit;
  1623. value:=_value;
  1624. end;
  1625. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1626. begin
  1627. inherited ppuload(t,ppufile);
  1628. value:=ppufile.getreal;
  1629. end;
  1630. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1631. begin
  1632. inherited ppuwrite(ppufile);
  1633. ppufile.putreal(value);
  1634. end;
  1635. {****************************************************************************
  1636. Tai_comp_64bit
  1637. ****************************************************************************}
  1638. constructor tai_comp_64bit.Create(_value : ts64comp);
  1639. begin
  1640. inherited Create;
  1641. typ:=ait_comp_64bit;
  1642. value:=_value;
  1643. end;
  1644. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1645. begin
  1646. inherited ppuload(t,ppufile);
  1647. ppufile.putdata(value,sizeof(value));
  1648. end;
  1649. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1650. begin
  1651. inherited ppuwrite(ppufile);
  1652. ppufile.getdata(value,sizeof(value));
  1653. end;
  1654. {****************************************************************************
  1655. TAI_STRING
  1656. ****************************************************************************}
  1657. constructor tai_string.Create(const _str : string);
  1658. begin
  1659. inherited Create;
  1660. typ:=ait_string;
  1661. len:=length(_str);
  1662. getmem(str,len+1);
  1663. move(_str[1],str^,len);
  1664. str[len]:=#0;
  1665. end;
  1666. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1667. begin
  1668. inherited Create;
  1669. typ:=ait_string;
  1670. str:=_str;
  1671. len:=length;
  1672. end;
  1673. destructor tai_string.destroy;
  1674. begin
  1675. if str<>nil then
  1676. freemem(str);
  1677. inherited Destroy;
  1678. end;
  1679. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1680. begin
  1681. inherited ppuload(t,ppufile);
  1682. len:=ppufile.getlongint;
  1683. getmem(str,len);
  1684. ppufile.getdata(str^,len);
  1685. end;
  1686. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1687. begin
  1688. inherited ppuwrite(ppufile);
  1689. ppufile.putlongint(len);
  1690. ppufile.putdata(str^,len);
  1691. end;
  1692. function tai_string.getcopy : tlinkedlistitem;
  1693. var
  1694. p : tlinkedlistitem;
  1695. begin
  1696. p:=inherited getcopy;
  1697. getmem(tai_string(p).str,len);
  1698. move(str^,tai_string(p).str^,len);
  1699. getcopy:=p;
  1700. end;
  1701. {****************************************************************************
  1702. TAI_LABEL
  1703. ****************************************************************************}
  1704. constructor tai_label.Create(_labsym : tasmlabel);
  1705. begin
  1706. inherited Create;
  1707. typ:=ait_label;
  1708. labsym:=_labsym;
  1709. labsym.is_set:=true;
  1710. is_global:=(labsym.bind in [AB_GLOBAL,AB_PRIVATE_EXTERN]);
  1711. end;
  1712. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1713. begin
  1714. inherited ppuload(t,ppufile);
  1715. labsym:=tasmlabel(ppufile.getasmsymbol);
  1716. is_global:=boolean(ppufile.getbyte);
  1717. end;
  1718. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1719. begin
  1720. inherited ppuwrite(ppufile);
  1721. ppufile.putasmsymbol(labsym);
  1722. ppufile.putbyte(byte(is_global));
  1723. end;
  1724. procedure tai_label.derefimpl;
  1725. begin
  1726. labsym.is_set:=true;
  1727. end;
  1728. {****************************************************************************
  1729. tai_comment comment to be inserted in the assembler file
  1730. ****************************************************************************}
  1731. constructor tai_comment.Create(_str : pchar);
  1732. begin
  1733. inherited Create;
  1734. typ:=ait_comment;
  1735. str:=_str;
  1736. end;
  1737. destructor tai_comment.destroy;
  1738. begin
  1739. freemem(str);
  1740. inherited Destroy;
  1741. end;
  1742. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1743. var
  1744. len : longint;
  1745. begin
  1746. inherited ppuload(t,ppufile);
  1747. len:=ppufile.getlongint;
  1748. getmem(str,len+1);
  1749. ppufile.getdata(str^,len);
  1750. str[len]:=#0;
  1751. end;
  1752. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1753. var
  1754. len : longint;
  1755. begin
  1756. inherited ppuwrite(ppufile);
  1757. len:=strlen(str);
  1758. ppufile.putlongint(len);
  1759. ppufile.putdata(str^,len);
  1760. end;
  1761. function tai_comment.getcopy : tlinkedlistitem;
  1762. var
  1763. p : tlinkedlistitem;
  1764. begin
  1765. p:=inherited getcopy;
  1766. getmem(tai_comment(p).str,strlen(str)+1);
  1767. move(str^,tai_comment(p).str^,strlen(str)+1);
  1768. getcopy:=p;
  1769. end;
  1770. {****************************************************************************
  1771. TAI_STABS
  1772. ****************************************************************************}
  1773. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  1774. begin
  1775. inherited create;
  1776. typ:=ait_stab;
  1777. str:=_str;
  1778. stabtype:=_stabtype;
  1779. end;
  1780. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  1781. begin
  1782. self.create(_stabtype,strpnew(s));
  1783. end;
  1784. constructor tai_stab.create_ansistr(_stabtype:TStabType;const s:ansistring);
  1785. begin
  1786. inherited create;
  1787. typ:=ait_stab;
  1788. stabtype:=_stabtype;
  1789. getmem(str,length(s)+1);
  1790. move(s[1],str^,length(s)+1);
  1791. end;
  1792. destructor tai_stab.destroy;
  1793. begin
  1794. freemem(str);
  1795. inherited destroy;
  1796. end;
  1797. {****************************************************************************
  1798. TAI_FORCE_LINE
  1799. ****************************************************************************}
  1800. constructor tai_force_line.create;
  1801. begin
  1802. inherited create;
  1803. typ:=ait_force_line;
  1804. end;
  1805. {****************************************************************************
  1806. TAI_FUNCTION_NAME
  1807. ****************************************************************************}
  1808. constructor tai_function_name.create(const s:string);
  1809. begin
  1810. inherited create;
  1811. typ:=ait_function_name;
  1812. funcname:=stringdup(s);
  1813. end;
  1814. destructor tai_function_name.destroy;
  1815. begin
  1816. stringdispose(funcname);
  1817. inherited destroy;
  1818. end;
  1819. {****************************************************************************
  1820. TAI_CUTOBJECT
  1821. ****************************************************************************}
  1822. constructor tai_cutobject.Create;
  1823. begin
  1824. inherited Create;
  1825. typ:=ait_cutobject;
  1826. place:=cut_normal;
  1827. end;
  1828. constructor tai_cutobject.Create_begin;
  1829. begin
  1830. inherited Create;
  1831. typ:=ait_cutobject;
  1832. place:=cut_begin;
  1833. end;
  1834. constructor tai_cutobject.Create_end;
  1835. begin
  1836. inherited Create;
  1837. typ:=ait_cutobject;
  1838. place:=cut_end;
  1839. end;
  1840. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1841. begin
  1842. inherited ppuload(t,ppufile);
  1843. place:=TCutPlace(ppufile.getbyte);
  1844. end;
  1845. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1846. begin
  1847. inherited ppuwrite(ppufile);
  1848. ppufile.putbyte(byte(place));
  1849. end;
  1850. {****************************************************************************
  1851. Tai_Marker
  1852. ****************************************************************************}
  1853. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1854. begin
  1855. Inherited Create;
  1856. typ := ait_marker;
  1857. Kind := _Kind;
  1858. end;
  1859. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1860. begin
  1861. inherited ppuload(t,ppufile);
  1862. kind:=TAsmMarker(ppufile.getbyte);
  1863. end;
  1864. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1865. begin
  1866. inherited ppuwrite(ppufile);
  1867. ppufile.putbyte(byte(kind));
  1868. end;
  1869. {*****************************************************************************
  1870. tai_tempalloc
  1871. *****************************************************************************}
  1872. constructor tai_tempalloc.alloc(pos,size:longint);
  1873. begin
  1874. inherited Create;
  1875. typ:=ait_tempalloc;
  1876. allocation:=true;
  1877. temppos:=pos;
  1878. tempsize:=size;
  1879. {$ifdef EXTDEBUG}
  1880. problem:=nil;
  1881. {$endif EXTDEBUG}
  1882. end;
  1883. destructor tai_tempalloc.destroy;
  1884. begin
  1885. {$ifdef EXTDEBUG}
  1886. stringdispose(problem);
  1887. {$endif EXTDEBUG}
  1888. inherited destroy;
  1889. end;
  1890. constructor tai_tempalloc.dealloc(pos,size:longint);
  1891. begin
  1892. inherited Create;
  1893. typ:=ait_tempalloc;
  1894. allocation:=false;
  1895. temppos:=pos;
  1896. tempsize:=size;
  1897. {$ifdef EXTDEBUG}
  1898. problem:=nil;
  1899. {$endif EXTDEBUG}
  1900. end;
  1901. {$ifdef EXTDEBUG}
  1902. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1903. begin
  1904. inherited Create;
  1905. typ:=ait_tempalloc;
  1906. allocation:=false;
  1907. temppos:=pos;
  1908. tempsize:=size;
  1909. problem:=stringdup(st);
  1910. end;
  1911. {$endif EXTDEBUG}
  1912. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1913. begin
  1914. inherited ppuload(t,ppufile);
  1915. temppos:=ppufile.getlongint;
  1916. tempsize:=ppufile.getlongint;
  1917. allocation:=boolean(ppufile.getbyte);
  1918. {$ifdef EXTDEBUG}
  1919. problem:=nil;
  1920. {$endif EXTDEBUG}
  1921. end;
  1922. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1923. begin
  1924. inherited ppuwrite(ppufile);
  1925. ppufile.putlongint(temppos);
  1926. ppufile.putlongint(tempsize);
  1927. ppufile.putbyte(byte(allocation));
  1928. end;
  1929. {*****************************************************************************
  1930. tai_regalloc
  1931. *****************************************************************************}
  1932. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1933. begin
  1934. inherited create;
  1935. typ:=ait_regalloc;
  1936. ratype:=ra_alloc;
  1937. reg:=r;
  1938. { ainstr must be an instruction }
  1939. if assigned(ainstr) and
  1940. (ainstr.typ<>ait_instruction) then
  1941. internalerror(200411011);
  1942. instr:=ainstr;
  1943. end;
  1944. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1945. begin
  1946. inherited create;
  1947. typ:=ait_regalloc;
  1948. ratype:=ra_dealloc;
  1949. reg:=r;
  1950. { ainstr must be an instruction }
  1951. if assigned(ainstr) and
  1952. (ainstr.typ<>ait_instruction) then
  1953. internalerror(200411012);
  1954. instr:=ainstr;
  1955. end;
  1956. constructor tai_regalloc.sync(r : tregister);
  1957. begin
  1958. inherited create;
  1959. typ:=ait_regalloc;
  1960. ratype:=ra_sync;
  1961. reg:=r;
  1962. end;
  1963. constructor tai_regalloc.resize(r : tregister);
  1964. begin
  1965. inherited create;
  1966. typ:=ait_regalloc;
  1967. ratype:=ra_resize;
  1968. reg:=r;
  1969. end;
  1970. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1971. begin
  1972. inherited ppuload(t,ppufile);
  1973. ppufile.getdata(reg,sizeof(Tregister));
  1974. ratype:=tregalloctype(ppufile.getbyte);
  1975. keep:=boolean(ppufile.getbyte);
  1976. end;
  1977. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1978. begin
  1979. inherited ppuwrite(ppufile);
  1980. ppufile.putdata(reg,sizeof(Tregister));
  1981. ppufile.putbyte(byte(ratype));
  1982. ppufile.putbyte(byte(keep));
  1983. end;
  1984. {*****************************************************************************
  1985. TaiInstruction
  1986. *****************************************************************************}
  1987. constructor tai_cpu_abstract.Create(op : tasmop);
  1988. begin
  1989. inherited create;
  1990. typ:=ait_instruction;
  1991. is_jmp:=false;
  1992. opcode:=op;
  1993. ops:=0;
  1994. end;
  1995. destructor tai_cpu_abstract.Destroy;
  1996. var
  1997. i : integer;
  1998. begin
  1999. for i:=0 to opercnt-1 do
  2000. freeop(i);
  2001. inherited destroy;
  2002. end;
  2003. { ---------------------------------------------------------------------
  2004. Loading of operands.
  2005. ---------------------------------------------------------------------}
  2006. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  2007. begin
  2008. while (opers>opercnt) do
  2009. begin
  2010. new(oper[opercnt]);
  2011. fillchar(oper[opercnt]^,sizeof(toper),0);
  2012. inc(opercnt);
  2013. end;
  2014. end;
  2015. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  2016. begin
  2017. allocate_oper(opidx+1);
  2018. with oper[opidx]^ do
  2019. begin
  2020. if typ<>top_const then
  2021. clearop(opidx);
  2022. val:=l;
  2023. typ:=top_const;
  2024. end;
  2025. end;
  2026. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  2027. var
  2028. r : treference;
  2029. begin
  2030. reference_reset_symbol(r,s,sofs,1);
  2031. r.refaddr:=addr_full;
  2032. loadref(opidx,r);
  2033. end;
  2034. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  2035. begin
  2036. if not assigned(s) then
  2037. internalerror(200204251);
  2038. allocate_oper(opidx+1);
  2039. with oper[opidx]^ do
  2040. begin
  2041. if typ<>top_local then
  2042. begin
  2043. clearop(opidx);
  2044. new(localoper);
  2045. end;
  2046. with oper[opidx]^.localoper^ do
  2047. begin
  2048. localsym:=s;
  2049. localsymofs:=sofs;
  2050. localindexreg:=indexreg;
  2051. localscale:=scale;
  2052. localgetoffset:=getoffset;
  2053. localforceref:=forceref;
  2054. end;
  2055. typ:=top_local;
  2056. end;
  2057. end;
  2058. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  2059. begin
  2060. allocate_oper(opidx+1);
  2061. with oper[opidx]^ do
  2062. begin
  2063. if typ<>top_ref then
  2064. begin
  2065. clearop(opidx);
  2066. new(ref);
  2067. end;
  2068. ref^:=r;
  2069. {$ifdef x86}
  2070. { We allow this exception for x86, since overloading this would be
  2071. too much of a a speed penalty}
  2072. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2073. segprefix:=ref^.segment;
  2074. {$endif}
  2075. if (cs_create_pic in current_settings.moduleswitches) and
  2076. assigned(r.symbol) and
  2077. not assigned(r.relsymbol) and
  2078. (r.refaddr=addr_no)
  2079. {$ifdef ARM}
  2080. and not(r.base=NR_R15)
  2081. {$endif ARM}
  2082. then
  2083. internalerror(200502052);
  2084. typ:=top_ref;
  2085. if assigned(add_reg_instruction_hook) then
  2086. begin
  2087. add_reg_instruction_hook(self,ref^.base);
  2088. add_reg_instruction_hook(self,ref^.index);
  2089. end;
  2090. { mark symbol as used }
  2091. if assigned(ref^.symbol) then
  2092. ref^.symbol.increfs;
  2093. if assigned(ref^.relsymbol) then
  2094. ref^.relsymbol.increfs;
  2095. end;
  2096. end;
  2097. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  2098. begin
  2099. allocate_oper(opidx+1);
  2100. with oper[opidx]^ do
  2101. begin
  2102. if typ<>top_reg then
  2103. clearop(opidx);
  2104. reg:=r;
  2105. typ:=top_reg;
  2106. end;
  2107. if assigned(add_reg_instruction_hook) then
  2108. add_reg_instruction_hook(self,r);
  2109. {$ifdef ARM}
  2110. { R15 is the PC on the ARM thus moves to R15 are jumps.
  2111. Due to speed considerations we don't use a virtual overridden method here.
  2112. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  2113. problems with iregs getting r15.
  2114. }
  2115. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  2116. {$endif ARM}
  2117. end;
  2118. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  2119. begin
  2120. allocate_oper(opidx+1);
  2121. clearop(opidx);
  2122. oper[opidx]^:=o;
  2123. { copy also the reference }
  2124. with oper[opidx]^ do
  2125. begin
  2126. case typ of
  2127. top_reg:
  2128. begin
  2129. if assigned(add_reg_instruction_hook) then
  2130. add_reg_instruction_hook(self,reg);
  2131. end;
  2132. top_ref:
  2133. begin
  2134. new(ref);
  2135. ref^:=o.ref^;
  2136. {$ifdef x86}
  2137. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2138. segprefix:=ref^.segment;
  2139. {$endif x86}
  2140. if assigned(add_reg_instruction_hook) then
  2141. begin
  2142. add_reg_instruction_hook(self,ref^.base);
  2143. add_reg_instruction_hook(self,ref^.index);
  2144. end;
  2145. end;
  2146. {$ifdef ARM}
  2147. top_shifterop:
  2148. begin
  2149. new(shifterop);
  2150. shifterop^:=o.shifterop^;
  2151. if assigned(add_reg_instruction_hook) then
  2152. add_reg_instruction_hook(self,shifterop^.rs);
  2153. end;
  2154. {$endif ARM}
  2155. end;
  2156. end;
  2157. end;
  2158. procedure tai_cpu_abstract.clearop(opidx:longint);
  2159. begin
  2160. with oper[opidx]^ do
  2161. begin
  2162. case typ of
  2163. top_ref:
  2164. dispose(ref);
  2165. top_local:
  2166. dispose(localoper);
  2167. {$ifdef ARM}
  2168. top_shifterop:
  2169. dispose(shifterop);
  2170. top_regset:
  2171. dispose(regset);
  2172. {$endif ARM}
  2173. {$ifdef jvm}
  2174. top_string:
  2175. freemem(pcval);
  2176. top_wstring:
  2177. donewidestring(pwstrval);
  2178. {$endif jvm}
  2179. end;
  2180. typ:=top_none;
  2181. end;
  2182. end;
  2183. procedure tai_cpu_abstract.freeop(opidx:longint);
  2184. begin
  2185. clearop(opidx);
  2186. dispose(oper[opidx]);
  2187. end;
  2188. { ---------------------------------------------------------------------
  2189. Miscellaneous methods.
  2190. ---------------------------------------------------------------------}
  2191. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  2192. begin
  2193. condition:=c;
  2194. end;
  2195. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  2196. var
  2197. i : longint;
  2198. p : tai_cpu_abstract;
  2199. begin
  2200. p:=tai_cpu_abstract(inherited getcopy);
  2201. { make a copy of the references }
  2202. p.opercnt:=0;
  2203. p.allocate_oper(ops);
  2204. for i:=0 to ops-1 do
  2205. begin
  2206. p.oper[i]^:=oper[i]^;
  2207. case oper[i]^.typ of
  2208. top_local :
  2209. begin
  2210. new(p.oper[i]^.localoper);
  2211. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  2212. end;
  2213. top_ref :
  2214. begin
  2215. new(p.oper[i]^.ref);
  2216. p.oper[i]^.ref^:=oper[i]^.ref^;
  2217. end;
  2218. {$ifdef ARM}
  2219. top_shifterop:
  2220. begin
  2221. new(p.oper[i]^.shifterop);
  2222. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  2223. end;
  2224. {$endif ARM}
  2225. end;
  2226. end;
  2227. getcopy:=p;
  2228. end;
  2229. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  2230. begin
  2231. { When the generic RA is used this needs to be overridden, we don't use
  2232. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  2233. when tai_cpu is created (PFV) }
  2234. internalerror(2004040901);
  2235. result:=false;
  2236. end;
  2237. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  2238. begin
  2239. internalerror(2004040902);
  2240. result:=operand_readwrite;
  2241. end;
  2242. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  2243. begin
  2244. result := operand_read;
  2245. end;
  2246. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2247. var
  2248. i : integer;
  2249. begin
  2250. inherited ppuload(t,ppufile);
  2251. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  2252. ppufile.getdata(condition,sizeof(tasmcond));
  2253. allocate_oper(ppufile.getbyte);
  2254. for i:=0 to ops-1 do
  2255. ppuloadoper(ppufile,oper[i]^);
  2256. opcode:=tasmop(ppufile.getword);
  2257. {$ifdef x86}
  2258. ppufile.getdata(segprefix,sizeof(Tregister));
  2259. {$endif x86}
  2260. is_jmp:=boolean(ppufile.getbyte);
  2261. end;
  2262. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  2263. var
  2264. i : integer;
  2265. begin
  2266. inherited ppuwrite(ppufile);
  2267. ppufile.putdata(condition,sizeof(tasmcond));
  2268. ppufile.putbyte(ops);
  2269. for i:=0 to ops-1 do
  2270. ppuwriteoper(ppufile,oper[i]^);
  2271. ppufile.putword(word(opcode));
  2272. {$ifdef x86}
  2273. ppufile.putdata(segprefix,sizeof(Tregister));
  2274. {$endif x86}
  2275. ppufile.putbyte(byte(is_jmp));
  2276. end;
  2277. procedure tai_cpu_abstract.buildderefimpl;
  2278. var
  2279. i : integer;
  2280. begin
  2281. for i:=0 to ops-1 do
  2282. ppubuildderefimploper(oper[i]^);
  2283. end;
  2284. procedure tai_cpu_abstract.derefimpl;
  2285. var
  2286. i : integer;
  2287. begin
  2288. for i:=0 to ops-1 do
  2289. ppuderefoper(oper[i]^);
  2290. end;
  2291. procedure tai_cpu_abstract.resetpass1;
  2292. begin
  2293. end;
  2294. procedure tai_cpu_abstract.resetpass2;
  2295. begin
  2296. end;
  2297. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  2298. begin
  2299. result:=0;
  2300. end;
  2301. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  2302. begin
  2303. end;
  2304. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  2305. begin
  2306. o.typ:=toptype(ppufile.getbyte);
  2307. o.ot:=ppufile.getlongint;
  2308. case o.typ of
  2309. top_reg :
  2310. ppufile.getdata(o.reg,sizeof(Tregister));
  2311. top_ref :
  2312. begin
  2313. new(o.ref);
  2314. {$ifdef x86}
  2315. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  2316. {$endif x86}
  2317. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  2318. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  2319. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2320. o.ref^.scalefactor:=ppufile.getbyte;
  2321. o.ref^.offset:=ppufile.getaint;
  2322. o.ref^.symbol:=ppufile.getasmsymbol;
  2323. o.ref^.relsymbol:=ppufile.getasmsymbol;
  2324. end;
  2325. top_const :
  2326. o.val:=ppufile.getaint;
  2327. top_local :
  2328. begin
  2329. new(o.localoper);
  2330. with o.localoper^ do
  2331. begin
  2332. ppufile.getderef(localsymderef);
  2333. localsymofs:=ppufile.getaint;
  2334. localindexreg:=tregister(ppufile.getlongint);
  2335. localscale:=ppufile.getbyte;
  2336. localgetoffset:=(ppufile.getbyte<>0);
  2337. end;
  2338. end;
  2339. else
  2340. internalerror(2007010210);
  2341. end;
  2342. end;
  2343. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  2344. begin
  2345. ppufile.putbyte(byte(o.typ));
  2346. ppufile.putlongint(o.ot);
  2347. case o.typ of
  2348. top_reg :
  2349. ppufile.putdata(o.reg,sizeof(Tregister));
  2350. top_ref :
  2351. begin
  2352. {$ifdef x86}
  2353. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  2354. {$endif x86}
  2355. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  2356. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  2357. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2358. ppufile.putbyte(o.ref^.scalefactor);
  2359. ppufile.putaint(o.ref^.offset);
  2360. ppufile.putasmsymbol(o.ref^.symbol);
  2361. ppufile.putasmsymbol(o.ref^.relsymbol);
  2362. end;
  2363. top_const :
  2364. ppufile.putaint(o.val);
  2365. top_local :
  2366. begin
  2367. with o.localoper^ do
  2368. begin
  2369. ppufile.putderef(localsymderef);
  2370. ppufile.putaint(localsymofs);
  2371. ppufile.putlongint(longint(localindexreg));
  2372. ppufile.putbyte(localscale);
  2373. ppufile.putbyte(byte(localgetoffset));
  2374. end;
  2375. end;
  2376. else
  2377. internalerror(2007010211);
  2378. end;
  2379. end;
  2380. {****************************************************************************
  2381. tai_align_abstract
  2382. ****************************************************************************}
  2383. constructor tai_align_abstract.Create(b: byte);
  2384. begin
  2385. inherited Create;
  2386. typ:=ait_align;
  2387. {$ifdef EXTDEBUG}
  2388. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  2389. internalerror(200709191);
  2390. {$endif EXTDEBUG}
  2391. if b in [1,2,4,8,16,32] then
  2392. aligntype := b
  2393. else
  2394. aligntype := 1;
  2395. fillsize:=0;
  2396. fillop:=0;
  2397. use_op:=false;
  2398. end;
  2399. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  2400. begin
  2401. inherited Create;
  2402. typ:=ait_align;
  2403. if b in [1,2,4,8,16,32] then
  2404. aligntype := b
  2405. else
  2406. aligntype := 1;
  2407. fillsize:=0;
  2408. fillop:=_op;
  2409. use_op:=true;
  2410. end;
  2411. constructor tai_align_abstract.Create_zeros(b: byte);
  2412. begin
  2413. inherited Create;
  2414. typ:=ait_align;
  2415. if b in [1,2,4,8,16,32] then
  2416. aligntype := b
  2417. else
  2418. aligntype := 1;
  2419. use_op:=true;
  2420. fillsize:=0;
  2421. fillop:=0;
  2422. end;
  2423. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
  2424. begin
  2425. if fillsize>sizeof(buf) then
  2426. internalerror(200404293);
  2427. fillchar(buf,high(buf),fillop);
  2428. calculatefillbuf:=pchar(@buf);
  2429. end;
  2430. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2431. begin
  2432. inherited ppuload(t,ppufile);
  2433. aligntype:=ppufile.getbyte;
  2434. fillsize:=0;
  2435. fillop:=ppufile.getbyte;
  2436. use_op:=boolean(ppufile.getbyte);
  2437. end;
  2438. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  2439. begin
  2440. inherited ppuwrite(ppufile);
  2441. ppufile.putbyte(aligntype);
  2442. ppufile.putbyte(fillop);
  2443. ppufile.putbyte(byte(use_op));
  2444. end;
  2445. {****************************************************************************
  2446. tai_seh_directive
  2447. ****************************************************************************}
  2448. const
  2449. datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
  2450. sd_string, { proc }
  2451. sd_none, { endproc }
  2452. sd_none, { endprologue }
  2453. sd_string, { handler }
  2454. sd_none, { handlerdata }
  2455. sd_none,sd_none,sd_none, { eh, 32, no32 }
  2456. sd_regoffset, { setframe }
  2457. sd_offset, { stackalloc }
  2458. sd_reg, { pushreg }
  2459. sd_regoffset, { savereg }
  2460. sd_regoffset, { savexmm }
  2461. sd_none { pushframe }
  2462. );
  2463. constructor tai_seh_directive.create(_kind:TAsmSehDirective);
  2464. begin
  2465. inherited Create;
  2466. typ:=ait_seh_directive;
  2467. kind:=_kind;
  2468. data.typ:=datatypemap[_kind];
  2469. end;
  2470. constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
  2471. begin
  2472. create(_kind);
  2473. data.name:=stringdup(_name);
  2474. end;
  2475. constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
  2476. begin
  2477. create(_kind);
  2478. data.reg:=r;
  2479. end;
  2480. constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
  2481. begin
  2482. create(_kind);
  2483. data.offset:=ofs;
  2484. end;
  2485. constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
  2486. r:TRegister;ofs:dword);
  2487. begin
  2488. create(_kind);
  2489. data.offset:=ofs;
  2490. data.reg:=r;
  2491. end;
  2492. constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  2493. begin
  2494. inherited ppuload(t, ppufile);
  2495. kind:=TAsmSehDirective(ppufile.getbyte);
  2496. data.typ:=datatypemap[kind];
  2497. case data.typ of
  2498. sd_none: ;
  2499. sd_string:
  2500. begin
  2501. data.name:=stringdup(ppufile.getstring);
  2502. data.flags:=ppufile.getbyte;
  2503. end;
  2504. sd_reg,sd_offset,sd_regoffset:
  2505. begin
  2506. ppufile.getdata(data.reg,sizeof(TRegister));
  2507. data.offset:=ppufile.getdword;
  2508. end;
  2509. else
  2510. InternalError(2011091201);
  2511. end;
  2512. end;
  2513. destructor tai_seh_directive.destroy;
  2514. begin
  2515. if data.typ=sd_string then
  2516. stringdispose(data.name);
  2517. inherited destroy;
  2518. end;
  2519. procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
  2520. begin
  2521. inherited ppuwrite(ppufile);
  2522. ppufile.putbyte(ord(kind));
  2523. case data.typ of
  2524. sd_none: ;
  2525. sd_string:
  2526. begin
  2527. ppufile.putstring(data.name^);
  2528. ppufile.putbyte(data.flags);
  2529. end;
  2530. sd_reg,sd_offset,sd_regoffset:
  2531. begin
  2532. ppufile.putdata(data.reg,sizeof(TRegister));
  2533. ppufile.putdword(data.offset);
  2534. end;
  2535. else
  2536. InternalError(2011091202);
  2537. end;
  2538. end;
  2539. procedure tai_seh_directive.generate_code(objdata:TObjData);
  2540. begin
  2541. end;
  2542. {$ifdef JVM}
  2543. {****************************************************************************
  2544. tai_jvar
  2545. ****************************************************************************}
  2546. constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  2547. begin
  2548. Inherited create;
  2549. typ:=ait_jvar;
  2550. stackslot:=_stackslot;
  2551. desc:=stringdup(_desc);
  2552. startlab:=_startlab;
  2553. stoplab:=_stoplab;
  2554. end;
  2555. constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
  2556. begin
  2557. inherited ppuload(t, ppufile);
  2558. stackslot:=ppufile.getlongint;
  2559. desc:=stringdup(ppufile.getstring);
  2560. startlab:=ppufile.getasmsymbol;
  2561. stoplab:=ppufile.getasmsymbol;
  2562. end;
  2563. procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
  2564. begin
  2565. inherited ppuwrite(ppufile);
  2566. ppufile.putlongint(stackslot);
  2567. ppufile.putstring(desc^);
  2568. ppufile.putasmsymbol(startlab);
  2569. ppufile.putasmsymbol(stoplab);
  2570. end;
  2571. destructor tai_jvar.destroy;
  2572. begin
  2573. stringdispose(desc);
  2574. inherited destroy;
  2575. end;
  2576. {****************************************************************************
  2577. tai_jcatch
  2578. ****************************************************************************}
  2579. constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  2580. begin
  2581. Inherited create;
  2582. typ:=ait_jcatch;
  2583. name:=stringdup(_name);
  2584. startlab:=_startlab;
  2585. startlab.increfs;
  2586. stoplab:=_stoplab;
  2587. stoplab.increfs;
  2588. handlerlab:=_handlerlab;
  2589. handlerlab.increfs;
  2590. end;
  2591. destructor tai_jcatch.destroy;
  2592. begin
  2593. stringdispose(name);
  2594. inherited destroy;
  2595. end;
  2596. constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
  2597. begin
  2598. inherited ppuload(t, ppufile);
  2599. name:=stringdup(ppufile.getstring);
  2600. startlab:=ppufile.getasmsymbol;
  2601. startlab.increfs;
  2602. stoplab:=ppufile.getasmsymbol;
  2603. stoplab.increfs;
  2604. handlerlab:=ppufile.getasmsymbol;
  2605. handlerlab.increfs;
  2606. end;
  2607. procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
  2608. begin
  2609. inherited ppuwrite(ppufile);
  2610. ppufile.putstring(name^);
  2611. ppufile.putasmsymbol(startlab);
  2612. ppufile.putasmsymbol(stoplab);
  2613. ppufile.putasmsymbol(handlerlab);
  2614. end;
  2615. {$endif JVM}
  2616. begin
  2617. {$push}{$warnings off}
  2618. { taitype should fit into a 4 byte set for speed reasons }
  2619. if ord(high(taitype))>31 then
  2620. internalerror(201108181);
  2621. {$pop}
  2622. end.