aasm.pas 34 KB

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