aasmtai.pas 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements an abstract asmoutput class for all processor types
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { @abstract(This unit implements an abstract asm output class for all processor types)
  19. This unit implements an abstract assembler output class for all processors, these
  20. are then overriden for each assembler writer to actually write the data in these
  21. classes to an assembler file.
  22. }
  23. unit aasmtai;
  24. {$i fpcdefs.inc}
  25. interface
  26. uses
  27. cutils,cclasses,
  28. globtype,globals,systems,
  29. cpuinfo,cpubase,
  30. symppu,
  31. aasmbase;
  32. type
  33. taitype = (
  34. ait_none,
  35. ait_align,
  36. ait_section,
  37. ait_comment,
  38. ait_direct,
  39. ait_string,
  40. ait_instruction,
  41. ait_datablock,
  42. ait_symbol,
  43. ait_symbol_end, { needed to calc the size of a symbol }
  44. ait_label,
  45. ait_const_32bit,
  46. ait_const_16bit,
  47. ait_const_8bit,
  48. ait_const_symbol,
  49. { the following is only used by the win32 version of the compiler }
  50. { and only the GNU AS Win32 is able to write it }
  51. ait_const_rva,
  52. ait_real_32bit,
  53. ait_real_64bit,
  54. ait_real_80bit,
  55. ait_comp_64bit,
  56. ait_real_128bit,
  57. {$ifdef GDB}
  58. ait_stabn,
  59. ait_stabs,
  60. ait_force_line,
  61. ait_stab_function_name,
  62. {$endif GDB}
  63. {$ifdef alpha}
  64. { the follow is for the DEC Alpha }
  65. ait_frame,
  66. ait_ent,
  67. {$endif alpha}
  68. {$ifdef ia64}
  69. ait_bundle,
  70. ait_stop,
  71. {$endif ia64}
  72. {$ifdef m68k}
  73. ait_labeled_instruction,
  74. {$endif m68k}
  75. {$ifdef SPARC}
  76. ait_labeled_instruction,
  77. {$endif SPARC}
  78. ait_cut, { used to split into tiny assembler files }
  79. ait_regalloc,
  80. ait_tempalloc,
  81. ait_marker { used to mark assembler blocks and inlined functions }
  82. );
  83. const
  84. taitypestr : array[taitype] of string[14] = (
  85. '<none>',
  86. 'align',
  87. 'section',
  88. 'comment',
  89. 'direct',
  90. 'string',
  91. 'instruction',
  92. 'datablock',
  93. 'symbol',
  94. 'symbol_end',
  95. 'label',
  96. 'const_32bit',
  97. 'const_16bit',
  98. 'const_8bit',
  99. 'const_symbol',
  100. 'const_rva',
  101. 'real_32bit',
  102. 'real_64bit',
  103. 'real_80bit',
  104. 'comp_64bit',
  105. 'real_128bit',
  106. {$ifdef GDB}
  107. 'stabn',
  108. 'stabs',
  109. 'force_line',
  110. 'stab_funcname',
  111. {$endif GDB}
  112. {$ifdef alpha}
  113. { the follow is for the DEC Alpha }
  114. 'frame',
  115. 'ent',
  116. {$endif alpha}
  117. {$ifdef ia64}
  118. 'bundle',
  119. 'stop',
  120. {$endif ia64}
  121. {$ifdef m68k}
  122. 'labeled_instr',
  123. {$endif m68k}
  124. {$ifdef SPARC}
  125. 'labeled_instr',
  126. {$endif SPARC}
  127. 'cut',
  128. 'regalloc',
  129. 'tempalloc',
  130. 'marker'
  131. );
  132. { ait_* types which don't result in executable code or which don't influence }
  133. { the way the program runs/behaves, but which may be encountered by the }
  134. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  135. { a new ait type! }
  136. const
  137. SkipInstr = [ait_comment, ait_symbol,ait_section
  138. {$ifdef GDB}
  139. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  140. {$endif GDB}
  141. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  142. { ait_* types which do not have line information (and hence which are of type
  143. tai, otherwise, they are of type tailineinfo }
  144. { ait_* types which do not have line information (and hence which are of type
  145. tai, otherwise, they are of type tailineinfo }
  146. SkipLineInfo =[ait_label,
  147. ait_regalloc,ait_tempalloc,
  148. {$ifdef GDB}
  149. ait_stabn,ait_stabs,ait_stab_function_name,
  150. {$endif GDB}
  151. ait_cut,ait_marker,ait_align,ait_section,ait_comment,
  152. ait_const_8bit,ait_const_16bit,ait_const_32bit,
  153. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit
  154. ];
  155. type
  156. { cut type, required for alphanumeric ordering of the assembler filenames }
  157. TCutPlace=(cut_normal,cut_begin,cut_end);
  158. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  159. AsmBlockStart,AsmBlockEnd,
  160. InlineStart,InlineEnd);
  161. { Buffer type used for alignment }
  162. tfillbuffer = array[0..63] of char;
  163. { abstract assembler item }
  164. tai = class(TLinkedListItem)
  165. {$ifndef NOOPT}
  166. { pointer to record with optimizer info about this tai object }
  167. optinfo : pointer;
  168. {$endif NOOPT}
  169. typ : taitype;
  170. constructor Create;
  171. constructor ppuload(t:taitype;ppufile:tcompilerppufile);virtual;
  172. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  173. procedure derefimpl;virtual;
  174. { helper for checking symbol redefines }
  175. procedure checkredefinesym(sym:tasmsymbol);
  176. end;
  177. { abstract assembler item with line information }
  178. tailineinfo = class(tai)
  179. fileinfo : tfileposinfo;
  180. constructor Create;
  181. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  182. procedure ppuwrite(ppufile:tcompilerppufile);override;
  183. end;
  184. taiclass = class of tai;
  185. taiclassarray = array[taitype] of taiclass;
  186. { Generates an assembler string }
  187. tai_string = class(tailineinfo)
  188. str : pchar;
  189. { extra len so the string can contain an \0 }
  190. len : longint;
  191. constructor Create(const _str : string);
  192. constructor Create_pchar(_str : pchar);
  193. constructor Create_length_pchar(_str : pchar;length : longint);
  194. destructor Destroy;override;
  195. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  196. procedure ppuwrite(ppufile:tcompilerppufile);override;
  197. function getcopy:tlinkedlistitem;override;
  198. end;
  199. { Generates a common label }
  200. tai_symbol = class(tailineinfo)
  201. is_global : boolean;
  202. sym : tasmsymbol;
  203. size : longint;
  204. constructor Create(_sym:tasmsymbol;siz:longint);
  205. constructor Createname(const _name : string;siz:longint);
  206. constructor Createname_global(const _name : string;siz:longint);
  207. constructor Createdataname(const _name : string;siz:longint);
  208. constructor Createdataname_global(const _name : string;siz:longint);
  209. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  210. procedure ppuwrite(ppufile:tcompilerppufile);override;
  211. procedure derefimpl;override;
  212. end;
  213. tai_symbol_end = class(tailineinfo)
  214. sym : tasmsymbol;
  215. constructor Create(_sym:tasmsymbol);
  216. constructor Createname(const _name : string);
  217. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  218. procedure ppuwrite(ppufile:tcompilerppufile);override;
  219. procedure derefimpl;override;
  220. end;
  221. { Generates an assembler label }
  222. tai_label = class(tai)
  223. is_global : boolean;
  224. l : tasmlabel;
  225. constructor Create(_l : tasmlabel);
  226. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  227. procedure ppuwrite(ppufile:tcompilerppufile);override;
  228. procedure derefimpl;override;
  229. end;
  230. { Directly output data to final assembler file }
  231. tai_direct = class(tailineinfo)
  232. str : pchar;
  233. constructor Create(_str : pchar);
  234. destructor Destroy; override;
  235. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  236. procedure ppuwrite(ppufile:tcompilerppufile);override;
  237. function getcopy:tlinkedlistitem;override;
  238. end;
  239. { Generates an assembler comment }
  240. tai_comment = class(tai)
  241. str : pchar;
  242. constructor Create(_str : pchar);
  243. destructor Destroy; override;
  244. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. function getcopy:tlinkedlistitem;override;
  247. end;
  248. { Generates a section / segment directive }
  249. tai_section = class(tai)
  250. sec : TSection;
  251. constructor Create(s : TSection);
  252. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  253. procedure ppuwrite(ppufile:tcompilerppufile);override;
  254. end;
  255. { Generates an uninitializised data block }
  256. tai_datablock = class(tailineinfo)
  257. is_global : boolean;
  258. sym : tasmsymbol;
  259. size : longint;
  260. constructor Create(const _name : string;_size : longint);
  261. constructor Create_global(const _name : string;_size : longint);
  262. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  263. procedure ppuwrite(ppufile:tcompilerppufile);override;
  264. procedure derefimpl;override;
  265. end;
  266. { Generates a long integer (32 bit) }
  267. tai_const = class(tai)
  268. value : longint;
  269. constructor Create_32bit(_value : longint);
  270. constructor Create_16bit(_value : word);
  271. constructor Create_8bit(_value : byte);
  272. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  273. procedure ppuwrite(ppufile:tcompilerppufile);override;
  274. end;
  275. tai_const_symbol = class(tailineinfo)
  276. sym : tasmsymbol;
  277. offset : longint;
  278. constructor Create(_sym:tasmsymbol);
  279. constructor Create_offset(_sym:tasmsymbol;ofs:longint);
  280. constructor Create_rva(_sym:tasmsymbol);
  281. constructor Createname(const name:string);
  282. constructor Createname_offset(const name:string;ofs:longint);
  283. constructor Createname_rva(const name:string);
  284. constructor Createdataname(const name:string);
  285. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  286. procedure ppuwrite(ppufile:tcompilerppufile);override;
  287. procedure derefimpl;override;
  288. function getcopy:tlinkedlistitem;override;
  289. end;
  290. { Generates a single float (32 bit real) }
  291. tai_real_32bit = class(tai)
  292. value : ts32real;
  293. constructor Create(_value : ts32real);
  294. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  295. procedure ppuwrite(ppufile:tcompilerppufile);override;
  296. end;
  297. { Generates a double float (64 bit real) }
  298. tai_real_64bit = class(tai)
  299. value : ts64real;
  300. constructor Create(_value : ts64real);
  301. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  302. procedure ppuwrite(ppufile:tcompilerppufile);override;
  303. end;
  304. { Generates an extended float (80 bit real) }
  305. tai_real_80bit = class(tai)
  306. value : ts80real;
  307. constructor Create(_value : ts80real);
  308. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  309. procedure ppuwrite(ppufile:tcompilerppufile);override;
  310. end;
  311. { Generates a comp int (integer over 64 bits)
  312. This is Intel 80x86 specific, and is not
  313. really supported on other processors.
  314. }
  315. tai_comp_64bit = class(tai)
  316. value : ts64comp;
  317. constructor Create(_value : ts64comp);
  318. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  319. procedure ppuwrite(ppufile:tcompilerppufile);override;
  320. end;
  321. { Insert a cut to split assembler into several smaller files }
  322. tai_cut = class(tai)
  323. place : tcutplace;
  324. constructor Create;
  325. constructor Create_begin;
  326. constructor Create_end;
  327. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  328. procedure ppuwrite(ppufile:tcompilerppufile);override;
  329. end;
  330. { Insert a marker for assembler and inline blocks }
  331. tai_marker = class(tai)
  332. Kind: TMarker;
  333. Constructor Create(_Kind: TMarker);
  334. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  335. procedure ppuwrite(ppufile:tcompilerppufile);override;
  336. end;
  337. tai_tempalloc = class(tai)
  338. allocation : boolean;
  339. {$ifdef EXTDEBUG}
  340. problem : pstring;
  341. {$endif EXTDEBUG}
  342. temppos,
  343. tempsize : longint;
  344. constructor alloc(pos,size:longint);
  345. constructor dealloc(pos,size:longint);
  346. {$ifdef EXTDEBUG}
  347. constructor allocinfo(pos,size:longint;const st:string);
  348. {$endif EXTDEBUG}
  349. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  350. procedure ppuwrite(ppufile:tcompilerppufile);override;
  351. end;
  352. tai_regalloc = class(tai)
  353. allocation : boolean;
  354. reg : tregister;
  355. constructor alloc(r : tregister);
  356. constructor dealloc(r : tregister);
  357. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  358. procedure ppuwrite(ppufile:tcompilerppufile);override;
  359. end;
  360. { Class template for assembler instructions
  361. }
  362. taicpu_abstract = class(tailineinfo)
  363. protected
  364. procedure ppuloadoper(ppufile:tcompilerppufile;var o:toper);virtual;abstract;
  365. procedure ppuwriteoper(ppufile:tcompilerppufile;const o:toper);virtual;abstract;
  366. procedure ppuderefoper(var o:toper);virtual;abstract;
  367. public
  368. { Condition flags for instruction }
  369. condition : TAsmCond;
  370. { Number of operands to instruction }
  371. ops : byte;
  372. { Operands of instruction }
  373. oper : array[0..max_operands-1] of toper;
  374. { Actual opcode of instruction }
  375. opcode : tasmop;
  376. {$ifdef i386}
  377. segprefix : tregister;
  378. {$endif i386}
  379. { true if instruction is a jmp }
  380. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  381. Constructor Create(op : tasmop);
  382. Destructor Destroy;override;
  383. function getcopy:TLinkedListItem;override;
  384. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  385. procedure ppuwrite(ppufile:tcompilerppufile);override;
  386. procedure derefimpl;override;
  387. procedure SetCondition(const c:TAsmCond);
  388. procedure loadconst(opidx:longint;l:aword);
  389. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  390. procedure loadref(opidx:longint;const r:treference);
  391. procedure loadreg(opidx:longint;r:tregister);
  392. procedure loadoper(opidx:longint;o:toper);
  393. end;
  394. { alignment for operator }
  395. tai_align_abstract = class(tai)
  396. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  397. fillsize : byte; { real size to fill }
  398. fillop : byte; { value to fill with - optional }
  399. use_op : boolean;
  400. constructor Create(b:byte);
  401. constructor Create_op(b: byte; _op: byte);
  402. constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
  403. procedure ppuwrite(ppufile:tcompilerppufile);override;
  404. function calculatefillbuf(var buf : tfillbuffer):pchar;virtual;
  405. end;
  406. taasmoutput = class(tlinkedlist)
  407. function getlasttaifilepos : pfileposinfo;
  408. procedure convert_registers;
  409. end;
  410. var
  411. { array with all class types for tais }
  412. aiclass : taiclassarray;
  413. { temporary lists }
  414. exprasmlist,
  415. { default lists }
  416. datasegment,codesegment,bsssegment,
  417. debuglist,withdebuglist,consts,
  418. importssection,exportssection,
  419. resourcesection,rttilist,
  420. resourcestringlist : taasmoutput;
  421. function ppuloadai(ppufile:tcompilerppufile):tai;
  422. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  423. implementation
  424. uses
  425. {$ifdef delphi}
  426. sysutils,
  427. {$else}
  428. strings,
  429. {$endif}
  430. verbose,
  431. ppu;
  432. const
  433. pputaimarker = 254;
  434. {****************************************************************************
  435. Helpers
  436. ****************************************************************************}
  437. function ppuloadai(ppufile:tcompilerppufile):tai;
  438. var
  439. b : byte;
  440. t : taitype;
  441. begin
  442. { marker }
  443. b:=ppufile.getbyte;
  444. if b<>pputaimarker then
  445. internalerror(200208181);
  446. { load nodetype }
  447. t:=taitype(ppufile.getbyte);
  448. if t<>ait_none then
  449. begin
  450. if t>high(taitype) then
  451. internalerror(200208182);
  452. if not assigned(aiclass[t]) then
  453. internalerror(200208183);
  454. //writeln('taiload: ',taitypestr[t]);
  455. { generate tai of the correct class }
  456. ppuloadai:=aiclass[t].ppuload(t,ppufile);
  457. end
  458. else
  459. ppuloadai:=nil;
  460. end;
  461. procedure ppuwriteai(ppufile:tcompilerppufile;n:tai);
  462. begin
  463. { marker, read by ppuloadnode }
  464. ppufile.putbyte(pputaimarker);
  465. if assigned(n) then
  466. begin
  467. { type, read by ppuloadnode }
  468. ppufile.putbyte(byte(n.typ));
  469. //writeln('taiwrite: ',taitypestr[n.typ]);
  470. n.ppuwrite(ppufile);
  471. end
  472. else
  473. ppufile.putbyte(byte(ait_none));
  474. end;
  475. {****************************************************************************
  476. TAI
  477. ****************************************************************************}
  478. constructor tai.Create;
  479. begin
  480. {$ifndef NOOPT}
  481. optinfo:=nil;
  482. {$endif NOOPT}
  483. end;
  484. constructor tai.ppuload(t:taitype;ppufile:tcompilerppufile);
  485. begin
  486. typ:=t;
  487. {$ifndef NOOPT}
  488. optinfo:=nil;
  489. {$endif}
  490. end;
  491. procedure tai.ppuwrite(ppufile:tcompilerppufile);
  492. begin
  493. end;
  494. procedure tai.derefimpl;
  495. begin
  496. end;
  497. procedure tai.checkredefinesym(sym:tasmsymbol);
  498. begin
  499. { if assigned(sym.taiowner) and
  500. (target_asm.id in binassem) then
  501. begin
  502. Message1(asmw_e_redefined_label,sym.name);
  503. end
  504. else
  505. sym.taiowner:=self;}
  506. end;
  507. {****************************************************************************
  508. TAILINEINFO
  509. ****************************************************************************}
  510. constructor tailineinfo.create;
  511. begin
  512. inherited create;
  513. fileinfo:=aktfilepos;
  514. end;
  515. constructor tailineinfo.ppuload(t:taitype;ppufile:tcompilerppufile);
  516. begin
  517. inherited ppuload(t,ppufile);
  518. ppufile.getposinfo(fileinfo);
  519. end;
  520. procedure tailineinfo.ppuwrite(ppufile:tcompilerppufile);
  521. begin
  522. inherited ppuwrite(ppufile);
  523. ppufile.putposinfo(fileinfo);
  524. end;
  525. {****************************************************************************
  526. TAI_SECTION
  527. ****************************************************************************}
  528. constructor tai_section.Create(s : TSection);
  529. begin
  530. inherited Create;
  531. typ:=ait_section;
  532. sec:=s;
  533. end;
  534. constructor tai_section.ppuload(t:taitype;ppufile:tcompilerppufile);
  535. begin
  536. inherited ppuload(t,ppufile);
  537. sec:=tsection(ppufile.getbyte);
  538. end;
  539. procedure tai_section.ppuwrite(ppufile:tcompilerppufile);
  540. begin
  541. inherited ppuwrite(ppufile);
  542. ppufile.putbyte(byte(sec));
  543. end;
  544. {****************************************************************************
  545. TAI_DATABLOCK
  546. ****************************************************************************}
  547. constructor tai_datablock.Create(const _name : string;_size : longint);
  548. begin
  549. inherited Create;
  550. typ:=ait_datablock;
  551. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  552. { checkredefinesym(sym);}
  553. { keep things aligned }
  554. if _size<=0 then
  555. _size:=4;
  556. size:=_size;
  557. is_global:=false;
  558. end;
  559. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  560. begin
  561. inherited Create;
  562. typ:=ait_datablock;
  563. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  564. { checkredefinesym(sym);}
  565. { keep things aligned }
  566. if _size<=0 then
  567. _size:=4;
  568. size:=_size;
  569. is_global:=true;
  570. end;
  571. constructor tai_datablock.ppuload(t:taitype;ppufile:tcompilerppufile);
  572. begin
  573. inherited Create;
  574. sym:=ppufile.getasmsymbol;
  575. size:=ppufile.getlongint;
  576. is_global:=boolean(ppufile.getbyte);
  577. end;
  578. procedure tai_datablock.ppuwrite(ppufile:tcompilerppufile);
  579. begin
  580. inherited ppuwrite(ppufile);
  581. ppufile.putasmsymbol(sym);
  582. ppufile.putlongint(size);
  583. ppufile.putbyte(byte(is_global));
  584. end;
  585. procedure tai_datablock.derefimpl;
  586. begin
  587. objectlibrary.DerefAsmsymbol(sym);
  588. end;
  589. {****************************************************************************
  590. TAI_SYMBOL
  591. ****************************************************************************}
  592. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  593. begin
  594. inherited Create;
  595. typ:=ait_symbol;
  596. sym:=_sym;
  597. { checkredefinesym(sym);}
  598. size:=siz;
  599. is_global:=(sym.defbind=AB_GLOBAL);
  600. end;
  601. constructor tai_symbol.Createname(const _name : string;siz:longint);
  602. begin
  603. inherited Create;
  604. typ:=ait_symbol;
  605. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_FUNCTION);
  606. { checkredefinesym(sym);}
  607. size:=siz;
  608. is_global:=false;
  609. end;
  610. constructor tai_symbol.Createname_global(const _name : string;siz:longint);
  611. begin
  612. inherited Create;
  613. typ:=ait_symbol;
  614. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_FUNCTION);
  615. { checkredefinesym(sym);}
  616. size:=siz;
  617. is_global:=true;
  618. end;
  619. constructor tai_symbol.Createdataname(const _name : string;siz:longint);
  620. begin
  621. inherited Create;
  622. typ:=ait_symbol;
  623. sym:=objectlibrary.newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  624. { checkredefinesym(sym);}
  625. size:=siz;
  626. is_global:=false;
  627. end;
  628. constructor tai_symbol.Createdataname_global(const _name : string;siz:longint);
  629. begin
  630. inherited Create;
  631. typ:=ait_symbol;
  632. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  633. { checkredefinesym(sym);}
  634. size:=siz;
  635. is_global:=true;
  636. end;
  637. constructor tai_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  638. begin
  639. inherited ppuload(t,ppufile);
  640. sym:=ppufile.getasmsymbol;
  641. size:=ppufile.getlongint;
  642. is_global:=boolean(ppufile.getbyte);
  643. end;
  644. procedure tai_symbol.ppuwrite(ppufile:tcompilerppufile);
  645. begin
  646. inherited ppuwrite(ppufile);
  647. ppufile.putasmsymbol(sym);
  648. ppufile.putlongint(size);
  649. ppufile.putbyte(byte(is_global));
  650. end;
  651. procedure tai_symbol.derefimpl;
  652. begin
  653. objectlibrary.DerefAsmsymbol(sym);
  654. end;
  655. {****************************************************************************
  656. TAI_SYMBOL
  657. ****************************************************************************}
  658. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  659. begin
  660. inherited Create;
  661. typ:=ait_symbol_end;
  662. sym:=_sym;
  663. end;
  664. constructor tai_symbol_end.Createname(const _name : string);
  665. begin
  666. inherited Create;
  667. typ:=ait_symbol_end;
  668. sym:=objectlibrary.newasmsymboltype(_name,AB_GLOBAL,AT_NONE);
  669. end;
  670. constructor tai_symbol_end.ppuload(t:taitype;ppufile:tcompilerppufile);
  671. begin
  672. inherited ppuload(t,ppufile);
  673. sym:=ppufile.getasmsymbol;
  674. end;
  675. procedure tai_symbol_end.ppuwrite(ppufile:tcompilerppufile);
  676. begin
  677. inherited ppuwrite(ppufile);
  678. ppufile.putasmsymbol(sym);
  679. end;
  680. procedure tai_symbol_end.derefimpl;
  681. begin
  682. objectlibrary.DerefAsmsymbol(sym);
  683. end;
  684. {****************************************************************************
  685. TAI_CONST
  686. ****************************************************************************}
  687. constructor tai_const.Create_32bit(_value : longint);
  688. begin
  689. inherited Create;
  690. typ:=ait_const_32bit;
  691. value:=_value;
  692. end;
  693. constructor tai_const.Create_16bit(_value : word);
  694. begin
  695. inherited Create;
  696. typ:=ait_const_16bit;
  697. value:=_value;
  698. end;
  699. constructor tai_const.Create_8bit(_value : byte);
  700. begin
  701. inherited Create;
  702. typ:=ait_const_8bit;
  703. value:=_value;
  704. end;
  705. constructor tai_const.ppuload(t:taitype;ppufile:tcompilerppufile);
  706. begin
  707. inherited ppuload(t,ppufile);
  708. value:=ppufile.getlongint;
  709. end;
  710. procedure tai_const.ppuwrite(ppufile:tcompilerppufile);
  711. begin
  712. inherited ppuwrite(ppufile);
  713. ppufile.putlongint(value);
  714. end;
  715. {****************************************************************************
  716. TAI_CONST_SYMBOL
  717. ****************************************************************************}
  718. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  719. begin
  720. inherited Create;
  721. typ:=ait_const_symbol;
  722. sym:=_sym;
  723. offset:=0;
  724. { update sym info }
  725. sym.increfs;
  726. end;
  727. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  728. begin
  729. inherited Create;
  730. typ:=ait_const_symbol;
  731. sym:=_sym;
  732. offset:=ofs;
  733. { update sym info }
  734. sym.increfs;
  735. end;
  736. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  737. begin
  738. inherited Create;
  739. typ:=ait_const_rva;
  740. sym:=_sym;
  741. offset:=0;
  742. { update sym info }
  743. sym.increfs;
  744. end;
  745. constructor tai_const_symbol.Createname(const name:string);
  746. begin
  747. inherited Create;
  748. typ:=ait_const_symbol;
  749. sym:=objectlibrary.newasmsymbol(name);
  750. offset:=0;
  751. { update sym info }
  752. sym.increfs;
  753. end;
  754. constructor tai_const_symbol.Createname_offset(const name:string;ofs:longint);
  755. begin
  756. inherited Create;
  757. typ:=ait_const_symbol;
  758. sym:=objectlibrary.newasmsymbol(name);
  759. offset:=ofs;
  760. { update sym info }
  761. sym.increfs;
  762. end;
  763. constructor tai_const_symbol.Createname_rva(const name:string);
  764. begin
  765. inherited Create;
  766. typ:=ait_const_rva;
  767. sym:=objectlibrary.newasmsymbol(name);
  768. offset:=0;
  769. { update sym info }
  770. sym.increfs;
  771. end;
  772. constructor tai_const_symbol.Createdataname(const name:string);
  773. begin
  774. inherited Create;
  775. typ:=ait_const_symbol;
  776. sym:=objectlibrary.newasmsymboltype(name,AB_EXTERNAL,AT_DATA);
  777. offset:=0;
  778. { update sym info }
  779. sym.increfs;
  780. end;
  781. constructor tai_const_symbol.ppuload(t:taitype;ppufile:tcompilerppufile);
  782. begin
  783. inherited ppuload(t,ppufile);
  784. sym:=ppufile.getasmsymbol;
  785. offset:=ppufile.getlongint;
  786. end;
  787. procedure tai_const_symbol.ppuwrite(ppufile:tcompilerppufile);
  788. begin
  789. inherited ppuwrite(ppufile);
  790. ppufile.putasmsymbol(sym);
  791. ppufile.putlongint(offset);
  792. end;
  793. procedure tai_const_symbol.derefimpl;
  794. begin
  795. objectlibrary.DerefAsmsymbol(sym);
  796. end;
  797. function tai_const_symbol.getcopy:tlinkedlistitem;
  798. begin
  799. getcopy:=inherited getcopy;
  800. { we need to increase the reference number }
  801. sym.increfs;
  802. end;
  803. {****************************************************************************
  804. TAI_real_32bit
  805. ****************************************************************************}
  806. constructor tai_real_32bit.Create(_value : ts32real);
  807. begin
  808. inherited Create;
  809. typ:=ait_real_32bit;
  810. value:=_value;
  811. end;
  812. constructor tai_real_32bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  813. begin
  814. inherited ppuload(t,ppufile);
  815. value:=ppufile.getreal;
  816. end;
  817. procedure tai_real_32bit.ppuwrite(ppufile:tcompilerppufile);
  818. begin
  819. inherited ppuwrite(ppufile);
  820. ppufile.putreal(value);
  821. end;
  822. {****************************************************************************
  823. TAI_real_64bit
  824. ****************************************************************************}
  825. constructor tai_real_64bit.Create(_value : ts64real);
  826. begin
  827. inherited Create;
  828. typ:=ait_real_64bit;
  829. value:=_value;
  830. end;
  831. constructor tai_real_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  832. begin
  833. inherited ppuload(t,ppufile);
  834. value:=ppufile.getreal;
  835. end;
  836. procedure tai_real_64bit.ppuwrite(ppufile:tcompilerppufile);
  837. begin
  838. inherited ppuwrite(ppufile);
  839. ppufile.putreal(value);
  840. end;
  841. {****************************************************************************
  842. TAI_real_80bit
  843. ****************************************************************************}
  844. constructor tai_real_80bit.Create(_value : ts80real);
  845. begin
  846. inherited Create;
  847. typ:=ait_real_80bit;
  848. value:=_value;
  849. end;
  850. constructor tai_real_80bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  851. begin
  852. inherited ppuload(t,ppufile);
  853. value:=ppufile.getreal;
  854. end;
  855. procedure tai_real_80bit.ppuwrite(ppufile:tcompilerppufile);
  856. begin
  857. inherited ppuwrite(ppufile);
  858. ppufile.putreal(value);
  859. end;
  860. {****************************************************************************
  861. Tai_comp_64bit
  862. ****************************************************************************}
  863. constructor tai_comp_64bit.Create(_value : ts64comp);
  864. begin
  865. inherited Create;
  866. typ:=ait_comp_64bit;
  867. value:=_value;
  868. end;
  869. constructor tai_comp_64bit.ppuload(t:taitype;ppufile:tcompilerppufile);
  870. begin
  871. inherited ppuload(t,ppufile);
  872. value:=ppufile.getreal;
  873. end;
  874. procedure tai_comp_64bit.ppuwrite(ppufile:tcompilerppufile);
  875. begin
  876. inherited ppuwrite(ppufile);
  877. ppufile.putreal(value);
  878. end;
  879. {****************************************************************************
  880. TAI_STRING
  881. ****************************************************************************}
  882. constructor tai_string.Create(const _str : string);
  883. begin
  884. inherited Create;
  885. typ:=ait_string;
  886. len:=length(_str);
  887. getmem(str,len+1);
  888. strpcopy(str,_str);
  889. end;
  890. constructor tai_string.Create_pchar(_str : pchar);
  891. begin
  892. inherited Create;
  893. typ:=ait_string;
  894. str:=_str;
  895. len:=strlen(_str);
  896. end;
  897. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  898. begin
  899. inherited Create;
  900. typ:=ait_string;
  901. str:=_str;
  902. len:=length;
  903. end;
  904. destructor tai_string.destroy;
  905. begin
  906. { you can have #0 inside the strings so }
  907. if str<>nil then
  908. freemem(str,len+1);
  909. inherited Destroy;
  910. end;
  911. constructor tai_string.ppuload(t:taitype;ppufile:tcompilerppufile);
  912. begin
  913. inherited ppuload(t,ppufile);
  914. len:=ppufile.getlongint;
  915. getmem(str,len+1);
  916. ppufile.getdata(str^,len);
  917. str[len]:=#0;
  918. end;
  919. procedure tai_string.ppuwrite(ppufile:tcompilerppufile);
  920. begin
  921. inherited ppuwrite(ppufile);
  922. ppufile.putlongint(len);
  923. ppufile.putdata(str^,len);
  924. end;
  925. function tai_string.getcopy : tlinkedlistitem;
  926. var
  927. p : tlinkedlistitem;
  928. begin
  929. p:=inherited getcopy;
  930. getmem(tai_string(p).str,len+1);
  931. move(str^,tai_string(p).str^,len+1);
  932. getcopy:=p;
  933. end;
  934. {****************************************************************************
  935. TAI_LABEL
  936. ****************************************************************************}
  937. constructor tai_label.create(_l : tasmlabel);
  938. begin
  939. inherited Create;
  940. typ:=ait_label;
  941. l:=_l;
  942. { checkredefinesym(l);}
  943. l.is_set:=true;
  944. is_global:=(l.defbind=AB_GLOBAL);
  945. end;
  946. constructor tai_label.ppuload(t:taitype;ppufile:tcompilerppufile);
  947. begin
  948. inherited ppuload(t,ppufile);
  949. l:=tasmlabel(ppufile.getasmsymbol);
  950. is_global:=boolean(ppufile.getbyte);
  951. end;
  952. procedure tai_label.ppuwrite(ppufile:tcompilerppufile);
  953. begin
  954. inherited ppuwrite(ppufile);
  955. ppufile.putasmsymbol(l);
  956. ppufile.putbyte(byte(is_global));
  957. end;
  958. procedure tai_label.derefimpl;
  959. begin
  960. objectlibrary.DerefAsmsymbol(tasmsymbol(l));
  961. l.is_set:=true;
  962. end;
  963. {****************************************************************************
  964. TAI_DIRECT
  965. ****************************************************************************}
  966. constructor tai_direct.Create(_str : pchar);
  967. begin
  968. inherited Create;
  969. typ:=ait_direct;
  970. str:=_str;
  971. end;
  972. destructor tai_direct.destroy;
  973. begin
  974. strdispose(str);
  975. inherited Destroy;
  976. end;
  977. constructor tai_direct.ppuload(t:taitype;ppufile:tcompilerppufile);
  978. var
  979. len : longint;
  980. begin
  981. inherited ppuload(t,ppufile);
  982. len:=ppufile.getlongint;
  983. getmem(str,len+1);
  984. ppufile.getdata(str^,len);
  985. str[len]:=#0;
  986. end;
  987. procedure tai_direct.ppuwrite(ppufile:tcompilerppufile);
  988. var
  989. len : longint;
  990. begin
  991. inherited ppuwrite(ppufile);
  992. len:=strlen(str);
  993. ppufile.putlongint(len);
  994. ppufile.putdata(str^,len);
  995. end;
  996. function tai_direct.getcopy : tlinkedlistitem;
  997. var
  998. p : tlinkedlistitem;
  999. begin
  1000. p:=inherited getcopy;
  1001. getmem(tai_direct(p).str,strlen(str)+1);
  1002. move(str^,tai_direct(p).str^,strlen(str)+1);
  1003. getcopy:=p;
  1004. end;
  1005. {****************************************************************************
  1006. tai_comment comment to be inserted in the assembler file
  1007. ****************************************************************************}
  1008. constructor tai_comment.Create(_str : pchar);
  1009. begin
  1010. inherited Create;
  1011. typ:=ait_comment;
  1012. str:=_str;
  1013. end;
  1014. destructor tai_comment.destroy;
  1015. begin
  1016. strdispose(str);
  1017. inherited Destroy;
  1018. end;
  1019. constructor tai_comment.ppuload(t:taitype;ppufile:tcompilerppufile);
  1020. var
  1021. len : longint;
  1022. begin
  1023. inherited ppuload(t,ppufile);
  1024. len:=ppufile.getlongint;
  1025. getmem(str,len+1);
  1026. ppufile.getdata(str^,len);
  1027. str[len]:=#0;
  1028. end;
  1029. procedure tai_comment.ppuwrite(ppufile:tcompilerppufile);
  1030. var
  1031. len : longint;
  1032. begin
  1033. inherited ppuwrite(ppufile);
  1034. len:=strlen(str);
  1035. ppufile.putlongint(len);
  1036. ppufile.putdata(str^,len);
  1037. end;
  1038. function tai_comment.getcopy : tlinkedlistitem;
  1039. var
  1040. p : tlinkedlistitem;
  1041. begin
  1042. p:=inherited getcopy;
  1043. getmem(tai_comment(p).str,strlen(str)+1);
  1044. move(str^,tai_comment(p).str^,strlen(str)+1);
  1045. getcopy:=p;
  1046. end;
  1047. {****************************************************************************
  1048. TAI_CUT
  1049. ****************************************************************************}
  1050. constructor tai_cut.Create;
  1051. begin
  1052. inherited Create;
  1053. typ:=ait_cut;
  1054. place:=cut_normal;
  1055. end;
  1056. constructor tai_cut.Create_begin;
  1057. begin
  1058. inherited Create;
  1059. typ:=ait_cut;
  1060. place:=cut_begin;
  1061. end;
  1062. constructor tai_cut.Create_end;
  1063. begin
  1064. inherited Create;
  1065. typ:=ait_cut;
  1066. place:=cut_end;
  1067. end;
  1068. constructor tai_cut.ppuload(t:taitype;ppufile:tcompilerppufile);
  1069. begin
  1070. inherited ppuload(t,ppufile);
  1071. place:=TCutPlace(ppufile.getbyte);
  1072. end;
  1073. procedure tai_cut.ppuwrite(ppufile:tcompilerppufile);
  1074. begin
  1075. inherited ppuwrite(ppufile);
  1076. ppufile.putbyte(byte(place));
  1077. end;
  1078. {****************************************************************************
  1079. Tai_Marker
  1080. ****************************************************************************}
  1081. constructor Tai_Marker.Create(_Kind: TMarker);
  1082. begin
  1083. Inherited Create;
  1084. typ := ait_marker;
  1085. Kind := _Kind;
  1086. end;
  1087. constructor Tai_Marker.ppuload(t:taitype;ppufile:tcompilerppufile);
  1088. begin
  1089. inherited ppuload(t,ppufile);
  1090. kind:=TMarker(ppufile.getbyte);
  1091. end;
  1092. procedure Tai_Marker.ppuwrite(ppufile:tcompilerppufile);
  1093. begin
  1094. inherited ppuwrite(ppufile);
  1095. ppufile.putbyte(byte(kind));
  1096. end;
  1097. {*****************************************************************************
  1098. tai_tempalloc
  1099. *****************************************************************************}
  1100. constructor tai_tempalloc.alloc(pos,size:longint);
  1101. begin
  1102. inherited Create;
  1103. typ:=ait_tempalloc;
  1104. allocation:=true;
  1105. temppos:=pos;
  1106. tempsize:=size;
  1107. {$ifdef EXTDEBUG}
  1108. problem:=nil;
  1109. {$endif EXTDEBUG}
  1110. end;
  1111. constructor tai_tempalloc.dealloc(pos,size:longint);
  1112. begin
  1113. inherited Create;
  1114. typ:=ait_tempalloc;
  1115. allocation:=false;
  1116. temppos:=pos;
  1117. tempsize:=size;
  1118. {$ifdef EXTDEBUG}
  1119. problem:=nil;
  1120. {$endif EXTDEBUG}
  1121. end;
  1122. {$ifdef EXTDEBUG}
  1123. constructor tai_tempalloc.allocinfo(pos,size:longint;const st:string);
  1124. begin
  1125. inherited Create;
  1126. typ:=ait_tempalloc;
  1127. allocation:=false;
  1128. temppos:=pos;
  1129. tempsize:=size;
  1130. problem:=stringdup(st);
  1131. end;
  1132. {$endif EXTDEBUG}
  1133. constructor tai_tempalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1134. begin
  1135. inherited ppuload(t,ppufile);
  1136. temppos:=ppufile.getlongint;
  1137. tempsize:=ppufile.getlongint;
  1138. allocation:=boolean(ppufile.getbyte);
  1139. {$ifdef EXTDEBUG}
  1140. problem:=nil;
  1141. {$endif EXTDEBUG}
  1142. end;
  1143. procedure tai_tempalloc.ppuwrite(ppufile:tcompilerppufile);
  1144. begin
  1145. inherited ppuwrite(ppufile);
  1146. ppufile.putlongint(temppos);
  1147. ppufile.putlongint(tempsize);
  1148. ppufile.putbyte(byte(allocation));
  1149. end;
  1150. {*****************************************************************************
  1151. tai_regalloc
  1152. *****************************************************************************}
  1153. constructor tai_regalloc.alloc(r : tregister);
  1154. begin
  1155. inherited create;
  1156. typ:=ait_regalloc;
  1157. allocation:=true;
  1158. reg:=r;
  1159. end;
  1160. constructor tai_regalloc.dealloc(r : tregister);
  1161. begin
  1162. inherited create;
  1163. typ:=ait_regalloc;
  1164. allocation:=false;
  1165. reg:=r;
  1166. end;
  1167. constructor tai_regalloc.ppuload(t:taitype;ppufile:tcompilerppufile);
  1168. begin
  1169. inherited ppuload(t,ppufile);
  1170. ppufile.getdata(reg,sizeof(Tregister));
  1171. allocation:=boolean(ppufile.getbyte);
  1172. end;
  1173. procedure tai_regalloc.ppuwrite(ppufile:tcompilerppufile);
  1174. begin
  1175. inherited ppuwrite(ppufile);
  1176. ppufile.putdata(reg,sizeof(Tregister));
  1177. ppufile.putbyte(byte(allocation));
  1178. end;
  1179. {*****************************************************************************
  1180. TaiInstruction
  1181. *****************************************************************************}
  1182. constructor taicpu_abstract.Create(op : tasmop);
  1183. begin
  1184. inherited create;
  1185. typ:=ait_instruction;
  1186. is_jmp:=false;
  1187. opcode:=op;
  1188. ops:=0;
  1189. fillchar(condition,sizeof(condition),0);
  1190. fillchar(oper,sizeof(oper),0);
  1191. end;
  1192. destructor taicpu_abstract.Destroy;
  1193. var
  1194. i : longint;
  1195. begin
  1196. for i:=0 to ops-1 do
  1197. case oper[i].typ of
  1198. top_ref:
  1199. dispose(oper[i].ref);
  1200. end;
  1201. inherited destroy;
  1202. end;
  1203. { ---------------------------------------------------------------------
  1204. Loading of operands.
  1205. ---------------------------------------------------------------------}
  1206. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  1207. begin
  1208. if opidx>=ops then
  1209. ops:=opidx+1;
  1210. with oper[opidx] do
  1211. begin
  1212. if typ=top_ref then
  1213. dispose(ref);
  1214. val:=l;
  1215. typ:=top_const;
  1216. end;
  1217. end;
  1218. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  1219. begin
  1220. if not assigned(s) then
  1221. internalerror(200204251);
  1222. if opidx>=ops then
  1223. ops:=opidx+1;
  1224. with oper[opidx] do
  1225. begin
  1226. if typ=top_ref then
  1227. dispose(ref);
  1228. sym:=s;
  1229. symofs:=sofs;
  1230. typ:=top_symbol;
  1231. end;
  1232. s.increfs;
  1233. end;
  1234. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  1235. begin
  1236. if opidx>=ops then
  1237. ops:=opidx+1;
  1238. with oper[opidx] do
  1239. begin
  1240. if typ<>top_ref then
  1241. new(ref);
  1242. ref^:=r;
  1243. {$ifdef i386}
  1244. { We allow this exception for i386, since overloading this would be
  1245. too much of a a speed penalty}
  1246. if ref^.segment.enum=R_INTREGISTER then
  1247. begin
  1248. if (ref^.segment.number <> NR_NO) and (ref^.segment.number <> NR_DS) then
  1249. segprefix:=ref^.segment;
  1250. end
  1251. else
  1252. if not(ref^.segment.enum in [R_DS,R_NO]) then
  1253. segprefix:=ref^.segment;
  1254. {$endif}
  1255. typ:=top_ref;
  1256. { mark symbol as used }
  1257. if assigned(ref^.symbol) then
  1258. ref^.symbol.increfs;
  1259. end;
  1260. end;
  1261. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  1262. begin
  1263. if opidx>=ops then
  1264. ops:=opidx+1;
  1265. with oper[opidx] do
  1266. begin
  1267. if typ=top_ref then
  1268. dispose(ref);
  1269. reg:=r;
  1270. typ:=top_reg;
  1271. end;
  1272. end;
  1273. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  1274. begin
  1275. if opidx>=ops then
  1276. ops:=opidx+1;
  1277. if oper[opidx].typ=top_ref then
  1278. dispose(oper[opidx].ref);
  1279. oper[opidx]:=o;
  1280. { copy also the reference }
  1281. if oper[opidx].typ=top_ref then
  1282. begin
  1283. new(oper[opidx].ref);
  1284. oper[opidx].ref^:=o.ref^;
  1285. end;
  1286. end;
  1287. { ---------------------------------------------------------------------
  1288. Miscellaneous methods.
  1289. ---------------------------------------------------------------------}
  1290. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  1291. begin
  1292. condition:=c;
  1293. end;
  1294. Function taicpu_abstract.getcopy:TLinkedListItem;
  1295. var
  1296. i : longint;
  1297. p : TLinkedListItem;
  1298. begin
  1299. p:=inherited getcopy;
  1300. { make a copy of the references }
  1301. for i:=1 to ops do
  1302. if (taicpu_abstract(p).oper[i-1].typ=top_ref) then
  1303. begin
  1304. new(taicpu_abstract(p).oper[i-1].ref);
  1305. taicpu_abstract(p).oper[i-1].ref^:=oper[i-1].ref^;
  1306. end;
  1307. getcopy:=p;
  1308. end;
  1309. constructor taicpu_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1310. var
  1311. i : integer;
  1312. begin
  1313. inherited ppuload(t,ppufile);
  1314. { hopefully, we don't get problems with big/litte endian here when cross compiling :/ }
  1315. ppufile.getdata(condition,sizeof(tasmcond));
  1316. ops:=ppufile.getbyte;
  1317. for i:=1 to ops do
  1318. ppuloadoper(ppufile,oper[i-1]);
  1319. opcode:=tasmop(ppufile.getword);
  1320. {$ifdef i386}
  1321. ppufile.getdata(segprefix,sizeof(Tregister));
  1322. {$endif i386}
  1323. is_jmp:=boolean(ppufile.getbyte);
  1324. end;
  1325. procedure taicpu_abstract.ppuwrite(ppufile:tcompilerppufile);
  1326. var
  1327. i : integer;
  1328. begin
  1329. inherited ppuwrite(ppufile);
  1330. ppufile.putdata(condition,sizeof(tasmcond));
  1331. ppufile.putbyte(ops);
  1332. for i:=1 to ops do
  1333. ppuwriteoper(ppufile,oper[i-1]);
  1334. ppufile.putword(word(opcode));
  1335. {$ifdef i386}
  1336. ppufile.putdata(segprefix,sizeof(Tregister));
  1337. {$endif i386}
  1338. ppufile.putbyte(byte(is_jmp));
  1339. end;
  1340. procedure taicpu_abstract.derefimpl;
  1341. var
  1342. i : integer;
  1343. begin
  1344. for i:=1 to ops do
  1345. ppuderefoper(oper[i-1]);
  1346. end;
  1347. {****************************************************************************
  1348. tai_align_abstract
  1349. ****************************************************************************}
  1350. constructor tai_align_abstract.Create(b: byte);
  1351. begin
  1352. inherited Create;
  1353. typ:=ait_align;
  1354. if b in [1,2,4,8,16,32] then
  1355. aligntype := b
  1356. else
  1357. aligntype := 1;
  1358. fillsize:=0;
  1359. fillop:=0;
  1360. use_op:=false;
  1361. end;
  1362. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  1363. begin
  1364. inherited Create;
  1365. typ:=ait_align;
  1366. if b in [1,2,4,8,16,32] then
  1367. aligntype := b
  1368. else
  1369. aligntype := 1;
  1370. fillsize:=0;
  1371. fillop:=_op;
  1372. use_op:=true;
  1373. end;
  1374. function tai_align_abstract.calculatefillbuf(var buf : tfillbuffer):pchar;
  1375. begin
  1376. fillchar(buf,high(buf),fillop);
  1377. calculatefillbuf:=pchar(@buf);
  1378. end;
  1379. constructor tai_align_abstract.ppuload(t:taitype;ppufile:tcompilerppufile);
  1380. begin
  1381. inherited ppuload(t,ppufile);
  1382. aligntype:=ppufile.getbyte;
  1383. fillsize:=0;
  1384. fillop:=ppufile.getbyte;
  1385. use_op:=boolean(ppufile.getbyte);
  1386. end;
  1387. procedure tai_align_abstract.ppuwrite(ppufile:tcompilerppufile);
  1388. begin
  1389. inherited ppuwrite(ppufile);
  1390. ppufile.putbyte(aligntype);
  1391. ppufile.putbyte(fillop);
  1392. ppufile.putbyte(byte(use_op));
  1393. end;
  1394. {*****************************************************************************
  1395. TAAsmOutput
  1396. *****************************************************************************}
  1397. function taasmoutput.getlasttaifilepos : pfileposinfo;
  1398. var
  1399. hp : tlinkedlistitem;
  1400. begin
  1401. getlasttaifilepos := nil;
  1402. if assigned(last) then
  1403. begin
  1404. { find the last file information record }
  1405. if not (tai(last).typ in SkipLineInfo) then
  1406. getlasttaifilepos:=@tailineinfo(last).fileinfo
  1407. else
  1408. { go through list backwards to find the first entry
  1409. with line information
  1410. }
  1411. begin
  1412. hp:=tai(last);
  1413. while assigned(hp) and (tai(hp).typ in SkipLineInfo) do
  1414. hp:=hp.Previous;
  1415. { found entry }
  1416. if assigned(hp) then
  1417. getlasttaifilepos:=@tailineinfo(hp).fileinfo
  1418. end;
  1419. end;
  1420. end;
  1421. procedure Taasmoutput.convert_registers;
  1422. var p:Tai;
  1423. i:shortint;
  1424. r:Preference;
  1425. begin
  1426. p:=Tai(first);
  1427. while assigned(p) do
  1428. begin
  1429. case p.typ of
  1430. ait_regalloc:
  1431. convert_register_to_enum(Tai_regalloc(p).reg);
  1432. ait_instruction:
  1433. begin
  1434. for i:=0 to Taicpu_abstract(p).ops-1 do
  1435. if Taicpu_abstract(p).oper[i].typ=Top_reg then
  1436. begin
  1437. if Taicpu_abstract(p).oper[i].reg.enum=R_NO then
  1438. internalerror(200302052);
  1439. convert_register_to_enum(Taicpu_abstract(p).oper[i].reg)
  1440. end
  1441. else if Taicpu_abstract(p).oper[i].typ=Top_ref then
  1442. begin
  1443. r:=Taicpu_abstract(p).oper[i].ref;
  1444. {$ifdef i386}
  1445. convert_register_to_enum(r^.segment);
  1446. {$endif i386}
  1447. convert_register_to_enum(r^.base);
  1448. convert_register_to_enum(r^.index);
  1449. end;
  1450. {$ifdef i386}
  1451. convert_register_to_enum(Taicpu_abstract(p).segprefix);
  1452. {$endif}
  1453. end;
  1454. end;
  1455. p:=Tai(p.next);
  1456. end;
  1457. end;
  1458. end.
  1459. {
  1460. $Log$
  1461. Revision 1.21 2003-02-19 22:00:14 daniel
  1462. * Code generator converted to new register notation
  1463. - Horribily outdated todo.txt removed
  1464. Revision 1.20 2003/01/30 21:46:20 peter
  1465. * tai_const_symbol.createdataname added
  1466. Revision 1.19 2003/01/21 08:48:08 daniel
  1467. * Another 200301081 fixed
  1468. Revision 1.18 2003/01/09 20:40:59 daniel
  1469. * Converted some code in cgx86.pas to new register numbering
  1470. Revision 1.17 2003/01/09 15:49:56 daniel
  1471. * Added register conversion
  1472. Revision 1.16 2003/01/08 18:43:56 daniel
  1473. * Tregister changed into a record
  1474. Revision 1.15 2003/01/05 13:36:53 florian
  1475. * x86-64 compiles
  1476. + very basic support for float128 type (x86-64 only)
  1477. Revision 1.14 2002/12/06 17:50:21 peter
  1478. * symbol count fix merged
  1479. Revision 1.13 2002/11/17 16:31:55 carl
  1480. * memory optimization (3-4%) : cleanup of tai fields,
  1481. cleanup of tdef and tsym fields.
  1482. * make it work for m68k
  1483. Revision 1.12 2002/11/15 16:29:30 peter
  1484. * made tasmsymbol.refs private (merged)
  1485. Revision 1.11 2002/11/15 01:58:45 peter
  1486. * merged changes from 1.0.7 up to 04-11
  1487. - -V option for generating bug report tracing
  1488. - more tracing for option parsing
  1489. - errors for cdecl and high()
  1490. - win32 import stabs
  1491. - win32 records<=8 are returned in eax:edx (turned off by default)
  1492. - heaptrc update
  1493. - more info for temp management in .s file with EXTDEBUG
  1494. Revision 1.10 2002/11/09 15:38:03 carl
  1495. + NOOPT removed the optinfo field
  1496. Revision 1.9 2002/10/05 12:43:23 carl
  1497. * fixes for Delphi 6 compilation
  1498. (warning : Some features do not work under Delphi)
  1499. Revision 1.8 2002/08/19 19:36:42 peter
  1500. * More fixes for cross unit inlining, all tnodes are now implemented
  1501. * Moved pocall_internconst to po_internconst because it is not a
  1502. calling type at all and it conflicted when inlining of these small
  1503. functions was requested
  1504. Revision 1.7 2002/08/18 20:06:23 peter
  1505. * inlining is now also allowed in interface
  1506. * renamed write/load to ppuwrite/ppuload
  1507. * tnode storing in ppu
  1508. * nld,ncon,nbas are already updated for storing in ppu
  1509. Revision 1.6 2002/08/16 05:21:09 florian
  1510. * powerpc compilation fix
  1511. Revision 1.5 2002/08/15 19:10:35 peter
  1512. * first things tai,tnode storing in ppu
  1513. Revision 1.4 2002/08/11 14:32:25 peter
  1514. * renamed current_library to objectlibrary
  1515. Revision 1.3 2002/08/11 13:24:10 peter
  1516. * saving of asmsymbols in ppu supported
  1517. * asmsymbollist global is removed and moved into a new class
  1518. tasmlibrarydata that will hold the info of a .a file which
  1519. corresponds with a single module. Added librarydata to tmodule
  1520. to keep the library info stored for the module. In the future the
  1521. objectfiles will also be stored to the tasmlibrarydata class
  1522. * all getlabel/newasmsymbol and friends are moved to the new class
  1523. Revision 1.2 2002/08/05 18:27:48 carl
  1524. + more more more documentation
  1525. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1526. Revision 1.1 2002/07/01 18:46:20 peter
  1527. * internal linker
  1528. * reorganized aasm layer
  1529. Revision 1.27 2002/05/18 13:34:04 peter
  1530. * readded missing revisions
  1531. Revision 1.25 2002/05/14 19:34:38 peter
  1532. * removed old logs and updated copyright year
  1533. Revision 1.24 2002/05/14 17:28:08 peter
  1534. * synchronized cpubase between powerpc and i386
  1535. * moved more tables from cpubase to cpuasm
  1536. * tai_align_abstract moved to tainst, cpuasm must define
  1537. the tai_align class now, which may be empty
  1538. Revision 1.23 2002/04/15 18:54:34 carl
  1539. - removed tcpuflags
  1540. Revision 1.22 2002/04/07 13:18:19 carl
  1541. + more documentation
  1542. Revision 1.21 2002/04/07 10:17:40 carl
  1543. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  1544. + changing some comments so its commented automatically
  1545. Revision 1.20 2002/03/24 19:04:31 carl
  1546. + patch for SPARC from Mazen NEIFER
  1547. }