assemble.pas 43 KB

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