aasm.pas 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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. cobjects,files,globals;
  22. type
  23. {$ifdef i386}
  24. bestreal = extended;
  25. {$endif}
  26. {$ifdef m68k}
  27. bestreal = real;
  28. {$endif}
  29. pbestreal=^bestreal;
  30. tait = (
  31. ait_string,
  32. ait_label,
  33. ait_direct,
  34. ait_labeled_instruction,
  35. ait_comment,
  36. ait_instruction,
  37. ait_datablock,
  38. ait_symbol,
  39. ait_const_32bit,
  40. ait_const_16bit,
  41. ait_const_8bit,
  42. ait_const_symbol,
  43. ait_const_symbol_offset,
  44. ait_real_64bit,
  45. ait_real_32bit,
  46. ait_real_extended,
  47. ait_comp,
  48. ait_external,
  49. ait_align,
  50. ait_section,
  51. { the following is only used by the win32 version of the compiler }
  52. { and only the GNU AS Win32 is able to write it }
  53. ait_const_rva,
  54. ait_stabn,
  55. ait_stabs,
  56. ait_force_line,
  57. ait_stab_function_name,
  58. ait_cut, { used to split into tiny assembler files }
  59. ait_regalloc,
  60. ait_regdealloc,
  61. ait_marker,
  62. { never used, makes insertation of new ait_ easier to type }
  63. ait_dummy);
  64. type
  65. { the short name makes typing easier }
  66. pai = ^tai;
  67. tai = object(tlinkedlist_item)
  68. typ : tait;
  69. fileinfo : tfileposinfo;
  70. constructor init;
  71. end;
  72. pai_string = ^tai_string;
  73. tai_string = object(tai)
  74. str : pchar;
  75. { extra len so the string can contain an \0 }
  76. len : longint;
  77. constructor init(const _str : string);
  78. constructor init_pchar(_str : pchar);
  79. constructor init_length_pchar(_str : pchar;length : longint);
  80. destructor done;virtual;
  81. end;
  82. { generates a common label }
  83. pai_symbol = ^tai_symbol;
  84. tai_symbol = object(tai)
  85. name : pchar;
  86. is_global : boolean;
  87. constructor init(const _name : string);
  88. constructor init_global(const _name : string);
  89. destructor done;virtual;
  90. end;
  91. { external types defined for TASM }
  92. { EXT_ANY for search purposes }
  93. texternal_typ = (EXT_ANY,EXT_NEAR, EXT_FAR, EXT_PROC, EXT_BYTE,
  94. EXT_WORD, EXT_DWORD, EXT_CODEPTR, EXT_DATAPTR,
  95. EXT_FWORD, EXT_PWORD, EXT_QWORD, EXT_TBYTE, EXT_ABS);
  96. { generates an symbol which is marked as external }
  97. pai_external = ^tai_external;
  98. tai_external = object(tai)
  99. name : pchar;
  100. exttyp : texternal_typ;
  101. constructor init(const _name : string;exttype : texternal_typ);
  102. destructor done; virtual;
  103. end;
  104. { type for a temporary label test if used for dispose of
  105. unnecessary labels }
  106. plabel = ^tlabel;
  107. tlabel = record
  108. nb : longint;
  109. is_data : boolean;
  110. is_used : boolean;
  111. is_set : boolean;
  112. refcount : word;
  113. end;
  114. pai_label = ^tai_label;
  115. tai_label = object(tai)
  116. l : plabel;
  117. constructor init(_l : plabel);
  118. destructor done; virtual;
  119. end;
  120. pai_direct = ^tai_direct;
  121. tai_direct = object(tai)
  122. str : pchar;
  123. constructor init(_str : pchar);
  124. destructor done; virtual;
  125. end;
  126. { to insert a comment into the generated assembler file }
  127. pai_asm_comment = ^tai_asm_comment;
  128. tai_asm_comment = object(tai)
  129. str : pchar;
  130. constructor init(_str : pchar);
  131. destructor done; virtual;
  132. end;
  133. { alignment for operator }
  134. pai_align = ^tai_align;
  135. tai_align = object(tai)
  136. aligntype: byte; { 1 = no align, 2 = word align, 4 = dword align }
  137. op: byte; { value to fill with - optional }
  138. use_op : boolean;
  139. constructor init(b:byte);
  140. constructor init_op(b: byte; _op: byte);
  141. destructor done;virtual;
  142. end;
  143. tsection=(sec_none,sec_code,sec_data,sec_bss,sec_idata,sec_edata);
  144. { Insert a section/segment directive }
  145. pai_section = ^tai_section;
  146. tai_section = object(tai)
  147. sec : tsection;
  148. idataidx : longint;
  149. constructor init(s : tsection);
  150. constructor init_idata(i:longint);
  151. destructor done;virtual;
  152. end;
  153. { generates an uninitializised data block }
  154. pai_datablock = ^tai_datablock;
  155. tai_datablock = object(tai)
  156. size : longint;
  157. name : pchar;
  158. is_global : boolean;
  159. constructor init(const _name : string;_size : longint);
  160. constructor init_global(const _name : string;_size : longint);
  161. destructor done; virtual;
  162. end;
  163. { generates a long integer (32 bit) }
  164. pai_const = ^tai_const;
  165. tai_const = object(tai)
  166. value : longint;
  167. constructor init_32bit(_value : longint);
  168. constructor init_16bit(_value : word);
  169. constructor init_8bit(_value : byte);
  170. constructor init_symbol(p : pchar);
  171. constructor init_rva(p : pchar);
  172. destructor done;virtual;
  173. end;
  174. pai_const_symbol_offset = ^tai_const_symbol_offset;
  175. tai_const_symbol_offset= object(tai)
  176. name : pchar;
  177. offset : longint;
  178. constructor init(p : pchar; l : longint);
  179. destructor done;virtual;
  180. end;
  181. { generates a double (64 bit real) }
  182. pai_double = ^tai_double;
  183. tai_double = object(tai)
  184. value : double;
  185. constructor init(_value : double);
  186. end;
  187. { generates an comp (integer over 64 bits) }
  188. pai_comp = ^tai_comp;
  189. tai_comp = object(tai)
  190. value : bestreal;
  191. constructor init(_value : bestreal);
  192. {$ifdef i386}
  193. { usefull for 64 bits apps, maybe later }
  194. { comp is not defined on m68k processors !! }
  195. constructor init_comp(_value : comp);
  196. {$endif i386}
  197. end;
  198. { generates a single (32 bit real) }
  199. pai_single = ^tai_single;
  200. tai_single = object(tai)
  201. value : single;
  202. constructor init(_value : single);
  203. end;
  204. { generates an extended (80 bit real) }
  205. pai_extended = ^tai_extended;
  206. tai_extended = object(tai)
  207. value : bestreal;
  208. constructor init(_value : bestreal);
  209. end;
  210. { insert a cut to split into several smaller files }
  211. pai_cut = ^tai_cut;
  212. tai_cut = object(tai)
  213. endname : boolean;
  214. constructor init;
  215. constructor init_end;
  216. end;
  217. TMarker = (NoPropInfoStart, NoPropInfoEnd, AsmBlockStart, AsmBlockEnd);
  218. pai_marker = ^tai_marker;
  219. tai_marker = object(tai)
  220. Kind: TMarker;
  221. Constructor init(_Kind: TMarker);
  222. end;
  223. { for each processor define the best precision }
  224. { bestreal is defined in globals }
  225. {$ifdef i386}
  226. const
  227. ait_bestreal = ait_real_extended;
  228. type
  229. pai_bestreal = pai_extended;
  230. tai_bestreal = tai_extended;
  231. {$endif i386}
  232. {$ifdef m68k}
  233. const
  234. ait_bestreal = ait_real_32bit;
  235. type
  236. pai_bestreal = pai_single;
  237. tai_bestreal = tai_single;
  238. {$endif m68k}
  239. paasmoutput = ^taasmoutput;
  240. taasmoutput = object(tlinkedlist)
  241. function getlasttaifilepos : pfileposinfo;
  242. end;
  243. var
  244. { temporary lists }
  245. exprasmlist,
  246. { default lists }
  247. datasegment,codesegment,bsssegment,
  248. internals,externals,debuglist,consts,
  249. importssection,exportssection,
  250. resourcesection,rttilist : paasmoutput;
  251. { external symbols without repetition }
  252. function search_assembler_symbol(pl : paasmoutput;const _name : string;exttype : texternal_typ) : pai_external;
  253. procedure concat_external(const _name : string;exttype : texternal_typ);
  254. procedure concat_internal(const _name : string;exttype : texternal_typ);
  255. { label functions }
  256. const
  257. nextlabelnr : longint = 1;
  258. countlabelref : boolean = true;
  259. { convert label to string}
  260. function lab2str(l : plabel) : string;
  261. { make l as a new label }
  262. procedure getlabel(var l : plabel);
  263. { make l as a new label and flag is_data }
  264. procedure getdatalabel(var l : plabel);
  265. { frees the label if unused }
  266. procedure freelabel(var l : plabel);
  267. { make a new zero label }
  268. procedure getzerolabel(var l : plabel);
  269. { reset a label to a zero label }
  270. procedure setzerolabel(var l : plabel);
  271. {just get a label number }
  272. procedure getlabelnr(var l : longint);
  273. implementation
  274. uses
  275. strings,verbose,systems,globtype;
  276. {****************************************************************************
  277. TAI
  278. ****************************************************************************}
  279. constructor tai.init;
  280. begin
  281. fileinfo:=aktfilepos;
  282. end;
  283. {****************************************************************************
  284. TAI_SECTION
  285. ****************************************************************************}
  286. constructor tai_section.init(s : tsection);
  287. begin
  288. inherited init;
  289. typ:=ait_section;
  290. sec:=s;
  291. idataidx:=0;
  292. end;
  293. constructor tai_section.init_idata(i:longint);
  294. begin
  295. inherited init;
  296. typ:=ait_section;
  297. sec:=sec_idata;
  298. idataidx:=i;
  299. end;
  300. destructor tai_section.done;
  301. begin
  302. inherited done;
  303. end;
  304. {****************************************************************************
  305. TAI_DATABLOCK
  306. ****************************************************************************}
  307. constructor tai_datablock.init(const _name : string;_size : longint);
  308. begin
  309. inherited init;
  310. typ:=ait_datablock;
  311. name:=strpnew(_name);
  312. concat_internal(_name,EXT_ANY);
  313. size:=_size;
  314. is_global:=false;
  315. end;
  316. constructor tai_datablock.init_global(const _name : string;_size : longint);
  317. begin
  318. inherited init;
  319. typ:=ait_datablock;
  320. name:=strpnew(_name);
  321. concat_internal(_name,EXT_ANY);
  322. size:=_size;
  323. is_global:=true;
  324. end;
  325. destructor tai_datablock.done;
  326. begin
  327. strdispose(name);
  328. inherited done;
  329. end;
  330. {****************************************************************************
  331. TAI_SYMBOL
  332. ****************************************************************************}
  333. constructor tai_symbol.init(const _name : string);
  334. begin
  335. inherited init;
  336. typ:=ait_symbol;
  337. name:=strpnew(_name);
  338. concat_internal(_name,EXT_ANY);
  339. is_global:=false;
  340. end;
  341. constructor tai_symbol.init_global(const _name : string);
  342. begin
  343. inherited init;
  344. typ:=ait_symbol;
  345. name:=strpnew(_name);
  346. concat_internal(_name,EXT_ANY);
  347. is_global:=true;
  348. end;
  349. destructor tai_symbol.done;
  350. begin
  351. strdispose(name);
  352. inherited done;
  353. end;
  354. {****************************************************************************
  355. TAI_EXTERNAL
  356. ****************************************************************************}
  357. constructor tai_external.init(const _name : string;exttype : texternal_typ);
  358. begin
  359. inherited init;
  360. typ:=ait_external;
  361. exttyp:=exttype;
  362. name:=strpnew(_name);
  363. end;
  364. destructor tai_external.done;
  365. begin
  366. strdispose(name);
  367. inherited done;
  368. end;
  369. {****************************************************************************
  370. TAI_CONST
  371. ****************************************************************************}
  372. constructor tai_const.init_32bit(_value : longint);
  373. begin
  374. inherited init;
  375. typ:=ait_const_32bit;
  376. value:=_value;
  377. end;
  378. constructor tai_const.init_16bit(_value : word);
  379. begin
  380. inherited init;
  381. typ:=ait_const_16bit;
  382. value:=_value;
  383. end;
  384. constructor tai_const.init_8bit(_value : byte);
  385. begin
  386. inherited init;
  387. typ:=ait_const_8bit;
  388. value:=_value;
  389. end;
  390. constructor tai_const.init_symbol(p : pchar);
  391. begin
  392. inherited init;
  393. typ:=ait_const_symbol;
  394. value:=longint(p);
  395. end;
  396. constructor tai_const.init_rva(p : pchar);
  397. begin
  398. inherited init;
  399. typ:=ait_const_rva;
  400. value:=longint(p);
  401. end;
  402. destructor tai_const.done;
  403. begin
  404. if typ=ait_const_symbol then
  405. strdispose(pchar(value));
  406. inherited done;
  407. end;
  408. {****************************************************************************
  409. TAI_CONST_SYMBOL_OFFSET
  410. ****************************************************************************}
  411. constructor tai_const_symbol_offset.init(p : pchar; l : longint);
  412. begin
  413. inherited init;
  414. typ:=ait_const_symbol_offset;
  415. name:=p;
  416. offset:=l;
  417. end;
  418. destructor tai_const_symbol_offset.done;
  419. begin
  420. strdispose(name);
  421. inherited done;
  422. end;
  423. {****************************************************************************
  424. TAI_DOUBLE
  425. ****************************************************************************}
  426. constructor tai_double.init(_value : double);
  427. begin
  428. inherited init;
  429. typ:=ait_real_64bit;
  430. value:=_value;
  431. end;
  432. {****************************************************************************
  433. TAI_SINGLE
  434. ****************************************************************************}
  435. constructor tai_single.init(_value : single);
  436. begin
  437. inherited init;
  438. typ:=ait_real_32bit;
  439. value:=_value;
  440. end;
  441. {****************************************************************************
  442. TAI_EXTENDED
  443. ****************************************************************************}
  444. constructor tai_extended.init(_value : bestreal);
  445. begin
  446. inherited init;
  447. typ:=ait_real_extended;
  448. value:=_value;
  449. end;
  450. {****************************************************************************
  451. TAI_COMP
  452. ****************************************************************************}
  453. constructor tai_comp.init(_value : bestreal);
  454. begin
  455. inherited init;
  456. typ:=ait_comp;
  457. value:=_value;
  458. end;
  459. {$ifdef i386}
  460. constructor tai_comp.init_comp(_value : comp);
  461. begin
  462. inherited init;
  463. typ:=ait_comp;
  464. value:=_value;
  465. end;
  466. {$endif i386}
  467. {****************************************************************************
  468. TAI_STRING
  469. ****************************************************************************}
  470. constructor tai_string.init(const _str : string);
  471. begin
  472. inherited init;
  473. typ:=ait_string;
  474. getmem(str,length(_str)+1);
  475. strpcopy(str,_str);
  476. len:=length(_str);
  477. end;
  478. constructor tai_string.init_pchar(_str : pchar);
  479. begin
  480. inherited init;
  481. typ:=ait_string;
  482. str:=_str;
  483. len:=strlen(_str);
  484. end;
  485. constructor tai_string.init_length_pchar(_str : pchar;length : longint);
  486. begin
  487. inherited init;
  488. typ:=ait_string;
  489. str:=_str;
  490. len:=length;
  491. end;
  492. destructor tai_string.done;
  493. begin
  494. { you can have #0 inside the strings so }
  495. if str<>nil then
  496. freemem(str,len+1);
  497. inherited done;
  498. end;
  499. {****************************************************************************
  500. TAI_LABEL
  501. ****************************************************************************}
  502. constructor tai_label.init(_l : plabel);
  503. begin
  504. inherited init;
  505. typ:=ait_label;
  506. l:=_l;
  507. l^.is_set:=true;
  508. end;
  509. destructor tai_label.done;
  510. begin
  511. if (l^.refcount>0) then
  512. { can now be disposed by a tai_labeled instruction !! }
  513. l^.is_set:=false
  514. else
  515. dispose(l);
  516. inherited done;
  517. end;
  518. {****************************************************************************
  519. TAI_DIRECT
  520. ****************************************************************************}
  521. constructor tai_direct.init(_str : pchar);
  522. begin
  523. inherited init;
  524. typ:=ait_direct;
  525. str:=_str;
  526. end;
  527. destructor tai_direct.done;
  528. begin
  529. strdispose(str);
  530. inherited done;
  531. end;
  532. {****************************************************************************
  533. TAI_ASM_COMMENT comment to be inserted in the assembler file
  534. ****************************************************************************}
  535. constructor tai_asm_comment.init(_str : pchar);
  536. begin
  537. inherited init;
  538. typ:=ait_comment;
  539. str:=_str;
  540. end;
  541. destructor tai_asm_comment.done;
  542. begin
  543. strdispose(str);
  544. inherited done;
  545. end;
  546. {****************************************************************************
  547. TAI_ALIGN
  548. ****************************************************************************}
  549. constructor tai_align.init(b: byte);
  550. begin
  551. inherited init;
  552. typ:=ait_align;
  553. if b in [1,2,4,8,16] then
  554. aligntype := b
  555. else
  556. aligntype := 1;
  557. op:=0;
  558. use_op:=false;
  559. end;
  560. constructor tai_align.init_op(b: byte; _op: byte);
  561. begin
  562. inherited init;
  563. typ:=ait_align;
  564. if b in [1,2,4,8,16] then
  565. aligntype := b
  566. else
  567. aligntype := 1;
  568. op:=_op;
  569. use_op:=true;
  570. end;
  571. destructor tai_align.done;
  572. begin
  573. inherited done;
  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. External Helpers
  601. *****************************************************************************}
  602. function search_assembler_symbol(pl : paasmoutput;const _name : string;exttype : texternal_typ) : pai_external;
  603. var
  604. p : pai;
  605. begin
  606. search_assembler_symbol:=nil;
  607. if pl=nil then
  608. internalerror(2001)
  609. else
  610. begin
  611. p:=pai(pl^.first);
  612. while (p<>nil) and
  613. (p<>pai(pl^.last)) do
  614. { if we get the same name with a different typ }
  615. { there is probably an error }
  616. if (p^.typ=ait_external) and
  617. ((exttype=EXT_ANY) or (pai_external(p)^.exttyp=exttype)) and
  618. (strpas(pai_external(p)^.name)=_name) then
  619. begin
  620. search_assembler_symbol:=pai_external(p);
  621. exit;
  622. end
  623. else
  624. p:=pai(p^.next);
  625. if (p<>nil) and
  626. (p^.typ=ait_external) and
  627. (pai_external(p)^.exttyp=exttype) and
  628. (strpas(pai_external(p)^.name)=_name) then
  629. begin
  630. search_assembler_symbol:=pai_external(p);
  631. exit;
  632. end;
  633. end;
  634. end;
  635. { insert each need external only once }
  636. procedure concat_external(const _name : string;exttype : texternal_typ);
  637. begin
  638. if not target_asm.externals then
  639. exit;
  640. if search_assembler_symbol(externals,_name,exttype)=nil then
  641. externals^.concat(new(pai_external,init(_name,exttype)));
  642. end;
  643. { insert each need internal only once }
  644. procedure concat_internal(const _name : string;exttype : texternal_typ);
  645. begin
  646. if not target_asm.externals then
  647. exit;
  648. if search_assembler_symbol(internals,_name,exttype)=nil then
  649. internals^.concat(new(pai_external,init(_name,exttype)));
  650. end;
  651. {*****************************************************************************
  652. Label Helpers
  653. *****************************************************************************}
  654. function lab2str(l : plabel) : string;
  655. begin
  656. if (l=nil) or (l^.nb=0) then
  657. begin
  658. {$ifdef EXTDEBUG}
  659. lab2str:='ILLEGAL'
  660. {$else EXTDEBUG}
  661. internalerror(2000);
  662. {$endif EXTDEBUG}
  663. end
  664. else
  665. begin
  666. if (l^.is_data) and (cs_smartlink in aktmoduleswitches) then
  667. lab2str:='_$'+current_module^.modulename^+'$_L'+tostr(l^.nb)
  668. else
  669. lab2str:=target_asm.labelprefix+tostr(l^.nb);
  670. end;
  671. { inside the WriteTree we must not count the refs PM }
  672. {$ifndef HEAPTRC}
  673. if countlabelref then
  674. inc(l^.refcount);
  675. {$endif HEAPTRC}
  676. l^.is_used:=true;
  677. end;
  678. procedure getlabel(var l : plabel);
  679. begin
  680. new(l);
  681. l^.nb:=nextlabelnr;
  682. l^.is_used:=false;
  683. l^.is_set:=false;
  684. l^.is_data:=false;
  685. l^.refcount:=0;
  686. inc(nextlabelnr);
  687. end;
  688. procedure getdatalabel(var l : plabel);
  689. begin
  690. new(l);
  691. l^.nb:=nextlabelnr;
  692. l^.is_used:=false;
  693. l^.is_set:=false;
  694. l^.is_data:=true;
  695. l^.refcount:=0;
  696. inc(nextlabelnr);
  697. end;
  698. procedure freelabel(var l : plabel);
  699. begin
  700. if (l<>nil) and (not l^.is_set) and (not l^.is_used) then
  701. dispose(l);
  702. l:=nil;
  703. end;
  704. procedure setzerolabel(var l : plabel);
  705. begin
  706. with l^ do
  707. begin
  708. nb:=0;
  709. is_used:=false;
  710. is_set:=false;
  711. is_data:=false;
  712. refcount:=0;
  713. end;
  714. end;
  715. procedure getzerolabel(var l : plabel);
  716. begin
  717. new(l);
  718. l^.nb:=0;
  719. l^.is_used:=false;
  720. l^.is_set:=false;
  721. l^.is_data:=false;
  722. l^.refcount:=0;
  723. end;
  724. procedure getlabelnr(var l : longint);
  725. begin
  726. l:=nextlabelnr;
  727. inc(nextlabelnr);
  728. end;
  729. function taasmoutput.getlasttaifilepos : pfileposinfo;
  730. begin
  731. if assigned(last) then
  732. getlasttaifilepos:=@pai(last)^.fileinfo
  733. else
  734. getlasttaifilepos:=nil;
  735. end;
  736. end.
  737. {
  738. $Log$
  739. Revision 1.29 1998-12-29 18:48:24 jonas
  740. + optimize pascal code surrounding assembler blocks
  741. Revision 1.28 1998/12/16 00:27:16 peter
  742. * removed some obsolete version checks
  743. Revision 1.27 1998/12/11 00:02:37 peter
  744. + globtype,tokens,version unit splitted from globals
  745. Revision 1.26 1998/12/01 23:36:31 pierre
  746. * zero padded alignment was buggy
  747. Revision 1.25 1998/11/30 09:42:52 pierre
  748. * some range check bugs fixed (still not working !)
  749. + added DLL writing support for win32 (also accepts variables)
  750. + TempAnsi for code that could be used for Temporary ansi strings
  751. handling
  752. Revision 1.24 1998/11/12 11:19:30 pierre
  753. * fix for first line of function break
  754. Revision 1.23 1998/10/14 15:56:37 pierre
  755. * all references to comp suppressed for m68k
  756. Revision 1.22 1998/10/12 12:20:38 pierre
  757. + added tai_const_symbol_offset
  758. for r : pointer = @var.field;
  759. * better message for different arg names on implementation
  760. of function
  761. Revision 1.21 1998/10/08 17:17:07 pierre
  762. * current_module old scanner tagged as invalid if unit is recompiled
  763. + added ppheap for better info on tracegetmem of heaptrc
  764. (adds line column and file index)
  765. * several memory leaks removed ith help of heaptrc !!
  766. Revision 1.20 1998/10/06 17:16:31 pierre
  767. * some memory leaks fixed (thanks to Peter for heaptrc !)
  768. Revision 1.19 1998/10/01 20:19:11 jonas
  769. + ait_marker support
  770. Revision 1.18 1998/09/20 17:11:25 jonas
  771. * released REGALLOC
  772. Revision 1.17 1998/09/07 18:33:31 peter
  773. + smartlinking for win95 imports
  774. Revision 1.16 1998/09/03 17:08:37 pierre
  775. * better lines for stabs
  776. (no scroll back to if before else part
  777. no return to case line at jump outside case)
  778. + source lines also if not in order
  779. Revision 1.15 1998/08/11 15:31:36 peter
  780. * write extended to ppu file
  781. * new version 0.99.7
  782. Revision 1.14 1998/08/10 23:56:03 peter
  783. * fixed extended writing
  784. Revision 1.13 1998/08/10 14:49:33 peter
  785. + localswitches, moduleswitches, globalswitches splitting
  786. Revision 1.12 1998/07/14 14:46:36 peter
  787. * released NEWINPUT
  788. Revision 1.11 1998/07/07 11:19:50 peter
  789. + NEWINPUT for a better inputfile and scanner object
  790. Revision 1.10 1998/06/08 22:59:41 peter
  791. * smartlinking works for win32
  792. * some defines to exclude some compiler parts
  793. Revision 1.9 1998/06/04 23:51:26 peter
  794. * m68k compiles
  795. + .def file creation moved to gendef.pas so it could also be used
  796. for win32
  797. Revision 1.8 1998/05/23 01:20:53 peter
  798. + aktasmmode, aktoptprocessor, aktoutputformat
  799. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  800. + $LIBNAME to set the library name where the unit will be put in
  801. * splitted cgi386 a bit (codeseg to large for bp7)
  802. * nasm, tasm works again. nasm moved to ag386nsm.pas
  803. Revision 1.7 1998/05/07 00:16:59 peter
  804. * smartlinking for sets
  805. + consts labels are now concated/generated in hcodegen
  806. * moved some cpu code to cga and some none cpu depended code from cga
  807. to tree and hcodegen and cleanup of hcodegen
  808. * assembling .. output reduced for smartlinking ;)
  809. Revision 1.6 1998/05/06 18:36:53 peter
  810. * tai_section extended with code,data,bss sections and enumerated type
  811. * ident 'compiled by FPC' moved to pmodules
  812. * small fix for smartlink
  813. Revision 1.5 1998/05/01 07:43:52 florian
  814. + basics for rtti implemented
  815. + switch $m (generate rtti for published sections)
  816. Revision 1.4 1998/04/29 10:33:40 pierre
  817. + added some code for ansistring (not complete nor working yet)
  818. * corrected operator overloading
  819. * corrected nasm output
  820. + started inline procedures
  821. + added starstarn : use ** for exponentiation (^ gave problems)
  822. + started UseTokenInfo cond to get accurate positions
  823. Revision 1.3 1998/04/27 23:10:27 peter
  824. + new scanner
  825. * $makelib -> if smartlink
  826. * small filename fixes pmodule.setfilename
  827. * moved import from files.pas -> import.pas
  828. Revision 1.2 1998/04/09 15:46:37 florian
  829. + register allocation tracing stuff added
  830. }