aasm.pas 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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_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_NONE,AS_EXTERNAL,AS_LOCAL,AS_GLOBAL);
  77. pasmsymbol = ^tasmsymbol;
  78. tasmsymbol = object(tnamedindexobject)
  79. orgtyp,
  80. typ : TAsmsymtype;
  81. proclocal : boolean;
  82. { this need to be incremented with every symbol loading into the
  83. paasmoutput, thus in loadsym/loadref/const_symbol (PFV) }
  84. refs : longint;
  85. { the next fields are filled in the binary writer }
  86. idx : longint;
  87. section : tsection;
  88. address,
  89. size : longint;
  90. { alternate symbol which can be used for 'renaming' needed for
  91. inlining }
  92. altsymbol : pasmsymbol;
  93. constructor init(const s:string;_typ:TAsmsymtype);
  94. procedure reset;
  95. function is_used:boolean;
  96. procedure settyp(t:tasmsymtype);
  97. procedure setaddress(sec:tsection;offset,len:longint);
  98. procedure GenerateAltSymbol;
  99. end;
  100. pasmlabel = ^tasmlabel;
  101. tasmlabel = object(tasmsymbol)
  102. labelnr : longint;
  103. { this is set by the pai_label.init }
  104. is_set : boolean;
  105. constructor init;
  106. constructor initdata;
  107. function name:string;virtual;
  108. end;
  109. pasmsymbollist = ^tasmsymbollist;
  110. tasmsymbollist = object(tdictionary)
  111. end;
  112. { the short name makes typing easier }
  113. pai = ^tai;
  114. tai = object(tlinkedlist_item)
  115. typ : tait;
  116. { pointer to record with optimizer info about this tai object }
  117. optinfo : pointer;
  118. fileinfo : tfileposinfo;
  119. constructor init;
  120. end;
  121. pai_string = ^tai_string;
  122. tai_string = object(tai)
  123. str : pchar;
  124. { extra len so the string can contain an \0 }
  125. len : longint;
  126. constructor init(const _str : string);
  127. constructor init_pchar(_str : pchar);
  128. constructor init_length_pchar(_str : pchar;length : longint);
  129. destructor done;virtual;
  130. end;
  131. { generates a common label }
  132. pai_symbol = ^tai_symbol;
  133. tai_symbol = object(tai)
  134. sym : pasmsymbol;
  135. is_global : boolean;
  136. size : longint;
  137. constructor init(_sym:PAsmSymbol;siz:longint);
  138. constructor initname(const _name : string;siz:longint);
  139. constructor initname_global(const _name : string;siz:longint);
  140. end;
  141. pai_symbol_end = ^tai_symbol_end;
  142. tai_symbol_end = object(tai)
  143. sym : pasmsymbol;
  144. constructor init(_sym:PAsmSymbol);
  145. constructor initname(const _name : string);
  146. end;
  147. pai_label = ^tai_label;
  148. tai_label = object(tai)
  149. l : pasmlabel;
  150. is_global : boolean;
  151. constructor init(_l : pasmlabel);
  152. end;
  153. pai_direct = ^tai_direct;
  154. tai_direct = object(tai)
  155. str : pchar;
  156. constructor init(_str : pchar);
  157. destructor done; virtual;
  158. end;
  159. { to insert a comment into the generated assembler file }
  160. pai_asm_comment = ^tai_asm_comment;
  161. tai_asm_comment = object(tai)
  162. str : pchar;
  163. constructor init(_str : pchar);
  164. destructor done; virtual;
  165. end;
  166. { alignment for operator }
  167. pai_align_abstract = ^tai_align_abstract;
  168. tai_align_abstract = object(tai)
  169. buf : array[0..63] of char; { buf used for fill }
  170. aligntype : byte; { 1 = no align, 2 = word align, 4 = dword align }
  171. fillsize : byte; { real size to fill }
  172. fillop : byte; { value to fill with - optional }
  173. use_op : boolean;
  174. constructor init(b:byte);
  175. constructor init_op(b: byte; _op: byte);
  176. function getfillbuf:pchar;
  177. end;
  178. { Insert a section/segment directive }
  179. pai_section = ^tai_section;
  180. tai_section = object(tai)
  181. sec : tsection;
  182. constructor init(s : tsection);
  183. end;
  184. { generates an uninitializised data block }
  185. pai_datablock = ^tai_datablock;
  186. tai_datablock = object(tai)
  187. sym : pasmsymbol;
  188. size : longint;
  189. is_global : boolean;
  190. constructor init(const _name : string;_size : longint);
  191. constructor init_global(const _name : string;_size : longint);
  192. end;
  193. { generates a long integer (32 bit) }
  194. pai_const = ^tai_const;
  195. tai_const = object(tai)
  196. value : longint;
  197. constructor init_32bit(_value : longint);
  198. constructor init_16bit(_value : word);
  199. constructor init_8bit(_value : byte);
  200. end;
  201. pai_const_symbol = ^tai_const_symbol;
  202. tai_const_symbol = object(tai)
  203. sym : pasmsymbol;
  204. offset : longint;
  205. constructor init(_sym:PAsmSymbol);
  206. constructor init_offset(_sym:PAsmSymbol;ofs:longint);
  207. constructor init_rva(_sym:PAsmSymbol);
  208. constructor initname(const name:string);
  209. constructor initname_offset(const name:string;ofs:longint);
  210. constructor initname_rva(const name:string);
  211. end;
  212. { generates a single (32 bit real) }
  213. pai_real_32bit = ^tai_real_32bit;
  214. tai_real_32bit = object(tai)
  215. value : ts32real;
  216. constructor init(_value : ts32real);
  217. end;
  218. { generates a double (64 bit real) }
  219. pai_real_64bit = ^tai_real_64bit;
  220. tai_real_64bit = object(tai)
  221. value : ts64real;
  222. constructor init(_value : ts64real);
  223. end;
  224. { generates an extended (80 bit real) }
  225. pai_real_80bit = ^tai_real_80bit;
  226. tai_real_80bit = object(tai)
  227. value : ts80real;
  228. constructor init(_value : ts80real);
  229. end;
  230. { generates an comp (integer over 64 bits) }
  231. pai_comp_64bit = ^tai_comp_64bit;
  232. tai_comp_64bit = object(tai)
  233. value : ts64comp;
  234. constructor init(_value : ts64comp);
  235. end;
  236. { insert a cut to split into several smaller files }
  237. tcutplace=(cut_normal,cut_begin,cut_end);
  238. pai_cut = ^tai_cut;
  239. tai_cut = object(tai)
  240. place : tcutplace;
  241. constructor init;
  242. constructor init_begin;
  243. constructor init_end;
  244. end;
  245. TMarker = (NoPropInfoStart, NoPropInfoEnd, AsmBlockStart, AsmBlockEnd);
  246. pai_marker = ^tai_marker;
  247. tai_marker = object(tai)
  248. Kind: TMarker;
  249. Constructor init(_Kind: TMarker);
  250. end;
  251. paitempalloc = ^taitempalloc;
  252. taitempalloc = object(tai)
  253. allocation : boolean;
  254. temppos,
  255. tempsize : longint;
  256. constructor alloc(pos,size:longint);
  257. constructor dealloc(pos,size:longint);
  258. end;
  259. { for each processor define the best precision }
  260. { bestreal is defined in globals }
  261. {$ifdef i386}
  262. const
  263. ait_bestreal = ait_real_80bit;
  264. type
  265. pai_bestreal = pai_real_80bit;
  266. tai_bestreal = tai_real_80bit;
  267. {$endif i386}
  268. {$ifdef m68k}
  269. const
  270. ait_bestreal = ait_real_32bit;
  271. type
  272. pai_bestreal = pai_real_32bit;
  273. tai_bestreal = tai_real_32bit;
  274. {$endif m68k}
  275. paasmoutput = ^taasmoutput;
  276. taasmoutput = object(tlinkedlist)
  277. function getlasttaifilepos : pfileposinfo;
  278. end;
  279. const
  280. { maximum of aasmoutput lists there will be }
  281. maxoutputlists = 10;
  282. var
  283. { temporary lists }
  284. exprasmlist,
  285. { default lists }
  286. datasegment,codesegment,bsssegment,
  287. debuglist,consts,
  288. importssection,exportssection,
  289. resourcesection,rttilist,
  290. resourcestringlist : paasmoutput;
  291. { asm symbol list }
  292. asmsymbollist : pasmsymbollist;
  293. const
  294. nextaltnr : longint = 1;
  295. nextlabelnr : longint = 1;
  296. countlabelref : boolean = true;
  297. { make l as a new label }
  298. procedure getlabel(var l : pasmlabel);
  299. { make l as a new label and flag is_data }
  300. procedure getdatalabel(var l : pasmlabel);
  301. {just get a label number }
  302. procedure getlabelnr(var l : longint);
  303. function newasmsymbol(const s : string) : pasmsymbol;
  304. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  305. function getasmsymbol(const s : string) : pasmsymbol;
  306. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  307. procedure ResetAsmsymbolList;
  308. procedure ResetAsmSymbolListAltSymbol;
  309. procedure CheckAsmSymbolListUndefined;
  310. implementation
  311. uses
  312. strings,files,verbose;
  313. {****************************************************************************
  314. TAI
  315. ****************************************************************************}
  316. constructor tai.init;
  317. begin
  318. optinfo := nil;
  319. fileinfo:=aktfilepos;
  320. end;
  321. {****************************************************************************
  322. TAI_SECTION
  323. ****************************************************************************}
  324. constructor tai_section.init(s : tsection);
  325. begin
  326. inherited init;
  327. typ:=ait_section;
  328. sec:=s;
  329. end;
  330. {****************************************************************************
  331. TAI_DATABLOCK
  332. ****************************************************************************}
  333. constructor tai_datablock.init(const _name : string;_size : longint);
  334. begin
  335. inherited init;
  336. typ:=ait_datablock;
  337. sym:=newasmsymboltyp(_name,AS_LOCAL);
  338. { keep things aligned }
  339. if _size<=0 then
  340. _size:=4;
  341. size:=_size;
  342. is_global:=false;
  343. end;
  344. constructor tai_datablock.init_global(const _name : string;_size : longint);
  345. begin
  346. inherited init;
  347. typ:=ait_datablock;
  348. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  349. { keep things aligned }
  350. if _size<=0 then
  351. _size:=4;
  352. size:=_size;
  353. is_global:=true;
  354. end;
  355. {****************************************************************************
  356. TAI_SYMBOL
  357. ****************************************************************************}
  358. constructor tai_symbol.init(_sym:PAsmSymbol;siz:longint);
  359. begin
  360. inherited init;
  361. typ:=ait_symbol;
  362. sym:=_sym;
  363. size:=siz;
  364. is_global:=(sym^.typ=AS_GLOBAL);
  365. end;
  366. constructor tai_symbol.initname(const _name : string;siz:longint);
  367. begin
  368. inherited init;
  369. typ:=ait_symbol;
  370. sym:=newasmsymboltyp(_name,AS_LOCAL);
  371. size:=siz;
  372. is_global:=false;
  373. end;
  374. constructor tai_symbol.initname_global(const _name : string;siz:longint);
  375. begin
  376. inherited init;
  377. typ:=ait_symbol;
  378. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  379. size:=siz;
  380. is_global:=true;
  381. end;
  382. {****************************************************************************
  383. TAI_SYMBOL
  384. ****************************************************************************}
  385. constructor tai_symbol_end.init(_sym:PAsmSymbol);
  386. begin
  387. inherited init;
  388. typ:=ait_symbol_end;
  389. sym:=_sym;
  390. end;
  391. constructor tai_symbol_end.initname(const _name : string);
  392. begin
  393. inherited init;
  394. typ:=ait_symbol_end;
  395. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  396. end;
  397. {****************************************************************************
  398. TAI_CONST
  399. ****************************************************************************}
  400. constructor tai_const.init_32bit(_value : longint);
  401. begin
  402. inherited init;
  403. typ:=ait_const_32bit;
  404. value:=_value;
  405. end;
  406. constructor tai_const.init_16bit(_value : word);
  407. begin
  408. inherited init;
  409. typ:=ait_const_16bit;
  410. value:=_value;
  411. end;
  412. constructor tai_const.init_8bit(_value : byte);
  413. begin
  414. inherited init;
  415. typ:=ait_const_8bit;
  416. value:=_value;
  417. end;
  418. {****************************************************************************
  419. TAI_CONST_SYMBOL_OFFSET
  420. ****************************************************************************}
  421. constructor tai_const_symbol.init(_sym:PAsmSymbol);
  422. begin
  423. inherited init;
  424. typ:=ait_const_symbol;
  425. sym:=_sym;
  426. offset:=0;
  427. { update sym info }
  428. inc(sym^.refs);
  429. end;
  430. constructor tai_const_symbol.init_offset(_sym:PAsmSymbol;ofs:longint);
  431. begin
  432. inherited init;
  433. typ:=ait_const_symbol;
  434. sym:=_sym;
  435. offset:=ofs;
  436. { update sym info }
  437. inc(sym^.refs);
  438. end;
  439. constructor tai_const_symbol.init_rva(_sym:PAsmSymbol);
  440. begin
  441. inherited init;
  442. typ:=ait_const_rva;
  443. sym:=_sym;
  444. offset:=0;
  445. { update sym info }
  446. inc(sym^.refs);
  447. end;
  448. constructor tai_const_symbol.initname(const name:string);
  449. begin
  450. inherited init;
  451. typ:=ait_const_symbol;
  452. sym:=newasmsymbol(name);
  453. offset:=0;
  454. { update sym info }
  455. inc(sym^.refs);
  456. end;
  457. constructor tai_const_symbol.initname_offset(const name:string;ofs:longint);
  458. begin
  459. inherited init;
  460. typ:=ait_const_symbol;
  461. sym:=newasmsymbol(name);
  462. offset:=ofs;
  463. { update sym info }
  464. inc(sym^.refs);
  465. end;
  466. constructor tai_const_symbol.initname_rva(const name:string);
  467. begin
  468. inherited init;
  469. typ:=ait_const_rva;
  470. sym:=newasmsymbol(name);
  471. offset:=0;
  472. { update sym info }
  473. inc(sym^.refs);
  474. end;
  475. {****************************************************************************
  476. TAI_real_32bit
  477. ****************************************************************************}
  478. constructor tai_real_32bit.init(_value : ts32real);
  479. begin
  480. inherited init;
  481. typ:=ait_real_32bit;
  482. value:=_value;
  483. end;
  484. {****************************************************************************
  485. TAI_real_64bit
  486. ****************************************************************************}
  487. constructor tai_real_64bit.init(_value : ts64real);
  488. begin
  489. inherited init;
  490. typ:=ait_real_64bit;
  491. value:=_value;
  492. end;
  493. {****************************************************************************
  494. TAI_real_80bit
  495. ****************************************************************************}
  496. constructor tai_real_80bit.init(_value : ts80real);
  497. begin
  498. inherited init;
  499. typ:=ait_real_80bit;
  500. value:=_value;
  501. end;
  502. {****************************************************************************
  503. Tai_comp_64bit
  504. ****************************************************************************}
  505. constructor tai_comp_64bit.init(_value : ts64comp);
  506. begin
  507. inherited init;
  508. typ:=ait_comp_64bit;
  509. value:=_value;
  510. end;
  511. {****************************************************************************
  512. TAI_STRING
  513. ****************************************************************************}
  514. constructor tai_string.init(const _str : string);
  515. begin
  516. inherited init;
  517. typ:=ait_string;
  518. getmem(str,length(_str)+1);
  519. strpcopy(str,_str);
  520. len:=length(_str);
  521. end;
  522. constructor tai_string.init_pchar(_str : pchar);
  523. begin
  524. inherited init;
  525. typ:=ait_string;
  526. str:=_str;
  527. len:=strlen(_str);
  528. end;
  529. constructor tai_string.init_length_pchar(_str : pchar;length : longint);
  530. begin
  531. inherited init;
  532. typ:=ait_string;
  533. str:=_str;
  534. len:=length;
  535. end;
  536. destructor tai_string.done;
  537. begin
  538. { you can have #0 inside the strings so }
  539. if str<>nil then
  540. freemem(str,len+1);
  541. inherited done;
  542. end;
  543. {****************************************************************************
  544. TAI_LABEL
  545. ****************************************************************************}
  546. constructor tai_label.init(_l : pasmlabel);
  547. begin
  548. inherited init;
  549. typ:=ait_label;
  550. l:=_l;
  551. l^.is_set:=true;
  552. is_global:=(l^.typ=AS_GLOBAL);
  553. end;
  554. {****************************************************************************
  555. TAI_DIRECT
  556. ****************************************************************************}
  557. constructor tai_direct.init(_str : pchar);
  558. begin
  559. inherited init;
  560. typ:=ait_direct;
  561. str:=_str;
  562. end;
  563. destructor tai_direct.done;
  564. begin
  565. strdispose(str);
  566. inherited done;
  567. end;
  568. {****************************************************************************
  569. TAI_ASM_COMMENT comment to be inserted in the assembler file
  570. ****************************************************************************}
  571. constructor tai_asm_comment.init(_str : pchar);
  572. begin
  573. inherited init;
  574. typ:=ait_comment;
  575. str:=_str;
  576. end;
  577. destructor tai_asm_comment.done;
  578. begin
  579. strdispose(str);
  580. inherited done;
  581. end;
  582. {****************************************************************************
  583. TAI_ALIGN
  584. ****************************************************************************}
  585. constructor tai_align_abstract.init(b: byte);
  586. begin
  587. inherited init;
  588. typ:=ait_align;
  589. if b in [1,2,4,8,16,32] then
  590. aligntype := b
  591. else
  592. aligntype := 1;
  593. fillsize:=0;
  594. fillop:=0;
  595. use_op:=false;
  596. end;
  597. constructor tai_align_abstract.init_op(b: byte; _op: byte);
  598. begin
  599. inherited init;
  600. typ:=ait_align;
  601. if b in [1,2,4,8,16,32] then
  602. aligntype := b
  603. else
  604. aligntype := 1;
  605. fillsize:=0;
  606. fillop:=_op;
  607. use_op:=true;
  608. fillchar(buf,sizeof(buf),_op)
  609. end;
  610. function tai_align_abstract.getfillbuf:pchar;
  611. begin
  612. getfillbuf:=@buf;
  613. end;
  614. {****************************************************************************
  615. TAI_CUT
  616. ****************************************************************************}
  617. constructor tai_cut.init;
  618. begin
  619. inherited init;
  620. typ:=ait_cut;
  621. place:=cut_normal;
  622. end;
  623. constructor tai_cut.init_begin;
  624. begin
  625. inherited init;
  626. typ:=ait_cut;
  627. place:=cut_begin;
  628. end;
  629. constructor tai_cut.init_end;
  630. begin
  631. inherited init;
  632. typ:=ait_cut;
  633. place:=cut_end;
  634. end;
  635. {****************************************************************************
  636. Tai_Marker
  637. ****************************************************************************}
  638. Constructor Tai_Marker.Init(_Kind: TMarker);
  639. Begin
  640. Inherited Init;
  641. typ := ait_marker;
  642. Kind := _Kind;
  643. End;
  644. {*****************************************************************************
  645. TaiTempAlloc
  646. *****************************************************************************}
  647. constructor taitempalloc.alloc(pos,size:longint);
  648. begin
  649. inherited init;
  650. typ:=ait_tempalloc;
  651. allocation:=true;
  652. temppos:=pos;
  653. tempsize:=size;
  654. end;
  655. constructor taitempalloc.dealloc(pos,size:longint);
  656. begin
  657. inherited init;
  658. typ:=ait_tempalloc;
  659. allocation:=false;
  660. temppos:=pos;
  661. tempsize:=size;
  662. end;
  663. {*****************************************************************************
  664. AsmSymbol
  665. *****************************************************************************}
  666. constructor tasmsymbol.init(const s:string;_typ:TAsmsymtype);
  667. begin;
  668. inherited initname(s);
  669. typ:=_typ;
  670. reset;
  671. end;
  672. procedure tasmsymbol.GenerateAltSymbol;
  673. begin
  674. if not assigned(altsymbol) then
  675. begin
  676. new(altsymbol,init(name+'_'+tostr(nextaltnr),typ));
  677. { also copy the amount of references }
  678. altsymbol^.refs:=refs;
  679. inc(nextaltnr);
  680. end;
  681. end;
  682. procedure tasmsymbol.reset;
  683. begin
  684. { save the original typ if not done yet }
  685. if orgtyp=AS_NONE then
  686. orgtyp:=typ;
  687. { reset section info }
  688. section:=sec_none;
  689. address:=0;
  690. size:=0;
  691. idx:=-1;
  692. typ:=AS_EXTERNAL;
  693. proclocal:=false;
  694. { mainly used to remove unused labels from the codesegment }
  695. refs:=0;
  696. end;
  697. function tasmsymbol.is_used:boolean;
  698. begin
  699. is_used:=(refs>0);
  700. end;
  701. procedure tasmsymbol.settyp(t:tasmsymtype);
  702. begin
  703. typ:=t;
  704. orgtyp:=t;
  705. end;
  706. procedure tasmsymbol.setaddress(sec:tsection;offset,len:longint);
  707. begin
  708. section:=sec;
  709. address:=offset;
  710. size:=len;
  711. { when the typ was reset to External, set it back to the original
  712. type it got when defined }
  713. if (typ=AS_EXTERNAL) and (orgtyp<>AS_NONE) then
  714. typ:=orgtyp;
  715. end;
  716. {*****************************************************************************
  717. AsmLabel
  718. *****************************************************************************}
  719. constructor tasmlabel.init;
  720. begin;
  721. labelnr:=nextlabelnr;
  722. inc(nextlabelnr);
  723. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  724. proclocal:=true;
  725. is_set:=false;
  726. end;
  727. constructor tasmlabel.initdata;
  728. begin;
  729. labelnr:=nextlabelnr;
  730. inc(nextlabelnr);
  731. if (cs_create_smart in aktmoduleswitches) then
  732. inherited init('_$'+current_module^.modulename^+'$_L'+tostr(labelnr),AS_GLOBAL)
  733. else
  734. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  735. is_set:=false;
  736. { write it always }
  737. refs:=1;
  738. end;
  739. function tasmlabel.name:string;
  740. begin
  741. name:=inherited name;
  742. inc(refs);
  743. end;
  744. {*****************************************************************************
  745. AsmSymbolList helpers
  746. *****************************************************************************}
  747. function newasmsymbol(const s : string) : pasmsymbol;
  748. var
  749. hp : pasmsymbol;
  750. begin
  751. hp:=pasmsymbol(asmsymbollist^.search(s));
  752. if assigned(hp) then
  753. begin
  754. newasmsymbol:=hp;
  755. exit;
  756. end;
  757. { Not found, insert it as an External }
  758. hp:=new(pasmsymbol,init(s,AS_EXTERNAL));
  759. asmsymbollist^.insert(hp);
  760. newasmsymbol:=hp;
  761. end;
  762. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  763. var
  764. hp : pasmsymbol;
  765. begin
  766. hp:=pasmsymbol(asmsymbollist^.search(s));
  767. if assigned(hp) then
  768. begin
  769. hp^.settyp(_typ);
  770. newasmsymboltyp:=hp;
  771. exit;
  772. end;
  773. { Not found, insert it as an External }
  774. hp:=new(pasmsymbol,init(s,_typ));
  775. asmsymbollist^.insert(hp);
  776. newasmsymboltyp:=hp;
  777. end;
  778. function getasmsymbol(const s : string) : pasmsymbol;
  779. begin
  780. getasmsymbol:=pasmsymbol(asmsymbollist^.search(s));
  781. end;
  782. { renames an asmsymbol }
  783. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  784. begin
  785. renameasmsymbol:=pasmsymbol(asmsymbollist^.rename(sold,snew));
  786. end;
  787. procedure ResetAsmSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  788. begin
  789. pasmsymbol(p)^.reset;
  790. end;
  791. procedure ResetAsmsymbolList;
  792. begin
  793. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetasmsym);
  794. end;
  795. procedure ResetAltSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  796. begin
  797. pasmsymbol(p)^.altsymbol:=nil;
  798. end;
  799. procedure ResetAsmSymbolListAltSymbol;
  800. begin
  801. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetaltsym);
  802. end;
  803. procedure checkundefinedasmsym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  804. begin
  805. if (pasmsymbol(p)^.refs>0) and
  806. (pasmsymbol(p)^.section=Sec_none) and
  807. (pasmsymbol(p)^.typ<>AS_EXTERNAL) then
  808. Message1(asmw_e_undefined_label,pasmsymbol(p)^.name);
  809. end;
  810. procedure CheckAsmSymbolListUndefined;
  811. begin
  812. asmsymbollist^.foreach({$ifndef TP}@{$endif}checkundefinedasmsym);
  813. end;
  814. {*****************************************************************************
  815. Label Helpers
  816. *****************************************************************************}
  817. procedure getlabel(var l : pasmlabel);
  818. begin
  819. l:=new(pasmlabel,init);
  820. asmsymbollist^.insert(l);
  821. end;
  822. procedure getdatalabel(var l : pasmlabel);
  823. begin
  824. l:=new(pasmlabel,initdata);
  825. asmsymbollist^.insert(l);
  826. end;
  827. procedure RegenerateLabel(var l : pasmlabel);
  828. begin
  829. if l^.proclocal then
  830. getlabel(pasmlabel(l^.altsymbol))
  831. else
  832. getdatalabel(pasmlabel(l^.altsymbol));
  833. end;
  834. procedure getlabelnr(var l : longint);
  835. begin
  836. l:=nextlabelnr;
  837. inc(nextlabelnr);
  838. end;
  839. {*****************************************************************************
  840. TAAsmOutput
  841. *****************************************************************************}
  842. function taasmoutput.getlasttaifilepos : pfileposinfo;
  843. begin
  844. if assigned(last) then
  845. getlasttaifilepos:=@pai(last)^.fileinfo
  846. else
  847. getlasttaifilepos:=nil;
  848. end;
  849. end.
  850. {
  851. $Log$
  852. Revision 1.74 2000-01-23 16:31:38 peter
  853. * fixed uninited asmsymbol.typ var
  854. Revision 1.73 2000/01/19 22:53:57 florian
  855. * empty records/objects would generate static data of size 0 which is optimized away, tai_datablock
  856. checks now the size and sets it to a value > 0
  857. Revision 1.72 2000/01/13 13:07:05 jonas
  858. * released -dalignreg
  859. * some small fixes to -dnewOptimizations helper procedures
  860. Revision 1.71 2000/01/12 10:38:16 peter
  861. * smartlinking fixes for binary writer
  862. * release alignreg code and moved instruction writing align to cpuasm,
  863. but it doesn't use the specified register yet
  864. Revision 1.70 2000/01/07 01:14:18 peter
  865. * updated copyright to 2000
  866. Revision 1.69 1999/12/22 01:01:46 peter
  867. - removed freelabel()
  868. * added undefined label detection in internal assembler, this prevents
  869. a lot of ld crashes and wrong .o files
  870. * .o files aren't written anymore if errors have occured
  871. * inlining of assembler labels is now correct
  872. Revision 1.68 1999/11/06 14:34:16 peter
  873. * truncated log to 20 revs
  874. Revision 1.67 1999/11/05 16:01:45 jonas
  875. + first implementation of choosing least used register for alignment code
  876. (not yet working, between ifdef alignreg)
  877. Revision 1.66 1999/11/02 15:06:56 peter
  878. * import library fixes for win32
  879. * alignment works again
  880. Revision 1.65 1999/10/27 16:11:27 peter
  881. * insns.dat is used to generate all i386*.inc files
  882. Revision 1.64 1999/09/20 16:38:51 peter
  883. * cs_create_smart instead of cs_smartlink
  884. * -CX is create smartlink
  885. * -CD is create dynamic, but does nothing atm.
  886. Revision 1.63 1999/09/16 23:05:51 florian
  887. * m68k compiler is again compilable (only gas writer, no assembler reader)
  888. Revision 1.62 1999/09/15 20:35:37 florian
  889. * small fix to operator overloading when in MMX mode
  890. + the compiler uses now fldz and fld1 if possible
  891. + some fixes to floating point registers
  892. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  893. * .... ???
  894. Revision 1.61 1999/09/08 15:01:29 jonas
  895. * some small changes so the noew optimizer is again compilable
  896. Revision 1.60 1999/08/06 15:30:17 florian
  897. + cpu flags added, mainly for the new cg
  898. Revision 1.59 1999/08/05 15:51:01 michael
  899. * Added ait_frame, ait_ent
  900. Revision 1.58 1999/08/04 00:39:56 michael
  901. + Added ait_frame
  902. Revision 1.57 1999/08/02 21:01:41 michael
  903. * Moved toperand type back =(
  904. Revision 1.56 1999/08/02 20:45:47 michael
  905. * Moved toperand type to aasm
  906. Revision 1.55 1999/08/01 23:55:55 michael
  907. * Moved taitempalloc
  908. Revision 1.54 1999/07/29 20:53:55 peter
  909. * write .size also
  910. Revision 1.53 1999/07/22 09:37:28 florian
  911. + resourcestring implemented
  912. + start of longstring support
  913. Revision 1.52 1999/07/03 00:26:01 peter
  914. * ag386bin doesn't destroy the aasmoutput lists anymore
  915. Revision 1.51 1999/06/02 22:43:57 pierre
  916. * previous wrong log corrected
  917. Revision 1.50 1999/06/02 22:25:24 pierre
  918. * changed $ifdef FPC @ into $ifndef TP
  919. Revision 1.49 1999/06/01 14:45:41 peter
  920. * @procvar is now always needed for FPC
  921. Revision 1.48 1999/05/28 09:11:39 peter
  922. * also count ref when asmlabel^.name is used
  923. }