assemble.pas 42 KB

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