aasmtai.pas 91 KB

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