aasm.pas 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. {
  2. $Id$
  3. Copyright (c) 1996-98 by Florian Klaempfl
  4. This unit implements an abstract asmoutput class for all processor types
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit aasm;
  19. interface
  20. uses
  21. globtype,systems,cobjects,files,globals;
  22. type
  23. tait = (
  24. ait_none,
  25. ait_direct,
  26. ait_string,
  27. ait_label,
  28. ait_comment,
  29. ait_instruction,
  30. ait_datablock,
  31. ait_symbol,
  32. ait_symbol_end, { needed to calc the size of a symbol }
  33. ait_const_32bit,
  34. ait_const_16bit,
  35. ait_const_8bit,
  36. ait_const_symbol,
  37. ait_real_80bit,
  38. ait_real_64bit,
  39. ait_real_32bit,
  40. ait_comp_64bit,
  41. ait_align,
  42. ait_section,
  43. { the following is only used by the win32 version of the compiler }
  44. { and only the GNU AS Win32 is able to write it }
  45. ait_const_rva,
  46. ait_stabn,
  47. ait_stabs,
  48. ait_force_line,
  49. ait_stab_function_name,
  50. ait_cut, { used to split into tiny assembler files }
  51. ait_regalloc, { for register,temp allocation debugging }
  52. ait_tempalloc,
  53. ait_marker,
  54. { the follow is for the DEC Alpha }
  55. ait_frame,
  56. ait_ent,
  57. {$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,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_smartlink 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.63 1999-09-16 23:05:51 florian
  808. * m68k compiler is again compilable (only gas writer, no assembler reader)
  809. Revision 1.62 1999/09/15 20:35:37 florian
  810. * small fix to operator overloading when in MMX mode
  811. + the compiler uses now fldz and fld1 if possible
  812. + some fixes to floating point registers
  813. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  814. * .... ???
  815. Revision 1.61 1999/09/08 15:01:29 jonas
  816. * some small changes so the noew optimizer is again compilable
  817. Revision 1.60 1999/08/06 15:30:17 florian
  818. + cpu flags added, mainly for the new cg
  819. Revision 1.59 1999/08/05 15:51:01 michael
  820. * Added ait_frame, ait_ent
  821. Revision 1.58 1999/08/04 00:39:56 michael
  822. + Added ait_frame
  823. Revision 1.57 1999/08/02 21:01:41 michael
  824. * Moved toperand type back =(
  825. Revision 1.56 1999/08/02 20:45:47 michael
  826. * Moved toperand type to aasm
  827. Revision 1.55 1999/08/01 23:55:55 michael
  828. * Moved taitempalloc
  829. Revision 1.54 1999/07/29 20:53:55 peter
  830. * write .size also
  831. Revision 1.53 1999/07/22 09:37:28 florian
  832. + resourcestring implemented
  833. + start of longstring support
  834. Revision 1.52 1999/07/03 00:26:01 peter
  835. * ag386bin doesn't destroy the aasmoutput lists anymore
  836. Revision 1.51 1999/06/02 22:43:57 pierre
  837. * previous wrong log corrected
  838. Revision 1.50 1999/06/02 22:25:24 pierre
  839. * changed $ifdef FPC @ into $ifndef TP
  840. Revision 1.49 1999/06/01 14:45:41 peter
  841. * @procvar is now always needed for FPC
  842. Revision 1.48 1999/05/28 09:11:39 peter
  843. * also count ref when asmlabel^.name is used
  844. Revision 1.47 1999/05/27 19:43:55 peter
  845. * removed oldasm
  846. * plabel -> pasmlabel
  847. * -a switches to source writing automaticly
  848. * assembler readers OOPed
  849. * asmsymbol automaticly external
  850. * jumptables and other label fixes for asm readers
  851. Revision 1.46 1999/05/21 13:54:38 peter
  852. * NEWLAB for label as symbol
  853. Revision 1.45 1999/05/20 22:18:51 pierre
  854. * fix from Peter for double bug reported 20/05/1999
  855. Revision 1.44 1999/05/12 00:19:34 peter
  856. * removed R_DEFAULT_SEG
  857. * uniform float names
  858. Revision 1.43 1999/05/08 20:38:02 jonas
  859. * seperate OPTimizer INFO pointer field in tai object
  860. Revision 1.42 1999/05/06 09:05:05 peter
  861. * generic write_float and str_float
  862. * fixed constant float conversions
  863. Revision 1.41 1999/05/02 22:41:46 peter
  864. * moved section names to systems
  865. * fixed nasm,intel writer
  866. Revision 1.40 1999/04/21 09:43:28 peter
  867. * storenumber works
  868. * fixed some typos in double_checksum
  869. + incompatible types type1 and type2 message (with storenumber)
  870. Revision 1.39 1999/04/16 11:49:36 peter
  871. + tempalloc
  872. + -at to show temp alloc info in .s file
  873. Revision 1.38 1999/04/14 09:14:44 peter
  874. * first things to store the symbol/def number in the ppu
  875. Revision 1.37 1999/03/10 13:25:42 pierre
  876. section order changed to get closer output from coff writer
  877. Revision 1.36 1999/03/08 14:51:04 peter
  878. + smartlinking for ag386bin
  879. Revision 1.35 1999/03/05 13:09:48 peter
  880. * first things for tai_cut support for ag386bin
  881. Revision 1.34 1999/03/03 11:59:27 pierre
  882. + getasmsymbol to search for existing assembler symbol only
  883. Revision 1.33 1999/03/02 02:56:08 peter
  884. + stabs support for binary writers
  885. * more fixes and missing updates from the previous commit :(
  886. Revision 1.32 1999/03/01 13:31:59 pierre
  887. * external used before implemented problem fixed
  888. Revision 1.31 1999/02/25 21:02:16 peter
  889. * ag386bin updates
  890. + coff writer
  891. Revision 1.30 1999/02/17 10:16:24 peter
  892. * small fixes for the binary writer
  893. Revision 1.29 1998/12/29 18:48:24 jonas
  894. + optimize pascal code surrounding assembler blocks
  895. Revision 1.28 1998/12/16 00:27:16 peter
  896. * removed some obsolete version checks
  897. Revision 1.27 1998/12/11 00:02:37 peter
  898. + globtype,tokens,version unit splitted from globals
  899. Revision 1.26 1998/12/01 23:36:31 pierre
  900. * zero padded alignment was buggy
  901. Revision 1.25 1998/11/30 09:42:52 pierre
  902. * some range check bugs fixed (still not working !)
  903. + added DLL writing support for win32 (also accepts variables)
  904. + TempAnsi for code that could be used for Temporary ansi strings
  905. handling
  906. Revision 1.24 1998/11/12 11:19:30 pierre
  907. * fix for first line of function break
  908. Revision 1.23 1998/10/14 15:56:37 pierre
  909. * all references to comp suppressed for m68k
  910. Revision 1.22 1998/10/12 12:20:38 pierre
  911. + added tai_const_symbol_offset
  912. for r : pointer = @var.field;
  913. * better message for different arg names on implementation
  914. of function
  915. Revision 1.21 1998/10/08 17:17:07 pierre
  916. * current_module old scanner tagged as invalid if unit is recompiled
  917. + added ppheap for better info on tracegetmem of heaptrc
  918. (adds line column and file index)
  919. * several memory leaks removed ith help of heaptrc !!
  920. Revision 1.20 1998/10/06 17:16:31 pierre
  921. * some memory leaks fixed (thanks to Peter for heaptrc !)
  922. Revision 1.19 1998/10/01 20:19:11 jonas
  923. + ait_marker support
  924. Revision 1.18 1998/09/20 17:11:25 jonas
  925. * released REGALLOC
  926. Revision 1.17 1998/09/07 18:33:31 peter
  927. + smartlinking for win95 imports
  928. Revision 1.16 1998/09/03 17:08:37 pierre
  929. * better lines for stabs
  930. (no scroll back to if before else part
  931. no return to case line at jump outside case)
  932. + source lines also if not in order
  933. Revision 1.15 1998/08/11 15:31:36 peter
  934. * write extended to ppu file
  935. * new version 0.99.7
  936. Revision 1.14 1998/08/10 23:56:03 peter
  937. * fixed extended writing
  938. Revision 1.13 1998/08/10 14:49:33 peter
  939. + localswitches, moduleswitches, globalswitches splitting
  940. Revision 1.12 1998/07/14 14:46:36 peter
  941. * released NEWINPUT
  942. Revision 1.11 1998/07/07 11:19:50 peter
  943. + NEWINPUT for a better inputfile and scanner object
  944. Revision 1.10 1998/06/08 22:59:41 peter
  945. * smartlinking works for win32
  946. * some defines to exclude some compiler parts
  947. Revision 1.9 1998/06/04 23:51:26 peter
  948. * m68k compiles
  949. + .def file creation moved to gendef.pas so it could also be used
  950. for win32
  951. Revision 1.8 1998/05/23 01:20:53 peter
  952. + aktasmmode, aktoptprocessor, aktoutputformat
  953. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  954. + $LIBNAME to set the library name where the unit will be put in
  955. * splitted cgi386 a bit (codeseg to large for bp7)
  956. * nasm, tasm works again. nasm moved to ag386nsm.pas
  957. Revision 1.7 1998/05/07 00:16:59 peter
  958. * smartlinking for sets
  959. + consts labels are now concated/generated in hcodegen
  960. * moved some cpu code to cga and some none cpu depended code from cga
  961. to tree and hcodegen and cleanup of hcodegen
  962. * assembling .. output reduced for smartlinking ;)
  963. Revision 1.6 1998/05/06 18:36:53 peter
  964. * tai_section extended with code,data,bss sections and enumerated type
  965. * ident 'compiled by FPC' moved to pmodules
  966. * small fix for smartlink
  967. Revision 1.5 1998/05/01 07:43:52 florian
  968. + basics for rtti implemented
  969. + switch $m (generate rtti for published sections)
  970. Revision 1.4 1998/04/29 10:33:40 pierre
  971. + added some code for ansistring (not complete nor working yet)
  972. * corrected operator overloading
  973. * corrected nasm output
  974. + started inline procedures
  975. + added starstarn : use ** for exponentiation (^ gave problems)
  976. + started UseTokenInfo cond to get accurate positions
  977. Revision 1.3 1998/04/27 23:10:27 peter
  978. + new scanner
  979. * $makelib -> if smartlink
  980. * small filename fixes pmodule.setfilename
  981. * moved import from files.pas -> import.pas
  982. Revision 1.2 1998/04/09 15:46:37 florian
  983. + register allocation tracing stuff added
  984. }