aasm.pas 30 KB

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