assemble.pas 45 KB

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