aasmtai.pas 90 KB

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