aasmtai.pas 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. aasmbase;
  31. type
  32. tait = (
  33. ait_none,
  34. ait_direct,
  35. ait_string,
  36. ait_label,
  37. ait_comment,
  38. ait_instruction,
  39. ait_datablock,
  40. ait_symbol,
  41. ait_symbol_end, { needed to calc the size of a symbol }
  42. ait_const_32bit,
  43. ait_const_16bit,
  44. ait_const_8bit,
  45. ait_const_symbol,
  46. ait_real_80bit,
  47. ait_real_64bit,
  48. ait_real_32bit,
  49. ait_comp_64bit,
  50. ait_align,
  51. ait_section,
  52. { the following is only used by the win32 version of the compiler }
  53. { and only the GNU AS Win32 is able to write it }
  54. ait_const_rva,
  55. {$ifdef GDB}
  56. ait_stabn,
  57. ait_stabs,
  58. ait_force_line,
  59. ait_stab_function_name,
  60. {$endif GDB}
  61. ait_cut, { used to split into tiny assembler files }
  62. ait_regalloc,
  63. ait_tempalloc,
  64. ait_marker, { used to mark assembler blocks and inlined functions }
  65. {$ifdef alpha}
  66. { the follow is for the DEC Alpha }
  67. ait_frame,
  68. ait_ent,
  69. {$endif alpha}
  70. {$ifdef m68k}
  71. ait_labeled_instruction,
  72. {$endif m68k}
  73. {$ifdef ia64}
  74. ait_bundle,
  75. ait_stop,
  76. {$endif ia64}
  77. {$ifdef SPARC}
  78. ait_labeled_instruction,
  79. {$endif SPARC}
  80. { never used, makes insertation of new ait_ easier to type }
  81. { lazy guy !!!! ;-) (FK) }
  82. ait_dummy);
  83. { ait_* types which don't result in executable code or which don't influence }
  84. { the way the program runs/behaves, but which may be encountered by the }
  85. { optimizer (= if it's sometimes added to the exprasm list). Update if you add }
  86. { a new ait type! }
  87. const
  88. SkipInstr = [ait_comment, ait_symbol,ait_section
  89. {$ifdef GDB}
  90. ,ait_stabs, ait_stabn, ait_stab_function_name, ait_force_line
  91. {$endif GDB}
  92. ,ait_regalloc, ait_tempalloc, ait_symbol_end];
  93. type
  94. { cut type, required for alphanumeric ordering of the assembler filenames }
  95. TCutPlace=(cut_normal,cut_begin,cut_end);
  96. TMarker = (NoPropInfoStart,NoPropInfoEnd,
  97. AsmBlockStart,AsmBlockEnd,
  98. InlineStart,InlineEnd);
  99. { the short name makes typing easier }
  100. tai = class(TLinkedListItem)
  101. { pointer to record with optimizer info about this tai object }
  102. optinfo : pointer;
  103. fileinfo : tfileposinfo;
  104. typ : tait;
  105. constructor Create;
  106. end;
  107. tai_string = class(tai)
  108. str : pchar;
  109. { extra len so the string can contain an \0 }
  110. len : longint;
  111. constructor Create(const _str : string);
  112. constructor Create_pchar(_str : pchar);
  113. constructor Create_length_pchar(_str : pchar;length : longint);
  114. destructor Destroy;override;
  115. end;
  116. { generates a common label }
  117. tai_symbol = class(tai)
  118. is_global : boolean;
  119. sym : tasmsymbol;
  120. size : longint;
  121. constructor Create(_sym:tasmsymbol;siz:longint);
  122. constructor Createname(const _name : string;siz:longint);
  123. constructor Createname_global(const _name : string;siz:longint);
  124. constructor Createdataname(const _name : string;siz:longint);
  125. constructor Createdataname_global(const _name : string;siz:longint);
  126. end;
  127. tai_symbol_end = class(tai)
  128. sym : tasmsymbol;
  129. constructor Create(_sym:tasmsymbol);
  130. constructor Createname(const _name : string);
  131. end;
  132. tai_label = class(tai)
  133. is_global : boolean;
  134. l : tasmlabel;
  135. constructor Create(_l : tasmlabel);
  136. end;
  137. tai_direct = class(tai)
  138. str : pchar;
  139. constructor Create(_str : pchar);
  140. destructor Destroy; override;
  141. end;
  142. { to insert a comment into the generated assembler file }
  143. tai_asm_comment = class(tai)
  144. str : pchar;
  145. constructor Create(_str : pchar);
  146. destructor Destroy; override;
  147. end;
  148. { Insert a section/segment directive }
  149. tai_section = class(tai)
  150. sec : TSection;
  151. constructor Create(s : TSection);
  152. end;
  153. { generates an uninitializised data block }
  154. tai_datablock = class(tai)
  155. is_global : boolean;
  156. sym : tasmsymbol;
  157. size : longint;
  158. constructor Create(const _name : string;_size : longint);
  159. constructor Create_global(const _name : string;_size : longint);
  160. end;
  161. { generates a long integer (32 bit) }
  162. tai_const = class(tai)
  163. value : longint;
  164. constructor Create_32bit(_value : longint);
  165. constructor Create_16bit(_value : word);
  166. constructor Create_8bit(_value : byte);
  167. end;
  168. tai_const_symbol = class(tai)
  169. sym : tasmsymbol;
  170. offset : longint;
  171. constructor Create(_sym:tasmsymbol);
  172. constructor Create_offset(_sym:tasmsymbol;ofs:longint);
  173. constructor Create_rva(_sym:tasmsymbol);
  174. constructor Createname(const name:string);
  175. constructor Createname_offset(const name:string;ofs:longint);
  176. constructor Createname_rva(const name:string);
  177. end;
  178. { generates a single (32 bit real) }
  179. tai_real_32bit = class(tai)
  180. value : ts32real;
  181. constructor Create(_value : ts32real);
  182. end;
  183. { generates a double (64 bit real) }
  184. tai_real_64bit = class(tai)
  185. value : ts64real;
  186. constructor Create(_value : ts64real);
  187. end;
  188. { generates an extended (80 bit real) }
  189. tai_real_80bit = class(tai)
  190. value : ts80real;
  191. constructor Create(_value : ts80real);
  192. end;
  193. { generates an comp (integer over 64 bits) }
  194. tai_comp_64bit = class(tai)
  195. value : ts64comp;
  196. constructor Create(_value : ts64comp);
  197. end;
  198. { insert a cut to split into several smaller files }
  199. tai_cut = class(tai)
  200. place : tcutplace;
  201. constructor Create;
  202. constructor Create_begin;
  203. constructor Create_end;
  204. end;
  205. { insert a marker for assembler and inline blocks }
  206. tai_marker = class(tai)
  207. Kind: TMarker;
  208. Constructor Create(_Kind: TMarker);
  209. end;
  210. tai_tempalloc = class(tai)
  211. allocation : boolean;
  212. temppos,
  213. tempsize : longint;
  214. constructor alloc(pos,size:longint);
  215. constructor dealloc(pos,size:longint);
  216. end;
  217. tai_regalloc = class(tai)
  218. allocation : boolean;
  219. reg : tregister;
  220. constructor alloc(r : tregister);
  221. constructor dealloc(r : tregister);
  222. end;
  223. taicpu_abstract = class(tai)
  224. condition : TAsmCond;
  225. ops : longint;
  226. oper : array[0..max_operands-1] of toper;
  227. opcode : tasmop;
  228. {$ifdef i386}
  229. segprefix : tregister;
  230. {$endif i386}
  231. is_jmp : boolean; { is this instruction a jump? (needed for optimizer) }
  232. Constructor Create(op : tasmop);
  233. Destructor Destroy;override;
  234. function getcopy:TLinkedListItem;override;
  235. procedure loadconst(opidx:longint;l:aword);
  236. procedure loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  237. procedure loadref(opidx:longint;const r:treference);
  238. procedure loadreg(opidx:longint;r:tregister);
  239. procedure loadoper(opidx:longint;o:toper);
  240. procedure SetCondition(const c:TAsmCond);
  241. end;
  242. { alignment for operator }
  243. tai_align_abstract = class(tai)
  244. buf : array[0..63] of char; { buf used for fill }
  245. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  246. fillsize : byte; { real size to fill }
  247. fillop : byte; { value to fill with - optional }
  248. use_op : boolean;
  249. constructor Create(b:byte);
  250. constructor Create_op(b: byte; _op: byte);
  251. function getfillbuf:pchar;virtual;
  252. end;
  253. taasmoutput = class(tlinkedlist)
  254. function getlasttaifilepos : pfileposinfo;
  255. end;
  256. var
  257. { temporary lists }
  258. exprasmlist,
  259. { default lists }
  260. datasegment,codesegment,bsssegment,
  261. debuglist,withdebuglist,consts,
  262. importssection,exportssection,
  263. resourcesection,rttilist,
  264. resourcestringlist : taasmoutput;
  265. implementation
  266. uses
  267. {$ifdef delphi}
  268. sysutils,
  269. {$else}
  270. strings,
  271. {$endif}
  272. verbose;
  273. {****************************************************************************
  274. TAI
  275. ****************************************************************************}
  276. constructor tai.Create;
  277. begin
  278. optinfo := nil;
  279. fileinfo:=aktfilepos;
  280. end;
  281. {****************************************************************************
  282. TAI_SECTION
  283. ****************************************************************************}
  284. constructor tai_section.Create(s : TSection);
  285. begin
  286. inherited Create;
  287. typ:=ait_section;
  288. sec:=s;
  289. end;
  290. {****************************************************************************
  291. TAI_DATABLOCK
  292. ****************************************************************************}
  293. constructor tai_datablock.Create(const _name : string;_size : longint);
  294. begin
  295. inherited Create;
  296. typ:=ait_datablock;
  297. sym:=newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  298. { keep things aligned }
  299. if _size<=0 then
  300. _size:=4;
  301. size:=_size;
  302. is_global:=false;
  303. end;
  304. constructor tai_datablock.Create_global(const _name : string;_size : longint);
  305. begin
  306. inherited Create;
  307. typ:=ait_datablock;
  308. sym:=newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  309. { keep things aligned }
  310. if _size<=0 then
  311. _size:=4;
  312. size:=_size;
  313. is_global:=true;
  314. end;
  315. {****************************************************************************
  316. TAI_SYMBOL
  317. ****************************************************************************}
  318. constructor tai_symbol.Create(_sym:tasmsymbol;siz:longint);
  319. begin
  320. inherited Create;
  321. typ:=ait_symbol;
  322. sym:=_sym;
  323. size:=siz;
  324. is_global:=(sym.defbind=AB_GLOBAL);
  325. end;
  326. constructor tai_symbol.Createname(const _name : string;siz:longint);
  327. begin
  328. inherited Create;
  329. typ:=ait_symbol;
  330. sym:=newasmsymboltype(_name,AB_LOCAL,AT_FUNCTION);
  331. size:=siz;
  332. is_global:=false;
  333. end;
  334. constructor tai_symbol.Createname_global(const _name : string;siz:longint);
  335. begin
  336. inherited Create;
  337. typ:=ait_symbol;
  338. sym:=newasmsymboltype(_name,AB_GLOBAL,AT_FUNCTION);
  339. size:=siz;
  340. is_global:=true;
  341. end;
  342. constructor tai_symbol.Createdataname(const _name : string;siz:longint);
  343. begin
  344. inherited Create;
  345. typ:=ait_symbol;
  346. sym:=newasmsymboltype(_name,AB_LOCAL,AT_DATA);
  347. size:=siz;
  348. is_global:=false;
  349. end;
  350. constructor tai_symbol.Createdataname_global(const _name : string;siz:longint);
  351. begin
  352. inherited Create;
  353. typ:=ait_symbol;
  354. sym:=newasmsymboltype(_name,AB_GLOBAL,AT_DATA);
  355. size:=siz;
  356. is_global:=true;
  357. end;
  358. {****************************************************************************
  359. TAI_SYMBOL
  360. ****************************************************************************}
  361. constructor tai_symbol_end.Create(_sym:tasmsymbol);
  362. begin
  363. inherited Create;
  364. typ:=ait_symbol_end;
  365. sym:=_sym;
  366. end;
  367. constructor tai_symbol_end.Createname(const _name : string);
  368. begin
  369. inherited Create;
  370. typ:=ait_symbol_end;
  371. sym:=newasmsymboltype(_name,AB_GLOBAL,AT_NONE);
  372. end;
  373. {****************************************************************************
  374. TAI_CONST
  375. ****************************************************************************}
  376. constructor tai_const.Create_32bit(_value : longint);
  377. begin
  378. inherited Create;
  379. typ:=ait_const_32bit;
  380. value:=_value;
  381. end;
  382. constructor tai_const.Create_16bit(_value : word);
  383. begin
  384. inherited Create;
  385. typ:=ait_const_16bit;
  386. value:=_value;
  387. end;
  388. constructor tai_const.Create_8bit(_value : byte);
  389. begin
  390. inherited Create;
  391. typ:=ait_const_8bit;
  392. value:=_value;
  393. end;
  394. {****************************************************************************
  395. TAI_CONST_SYMBOL_OFFSET
  396. ****************************************************************************}
  397. constructor tai_const_symbol.Create(_sym:tasmsymbol);
  398. begin
  399. inherited Create;
  400. typ:=ait_const_symbol;
  401. sym:=_sym;
  402. offset:=0;
  403. { update sym info }
  404. inc(sym.refs);
  405. end;
  406. constructor tai_const_symbol.Create_offset(_sym:tasmsymbol;ofs:longint);
  407. begin
  408. inherited Create;
  409. typ:=ait_const_symbol;
  410. sym:=_sym;
  411. offset:=ofs;
  412. { update sym info }
  413. inc(sym.refs);
  414. end;
  415. constructor tai_const_symbol.Create_rva(_sym:tasmsymbol);
  416. begin
  417. inherited Create;
  418. typ:=ait_const_rva;
  419. sym:=_sym;
  420. offset:=0;
  421. { update sym info }
  422. inc(sym.refs);
  423. end;
  424. constructor tai_const_symbol.Createname(const name:string);
  425. begin
  426. inherited Create;
  427. typ:=ait_const_symbol;
  428. sym:=newasmsymbol(name);
  429. offset:=0;
  430. { update sym info }
  431. inc(sym.refs);
  432. end;
  433. constructor tai_const_symbol.Createname_offset(const name:string;ofs:longint);
  434. begin
  435. inherited Create;
  436. typ:=ait_const_symbol;
  437. sym:=newasmsymbol(name);
  438. offset:=ofs;
  439. { update sym info }
  440. inc(sym.refs);
  441. end;
  442. constructor tai_const_symbol.Createname_rva(const name:string);
  443. begin
  444. inherited Create;
  445. typ:=ait_const_rva;
  446. sym:=newasmsymbol(name);
  447. offset:=0;
  448. { update sym info }
  449. inc(sym.refs);
  450. end;
  451. {****************************************************************************
  452. TAI_real_32bit
  453. ****************************************************************************}
  454. constructor tai_real_32bit.Create(_value : ts32real);
  455. begin
  456. inherited Create;
  457. typ:=ait_real_32bit;
  458. value:=_value;
  459. end;
  460. {****************************************************************************
  461. TAI_real_64bit
  462. ****************************************************************************}
  463. constructor tai_real_64bit.Create(_value : ts64real);
  464. begin
  465. inherited Create;
  466. typ:=ait_real_64bit;
  467. value:=_value;
  468. end;
  469. {****************************************************************************
  470. TAI_real_80bit
  471. ****************************************************************************}
  472. constructor tai_real_80bit.Create(_value : ts80real);
  473. begin
  474. inherited Create;
  475. typ:=ait_real_80bit;
  476. value:=_value;
  477. end;
  478. {****************************************************************************
  479. Tai_comp_64bit
  480. ****************************************************************************}
  481. constructor tai_comp_64bit.Create(_value : ts64comp);
  482. begin
  483. inherited Create;
  484. typ:=ait_comp_64bit;
  485. value:=_value;
  486. end;
  487. {****************************************************************************
  488. TAI_STRING
  489. ****************************************************************************}
  490. constructor tai_string.Create(const _str : string);
  491. begin
  492. inherited Create;
  493. typ:=ait_string;
  494. getmem(str,length(_str)+1);
  495. strpcopy(str,_str);
  496. len:=length(_str);
  497. end;
  498. constructor tai_string.Create_pchar(_str : pchar);
  499. begin
  500. inherited Create;
  501. typ:=ait_string;
  502. str:=_str;
  503. len:=strlen(_str);
  504. end;
  505. constructor tai_string.Create_length_pchar(_str : pchar;length : longint);
  506. begin
  507. inherited Create;
  508. typ:=ait_string;
  509. str:=_str;
  510. len:=length;
  511. end;
  512. destructor tai_string.destroy;
  513. begin
  514. { you can have #0 inside the strings so }
  515. if str<>nil then
  516. freemem(str,len+1);
  517. inherited Destroy;
  518. end;
  519. {****************************************************************************
  520. TAI_LABEL
  521. ****************************************************************************}
  522. constructor tai_label.create(_l : tasmlabel);
  523. begin
  524. inherited Create;
  525. typ:=ait_label;
  526. l:=_l;
  527. l.is_set:=true;
  528. is_global:=(l.defbind=AB_GLOBAL);
  529. end;
  530. {****************************************************************************
  531. TAI_DIRECT
  532. ****************************************************************************}
  533. constructor tai_direct.Create(_str : pchar);
  534. begin
  535. inherited Create;
  536. typ:=ait_direct;
  537. str:=_str;
  538. end;
  539. destructor tai_direct.destroy;
  540. begin
  541. strdispose(str);
  542. inherited Destroy;
  543. end;
  544. {****************************************************************************
  545. TAI_ASM_COMMENT comment to be inserted in the assembler file
  546. ****************************************************************************}
  547. constructor tai_asm_comment.Create(_str : pchar);
  548. begin
  549. inherited Create;
  550. typ:=ait_comment;
  551. str:=_str;
  552. end;
  553. destructor tai_asm_comment.destroy;
  554. begin
  555. strdispose(str);
  556. inherited Destroy;
  557. end;
  558. {****************************************************************************
  559. TAI_CUT
  560. ****************************************************************************}
  561. constructor tai_cut.Create;
  562. begin
  563. inherited Create;
  564. typ:=ait_cut;
  565. place:=cut_normal;
  566. end;
  567. constructor tai_cut.Create_begin;
  568. begin
  569. inherited Create;
  570. typ:=ait_cut;
  571. place:=cut_begin;
  572. end;
  573. constructor tai_cut.Create_end;
  574. begin
  575. inherited Create;
  576. typ:=ait_cut;
  577. place:=cut_end;
  578. end;
  579. {****************************************************************************
  580. Tai_Marker
  581. ****************************************************************************}
  582. Constructor Tai_Marker.Create(_Kind: TMarker);
  583. Begin
  584. Inherited Create;
  585. typ := ait_marker;
  586. Kind := _Kind;
  587. End;
  588. {*****************************************************************************
  589. tai_tempalloc
  590. *****************************************************************************}
  591. constructor tai_tempalloc.alloc(pos,size:longint);
  592. begin
  593. inherited Create;
  594. typ:=ait_tempalloc;
  595. allocation:=true;
  596. temppos:=pos;
  597. tempsize:=size;
  598. end;
  599. constructor tai_tempalloc.dealloc(pos,size:longint);
  600. begin
  601. inherited Create;
  602. typ:=ait_tempalloc;
  603. allocation:=false;
  604. temppos:=pos;
  605. tempsize:=size;
  606. end;
  607. {*****************************************************************************
  608. tai_regalloc
  609. *****************************************************************************}
  610. constructor tai_regalloc.alloc(r : tregister);
  611. begin
  612. inherited create;
  613. typ:=ait_regalloc;
  614. allocation:=true;
  615. reg:=r;
  616. end;
  617. constructor tai_regalloc.dealloc(r : tregister);
  618. begin
  619. inherited create;
  620. typ:=ait_regalloc;
  621. allocation:=false;
  622. reg:=r;
  623. end;
  624. {*****************************************************************************
  625. TaiInstruction
  626. *****************************************************************************}
  627. constructor taicpu_abstract.Create(op : tasmop);
  628. begin
  629. inherited create;
  630. typ:=ait_instruction;
  631. is_jmp:=false;
  632. opcode:=op;
  633. ops:=0;
  634. fillchar(condition,sizeof(condition),0);
  635. fillchar(oper,sizeof(oper),0);
  636. end;
  637. destructor taicpu_abstract.Destroy;
  638. var
  639. i : longint;
  640. begin
  641. for i:=0 to ops-1 do
  642. case oper[i].typ of
  643. top_ref:
  644. dispose(oper[i].ref);
  645. top_symbol:
  646. dec(tasmsymbol(oper[i].sym).refs);
  647. end;
  648. inherited destroy;
  649. end;
  650. { ---------------------------------------------------------------------
  651. Loading of operands.
  652. ---------------------------------------------------------------------}
  653. procedure taicpu_abstract.loadconst(opidx:longint;l:aword);
  654. begin
  655. if opidx>=ops then
  656. ops:=opidx+1;
  657. with oper[opidx] do
  658. begin
  659. if typ=top_ref then
  660. dispose(ref);
  661. val:=l;
  662. typ:=top_const;
  663. end;
  664. end;
  665. procedure taicpu_abstract.loadsymbol(opidx:longint;s:tasmsymbol;sofs:longint);
  666. begin
  667. if not assigned(s) then
  668. internalerror(200204251);
  669. if opidx>=ops then
  670. ops:=opidx+1;
  671. with oper[opidx] do
  672. begin
  673. if typ=top_ref then
  674. dispose(ref);
  675. sym:=s;
  676. symofs:=sofs;
  677. typ:=top_symbol;
  678. end;
  679. inc(s.refs);
  680. end;
  681. procedure taicpu_abstract.loadref(opidx:longint;const r:treference);
  682. begin
  683. if opidx>=ops then
  684. ops:=opidx+1;
  685. with oper[opidx] do
  686. begin
  687. if typ<>top_ref then
  688. new(ref);
  689. ref^:=r;
  690. {$ifdef i386}
  691. { We allow this exception for i386, since overloading this would be
  692. too much of a a speed penalty}
  693. if not(ref^.segment in [R_DS,R_NO]) then
  694. segprefix:=ref^.segment;
  695. {$endif}
  696. typ:=top_ref;
  697. { mark symbol as used }
  698. if assigned(ref^.symbol) then
  699. inc(ref^.symbol.refs);
  700. end;
  701. end;
  702. procedure taicpu_abstract.loadreg(opidx:longint;r:tregister);
  703. begin
  704. if opidx>=ops then
  705. ops:=opidx+1;
  706. with oper[opidx] do
  707. begin
  708. if typ=top_ref then
  709. dispose(ref);
  710. reg:=r;
  711. typ:=top_reg;
  712. end;
  713. end;
  714. procedure taicpu_abstract.loadoper(opidx:longint;o:toper);
  715. begin
  716. if opidx>=ops then
  717. ops:=opidx+1;
  718. if oper[opidx].typ=top_ref then
  719. dispose(oper[opidx].ref);
  720. oper[opidx]:=o;
  721. { copy also the reference }
  722. if oper[opidx].typ=top_ref then
  723. begin
  724. new(oper[opidx].ref);
  725. oper[opidx].ref^:=o.ref^;
  726. end;
  727. end;
  728. { ---------------------------------------------------------------------
  729. Miscellaneous methods.
  730. ---------------------------------------------------------------------}
  731. procedure taicpu_abstract.SetCondition(const c:TAsmCond);
  732. begin
  733. condition:=c;
  734. end;
  735. Function taicpu_abstract.getcopy:TLinkedListItem;
  736. var
  737. i : longint;
  738. p : TLinkedListItem;
  739. begin
  740. p:=inherited getcopy;
  741. { make a copy of the references }
  742. for i:=1 to ops do
  743. if (taicpu_abstract(p).oper[i-1].typ=top_ref) then
  744. begin
  745. new(taicpu_abstract(p).oper[i-1].ref);
  746. taicpu_abstract(p).oper[i-1].ref^:=oper[i-1].ref^;
  747. end;
  748. getcopy:=p;
  749. end;
  750. {****************************************************************************
  751. tai_align_abstract
  752. ****************************************************************************}
  753. constructor tai_align_abstract.Create(b: byte);
  754. begin
  755. inherited Create;
  756. typ:=ait_align;
  757. if b in [1,2,4,8,16,32] then
  758. aligntype := b
  759. else
  760. aligntype := 1;
  761. fillsize:=0;
  762. fillop:=0;
  763. use_op:=false;
  764. end;
  765. constructor tai_align_abstract.Create_op(b: byte; _op: byte);
  766. begin
  767. inherited Create;
  768. typ:=ait_align;
  769. if b in [1,2,4,8,16,32] then
  770. aligntype := b
  771. else
  772. aligntype := 1;
  773. fillsize:=0;
  774. fillop:=_op;
  775. use_op:=true;
  776. fillchar(buf,sizeof(buf),_op)
  777. end;
  778. function tai_align_abstract.getfillbuf:pchar;
  779. begin
  780. getfillbuf:=@buf;
  781. end;
  782. {*****************************************************************************
  783. TAAsmOutput
  784. *****************************************************************************}
  785. function taasmoutput.getlasttaifilepos : pfileposinfo;
  786. begin
  787. if assigned(last) then
  788. getlasttaifilepos:=@tai(last).fileinfo
  789. else
  790. getlasttaifilepos:=nil;
  791. end;
  792. end.
  793. {
  794. $Log$
  795. Revision 1.1 2002-07-01 18:46:20 peter
  796. * internal linker
  797. * reorganized aasm layer
  798. Revision 1.27 2002/05/18 13:34:04 peter
  799. * readded missing revisions
  800. Revision 1.25 2002/05/14 19:34:38 peter
  801. * removed old logs and updated copyright year
  802. Revision 1.24 2002/05/14 17:28:08 peter
  803. * synchronized cpubase between powerpc and i386
  804. * moved more tables from cpubase to cpuasm
  805. * tai_align_abstract moved to tainst, cpuasm must define
  806. the tai_align class now, which may be empty
  807. Revision 1.23 2002/04/15 18:54:34 carl
  808. - removed tcpuflags
  809. Revision 1.22 2002/04/07 13:18:19 carl
  810. + more documentation
  811. Revision 1.21 2002/04/07 10:17:40 carl
  812. - remove packenumfixed (requires version 1.0.2 or later to compile now!)
  813. + changing some comments so its commented automatically
  814. Revision 1.20 2002/03/24 19:04:31 carl
  815. + patch for SPARC from Mazen NEIFER
  816. }