aasmtai.pas 53 KB

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