aasmtai.pas 51 KB

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