aasmtai.pas 88 KB

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