aasmtai.pas 87 KB

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