aasm.pas 34 KB

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