aasm.pas 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 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. unit aasm;
  19. interface
  20. uses
  21. globtype,systems,cobjects,files,globals;
  22. type
  23. tait = (
  24. ait_none,
  25. ait_direct,
  26. ait_string,
  27. ait_label,
  28. ait_comment,
  29. ait_instruction,
  30. ait_datablock,
  31. ait_symbol,
  32. ait_symbol_end, { needed to calc the size of a symbol }
  33. ait_const_32bit,
  34. ait_const_16bit,
  35. ait_const_8bit,
  36. ait_const_symbol,
  37. ait_real_80bit,
  38. ait_real_64bit,
  39. ait_real_32bit,
  40. ait_comp_64bit,
  41. ait_align,
  42. ait_section,
  43. { the following is only used by the win32 version of the compiler }
  44. { and only the GNU AS Win32 is able to write it }
  45. ait_const_rva,
  46. ait_stabn,
  47. ait_stabs,
  48. ait_force_line,
  49. ait_stab_function_name,
  50. ait_cut, { used to split into tiny assembler files }
  51. ait_regalloc, { for register,temp allocation debugging }
  52. ait_tempalloc,
  53. ait_marker,
  54. ait_frame,
  55. { never used, makes insertation of new ait_ easier to type }
  56. ait_dummy);
  57. { asm symbol functions }
  58. type
  59. TAsmsymtype=(AS_EXTERNAL,AS_LOCAL,AS_GLOBAL);
  60. pasmsymbol = ^tasmsymbol;
  61. tasmsymbol = object(tnamedindexobject)
  62. typ : TAsmsymtype;
  63. { this need te incremented with every symbol loading into the
  64. paasmoutput, thus in loadsym/loadref/const_symbol (PFV) }
  65. refs : longint;
  66. { the next fields are filled in the binary writer }
  67. idx : longint;
  68. section : tsection;
  69. address,
  70. size : longint;
  71. constructor init(const s:string;_typ:TAsmsymtype);
  72. procedure reset;
  73. function is_used:boolean;
  74. procedure setaddress(sec:tsection;offset,len:longint);
  75. end;
  76. pasmlabel = ^tasmlabel;
  77. tasmlabel = object(tasmsymbol)
  78. labelnr : longint;
  79. { this is set by the pai_label.init }
  80. is_set : boolean;
  81. constructor init;
  82. constructor initdata;
  83. function name:string;virtual;
  84. end;
  85. pasmsymbollist = ^tasmsymbollist;
  86. tasmsymbollist = object(tdictionary)
  87. end;
  88. { the short name makes typing easier }
  89. pai = ^tai;
  90. tai = object(tlinkedlist_item)
  91. typ : tait;
  92. { pointer to record with optimizer info about this tai object }
  93. optinfo : pointer;
  94. fileinfo : tfileposinfo;
  95. constructor init;
  96. end;
  97. pai_string = ^tai_string;
  98. tai_string = object(tai)
  99. str : pchar;
  100. { extra len so the string can contain an \0 }
  101. len : longint;
  102. constructor init(const _str : string);
  103. constructor init_pchar(_str : pchar);
  104. constructor init_length_pchar(_str : pchar;length : longint);
  105. destructor done;virtual;
  106. end;
  107. { generates a common label }
  108. pai_symbol = ^tai_symbol;
  109. tai_symbol = object(tai)
  110. sym : pasmsymbol;
  111. is_global : boolean;
  112. size : longint;
  113. constructor init(_sym:PAsmSymbol;siz:longint);
  114. constructor initname(const _name : string;siz:longint);
  115. constructor initname_global(const _name : string;siz:longint);
  116. end;
  117. pai_symbol_end = ^tai_symbol_end;
  118. tai_symbol_end = object(tai)
  119. sym : pasmsymbol;
  120. constructor init(_sym:PAsmSymbol);
  121. constructor initname(const _name : string);
  122. end;
  123. pai_label = ^tai_label;
  124. tai_label = object(tai)
  125. l : pasmlabel;
  126. is_global : boolean;
  127. constructor init(_l : pasmlabel);
  128. end;
  129. pai_direct = ^tai_direct;
  130. tai_direct = object(tai)
  131. str : pchar;
  132. constructor init(_str : pchar);
  133. destructor done; virtual;
  134. end;
  135. { to insert a comment into the generated assembler file }
  136. pai_asm_comment = ^tai_asm_comment;
  137. tai_asm_comment = object(tai)
  138. str : pchar;
  139. constructor init(_str : pchar);
  140. destructor done; virtual;
  141. end;
  142. { alignment for operator }
  143. pai_align = ^tai_align;
  144. tai_align = object(tai)
  145. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  146. fillsize : byte; { real size to fill }
  147. fillop : byte; { value to fill with - optional }
  148. use_op : boolean;
  149. constructor init(b:byte);
  150. constructor init_op(b: byte; _op: byte);
  151. end;
  152. { Insert a section/segment directive }
  153. pai_section = ^tai_section;
  154. tai_section = object(tai)
  155. sec : tsection;
  156. constructor init(s : tsection);
  157. end;
  158. { generates an uninitializised data block }
  159. pai_datablock = ^tai_datablock;
  160. tai_datablock = object(tai)
  161. sym : pasmsymbol;
  162. size : longint;
  163. is_global : boolean;
  164. constructor init(const _name : string;_size : longint);
  165. constructor init_global(const _name : string;_size : longint);
  166. end;
  167. { generates a long integer (32 bit) }
  168. pai_const = ^tai_const;
  169. tai_const = object(tai)
  170. value : longint;
  171. constructor init_32bit(_value : longint);
  172. constructor init_16bit(_value : word);
  173. constructor init_8bit(_value : byte);
  174. end;
  175. pai_const_symbol = ^tai_const_symbol;
  176. tai_const_symbol = object(tai)
  177. sym : pasmsymbol;
  178. offset : longint;
  179. constructor init(_sym:PAsmSymbol);
  180. constructor init_offset(_sym:PAsmSymbol;ofs:longint);
  181. constructor init_rva(_sym:PAsmSymbol);
  182. constructor initname(const name:string);
  183. constructor initname_offset(const name:string;ofs:longint);
  184. constructor initname_rva(const name:string);
  185. end;
  186. { generates a single (32 bit real) }
  187. pai_real_32bit = ^tai_real_32bit;
  188. tai_real_32bit = object(tai)
  189. value : ts32real;
  190. constructor init(_value : ts32real);
  191. end;
  192. { generates a double (64 bit real) }
  193. pai_real_64bit = ^tai_real_64bit;
  194. tai_real_64bit = object(tai)
  195. value : ts64real;
  196. constructor init(_value : ts64real);
  197. end;
  198. { generates an extended (80 bit real) }
  199. pai_real_80bit = ^tai_real_80bit;
  200. tai_real_80bit = object(tai)
  201. value : ts80real;
  202. constructor init(_value : ts80real);
  203. end;
  204. { generates an comp (integer over 64 bits) }
  205. pai_comp_64bit = ^tai_comp_64bit;
  206. tai_comp_64bit = object(tai)
  207. value : ts64comp;
  208. constructor init(_value : ts64comp);
  209. end;
  210. { insert a cut to split into several smaller files }
  211. pai_cut = ^tai_cut;
  212. tai_cut = object(tai)
  213. endname : boolean;
  214. constructor init;
  215. constructor init_end;
  216. end;
  217. TMarker = (NoPropInfoStart, NoPropInfoEnd, AsmBlockStart, AsmBlockEnd);
  218. pai_marker = ^tai_marker;
  219. tai_marker = object(tai)
  220. Kind: TMarker;
  221. Constructor init(_Kind: TMarker);
  222. end;
  223. paitempalloc = ^taitempalloc;
  224. taitempalloc = object(tai)
  225. allocation : boolean;
  226. temppos,
  227. tempsize : longint;
  228. constructor alloc(pos,size:longint);
  229. constructor dealloc(pos,size:longint);
  230. end;
  231. { for each processor define the best precision }
  232. { bestreal is defined in globals }
  233. {$ifdef i386}
  234. const
  235. ait_bestreal = ait_real_80bit;
  236. type
  237. pai_bestreal = pai_real_80bit;
  238. tai_bestreal = tai_real_80bit;
  239. {$endif i386}
  240. {$ifdef m68k}
  241. const
  242. ait_bestreal = ait_real_32bit;
  243. type
  244. pai_bestreal = pai_real_32bit;
  245. tai_bestreal = tai_real_32bit;
  246. {$endif m68k}
  247. paasmoutput = ^taasmoutput;
  248. taasmoutput = object(tlinkedlist)
  249. function getlasttaifilepos : pfileposinfo;
  250. end;
  251. const
  252. { maximum of aasmoutput lists there will be }
  253. maxoutputlists = 10;
  254. var
  255. { temporary lists }
  256. exprasmlist,
  257. { default lists }
  258. datasegment,codesegment,bsssegment,
  259. debuglist,consts,
  260. importssection,exportssection,
  261. resourcesection,rttilist,
  262. resourcestringlist : paasmoutput;
  263. { asm symbol list }
  264. asmsymbollist : pasmsymbollist;
  265. const
  266. nextlabelnr : longint = 1;
  267. countlabelref : boolean = true;
  268. { make l as a new label }
  269. procedure getlabel(var l : pasmlabel);
  270. { make l as a new label and flag is_data }
  271. procedure getdatalabel(var l : pasmlabel);
  272. { free a label }
  273. procedure freelabel(var l : pasmlabel);
  274. {just get a label number }
  275. procedure getlabelnr(var l : longint);
  276. function newasmsymbol(const s : string) : pasmsymbol;
  277. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  278. function getasmsymbol(const s : string) : pasmsymbol;
  279. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  280. procedure ResetAsmsymbolList;
  281. implementation
  282. uses
  283. strings,verbose;
  284. {****************************************************************************
  285. TAI
  286. ****************************************************************************}
  287. constructor tai.init;
  288. begin
  289. optinfo := nil;
  290. fileinfo:=aktfilepos;
  291. end;
  292. {****************************************************************************
  293. TAI_SECTION
  294. ****************************************************************************}
  295. constructor tai_section.init(s : tsection);
  296. begin
  297. inherited init;
  298. typ:=ait_section;
  299. sec:=s;
  300. end;
  301. {****************************************************************************
  302. TAI_DATABLOCK
  303. ****************************************************************************}
  304. constructor tai_datablock.init(const _name : string;_size : longint);
  305. begin
  306. inherited init;
  307. typ:=ait_datablock;
  308. sym:=newasmsymboltyp(_name,AS_LOCAL);
  309. size:=_size;
  310. is_global:=false;
  311. end;
  312. constructor tai_datablock.init_global(const _name : string;_size : longint);
  313. begin
  314. inherited init;
  315. typ:=ait_datablock;
  316. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  317. size:=_size;
  318. is_global:=true;
  319. end;
  320. {****************************************************************************
  321. TAI_SYMBOL
  322. ****************************************************************************}
  323. constructor tai_symbol.init(_sym:PAsmSymbol;siz:longint);
  324. begin
  325. inherited init;
  326. typ:=ait_symbol;
  327. sym:=_sym;
  328. size:=siz;
  329. is_global:=(sym^.typ=AS_GLOBAL);
  330. end;
  331. constructor tai_symbol.initname(const _name : string;siz:longint);
  332. begin
  333. inherited init;
  334. typ:=ait_symbol;
  335. sym:=newasmsymboltyp(_name,AS_LOCAL);
  336. size:=siz;
  337. is_global:=false;
  338. end;
  339. constructor tai_symbol.initname_global(const _name : string;siz:longint);
  340. begin
  341. inherited init;
  342. typ:=ait_symbol;
  343. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  344. size:=siz;
  345. is_global:=true;
  346. end;
  347. {****************************************************************************
  348. TAI_SYMBOL
  349. ****************************************************************************}
  350. constructor tai_symbol_end.init(_sym:PAsmSymbol);
  351. begin
  352. inherited init;
  353. typ:=ait_symbol_end;
  354. sym:=_sym;
  355. end;
  356. constructor tai_symbol_end.initname(const _name : string);
  357. begin
  358. inherited init;
  359. typ:=ait_symbol_end;
  360. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  361. end;
  362. {****************************************************************************
  363. TAI_CONST
  364. ****************************************************************************}
  365. constructor tai_const.init_32bit(_value : longint);
  366. begin
  367. inherited init;
  368. typ:=ait_const_32bit;
  369. value:=_value;
  370. end;
  371. constructor tai_const.init_16bit(_value : word);
  372. begin
  373. inherited init;
  374. typ:=ait_const_16bit;
  375. value:=_value;
  376. end;
  377. constructor tai_const.init_8bit(_value : byte);
  378. begin
  379. inherited init;
  380. typ:=ait_const_8bit;
  381. value:=_value;
  382. end;
  383. {****************************************************************************
  384. TAI_CONST_SYMBOL_OFFSET
  385. ****************************************************************************}
  386. constructor tai_const_symbol.init(_sym:PAsmSymbol);
  387. begin
  388. inherited init;
  389. typ:=ait_const_symbol;
  390. sym:=_sym;
  391. offset:=0;
  392. { update sym info }
  393. inc(sym^.refs);
  394. end;
  395. constructor tai_const_symbol.init_offset(_sym:PAsmSymbol;ofs:longint);
  396. begin
  397. inherited init;
  398. typ:=ait_const_symbol;
  399. sym:=_sym;
  400. offset:=ofs;
  401. { update sym info }
  402. inc(sym^.refs);
  403. end;
  404. constructor tai_const_symbol.init_rva(_sym:PAsmSymbol);
  405. begin
  406. inherited init;
  407. typ:=ait_const_rva;
  408. sym:=_sym;
  409. offset:=0;
  410. { update sym info }
  411. inc(sym^.refs);
  412. end;
  413. constructor tai_const_symbol.initname(const name:string);
  414. begin
  415. inherited init;
  416. typ:=ait_const_symbol;
  417. sym:=newasmsymbol(name);
  418. offset:=0;
  419. { update sym info }
  420. inc(sym^.refs);
  421. end;
  422. constructor tai_const_symbol.initname_offset(const name:string;ofs:longint);
  423. begin
  424. inherited init;
  425. typ:=ait_const_symbol;
  426. sym:=newasmsymbol(name);
  427. offset:=ofs;
  428. { update sym info }
  429. inc(sym^.refs);
  430. end;
  431. constructor tai_const_symbol.initname_rva(const name:string);
  432. begin
  433. inherited init;
  434. typ:=ait_const_rva;
  435. sym:=newasmsymbol(name);
  436. offset:=0;
  437. { update sym info }
  438. inc(sym^.refs);
  439. end;
  440. {****************************************************************************
  441. TAI_real_32bit
  442. ****************************************************************************}
  443. constructor tai_real_32bit.init(_value : ts32real);
  444. begin
  445. inherited init;
  446. typ:=ait_real_32bit;
  447. value:=_value;
  448. end;
  449. {****************************************************************************
  450. TAI_real_64bit
  451. ****************************************************************************}
  452. constructor tai_real_64bit.init(_value : ts64real);
  453. begin
  454. inherited init;
  455. typ:=ait_real_64bit;
  456. value:=_value;
  457. end;
  458. {****************************************************************************
  459. TAI_real_80bit
  460. ****************************************************************************}
  461. constructor tai_real_80bit.init(_value : ts80real);
  462. begin
  463. inherited init;
  464. typ:=ait_real_80bit;
  465. value:=_value;
  466. end;
  467. {****************************************************************************
  468. Tai_comp_64bit
  469. ****************************************************************************}
  470. constructor tai_comp_64bit.init(_value : ts64comp);
  471. begin
  472. inherited init;
  473. typ:=ait_comp_64bit;
  474. value:=_value;
  475. end;
  476. {****************************************************************************
  477. TAI_STRING
  478. ****************************************************************************}
  479. constructor tai_string.init(const _str : string);
  480. begin
  481. inherited init;
  482. typ:=ait_string;
  483. getmem(str,length(_str)+1);
  484. strpcopy(str,_str);
  485. len:=length(_str);
  486. end;
  487. constructor tai_string.init_pchar(_str : pchar);
  488. begin
  489. inherited init;
  490. typ:=ait_string;
  491. str:=_str;
  492. len:=strlen(_str);
  493. end;
  494. constructor tai_string.init_length_pchar(_str : pchar;length : longint);
  495. begin
  496. inherited init;
  497. typ:=ait_string;
  498. str:=_str;
  499. len:=length;
  500. end;
  501. destructor tai_string.done;
  502. begin
  503. { you can have #0 inside the strings so }
  504. if str<>nil then
  505. freemem(str,len+1);
  506. inherited done;
  507. end;
  508. {****************************************************************************
  509. TAI_LABEL
  510. ****************************************************************************}
  511. constructor tai_label.init(_l : pasmlabel);
  512. begin
  513. inherited init;
  514. typ:=ait_label;
  515. l:=_l;
  516. l^.is_set:=true;
  517. is_global:=(l^.typ=AS_GLOBAL);
  518. end;
  519. {****************************************************************************
  520. TAI_DIRECT
  521. ****************************************************************************}
  522. constructor tai_direct.init(_str : pchar);
  523. begin
  524. inherited init;
  525. typ:=ait_direct;
  526. str:=_str;
  527. end;
  528. destructor tai_direct.done;
  529. begin
  530. strdispose(str);
  531. inherited done;
  532. end;
  533. {****************************************************************************
  534. TAI_ASM_COMMENT comment to be inserted in the assembler file
  535. ****************************************************************************}
  536. constructor tai_asm_comment.init(_str : pchar);
  537. begin
  538. inherited init;
  539. typ:=ait_comment;
  540. str:=_str;
  541. end;
  542. destructor tai_asm_comment.done;
  543. begin
  544. strdispose(str);
  545. inherited done;
  546. end;
  547. {****************************************************************************
  548. TAI_ALIGN
  549. ****************************************************************************}
  550. constructor tai_align.init(b: byte);
  551. begin
  552. inherited init;
  553. typ:=ait_align;
  554. if b in [1,2,4,8,16] then
  555. aligntype := b
  556. else
  557. aligntype := 1;
  558. fillsize:=0;
  559. fillop:=0;
  560. use_op:=false;
  561. end;
  562. constructor tai_align.init_op(b: byte; _op: byte);
  563. begin
  564. inherited init;
  565. typ:=ait_align;
  566. if b in [1,2,4,8,16] then
  567. aligntype := b
  568. else
  569. aligntype := 1;
  570. fillsize:=0;
  571. fillop:=_op;
  572. use_op:=true;
  573. end;
  574. {****************************************************************************
  575. TAI_CUT
  576. ****************************************************************************}
  577. constructor tai_cut.init;
  578. begin
  579. inherited init;
  580. typ:=ait_cut;
  581. endname:=false;
  582. end;
  583. constructor tai_cut.init_end;
  584. begin
  585. inherited init;
  586. typ:=ait_cut;
  587. endname:=true;
  588. end;
  589. {****************************************************************************
  590. Tai_Marker
  591. ****************************************************************************}
  592. Constructor Tai_Marker.Init(_Kind: TMarker);
  593. Begin
  594. Inherited Init;
  595. typ := ait_marker;
  596. Kind := _Kind;
  597. End;
  598. {*****************************************************************************
  599. TaiTempAlloc
  600. *****************************************************************************}
  601. constructor taitempalloc.alloc(pos,size:longint);
  602. begin
  603. inherited init;
  604. typ:=ait_tempalloc;
  605. allocation:=true;
  606. temppos:=pos;
  607. tempsize:=size;
  608. end;
  609. constructor taitempalloc.dealloc(pos,size:longint);
  610. begin
  611. inherited init;
  612. typ:=ait_tempalloc;
  613. allocation:=false;
  614. temppos:=pos;
  615. tempsize:=size;
  616. end;
  617. {*****************************************************************************
  618. AsmSymbol
  619. *****************************************************************************}
  620. constructor tasmsymbol.init(const s:string;_typ:TAsmsymtype);
  621. begin;
  622. inherited initname(s);
  623. reset;
  624. typ:=_typ;
  625. end;
  626. procedure tasmsymbol.reset;
  627. begin
  628. section:=sec_none;
  629. address:=0;
  630. size:=0;
  631. idx:=-1;
  632. typ:=AS_EXTERNAL;
  633. { mainly used to remove unused labels from the codesegment }
  634. refs:=0;
  635. end;
  636. function tasmsymbol.is_used:boolean;
  637. begin
  638. is_used:=(refs>0);
  639. end;
  640. procedure tasmsymbol.setaddress(sec:tsection;offset,len:longint);
  641. begin
  642. section:=sec;
  643. address:=offset;
  644. size:=len;
  645. end;
  646. {*****************************************************************************
  647. AsmLabel
  648. *****************************************************************************}
  649. constructor tasmlabel.init;
  650. begin;
  651. labelnr:=nextlabelnr;
  652. inc(nextlabelnr);
  653. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  654. is_set:=false;
  655. end;
  656. constructor tasmlabel.initdata;
  657. begin;
  658. labelnr:=nextlabelnr;
  659. inc(nextlabelnr);
  660. if (cs_smartlink in aktmoduleswitches) then
  661. inherited init('_$'+current_module^.modulename^+'$_L'+tostr(labelnr),AS_GLOBAL)
  662. else
  663. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  664. is_set:=false;
  665. { write it always }
  666. refs:=1;
  667. end;
  668. function tasmlabel.name:string;
  669. begin
  670. name:=inherited name;
  671. inc(refs);
  672. end;
  673. {*****************************************************************************
  674. AsmSymbolList helpers
  675. *****************************************************************************}
  676. function newasmsymbol(const s : string) : pasmsymbol;
  677. var
  678. hp : pasmsymbol;
  679. begin
  680. hp:=pasmsymbol(asmsymbollist^.search(s));
  681. if assigned(hp) then
  682. begin
  683. newasmsymbol:=hp;
  684. exit;
  685. end;
  686. { Not found, insert it as an External }
  687. hp:=new(pasmsymbol,init(s,AS_EXTERNAL));
  688. asmsymbollist^.insert(hp);
  689. newasmsymbol:=hp;
  690. end;
  691. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  692. var
  693. hp : pasmsymbol;
  694. begin
  695. hp:=pasmsymbol(asmsymbollist^.search(s));
  696. if assigned(hp) then
  697. begin
  698. hp^.typ:=_typ;
  699. newasmsymboltyp:=hp;
  700. exit;
  701. end;
  702. { Not found, insert it as an External }
  703. hp:=new(pasmsymbol,init(s,_typ));
  704. asmsymbollist^.insert(hp);
  705. newasmsymboltyp:=hp;
  706. end;
  707. function getasmsymbol(const s : string) : pasmsymbol;
  708. begin
  709. getasmsymbol:=pasmsymbol(asmsymbollist^.search(s));
  710. end;
  711. { renames an asmsymbol }
  712. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  713. {$ifdef nodictonaryrename}
  714. var
  715. hpold,hpnew : pasmsymbol;
  716. begin
  717. hpnew:=pasmsymbol(asmsymbollist^.search(snew));
  718. if assigned(hpnew) then
  719. internalerror(405405);
  720. hpold:=pasmsymbol(asmsymbollist^.search(sold));
  721. if not assigned(hpold) then
  722. internalerror(405406);
  723. hpnew:=new(pasmsymbol,init(sold));
  724. { replace the old one }
  725. { WARNING this heavily depends on the
  726. feature that tdictionnary.insert does not delete
  727. the tree element that it replaces !! }
  728. asmsymbollist^.replace_existing:=true;
  729. asmsymbollist^.insert(hpnew);
  730. asmsymbollist^.replace_existing:=false;
  731. { restore the tree }
  732. hpnew^.left:=hpold^.left;
  733. hpnew^.right:=hpold^.right;
  734. stringdispose(hpold^._name);
  735. hpold^._name:=stringdup(snew);
  736. hpold^.speedvalue:=getspeedvalue(snew);
  737. { now reinsert it at right location !! }
  738. asmsymbollist^.insert(hpold);
  739. renameasmsymbol:=hpold;
  740. end;
  741. {$else}
  742. begin
  743. renameasmsymbol:=pasmsymbol(asmsymbollist^.rename(sold,snew));
  744. end;
  745. {$endif}
  746. procedure ResetAsmSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  747. begin
  748. pasmsymbol(p)^.reset;
  749. end;
  750. procedure ResetAsmsymbolList;
  751. begin
  752. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetasmsym);
  753. end;
  754. {*****************************************************************************
  755. Label Helpers
  756. *****************************************************************************}
  757. procedure getlabel(var l : pasmlabel);
  758. begin
  759. l:=new(pasmlabel,init);
  760. asmsymbollist^.insert(l);
  761. end;
  762. procedure getdatalabel(var l : pasmlabel);
  763. begin
  764. l:=new(pasmlabel,initdata);
  765. asmsymbollist^.insert(l);
  766. end;
  767. procedure freelabel(var l : pasmlabel);
  768. begin
  769. { nothing to do, the dispose of the asmsymbollist will do it }
  770. l:=nil;
  771. end;
  772. procedure getlabelnr(var l : longint);
  773. begin
  774. l:=nextlabelnr;
  775. inc(nextlabelnr);
  776. end;
  777. {*****************************************************************************
  778. TAAsmOutput
  779. *****************************************************************************}
  780. function taasmoutput.getlasttaifilepos : pfileposinfo;
  781. begin
  782. if assigned(last) then
  783. getlasttaifilepos:=@pai(last)^.fileinfo
  784. else
  785. getlasttaifilepos:=nil;
  786. end;
  787. end.
  788. {
  789. $Log$
  790. Revision 1.58 1999-08-04 00:39:56 michael
  791. + Added ait_frame
  792. Revision 1.57 1999/08/02 21:01:41 michael
  793. * Moved toperand type back =(
  794. Revision 1.56 1999/08/02 20:45:47 michael
  795. * Moved toperand type to aasm
  796. Revision 1.55 1999/08/01 23:55:55 michael
  797. * Moved taitempalloc
  798. Revision 1.54 1999/07/29 20:53:55 peter
  799. * write .size also
  800. Revision 1.53 1999/07/22 09:37:28 florian
  801. + resourcestring implemented
  802. + start of longstring support
  803. Revision 1.52 1999/07/03 00:26:01 peter
  804. * ag386bin doesn't destroy the aasmoutput lists anymore
  805. Revision 1.51 1999/06/02 22:43:57 pierre
  806. * previous wrong log corrected
  807. Revision 1.50 1999/06/02 22:25:24 pierre
  808. * changed $ifdef FPC @ into $ifndef TP
  809. Revision 1.49 1999/06/01 14:45:41 peter
  810. * @procvar is now always needed for FPC
  811. Revision 1.48 1999/05/28 09:11:39 peter
  812. * also count ref when asmlabel^.name is used
  813. Revision 1.47 1999/05/27 19:43:55 peter
  814. * removed oldasm
  815. * plabel -> pasmlabel
  816. * -a switches to source writing automaticly
  817. * assembler readers OOPed
  818. * asmsymbol automaticly external
  819. * jumptables and other label fixes for asm readers
  820. Revision 1.46 1999/05/21 13:54:38 peter
  821. * NEWLAB for label as symbol
  822. Revision 1.45 1999/05/20 22:18:51 pierre
  823. * fix from Peter for double bug reported 20/05/1999
  824. Revision 1.44 1999/05/12 00:19:34 peter
  825. * removed R_DEFAULT_SEG
  826. * uniform float names
  827. Revision 1.43 1999/05/08 20:38:02 jonas
  828. * seperate OPTimizer INFO pointer field in tai object
  829. Revision 1.42 1999/05/06 09:05:05 peter
  830. * generic write_float and str_float
  831. * fixed constant float conversions
  832. Revision 1.41 1999/05/02 22:41:46 peter
  833. * moved section names to systems
  834. * fixed nasm,intel writer
  835. Revision 1.40 1999/04/21 09:43:28 peter
  836. * storenumber works
  837. * fixed some typos in double_checksum
  838. + incompatible types type1 and type2 message (with storenumber)
  839. Revision 1.39 1999/04/16 11:49:36 peter
  840. + tempalloc
  841. + -at to show temp alloc info in .s file
  842. Revision 1.38 1999/04/14 09:14:44 peter
  843. * first things to store the symbol/def number in the ppu
  844. Revision 1.37 1999/03/10 13:25:42 pierre
  845. section order changed to get closer output from coff writer
  846. Revision 1.36 1999/03/08 14:51:04 peter
  847. + smartlinking for ag386bin
  848. Revision 1.35 1999/03/05 13:09:48 peter
  849. * first things for tai_cut support for ag386bin
  850. Revision 1.34 1999/03/03 11:59:27 pierre
  851. + getasmsymbol to search for existing assembler symbol only
  852. Revision 1.33 1999/03/02 02:56:08 peter
  853. + stabs support for binary writers
  854. * more fixes and missing updates from the previous commit :(
  855. Revision 1.32 1999/03/01 13:31:59 pierre
  856. * external used before implemented problem fixed
  857. Revision 1.31 1999/02/25 21:02:16 peter
  858. * ag386bin updates
  859. + coff writer
  860. Revision 1.30 1999/02/17 10:16:24 peter
  861. * small fixes for the binary writer
  862. Revision 1.29 1998/12/29 18:48:24 jonas
  863. + optimize pascal code surrounding assembler blocks
  864. Revision 1.28 1998/12/16 00:27:16 peter
  865. * removed some obsolete version checks
  866. Revision 1.27 1998/12/11 00:02:37 peter
  867. + globtype,tokens,version unit splitted from globals
  868. Revision 1.26 1998/12/01 23:36:31 pierre
  869. * zero padded alignment was buggy
  870. Revision 1.25 1998/11/30 09:42:52 pierre
  871. * some range check bugs fixed (still not working !)
  872. + added DLL writing support for win32 (also accepts variables)
  873. + TempAnsi for code that could be used for Temporary ansi strings
  874. handling
  875. Revision 1.24 1998/11/12 11:19:30 pierre
  876. * fix for first line of function break
  877. Revision 1.23 1998/10/14 15:56:37 pierre
  878. * all references to comp suppressed for m68k
  879. Revision 1.22 1998/10/12 12:20:38 pierre
  880. + added tai_const_symbol_offset
  881. for r : pointer = @var.field;
  882. * better message for different arg names on implementation
  883. of function
  884. Revision 1.21 1998/10/08 17:17:07 pierre
  885. * current_module old scanner tagged as invalid if unit is recompiled
  886. + added ppheap for better info on tracegetmem of heaptrc
  887. (adds line column and file index)
  888. * several memory leaks removed ith help of heaptrc !!
  889. Revision 1.20 1998/10/06 17:16:31 pierre
  890. * some memory leaks fixed (thanks to Peter for heaptrc !)
  891. Revision 1.19 1998/10/01 20:19:11 jonas
  892. + ait_marker support
  893. Revision 1.18 1998/09/20 17:11:25 jonas
  894. * released REGALLOC
  895. Revision 1.17 1998/09/07 18:33:31 peter
  896. + smartlinking for win95 imports
  897. Revision 1.16 1998/09/03 17:08:37 pierre
  898. * better lines for stabs
  899. (no scroll back to if before else part
  900. no return to case line at jump outside case)
  901. + source lines also if not in order
  902. Revision 1.15 1998/08/11 15:31:36 peter
  903. * write extended to ppu file
  904. * new version 0.99.7
  905. Revision 1.14 1998/08/10 23:56:03 peter
  906. * fixed extended writing
  907. Revision 1.13 1998/08/10 14:49:33 peter
  908. + localswitches, moduleswitches, globalswitches splitting
  909. Revision 1.12 1998/07/14 14:46:36 peter
  910. * released NEWINPUT
  911. Revision 1.11 1998/07/07 11:19:50 peter
  912. + NEWINPUT for a better inputfile and scanner object
  913. Revision 1.10 1998/06/08 22:59:41 peter
  914. * smartlinking works for win32
  915. * some defines to exclude some compiler parts
  916. Revision 1.9 1998/06/04 23:51:26 peter
  917. * m68k compiles
  918. + .def file creation moved to gendef.pas so it could also be used
  919. for win32
  920. Revision 1.8 1998/05/23 01:20:53 peter
  921. + aktasmmode, aktoptprocessor, aktoutputformat
  922. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  923. + $LIBNAME to set the library name where the unit will be put in
  924. * splitted cgi386 a bit (codeseg to large for bp7)
  925. * nasm, tasm works again. nasm moved to ag386nsm.pas
  926. Revision 1.7 1998/05/07 00:16:59 peter
  927. * smartlinking for sets
  928. + consts labels are now concated/generated in hcodegen
  929. * moved some cpu code to cga and some none cpu depended code from cga
  930. to tree and hcodegen and cleanup of hcodegen
  931. * assembling .. output reduced for smartlinking ;)
  932. Revision 1.6 1998/05/06 18:36:53 peter
  933. * tai_section extended with code,data,bss sections and enumerated type
  934. * ident 'compiled by FPC' moved to pmodules
  935. * small fix for smartlink
  936. Revision 1.5 1998/05/01 07:43:52 florian
  937. + basics for rtti implemented
  938. + switch $m (generate rtti for published sections)
  939. Revision 1.4 1998/04/29 10:33:40 pierre
  940. + added some code for ansistring (not complete nor working yet)
  941. * corrected operator overloading
  942. * corrected nasm output
  943. + started inline procedures
  944. + added starstarn : use ** for exponentiation (^ gave problems)
  945. + started UseTokenInfo cond to get accurate positions
  946. Revision 1.3 1998/04/27 23:10:27 peter
  947. + new scanner
  948. * $makelib -> if smartlink
  949. * small filename fixes pmodule.setfilename
  950. * moved import from files.pas -> import.pas
  951. Revision 1.2 1998/04/09 15:46:37 florian
  952. + register allocation tracing stuff added
  953. }