aasmtai.pas 51 KB

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