aasm.pas 32 KB

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