assemble.pas 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. {
  2. Copyright (c) 1998-2004 by Peter Vreman
  3. This unit handles the assemblerfile write and assembler calls of FPC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. {# @abstract(This unit handles the assembler file write and assembler calls of FPC)
  18. Handles the calls to the actual external assemblers, as well as the generation
  19. of object files for smart linking. Also contains the base class for writing
  20. the assembler statements to file.
  21. }
  22. unit assemble;
  23. {$i fpcdefs.inc}
  24. interface
  25. uses
  26. SysUtils,
  27. systems,globtype,globals,aasmbase,aasmtai,aasmdata,ogbase;
  28. const
  29. { maximum of aasmoutput lists there will be }
  30. maxoutputlists = 20;
  31. { buffer size for writing the .s file }
  32. AsmOutSize=32768*4;
  33. type
  34. TAssembler=class(TAbstractAssembler)
  35. public
  36. {filenames}
  37. path : string;
  38. name : string;
  39. AsmFileName, { current .s and .o file }
  40. ObjFileName,
  41. ppufilename : string;
  42. asmprefix : string;
  43. SmartAsm : boolean;
  44. SmartFilesCount,
  45. SmartHeaderCount : longint;
  46. Constructor Create(smart:boolean);virtual;
  47. Destructor Destroy;override;
  48. procedure NextSmartName(place:tcutplace);
  49. procedure MakeObject;virtual;abstract;
  50. end;
  51. {# This is the base class which should be overriden for each each
  52. assembler writer. It is used to actually assembler a file,
  53. and write the output to the assembler file.
  54. }
  55. TExternalAssembler=class(TAssembler)
  56. private
  57. procedure CreateSmartLinkPath(const s:string);
  58. protected
  59. {outfile}
  60. AsmSize,
  61. AsmStartSize,
  62. outcnt : longint;
  63. outbuf : array[0..AsmOutSize-1] of char;
  64. outfile : file;
  65. ioerror : boolean;
  66. public
  67. {# Returns the complete path and executable name of the assembler
  68. program.
  69. It first tries looking in the UTIL directory if specified,
  70. otherwise it searches in the free pascal binary directory, in
  71. the current working directory and then in the directories
  72. in the $PATH environment.}
  73. Function FindAssembler:string;
  74. {# Actually does the call to the assembler file. Returns false
  75. if the assembling of the file failed.}
  76. Function CallAssembler(const command:string; const para:TCmdStr):Boolean;
  77. Function DoAssemble:boolean;virtual;
  78. Procedure RemoveAsm;
  79. Procedure AsmFlush;
  80. Procedure AsmClear;
  81. {# Write a string to the assembler file }
  82. Procedure AsmWrite(const s:string);
  83. {# Write a string to the assembler file }
  84. Procedure AsmWritePChar(p:pchar);
  85. {# Write a string to the assembler file followed by a new line }
  86. Procedure AsmWriteLn(const s:string);
  87. {# Write a new line to the assembler file }
  88. Procedure AsmLn;
  89. procedure AsmCreate(Aplace:tcutplace);
  90. procedure AsmClose;
  91. {# This routine should be overriden for each assembler, it is used
  92. to actually write the abstract assembler stream to file.}
  93. procedure WriteTree(p:TAsmList);virtual;
  94. {# This routine should be overriden for each assembler, it is used
  95. to actually write all the different abstract assembler streams
  96. by calling for each stream type, the @var(WriteTree) method.}
  97. procedure WriteAsmList;virtual;
  98. {# Constructs the command line for calling the assembler }
  99. function MakeCmdLine: TCmdStr; virtual;
  100. public
  101. Constructor Create(smart:boolean);override;
  102. procedure MakeObject;override;
  103. end;
  104. TInternalAssembler=class(TAssembler)
  105. private
  106. FCObjOutput : TObjOutputclass;
  107. { the aasmoutput lists that need to be processed }
  108. lists : byte;
  109. list : array[1..maxoutputlists] of TAsmList;
  110. { current processing }
  111. currlistidx : byte;
  112. currlist : TAsmList;
  113. procedure WriteStab(p:pchar);
  114. function MaybeNextList(var hp:Tai):boolean;
  115. function TreePass0(hp:Tai):Tai;
  116. function TreePass1(hp:Tai):Tai;
  117. function TreePass2(hp:Tai):Tai;
  118. procedure writetree;
  119. procedure writetreesmart;
  120. protected
  121. ObjData : TObjData;
  122. ObjOutput : tObjOutput;
  123. property CObjOutput:TObjOutputclass read FCObjOutput write FCObjOutput;
  124. public
  125. constructor create(smart:boolean);override;
  126. destructor destroy;override;
  127. procedure MakeObject;override;
  128. end;
  129. TAssemblerClass = class of TAssembler;
  130. Procedure GenerateAsm(smart:boolean);
  131. Procedure OnlyAsm;
  132. procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
  133. procedure InitAssembler;
  134. procedure DoneAssembler;
  135. Implementation
  136. uses
  137. {$ifdef hasunix}
  138. unix,
  139. {$endif}
  140. cutils,cfileutl,
  141. {$ifdef memdebug}
  142. cclasses,
  143. {$endif memdebug}
  144. script,fmodule,verbose,
  145. {$ifdef m68k}
  146. cpuinfo,
  147. {$endif m68k}
  148. aasmcpu,
  149. owbase,owar
  150. ;
  151. var
  152. CAssembler : array[tasm] of TAssemblerClass;
  153. {*****************************************************************************
  154. TAssembler
  155. *****************************************************************************}
  156. Constructor TAssembler.Create(smart:boolean);
  157. begin
  158. { load start values }
  159. AsmFileName:=current_module.AsmFilename^;
  160. ObjFileName:=current_module.ObjFileName^;
  161. name:=Lower(current_module.modulename^);
  162. path:=current_module.outputpath^;
  163. asmprefix := current_module.asmprefix^;
  164. if not assigned(current_module.outputpath) then
  165. ppufilename := ''
  166. else
  167. ppufilename := current_module.ppufilename^;
  168. SmartAsm:=smart;
  169. SmartFilesCount:=0;
  170. SmartHeaderCount:=0;
  171. SmartLinkOFiles.Clear;
  172. end;
  173. Destructor TAssembler.Destroy;
  174. begin
  175. end;
  176. procedure TAssembler.NextSmartName(place:tcutplace);
  177. var
  178. s : string;
  179. begin
  180. inc(SmartFilesCount);
  181. if SmartFilesCount>999999 then
  182. Message(asmw_f_too_many_asm_files);
  183. case place of
  184. cut_begin :
  185. begin
  186. inc(SmartHeaderCount);
  187. s:=asmprefix+tostr(SmartHeaderCount)+'h';
  188. end;
  189. cut_normal :
  190. s:=asmprefix+tostr(SmartHeaderCount)+'s';
  191. cut_end :
  192. s:=asmprefix+tostr(SmartHeaderCount)+'t';
  193. end;
  194. AsmFileName:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.asmext);
  195. ObjFileName:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.objext);
  196. { insert in container so it can be cleared after the linking }
  197. SmartLinkOFiles.Insert(ObjFileName);
  198. end;
  199. {*****************************************************************************
  200. TExternalAssembler
  201. *****************************************************************************}
  202. Function DoPipe:boolean;
  203. begin
  204. DoPipe:=(cs_asm_pipe in current_settings.globalswitches) and
  205. (([cs_asm_leave,cs_link_on_target] * current_settings.globalswitches) = []) and
  206. ((target_asm.id in [as_gas,as_ggas,as_darwin]));
  207. end;
  208. Constructor TExternalAssembler.Create(smart:boolean);
  209. begin
  210. inherited Create(smart);
  211. if SmartAsm then
  212. begin
  213. path:=FixPath(ChangeFileExt(AsmFileName,target_info.smartext),false);
  214. CreateSmartLinkPath(path);
  215. end;
  216. Outcnt:=0;
  217. end;
  218. procedure TExternalAssembler.CreateSmartLinkPath(const s:string);
  219. procedure DeleteFilesWithExt(const AExt:string);
  220. var
  221. dir : TSearchRec;
  222. begin
  223. if findfirst(s+source_info.dirsep+'*'+AExt,faAnyFile,dir) = 0 then
  224. begin
  225. repeat
  226. DeleteFile(s+source_info.dirsep+dir.name);
  227. until findnext(dir) <> 0;
  228. end;
  229. findclose(dir);
  230. end;
  231. var
  232. hs : string;
  233. begin
  234. if PathExists(s,false) then
  235. begin
  236. { the path exists, now we clean only all the .o and .s files }
  237. DeleteFilesWithExt(target_info.objext);
  238. DeleteFilesWithExt(target_info.asmext);
  239. end
  240. else
  241. begin
  242. hs:=s;
  243. if hs[length(hs)] in ['/','\'] then
  244. delete(hs,length(hs),1);
  245. {$I-}
  246. mkdir(hs);
  247. {$I+}
  248. if ioresult<>0 then;
  249. end;
  250. end;
  251. const
  252. lastas : byte=255;
  253. var
  254. LastASBin : TCmdStr;
  255. Function TExternalAssembler.FindAssembler:string;
  256. var
  257. asfound : boolean;
  258. UtilExe : string;
  259. begin
  260. asfound:=false;
  261. if cs_link_on_target in current_settings.globalswitches then
  262. begin
  263. { If linking on target, don't add any path PM }
  264. FindAssembler:=utilsprefix+ChangeFileExt(target_asm.asmbin,target_info.exeext);
  265. exit;
  266. end
  267. else
  268. UtilExe:=utilsprefix+ChangeFileExt(target_asm.asmbin,source_info.exeext);
  269. if lastas<>ord(target_asm.id) then
  270. begin
  271. lastas:=ord(target_asm.id);
  272. { is an assembler passed ? }
  273. if utilsdirectory<>'' then
  274. asfound:=FindFile(UtilExe,utilsdirectory,false,LastASBin);
  275. if not AsFound then
  276. asfound:=FindExe(UtilExe,false,LastASBin);
  277. if (not asfound) and not(cs_asm_extern in current_settings.globalswitches) then
  278. begin
  279. Message1(exec_e_assembler_not_found,LastASBin);
  280. current_settings.globalswitches:=current_settings.globalswitches+[cs_asm_extern];
  281. end;
  282. if asfound then
  283. Message1(exec_t_using_assembler,LastASBin);
  284. end;
  285. FindAssembler:=LastASBin;
  286. end;
  287. Function TExternalAssembler.CallAssembler(const command:string; const para:TCmdStr):Boolean;
  288. var
  289. DosExitCode : Integer;
  290. begin
  291. result:=true;
  292. if (cs_asm_extern in current_settings.globalswitches) then
  293. begin
  294. AsmRes.AddAsmCommand(command,para,name);
  295. exit;
  296. end;
  297. try
  298. FlushOutput;
  299. DosExitCode := ExecuteProcess(command,para);
  300. if DosExitCode <>0
  301. then begin
  302. Message1(exec_e_error_while_assembling,tostr(dosexitcode));
  303. result:=false;
  304. end;
  305. except on E:EOSError do
  306. begin
  307. Message1(exec_e_cant_call_assembler,tostr(E.ErrorCode));
  308. current_settings.globalswitches:=current_settings.globalswitches+[cs_asm_extern];
  309. result:=false;
  310. end;
  311. end;
  312. end;
  313. procedure TExternalAssembler.RemoveAsm;
  314. var
  315. g : file;
  316. begin
  317. if cs_asm_leave in current_settings.globalswitches then
  318. exit;
  319. if cs_asm_extern in current_settings.globalswitches then
  320. AsmRes.AddDeleteCommand(AsmFileName)
  321. else
  322. begin
  323. assign(g,AsmFileName);
  324. {$I-}
  325. erase(g);
  326. {$I+}
  327. if ioresult<>0 then;
  328. end;
  329. end;
  330. Function TExternalAssembler.DoAssemble:boolean;
  331. begin
  332. DoAssemble:=true;
  333. if DoPipe then
  334. exit;
  335. if not(cs_asm_extern in current_settings.globalswitches) then
  336. begin
  337. if SmartAsm then
  338. begin
  339. if (SmartFilesCount<=1) then
  340. Message1(exec_i_assembling_smart,name);
  341. end
  342. else
  343. Message1(exec_i_assembling,name);
  344. end;
  345. if CallAssembler(FindAssembler,MakeCmdLine) then
  346. RemoveAsm
  347. else
  348. begin
  349. DoAssemble:=false;
  350. GenerateError;
  351. end;
  352. end;
  353. Procedure TExternalAssembler.AsmFlush;
  354. begin
  355. if outcnt>0 then
  356. begin
  357. { suppress i/o error }
  358. {$i-}
  359. BlockWrite(outfile,outbuf,outcnt);
  360. {$i+}
  361. ioerror:=ioerror or (ioresult<>0);
  362. outcnt:=0;
  363. end;
  364. end;
  365. Procedure TExternalAssembler.AsmClear;
  366. begin
  367. outcnt:=0;
  368. end;
  369. Procedure TExternalAssembler.AsmWrite(const s:string);
  370. begin
  371. if OutCnt+length(s)>=AsmOutSize then
  372. AsmFlush;
  373. Move(s[1],OutBuf[OutCnt],length(s));
  374. inc(OutCnt,length(s));
  375. inc(AsmSize,length(s));
  376. end;
  377. Procedure TExternalAssembler.AsmWriteLn(const s:string);
  378. begin
  379. AsmWrite(s);
  380. AsmLn;
  381. end;
  382. Procedure TExternalAssembler.AsmWritePChar(p:pchar);
  383. var
  384. i,j : longint;
  385. begin
  386. i:=StrLen(p);
  387. j:=i;
  388. while j>0 do
  389. begin
  390. i:=min(j,AsmOutSize);
  391. if OutCnt+i>=AsmOutSize then
  392. AsmFlush;
  393. Move(p[0],OutBuf[OutCnt],i);
  394. inc(OutCnt,i);
  395. inc(AsmSize,i);
  396. dec(j,i);
  397. p:=pchar(@p[i]);
  398. end;
  399. end;
  400. Procedure TExternalAssembler.AsmLn;
  401. begin
  402. if OutCnt>=AsmOutSize-2 then
  403. AsmFlush;
  404. if (cs_link_on_target in current_settings.globalswitches) then
  405. begin
  406. OutBuf[OutCnt]:=target_info.newline[1];
  407. inc(OutCnt);
  408. inc(AsmSize);
  409. if length(target_info.newline)>1 then
  410. begin
  411. OutBuf[OutCnt]:=target_info.newline[2];
  412. inc(OutCnt);
  413. inc(AsmSize);
  414. end;
  415. end
  416. else
  417. begin
  418. OutBuf[OutCnt]:=source_info.newline[1];
  419. inc(OutCnt);
  420. inc(AsmSize);
  421. if length(source_info.newline)>1 then
  422. begin
  423. OutBuf[OutCnt]:=source_info.newline[2];
  424. inc(OutCnt);
  425. inc(AsmSize);
  426. end;
  427. end;
  428. end;
  429. function TExternalAssembler.MakeCmdLine: TCmdStr;
  430. begin
  431. result:=target_asm.asmcmd;
  432. {$ifdef m68k}
  433. if current_settings.cputype = cpu_MC68020 then
  434. result:='-m68020 '+result
  435. else
  436. result:='-m68000 '+result;
  437. {$endif}
  438. if (cs_link_on_target in current_settings.globalswitches) then
  439. begin
  440. Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
  441. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(ObjFileName)));
  442. end
  443. else
  444. begin
  445. {$ifdef hasunix}
  446. if DoPipe then
  447. Replace(result,'$ASM','')
  448. else
  449. {$endif}
  450. Replace(result,'$ASM',maybequoted(AsmFileName));
  451. Replace(result,'$OBJ',maybequoted(ObjFileName));
  452. end;
  453. end;
  454. procedure TExternalAssembler.AsmCreate(Aplace:tcutplace);
  455. begin
  456. if SmartAsm then
  457. NextSmartName(Aplace);
  458. {$ifdef hasunix}
  459. if DoPipe then
  460. begin
  461. if SmartAsm then
  462. begin
  463. if (SmartFilesCount<=1) then
  464. Message1(exec_i_assembling_smart,name);
  465. end
  466. else
  467. Message1(exec_i_assembling_pipe,AsmFileName);
  468. POpen(outfile,FindAssembler+' '+MakeCmdLine,'W');
  469. end
  470. else
  471. {$endif}
  472. begin
  473. Assign(outfile,AsmFileName);
  474. {$I-}
  475. Rewrite(outfile,1);
  476. {$I+}
  477. if ioresult<>0 then
  478. begin
  479. ioerror:=true;
  480. Message1(exec_d_cant_create_asmfile,AsmFileName);
  481. end;
  482. end;
  483. outcnt:=0;
  484. AsmSize:=0;
  485. AsmStartSize:=0;
  486. end;
  487. procedure TExternalAssembler.AsmClose;
  488. var
  489. f : file;
  490. FileAge : longint;
  491. begin
  492. AsmFlush;
  493. {$ifdef hasunix}
  494. if DoPipe then
  495. begin
  496. if PClose(outfile) <> 0 then
  497. GenerateError;
  498. end
  499. else
  500. {$endif}
  501. begin
  502. {Touch Assembler time to ppu time is there is a ppufilename}
  503. if ppufilename<>'' then
  504. begin
  505. Assign(f,ppufilename);
  506. {$I-}
  507. reset(f,1);
  508. {$I+}
  509. if ioresult=0 then
  510. begin
  511. FileAge := FileGetDate(GetFileHandle(f));
  512. close(f);
  513. reset(outfile,1);
  514. FileSetDate(GetFileHandle(outFile),FileAge);
  515. end;
  516. end;
  517. close(outfile);
  518. end;
  519. end;
  520. procedure TExternalAssembler.WriteTree(p:TAsmList);
  521. begin
  522. end;
  523. procedure TExternalAssembler.WriteAsmList;
  524. begin
  525. end;
  526. procedure TExternalAssembler.MakeObject;
  527. begin
  528. AsmCreate(cut_normal);
  529. WriteAsmList;
  530. AsmClose;
  531. if not(ioerror) then
  532. DoAssemble;
  533. end;
  534. {*****************************************************************************
  535. TInternalAssembler
  536. *****************************************************************************}
  537. constructor TInternalAssembler.create(smart:boolean);
  538. begin
  539. inherited create(smart);
  540. ObjOutput:=nil;
  541. ObjData:=nil;
  542. SmartAsm:=smart;
  543. end;
  544. destructor TInternalAssembler.destroy;
  545. begin
  546. if assigned(ObjData) then
  547. ObjData.free;
  548. if assigned(ObjOutput) then
  549. ObjOutput.free;
  550. end;
  551. procedure TInternalAssembler.WriteStab(p:pchar);
  552. function consumecomma(var p:pchar):boolean;
  553. begin
  554. while (p^=' ') do
  555. inc(p);
  556. result:=(p^=',');
  557. inc(p);
  558. end;
  559. function consumenumber(var p:pchar;out value:longint):boolean;
  560. var
  561. hs : string;
  562. len,
  563. code : integer;
  564. begin
  565. value:=0;
  566. while (p^=' ') do
  567. inc(p);
  568. len:=0;
  569. while (p^ in ['0'..'9']) do
  570. begin
  571. inc(len);
  572. hs[len]:=p^;
  573. inc(p);
  574. end;
  575. if len>0 then
  576. begin
  577. hs[0]:=chr(len);
  578. val(hs,value,code);
  579. end
  580. else
  581. code:=-1;
  582. result:=(code=0);
  583. end;
  584. function consumeoffset(var p:pchar;out relocsym:tobjsymbol;out value:longint):boolean;
  585. var
  586. hs : string;
  587. len,
  588. code : integer;
  589. pstart : pchar;
  590. sym : tobjsymbol;
  591. exprvalue : longint;
  592. gotmin,
  593. have_first_symbol,
  594. have_second_symbol,
  595. dosub : boolean;
  596. begin
  597. result:=false;
  598. value:=0;
  599. relocsym:=nil;
  600. gotmin:=false;
  601. have_first_symbol:=false;
  602. have_second_symbol:=false;
  603. repeat
  604. dosub:=false;
  605. exprvalue:=0;
  606. if gotmin then
  607. begin
  608. dosub:=true;
  609. gotmin:=false;
  610. end;
  611. while (p^=' ') do
  612. inc(p);
  613. case p^ of
  614. #0 :
  615. break;
  616. ' ' :
  617. inc(p);
  618. '0'..'9' :
  619. begin
  620. len:=0;
  621. while (p^ in ['0'..'9']) do
  622. begin
  623. inc(len);
  624. hs[len]:=p^;
  625. inc(p);
  626. end;
  627. hs[0]:=chr(len);
  628. val(hs,exprvalue,code);
  629. if code<>0 then
  630. internalerror(200702251);
  631. end;
  632. '.','_',
  633. 'A'..'Z',
  634. 'a'..'z' :
  635. begin
  636. pstart:=p;
  637. while not(p^ in [#0,' ','-','+']) do
  638. inc(p);
  639. len:=p-pstart;
  640. if len>255 then
  641. internalerror(200509187);
  642. move(pstart^,hs[1],len);
  643. hs[0]:=chr(len);
  644. sym:=objdata.symbolref(hs);
  645. have_first_symbol:=true;
  646. { Second symbol? }
  647. if assigned(relocsym) then
  648. begin
  649. if have_second_symbol then
  650. internalerror(2007032201);
  651. have_second_symbol:=true;
  652. if not have_first_symbol then
  653. internalerror(2007032202);
  654. { second symbol should substracted to first }
  655. if not dosub then
  656. internalerror(2007032203);
  657. if (relocsym.objsection<>sym.objsection) then
  658. internalerror(2005091810);
  659. exprvalue:=relocsym.address-sym.address;
  660. relocsym:=nil;
  661. dosub:=false;
  662. end
  663. else
  664. begin
  665. relocsym:=sym;
  666. if assigned(sym.objsection) then
  667. begin
  668. { first symbol should be + }
  669. if not have_first_symbol and dosub then
  670. internalerror(2007032204);
  671. have_first_symbol:=true;
  672. end;
  673. end;
  674. end;
  675. '+' :
  676. begin
  677. { nothing, by default addition is done }
  678. inc(p);
  679. end;
  680. '-' :
  681. begin
  682. gotmin:=true;
  683. inc(p);
  684. end;
  685. else
  686. internalerror(200509189);
  687. end;
  688. if dosub then
  689. dec(value,exprvalue)
  690. else
  691. inc(value,exprvalue);
  692. until false;
  693. result:=true;
  694. end;
  695. var
  696. stabstrlen,
  697. ofs,
  698. nline,
  699. nidx,
  700. nother,
  701. i : longint;
  702. stab : TObjStabEntry;
  703. relocsym : TObjSymbol;
  704. pstr,
  705. pcurr,
  706. pendquote : pchar;
  707. oldsec : TObjSection;
  708. begin
  709. pcurr:=nil;
  710. pstr:=nil;
  711. pendquote:=nil;
  712. relocsym:=nil;
  713. ofs:=0;
  714. { Parse string part }
  715. if (p[0]='"') then
  716. begin
  717. pstr:=@p[1];
  718. { Ignore \" inside the string }
  719. i:=1;
  720. while not((p[i]='"') and (p[i-1]<>'\')) and
  721. (p[i]<>#0) do
  722. inc(i);
  723. pendquote:=@p[i];
  724. pendquote^:=#0;
  725. pcurr:=@p[i+1];
  726. if not consumecomma(pcurr) then
  727. internalerror(200509181);
  728. end
  729. else
  730. pcurr:=p;
  731. { When in pass 1 then only alloc and leave }
  732. if ObjData.currpass=1 then
  733. begin
  734. ObjData.StabsSec.Alloc(sizeof(TObjStabEntry));
  735. if assigned(pstr) and (pstr[0]<>#0) then
  736. ObjData.StabStrSec.Alloc(strlen(pstr)+1);
  737. end
  738. else
  739. begin
  740. { Stabs format: nidx,nother,nline[,offset] }
  741. if not consumenumber(pcurr,nidx) then
  742. internalerror(200509182);
  743. if not consumecomma(pcurr) then
  744. internalerror(200509183);
  745. if not consumenumber(pcurr,nother) then
  746. internalerror(200509184);
  747. if not consumecomma(pcurr) then
  748. internalerror(200509185);
  749. if not consumenumber(pcurr,nline) then
  750. internalerror(200509186);
  751. if consumecomma(pcurr) then
  752. consumeoffset(pcurr,relocsym,ofs);
  753. { Generate stab entry }
  754. if assigned(pstr) and (pstr[0]<>#0) then
  755. begin
  756. stabstrlen:=strlen(pstr);
  757. {$ifdef optimizestabs}
  758. StabStrEntry:=nil;
  759. if (nidx=N_SourceFile) or (nidx=N_IncludeFile) then
  760. begin
  761. hs:=strpas(pstr);
  762. StabstrEntry:=StabStrDict.Find(hs);
  763. if not assigned(StabstrEntry) then
  764. begin
  765. StabstrEntry:=TStabStrEntry.Create(hs);
  766. StabstrEntry:=StabStrSec.Size;
  767. StabStrDict.Insert(StabstrEntry);
  768. { generate new stab }
  769. StabstrEntry:=nil;
  770. end;
  771. end;
  772. if assigned(StabstrEntry) then
  773. stab.strpos:=StabstrEntry.strpos
  774. else
  775. {$endif optimizestabs}
  776. begin
  777. stab.strpos:=ObjData.StabStrSec.Size;
  778. ObjData.StabStrSec.write(pstr^,stabstrlen+1);
  779. end;
  780. end
  781. else
  782. stab.strpos:=0;
  783. stab.ntype:=byte(nidx);
  784. stab.ndesc:=word(nline);
  785. stab.nother:=byte(nother);
  786. stab.nvalue:=ofs;
  787. { Write the stab first without the value field. Then
  788. write a the value field with relocation }
  789. oldsec:=ObjData.CurrObjSec;
  790. ObjData.SetSection(ObjData.StabsSec);
  791. ObjData.Writebytes(stab,sizeof(TObjStabEntry)-4);
  792. ObjData.Writereloc(stab.nvalue,4,relocsym,RELOC_ABSOLUTE);
  793. ObjData.setsection(oldsec);
  794. end;
  795. if assigned(pendquote) then
  796. pendquote^:='"';
  797. end;
  798. function TInternalAssembler.MaybeNextList(var hp:Tai):boolean;
  799. begin
  800. { maybe end of list }
  801. while not assigned(hp) do
  802. begin
  803. if currlistidx<lists then
  804. begin
  805. inc(currlistidx);
  806. currlist:=list[currlistidx];
  807. hp:=Tai(currList.first);
  808. end
  809. else
  810. begin
  811. MaybeNextList:=false;
  812. exit;
  813. end;
  814. end;
  815. MaybeNextList:=true;
  816. end;
  817. function TInternalAssembler.TreePass0(hp:Tai):Tai;
  818. var
  819. objsym,
  820. objsymend : TObjSymbol;
  821. begin
  822. while assigned(hp) do
  823. begin
  824. case hp.typ of
  825. ait_align :
  826. begin
  827. { always use the maximum fillsize in this pass to avoid possible
  828. short jumps to become out of range }
  829. Tai_align_abstract(hp).fillsize:=Tai_align_abstract(hp).aligntype;
  830. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  831. end;
  832. ait_datablock :
  833. begin
  834. if Tai_datablock(hp).is_global then
  835. ObjData.SymbolDefine(Tai_datablock(hp).sym)
  836. else
  837. begin
  838. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  839. ObjData.SymbolDefine(Tai_datablock(hp).sym);
  840. ObjData.alloc(Tai_datablock(hp).size);
  841. end;
  842. end;
  843. ait_real_80bit :
  844. ObjData.alloc(10);
  845. ait_real_64bit :
  846. ObjData.alloc(8);
  847. ait_real_32bit :
  848. ObjData.alloc(4);
  849. ait_comp_64bit :
  850. ObjData.alloc(8);
  851. ait_const:
  852. begin
  853. { if symbols are provided we can calculate the value for relative symbols.
  854. This is required for length calculation of leb128 constants }
  855. if assigned(tai_const(hp).sym) then
  856. begin
  857. objsym:=Objdata.SymbolRef(tai_const(hp).sym);
  858. if assigned(tai_const(hp).endsym) then
  859. begin
  860. objsymend:=Objdata.SymbolRef(tai_const(hp).endsym);
  861. if objsymend.objsection<>objsym.objsection then
  862. internalerror(200404124);
  863. Tai_const(hp).value:=objsymend.address-objsym.address+Tai_const(hp).symofs;
  864. end;
  865. end;
  866. ObjData.alloc(tai_const(hp).size);
  867. end;
  868. ait_section:
  869. begin
  870. ObjData.CreateSection(Tai_section(hp).sectype,Tai_section(hp).name^,Tai_section(hp).secorder);
  871. Tai_section(hp).sec:=ObjData.CurrObjSec;
  872. end;
  873. ait_symbol :
  874. ObjData.SymbolDefine(Tai_symbol(hp).sym);
  875. ait_label :
  876. ObjData.SymbolDefine(Tai_label(hp).labsym);
  877. ait_string :
  878. ObjData.alloc(Tai_string(hp).len);
  879. ait_instruction :
  880. begin
  881. { reset instructions which could change in pass 2 }
  882. Taicpu(hp).resetpass2;
  883. ObjData.alloc(Taicpu(hp).Pass1(ObjData));
  884. end;
  885. ait_cutobject :
  886. if SmartAsm then
  887. break;
  888. end;
  889. hp:=Tai(hp.next);
  890. end;
  891. TreePass0:=hp;
  892. end;
  893. function TInternalAssembler.TreePass1(hp:Tai):Tai;
  894. var
  895. objsym,
  896. objsymend : TObjSymbol;
  897. begin
  898. while assigned(hp) do
  899. begin
  900. case hp.typ of
  901. ait_align :
  902. begin
  903. { here we must determine the fillsize which is used in pass2 }
  904. Tai_align_abstract(hp).fillsize:=align(ObjData.CurrObjSec.Size,Tai_align_abstract(hp).aligntype)-
  905. ObjData.CurrObjSec.Size;
  906. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  907. end;
  908. ait_datablock :
  909. begin
  910. if (oso_data in ObjData.CurrObjSec.secoptions) then
  911. Message(asmw_e_alloc_data_only_in_bss);
  912. if Tai_datablock(hp).is_global then
  913. begin
  914. objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
  915. objsym.size:=Tai_datablock(hp).size;
  916. objsym.bind:=AB_COMMON;
  917. end
  918. else
  919. begin
  920. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  921. objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
  922. objsym.size:=Tai_datablock(hp).size;
  923. ObjData.alloc(Tai_datablock(hp).size);
  924. end;
  925. end;
  926. ait_real_80bit :
  927. ObjData.alloc(10);
  928. ait_real_64bit :
  929. ObjData.alloc(8);
  930. ait_real_32bit :
  931. ObjData.alloc(4);
  932. ait_comp_64bit :
  933. ObjData.alloc(8);
  934. ait_const:
  935. begin
  936. { Recalculate relative symbols, all checks are done in treepass0 }
  937. if assigned(tai_const(hp).sym) and
  938. assigned(tai_const(hp).endsym) then
  939. begin
  940. objsym:=Objdata.SymbolRef(tai_const(hp).sym);
  941. objsymend:=Objdata.SymbolRef(tai_const(hp).endsym);
  942. Tai_const(hp).value:=objsymend.address-objsym.address+Tai_const(hp).symofs;
  943. end;
  944. ObjData.alloc(tai_const(hp).size);
  945. end;
  946. ait_section:
  947. begin
  948. { use cached value }
  949. ObjData.setsection(Tai_section(hp).sec);
  950. end;
  951. ait_stab :
  952. begin
  953. if assigned(Tai_stab(hp).str) then
  954. WriteStab(Tai_stab(hp).str);
  955. end;
  956. ait_symbol :
  957. ObjData.SymbolDefine(Tai_symbol(hp).sym);
  958. ait_symbol_end :
  959. begin
  960. objsym:=ObjData.SymbolRef(Tai_symbol_end(hp).sym);
  961. objsym.size:=ObjData.CurrObjSec.Size-objsym.offset;
  962. end;
  963. ait_label :
  964. ObjData.SymbolDefine(Tai_label(hp).labsym);
  965. ait_string :
  966. ObjData.alloc(Tai_string(hp).len);
  967. ait_instruction :
  968. ObjData.alloc(Taicpu(hp).Pass1(ObjData));
  969. ait_cutobject :
  970. if SmartAsm then
  971. break;
  972. end;
  973. hp:=Tai(hp.next);
  974. end;
  975. TreePass1:=hp;
  976. end;
  977. function TInternalAssembler.TreePass2(hp:Tai):Tai;
  978. var
  979. fillbuffer : tfillbuffer;
  980. {$ifdef x86}
  981. co : comp;
  982. {$endif x86}
  983. leblen : byte;
  984. lebbuf : array[0..63] of byte;
  985. begin
  986. { main loop }
  987. while assigned(hp) do
  988. begin
  989. case hp.typ of
  990. ait_align :
  991. begin
  992. if (oso_data in ObjData.CurrObjSec.secoptions) then
  993. ObjData.writebytes(Tai_align_abstract(hp).calculatefillbuf(fillbuffer)^,Tai_align_abstract(hp).fillsize)
  994. else
  995. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  996. end;
  997. ait_section :
  998. begin
  999. { use cached value }
  1000. ObjData.setsection(Tai_section(hp).sec);
  1001. end;
  1002. ait_symbol :
  1003. begin
  1004. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_symbol(hp).sym));
  1005. end;
  1006. ait_datablock :
  1007. begin
  1008. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_datablock(hp).sym));
  1009. if not Tai_datablock(hp).is_global then
  1010. begin
  1011. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  1012. ObjData.alloc(Tai_datablock(hp).size);
  1013. end;
  1014. end;
  1015. ait_real_80bit :
  1016. ObjData.writebytes(Tai_real_80bit(hp).value,10);
  1017. ait_real_64bit :
  1018. ObjData.writebytes(Tai_real_64bit(hp).value,8);
  1019. ait_real_32bit :
  1020. ObjData.writebytes(Tai_real_32bit(hp).value,4);
  1021. ait_comp_64bit :
  1022. begin
  1023. {$ifdef x86}
  1024. co:=comp(Tai_comp_64bit(hp).value);
  1025. ObjData.writebytes(co,8);
  1026. {$endif x86}
  1027. end;
  1028. ait_string :
  1029. ObjData.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
  1030. ait_const :
  1031. begin
  1032. case tai_const(hp).consttype of
  1033. aitconst_64bit,
  1034. aitconst_32bit,
  1035. aitconst_16bit,
  1036. aitconst_8bit :
  1037. begin
  1038. if assigned(tai_const(hp).sym) and
  1039. not assigned(tai_const(hp).endsym) then
  1040. ObjData.writereloc(Tai_const(hp).symofs,tai_const(hp).size,Objdata.SymbolRef(tai_const(hp).sym),RELOC_ABSOLUTE)
  1041. else
  1042. ObjData.writebytes(Tai_const(hp).value,tai_const(hp).size);
  1043. end;
  1044. aitconst_rva_symbol :
  1045. begin
  1046. { PE32+? }
  1047. if target_info.system=system_x86_64_win64 then
  1048. ObjData.writereloc(Tai_const(hp).symofs,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA)
  1049. else
  1050. ObjData.writereloc(Tai_const(hp).symofs,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
  1051. end;
  1052. aitconst_secrel32_symbol :
  1053. begin
  1054. { Required for DWARF2 support under Windows }
  1055. ObjData.writereloc(Tai_const(hp).symofs,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_SECREL32);
  1056. end;
  1057. aitconst_uleb128bit,
  1058. aitconst_sleb128bit :
  1059. begin
  1060. if tai_const(hp).consttype=aitconst_uleb128bit then
  1061. leblen:=EncodeUleb128(qword(Tai_const(hp).value),lebbuf)
  1062. else
  1063. leblen:=EncodeSleb128(Tai_const(hp).value,lebbuf);
  1064. if leblen<>tai_const(hp).size then
  1065. internalerror(200709271);
  1066. ObjData.writebytes(lebbuf,leblen);
  1067. end;
  1068. else
  1069. internalerror(200603254);
  1070. end;
  1071. end;
  1072. ait_label :
  1073. begin
  1074. { exporting shouldn't be necessary as labels are local,
  1075. but it's better to be on the safe side (PFV) }
  1076. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_label(hp).labsym));
  1077. end;
  1078. ait_instruction :
  1079. Taicpu(hp).Pass2(ObjData);
  1080. ait_stab :
  1081. WriteStab(Tai_stab(hp).str);
  1082. ait_function_name,
  1083. ait_force_line : ;
  1084. ait_cutobject :
  1085. if SmartAsm then
  1086. break;
  1087. end;
  1088. hp:=Tai(hp.next);
  1089. end;
  1090. TreePass2:=hp;
  1091. end;
  1092. procedure TInternalAssembler.writetree;
  1093. label
  1094. doexit;
  1095. var
  1096. hp : Tai;
  1097. ObjWriter : TObjectWriter;
  1098. begin
  1099. ObjWriter:=TObjectwriter.create;
  1100. ObjOutput:=CObjOutput.Create(ObjWriter);
  1101. ObjData:=ObjOutput.newObjData(ObjFileName);
  1102. { Pass 0 }
  1103. ObjData.currpass:=0;
  1104. ObjData.createsection(sec_code);
  1105. ObjData.beforealloc;
  1106. { start with list 1 }
  1107. currlistidx:=1;
  1108. currlist:=list[currlistidx];
  1109. hp:=Tai(currList.first);
  1110. while assigned(hp) do
  1111. begin
  1112. hp:=TreePass0(hp);
  1113. MaybeNextList(hp);
  1114. end;
  1115. ObjData.afteralloc;
  1116. { leave if errors have occured }
  1117. if errorcount>0 then
  1118. goto doexit;
  1119. { Pass 1 }
  1120. ObjData.currpass:=1;
  1121. ObjData.resetsections;
  1122. ObjData.beforealloc;
  1123. ObjData.createsection(sec_code);
  1124. { start with list 1 }
  1125. currlistidx:=1;
  1126. currlist:=list[currlistidx];
  1127. hp:=Tai(currList.first);
  1128. while assigned(hp) do
  1129. begin
  1130. hp:=TreePass1(hp);
  1131. MaybeNextList(hp);
  1132. end;
  1133. ObjData.createsection(sec_code);
  1134. ObjData.afteralloc;
  1135. { leave if errors have occured }
  1136. if errorcount>0 then
  1137. goto doexit;
  1138. { Pass 2 }
  1139. ObjData.currpass:=2;
  1140. ObjData.resetsections;
  1141. ObjData.beforewrite;
  1142. ObjData.createsection(sec_code);
  1143. { start with list 1 }
  1144. currlistidx:=1;
  1145. currlist:=list[currlistidx];
  1146. hp:=Tai(currList.first);
  1147. while assigned(hp) do
  1148. begin
  1149. hp:=TreePass2(hp);
  1150. MaybeNextList(hp);
  1151. end;
  1152. ObjData.createsection(sec_code);
  1153. ObjData.afterwrite;
  1154. { don't write the .o file if errors have occured }
  1155. if errorcount=0 then
  1156. begin
  1157. { write objectfile }
  1158. ObjOutput.startobjectfile(ObjFileName);
  1159. ObjOutput.writeobjectfile(ObjData);
  1160. end;
  1161. doexit:
  1162. { Cleanup }
  1163. ObjData.free;
  1164. ObjData:=nil;
  1165. ObjWriter.free;
  1166. end;
  1167. procedure TInternalAssembler.writetreesmart;
  1168. var
  1169. hp : Tai;
  1170. startsectype : TAsmSectiontype;
  1171. place: tcutplace;
  1172. ObjWriter : TObjectWriter;
  1173. begin
  1174. if not(cs_asm_leave in current_settings.globalswitches) then
  1175. ObjWriter:=TARObjectWriter.create(current_module.staticlibfilename^)
  1176. else
  1177. ObjWriter:=TObjectwriter.create;
  1178. NextSmartName(cut_normal);
  1179. ObjOutput:=CObjOutput.Create(ObjWriter);
  1180. startsectype:=sec_code;
  1181. { start with list 1 }
  1182. currlistidx:=1;
  1183. currlist:=list[currlistidx];
  1184. hp:=Tai(currList.first);
  1185. while assigned(hp) do
  1186. begin
  1187. ObjData:=ObjOutput.newObjData(ObjFileName);
  1188. { Pass 0 }
  1189. ObjData.currpass:=0;
  1190. ObjData.resetsections;
  1191. ObjData.beforealloc;
  1192. ObjData.createsection(startsectype);
  1193. TreePass0(hp);
  1194. ObjData.afteralloc;
  1195. { leave if errors have occured }
  1196. if errorcount>0 then
  1197. break;
  1198. { Pass 1 }
  1199. ObjData.currpass:=1;
  1200. ObjData.resetsections;
  1201. ObjData.beforealloc;
  1202. ObjData.createsection(startsectype);
  1203. TreePass1(hp);
  1204. ObjData.afteralloc;
  1205. { leave if errors have occured }
  1206. if errorcount>0 then
  1207. break;
  1208. { Pass 2 }
  1209. ObjData.currpass:=2;
  1210. ObjOutput.startobjectfile(ObjFileName);
  1211. ObjData.resetsections;
  1212. ObjData.beforewrite;
  1213. ObjData.createsection(startsectype);
  1214. hp:=TreePass2(hp);
  1215. ObjData.afterwrite;
  1216. { leave if errors have occured }
  1217. if errorcount>0 then
  1218. break;
  1219. { write the current objectfile }
  1220. ObjOutput.writeobjectfile(ObjData);
  1221. ObjData.free;
  1222. ObjData:=nil;
  1223. { end of lists? }
  1224. if not MaybeNextList(hp) then
  1225. break;
  1226. { we will start a new objectfile so reset everything }
  1227. { The place can still change in the next while loop, so don't init }
  1228. { the writer yet (JM) }
  1229. if (hp.typ=ait_cutobject) then
  1230. place := Tai_cutobject(hp).place
  1231. else
  1232. place := cut_normal;
  1233. { avoid empty files }
  1234. startsectype:=sec_code;
  1235. while assigned(hp) and
  1236. (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
  1237. begin
  1238. if Tai(hp).typ=ait_section then
  1239. startsectype:=Tai_section(hp).sectype;
  1240. if (Tai(hp).typ=ait_cutobject) then
  1241. place:=Tai_cutobject(hp).place;
  1242. hp:=Tai(hp.next);
  1243. end;
  1244. if not MaybeNextList(hp) then
  1245. break;
  1246. { start next objectfile }
  1247. NextSmartName(place);
  1248. end;
  1249. ObjData.free;
  1250. ObjData:=nil;
  1251. ObjWriter.free;
  1252. end;
  1253. procedure TInternalAssembler.MakeObject;
  1254. var to_do:set of TasmlistType;
  1255. i:TasmlistType;
  1256. procedure addlist(p:TAsmList);
  1257. begin
  1258. inc(lists);
  1259. list[lists]:=p;
  1260. end;
  1261. begin
  1262. to_do:=[low(Tasmlisttype)..high(Tasmlisttype)];
  1263. if usedeffileforexports then
  1264. exclude(to_do,al_exports);
  1265. if not(tf_section_threadvars in target_info.flags) then
  1266. exclude(to_do,al_threadvars);
  1267. for i:=low(TasmlistType) to high(TasmlistType) do
  1268. if (i in to_do) and (current_asmdata.asmlists[i]<>nil) then
  1269. addlist(current_asmdata.asmlists[i]);
  1270. if SmartAsm then
  1271. writetreesmart
  1272. else
  1273. writetree;
  1274. end;
  1275. {*****************************************************************************
  1276. Generate Assembler Files Main Procedure
  1277. *****************************************************************************}
  1278. Procedure GenerateAsm(smart:boolean);
  1279. var
  1280. a : TAssembler;
  1281. begin
  1282. if not assigned(CAssembler[target_asm.id]) then
  1283. Message(asmw_f_assembler_output_not_supported);
  1284. a:=CAssembler[target_asm.id].Create(smart);
  1285. a.MakeObject;
  1286. a.Free;
  1287. end;
  1288. Procedure OnlyAsm;
  1289. var
  1290. a : TExternalAssembler;
  1291. begin
  1292. a:=TExternalAssembler.Create(false);
  1293. a.DoAssemble;
  1294. a.Free;
  1295. end;
  1296. {*****************************************************************************
  1297. Init/Done
  1298. *****************************************************************************}
  1299. procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
  1300. var
  1301. t : tasm;
  1302. begin
  1303. t:=r.id;
  1304. if assigned(asminfos[t]) then
  1305. writeln('Warning: Assembler is already registered!')
  1306. else
  1307. Getmem(asminfos[t],sizeof(tasminfo));
  1308. asminfos[t]^:=r;
  1309. CAssembler[t]:=c;
  1310. end;
  1311. procedure InitAssembler;
  1312. begin
  1313. end;
  1314. procedure DoneAssembler;
  1315. begin
  1316. end;
  1317. end.