aasmtai.pas 68 KB

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