aasmtai.pas 92 KB

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