aasmtai.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380
  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 overriden 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,globals,systems,
  28. cpuinfo,cpubase,
  29. cgbase,cgutils,
  30. symtype,
  31. aasmbase,aasmdata,ogbase;
  32. type
  33. { keep the number of elements in this enumeration less or equal than 32 as long
  34. as FPC knows only 4 byte and 32 byte sets (FK) }
  35. taitype = (
  36. ait_none,
  37. ait_align,
  38. ait_section,
  39. ait_comment,
  40. ait_string,
  41. ait_instruction,
  42. ait_datablock,
  43. ait_symbol,
  44. { needed to calc the size of a symbol }
  45. ait_symbol_end,
  46. ait_directive,
  47. ait_label,
  48. ait_const,
  49. ait_real_32bit,
  50. ait_real_64bit,
  51. ait_real_80bit,
  52. ait_comp_64bit,
  53. ait_real_128bit,
  54. ait_stab,
  55. ait_force_line,
  56. ait_function_name,
  57. {$ifdef alpha}
  58. { the follow is for the DEC Alpha }
  59. ait_frame,
  60. ait_ent,
  61. {$endif alpha}
  62. {$ifdef ia64}
  63. ait_bundle,
  64. ait_stop,
  65. {$endif ia64}
  66. {$ifdef m68k}
  67. ait_labeled_instruction,
  68. {$endif m68k}
  69. { used to split into tiny assembler files }
  70. ait_cutobject,
  71. ait_regalloc,
  72. ait_tempalloc,
  73. { used to mark assembler blocks and inlined functions }
  74. ait_marker
  75. );
  76. taiconst_type = (
  77. aitconst_128bit,
  78. aitconst_64bit,
  79. aitconst_32bit,
  80. aitconst_16bit,
  81. aitconst_8bit,
  82. aitconst_sleb128bit,
  83. aitconst_uleb128bit,
  84. { win32 only }
  85. aitconst_rva_symbol,
  86. aitconst_secrel32_symbol,
  87. { darwin only }
  88. aitconst_indirect_symbol
  89. );
  90. const
  91. {$ifdef cpu64bit}
  92. aitconst_aint = aitconst_64bit;
  93. aitconst_ptr = aitconst_64bit;
  94. {$else cpu64bit}
  95. aitconst_aint = aitconst_32bit;
  96. aitconst_ptr = aitconst_32bit;
  97. {$endif cpu64bit}
  98. taitypestr : array[taitype] of string[24] = (
  99. '<none>',
  100. 'align',
  101. 'section',
  102. 'comment',
  103. 'string',
  104. 'instruction',
  105. 'datablock',
  106. 'symbol',
  107. 'symbol_end',
  108. 'symbol_directive',
  109. 'label',
  110. 'const',
  111. 'real_32bit',
  112. 'real_64bit',
  113. 'real_80bit',
  114. 'comp_64bit',
  115. 'real_128bit',
  116. 'stab',
  117. 'force_line',
  118. 'function_name',
  119. {$ifdef alpha}
  120. { the follow is for the DEC Alpha }
  121. 'frame',
  122. 'ent',
  123. {$endif alpha}
  124. {$ifdef ia64}
  125. 'bundle',
  126. 'stop',
  127. {$endif ia64}
  128. {$ifdef m68k}
  129. 'labeled_instr',
  130. {$endif m68k}
  131. 'cut',
  132. 'regalloc',
  133. 'tempalloc',
  134. 'marker'
  135. );
  136. type
  137. { Types of operand }
  138. toptype=(top_none,top_reg,top_ref,top_const,top_bool,top_local
  139. {$ifdef arm}
  140. { ARM only }
  141. ,top_regset
  142. ,top_shifterop
  143. {$endif arm}
  144. {$ifdef m68k}
  145. { m68k only }
  146. ,top_regset
  147. {$endif m68k}
  148. { i386 only});
  149. { kinds of operations that an instruction can perform on an operand }
  150. topertype = (operand_read,operand_write,operand_readwrite);
  151. tlocaloper = record
  152. localsym : pointer;
  153. localsymderef : tderef;
  154. localsymofs : longint;
  155. localindexreg : tregister;
  156. localscale : byte;
  157. localgetoffset,
  158. localforceref : boolean
  159. end;
  160. plocaloper = ^tlocaloper;
  161. { please keep the size of this record <=12 bytes and keep it properly aligned }
  162. toper = record
  163. ot : longint;
  164. case typ : toptype of
  165. top_none : ();
  166. top_reg : (reg:tregister);
  167. top_ref : (ref:preference);
  168. top_const : (val:aint);
  169. top_bool : (b:boolean);
  170. { local varsym that will be inserted in pass_generate_code }
  171. top_local : (localoper:plocaloper);
  172. {$ifdef arm}
  173. top_regset : (regset:^tcpuregisterset);
  174. top_shifterop : (shifterop : pshifterop);
  175. {$endif arm}
  176. {$ifdef m68k}
  177. top_regset : (regset:^tcpuregisterset);
  178. {$endif m68k}
  179. end;
  180. poper=^toper;
  181. const
  182. { ait_* types which don't result in executable code or which don't influence
  183. the way the program runs/behaves, but which may be encountered by the
  184. optimizer (= if it's sometimes added to the exprasm list). Update if you add
  185. a new ait type! }
  186. SkipInstr = [ait_comment, ait_symbol,ait_section
  187. ,ait_stab, ait_function_name, ait_force_line
  188. ,ait_regalloc, ait_tempalloc, ait_symbol_end, ait_directive];
  189. { ait_* types which do not have line information (and hence which are of type
  190. tai, otherwise, they are of type tailineinfo }
  191. SkipLineInfo =[ait_label,
  192. ait_regalloc,ait_tempalloc,
  193. ait_stab,ait_function_name,
  194. ait_cutobject,ait_marker,ait_align,ait_section,ait_comment,
  195. ait_const,
  196. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_real_128bit,
  197. ait_symbol
  198. ];
  199. type
  200. { cut type, required for alphanumeric ordering of the assembler filenames }
  201. TCutPlace=(cut_normal,cut_begin,cut_end);
  202. TAsmMarker = (
  203. mark_NoPropInfoStart,mark_NoPropInfoEnd,
  204. mark_AsmBlockStart,mark_AsmBlockEnd,
  205. mark_InlineStart,mark_InlineEnd,mark_BlockStart,
  206. mark_Position
  207. );
  208. TRegAllocType = (ra_alloc,ra_dealloc,ra_sync,ra_resize);
  209. TStabType = (stab_stabs,stab_stabn,stab_stabd);
  210. TAsmDirective=(
  211. asd_non_lazy_symbol_pointer,asd_indirect_symbol,asd_lazy_symbol_pointer,
  212. asd_extern,asd_nasm_import, asd_toc_entry, asd_mod_init_func, asd_mod_term_func,
  213. asd_reference,asd_no_dead_strip
  214. );
  215. const
  216. regallocstr : array[tregalloctype] of string[10]=('allocated','released','sync','resized');
  217. tempallocstr : array[boolean] of string[10]=('released','allocated');
  218. stabtypestr : array[TStabType] of string[5]=('stabs','stabn','stabd');
  219. directivestr : array[TAsmDirective] of string[23]=(
  220. 'non_lazy_symbol_pointer','indirect_symbol','lazy_symbol_pointer',
  221. 'extern','nasm_import', 'tc', 'mod_init_func', 'mod_term_func', 'reference',
  222. 'no_dead_strip'
  223. );
  224. type
  225. { abstract assembler item }
  226. tai = class(TLinkedListItem)
  227. {$ifndef NOOPT}
  228. { pointer to record with optimizer info about this tai object }
  229. optinfo : pointer;
  230. {$endif NOOPT}
  231. typ : taitype;
  232. constructor Create;
  233. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  234. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  235. procedure buildderefimpl;virtual;
  236. procedure derefimpl;virtual;
  237. end;
  238. { abstract assembler item with line information }
  239. tailineinfo = class(tai)
  240. fileinfo : tfileposinfo;
  241. constructor Create;
  242. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  243. procedure ppuwrite(ppufile:tcompilerppufile);override;
  244. end;
  245. tai_simple = class(tai)
  246. constructor create(_typ : taitype);
  247. end;
  248. taiclass = class of tai;
  249. taiclassarray = array[taitype] of taiclass;
  250. { Generates an assembler string }
  251. tai_string = class(tailineinfo)
  252. str : pchar;
  253. { extra len so the string can contain an \0 }
  254. len : longint;
  255. constructor Create(const _str : string);
  256. constructor Create_pchar(_str : pchar;length : longint);
  257. destructor Destroy;override;
  258. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  259. procedure ppuwrite(ppufile:tcompilerppufile);override;
  260. function getcopy:tlinkedlistitem;override;
  261. end;
  262. { Generates a common label }
  263. tai_symbol = class(tai)
  264. is_global : boolean;
  265. sym : tasmsymbol;
  266. size : longint;
  267. constructor Create(_sym:tasmsymbol;siz:longint);
  268. constructor Create_Global(_sym:tasmsymbol;siz:longint);
  269. constructor Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  270. constructor Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  271. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  272. procedure ppuwrite(ppufile:tcompilerppufile);override;
  273. procedure derefimpl;override;
  274. end;
  275. tai_symbol_end = class(tailineinfo)
  276. sym : tasmsymbol;
  277. constructor Create(_sym:tasmsymbol);
  278. constructor Createname(const _name : string);
  279. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  280. procedure ppuwrite(ppufile:tcompilerppufile);override;
  281. procedure derefimpl;override;
  282. end;
  283. tai_directive = class(tailineinfo)
  284. name : pshortstring;
  285. directive : TAsmDirective;
  286. constructor Create(_directive:TAsmDirective;const _name:string);
  287. destructor Destroy;override;
  288. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  289. procedure ppuwrite(ppufile:tcompilerppufile);override;
  290. end;
  291. { Generates an assembler label }
  292. tai_label = class(tai)
  293. is_global : boolean;
  294. labsym : tasmlabel;
  295. constructor Create(_labsym : tasmlabel);
  296. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  297. procedure ppuwrite(ppufile:tcompilerppufile);override;
  298. procedure derefimpl;override;
  299. end;
  300. { Generates an assembler comment }
  301. tai_comment = class(tai)
  302. str : pchar;
  303. constructor Create(_str : pchar);
  304. destructor Destroy; override;
  305. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  306. procedure ppuwrite(ppufile:tcompilerppufile);override;
  307. function getcopy:tlinkedlistitem;override;
  308. end;
  309. { Generates a section / segment directive }
  310. tai_section = class(tai)
  311. sectype : TAsmSectiontype;
  312. secorder : TasmSectionorder;
  313. secalign : byte;
  314. name : pshortstring;
  315. sec : TObjSection; { used in binary writer }
  316. constructor Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  317. destructor Destroy;override;
  318. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  319. procedure ppuwrite(ppufile:tcompilerppufile);override;
  320. end;
  321. { Generates an uninitializised data block }
  322. tai_datablock = class(tailineinfo)
  323. is_global : boolean;
  324. sym : tasmsymbol;
  325. size : aint;
  326. constructor Create(const _name : string;_size : aint);
  327. constructor Create_global(const _name : string;_size : aint);
  328. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  329. procedure ppuwrite(ppufile:tcompilerppufile);override;
  330. procedure derefimpl;override;
  331. end;
  332. { Generates an integer const }
  333. tai_const = class(tai)
  334. sym,
  335. endsym : tasmsymbol;
  336. value : int64;
  337. consttype : taiconst_type;
  338. { we use for the 128bit int64/qword for now because I can't imagine a
  339. case where we need 128 bit now (FK) }
  340. constructor Create(_typ:taiconst_type;_value : int64);
  341. constructor Create_128bit(_value : int64);
  342. constructor Create_64bit(_value : int64);
  343. constructor Create_32bit(_value : longint);
  344. constructor Create_16bit(_value : word);
  345. constructor Create_8bit(_value : byte);
  346. constructor Create_sleb128bit(_value : int64);
  347. constructor Create_uleb128bit(_value : qword);
  348. constructor Create_aint(_value : aint);
  349. constructor Create_sym(_sym:tasmsymbol);
  350. constructor Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  351. constructor Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  352. constructor Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  353. constructor Create_rva_sym(_sym:tasmsymbol);
  354. constructor Create_indirect_sym(_sym:tasmsymbol);
  355. constructor Createname(const name:string;ofs:aint);
  356. constructor Createname_rva(const name:string);
  357. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  358. procedure ppuwrite(ppufile:tcompilerppufile);override;
  359. procedure derefimpl;override;
  360. function getcopy:tlinkedlistitem;override;
  361. function size:longint;
  362. end;
  363. { Generates a single float (32 bit real) }
  364. tai_real_32bit = class(tai)
  365. value : ts32real;
  366. constructor Create(_value : ts32real);
  367. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  368. procedure ppuwrite(ppufile:tcompilerppufile);override;
  369. end;
  370. tformatoptions = (fo_none,fo_hiloswapped);
  371. { Generates a double float (64 bit real) }
  372. tai_real_64bit = class(tai)
  373. value : ts64real;
  374. {$ifdef ARM}
  375. formatoptions : tformatoptions;
  376. constructor Create_hiloswapped(_value : ts64real);
  377. {$endif ARM}
  378. constructor Create(_value : ts64real);
  379. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  380. procedure ppuwrite(ppufile:tcompilerppufile);override;
  381. end;
  382. { Generates an extended float (80 bit real) }
  383. tai_real_80bit = class(tai)
  384. value : ts80real;
  385. constructor Create(_value : ts80real);
  386. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  387. procedure ppuwrite(ppufile:tcompilerppufile);override;
  388. end;
  389. { Generates an float128 (128 bit real) }
  390. tai_real_128bit = class(tai)
  391. value : ts128real;
  392. constructor Create(_value : ts128real);
  393. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  394. procedure ppuwrite(ppufile:tcompilerppufile);override;
  395. end;
  396. { Generates a comp int (integer over 64 bits)
  397. This is Intel 80x86 specific, and is not
  398. really supported on other processors.
  399. }
  400. tai_comp_64bit = class(tai)
  401. value : ts64comp;
  402. constructor Create(_value : ts64comp);
  403. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  404. procedure ppuwrite(ppufile:tcompilerppufile);override;
  405. end;
  406. tai_stab = class(tai)
  407. str : pchar;
  408. stabtype : TStabType;
  409. constructor Create(_stabtype:TStabType;_str : pchar);
  410. constructor Create_str(_stabtype:TStabType;const s:string);
  411. destructor Destroy;override;
  412. end;
  413. tai_force_line = class(tailineinfo)
  414. constructor Create;
  415. end;
  416. tai_function_name = class(tai)
  417. funcname : pshortstring;
  418. constructor create(const s:string);
  419. destructor destroy;override;
  420. end;
  421. { Insert a cut to split assembler into several smaller files }
  422. tai_cutobject = class(tai)
  423. place : tcutplace;
  424. constructor Create;
  425. constructor Create_begin;
  426. constructor Create_end;
  427. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  428. procedure ppuwrite(ppufile:tcompilerppufile);override;
  429. end;
  430. { Insert a marker for assembler and inline blocks }
  431. tai_marker = class(tai)
  432. Kind: TAsmMarker;
  433. Constructor Create(_Kind: TAsmMarker);
  434. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  435. procedure ppuwrite(ppufile:tcompilerppufile);override;
  436. end;
  437. tai_tempalloc = class(tai)
  438. allocation : boolean;
  439. {$ifdef EXTDEBUG}
  440. problem : pshortstring;
  441. {$endif EXTDEBUG}
  442. temppos,
  443. tempsize : longint;
  444. constructor alloc(pos,size:longint);
  445. constructor dealloc(pos,size:longint);
  446. {$ifdef EXTDEBUG}
  447. constructor allocinfo(pos,size:longint;const st:string);
  448. {$endif EXTDEBUG}
  449. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  450. destructor destroy;override;
  451. procedure ppuwrite(ppufile:tcompilerppufile);override;
  452. end;
  453. tai_regalloc = class(tai)
  454. reg : tregister;
  455. ratype : TRegAllocType;
  456. { reg(de)alloc belongs to this instruction, this
  457. is only used for automatic inserted (de)alloc for
  458. imaginary register and required for spilling code }
  459. instr : tai;
  460. constructor alloc(r : tregister;ainstr:tai);
  461. constructor dealloc(r : tregister;ainstr:tai);
  462. constructor sync(r : tregister);
  463. constructor resize(r : tregister);
  464. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  465. procedure ppuwrite(ppufile:tcompilerppufile);override;
  466. end;
  467. tadd_reg_instruction_proc=procedure(instr:Tai;r:tregister) of object;
  468. { Class template for assembler instructions
  469. }
  470. tai_cpu_abstract = class(tailineinfo)
  471. protected
  472. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;
  473. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;
  474. procedure ppubuildderefimploper(var o:toper);virtual;abstract;
  475. procedure ppuderefoper(var o:toper);virtual;abstract;
  476. public
  477. { Condition flags for instruction }
  478. condition : TAsmCond;
  479. { Number of operands to instruction }
  480. ops : byte;
  481. { Number of allocate oper structures }
  482. opercnt : byte;
  483. { Operands of instruction }
  484. oper : array[0..max_operands-1] of poper;
  485. { Actual opcode of instruction }
  486. opcode : tasmop;
  487. {$ifdef x86}
  488. segprefix : tregister;
  489. {$endif x86}
  490. { true if instruction is a jmp }
  491. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  492. Constructor Create(op : tasmop);virtual;
  493. Destructor Destroy;override;
  494. function getcopy:TLinkedListItem;override;
  495. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  496. procedure ppuwrite(ppufile:tcompilerppufile);override;
  497. procedure buildderefimpl;override;
  498. procedure derefimpl;override;
  499. procedure SetCondition(const c:TAsmCond);
  500. procedure allocate_oper(opers:longint);
  501. procedure loadconst(opidx:longint;l:aint);
  502. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  503. procedure loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  504. procedure loadref(opidx:longint;const r:treference);
  505. procedure loadreg(opidx:longint;r:tregister);
  506. procedure loadoper(opidx:longint;o:toper);
  507. procedure clearop(opidx:longint);
  508. procedure freeop(opidx:longint);
  509. { register allocator }
  510. function is_same_reg_move(regtype: Tregistertype):boolean;virtual;
  511. function spilling_get_operation_type(opnr: longint): topertype;virtual;
  512. function spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;virtual;
  513. function Pass1(objdata:TObjData):longint;virtual;
  514. procedure Pass2(objdata:TObjData);virtual;
  515. procedure resetpass1; virtual;
  516. procedure resetpass2; virtual;
  517. end;
  518. tai_cpu_class = class of tai_cpu_abstract;
  519. { Buffer type used for alignment }
  520. tfillbuffer = array[0..63] of char;
  521. { alignment for operator }
  522. tai_align_abstract = class(tai)
  523. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  524. fillsize : byte; { real size to fill }
  525. fillop : byte; { value to fill with - optional }
  526. use_op : boolean;
  527. constructor Create(b:byte);virtual;
  528. constructor Create_op(b: byte; _op: byte);virtual;
  529. constructor Create_zeros(b:byte);
  530. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  531. procedure ppuwrite(ppufile:tcompilerppufile);override;
  532. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  533. end;
  534. tai_align_class = class of tai_align_abstract;
  535. var
  536. { array with all class types for tais }
  537. aiclass : taiclassarray;
  538. { target specific tais }
  539. cai_align : tai_align_class;
  540. cai_cpu : tai_cpu_class;
  541. { hook to notify uses of registers }
  542. add_reg_instruction_hook : tadd_reg_instruction_proc;
  543. procedure maybe_new_object_file(list:TAsmList);
  544. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  545. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  546. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  547. procedure section_symbol_end(list:TAsmList;const Aname:string);
  548. function ppuloadai(ppufile:tcompilerppufile):tai;
  549. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  550. implementation
  551. uses
  552. SysUtils,
  553. verbose;
  554. const
  555. pputaimarker = 254;
  556. {****************************************************************************
  557. Helpers
  558. ****************************************************************************}
  559. procedure maybe_new_object_file(list:TAsmList);
  560. begin
  561. if (cs_create_smart in current_settings.moduleswitches) and
  562. (not use_smartlink_section) then
  563. list.concat(tai_cutobject.create);
  564. end;
  565. procedure new_section(list:TAsmList;Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  566. begin
  567. list.concat(tai_section.create(Asectype,Aname,Aalign,Asecorder));
  568. list.concat(cai_align.create(Aalign));
  569. end;
  570. procedure section_symbol_start(list:TAsmList;const Aname:string;Asymtyp:Tasmsymtype;
  571. Aglobal:boolean;Asectype:TAsmSectiontype;Aalign:byte);
  572. begin
  573. maybe_new_object_file(list);
  574. list.concat(tai_section.create(Asectype,Aname,Aalign));
  575. list.concat(cai_align.create(Aalign));
  576. if Aglobal or
  577. maybe_smartlink_symbol then
  578. list.concat(tai_symbol.createname_global(Aname,Asymtyp,0))
  579. else
  580. list.concat(tai_symbol.createname(Aname,Asymtyp,0));
  581. end;
  582. procedure section_symbol_end(list:TAsmList;const Aname:string);
  583. begin
  584. list.concat(tai_symbol_end.createname(Aname));
  585. end;
  586. function ppuloadai(ppufile:tcompilerppufile):tai;
  587. var
  588. b : byte;
  589. t : taitype;
  590. begin
  591. { marker }
  592. b:=ppufile.getbyte;
  593. if b<>pputaimarker then
  594. internalerror(200208181);
  595. { load nodetype }
  596. t:=taitype(ppufile.getbyte);
  597. if t<>ait_none then
  598. begin
  599. if t>high(taitype) then
  600. internalerror(200208182);
  601. if not assigned(aiclass[t]) then
  602. internalerror(200208183);
  603. {writeln('taiload: ',taitypestr[t]);}
  604. { generate tai of the correct class }
  605. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  606. end
  607. else
  608. ppuloadai:=nil;
  609. end;
  610. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  611. begin
  612. { marker, read by ppuloadnode }
  613. ppufile.putbyte(pputaimarker);
  614. if assigned(n) then
  615. begin
  616. { type, read by ppuloadnode }
  617. ppufile.putbyte(byte(n.typ));
  618. {writeln('taiwrite: ',taitypestr[n.typ]);}
  619. n.ppuwrite(ppufile);
  620. end
  621. else
  622. ppufile.putbyte(byte(ait_none));
  623. end;
  624. {****************************************************************************
  625. TAI
  626. ****************************************************************************}
  627. constructor tai.Create;
  628. begin
  629. {$ifndef NOOPT}
  630. optinfo:=nil;
  631. {$endif NOOPT}
  632. end;
  633. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  634. begin
  635. typ:=t;
  636. {$ifndef NOOPT}
  637. optinfo:=nil;
  638. {$endif}
  639. end;
  640. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  641. begin
  642. end;
  643. procedure tai.buildderefimpl;
  644. begin
  645. end;
  646. procedure tai.derefimpl;
  647. begin
  648. end;
  649. {****************************************************************************
  650. TAILINEINFO
  651. ****************************************************************************}
  652. constructor tailineinfo.create;
  653. begin
  654. inherited create;
  655. fileinfo:=current_filepos;
  656. end;
  657. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  658. begin
  659. inherited ppuload(t,ppufile);
  660. ppufile.getposinfo(fileinfo);
  661. end;
  662. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  663. begin
  664. inherited ppuwrite(ppufile);
  665. ppufile.putposinfo(fileinfo);
  666. end;
  667. {****************************************************************************
  668. TAI_SIMPLE
  669. ****************************************************************************}
  670. constructor tai_simple.create(_typ : taitype);
  671. begin
  672. inherited create;
  673. typ:=_typ;
  674. end;
  675. {****************************************************************************
  676. TAI_SECTION
  677. ****************************************************************************}
  678. constructor tai_section.Create(Asectype:TAsmSectiontype;Aname:string;Aalign:byte;Asecorder:TasmSectionorder=secorder_default);
  679. begin
  680. inherited Create;
  681. typ:=ait_section;
  682. sectype:=asectype;
  683. secalign:=Aalign;
  684. secorder:=Asecorder;
  685. name:=stringdup(Aname);
  686. sec:=nil;
  687. end;
  688. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  689. begin
  690. inherited ppuload(t,ppufile);
  691. sectype:=TAsmSectiontype(ppufile.getbyte);
  692. secalign:=ppufile.getbyte;
  693. name:=stringdup(ppufile.getstring);
  694. sec:=nil;
  695. end;
  696. destructor tai_section.Destroy;
  697. begin
  698. stringdispose(name);
  699. end;
  700. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  701. begin
  702. inherited ppuwrite(ppufile);
  703. ppufile.putbyte(byte(sectype));
  704. ppufile.putbyte(secalign);
  705. ppufile.putstring(name^);
  706. end;
  707. {****************************************************************************
  708. TAI_DATABLOCK
  709. ****************************************************************************}
  710. constructor tai_datablock.Create(const _name : string;_size : aint);
  711. begin
  712. inherited Create;
  713. typ:=ait_datablock;
  714. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,AT_DATA);
  715. { keep things aligned }
  716. if _size<=0 then
  717. _size:=sizeof(aint);
  718. size:=_size;
  719. is_global:=false;
  720. end;
  721. constructor tai_datablock.Create_global(const _name : string;_size : aint);
  722. begin
  723. inherited Create;
  724. typ:=ait_datablock;
  725. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,AT_DATA);
  726. { keep things aligned }
  727. if _size<=0 then
  728. _size:=sizeof(aint);
  729. size:=_size;
  730. is_global:=true;
  731. end;
  732. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  733. begin
  734. inherited Create;
  735. sym:=ppufile.getasmsymbol;
  736. size:=ppufile.getaint;
  737. is_global:=boolean(ppufile.getbyte);
  738. end;
  739. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  740. begin
  741. inherited ppuwrite(ppufile);
  742. ppufile.putasmsymbol(sym);
  743. ppufile.putaint(size);
  744. ppufile.putbyte(byte(is_global));
  745. end;
  746. procedure tai_datablock.derefimpl;
  747. begin
  748. end;
  749. {****************************************************************************
  750. TAI_SYMBOL
  751. ****************************************************************************}
  752. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  753. begin
  754. inherited Create;
  755. typ:=ait_symbol;
  756. sym:=_sym;
  757. size:=siz;
  758. sym.bind:=AB_LOCAL;
  759. is_global:=false;
  760. end;
  761. constructor tai_symbol.Create_global(_sym:tasmsymbol;siz:longint);
  762. begin
  763. inherited Create;
  764. typ:=ait_symbol;
  765. sym:=_sym;
  766. size:=siz;
  767. sym.bind:=AB_GLOBAL;
  768. is_global:=true;
  769. end;
  770. constructor tai_symbol.Createname(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  771. begin
  772. inherited Create;
  773. typ:=ait_symbol;
  774. sym:=current_asmdata.DefineAsmSymbol(_name,AB_LOCAL,_symtyp);
  775. size:=siz;
  776. is_global:=false;
  777. end;
  778. constructor tai_symbol.Createname_global(const _name : string;_symtyp:Tasmsymtype;siz:longint);
  779. begin
  780. inherited Create;
  781. typ:=ait_symbol;
  782. sym:=current_asmdata.DefineAsmSymbol(_name,AB_GLOBAL,_symtyp);
  783. size:=siz;
  784. is_global:=true;
  785. end;
  786. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  787. begin
  788. inherited ppuload(t,ppufile);
  789. sym:=ppufile.getasmsymbol;
  790. size:=ppufile.getlongint;
  791. is_global:=boolean(ppufile.getbyte);
  792. end;
  793. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  794. begin
  795. inherited ppuwrite(ppufile);
  796. ppufile.putasmsymbol(sym);
  797. ppufile.putlongint(size);
  798. ppufile.putbyte(byte(is_global));
  799. end;
  800. procedure tai_symbol.derefimpl;
  801. begin
  802. end;
  803. {****************************************************************************
  804. TAI_SYMBOL_END
  805. ****************************************************************************}
  806. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  807. begin
  808. inherited Create;
  809. typ:=ait_symbol_end;
  810. sym:=_sym;
  811. end;
  812. constructor tai_symbol_end.Createname(const _name : string);
  813. begin
  814. inherited Create;
  815. typ:=ait_symbol_end;
  816. sym:=current_asmdata.RefAsmSymbol(_name);
  817. end;
  818. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  819. begin
  820. inherited ppuload(t,ppufile);
  821. sym:=ppufile.getasmsymbol;
  822. end;
  823. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  824. begin
  825. inherited ppuwrite(ppufile);
  826. ppufile.putasmsymbol(sym);
  827. end;
  828. procedure tai_symbol_end.derefimpl;
  829. begin
  830. end;
  831. {****************************************************************************
  832. TAI_SYMBOL_END
  833. ****************************************************************************}
  834. constructor tai_directive.Create(_directive:TAsmDirective;const _name:string);
  835. begin
  836. inherited Create;
  837. typ:=ait_directive;
  838. name:=stringdup(_name);
  839. directive:=_directive;
  840. end;
  841. destructor tai_directive.Destroy;
  842. begin
  843. stringdispose(name);
  844. end;
  845. constructor tai_directive.ppuload(t:taitype;ppufile:tcompilerppufile);
  846. begin
  847. inherited ppuload(t,ppufile);
  848. name:=stringdup(ppufile.getstring);
  849. directive:=TAsmDirective(ppufile.getbyte);
  850. end;
  851. procedure tai_directive.ppuwrite(ppufile:tcompilerppufile);
  852. begin
  853. inherited ppuwrite(ppufile);
  854. ppufile.putstring(name^);
  855. ppufile.putbyte(byte(directive));
  856. end;
  857. {****************************************************************************
  858. TAI_CONST
  859. ****************************************************************************}
  860. constructor tai_const.Create(_typ:taiconst_type;_value : int64);
  861. begin
  862. inherited Create;
  863. typ:=ait_const;
  864. consttype:=_typ;
  865. value:=_value;
  866. sym:=nil;
  867. endsym:=nil;
  868. end;
  869. constructor tai_const.Create_128bit(_value : int64);
  870. begin
  871. inherited Create;
  872. typ:=ait_const;
  873. consttype:=aitconst_128bit;
  874. value:=_value;
  875. sym:=nil;
  876. endsym:=nil;
  877. end;
  878. constructor tai_const.Create_64bit(_value : int64);
  879. begin
  880. inherited Create;
  881. typ:=ait_const;
  882. consttype:=aitconst_64bit;
  883. value:=_value;
  884. sym:=nil;
  885. endsym:=nil;
  886. end;
  887. constructor tai_const.Create_32bit(_value : longint);
  888. begin
  889. inherited Create;
  890. typ:=ait_const;
  891. consttype:=aitconst_32bit;
  892. value:=_value;
  893. sym:=nil;
  894. endsym:=nil;
  895. end;
  896. constructor tai_const.Create_16bit(_value : word);
  897. begin
  898. inherited Create;
  899. typ:=ait_const;
  900. consttype:=aitconst_16bit;
  901. value:=_value;
  902. sym:=nil;
  903. endsym:=nil;
  904. end;
  905. constructor tai_const.Create_8bit(_value : byte);
  906. begin
  907. inherited Create;
  908. typ:=ait_const;
  909. consttype:=aitconst_8bit;
  910. value:=_value;
  911. sym:=nil;
  912. endsym:=nil;
  913. end;
  914. constructor tai_const.Create_sleb128bit(_value : int64);
  915. begin
  916. inherited Create;
  917. typ:=ait_const;
  918. consttype:=aitconst_sleb128bit;
  919. value:=_value;
  920. sym:=nil;
  921. endsym:=nil;
  922. end;
  923. constructor tai_const.Create_uleb128bit(_value : qword);
  924. begin
  925. inherited Create;
  926. typ:=ait_const;
  927. consttype:=aitconst_uleb128bit;
  928. value:=int64(_value);
  929. sym:=nil;
  930. endsym:=nil;
  931. end;
  932. constructor tai_const.Create_aint(_value : aint);
  933. begin
  934. inherited Create;
  935. typ:=ait_const;
  936. consttype:=aitconst_aint;
  937. value:=_value;
  938. sym:=nil;
  939. endsym:=nil;
  940. end;
  941. constructor tai_const.Create_type_sym(_typ:taiconst_type;_sym:tasmsymbol);
  942. begin
  943. inherited Create;
  944. typ:=ait_const;
  945. consttype:=_typ;
  946. sym:=_sym;
  947. endsym:=nil;
  948. value:=0;
  949. { update sym info }
  950. if assigned(sym) then
  951. sym.increfs;
  952. end;
  953. constructor tai_const.Create_sym(_sym:tasmsymbol);
  954. begin
  955. inherited Create;
  956. typ:=ait_const;
  957. consttype:=aitconst_ptr;
  958. { sym is allowed to be nil, this is used to write nil pointers }
  959. sym:=_sym;
  960. endsym:=nil;
  961. value:=0;
  962. { update sym info }
  963. if assigned(sym) then
  964. sym.increfs;
  965. end;
  966. constructor tai_const.Create_sym_offset(_sym:tasmsymbol;ofs:aint);
  967. begin
  968. inherited Create;
  969. typ:=ait_const;
  970. consttype:=aitconst_ptr;
  971. if not assigned(_sym) then
  972. internalerror(200404121);
  973. sym:=_sym;
  974. endsym:=nil;
  975. value:=ofs;
  976. { update sym info }
  977. sym.increfs;
  978. end;
  979. constructor tai_const.Create_rel_sym(_typ:taiconst_type;_sym,_endsym:tasmsymbol);
  980. begin
  981. inherited Create;
  982. typ:=ait_const;
  983. consttype:=_typ;
  984. sym:=_sym;
  985. endsym:=_endsym;
  986. value:=0;
  987. { update sym info }
  988. sym.increfs;
  989. endsym.increfs;
  990. end;
  991. constructor tai_const.Create_rva_sym(_sym:tasmsymbol);
  992. begin
  993. inherited Create;
  994. typ:=ait_const;
  995. consttype:=aitconst_rva_symbol;
  996. sym:=_sym;
  997. endsym:=nil;
  998. value:=0;
  999. { update sym info }
  1000. sym.increfs;
  1001. end;
  1002. constructor tai_const.Create_indirect_sym(_sym:tasmsymbol);
  1003. begin
  1004. inherited Create;
  1005. typ:=ait_const;
  1006. consttype:=aitconst_indirect_symbol;
  1007. sym:=_sym;
  1008. endsym:=nil;
  1009. value:=0;
  1010. { update sym info }
  1011. sym.increfs;
  1012. end;
  1013. constructor tai_const.Createname(const name:string;ofs:aint);
  1014. begin
  1015. inherited Create;
  1016. typ:=ait_const;
  1017. consttype:=aitconst_ptr;
  1018. sym:=current_asmdata.RefAsmSymbol(name);
  1019. endsym:=nil;
  1020. value:=ofs;
  1021. { update sym info }
  1022. sym.increfs;
  1023. end;
  1024. constructor tai_const.Createname_rva(const name:string);
  1025. begin
  1026. inherited Create;
  1027. typ:=ait_const;
  1028. consttype:=aitconst_rva_symbol;
  1029. sym:=current_asmdata.RefAsmSymbol(name);
  1030. endsym:=nil;
  1031. value:=0;
  1032. { update sym info }
  1033. sym.increfs;
  1034. end;
  1035. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  1036. begin
  1037. inherited ppuload(t,ppufile);
  1038. consttype:=taiconst_type(ppufile.getbyte);
  1039. sym:=ppufile.getasmsymbol;
  1040. endsym:=ppufile.getasmsymbol;
  1041. value:=ppufile.getint64;
  1042. end;
  1043. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  1044. begin
  1045. inherited ppuwrite(ppufile);
  1046. ppufile.putbyte(byte(consttype));
  1047. ppufile.putasmsymbol(sym);
  1048. ppufile.putasmsymbol(endsym);
  1049. ppufile.putint64(value);
  1050. end;
  1051. procedure tai_const.derefimpl;
  1052. begin
  1053. end;
  1054. function tai_const.getcopy:tlinkedlistitem;
  1055. begin
  1056. getcopy:=inherited getcopy;
  1057. { we need to increase the reference number }
  1058. sym.increfs;
  1059. if assigned(endsym) then
  1060. endsym.increfs;
  1061. end;
  1062. function tai_const.size:longint;
  1063. begin
  1064. case consttype of
  1065. aitconst_8bit :
  1066. result:=1;
  1067. aitconst_16bit :
  1068. result:=2;
  1069. aitconst_32bit :
  1070. result:=4;
  1071. aitconst_64bit :
  1072. result:=8;
  1073. aitconst_indirect_symbol,
  1074. aitconst_secrel32_symbol,
  1075. aitconst_rva_symbol :
  1076. if target_info.system=system_x86_64_win64 then
  1077. result:=sizeof(longint)
  1078. else
  1079. result:=sizeof(aint);
  1080. aitconst_uleb128bit :
  1081. result:=LengthUleb128(qword(value));
  1082. aitconst_sleb128bit :
  1083. result:=LengthSleb128(value);
  1084. else
  1085. internalerror(200603253);
  1086. end;
  1087. end;
  1088. {****************************************************************************
  1089. TAI_real_32bit
  1090. ****************************************************************************}
  1091. constructor tai_real_32bit.Create(_value : ts32real);
  1092. begin
  1093. inherited Create;
  1094. typ:=ait_real_32bit;
  1095. value:=_value;
  1096. end;
  1097. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1098. begin
  1099. inherited ppuload(t,ppufile);
  1100. value:=ppufile.getreal;
  1101. end;
  1102. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  1103. begin
  1104. inherited ppuwrite(ppufile);
  1105. ppufile.putreal(value);
  1106. end;
  1107. {****************************************************************************
  1108. TAI_real_64bit
  1109. ****************************************************************************}
  1110. constructor tai_real_64bit.Create(_value : ts64real);
  1111. begin
  1112. inherited Create;
  1113. typ:=ait_real_64bit;
  1114. value:=_value;
  1115. end;
  1116. {$ifdef ARM}
  1117. constructor tai_real_64bit.Create_hiloswapped(_value : ts64real);
  1118. begin
  1119. inherited Create;
  1120. typ:=ait_real_64bit;
  1121. value:=_value;
  1122. formatoptions:=fo_hiloswapped;
  1123. end;
  1124. {$endif ARM}
  1125. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1126. begin
  1127. inherited ppuload(t,ppufile);
  1128. value:=ppufile.getreal;
  1129. {$ifdef ARM}
  1130. formatoptions:=tformatoptions(ppufile.getbyte);
  1131. {$endif ARM}
  1132. end;
  1133. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  1134. begin
  1135. inherited ppuwrite(ppufile);
  1136. ppufile.putreal(value);
  1137. {$ifdef ARM}
  1138. ppufile.putbyte(byte(formatoptions));
  1139. {$endif ARM}
  1140. end;
  1141. {****************************************************************************
  1142. TAI_real_80bit
  1143. ****************************************************************************}
  1144. constructor tai_real_80bit.Create(_value : ts80real);
  1145. begin
  1146. inherited Create;
  1147. typ:=ait_real_80bit;
  1148. value:=_value;
  1149. end;
  1150. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1151. begin
  1152. inherited ppuload(t,ppufile);
  1153. value:=ppufile.getreal;
  1154. end;
  1155. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  1156. begin
  1157. inherited ppuwrite(ppufile);
  1158. ppufile.putreal(value);
  1159. end;
  1160. {****************************************************************************
  1161. TAI_real_80bit
  1162. ****************************************************************************}
  1163. constructor tai_real_128bit.Create(_value : ts128real);
  1164. begin
  1165. inherited Create;
  1166. typ:=ait_real_128bit;
  1167. value:=_value;
  1168. end;
  1169. constructor tai_real_128bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1170. begin
  1171. inherited ppuload(t,ppufile);
  1172. value:=ppufile.getreal;
  1173. end;
  1174. procedure tai_real_128bit.ppuwrite(ppufile:tcompilerppufile);
  1175. begin
  1176. inherited ppuwrite(ppufile);
  1177. ppufile.putreal(value);
  1178. end;
  1179. {****************************************************************************
  1180. Tai_comp_64bit
  1181. ****************************************************************************}
  1182. constructor tai_comp_64bit.Create(_value : ts64comp);
  1183. begin
  1184. inherited Create;
  1185. typ:=ait_comp_64bit;
  1186. value:=_value;
  1187. end;
  1188. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  1189. begin
  1190. inherited ppuload(t,ppufile);
  1191. ppufile.putdata(value,sizeof(value));
  1192. end;
  1193. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  1194. begin
  1195. inherited ppuwrite(ppufile);
  1196. ppufile.getdata(value,sizeof(value));
  1197. end;
  1198. {****************************************************************************
  1199. TAI_STRING
  1200. ****************************************************************************}
  1201. constructor tai_string.Create(const _str : string);
  1202. begin
  1203. inherited Create;
  1204. typ:=ait_string;
  1205. len:=length(_str);
  1206. getmem(str,len+1);
  1207. strpcopy(str,_str);
  1208. end;
  1209. constructor tai_string.Create_pchar(_str : pchar;length : longint);
  1210. begin
  1211. inherited Create;
  1212. typ:=ait_string;
  1213. str:=_str;
  1214. len:=length;
  1215. end;
  1216. destructor tai_string.destroy;
  1217. begin
  1218. if str<>nil then
  1219. freemem(str);
  1220. inherited Destroy;
  1221. end;
  1222. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  1223. begin
  1224. inherited ppuload(t,ppufile);
  1225. len:=ppufile.getlongint;
  1226. getmem(str,len);
  1227. ppufile.getdata(str^,len);
  1228. end;
  1229. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  1230. begin
  1231. inherited ppuwrite(ppufile);
  1232. ppufile.putlongint(len);
  1233. ppufile.putdata(str^,len);
  1234. end;
  1235. function tai_string.getcopy : tlinkedlistitem;
  1236. var
  1237. p : tlinkedlistitem;
  1238. begin
  1239. p:=inherited getcopy;
  1240. getmem(tai_string(p).str,len);
  1241. move(str^,tai_string(p).str^,len);
  1242. getcopy:=p;
  1243. end;
  1244. {****************************************************************************
  1245. TAI_LABEL
  1246. ****************************************************************************}
  1247. constructor tai_label.create(_labsym : tasmlabel);
  1248. begin
  1249. inherited Create;
  1250. typ:=ait_label;
  1251. labsym:=_labsym;
  1252. labsym.is_set:=true;
  1253. is_global:=(labsym.bind=AB_GLOBAL);
  1254. end;
  1255. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  1256. begin
  1257. inherited ppuload(t,ppufile);
  1258. labsym:=tasmlabel(ppufile.getasmsymbol);
  1259. is_global:=boolean(ppufile.getbyte);
  1260. end;
  1261. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  1262. begin
  1263. inherited ppuwrite(ppufile);
  1264. ppufile.putasmsymbol(labsym);
  1265. ppufile.putbyte(byte(is_global));
  1266. end;
  1267. procedure tai_label.derefimpl;
  1268. begin
  1269. labsym.is_set:=true;
  1270. end;
  1271. {****************************************************************************
  1272. tai_comment comment to be inserted in the assembler file
  1273. ****************************************************************************}
  1274. constructor tai_comment.Create(_str : pchar);
  1275. begin
  1276. inherited Create;
  1277. typ:=ait_comment;
  1278. str:=_str;
  1279. end;
  1280. destructor tai_comment.destroy;
  1281. begin
  1282. freemem(str);
  1283. inherited Destroy;
  1284. end;
  1285. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1286. var
  1287. len : longint;
  1288. begin
  1289. inherited ppuload(t,ppufile);
  1290. len:=ppufile.getlongint;
  1291. getmem(str,len+1);
  1292. ppufile.getdata(str^,len);
  1293. str[len]:=#0;
  1294. end;
  1295. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1296. var
  1297. len : longint;
  1298. begin
  1299. inherited ppuwrite(ppufile);
  1300. len:=strlen(str);
  1301. ppufile.putlongint(len);
  1302. ppufile.putdata(str^,len);
  1303. end;
  1304. function tai_comment.getcopy : tlinkedlistitem;
  1305. var
  1306. p : tlinkedlistitem;
  1307. begin
  1308. p:=inherited getcopy;
  1309. getmem(tai_comment(p).str,strlen(str)+1);
  1310. move(str^,tai_comment(p).str^,strlen(str)+1);
  1311. getcopy:=p;
  1312. end;
  1313. {****************************************************************************
  1314. TAI_STABS
  1315. ****************************************************************************}
  1316. constructor tai_stab.create(_stabtype:TStabType;_str : pchar);
  1317. begin
  1318. inherited create;
  1319. typ:=ait_stab;
  1320. str:=_str;
  1321. stabtype:=_stabtype;
  1322. end;
  1323. constructor tai_stab.create_str(_stabtype:TStabType;const s:string);
  1324. begin
  1325. self.create(_stabtype,strpnew(s));
  1326. end;
  1327. destructor tai_stab.destroy;
  1328. begin
  1329. freemem(str);
  1330. inherited destroy;
  1331. end;
  1332. {****************************************************************************
  1333. TAI_FORCE_LINE
  1334. ****************************************************************************}
  1335. constructor tai_force_line.create;
  1336. begin
  1337. inherited create;
  1338. typ:=ait_force_line;
  1339. end;
  1340. {****************************************************************************
  1341. TAI_FUNCTION_NAME
  1342. ****************************************************************************}
  1343. constructor tai_function_name.create(const s:string);
  1344. begin
  1345. inherited create;
  1346. typ:=ait_function_name;
  1347. funcname:=stringdup(s);
  1348. end;
  1349. destructor tai_function_name.destroy;
  1350. begin
  1351. stringdispose(funcname);
  1352. inherited destroy;
  1353. end;
  1354. {****************************************************************************
  1355. TAI_CUTOBJECT
  1356. ****************************************************************************}
  1357. constructor tai_cutobject.Create;
  1358. begin
  1359. inherited Create;
  1360. typ:=ait_cutobject;
  1361. place:=cut_normal;
  1362. end;
  1363. constructor tai_cutobject.Create_begin;
  1364. begin
  1365. inherited Create;
  1366. typ:=ait_cutobject;
  1367. place:=cut_begin;
  1368. end;
  1369. constructor tai_cutobject.Create_end;
  1370. begin
  1371. inherited Create;
  1372. typ:=ait_cutobject;
  1373. place:=cut_end;
  1374. end;
  1375. constructor tai_cutobject.ppuload(t:taitype;ppufile:tcompilerppufile);
  1376. begin
  1377. inherited ppuload(t,ppufile);
  1378. place:=TCutPlace(ppufile.getbyte);
  1379. end;
  1380. procedure tai_cutobject.ppuwrite(ppufile:tcompilerppufile);
  1381. begin
  1382. inherited ppuwrite(ppufile);
  1383. ppufile.putbyte(byte(place));
  1384. end;
  1385. {****************************************************************************
  1386. Tai_Marker
  1387. ****************************************************************************}
  1388. constructor Tai_Marker.Create(_Kind: TAsmMarker);
  1389. begin
  1390. Inherited Create;
  1391. typ := ait_marker;
  1392. Kind := _Kind;
  1393. end;
  1394. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1395. begin
  1396. inherited ppuload(t,ppufile);
  1397. kind:=TAsmMarker(ppufile.getbyte);
  1398. end;
  1399. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1400. begin
  1401. inherited ppuwrite(ppufile);
  1402. ppufile.putbyte(byte(kind));
  1403. end;
  1404. {*****************************************************************************
  1405. tai_tempalloc
  1406. *****************************************************************************}
  1407. constructor tai_tempalloc.alloc(pos,size:longint);
  1408. begin
  1409. inherited Create;
  1410. typ:=ait_tempalloc;
  1411. allocation:=true;
  1412. temppos:=pos;
  1413. tempsize:=size;
  1414. {$ifdef EXTDEBUG}
  1415. problem:=nil;
  1416. {$endif EXTDEBUG}
  1417. end;
  1418. destructor tai_tempalloc.destroy;
  1419. begin
  1420. {$ifdef EXTDEBUG}
  1421. stringdispose(problem);
  1422. {$endif EXTDEBUG}
  1423. inherited destroy;
  1424. end;
  1425. constructor tai_tempalloc.dealloc(pos,size:longint);
  1426. begin
  1427. inherited Create;
  1428. typ:=ait_tempalloc;
  1429. allocation:=false;
  1430. temppos:=pos;
  1431. tempsize:=size;
  1432. {$ifdef EXTDEBUG}
  1433. problem:=nil;
  1434. {$endif EXTDEBUG}
  1435. end;
  1436. {$ifdef EXTDEBUG}
  1437. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1438. begin
  1439. inherited Create;
  1440. typ:=ait_tempalloc;
  1441. allocation:=false;
  1442. temppos:=pos;
  1443. tempsize:=size;
  1444. problem:=stringdup(st);
  1445. end;
  1446. {$endif EXTDEBUG}
  1447. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1448. begin
  1449. inherited ppuload(t,ppufile);
  1450. temppos:=ppufile.getlongint;
  1451. tempsize:=ppufile.getlongint;
  1452. allocation:=boolean(ppufile.getbyte);
  1453. {$ifdef EXTDEBUG}
  1454. problem:=nil;
  1455. {$endif EXTDEBUG}
  1456. end;
  1457. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1458. begin
  1459. inherited ppuwrite(ppufile);
  1460. ppufile.putlongint(temppos);
  1461. ppufile.putlongint(tempsize);
  1462. ppufile.putbyte(byte(allocation));
  1463. end;
  1464. {*****************************************************************************
  1465. tai_regalloc
  1466. *****************************************************************************}
  1467. constructor tai_regalloc.alloc(r : tregister;ainstr:tai);
  1468. begin
  1469. inherited create;
  1470. typ:=ait_regalloc;
  1471. ratype:=ra_alloc;
  1472. reg:=r;
  1473. { ainstr must be an instruction }
  1474. if assigned(ainstr) and
  1475. (ainstr.typ<>ait_instruction) then
  1476. internalerror(200411011);
  1477. instr:=ainstr;
  1478. end;
  1479. constructor tai_regalloc.dealloc(r : tregister;ainstr:tai);
  1480. begin
  1481. inherited create;
  1482. typ:=ait_regalloc;
  1483. ratype:=ra_dealloc;
  1484. reg:=r;
  1485. { ainstr must be an instruction }
  1486. if assigned(ainstr) and
  1487. (ainstr.typ<>ait_instruction) then
  1488. internalerror(200411012);
  1489. instr:=ainstr;
  1490. end;
  1491. constructor tai_regalloc.sync(r : tregister);
  1492. begin
  1493. inherited create;
  1494. typ:=ait_regalloc;
  1495. ratype:=ra_sync;
  1496. reg:=r;
  1497. end;
  1498. constructor tai_regalloc.resize(r : tregister);
  1499. begin
  1500. inherited create;
  1501. typ:=ait_regalloc;
  1502. ratype:=ra_resize;
  1503. reg:=r;
  1504. end;
  1505. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1506. begin
  1507. inherited ppuload(t,ppufile);
  1508. ppufile.getdata(reg,sizeof(Tregister));
  1509. ratype:=tregalloctype(ppufile.getbyte);
  1510. end;
  1511. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1512. begin
  1513. inherited ppuwrite(ppufile);
  1514. ppufile.putdata(reg,sizeof(Tregister));
  1515. ppufile.putbyte(byte(ratype));
  1516. end;
  1517. {*****************************************************************************
  1518. TaiInstruction
  1519. *****************************************************************************}
  1520. constructor tai_cpu_abstract.Create(op : tasmop);
  1521. begin
  1522. inherited create;
  1523. typ:=ait_instruction;
  1524. is_jmp:=false;
  1525. opcode:=op;
  1526. ops:=0;
  1527. fillchar(condition,sizeof(condition),0);
  1528. fillchar(oper,sizeof(oper),0);
  1529. end;
  1530. destructor tai_cpu_abstract.Destroy;
  1531. var
  1532. i : integer;
  1533. begin
  1534. for i:=0 to opercnt-1 do
  1535. freeop(i);
  1536. inherited destroy;
  1537. end;
  1538. { ---------------------------------------------------------------------
  1539. Loading of operands.
  1540. ---------------------------------------------------------------------}
  1541. procedure tai_cpu_abstract.allocate_oper(opers:longint);
  1542. begin
  1543. while (opers>opercnt) do
  1544. begin
  1545. new(oper[opercnt]);
  1546. fillchar(oper[opercnt]^,sizeof(toper),0);
  1547. inc(opercnt);
  1548. end;
  1549. end;
  1550. procedure tai_cpu_abstract.loadconst(opidx:longint;l:aint);
  1551. begin
  1552. allocate_oper(opidx+1);
  1553. with oper[opidx]^ do
  1554. begin
  1555. if typ<>top_const then
  1556. clearop(opidx);
  1557. val:=l;
  1558. typ:=top_const;
  1559. end;
  1560. end;
  1561. procedure tai_cpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1562. var
  1563. r : treference;
  1564. begin
  1565. reference_reset_symbol(r,s,sofs);
  1566. r.refaddr:=addr_full;
  1567. loadref(opidx,r);
  1568. end;
  1569. procedure tai_cpu_abstract.loadlocal(opidx:longint;s:pointer;sofs:longint;indexreg:tregister;scale:byte;getoffset,forceref:boolean);
  1570. begin
  1571. if not assigned(s) then
  1572. internalerror(200204251);
  1573. allocate_oper(opidx+1);
  1574. with oper[opidx]^ do
  1575. begin
  1576. if typ<>top_local then
  1577. begin
  1578. clearop(opidx);
  1579. new(localoper);
  1580. end;
  1581. with oper[opidx]^.localoper^ do
  1582. begin
  1583. localsym:=s;
  1584. localsymofs:=sofs;
  1585. localindexreg:=indexreg;
  1586. localscale:=scale;
  1587. localgetoffset:=getoffset;
  1588. localforceref:=forceref;
  1589. end;
  1590. typ:=top_local;
  1591. end;
  1592. end;
  1593. procedure tai_cpu_abstract.loadref(opidx:longint;const r:treference);
  1594. begin
  1595. allocate_oper(opidx+1);
  1596. with oper[opidx]^ do
  1597. begin
  1598. if typ<>top_ref then
  1599. begin
  1600. clearop(opidx);
  1601. new(ref);
  1602. end;
  1603. ref^:=r;
  1604. {$ifdef x86}
  1605. { We allow this exception for x86, since overloading this would be
  1606. too much of a a speed penalty}
  1607. if (ref^.segment<>NR_NO) and (ref^.segment<>NR_DS) then
  1608. segprefix:=ref^.segment;
  1609. {$endif}
  1610. {$ifdef extdebug}
  1611. if (cs_create_pic in current_settings.moduleswitches) and
  1612. assigned(r.symbol) and
  1613. (r.refaddr=addr_no) then
  1614. internalerror(200502052);
  1615. {$endif}
  1616. typ:=top_ref;
  1617. if assigned(add_reg_instruction_hook) then
  1618. begin
  1619. add_reg_instruction_hook(self,ref^.base);
  1620. add_reg_instruction_hook(self,ref^.index);
  1621. end;
  1622. { mark symbol as used }
  1623. if assigned(ref^.symbol) then
  1624. ref^.symbol.increfs;
  1625. end;
  1626. end;
  1627. procedure tai_cpu_abstract.loadreg(opidx:longint;r:tregister);
  1628. begin
  1629. allocate_oper(opidx+1);
  1630. with oper[opidx]^ do
  1631. begin
  1632. if typ<>top_reg then
  1633. clearop(opidx);
  1634. reg:=r;
  1635. typ:=top_reg;
  1636. end;
  1637. if assigned(add_reg_instruction_hook) then
  1638. add_reg_instruction_hook(self,r);
  1639. {$ifdef ARM}
  1640. { R15 is the PC on the ARM thus moves to R15 are jumps.
  1641. Due to speed considerations we don't use a virtual overridden method here.
  1642. Because the pc/r15 isn't handled by the reg. allocator this should never cause
  1643. problems with iregs getting r15.
  1644. }
  1645. is_jmp:=(opcode=A_MOV) and (opidx=0) and (r=NR_R15);
  1646. {$endif ARM}
  1647. end;
  1648. procedure tai_cpu_abstract.loadoper(opidx:longint;o:toper);
  1649. begin
  1650. allocate_oper(opidx+1);
  1651. clearop(opidx);
  1652. oper[opidx]^:=o;
  1653. { copy also the reference }
  1654. with oper[opidx]^ do
  1655. begin
  1656. case typ of
  1657. top_reg:
  1658. begin
  1659. if assigned(add_reg_instruction_hook) then
  1660. add_reg_instruction_hook(self,reg);
  1661. end;
  1662. top_ref:
  1663. begin
  1664. new(ref);
  1665. ref^:=o.ref^;
  1666. if assigned(add_reg_instruction_hook) then
  1667. begin
  1668. add_reg_instruction_hook(self,ref^.base);
  1669. add_reg_instruction_hook(self,ref^.index);
  1670. end;
  1671. end;
  1672. {$ifdef ARM}
  1673. top_shifterop:
  1674. begin
  1675. new(shifterop);
  1676. shifterop^:=o.shifterop^;
  1677. if assigned(add_reg_instruction_hook) then
  1678. add_reg_instruction_hook(self,shifterop^.rs);
  1679. end;
  1680. {$endif ARM}
  1681. end;
  1682. end;
  1683. end;
  1684. procedure tai_cpu_abstract.clearop(opidx:longint);
  1685. begin
  1686. with oper[opidx]^ do
  1687. begin
  1688. case typ of
  1689. top_ref:
  1690. dispose(ref);
  1691. top_local:
  1692. dispose(localoper);
  1693. {$ifdef ARM}
  1694. top_shifterop:
  1695. dispose(shifterop);
  1696. top_regset:
  1697. dispose(regset);
  1698. {$endif ARM}
  1699. end;
  1700. typ:=top_none;
  1701. end;
  1702. end;
  1703. procedure tai_cpu_abstract.freeop(opidx:longint);
  1704. begin
  1705. clearop(opidx);
  1706. dispose(oper[opidx]);
  1707. end;
  1708. { ---------------------------------------------------------------------
  1709. Miscellaneous methods.
  1710. ---------------------------------------------------------------------}
  1711. procedure tai_cpu_abstract.SetCondition(const c:TAsmCond);
  1712. begin
  1713. condition:=c;
  1714. end;
  1715. Function tai_cpu_abstract.getcopy:TLinkedListItem;
  1716. var
  1717. i : longint;
  1718. p : tai_cpu_abstract;
  1719. begin
  1720. p:=tai_cpu_abstract(inherited getcopy);
  1721. { make a copy of the references }
  1722. p.opercnt:=0;
  1723. p.allocate_oper(ops);
  1724. for i:=0 to ops-1 do
  1725. begin
  1726. p.oper[i]^:=oper[i]^;
  1727. case oper[i]^.typ of
  1728. top_local :
  1729. begin
  1730. new(p.oper[i]^.localoper);
  1731. p.oper[i]^.localoper^:=oper[i]^.localoper^;
  1732. end;
  1733. top_ref :
  1734. begin
  1735. new(p.oper[i]^.ref);
  1736. p.oper[i]^.ref^:=oper[i]^.ref^;
  1737. end;
  1738. {$ifdef ARM}
  1739. top_shifterop:
  1740. begin
  1741. new(p.oper[i]^.shifterop);
  1742. p.oper[i]^.shifterop^:=oper[i]^.shifterop^;
  1743. end;
  1744. {$endif ARM}
  1745. end;
  1746. end;
  1747. getcopy:=p;
  1748. end;
  1749. function tai_cpu_abstract.is_same_reg_move(regtype: Tregistertype):boolean;
  1750. begin
  1751. { When the generic RA is used this needs to be overriden, we don't use
  1752. virtual;abstract; to prevent a lot of warnings of unimplemented abstract methods
  1753. when tai_cpu is created (PFV) }
  1754. internalerror(200404091);
  1755. result:=false;
  1756. end;
  1757. function tai_cpu_abstract.spilling_get_operation_type(opnr: longint): topertype;
  1758. begin
  1759. internalerror(200404091);
  1760. result:=operand_readwrite;
  1761. end;
  1762. function tai_cpu_abstract.spilling_get_operation_type_ref(opnr: longint; reg: tregister): topertype;
  1763. begin
  1764. result := operand_read;
  1765. end;
  1766. constructor tai_cpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1767. var
  1768. i : integer;
  1769. begin
  1770. inherited ppuload(t,ppufile);
  1771. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1772. ppufile.getdata(condition,sizeof(tasmcond));
  1773. allocate_oper(ppufile.getbyte);
  1774. for i:=0 to ops-1 do
  1775. ppuloadoper(ppufile,oper[i]^);
  1776. opcode:=tasmop(ppufile.getword);
  1777. {$ifdef x86}
  1778. ppufile.getdata(segprefix,sizeof(Tregister));
  1779. {$endif x86}
  1780. is_jmp:=boolean(ppufile.getbyte);
  1781. end;
  1782. procedure tai_cpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1783. var
  1784. i : integer;
  1785. begin
  1786. inherited ppuwrite(ppufile);
  1787. ppufile.putdata(condition,sizeof(tasmcond));
  1788. ppufile.putbyte(ops);
  1789. for i:=0 to ops-1 do
  1790. ppuwriteoper(ppufile,oper[i]^);
  1791. ppufile.putword(word(opcode));
  1792. {$ifdef x86}
  1793. ppufile.putdata(segprefix,sizeof(Tregister));
  1794. {$endif x86}
  1795. ppufile.putbyte(byte(is_jmp));
  1796. end;
  1797. procedure tai_cpu_abstract.buildderefimpl;
  1798. var
  1799. i : integer;
  1800. begin
  1801. for i:=0 to ops-1 do
  1802. ppubuildderefimploper(oper[i]^);
  1803. end;
  1804. procedure tai_cpu_abstract.derefimpl;
  1805. var
  1806. i : integer;
  1807. begin
  1808. for i:=0 to ops-1 do
  1809. ppuderefoper(oper[i]^);
  1810. end;
  1811. procedure tai_cpu_abstract.resetpass1;
  1812. begin
  1813. end;
  1814. procedure tai_cpu_abstract.resetpass2;
  1815. begin
  1816. end;
  1817. function tai_cpu_abstract.Pass1(objdata:TObjData):longint;
  1818. begin
  1819. result:=0;
  1820. end;
  1821. procedure tai_cpu_abstract.Pass2(objdata:TObjData);
  1822. begin
  1823. end;
  1824. procedure tai_cpu_abstract.ppuloadoper(ppufile:tcompilerppufile;var o:toper);
  1825. begin
  1826. o.typ:=toptype(ppufile.getbyte);
  1827. o.ot:=ppufile.getlongint;
  1828. case o.typ of
  1829. top_reg :
  1830. ppufile.getdata(o.reg,sizeof(Tregister));
  1831. top_ref :
  1832. begin
  1833. new(o.ref);
  1834. {$ifdef x86}
  1835. ppufile.getdata(o.ref^.segment,sizeof(Tregister));
  1836. {$endif x86}
  1837. ppufile.getdata(o.ref^.base,sizeof(Tregister));
  1838. ppufile.getdata(o.ref^.index,sizeof(Tregister));
  1839. ppufile.getdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  1840. o.ref^.scalefactor:=ppufile.getbyte;
  1841. o.ref^.offset:=ppufile.getaint;
  1842. o.ref^.symbol:=ppufile.getasmsymbol;
  1843. o.ref^.relsymbol:=ppufile.getasmsymbol;
  1844. end;
  1845. top_const :
  1846. o.val:=ppufile.getaint;
  1847. top_local :
  1848. begin
  1849. new(o.localoper);
  1850. with o.localoper^ do
  1851. begin
  1852. ppufile.getderef(localsymderef);
  1853. localsymofs:=ppufile.getaint;
  1854. localindexreg:=tregister(ppufile.getlongint);
  1855. localscale:=ppufile.getbyte;
  1856. localgetoffset:=(ppufile.getbyte<>0);
  1857. end;
  1858. end;
  1859. else
  1860. internalerror(2007010210);
  1861. end;
  1862. end;
  1863. procedure tai_cpu_abstract.ppuwriteoper(ppufile:tcompilerppufile;const o:toper);
  1864. begin
  1865. ppufile.putbyte(byte(o.typ));
  1866. ppufile.putlongint(o.ot);
  1867. case o.typ of
  1868. top_reg :
  1869. ppufile.putdata(o.reg,sizeof(Tregister));
  1870. top_ref :
  1871. begin
  1872. {$ifdef x86}
  1873. ppufile.putdata(o.ref^.segment,sizeof(Tregister));
  1874. {$endif x86}
  1875. ppufile.putdata(o.ref^.base,sizeof(Tregister));
  1876. ppufile.putdata(o.ref^.index,sizeof(Tregister));
  1877. ppufile.putdata(o.ref^.refaddr,sizeof(o.ref^.refaddr));
  1878. ppufile.putbyte(o.ref^.scalefactor);
  1879. ppufile.putaint(o.ref^.offset);
  1880. ppufile.putasmsymbol(o.ref^.symbol);
  1881. ppufile.putasmsymbol(o.ref^.relsymbol);
  1882. end;
  1883. top_const :
  1884. ppufile.putaint(o.val);
  1885. top_local :
  1886. begin
  1887. with o.localoper^ do
  1888. begin
  1889. ppufile.putderef(localsymderef);
  1890. ppufile.putaint(localsymofs);
  1891. ppufile.putlongint(longint(localindexreg));
  1892. ppufile.putbyte(localscale);
  1893. ppufile.putbyte(byte(localgetoffset));
  1894. end;
  1895. end;
  1896. else
  1897. internalerror(2007010211);
  1898. end;
  1899. end;
  1900. {****************************************************************************
  1901. tai_align_abstract
  1902. ****************************************************************************}
  1903. constructor tai_align_abstract.Create(b: byte);
  1904. begin
  1905. inherited Create;
  1906. typ:=ait_align;
  1907. {$ifdef EXTDEBUG}
  1908. if upper(classname)='TAI_ALIGN_ABSTRACT' then
  1909. internalerror(200709191);
  1910. {$endif EXTDEBUG}
  1911. if b in [1,2,4,8,16,32] then
  1912. aligntype := b
  1913. else
  1914. aligntype := 1;
  1915. fillsize:=0;
  1916. fillop:=0;
  1917. use_op:=false;
  1918. end;
  1919. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1920. begin
  1921. inherited Create;
  1922. typ:=ait_align;
  1923. if b in [1,2,4,8,16,32] then
  1924. aligntype := b
  1925. else
  1926. aligntype := 1;
  1927. fillsize:=0;
  1928. fillop:=_op;
  1929. use_op:=true;
  1930. end;
  1931. constructor tai_align_abstract.Create_zeros(b: byte);
  1932. begin
  1933. inherited Create;
  1934. typ:=ait_align;
  1935. if b in [1,2,4,8,16,32] then
  1936. aligntype := b
  1937. else
  1938. aligntype := 1;
  1939. use_op:=true;
  1940. fillsize:=0;
  1941. fillop:=0;
  1942. end;
  1943. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1944. begin
  1945. if fillsize>sizeof(buf) then
  1946. internalerror(200404293);
  1947. fillchar(buf,high(buf),fillop);
  1948. calculatefillbuf:=pchar(@buf);
  1949. end;
  1950. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1951. begin
  1952. inherited ppuload(t,ppufile);
  1953. aligntype:=ppufile.getbyte;
  1954. fillsize:=0;
  1955. fillop:=ppufile.getbyte;
  1956. use_op:=boolean(ppufile.getbyte);
  1957. end;
  1958. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1959. begin
  1960. inherited ppuwrite(ppufile);
  1961. ppufile.putbyte(aligntype);
  1962. ppufile.putbyte(fillop);
  1963. ppufile.putbyte(byte(use_op));
  1964. end;
  1965. begin
  1966. cai_cpu:=tai_cpu_abstract;
  1967. { aasmcpu is earlier in the unit order and can
  1968. already set the cai_align }
  1969. if not assigned(cai_align) then
  1970. cai_align:=tai_align_abstract;
  1971. end.