aasmtai.pas 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183
  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. move(s[1],str^,length(s)+1);
  1835. end;
  1836. destructor tai_stab.destroy;
  1837. begin
  1838. freemem(str);
  1839. inherited destroy;
  1840. end;
  1841. {****************************************************************************
  1842. TAI_FORCE_LINE
  1843. ****************************************************************************}
  1844. constructor tai_force_line.create;
  1845. begin
  1846. inherited create;
  1847. typ:=ait_force_line;
  1848. end;
  1849. {****************************************************************************
  1850. TAI_FUNCTION_NAME
  1851. ****************************************************************************}
  1852. constructor tai_function_name.create(const s:string);
  1853. begin
  1854. inherited create;
  1855. typ:=ait_function_name;
  1856. funcname:=stringdup(s);
  1857. end;
  1858. destructor tai_function_name.destroy;
  1859. begin
  1860. stringdispose(funcname);
  1861. inherited destroy;
  1862. end;
  1863. {****************************************************************************
  1864. TAI_CUTOBJECT
  1865. ****************************************************************************}
  1866. constructor tai_cutobject.Create;
  1867. begin
  1868. inherited Create;
  1869. typ:=ait_cutobject;
  1870. place:=cut_normal;
  1871. end;
  1872. constructor tai_cutobject.Create_begin;
  1873. begin
  1874. inherited Create;
  1875. typ:=ait_cutobject;
  1876. place:=cut_begin;
  1877. end;
  1878. constructor tai_cutobject.Create_end;
  1879. begin
  1880. inherited Create;
  1881. typ:=ait_cutobject;
  1882. place:=cut_end;
  1883. end;
  1884. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1885. begin
  1886. inherited ppuload(t,ppufile);
  1887. place:=TCutPlace(ppufile.getbyte);
  1888. end;
  1889. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1890. begin
  1891. inherited ppuwrite(ppufile);
  1892. ppufile.putbyte(byte(place));
  1893. end;
  1894. {****************************************************************************
  1895. Tai_Marker
  1896. ****************************************************************************}
  1897. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1898. begin
  1899. Inherited Create;
  1900. typ := ait_marker;
  1901. Kind := _Kind;
  1902. end;
  1903. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1904. begin
  1905. inherited ppuload(t,ppufile);
  1906. kind:=TAsmMarker(ppufile.getbyte);
  1907. end;
  1908. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1909. begin
  1910. inherited ppuwrite(ppufile);
  1911. ppufile.putbyte(byte(kind));
  1912. end;
  1913. {*****************************************************************************
  1914. tai_tempalloc
  1915. *****************************************************************************}
  1916. constructor tai_tempalloc.alloc(pos,size:longint);
  1917. begin
  1918. inherited Create;
  1919. typ:=ait_tempalloc;
  1920. allocation:=true;
  1921. temppos:=pos;
  1922. tempsize:=size;
  1923. {$ifdef EXTDEBUG}
  1924. problem:=nil;
  1925. {$endif EXTDEBUG}
  1926. end;
  1927. destructor tai_tempalloc.destroy;
  1928. begin
  1929. {$ifdef EXTDEBUG}
  1930. stringdispose(problem);
  1931. {$endif EXTDEBUG}
  1932. inherited destroy;
  1933. end;
  1934. constructor tai_tempalloc.dealloc(pos,size:longint);
  1935. begin
  1936. inherited Create;
  1937. typ:=ait_tempalloc;
  1938. allocation:=false;
  1939. temppos:=pos;
  1940. tempsize:=size;
  1941. {$ifdef EXTDEBUG}
  1942. problem:=nil;
  1943. {$endif EXTDEBUG}
  1944. end;
  1945. {$ifdef EXTDEBUG}
  1946. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1947. begin
  1948. inherited Create;
  1949. typ:=ait_tempalloc;
  1950. allocation:=false;
  1951. temppos:=pos;
  1952. tempsize:=size;
  1953. problem:=stringdup(st);
  1954. end;
  1955. {$endif EXTDEBUG}
  1956. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1957. begin
  1958. inherited ppuload(t,ppufile);
  1959. temppos:=ppufile.getlongint;
  1960. tempsize:=ppufile.getlongint;
  1961. allocation:=boolean(ppufile.getbyte);
  1962. {$ifdef EXTDEBUG}
  1963. problem:=nil;
  1964. {$endif EXTDEBUG}
  1965. end;
  1966. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1967. begin
  1968. inherited ppuwrite(ppufile);
  1969. ppufile.putlongint(temppos);
  1970. ppufile.putlongint(tempsize);
  1971. ppufile.putbyte(byte(allocation));
  1972. end;
  1973. {*****************************************************************************
  1974. tai_regalloc
  1975. *****************************************************************************}
  1976. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1977. begin
  1978. inherited create;
  1979. typ:=ait_regalloc;
  1980. ratype:=ra_alloc;
  1981. reg:=r;
  1982. { ainstr must be an instruction }
  1983. if assigned(ainstr) and
  1984. (ainstr.typ<>ait_instruction) then
  1985. internalerror(200411011);
  1986. instr:=ainstr;
  1987. end;
  1988. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1989. begin
  1990. inherited create;
  1991. typ:=ait_regalloc;
  1992. ratype:=ra_dealloc;
  1993. reg:=r;
  1994. { ainstr must be an instruction }
  1995. if assigned(ainstr) and
  1996. (ainstr.typ<>ait_instruction) then
  1997. internalerror(200411012);
  1998. instr:=ainstr;
  1999. end;
  2000. constructor tai_regalloc.sync(r : tregister);
  2001. begin
  2002. inherited create;
  2003. typ:=ait_regalloc;
  2004. ratype:=ra_sync;
  2005. reg:=r;
  2006. end;
  2007. constructor tai_regalloc.resize(r : tregister);
  2008. begin
  2009. inherited create;
  2010. typ:=ait_regalloc;
  2011. ratype:=ra_resize;
  2012. reg:=r;
  2013. end;
  2014. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  2015. begin
  2016. inherited ppuload(t,ppufile);
  2017. ppufile.getdata(reg,sizeof(Tregister));
  2018. ratype:=tregalloctype(ppufile.getbyte);
  2019. keep:=boolean(ppufile.getbyte);
  2020. end;
  2021. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  2022. begin
  2023. inherited ppuwrite(ppufile);
  2024. ppufile.putdata(reg,sizeof(Tregister));
  2025. ppufile.putbyte(byte(ratype));
  2026. ppufile.putbyte(byte(keep));
  2027. end;
  2028. {*****************************************************************************
  2029. TaiInstruction
  2030. *****************************************************************************}
  2031. constructor tai_cpu_abstract.Create(op : tasmop);
  2032. begin
  2033. inherited create;
  2034. typ:=ait_instruction;
  2035. is_jmp:=false;
  2036. opcode:=op;
  2037. ops:=0;
  2038. end;
  2039. destructor tai_cpu_abstract.Destroy;
  2040. var
  2041. i : integer;
  2042. begin
  2043. for i:=0 to opercnt-1 do
  2044. freeop(i);
  2045. inherited destroy;
  2046. end;
  2047. { ---------------------------------------------------------------------
  2048. Loading of operands.
  2049. ---------------------------------------------------------------------}
  2050. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  2051. begin
  2052. while (opers>opercnt) do
  2053. begin
  2054. new(oper[opercnt]);
  2055. fillchar(oper[opercnt]^,sizeof(toper),0);
  2056. inc(opercnt);
  2057. end;
  2058. end;
  2059. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  2060. begin
  2061. allocate_oper(opidx+1);
  2062. with oper[opidx]^ do
  2063. begin
  2064. if typ<>top_const then
  2065. clearop(opidx);
  2066. val:=l;
  2067. typ:=top_const;
  2068. end;
  2069. end;
  2070. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  2071. var
  2072. r : treference;
  2073. begin
  2074. reference_reset_symbol(r,s,sofs,1);
  2075. r.refaddr:=addr_full;
  2076. loadref(opidx,r);
  2077. end;
  2078. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  2079. begin
  2080. if not assigned(s) then
  2081. internalerror(200204251);
  2082. allocate_oper(opidx+1);
  2083. with oper[opidx]^ do
  2084. begin
  2085. if typ<>top_local then
  2086. begin
  2087. clearop(opidx);
  2088. new(localoper);
  2089. end;
  2090. with oper[opidx]^.localoper^ do
  2091. begin
  2092. localsym:=s;
  2093. localsymofs:=sofs;
  2094. localindexreg:=indexreg;
  2095. localscale:=scale;
  2096. localgetoffset:=getoffset;
  2097. localforceref:=forceref;
  2098. end;
  2099. typ:=top_local;
  2100. end;
  2101. end;
  2102. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  2103. begin
  2104. allocate_oper(opidx+1);
  2105. with oper[opidx]^ do
  2106. begin
  2107. if typ<>top_ref then
  2108. begin
  2109. clearop(opidx);
  2110. new(ref);
  2111. end;
  2112. ref^:=r;
  2113. {$ifdef x86}
  2114. { We allow this exception for x86, since overloading this would be
  2115. too much of a a speed penalty}
  2116. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2117. segprefix:=ref^.segment;
  2118. {$endif}
  2119. if (cs_create_pic in current_settings.moduleswitches) and
  2120. assigned(r.symbol) and
  2121. not assigned(r.relsymbol) and
  2122. (r.refaddr=addr_no)
  2123. {$ifdef ARM}
  2124. and not(r.base=NR_R15)
  2125. {$endif ARM}
  2126. then
  2127. internalerror(200502052);
  2128. typ:=top_ref;
  2129. if assigned(add_reg_instruction_hook) then
  2130. begin
  2131. add_reg_instruction_hook(self,ref^.base);
  2132. add_reg_instruction_hook(self,ref^.index);
  2133. end;
  2134. { mark symbol as used }
  2135. if assigned(ref^.symbol) then
  2136. ref^.symbol.increfs;
  2137. if assigned(ref^.relsymbol) then
  2138. ref^.relsymbol.increfs;
  2139. end;
  2140. end;
  2141. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  2142. begin
  2143. allocate_oper(opidx+1);
  2144. with oper[opidx]^ do
  2145. begin
  2146. if typ<>top_reg then
  2147. clearop(opidx);
  2148. reg:=r;
  2149. typ:=top_reg;
  2150. end;
  2151. if assigned(add_reg_instruction_hook) then
  2152. add_reg_instruction_hook(self,r);
  2153. {$ifdef ARM}
  2154. { R15 is the PC on the ARM thus moves to R15 are jumps.
  2155. Due to speed considerations we don't use a virtual overridden method here.
  2156. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  2157. problems with iregs getting r15.
  2158. }
  2159. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  2160. {$endif ARM}
  2161. end;
  2162. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  2163. begin
  2164. allocate_oper(opidx+1);
  2165. clearop(opidx);
  2166. oper[opidx]^:=o;
  2167. { copy also the reference }
  2168. with oper[opidx]^ do
  2169. begin
  2170. case typ of
  2171. top_reg:
  2172. begin
  2173. if assigned(add_reg_instruction_hook) then
  2174. add_reg_instruction_hook(self,reg);
  2175. end;
  2176. top_ref:
  2177. begin
  2178. new(ref);
  2179. ref^:=o.ref^;
  2180. {$ifdef x86}
  2181. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  2182. segprefix:=ref^.segment;
  2183. {$endif x86}
  2184. if assigned(add_reg_instruction_hook) then
  2185. begin
  2186. add_reg_instruction_hook(self,ref^.base);
  2187. add_reg_instruction_hook(self,ref^.index);
  2188. end;
  2189. end;
  2190. {$ifdef ARM}
  2191. top_shifterop:
  2192. begin
  2193. new(shifterop);
  2194. shifterop^:=o.shifterop^;
  2195. if assigned(add_reg_instruction_hook) then
  2196. add_reg_instruction_hook(self,shifterop^.rs);
  2197. end;
  2198. {$endif ARM}
  2199. end;
  2200. end;
  2201. end;
  2202. procedure tai_cpu_abstract.clearop(opidx:longint);
  2203. begin
  2204. with oper[opidx]^ do
  2205. begin
  2206. case typ of
  2207. top_ref:
  2208. dispose(ref);
  2209. top_local:
  2210. dispose(localoper);
  2211. {$ifdef ARM}
  2212. top_shifterop:
  2213. dispose(shifterop);
  2214. top_regset:
  2215. dispose(regset);
  2216. {$endif ARM}
  2217. {$ifdef m68k}
  2218. top_regset:
  2219. begin
  2220. dispose(dataregset);
  2221. dispose(addrregset);
  2222. end;
  2223. {$endif m68k}
  2224. {$ifdef jvm}
  2225. top_string:
  2226. freemem(pcval);
  2227. top_wstring:
  2228. donewidestring(pwstrval);
  2229. {$endif jvm}
  2230. end;
  2231. typ:=top_none;
  2232. end;
  2233. end;
  2234. procedure tai_cpu_abstract.freeop(opidx:longint);
  2235. begin
  2236. clearop(opidx);
  2237. dispose(oper[opidx]);
  2238. end;
  2239. { ---------------------------------------------------------------------
  2240. Miscellaneous methods.
  2241. ---------------------------------------------------------------------}
  2242. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  2243. begin
  2244. condition:=c;
  2245. end;
  2246. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  2247. var
  2248. i : longint;
  2249. p : tai_cpu_abstract;
  2250. begin
  2251. p:=tai_cpu_abstract(inherited getcopy);
  2252. { make a copy of the references }
  2253. p.opercnt:=0;
  2254. p.allocate_oper(ops);
  2255. for i:=0 to ops-1 do
  2256. begin
  2257. p.oper[i]^:=oper[i]^;
  2258. case oper[i]^.typ of
  2259. top_local :
  2260. begin
  2261. new(p.oper[i]^.localoper);
  2262. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  2263. end;
  2264. top_ref :
  2265. begin
  2266. new(p.oper[i]^.ref);
  2267. p.oper[i]^.ref^:=oper[i]^.ref^;
  2268. end;
  2269. {$ifdef ARM}
  2270. top_shifterop:
  2271. begin
  2272. new(p.oper[i]^.shifterop);
  2273. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  2274. end;
  2275. {$endif ARM}
  2276. end;
  2277. end;
  2278. getcopy:=p;
  2279. end;
  2280. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  2281. begin
  2282. { When the generic RA is used this needs to be overridden, we don't use
  2283. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  2284. when tai_cpu is created (PFV) }
  2285. internalerror(2004040901);
  2286. result:=false;
  2287. end;
  2288. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  2289. begin
  2290. internalerror(2004040902);
  2291. result:=operand_readwrite;
  2292. end;
  2293. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  2294. begin
  2295. result := operand_read;
  2296. end;
  2297. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2298. var
  2299. i : integer;
  2300. begin
  2301. inherited ppuload(t,ppufile);
  2302. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  2303. ppufile.getdata(condition,sizeof(tasmcond));
  2304. allocate_oper(ppufile.getbyte);
  2305. for i:=0 to ops-1 do
  2306. ppuloadoper(ppufile,oper[i]^);
  2307. opcode:=tasmop(ppufile.getword);
  2308. {$ifdef x86}
  2309. ppufile.getdata(segprefix,sizeof(Tregister));
  2310. {$endif x86}
  2311. is_jmp:=boolean(ppufile.getbyte);
  2312. end;
  2313. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  2314. var
  2315. i : integer;
  2316. begin
  2317. inherited ppuwrite(ppufile);
  2318. ppufile.putdata(condition,sizeof(tasmcond));
  2319. ppufile.putbyte(ops);
  2320. for i:=0 to ops-1 do
  2321. ppuwriteoper(ppufile,oper[i]^);
  2322. ppufile.putword(word(opcode));
  2323. {$ifdef x86}
  2324. ppufile.putdata(segprefix,sizeof(Tregister));
  2325. {$endif x86}
  2326. ppufile.putbyte(byte(is_jmp));
  2327. end;
  2328. procedure tai_cpu_abstract.buildderefimpl;
  2329. var
  2330. i : integer;
  2331. begin
  2332. for i:=0 to ops-1 do
  2333. ppubuildderefimploper(oper[i]^);
  2334. end;
  2335. procedure tai_cpu_abstract.derefimpl;
  2336. var
  2337. i : integer;
  2338. begin
  2339. for i:=0 to ops-1 do
  2340. ppuderefoper(oper[i]^);
  2341. end;
  2342. procedure tai_cpu_abstract.resetpass1;
  2343. begin
  2344. end;
  2345. procedure tai_cpu_abstract.resetpass2;
  2346. begin
  2347. end;
  2348. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  2349. begin
  2350. result:=0;
  2351. end;
  2352. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  2353. begin
  2354. end;
  2355. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  2356. begin
  2357. o.typ:=toptype(ppufile.getbyte);
  2358. o.ot:=ppufile.getlongint;
  2359. case o.typ of
  2360. top_reg :
  2361. ppufile.getdata(o.reg,sizeof(Tregister));
  2362. top_ref :
  2363. begin
  2364. new(o.ref);
  2365. {$ifdef x86}
  2366. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  2367. {$endif x86}
  2368. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  2369. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  2370. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2371. o.ref^.scalefactor:=ppufile.getbyte;
  2372. o.ref^.offset:=ppufile.getaint;
  2373. o.ref^.symbol:=ppufile.getasmsymbol;
  2374. o.ref^.relsymbol:=ppufile.getasmsymbol;
  2375. end;
  2376. top_const :
  2377. o.val:=ppufile.getaint;
  2378. top_local :
  2379. begin
  2380. new(o.localoper);
  2381. with o.localoper^ do
  2382. begin
  2383. ppufile.getderef(localsymderef);
  2384. localsymofs:=ppufile.getaint;
  2385. localindexreg:=tregister(ppufile.getlongint);
  2386. localscale:=ppufile.getbyte;
  2387. localgetoffset:=(ppufile.getbyte<>0);
  2388. end;
  2389. end;
  2390. else
  2391. internalerror(2007010210);
  2392. end;
  2393. end;
  2394. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  2395. begin
  2396. ppufile.putbyte(byte(o.typ));
  2397. ppufile.putlongint(o.ot);
  2398. case o.typ of
  2399. top_reg :
  2400. ppufile.putdata(o.reg,sizeof(Tregister));
  2401. top_ref :
  2402. begin
  2403. {$ifdef x86}
  2404. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  2405. {$endif x86}
  2406. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  2407. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  2408. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  2409. ppufile.putbyte(o.ref^.scalefactor);
  2410. ppufile.putaint(o.ref^.offset);
  2411. ppufile.putasmsymbol(o.ref^.symbol);
  2412. ppufile.putasmsymbol(o.ref^.relsymbol);
  2413. end;
  2414. top_const :
  2415. ppufile.putaint(o.val);
  2416. top_local :
  2417. begin
  2418. with o.localoper^ do
  2419. begin
  2420. ppufile.putderef(localsymderef);
  2421. ppufile.putaint(localsymofs);
  2422. ppufile.putlongint(longint(localindexreg));
  2423. ppufile.putbyte(localscale);
  2424. ppufile.putbyte(byte(localgetoffset));
  2425. end;
  2426. end;
  2427. else
  2428. internalerror(2007010211);
  2429. end;
  2430. end;
  2431. {****************************************************************************
  2432. tai_align_abstract
  2433. ****************************************************************************}
  2434. constructor tai_align_abstract.Create(b: byte);
  2435. begin
  2436. inherited Create;
  2437. typ:=ait_align;
  2438. {$ifdef EXTDEBUG}
  2439. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  2440. internalerror(200709191);
  2441. {$endif EXTDEBUG}
  2442. if b in [1,2,4,8,16,32] then
  2443. aligntype := b
  2444. else
  2445. aligntype := 1;
  2446. fillsize:=0;
  2447. fillop:=0;
  2448. use_op:=false;
  2449. end;
  2450. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  2451. begin
  2452. inherited Create;
  2453. typ:=ait_align;
  2454. if b in [1,2,4,8,16,32] then
  2455. aligntype := b
  2456. else
  2457. aligntype := 1;
  2458. fillsize:=0;
  2459. fillop:=_op;
  2460. use_op:=true;
  2461. end;
  2462. constructor tai_align_abstract.Create_zeros(b: byte);
  2463. begin
  2464. inherited Create;
  2465. typ:=ait_align;
  2466. if b in [1,2,4,8,16,32] then
  2467. aligntype := b
  2468. else
  2469. aligntype := 1;
  2470. use_op:=true;
  2471. fillsize:=0;
  2472. fillop:=0;
  2473. end;
  2474. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer;executable : boolean):pchar;
  2475. begin
  2476. if fillsize>sizeof(buf) then
  2477. internalerror(200404293);
  2478. fillchar(buf,high(buf),fillop);
  2479. calculatefillbuf:=pchar(@buf);
  2480. end;
  2481. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  2482. begin
  2483. inherited ppuload(t,ppufile);
  2484. aligntype:=ppufile.getbyte;
  2485. fillsize:=0;
  2486. fillop:=ppufile.getbyte;
  2487. use_op:=boolean(ppufile.getbyte);
  2488. end;
  2489. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  2490. begin
  2491. inherited ppuwrite(ppufile);
  2492. ppufile.putbyte(aligntype);
  2493. ppufile.putbyte(fillop);
  2494. ppufile.putbyte(byte(use_op));
  2495. end;
  2496. {****************************************************************************
  2497. tai_seh_directive
  2498. ****************************************************************************}
  2499. const
  2500. datatypemap: array[TAsmSehDirective] of TSehDirectiveDatatype=(
  2501. sd_string, { proc }
  2502. sd_none, { endproc }
  2503. sd_none, { endprologue }
  2504. sd_string, { handler }
  2505. sd_none, { handlerdata }
  2506. sd_none,sd_none,sd_none, { eh, 32, no32 }
  2507. sd_regoffset, { setframe }
  2508. sd_offset, { stackalloc }
  2509. sd_reg, { pushreg }
  2510. sd_regoffset, { savereg }
  2511. sd_regoffset, { savexmm }
  2512. sd_none { pushframe }
  2513. );
  2514. constructor tai_seh_directive.create(_kind:TAsmSehDirective);
  2515. begin
  2516. inherited Create;
  2517. typ:=ait_seh_directive;
  2518. kind:=_kind;
  2519. data.typ:=datatypemap[_kind];
  2520. end;
  2521. constructor tai_seh_directive.create_name(_kind:TAsmSehDirective;const _name:string);
  2522. begin
  2523. create(_kind);
  2524. data.name:=stringdup(_name);
  2525. end;
  2526. constructor tai_seh_directive.create_reg(_kind:TAsmSehDirective;r:TRegister);
  2527. begin
  2528. create(_kind);
  2529. data.reg:=r;
  2530. end;
  2531. constructor tai_seh_directive.create_offset(_kind:TAsmSehDirective;ofs:dword);
  2532. begin
  2533. create(_kind);
  2534. data.offset:=ofs;
  2535. end;
  2536. constructor tai_seh_directive.create_reg_offset(_kind:TAsmSehDirective;
  2537. r:TRegister;ofs:dword);
  2538. begin
  2539. create(_kind);
  2540. data.offset:=ofs;
  2541. data.reg:=r;
  2542. end;
  2543. constructor tai_seh_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  2544. begin
  2545. inherited ppuload(t, ppufile);
  2546. kind:=TAsmSehDirective(ppufile.getbyte);
  2547. data.typ:=datatypemap[kind];
  2548. case data.typ of
  2549. sd_none: ;
  2550. sd_string:
  2551. begin
  2552. data.name:=stringdup(ppufile.getstring);
  2553. data.flags:=ppufile.getbyte;
  2554. end;
  2555. sd_reg,sd_offset,sd_regoffset:
  2556. begin
  2557. ppufile.getdata(data.reg,sizeof(TRegister));
  2558. data.offset:=ppufile.getdword;
  2559. end;
  2560. else
  2561. InternalError(2011091201);
  2562. end;
  2563. end;
  2564. destructor tai_seh_directive.destroy;
  2565. begin
  2566. if data.typ=sd_string then
  2567. stringdispose(data.name);
  2568. inherited destroy;
  2569. end;
  2570. procedure tai_seh_directive.ppuwrite(ppufile:tcompilerppufile);
  2571. begin
  2572. inherited ppuwrite(ppufile);
  2573. ppufile.putbyte(ord(kind));
  2574. case data.typ of
  2575. sd_none: ;
  2576. sd_string:
  2577. begin
  2578. ppufile.putstring(data.name^);
  2579. ppufile.putbyte(data.flags);
  2580. end;
  2581. sd_reg,sd_offset,sd_regoffset:
  2582. begin
  2583. ppufile.putdata(data.reg,sizeof(TRegister));
  2584. ppufile.putdword(data.offset);
  2585. end;
  2586. else
  2587. InternalError(2011091202);
  2588. end;
  2589. end;
  2590. procedure tai_seh_directive.generate_code(objdata:TObjData);
  2591. begin
  2592. end;
  2593. {$ifdef JVM}
  2594. {****************************************************************************
  2595. tai_jvar
  2596. ****************************************************************************}
  2597. constructor tai_jvar.Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
  2598. begin
  2599. Inherited create;
  2600. typ:=ait_jvar;
  2601. stackslot:=_stackslot;
  2602. desc:=stringdup(_desc);
  2603. startlab:=_startlab;
  2604. stoplab:=_stoplab;
  2605. end;
  2606. constructor tai_jvar.ppuload(t: taitype; ppufile: tcompilerppufile);
  2607. begin
  2608. inherited ppuload(t, ppufile);
  2609. stackslot:=ppufile.getlongint;
  2610. desc:=stringdup(ppufile.getstring);
  2611. startlab:=ppufile.getasmsymbol;
  2612. stoplab:=ppufile.getasmsymbol;
  2613. end;
  2614. procedure tai_jvar.ppuwrite(ppufile: tcompilerppufile);
  2615. begin
  2616. inherited ppuwrite(ppufile);
  2617. ppufile.putlongint(stackslot);
  2618. ppufile.putstring(desc^);
  2619. ppufile.putasmsymbol(startlab);
  2620. ppufile.putasmsymbol(stoplab);
  2621. end;
  2622. destructor tai_jvar.destroy;
  2623. begin
  2624. stringdispose(desc);
  2625. inherited destroy;
  2626. end;
  2627. {****************************************************************************
  2628. tai_jcatch
  2629. ****************************************************************************}
  2630. constructor tai_jcatch.Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
  2631. begin
  2632. Inherited create;
  2633. typ:=ait_jcatch;
  2634. name:=stringdup(_name);
  2635. startlab:=_startlab;
  2636. startlab.increfs;
  2637. stoplab:=_stoplab;
  2638. stoplab.increfs;
  2639. handlerlab:=_handlerlab;
  2640. handlerlab.increfs;
  2641. end;
  2642. destructor tai_jcatch.destroy;
  2643. begin
  2644. stringdispose(name);
  2645. inherited destroy;
  2646. end;
  2647. constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
  2648. begin
  2649. inherited ppuload(t, ppufile);
  2650. name:=stringdup(ppufile.getstring);
  2651. startlab:=ppufile.getasmsymbol;
  2652. startlab.increfs;
  2653. stoplab:=ppufile.getasmsymbol;
  2654. stoplab.increfs;
  2655. handlerlab:=ppufile.getasmsymbol;
  2656. handlerlab.increfs;
  2657. end;
  2658. procedure tai_jcatch.ppuwrite(ppufile: tcompilerppufile);
  2659. begin
  2660. inherited ppuwrite(ppufile);
  2661. ppufile.putstring(name^);
  2662. ppufile.putasmsymbol(startlab);
  2663. ppufile.putasmsymbol(stoplab);
  2664. ppufile.putasmsymbol(handlerlab);
  2665. end;
  2666. {$endif JVM}
  2667. begin
  2668. {$push}{$warnings off}
  2669. { taitype should fit into a 4 byte set for speed reasons }
  2670. if ord(high(taitype))>31 then
  2671. internalerror(201108181);
  2672. {$pop}
  2673. end.