assemble.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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 current_settings.globalswitches) and
  215. (([cs_asm_leave,cs_link_on_target] * current_settings.globalswitches) = []) 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 current_settings.globalswitches 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 current_settings.globalswitches) then
  309. begin
  310. Message1(exec_e_assembler_not_found,LastASBin);
  311. current_settings.globalswitches:=current_settings.globalswitches+[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 current_settings.globalswitches) 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. current_settings.globalswitches:=current_settings.globalswitches+[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. current_settings.globalswitches:=current_settings.globalswitches+[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 current_settings.globalswitches then
  370. exit;
  371. if cs_asm_extern in current_settings.globalswitches 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 current_settings.globalswitches) 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 current_settings.globalswitches) 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 current_settings.cputype = cpu_MC68020 then
  486. result:='-m68020 '+result
  487. else
  488. result:='-m68000 '+result;
  489. {$endif}
  490. if (cs_link_on_target in current_settings.globalswitches) 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_LOCAL) then
  798. ofs:=0;
  799. ObjData.writestab(ofs,relocsym,byte(nidx),byte(nother),word(nline),pstr);
  800. end;
  801. if assigned(pendquote) then
  802. pendquote^:='"';
  803. end;
  804. function TInternalAssembler.MaybeNextList(var hp:Tai):boolean;
  805. begin
  806. { maybe end of list }
  807. while not assigned(hp) do
  808. begin
  809. if currlistidx<lists then
  810. begin
  811. inc(currlistidx);
  812. currlist:=list[currlistidx];
  813. hp:=Tai(currList.first);
  814. end
  815. else
  816. begin
  817. MaybeNextList:=false;
  818. exit;
  819. end;
  820. end;
  821. MaybeNextList:=true;
  822. end;
  823. function TInternalAssembler.TreePass0(hp:Tai):Tai;
  824. begin
  825. while assigned(hp) do
  826. begin
  827. case hp.typ of
  828. ait_align :
  829. begin
  830. { always use the maximum fillsize in this pass to avoid possible
  831. short jumps to become out of range }
  832. Tai_align_abstract(hp).fillsize:=Tai_align_abstract(hp).aligntype;
  833. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  834. end;
  835. ait_datablock :
  836. begin
  837. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  838. ObjData.SymbolDefine(Tai_datablock(hp).sym);
  839. ObjData.alloc(Tai_datablock(hp).size);
  840. end;
  841. ait_real_80bit :
  842. ObjData.alloc(10);
  843. ait_real_64bit :
  844. ObjData.alloc(8);
  845. ait_real_32bit :
  846. ObjData.alloc(4);
  847. ait_comp_64bit :
  848. ObjData.alloc(8);
  849. ait_const:
  850. ObjData.alloc(tai_const(hp).size);
  851. ait_section:
  852. begin
  853. ObjData.CreateSection(Tai_section(hp).sectype,Tai_section(hp).name^);
  854. Tai_section(hp).sec:=ObjData.CurrObjSec;
  855. end;
  856. ait_symbol :
  857. ObjData.SymbolDefine(Tai_symbol(hp).sym);
  858. ait_label :
  859. ObjData.SymbolDefine(Tai_label(hp).labsym);
  860. ait_string :
  861. ObjData.alloc(Tai_string(hp).len);
  862. ait_instruction :
  863. begin
  864. { reset instructions which could change in pass 2 }
  865. Taicpu(hp).resetpass2;
  866. ObjData.alloc(Taicpu(hp).Pass1(ObjData));
  867. end;
  868. ait_cutobject :
  869. if SmartAsm then
  870. break;
  871. end;
  872. hp:=Tai(hp.next);
  873. end;
  874. TreePass0:=hp;
  875. end;
  876. function TInternalAssembler.TreePass1(hp:Tai):Tai;
  877. var
  878. InlineLevel : longint;
  879. objsym : TObjSymbol;
  880. begin
  881. inlinelevel:=0;
  882. while assigned(hp) do
  883. begin
  884. case hp.typ of
  885. ait_align :
  886. begin
  887. { here we must determine the fillsize which is used in pass2 }
  888. Tai_align_abstract(hp).fillsize:=align(ObjData.CurrObjSec.Size,Tai_align_abstract(hp).aligntype)-
  889. ObjData.CurrObjSec.Size;
  890. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  891. end;
  892. ait_datablock :
  893. begin
  894. if (oso_data in ObjData.CurrObjSec.secoptions) then
  895. Message(asmw_e_alloc_data_only_in_bss);
  896. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  897. objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
  898. objsym.size:=Tai_datablock(hp).size;
  899. ObjData.alloc(Tai_datablock(hp).size);
  900. end;
  901. ait_real_80bit :
  902. ObjData.alloc(10);
  903. ait_real_64bit :
  904. ObjData.alloc(8);
  905. ait_real_32bit :
  906. ObjData.alloc(4);
  907. ait_comp_64bit :
  908. ObjData.alloc(8);
  909. ait_const:
  910. begin
  911. ObjData.alloc(tai_const(hp).size);
  912. if assigned(Tai_const(hp).sym) then
  913. ObjData.SymbolRef(Tai_const(hp).sym);
  914. if assigned(Tai_const(hp).endsym) then
  915. ObjData.SymbolRef(Tai_const(hp).endsym);
  916. end;
  917. ait_section:
  918. begin
  919. { use cached value }
  920. ObjData.setsection(Tai_section(hp).sec);
  921. end;
  922. ait_stab :
  923. begin
  924. if assigned(Tai_stab(hp).str) then
  925. convertstab(Tai_stab(hp).str);
  926. end;
  927. ait_symbol :
  928. ObjData.SymbolDefine(Tai_symbol(hp).sym);
  929. ait_symbol_end :
  930. begin
  931. objsym:=ObjData.SymbolRef(Tai_symbol_end(hp).sym);
  932. objsym.size:=ObjData.CurrObjSec.Size-objsym.offset;
  933. end;
  934. ait_label :
  935. ObjData.SymbolDefine(Tai_label(hp).labsym);
  936. ait_string :
  937. ObjData.alloc(Tai_string(hp).len);
  938. ait_instruction :
  939. ObjData.alloc(Taicpu(hp).Pass1(ObjData));
  940. ait_cutobject :
  941. if SmartAsm then
  942. break;
  943. ait_marker :
  944. if tai_marker(hp).kind=mark_InlineStart then
  945. inc(InlineLevel)
  946. else if tai_marker(hp).kind=mark_InlineEnd then
  947. dec(InlineLevel);
  948. end;
  949. hp:=Tai(hp.next);
  950. end;
  951. TreePass1:=hp;
  952. end;
  953. function TInternalAssembler.TreePass2(hp:Tai):Tai;
  954. var
  955. fillbuffer : tfillbuffer;
  956. InlineLevel,
  957. v : int64;
  958. {$ifdef x86}
  959. co : comp;
  960. {$endif x86}
  961. objsym,
  962. objsymend : TObjSymbol;
  963. leblen : byte;
  964. lebbuf : array[0..63] of byte;
  965. begin
  966. inlinelevel:=0;
  967. { main loop }
  968. while assigned(hp) do
  969. begin
  970. case hp.typ of
  971. ait_align :
  972. begin
  973. if (oso_data in ObjData.CurrObjSec.secoptions) then
  974. ObjData.writebytes(Tai_align_abstract(hp).calculatefillbuf(fillbuffer)^,Tai_align_abstract(hp).fillsize)
  975. else
  976. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  977. end;
  978. ait_section :
  979. begin
  980. { use cached value }
  981. ObjData.setsection(Tai_section(hp).sec);
  982. end;
  983. ait_symbol :
  984. begin
  985. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_symbol(hp).sym));
  986. end;
  987. ait_datablock :
  988. begin
  989. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  990. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_datablock(hp).sym));
  991. ObjData.alloc(Tai_datablock(hp).size);
  992. end;
  993. ait_real_80bit :
  994. ObjData.writebytes(Tai_real_80bit(hp).value,10);
  995. ait_real_64bit :
  996. ObjData.writebytes(Tai_real_64bit(hp).value,8);
  997. ait_real_32bit :
  998. ObjData.writebytes(Tai_real_32bit(hp).value,4);
  999. ait_comp_64bit :
  1000. begin
  1001. {$ifdef x86}
  1002. co:=comp(Tai_comp_64bit(hp).value);
  1003. ObjData.writebytes(co,8);
  1004. {$endif x86}
  1005. end;
  1006. ait_string :
  1007. ObjData.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
  1008. ait_const :
  1009. begin
  1010. case tai_const(hp).consttype of
  1011. aitconst_64bit,
  1012. aitconst_32bit,
  1013. aitconst_16bit,
  1014. aitconst_8bit :
  1015. begin
  1016. if assigned(tai_const(hp).sym) then
  1017. begin
  1018. objsym:=Objdata.SymbolRef(tai_const(hp).sym);
  1019. if assigned(tai_const(hp).endsym) then
  1020. begin
  1021. objsymend:=Objdata.SymbolRef(tai_const(hp).endsym);
  1022. if objsymend.objsection<>objsym.objsection then
  1023. internalerror(200404124);
  1024. v:=objsymend.address-objsym.address+Tai_const(hp).value;
  1025. ObjData.writebytes(v,tai_const(hp).size);
  1026. end
  1027. else
  1028. ObjData.writereloc(Tai_const(hp).value,Tai_const(hp).size,objsym,RELOC_ABSOLUTE);
  1029. end
  1030. else
  1031. ObjData.writebytes(Tai_const(hp).value,tai_const(hp).size);
  1032. end;
  1033. aitconst_rva_symbol :
  1034. { PE32+? }
  1035. if target_info.system=system_x86_64_win64 then
  1036. ObjData.writereloc(Tai_const(hp).value,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA)
  1037. else
  1038. ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
  1039. aitconst_uleb128bit :
  1040. begin
  1041. leblen:=EncodeUleb128(Tai_const(hp).value,lebbuf);
  1042. ObjData.writebytes(lebbuf,leblen);
  1043. end;
  1044. aitconst_sleb128bit :
  1045. begin
  1046. leblen:=EncodeSleb128(Tai_const(hp).value,lebbuf);
  1047. ObjData.writebytes(lebbuf,leblen);
  1048. end;
  1049. else
  1050. internalerror(200603254);
  1051. end;
  1052. end;
  1053. ait_label :
  1054. begin
  1055. { exporting shouldn't be necessary as labels are local,
  1056. but it's better to be on the safe side (PFV) }
  1057. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_label(hp).labsym));
  1058. end;
  1059. ait_instruction :
  1060. Taicpu(hp).Pass2(ObjData);
  1061. ait_stab :
  1062. convertstab(Tai_stab(hp).str);
  1063. ait_function_name,
  1064. ait_force_line : ;
  1065. ait_cutobject :
  1066. if SmartAsm then
  1067. break;
  1068. ait_marker :
  1069. if tai_marker(hp).kind=mark_InlineStart then
  1070. inc(InlineLevel)
  1071. else if tai_marker(hp).kind=mark_InlineEnd then
  1072. dec(InlineLevel);
  1073. end;
  1074. hp:=Tai(hp.next);
  1075. end;
  1076. TreePass2:=hp;
  1077. end;
  1078. procedure TInternalAssembler.writetree;
  1079. label
  1080. doexit;
  1081. var
  1082. hp : Tai;
  1083. ObjWriter : TObjectWriter;
  1084. begin
  1085. ObjWriter:=TObjectwriter.create;
  1086. ObjOutput:=CObjOutput.Create(ObjWriter);
  1087. ObjData:=ObjOutput.newObjData(ObjFileName);
  1088. { Pass 0 }
  1089. ObjData.currpass:=0;
  1090. ObjData.createsection(sec_code,'');
  1091. ObjData.beforealloc;
  1092. { start with list 1 }
  1093. currlistidx:=1;
  1094. currlist:=list[currlistidx];
  1095. hp:=Tai(currList.first);
  1096. while assigned(hp) do
  1097. begin
  1098. hp:=TreePass0(hp);
  1099. MaybeNextList(hp);
  1100. end;
  1101. ObjData.afteralloc;
  1102. { leave if errors have occured }
  1103. if errorcount>0 then
  1104. goto doexit;
  1105. { Pass 1 }
  1106. ObjData.currpass:=1;
  1107. ObjData.resetsections;
  1108. ObjData.beforealloc;
  1109. ObjData.createsection(sec_code,'');
  1110. { start with list 1 }
  1111. currlistidx:=1;
  1112. currlist:=list[currlistidx];
  1113. hp:=Tai(currList.first);
  1114. while assigned(hp) do
  1115. begin
  1116. hp:=TreePass1(hp);
  1117. MaybeNextList(hp);
  1118. end;
  1119. ObjData.createsection(sec_code,'');
  1120. ObjData.afteralloc;
  1121. { leave if errors have occured }
  1122. if errorcount>0 then
  1123. goto doexit;
  1124. { Pass 2 }
  1125. ObjData.currpass:=2;
  1126. ObjData.resetsections;
  1127. ObjData.beforewrite;
  1128. ObjData.createsection(sec_code,'');
  1129. { start with list 1 }
  1130. currlistidx:=1;
  1131. currlist:=list[currlistidx];
  1132. hp:=Tai(currList.first);
  1133. while assigned(hp) do
  1134. begin
  1135. hp:=TreePass2(hp);
  1136. MaybeNextList(hp);
  1137. end;
  1138. ObjData.createsection(sec_code,'');
  1139. ObjData.afterwrite;
  1140. { don't write the .o file if errors have occured }
  1141. if errorcount=0 then
  1142. begin
  1143. { write objectfile }
  1144. ObjOutput.startobjectfile(ObjFileName);
  1145. ObjOutput.writeobjectfile(ObjData);
  1146. end;
  1147. doexit:
  1148. { Cleanup }
  1149. ObjData.free;
  1150. ObjData:=nil;
  1151. ObjWriter.free;
  1152. end;
  1153. procedure TInternalAssembler.writetreesmart;
  1154. var
  1155. hp : Tai;
  1156. startsectype : TAsmSectiontype;
  1157. place: tcutplace;
  1158. ObjWriter : TObjectWriter;
  1159. begin
  1160. if not(cs_asm_leave in current_settings.globalswitches) then
  1161. ObjWriter:=TARObjectWriter.create(current_module.staticlibfilename^)
  1162. else
  1163. ObjWriter:=TObjectwriter.create;
  1164. NextSmartName(cut_normal);
  1165. ObjOutput:=CObjOutput.Create(ObjWriter);
  1166. startsectype:=sec_code;
  1167. { start with list 1 }
  1168. currlistidx:=1;
  1169. currlist:=list[currlistidx];
  1170. hp:=Tai(currList.first);
  1171. while assigned(hp) do
  1172. begin
  1173. ObjData:=ObjOutput.newObjData(ObjFileName);
  1174. { Pass 0 }
  1175. ObjData.currpass:=0;
  1176. ObjData.resetsections;
  1177. ObjData.beforealloc;
  1178. ObjData.createsection(startsectype,'');
  1179. TreePass0(hp);
  1180. ObjData.afteralloc;
  1181. { leave if errors have occured }
  1182. if errorcount>0 then
  1183. break;
  1184. { Pass 1 }
  1185. ObjData.currpass:=1;
  1186. ObjData.resetsections;
  1187. ObjData.beforealloc;
  1188. ObjData.createsection(startsectype,'');
  1189. TreePass1(hp);
  1190. ObjData.afteralloc;
  1191. { leave if errors have occured }
  1192. if errorcount>0 then
  1193. break;
  1194. { Pass 2 }
  1195. ObjData.currpass:=2;
  1196. ObjOutput.startobjectfile(ObjFileName);
  1197. ObjData.resetsections;
  1198. ObjData.beforewrite;
  1199. ObjData.createsection(startsectype,'');
  1200. hp:=TreePass2(hp);
  1201. ObjData.afterwrite;
  1202. { leave if errors have occured }
  1203. if errorcount>0 then
  1204. break;
  1205. { write the current objectfile }
  1206. ObjOutput.writeobjectfile(ObjData);
  1207. ObjData.free;
  1208. ObjData:=nil;
  1209. { end of lists? }
  1210. if not MaybeNextList(hp) then
  1211. break;
  1212. { we will start a new objectfile so reset everything }
  1213. { The place can still change in the next while loop, so don't init }
  1214. { the writer yet (JM) }
  1215. if (hp.typ=ait_cutobject) then
  1216. place := Tai_cutobject(hp).place
  1217. else
  1218. place := cut_normal;
  1219. { avoid empty files }
  1220. startsectype:=sec_code;
  1221. while assigned(hp) and
  1222. (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
  1223. begin
  1224. if Tai(hp).typ=ait_section then
  1225. startsectype:=Tai_section(hp).sectype;
  1226. if (Tai(hp).typ=ait_cutobject) then
  1227. place:=Tai_cutobject(hp).place;
  1228. hp:=Tai(hp.next);
  1229. end;
  1230. if not MaybeNextList(hp) then
  1231. break;
  1232. { start next objectfile }
  1233. NextSmartName(place);
  1234. end;
  1235. ObjData.free;
  1236. ObjData:=nil;
  1237. ObjWriter.free;
  1238. end;
  1239. procedure TInternalAssembler.MakeObject;
  1240. var to_do:set of TasmlistType;
  1241. i:TasmlistType;
  1242. {$ifdef MEMDEBUG}
  1243. d : tmemdebug;
  1244. {$endif}
  1245. procedure addlist(p:TAsmList);
  1246. begin
  1247. inc(lists);
  1248. list[lists]:=p;
  1249. end;
  1250. begin
  1251. to_do:=[low(Tasmlisttype)..high(Tasmlisttype)];
  1252. if usedeffileforexports then
  1253. exclude(to_do,al_exports);
  1254. if not(tf_section_threadvars in target_info.flags) then
  1255. exclude(to_do,al_threadvars);
  1256. for i:=low(TasmlistType) to high(TasmlistType) do
  1257. if (i in to_do) and (current_asmdata.asmlists[i]<>nil) then
  1258. addlist(current_asmdata.asmlists[i]);
  1259. if SmartAsm then
  1260. writetreesmart
  1261. else
  1262. writetree;
  1263. (*
  1264. if assigned(objectlibrary) then
  1265. begin
  1266. if objectlibrary<>current_module.librarydata then
  1267. internalerror(200603013);
  1268. {$ifdef MEMDEBUG}
  1269. d:=tmemdebug.create(modulename^+' - librarydata');
  1270. {$endif}
  1271. current_asmdata.free;
  1272. objectlibrary:=nil;
  1273. current_module.librarydata:=nil;
  1274. {$ifdef MEMDEBUG}
  1275. d.free;
  1276. {$endif}
  1277. end;
  1278. *)
  1279. end;
  1280. {*****************************************************************************
  1281. Generate Assembler Files Main Procedure
  1282. *****************************************************************************}
  1283. Procedure GenerateAsm(smart:boolean);
  1284. var
  1285. a : TAssembler;
  1286. begin
  1287. if not assigned(CAssembler[target_asm.id]) then
  1288. Message(asmw_f_assembler_output_not_supported);
  1289. a:=CAssembler[target_asm.id].Create(smart);
  1290. a.MakeObject;
  1291. a.Free;
  1292. end;
  1293. Procedure OnlyAsm;
  1294. var
  1295. a : TExternalAssembler;
  1296. begin
  1297. a:=TExternalAssembler.Create(false);
  1298. a.DoAssemble;
  1299. a.Free;
  1300. end;
  1301. {*****************************************************************************
  1302. Init/Done
  1303. *****************************************************************************}
  1304. procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
  1305. var
  1306. t : tasm;
  1307. begin
  1308. t:=r.id;
  1309. if assigned(asminfos[t]) then
  1310. writeln('Warning: Assembler is already registered!')
  1311. else
  1312. Getmem(asminfos[t],sizeof(tasminfo));
  1313. asminfos[t]^:=r;
  1314. CAssembler[t]:=c;
  1315. end;
  1316. procedure InitAssembler;
  1317. begin
  1318. end;
  1319. procedure DoneAssembler;
  1320. begin
  1321. end;
  1322. end.