aasmtai.pas 93 KB

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