aasm.pas 35 KB

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