assemble.pas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  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. dosub : boolean;
  594. begin
  595. result:=false;
  596. value:=0;
  597. relocsym:=nil;
  598. gotmin:=false;
  599. repeat
  600. dosub:=false;
  601. exprvalue:=0;
  602. if gotmin then
  603. begin
  604. dosub:=true;
  605. gotmin:=false;
  606. end;
  607. while (p^=' ') do
  608. inc(p);
  609. case p^ of
  610. #0 :
  611. break;
  612. ' ' :
  613. inc(p);
  614. '0'..'9' :
  615. begin
  616. len:=0;
  617. while (p^ in ['0'..'9']) do
  618. begin
  619. inc(len);
  620. hs[len]:=p^;
  621. inc(p);
  622. end;
  623. hs[0]:=chr(len);
  624. val(hs,exprvalue,code);
  625. if code<>0 then
  626. internalerror(200702251);
  627. end;
  628. '.','_',
  629. 'A'..'Z',
  630. 'a'..'z' :
  631. begin
  632. pstart:=p;
  633. while not(p^ in [#0,' ','-','+']) do
  634. inc(p);
  635. len:=p-pstart;
  636. if len>255 then
  637. internalerror(200509187);
  638. move(pstart^,hs[1],len);
  639. hs[0]:=chr(len);
  640. sym:=objdata.symbolref(hs);
  641. { Second symbol? }
  642. if assigned(relocsym) then
  643. begin
  644. if (relocsym.objsection<>sym.objsection) then
  645. internalerror(2005091810);
  646. relocsym:=nil;
  647. end
  648. else
  649. relocsym:=sym;
  650. exprvalue:=sym.address;
  651. end;
  652. '+' :
  653. begin
  654. { nothing, by default addition is done }
  655. inc(p);
  656. end;
  657. '-' :
  658. begin
  659. gotmin:=true;
  660. inc(p);
  661. end;
  662. else
  663. internalerror(200509189);
  664. end;
  665. if dosub then
  666. dec(value,exprvalue)
  667. else
  668. inc(value,exprvalue);
  669. until false;
  670. result:=true;
  671. end;
  672. const
  673. N_Function = $24; { function or const }
  674. var
  675. stabstrlen,
  676. ofs,
  677. nline,
  678. nidx,
  679. nother,
  680. i : longint;
  681. stab : TObjStabEntry;
  682. relocsym : TObjSymbol;
  683. pstr,
  684. pcurr,
  685. pendquote : pchar;
  686. oldsec : TObjSection;
  687. reltype : TObjRelocationType;
  688. begin
  689. pcurr:=nil;
  690. pstr:=nil;
  691. pendquote:=nil;
  692. { Parse string part }
  693. if (p[0]='"') then
  694. begin
  695. pstr:=@p[1];
  696. { Ignore \" inside the string }
  697. i:=1;
  698. while not((p[i]='"') and (p[i-1]<>'\')) and
  699. (p[i]<>#0) do
  700. inc(i);
  701. pendquote:=@p[i];
  702. pendquote^:=#0;
  703. pcurr:=@p[i+1];
  704. if not consumecomma(pcurr) then
  705. internalerror(200509181);
  706. end
  707. else
  708. pcurr:=p;
  709. { When in pass 1 then only alloc and leave }
  710. if ObjData.currpass=1 then
  711. begin
  712. ObjData.StabsSec.Alloc(sizeof(TObjStabEntry));
  713. if assigned(pstr) and (pstr[0]<>#0) then
  714. ObjData.StabStrSec.Alloc(strlen(pstr)+1);
  715. end
  716. else
  717. begin
  718. { Stabs format: nidx,nother,nline[,offset] }
  719. if not consumenumber(pcurr,nidx) then
  720. internalerror(200509182);
  721. if not consumecomma(pcurr) then
  722. internalerror(200509183);
  723. if not consumenumber(pcurr,nother) then
  724. internalerror(200509184);
  725. if not consumecomma(pcurr) then
  726. internalerror(200509185);
  727. if not consumenumber(pcurr,nline) then
  728. internalerror(200509186);
  729. if consumecomma(pcurr) then
  730. consumeoffset(pcurr,relocsym,ofs)
  731. else
  732. begin
  733. ofs:=0;
  734. relocsym:=nil;
  735. end;
  736. if assigned(relocsym) and
  737. (relocsym.bind<>AB_LOCAL) then
  738. ofs:=0;
  739. { Generate stab entry }
  740. if assigned(pstr) and (pstr[0]<>#0) then
  741. begin
  742. stabstrlen:=strlen(pstr);
  743. {$ifdef optimizestabs}
  744. StabStrEntry:=nil;
  745. if (nidx=N_SourceFile) or (nidx=N_IncludeFile) then
  746. begin
  747. hs:=strpas(pstr);
  748. StabstrEntry:=StabStrDict.Find(hs);
  749. if not assigned(StabstrEntry) then
  750. begin
  751. StabstrEntry:=TStabStrEntry.Create(hs);
  752. StabstrEntry:=StabStrSec.Size;
  753. StabStrDict.Insert(StabstrEntry);
  754. { generate new stab }
  755. StabstrEntry:=nil;
  756. end;
  757. end;
  758. if assigned(StabstrEntry) then
  759. stab.strpos:=StabstrEntry.strpos
  760. else
  761. {$endif optimizestabs}
  762. begin
  763. stab.strpos:=ObjData.StabStrSec.Size;
  764. ObjData.StabStrSec.write(pstr^,stabstrlen+1);
  765. end;
  766. end
  767. else
  768. stab.strpos:=0;
  769. stab.ntype:=byte(nidx);
  770. stab.ndesc:=word(nline);
  771. stab.nother:=byte(nother);
  772. stab.nvalue:=ofs;
  773. { Write the stab first without the value field. Then
  774. write a the value field with relocation }
  775. oldsec:=ObjData.CurrObjSec;
  776. ObjData.SetSection(ObjData.StabsSec);
  777. ObjData.Writebytes(stab,sizeof(TObjStabEntry)-4);
  778. if assigned(relocsym) and
  779. (target_info.system in system_windows+system_wince) and
  780. (DLLSource and RelocSection) then
  781. reltype:=RELOC_RVA
  782. else
  783. reltype:=RELOC_ABSOLUTE;
  784. ObjData.Writereloc(stab.nvalue,4,relocsym,reltype);
  785. ObjData.setsection(oldsec);
  786. end;
  787. if assigned(pendquote) then
  788. pendquote^:='"';
  789. end;
  790. function TInternalAssembler.MaybeNextList(var hp:Tai):boolean;
  791. begin
  792. { maybe end of list }
  793. while not assigned(hp) do
  794. begin
  795. if currlistidx<lists then
  796. begin
  797. inc(currlistidx);
  798. currlist:=list[currlistidx];
  799. hp:=Tai(currList.first);
  800. end
  801. else
  802. begin
  803. MaybeNextList:=false;
  804. exit;
  805. end;
  806. end;
  807. MaybeNextList:=true;
  808. end;
  809. function TInternalAssembler.TreePass0(hp:Tai):Tai;
  810. begin
  811. while assigned(hp) do
  812. begin
  813. case hp.typ of
  814. ait_align :
  815. begin
  816. { always use the maximum fillsize in this pass to avoid possible
  817. short jumps to become out of range }
  818. Tai_align_abstract(hp).fillsize:=Tai_align_abstract(hp).aligntype;
  819. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  820. end;
  821. ait_datablock :
  822. begin
  823. if Tai_datablock(hp).is_global then
  824. ObjData.SymbolDefine(Tai_datablock(hp).sym)
  825. else
  826. begin
  827. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  828. ObjData.SymbolDefine(Tai_datablock(hp).sym);
  829. ObjData.alloc(Tai_datablock(hp).size);
  830. end;
  831. end;
  832. ait_real_80bit :
  833. ObjData.alloc(10);
  834. ait_real_64bit :
  835. ObjData.alloc(8);
  836. ait_real_32bit :
  837. ObjData.alloc(4);
  838. ait_comp_64bit :
  839. ObjData.alloc(8);
  840. ait_const:
  841. ObjData.alloc(tai_const(hp).size);
  842. ait_section:
  843. begin
  844. ObjData.CreateSection(Tai_section(hp).sectype,Tai_section(hp).name^,Tai_section(hp).secorder);
  845. Tai_section(hp).sec:=ObjData.CurrObjSec;
  846. end;
  847. ait_symbol :
  848. ObjData.SymbolDefine(Tai_symbol(hp).sym);
  849. ait_label :
  850. ObjData.SymbolDefine(Tai_label(hp).labsym);
  851. ait_string :
  852. ObjData.alloc(Tai_string(hp).len);
  853. ait_instruction :
  854. begin
  855. { reset instructions which could change in pass 2 }
  856. Taicpu(hp).resetpass2;
  857. ObjData.alloc(Taicpu(hp).Pass1(ObjData));
  858. end;
  859. ait_cutobject :
  860. if SmartAsm then
  861. break;
  862. end;
  863. hp:=Tai(hp.next);
  864. end;
  865. TreePass0:=hp;
  866. end;
  867. function TInternalAssembler.TreePass1(hp:Tai):Tai;
  868. var
  869. InlineLevel : longint;
  870. objsym : TObjSymbol;
  871. begin
  872. inlinelevel:=0;
  873. while assigned(hp) do
  874. begin
  875. case hp.typ of
  876. ait_align :
  877. begin
  878. { here we must determine the fillsize which is used in pass2 }
  879. Tai_align_abstract(hp).fillsize:=align(ObjData.CurrObjSec.Size,Tai_align_abstract(hp).aligntype)-
  880. ObjData.CurrObjSec.Size;
  881. ObjData.alloc(Tai_align_abstract(hp).fillsize);
  882. end;
  883. ait_datablock :
  884. begin
  885. if (oso_data in ObjData.CurrObjSec.secoptions) then
  886. Message(asmw_e_alloc_data_only_in_bss);
  887. if Tai_datablock(hp).is_global then
  888. begin
  889. objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
  890. objsym.size:=Tai_datablock(hp).size;
  891. objsym.bind:=AB_COMMON;
  892. end
  893. else
  894. begin
  895. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  896. objsym:=ObjData.SymbolDefine(Tai_datablock(hp).sym);
  897. objsym.size:=Tai_datablock(hp).size;
  898. ObjData.alloc(Tai_datablock(hp).size);
  899. end;
  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. WriteStab(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. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_datablock(hp).sym));
  990. if not Tai_datablock(hp).is_global then
  991. begin
  992. ObjData.allocalign(used_align(size_2_align(Tai_datablock(hp).size),0,ObjData.CurrObjSec.secalign));
  993. ObjData.alloc(Tai_datablock(hp).size);
  994. end;
  995. end;
  996. ait_real_80bit :
  997. ObjData.writebytes(Tai_real_80bit(hp).value,10);
  998. ait_real_64bit :
  999. ObjData.writebytes(Tai_real_64bit(hp).value,8);
  1000. ait_real_32bit :
  1001. ObjData.writebytes(Tai_real_32bit(hp).value,4);
  1002. ait_comp_64bit :
  1003. begin
  1004. {$ifdef x86}
  1005. co:=comp(Tai_comp_64bit(hp).value);
  1006. ObjData.writebytes(co,8);
  1007. {$endif x86}
  1008. end;
  1009. ait_string :
  1010. ObjData.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
  1011. ait_const :
  1012. begin
  1013. case tai_const(hp).consttype of
  1014. aitconst_64bit,
  1015. aitconst_32bit,
  1016. aitconst_16bit,
  1017. aitconst_8bit :
  1018. begin
  1019. if assigned(tai_const(hp).sym) then
  1020. begin
  1021. objsym:=Objdata.SymbolRef(tai_const(hp).sym);
  1022. if assigned(tai_const(hp).endsym) then
  1023. begin
  1024. objsymend:=Objdata.SymbolRef(tai_const(hp).endsym);
  1025. if objsymend.objsection<>objsym.objsection then
  1026. internalerror(200404124);
  1027. v:=objsymend.address-objsym.address+Tai_const(hp).value;
  1028. ObjData.writebytes(v,tai_const(hp).size);
  1029. end
  1030. else
  1031. ObjData.writereloc(Tai_const(hp).value,Tai_const(hp).size,objsym,RELOC_ABSOLUTE);
  1032. end
  1033. else
  1034. ObjData.writebytes(Tai_const(hp).value,tai_const(hp).size);
  1035. end;
  1036. aitconst_rva_symbol :
  1037. { PE32+? }
  1038. if target_info.system=system_x86_64_win64 then
  1039. ObjData.writereloc(Tai_const(hp).value,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA)
  1040. else
  1041. ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA);
  1042. aitconst_uleb128bit :
  1043. begin
  1044. leblen:=EncodeUleb128(Tai_const(hp).value,lebbuf);
  1045. ObjData.writebytes(lebbuf,leblen);
  1046. end;
  1047. aitconst_sleb128bit :
  1048. begin
  1049. leblen:=EncodeSleb128(Tai_const(hp).value,lebbuf);
  1050. ObjData.writebytes(lebbuf,leblen);
  1051. end;
  1052. else
  1053. internalerror(200603254);
  1054. end;
  1055. end;
  1056. ait_label :
  1057. begin
  1058. { exporting shouldn't be necessary as labels are local,
  1059. but it's better to be on the safe side (PFV) }
  1060. ObjOutput.exportsymbol(ObjData.SymbolRef(Tai_label(hp).labsym));
  1061. end;
  1062. ait_instruction :
  1063. Taicpu(hp).Pass2(ObjData);
  1064. ait_stab :
  1065. WriteStab(Tai_stab(hp).str);
  1066. ait_function_name,
  1067. ait_force_line : ;
  1068. ait_cutobject :
  1069. if SmartAsm then
  1070. break;
  1071. ait_marker :
  1072. if tai_marker(hp).kind=mark_InlineStart then
  1073. inc(InlineLevel)
  1074. else if tai_marker(hp).kind=mark_InlineEnd then
  1075. dec(InlineLevel);
  1076. end;
  1077. hp:=Tai(hp.next);
  1078. end;
  1079. TreePass2:=hp;
  1080. end;
  1081. procedure TInternalAssembler.writetree;
  1082. label
  1083. doexit;
  1084. var
  1085. hp : Tai;
  1086. ObjWriter : TObjectWriter;
  1087. begin
  1088. ObjWriter:=TObjectwriter.create;
  1089. ObjOutput:=CObjOutput.Create(ObjWriter);
  1090. ObjData:=ObjOutput.newObjData(ObjFileName);
  1091. { Pass 0 }
  1092. ObjData.currpass:=0;
  1093. ObjData.createsection(sec_code);
  1094. ObjData.beforealloc;
  1095. { start with list 1 }
  1096. currlistidx:=1;
  1097. currlist:=list[currlistidx];
  1098. hp:=Tai(currList.first);
  1099. while assigned(hp) do
  1100. begin
  1101. hp:=TreePass0(hp);
  1102. MaybeNextList(hp);
  1103. end;
  1104. ObjData.afteralloc;
  1105. { leave if errors have occured }
  1106. if errorcount>0 then
  1107. goto doexit;
  1108. { Pass 1 }
  1109. ObjData.currpass:=1;
  1110. ObjData.resetsections;
  1111. ObjData.beforealloc;
  1112. ObjData.createsection(sec_code);
  1113. { start with list 1 }
  1114. currlistidx:=1;
  1115. currlist:=list[currlistidx];
  1116. hp:=Tai(currList.first);
  1117. while assigned(hp) do
  1118. begin
  1119. hp:=TreePass1(hp);
  1120. MaybeNextList(hp);
  1121. end;
  1122. ObjData.createsection(sec_code);
  1123. ObjData.afteralloc;
  1124. { leave if errors have occured }
  1125. if errorcount>0 then
  1126. goto doexit;
  1127. { Pass 2 }
  1128. ObjData.currpass:=2;
  1129. ObjData.resetsections;
  1130. ObjData.beforewrite;
  1131. ObjData.createsection(sec_code);
  1132. { start with list 1 }
  1133. currlistidx:=1;
  1134. currlist:=list[currlistidx];
  1135. hp:=Tai(currList.first);
  1136. while assigned(hp) do
  1137. begin
  1138. hp:=TreePass2(hp);
  1139. MaybeNextList(hp);
  1140. end;
  1141. ObjData.createsection(sec_code);
  1142. ObjData.afterwrite;
  1143. { don't write the .o file if errors have occured }
  1144. if errorcount=0 then
  1145. begin
  1146. { write objectfile }
  1147. ObjOutput.startobjectfile(ObjFileName);
  1148. ObjOutput.writeobjectfile(ObjData);
  1149. end;
  1150. doexit:
  1151. { Cleanup }
  1152. ObjData.free;
  1153. ObjData:=nil;
  1154. ObjWriter.free;
  1155. end;
  1156. procedure TInternalAssembler.writetreesmart;
  1157. var
  1158. hp : Tai;
  1159. startsectype : TAsmSectiontype;
  1160. place: tcutplace;
  1161. ObjWriter : TObjectWriter;
  1162. begin
  1163. if not(cs_asm_leave in current_settings.globalswitches) then
  1164. ObjWriter:=TARObjectWriter.create(current_module.staticlibfilename^)
  1165. else
  1166. ObjWriter:=TObjectwriter.create;
  1167. NextSmartName(cut_normal);
  1168. ObjOutput:=CObjOutput.Create(ObjWriter);
  1169. startsectype:=sec_code;
  1170. { start with list 1 }
  1171. currlistidx:=1;
  1172. currlist:=list[currlistidx];
  1173. hp:=Tai(currList.first);
  1174. while assigned(hp) do
  1175. begin
  1176. ObjData:=ObjOutput.newObjData(ObjFileName);
  1177. { Pass 0 }
  1178. ObjData.currpass:=0;
  1179. ObjData.resetsections;
  1180. ObjData.beforealloc;
  1181. ObjData.createsection(startsectype);
  1182. TreePass0(hp);
  1183. ObjData.afteralloc;
  1184. { leave if errors have occured }
  1185. if errorcount>0 then
  1186. break;
  1187. { Pass 1 }
  1188. ObjData.currpass:=1;
  1189. ObjData.resetsections;
  1190. ObjData.beforealloc;
  1191. ObjData.createsection(startsectype);
  1192. TreePass1(hp);
  1193. ObjData.afteralloc;
  1194. { leave if errors have occured }
  1195. if errorcount>0 then
  1196. break;
  1197. { Pass 2 }
  1198. ObjData.currpass:=2;
  1199. ObjOutput.startobjectfile(ObjFileName);
  1200. ObjData.resetsections;
  1201. ObjData.beforewrite;
  1202. ObjData.createsection(startsectype);
  1203. hp:=TreePass2(hp);
  1204. ObjData.afterwrite;
  1205. { leave if errors have occured }
  1206. if errorcount>0 then
  1207. break;
  1208. { write the current objectfile }
  1209. ObjOutput.writeobjectfile(ObjData);
  1210. ObjData.free;
  1211. ObjData:=nil;
  1212. { end of lists? }
  1213. if not MaybeNextList(hp) then
  1214. break;
  1215. { we will start a new objectfile so reset everything }
  1216. { The place can still change in the next while loop, so don't init }
  1217. { the writer yet (JM) }
  1218. if (hp.typ=ait_cutobject) then
  1219. place := Tai_cutobject(hp).place
  1220. else
  1221. place := cut_normal;
  1222. { avoid empty files }
  1223. startsectype:=sec_code;
  1224. while assigned(hp) and
  1225. (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cutobject]) do
  1226. begin
  1227. if Tai(hp).typ=ait_section then
  1228. startsectype:=Tai_section(hp).sectype;
  1229. if (Tai(hp).typ=ait_cutobject) then
  1230. place:=Tai_cutobject(hp).place;
  1231. hp:=Tai(hp.next);
  1232. end;
  1233. if not MaybeNextList(hp) then
  1234. break;
  1235. { start next objectfile }
  1236. NextSmartName(place);
  1237. end;
  1238. ObjData.free;
  1239. ObjData:=nil;
  1240. ObjWriter.free;
  1241. end;
  1242. procedure TInternalAssembler.MakeObject;
  1243. var to_do:set of TasmlistType;
  1244. i:TasmlistType;
  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. end;
  1264. {*****************************************************************************
  1265. Generate Assembler Files Main Procedure
  1266. *****************************************************************************}
  1267. Procedure GenerateAsm(smart:boolean);
  1268. var
  1269. a : TAssembler;
  1270. begin
  1271. if not assigned(CAssembler[target_asm.id]) then
  1272. Message(asmw_f_assembler_output_not_supported);
  1273. a:=CAssembler[target_asm.id].Create(smart);
  1274. a.MakeObject;
  1275. a.Free;
  1276. end;
  1277. Procedure OnlyAsm;
  1278. var
  1279. a : TExternalAssembler;
  1280. begin
  1281. a:=TExternalAssembler.Create(false);
  1282. a.DoAssemble;
  1283. a.Free;
  1284. end;
  1285. {*****************************************************************************
  1286. Init/Done
  1287. *****************************************************************************}
  1288. procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
  1289. var
  1290. t : tasm;
  1291. begin
  1292. t:=r.id;
  1293. if assigned(asminfos[t]) then
  1294. writeln('Warning: Assembler is already registered!')
  1295. else
  1296. Getmem(asminfos[t],sizeof(tasminfo));
  1297. asminfos[t]^:=r;
  1298. CAssembler[t]:=c;
  1299. end;
  1300. procedure InitAssembler;
  1301. begin
  1302. end;
  1303. procedure DoneAssembler;
  1304. begin
  1305. end;
  1306. end.