aasmtai.pas 67 KB

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