aasm.pas 32 KB

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