aasm.pas 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  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,
  248. AsmBlockStart, AsmBlockEnd,
  249. InlineStart,InlineEnd);
  250. pai_marker = ^tai_marker;
  251. tai_marker = object(tai)
  252. Kind: TMarker;
  253. Constructor init(_Kind: TMarker);
  254. end;
  255. paitempalloc = ^taitempalloc;
  256. taitempalloc = object(tai)
  257. allocation : boolean;
  258. temppos,
  259. tempsize : longint;
  260. constructor alloc(pos,size:longint);
  261. constructor dealloc(pos,size:longint);
  262. end;
  263. { for each processor define the best precision }
  264. { bestreal is defined in globals }
  265. {$ifdef i386}
  266. const
  267. ait_bestreal = ait_real_80bit;
  268. type
  269. pai_bestreal = pai_real_80bit;
  270. tai_bestreal = tai_real_80bit;
  271. {$endif i386}
  272. {$ifdef m68k}
  273. const
  274. ait_bestreal = ait_real_32bit;
  275. type
  276. pai_bestreal = pai_real_32bit;
  277. tai_bestreal = tai_real_32bit;
  278. {$endif m68k}
  279. paasmoutput = ^taasmoutput;
  280. taasmoutput = object(tlinkedlist)
  281. function getlasttaifilepos : pfileposinfo;
  282. end;
  283. const
  284. { maximum of aasmoutput lists there will be }
  285. maxoutputlists = 10;
  286. var
  287. { temporary lists }
  288. exprasmlist,
  289. { default lists }
  290. datasegment,codesegment,bsssegment,
  291. debuglist,withdebuglist,consts,
  292. importssection,exportssection,
  293. resourcesection,rttilist,
  294. resourcestringlist : paasmoutput;
  295. { asm symbol list }
  296. asmsymbollist : pasmsymbollist;
  297. const
  298. nextaltnr : longint = 1;
  299. nextlabelnr : longint = 1;
  300. countlabelref : boolean = true;
  301. { make l as a new label }
  302. procedure getlabel(var l : pasmlabel);
  303. { make l as a new label and flag is_data }
  304. procedure getdatalabel(var l : pasmlabel);
  305. {just get a label number }
  306. procedure getlabelnr(var l : longint);
  307. function newasmsymbol(const s : string) : pasmsymbol;
  308. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  309. function getasmsymbol(const s : string) : pasmsymbol;
  310. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  311. procedure ResetAsmsymbolList;
  312. procedure ResetAsmSymbolListAltSymbol;
  313. procedure CheckAsmSymbolListUndefined;
  314. implementation
  315. uses
  316. strings,files,verbose;
  317. {****************************************************************************
  318. TAI
  319. ****************************************************************************}
  320. constructor tai.init;
  321. begin
  322. optinfo := nil;
  323. fileinfo:=aktfilepos;
  324. end;
  325. {****************************************************************************
  326. TAI_SECTION
  327. ****************************************************************************}
  328. constructor tai_section.init(s : tsection);
  329. begin
  330. inherited init;
  331. typ:=ait_section;
  332. sec:=s;
  333. end;
  334. {****************************************************************************
  335. TAI_DATABLOCK
  336. ****************************************************************************}
  337. constructor tai_datablock.init(const _name : string;_size : longint);
  338. begin
  339. inherited init;
  340. typ:=ait_datablock;
  341. sym:=newasmsymboltyp(_name,AS_LOCAL);
  342. { keep things aligned }
  343. if _size<=0 then
  344. _size:=4;
  345. size:=_size;
  346. is_global:=false;
  347. end;
  348. constructor tai_datablock.init_global(const _name : string;_size : longint);
  349. begin
  350. inherited init;
  351. typ:=ait_datablock;
  352. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  353. { keep things aligned }
  354. if _size<=0 then
  355. _size:=4;
  356. size:=_size;
  357. is_global:=true;
  358. end;
  359. {****************************************************************************
  360. TAI_SYMBOL
  361. ****************************************************************************}
  362. constructor tai_symbol.init(_sym:PAsmSymbol;siz:longint);
  363. begin
  364. inherited init;
  365. typ:=ait_symbol;
  366. sym:=_sym;
  367. size:=siz;
  368. is_global:=(sym^.typ=AS_GLOBAL);
  369. end;
  370. constructor tai_symbol.initname(const _name : string;siz:longint);
  371. begin
  372. inherited init;
  373. typ:=ait_symbol;
  374. sym:=newasmsymboltyp(_name,AS_LOCAL);
  375. size:=siz;
  376. is_global:=false;
  377. end;
  378. constructor tai_symbol.initname_global(const _name : string;siz:longint);
  379. begin
  380. inherited init;
  381. typ:=ait_symbol;
  382. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  383. size:=siz;
  384. is_global:=true;
  385. end;
  386. {****************************************************************************
  387. TAI_SYMBOL
  388. ****************************************************************************}
  389. constructor tai_symbol_end.init(_sym:PAsmSymbol);
  390. begin
  391. inherited init;
  392. typ:=ait_symbol_end;
  393. sym:=_sym;
  394. end;
  395. constructor tai_symbol_end.initname(const _name : string);
  396. begin
  397. inherited init;
  398. typ:=ait_symbol_end;
  399. sym:=newasmsymboltyp(_name,AS_GLOBAL);
  400. end;
  401. {****************************************************************************
  402. TAI_CONST
  403. ****************************************************************************}
  404. constructor tai_const.init_32bit(_value : longint);
  405. begin
  406. inherited init;
  407. typ:=ait_const_32bit;
  408. value:=_value;
  409. end;
  410. constructor tai_const.init_16bit(_value : word);
  411. begin
  412. inherited init;
  413. typ:=ait_const_16bit;
  414. value:=_value;
  415. end;
  416. constructor tai_const.init_8bit(_value : byte);
  417. begin
  418. inherited init;
  419. typ:=ait_const_8bit;
  420. value:=_value;
  421. end;
  422. {****************************************************************************
  423. TAI_CONST_SYMBOL_OFFSET
  424. ****************************************************************************}
  425. constructor tai_const_symbol.init(_sym:PAsmSymbol);
  426. begin
  427. inherited init;
  428. typ:=ait_const_symbol;
  429. sym:=_sym;
  430. offset:=0;
  431. { update sym info }
  432. inc(sym^.refs);
  433. end;
  434. constructor tai_const_symbol.init_offset(_sym:PAsmSymbol;ofs:longint);
  435. begin
  436. inherited init;
  437. typ:=ait_const_symbol;
  438. sym:=_sym;
  439. offset:=ofs;
  440. { update sym info }
  441. inc(sym^.refs);
  442. end;
  443. constructor tai_const_symbol.init_rva(_sym:PAsmSymbol);
  444. begin
  445. inherited init;
  446. typ:=ait_const_rva;
  447. sym:=_sym;
  448. offset:=0;
  449. { update sym info }
  450. inc(sym^.refs);
  451. end;
  452. constructor tai_const_symbol.initname(const name:string);
  453. begin
  454. inherited init;
  455. typ:=ait_const_symbol;
  456. sym:=newasmsymbol(name);
  457. offset:=0;
  458. { update sym info }
  459. inc(sym^.refs);
  460. end;
  461. constructor tai_const_symbol.initname_offset(const name:string;ofs:longint);
  462. begin
  463. inherited init;
  464. typ:=ait_const_symbol;
  465. sym:=newasmsymbol(name);
  466. offset:=ofs;
  467. { update sym info }
  468. inc(sym^.refs);
  469. end;
  470. constructor tai_const_symbol.initname_rva(const name:string);
  471. begin
  472. inherited init;
  473. typ:=ait_const_rva;
  474. sym:=newasmsymbol(name);
  475. offset:=0;
  476. { update sym info }
  477. inc(sym^.refs);
  478. end;
  479. {****************************************************************************
  480. TAI_real_32bit
  481. ****************************************************************************}
  482. constructor tai_real_32bit.init(_value : ts32real);
  483. begin
  484. inherited init;
  485. typ:=ait_real_32bit;
  486. value:=_value;
  487. end;
  488. {****************************************************************************
  489. TAI_real_64bit
  490. ****************************************************************************}
  491. constructor tai_real_64bit.init(_value : ts64real);
  492. begin
  493. inherited init;
  494. typ:=ait_real_64bit;
  495. value:=_value;
  496. end;
  497. {****************************************************************************
  498. TAI_real_80bit
  499. ****************************************************************************}
  500. constructor tai_real_80bit.init(_value : ts80real);
  501. begin
  502. inherited init;
  503. typ:=ait_real_80bit;
  504. value:=_value;
  505. end;
  506. {****************************************************************************
  507. Tai_comp_64bit
  508. ****************************************************************************}
  509. constructor tai_comp_64bit.init(_value : ts64comp);
  510. begin
  511. inherited init;
  512. typ:=ait_comp_64bit;
  513. value:=_value;
  514. end;
  515. {****************************************************************************
  516. TAI_STRING
  517. ****************************************************************************}
  518. constructor tai_string.init(const _str : string);
  519. begin
  520. inherited init;
  521. typ:=ait_string;
  522. getmem(str,length(_str)+1);
  523. strpcopy(str,_str);
  524. len:=length(_str);
  525. end;
  526. constructor tai_string.init_pchar(_str : pchar);
  527. begin
  528. inherited init;
  529. typ:=ait_string;
  530. str:=_str;
  531. len:=strlen(_str);
  532. end;
  533. constructor tai_string.init_length_pchar(_str : pchar;length : longint);
  534. begin
  535. inherited init;
  536. typ:=ait_string;
  537. str:=_str;
  538. len:=length;
  539. end;
  540. destructor tai_string.done;
  541. begin
  542. { you can have #0 inside the strings so }
  543. if str<>nil then
  544. freemem(str,len+1);
  545. inherited done;
  546. end;
  547. {****************************************************************************
  548. TAI_LABEL
  549. ****************************************************************************}
  550. constructor tai_label.init(_l : pasmlabel);
  551. begin
  552. inherited init;
  553. typ:=ait_label;
  554. l:=_l;
  555. l^.is_set:=true;
  556. is_global:=(l^.typ=AS_GLOBAL);
  557. end;
  558. {****************************************************************************
  559. TAI_DIRECT
  560. ****************************************************************************}
  561. constructor tai_direct.init(_str : pchar);
  562. begin
  563. inherited init;
  564. typ:=ait_direct;
  565. str:=_str;
  566. end;
  567. destructor tai_direct.done;
  568. begin
  569. strdispose(str);
  570. inherited done;
  571. end;
  572. {****************************************************************************
  573. TAI_ASM_COMMENT comment to be inserted in the assembler file
  574. ****************************************************************************}
  575. constructor tai_asm_comment.init(_str : pchar);
  576. begin
  577. inherited init;
  578. typ:=ait_comment;
  579. str:=_str;
  580. end;
  581. destructor tai_asm_comment.done;
  582. begin
  583. strdispose(str);
  584. inherited done;
  585. end;
  586. {****************************************************************************
  587. TAI_ALIGN
  588. ****************************************************************************}
  589. constructor tai_align_abstract.init(b: byte);
  590. begin
  591. inherited init;
  592. typ:=ait_align;
  593. if b in [1,2,4,8,16,32] then
  594. aligntype := b
  595. else
  596. aligntype := 1;
  597. fillsize:=0;
  598. fillop:=0;
  599. use_op:=false;
  600. end;
  601. constructor tai_align_abstract.init_op(b: byte; _op: byte);
  602. begin
  603. inherited init;
  604. typ:=ait_align;
  605. if b in [1,2,4,8,16,32] then
  606. aligntype := b
  607. else
  608. aligntype := 1;
  609. fillsize:=0;
  610. fillop:=_op;
  611. use_op:=true;
  612. fillchar(buf,sizeof(buf),_op)
  613. end;
  614. function tai_align_abstract.getfillbuf:pchar;
  615. begin
  616. getfillbuf:=@buf;
  617. end;
  618. {****************************************************************************
  619. TAI_CUT
  620. ****************************************************************************}
  621. constructor tai_cut.init;
  622. begin
  623. inherited init;
  624. typ:=ait_cut;
  625. place:=cut_normal;
  626. end;
  627. constructor tai_cut.init_begin;
  628. begin
  629. inherited init;
  630. typ:=ait_cut;
  631. place:=cut_begin;
  632. end;
  633. constructor tai_cut.init_end;
  634. begin
  635. inherited init;
  636. typ:=ait_cut;
  637. place:=cut_end;
  638. end;
  639. {****************************************************************************
  640. Tai_Marker
  641. ****************************************************************************}
  642. Constructor Tai_Marker.Init(_Kind: TMarker);
  643. Begin
  644. Inherited Init;
  645. typ := ait_marker;
  646. Kind := _Kind;
  647. End;
  648. {*****************************************************************************
  649. TaiTempAlloc
  650. *****************************************************************************}
  651. constructor taitempalloc.alloc(pos,size:longint);
  652. begin
  653. inherited init;
  654. typ:=ait_tempalloc;
  655. allocation:=true;
  656. temppos:=pos;
  657. tempsize:=size;
  658. end;
  659. constructor taitempalloc.dealloc(pos,size:longint);
  660. begin
  661. inherited init;
  662. typ:=ait_tempalloc;
  663. allocation:=false;
  664. temppos:=pos;
  665. tempsize:=size;
  666. end;
  667. {*****************************************************************************
  668. AsmSymbol
  669. *****************************************************************************}
  670. constructor tasmsymbol.init(const s:string;_typ:TAsmsymtype);
  671. begin;
  672. {$IFDEF NEWST}
  673. inherited init(s);
  674. {$ELSE}
  675. inherited initname(s);
  676. {$ENDIF NEWST}
  677. reset;
  678. orgtyp:=_typ;
  679. typ:=_typ;
  680. end;
  681. procedure tasmsymbol.GenerateAltSymbol;
  682. begin
  683. if not assigned(altsymbol) then
  684. begin
  685. new(altsymbol,init(name+'_'+tostr(nextaltnr),typ));
  686. { also copy the amount of references }
  687. altsymbol^.refs:=refs;
  688. inc(nextaltnr);
  689. end;
  690. end;
  691. procedure tasmsymbol.reset;
  692. begin
  693. { reset section info }
  694. section:=sec_none;
  695. address:=0;
  696. size:=0;
  697. idx:=-1;
  698. typ:=AS_EXTERNAL;
  699. proclocal:=false;
  700. { mainly used to remove unused labels from the codesegment }
  701. refs:=0;
  702. end;
  703. function tasmsymbol.is_used:boolean;
  704. begin
  705. is_used:=(refs>0);
  706. end;
  707. procedure tasmsymbol.settyp(t:tasmsymtype);
  708. begin
  709. typ:=t;
  710. orgtyp:=t;
  711. end;
  712. procedure tasmsymbol.setaddress(sec:tsection;offset,len:longint);
  713. begin
  714. section:=sec;
  715. address:=offset;
  716. size:=len;
  717. { when the typ was reset to External, set it back to the original
  718. type it got when defined }
  719. if (typ=AS_EXTERNAL) and (orgtyp<>AS_NONE) then
  720. typ:=orgtyp;
  721. end;
  722. {*****************************************************************************
  723. AsmLabel
  724. *****************************************************************************}
  725. constructor tasmlabel.init;
  726. begin;
  727. labelnr:=nextlabelnr;
  728. inc(nextlabelnr);
  729. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  730. proclocal:=true;
  731. is_set:=false;
  732. end;
  733. constructor tasmlabel.initdata;
  734. begin;
  735. labelnr:=nextlabelnr;
  736. inc(nextlabelnr);
  737. if (cs_create_smart in aktmoduleswitches) then
  738. inherited init('_$'+current_module^.modulename^+'$_L'+tostr(labelnr),AS_GLOBAL)
  739. else
  740. inherited init(target_asm.labelprefix+tostr(labelnr),AS_LOCAL);
  741. is_set:=false;
  742. { write it always }
  743. refs:=1;
  744. end;
  745. function tasmlabel.name:string;
  746. begin
  747. name:=inherited name;
  748. inc(refs);
  749. end;
  750. {*****************************************************************************
  751. AsmSymbolList helpers
  752. *****************************************************************************}
  753. function newasmsymbol(const s : string) : pasmsymbol;
  754. var
  755. hp : pasmsymbol;
  756. begin
  757. hp:=pasmsymbol(asmsymbollist^.search(s));
  758. if assigned(hp) then
  759. begin
  760. newasmsymbol:=hp;
  761. exit;
  762. end;
  763. { Not found, insert it as an External }
  764. hp:=new(pasmsymbol,init(s,AS_EXTERNAL));
  765. asmsymbollist^.insert(hp);
  766. newasmsymbol:=hp;
  767. end;
  768. function newasmsymboltyp(const s : string;_typ:TAsmSymType) : pasmsymbol;
  769. var
  770. hp : pasmsymbol;
  771. begin
  772. hp:=pasmsymbol(asmsymbollist^.search(s));
  773. if assigned(hp) then
  774. begin
  775. hp^.settyp(_typ);
  776. newasmsymboltyp:=hp;
  777. exit;
  778. end;
  779. { Not found, insert it as an External }
  780. hp:=new(pasmsymbol,init(s,_typ));
  781. asmsymbollist^.insert(hp);
  782. newasmsymboltyp:=hp;
  783. end;
  784. function getasmsymbol(const s : string) : pasmsymbol;
  785. begin
  786. getasmsymbol:=pasmsymbol(asmsymbollist^.search(s));
  787. end;
  788. { renames an asmsymbol }
  789. function renameasmsymbol(const sold, snew : string):pasmsymbol;
  790. begin
  791. renameasmsymbol:=pasmsymbol(asmsymbollist^.rename(sold,snew));
  792. end;
  793. procedure ResetAsmSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  794. begin
  795. pasmsymbol(p)^.reset;
  796. end;
  797. procedure ResetAsmsymbolList;
  798. begin
  799. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetasmsym);
  800. end;
  801. procedure ResetAltSym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  802. begin
  803. pasmsymbol(p)^.altsymbol:=nil;
  804. end;
  805. procedure ResetAsmSymbolListAltSymbol;
  806. begin
  807. asmsymbollist^.foreach({$ifndef TP}@{$endif}resetaltsym);
  808. end;
  809. procedure checkundefinedasmsym(p:Pnamedindexobject);{$ifndef FPC}far;{$endif}
  810. begin
  811. if (pasmsymbol(p)^.refs>0) and
  812. (pasmsymbol(p)^.section=Sec_none) and
  813. (pasmsymbol(p)^.typ<>AS_EXTERNAL) then
  814. Message1(asmw_e_undefined_label,pasmsymbol(p)^.name);
  815. end;
  816. procedure CheckAsmSymbolListUndefined;
  817. begin
  818. asmsymbollist^.foreach({$ifndef TP}@{$endif}checkundefinedasmsym);
  819. end;
  820. {*****************************************************************************
  821. Label Helpers
  822. *****************************************************************************}
  823. procedure getlabel(var l : pasmlabel);
  824. begin
  825. l:=new(pasmlabel,init);
  826. asmsymbollist^.insert(l);
  827. end;
  828. procedure getdatalabel(var l : pasmlabel);
  829. begin
  830. l:=new(pasmlabel,initdata);
  831. asmsymbollist^.insert(l);
  832. end;
  833. procedure RegenerateLabel(var l : pasmlabel);
  834. begin
  835. if l^.proclocal then
  836. getlabel(pasmlabel(l^.altsymbol))
  837. else
  838. getdatalabel(pasmlabel(l^.altsymbol));
  839. end;
  840. procedure getlabelnr(var l : longint);
  841. begin
  842. l:=nextlabelnr;
  843. inc(nextlabelnr);
  844. end;
  845. {*****************************************************************************
  846. TAAsmOutput
  847. *****************************************************************************}
  848. function taasmoutput.getlasttaifilepos : pfileposinfo;
  849. begin
  850. if assigned(last) then
  851. getlasttaifilepos:=@pai(last)^.fileinfo
  852. else
  853. getlasttaifilepos:=nil;
  854. end;
  855. end.
  856. {
  857. $Log$
  858. Revision 1.80 2000-02-29 23:55:53 pierre
  859. + InlineStat and InlineEnd amrker added
  860. Revision 1.79 2000/02/28 17:23:56 daniel
  861. * Current work of symtable integration committed. The symtable can be
  862. activated by defining 'newst', but doesn't compile yet. Changes in type
  863. checking and oop are completed. What is left is to write a new
  864. symtablestack and adapt the parser to use it.
  865. Revision 1.78 2000/02/18 20:53:14 pierre
  866. * fixes a stabs problem for functions
  867. + includes a stabs local var for with statements
  868. the name is with in lowercase followed by an index
  869. for nested with.
  870. + Withdebuglist added because the stabs declarations of local
  871. var are postponed to end of function.
  872. Revision 1.77 2000/02/09 13:22:42 peter
  873. * log truncated
  874. Revision 1.76 2000/02/03 23:01:45 peter
  875. * fixed smartlinking
  876. Revision 1.75 2000/01/28 15:15:31 jonas
  877. * moved skipinstr from daopt386 to aasm
  878. * fixed crashing bug with -dreplacereg in csopt386.pas
  879. Revision 1.74 2000/01/23 16:31:38 peter
  880. * fixed uninited asmsymbol.typ var
  881. Revision 1.73 2000/01/19 22:53:57 florian
  882. * empty records/objects would generate static data of size 0 which is optimized away, tai_datablock
  883. checks now the size and sets it to a value > 0
  884. Revision 1.72 2000/01/13 13:07:05 jonas
  885. * released -dalignreg
  886. * some small fixes to -dnewOptimizations helper procedures
  887. Revision 1.71 2000/01/12 10:38:16 peter
  888. * smartlinking fixes for binary writer
  889. * release alignreg code and moved instruction writing align to cpuasm,
  890. but it doesn't use the specified register yet
  891. Revision 1.70 2000/01/07 01:14:18 peter
  892. * updated copyright to 2000
  893. Revision 1.69 1999/12/22 01:01:46 peter
  894. - removed freelabel()
  895. * added undefined label detection in internal assembler, this prevents
  896. a lot of ld crashes and wrong .o files
  897. * .o files aren't written anymore if errors have occured
  898. * inlining of assembler labels is now correct
  899. Revision 1.68 1999/11/06 14:34:16 peter
  900. * truncated log to 20 revs
  901. Revision 1.67 1999/11/05 16:01:45 jonas
  902. + first implementation of choosing least used register for alignment code
  903. (not yet working, between ifdef alignreg)
  904. Revision 1.66 1999/11/02 15:06:56 peter
  905. * import library fixes for win32
  906. * alignment works again
  907. Revision 1.65 1999/10/27 16:11:27 peter
  908. * insns.dat is used to generate all i386*.inc files
  909. Revision 1.64 1999/09/20 16:38:51 peter
  910. * cs_create_smart instead of cs_smartlink
  911. * -CX is create smartlink
  912. * -CD is create dynamic, but does nothing atm.
  913. Revision 1.63 1999/09/16 23:05:51 florian
  914. * m68k compiler is again compilable (only gas writer, no assembler reader)
  915. Revision 1.62 1999/09/15 20:35:37 florian
  916. * small fix to operator overloading when in MMX mode
  917. + the compiler uses now fldz and fld1 if possible
  918. + some fixes to floating point registers
  919. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  920. * .... ???
  921. Revision 1.61 1999/09/08 15:01:29 jonas
  922. * some small changes so the noew optimizer is again compilable
  923. Revision 1.60 1999/08/06 15:30:17 florian
  924. + cpu flags added, mainly for the new cg
  925. Revision 1.59 1999/08/05 15:51:01 michael
  926. * Added ait_frame, ait_ent
  927. Revision 1.58 1999/08/04 00:39:56 michael
  928. + Added ait_frame
  929. Revision 1.57 1999/08/02 21:01:41 michael
  930. * Moved toperand type back =(
  931. }