123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785 |
- {
- $Id$
- Copyright (c) 1998-2002 by Peter Vreman
- This unit handles the assemblerfile write and assembler calls of FPC
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- {# @abstract(This unit handles the assembler file write and assembler calls of FPC)
- Handles the calls to the actual external assemblers, as well as the generation
- of object files for smart linking. Also contains the base class for writing
- the assembler statements to file.
- }
- unit assemble;
- {$i fpcdefs.inc}
- interface
- uses
- {$ifdef Delphi}
- sysutils,
- dmisc,
- {$else Delphi}
- strings,
- dos,
- {$endif Delphi}
- systems,globtype,globals,aasmbase,aasmtai,ogbase;
- const
- { maximum of aasmoutput lists there will be }
- maxoutputlists = 10;
- { buffer size for writing the .s file }
- AsmOutSize=32768;
- type
- TAssembler=class(TAbstractAssembler)
- public
- {filenames}
- path : pathstr;
- name : namestr;
- asmfile, { current .s and .o file }
- objfile : string;
- ppufilename : string;
- asmprefix : string;
- SmartAsm : boolean;
- SmartFilesCount,
- SmartHeaderCount : longint;
- Constructor Create(smart:boolean);virtual;
- Destructor Destroy;override;
- procedure NextSmartName(place:tcutplace);
- procedure MakeObject;virtual;abstract;
- end;
- {# This is the base class which should be overriden for each each
- assembler writer. It is used to actually assembler a file,
- and write the output to the assembler file.
- }
- TExternalAssembler=class(TAssembler)
- private
- procedure CreateSmartLinkPath(const s:string);
- protected
- {outfile}
- AsmSize,
- AsmStartSize,
- outcnt : longint;
- outbuf : array[0..AsmOutSize-1] of char;
- outfile : file;
- public
- {# Returns the complete path and executable name of the assembler
- program.
- It first tries looking in the UTIL directory if specified,
- otherwise it searches in the free pascal binary directory, in
- the current working directory and then in the directories
- in the $PATH environment.}
- Function FindAssembler:string;
- {# Actually does the call to the assembler file. Returns false
- if the assembling of the file failed.}
- Function CallAssembler(const command,para:string):Boolean;
- Function DoAssemble:boolean;virtual;
- Procedure RemoveAsm;
- Procedure AsmFlush;
- Procedure AsmClear;
- {# Write a string to the assembler file }
- Procedure AsmWrite(const s:string);
- {# Write a string to the assembler file }
- Procedure AsmWritePChar(p:pchar);
- {# Write a string to the assembler file followed by a new line }
- Procedure AsmWriteLn(const s:string);
- {# Write a new line to the assembler file }
- Procedure AsmLn;
- procedure AsmCreate(Aplace:tcutplace);
- procedure AsmClose;
- {# This routine should be overriden for each assembler, it is used
- to actually write the abstract assembler stream to file.}
- procedure WriteTree(p:TAAsmoutput);virtual;
- {# This routine should be overriden for each assembler, it is used
- to actually write all the different abstract assembler streams
- by calling for each stream type, the @var(WriteTree) method.}
- procedure WriteAsmList;virtual;
- public
- Constructor Create(smart:boolean);override;
- procedure MakeObject;override;
- end;
- TInternalAssembler=class(TAssembler)
- public
- constructor create(smart:boolean);override;
- destructor destroy;override;
- procedure MakeObject;override;
- protected
- { object alloc and output }
- objectalloc : TAsmObjectAlloc;
- objectdata : TAsmObjectData;
- objectoutput : tobjectoutput;
- private
- { the aasmoutput lists that need to be processed }
- lists : byte;
- list : array[1..maxoutputlists] of TAAsmoutput;
- { current processing }
- currlistidx : byte;
- currlist : TAAsmoutput;
- currpass : byte;
- {$ifdef GDB}
- n_line : byte; { different types of source lines }
- linecount,
- includecount : longint;
- funcname : tasmsymbol;
- stabslastfileinfo : tfileposinfo;
- procedure convertstabs(p:pchar);
- procedure emitlineinfostabs(nidx,line : longint);
- procedure emitstabs(s:string);
- procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
- procedure StartFileLineInfo;
- procedure EndFileLineInfo;
- {$endif}
- function MaybeNextList(var hp:Tai):boolean;
- function TreePass0(hp:Tai):Tai;
- function TreePass1(hp:Tai):Tai;
- function TreePass2(hp:Tai):Tai;
- procedure writetree;
- procedure writetreesmart;
- end;
- TAssemblerClass = class of TAssembler;
- Procedure GenerateAsm(smart:boolean);
- Procedure OnlyAsm;
- procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
- procedure InitAssembler;
- procedure DoneAssembler;
- Implementation
- uses
- {$ifdef hasunix}
- {$ifdef ver1_0}
- linux,
- {$else}
- unix,
- {$endif}
- {$endif}
- cutils,script,fmodule,verbose,
- {$ifdef memdebug}
- cclasses,
- {$endif memdebug}
- {$ifdef GDB}
- finput,
- gdb,
- {$endif GDB}
- {$ifdef m68k}
- cpuinfo,
- {$endif m68k}
- cpubase,aasmcpu
- ;
- var
- CAssembler : array[tasm] of TAssemblerClass;
- {*****************************************************************************
- TAssembler
- *****************************************************************************}
- Constructor TAssembler.Create(smart:boolean);
- begin
- { load start values }
- asmfile:=current_module.get_asmfilename;
- objfile:=current_module.objfilename^;
- name:=Lower(current_module.modulename^);
- path:=current_module.outputpath^;
- asmprefix := current_module.asmprefix^;
- if not assigned(current_module.outputpath) then
- ppufilename := ''
- else
- ppufilename := current_module.ppufilename^;
- SmartAsm:=smart;
- SmartFilesCount:=0;
- SmartHeaderCount:=0;
- SmartLinkOFiles.Clear;
- end;
- Destructor TAssembler.Destroy;
- begin
- end;
- procedure TAssembler.NextSmartName(place:tcutplace);
- var
- s : string;
- begin
- inc(SmartFilesCount);
- if SmartFilesCount>999999 then
- Message(asmw_f_too_many_asm_files);
- case place of
- cut_begin :
- begin
- inc(SmartHeaderCount);
- s:=asmprefix+tostr(SmartHeaderCount)+'h';
- end;
- cut_normal :
- s:=asmprefix+tostr(SmartHeaderCount)+'s';
- cut_end :
- s:=asmprefix+tostr(SmartHeaderCount)+'t';
- end;
- AsmFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.asmext);
- ObjFile:=Path+FixFileName(s+tostr(SmartFilesCount)+target_info.objext);
- { insert in container so it can be cleared after the linking }
- SmartLinkOFiles.Insert(Objfile);
- end;
- {*****************************************************************************
- TExternalAssembler
- *****************************************************************************}
- Function DoPipe:boolean;
- begin
- DoPipe:=(cs_asm_pipe in aktglobalswitches) and
- not(cs_asm_leave in aktglobalswitches)
- and ((aktoutputformat=as_gas));
- end;
- Constructor TExternalAssembler.Create(smart:boolean);
- begin
- inherited Create(smart);
- if SmartAsm then
- begin
- path:=FixPath(path+FixFileName(name)+target_info.smartext,false);
- CreateSmartLinkPath(path);
- end;
- Outcnt:=0;
- end;
- procedure TExternalAssembler.CreateSmartLinkPath(const s:string);
- var
- dir : searchrec;
- hs : string;
- begin
- if PathExists(s) then
- begin
- { the path exists, now we clean only all the .o and .s files }
- { .o files }
- findfirst(s+source_info.dirsep+'*'+target_info.objext,anyfile,dir);
- while (doserror=0) do
- begin
- RemoveFile(s+source_info.dirsep+dir.name);
- findnext(dir);
- end;
- findclose(dir);
- { .s files }
- findfirst(s+source_info.dirsep+'*'+target_info.asmext,anyfile,dir);
- while (doserror=0) do
- begin
- RemoveFile(s+source_info.dirsep+dir.name);
- findnext(dir);
- end;
- findclose(dir);
- end
- else
- begin
- hs:=s;
- if hs[length(hs)] in ['/','\'] then
- delete(hs,length(hs),1);
- {$I-}
- mkdir(hs);
- {$I+}
- if ioresult<>0 then;
- end;
- end;
- const
- lastas : byte=255;
- var
- LastASBin : pathstr;
- Function TExternalAssembler.FindAssembler:string;
- var
- asfound : boolean;
- UtilExe : string;
- begin
- asfound:=false;
- if cs_link_on_target in aktglobalswitches then
- begin
- { If linking on target, don't add any path PM }
- FindAssembler:=utilsprefix+AddExtension(target_asm.asmbin,target_info.exeext);
- exit;
- end
- else
- UtilExe:=utilsprefix+AddExtension(target_asm.asmbin,source_info.exeext);
- if lastas<>ord(target_asm.id) then
- begin
- lastas:=ord(target_asm.id);
- { is an assembler passed ? }
- if utilsdirectory<>'' then
- asfound:=FindFile(UtilExe,utilsdirectory,LastASBin);
- if not AsFound then
- asfound:=FindExe(UtilExe,LastASBin);
- if (not asfound) and not(cs_asm_extern in aktglobalswitches) then
- begin
- Message1(exec_e_assembler_not_found,LastASBin);
- aktglobalswitches:=aktglobalswitches+[cs_asm_extern];
- end;
- if asfound then
- Message1(exec_t_using_assembler,LastASBin);
- end;
- FindAssembler:=LastASBin;
- end;
- Function TExternalAssembler.CallAssembler(const command,para:string):Boolean;
- begin
- callassembler:=true;
- if not(cs_asm_extern in aktglobalswitches) then
- begin
- swapvectors;
- exec(command,para);
- swapvectors;
- if (doserror<>0) then
- begin
- Message1(exec_e_cant_call_assembler,tostr(doserror));
- aktglobalswitches:=aktglobalswitches+[cs_asm_extern];
- callassembler:=false;
- end
- else
- if (dosexitcode<>0) then
- begin
- Message1(exec_e_error_while_assembling,tostr(dosexitcode));
- callassembler:=false;
- end;
- end
- else
- AsmRes.AddAsmCommand(command,para,name);
- end;
- procedure TExternalAssembler.RemoveAsm;
- var
- g : file;
- begin
- if cs_asm_leave in aktglobalswitches then
- exit;
- if cs_asm_extern in aktglobalswitches then
- AsmRes.AddDeleteCommand(AsmFile)
- else
- begin
- assign(g,AsmFile);
- {$I-}
- erase(g);
- {$I+}
- if ioresult<>0 then;
- end;
- end;
- Function TExternalAssembler.DoAssemble:boolean;
- var
- s : string;
- begin
- DoAssemble:=true;
- if DoPipe then
- exit;
- if not(cs_asm_extern in aktglobalswitches) then
- begin
- if SmartAsm then
- begin
- if (SmartFilesCount<=1) then
- Message1(exec_i_assembling_smart,name);
- end
- else
- Message1(exec_i_assembling,name);
- end;
- s:=target_asm.asmcmd;
- {$ifdef m68k}
- if aktoptprocessor = MC68020 then
- s:='-m68020 '+s
- else
- s:='-m68000 '+s;
- {$endif}
- if (cs_link_on_target in aktglobalswitches) then
- begin
- Replace(s,'$ASM',ScriptFixFileName(AsmFile));
- Replace(s,'$OBJ',ScriptFixFileName(ObjFile));
- end
- else
- begin
- Replace(s,'$ASM',AsmFile);
- Replace(s,'$OBJ',ObjFile);
- end;
- if CallAssembler(FindAssembler,s) then
- RemoveAsm
- else
- begin
- DoAssemble:=false;
- GenerateError;
- end;
- end;
- Procedure TExternalAssembler.AsmFlush;
- begin
- if outcnt>0 then
- begin
- BlockWrite(outfile,outbuf,outcnt);
- outcnt:=0;
- end;
- end;
- Procedure TExternalAssembler.AsmClear;
- begin
- outcnt:=0;
- end;
- Procedure TExternalAssembler.AsmWrite(const s:string);
- begin
- if OutCnt+length(s)>=AsmOutSize then
- AsmFlush;
- Move(s[1],OutBuf[OutCnt],length(s));
- inc(OutCnt,length(s));
- inc(AsmSize,length(s));
- end;
- Procedure TExternalAssembler.AsmWriteLn(const s:string);
- begin
- AsmWrite(s);
- AsmLn;
- end;
- Procedure TExternalAssembler.AsmWritePChar(p:pchar);
- var
- i,j : longint;
- begin
- i:=StrLen(p);
- j:=i;
- while j>0 do
- begin
- i:=min(j,AsmOutSize);
- if OutCnt+i>=AsmOutSize then
- AsmFlush;
- Move(p[0],OutBuf[OutCnt],i);
- inc(OutCnt,i);
- inc(AsmSize,i);
- dec(j,i);
- p:=pchar(@p[i]);
- end;
- end;
- Procedure TExternalAssembler.AsmLn;
- begin
- if OutCnt>=AsmOutSize-2 then
- AsmFlush;
- if (cs_link_on_target in aktglobalswitches) then
- begin
- OutBuf[OutCnt]:=target_info.newline[1];
- inc(OutCnt);
- inc(AsmSize);
- if length(target_info.newline)>1 then
- begin
- OutBuf[OutCnt]:=target_info.newline[2];
- inc(OutCnt);
- inc(AsmSize);
- end;
- end
- else
- begin
- OutBuf[OutCnt]:=source_info.newline[1];
- inc(OutCnt);
- inc(AsmSize);
- if length(source_info.newline)>1 then
- begin
- OutBuf[OutCnt]:=source_info.newline[2];
- inc(OutCnt);
- inc(AsmSize);
- end;
- end;
- end;
- procedure TExternalAssembler.AsmCreate(Aplace:tcutplace);
- begin
- if SmartAsm then
- NextSmartName(Aplace);
- {$ifdef hasunix}
- if DoPipe then
- begin
- Message1(exec_i_assembling_pipe,asmfile);
- POpen(outfile,'as -o '+objfile,'W');
- end
- else
- {$endif}
- begin
- Assign(outfile,asmfile);
- {$I-}
- Rewrite(outfile,1);
- {$I+}
- if ioresult<>0 then
- Message1(exec_d_cant_create_asmfile,asmfile);
- end;
- outcnt:=0;
- AsmSize:=0;
- AsmStartSize:=0;
- end;
- procedure TExternalAssembler.AsmClose;
- var
- f : file;
- l : longint;
- begin
- AsmFlush;
- {$ifdef hasunix}
- if DoPipe then
- PClose(outfile)
- else
- {$endif}
- begin
- {Touch Assembler time to ppu time is there is a ppufilename}
- if ppufilename<>'' then
- begin
- Assign(f,ppufilename);
- {$I-}
- reset(f,1);
- {$I+}
- if ioresult=0 then
- begin
- getftime(f,l);
- close(f);
- reset(outfile,1);
- setftime(outfile,l);
- end;
- end;
- close(outfile);
- end;
- end;
- procedure TExternalAssembler.WriteTree(p:TAAsmoutput);
- begin
- end;
- procedure TExternalAssembler.WriteAsmList;
- begin
- end;
- procedure TExternalAssembler.MakeObject;
- begin
- AsmCreate(cut_normal);
- WriteAsmList;
- AsmClose;
- DoAssemble;
- end;
- {*****************************************************************************
- TInternalAssembler
- *****************************************************************************}
- constructor TInternalAssembler.create(smart:boolean);
- begin
- inherited create(smart);
- objectoutput:=nil;
- objectdata:=nil;
- objectalloc:=TAsmObjectAlloc.create;
- SmartAsm:=smart;
- currpass:=0;
- end;
- destructor TInternalAssembler.destroy;
- {$ifdef MEMDEBUG}
- var
- d : tmemdebug;
- {$endif}
- begin
- {$ifdef MEMDEBUG}
- d := tmemdebug.create(name+' - agbin');
- {$endif}
- objectdata.free;
- objectoutput.free;
- objectalloc.free;
- {$ifdef MEMDEBUG}
- d.free;
- {$endif}
- end;
- {$ifdef GDB}
- procedure TInternalAssembler.convertstabs(p:pchar);
- var
- ofs,
- nidx,nother,ii,i,line,j : longint;
- code : integer;
- hp : pchar;
- reloc : boolean;
- sec : TSection;
- ps : tasmsymbol;
- s : string;
- begin
- ofs:=0;
- reloc:=true;
- ps:=nil;
- sec:=sec_none;
- if p[0]='"' then
- begin
- i:=1;
- { we can have \" inside the string !! PM }
- while not ((p[i]='"') and (p[i-1]<>'\')) do
- inc(i);
- p[i]:=#0;
- ii:=i;
- hp:=@p[1];
- s:=StrPas(@P[i+2]);
- end
- else
- begin
- hp:=nil;
- s:=StrPas(P);
- i:=-2; {needed below (PM) }
- end;
- { When in pass 1 then only alloc and leave }
- if currpass=1 then
- begin
- objectalloc.staballoc(hp);
- if assigned(hp) then
- p[i]:='"';
- exit;
- end;
- { Parse the rest of the stabs }
- if s='' then
- internalerror(33000);
- j:=pos(',',s);
- if j=0 then
- internalerror(33001);
- Val(Copy(s,1,j-1),nidx,code);
- if code<>0 then
- internalerror(33002);
- i:=i+2+j;
- Delete(s,1,j);
- j:=pos(',',s);
- if (j=0) then
- internalerror(33003);
- Val(Copy(s,1,j-1),nother,code);
- if code<>0 then
- internalerror(33004);
- i:=i+j;
- Delete(s,1,j);
- j:=pos(',',s);
- if j=0 then
- begin
- j:=256;
- ofs:=-1;
- end;
- Val(Copy(s,1,j-1),line,code);
- if code<>0 then
- internalerror(33005);
- if ofs=0 then
- begin
- Delete(s,1,j);
- i:=i+j;
- Val(s,ofs,code);
- if code=0 then
- reloc:=false
- else
- begin
- ofs:=0;
- s:=strpas(@p[i]);
- { handle asmsymbol or
- asmsymbol - asmsymbol }
- j:=pos(' ',s);
- if j=0 then
- j:=pos('-',s);
- { also try to handle
- asmsymbol + constant
- or
- asmsymbol - constant }
- if j=0 then
- j:=pos('+',s);
- if j<>0 then
- begin
- Val(Copy(s,j+1,255),ofs,code);
- if code<>0 then
- ofs:=0
- else
- { constant reading successful,
- avoid further treatment by
- setting s[j] to '+' }
- s[j]:='+';
- end
- else
- { single asmsymbol }
- j:=256;
- { the symbol can be external
- so we must use newasmsymbol and
- not getasmsymbol !! PM }
- ps:=objectlibrary.newasmsymbol(copy(s,1,j-1));
- if not assigned(ps) then
- internalerror(33006)
- else
- begin
- sec:=ps.section;
- ofs:=ofs+ps.address;
- reloc:=true;
- objectlibrary.UsedAsmSymbolListInsert(ps);
- end;
- if (j<256) and (s[j]<>'+') then
- begin
- i:=i+j;
- s:=strpas(@p[i]);
- if (s<>'') and (s[1]=' ') then
- begin
- j:=0;
- while (s[j+1]=' ') do
- inc(j);
- i:=i+j;
- s:=strpas(@p[i]);
- end;
- ps:=objectlibrary.getasmsymbol(s);
- if not assigned(ps) then
- internalerror(33007)
- else
- begin
- if ps.section<>sec then
- internalerror(33008);
- ofs:=ofs-ps.address;
- reloc:=false;
- objectlibrary.UsedAsmSymbolListInsert(ps);
- end;
- end;
- end;
- end;
- { external bss need speical handling (PM) }
- if assigned(ps) and (ps.section=sec_none) then
- begin
- if currpass=2 then
- begin
- objectdata.writesymbol(ps);
- objectoutput.exportsymbol(ps);
- end;
- objectdata.writeSymStabs(sec,ofs,hp,ps,nidx,nother,line,reloc)
- end
- else
- objectdata.writeStabs(sec,ofs,hp,nidx,nother,line,reloc);
- if assigned(hp) then
- p[ii]:='"';
- end;
- procedure TInternalAssembler.emitlineinfostabs(nidx,line : longint);
- var
- sec : TSection;
- begin
- if currpass=1 then
- begin
- objectalloc.staballoc(nil);
- exit;
- end;
- if (nidx=n_textline) and assigned(funcname) and
- (target_info.use_function_relative_addresses) then
- objectdata.writeStabs(sec_code,objectdata.sectionsize(sec_code)-funcname.address,
- nil,nidx,0,line,false)
- else
- begin
- if nidx=n_textline then
- sec:=sec_code
- else if nidx=n_dataline then
- sec:=sec_data
- else
- sec:=sec_bss;
- objectdata.writeStabs(sec,objectdata.sectionsize(sec),
- nil,nidx,0,line,true);
- end;
- end;
- procedure TInternalAssembler.emitstabs(s:string);
- begin
- s:=s+#0;
- ConvertStabs(@s[1]);
- end;
- procedure TInternalAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
- var
- curr_n : byte;
- hp : tasmsymbol;
- infile : tinputfile;
- begin
- if not ((cs_debuginfo in aktmoduleswitches) or
- (cs_gdb_lineinfo in aktglobalswitches)) then
- exit;
- { file changed ? (must be before line info) }
- if (fileinfo.fileindex<>0) and
- (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
- begin
- infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
- if assigned(infile) then
- begin
- if includecount=0 then
- curr_n:=n_sourcefile
- else
- curr_n:=n_includefile;
- { get symbol for this includefile }
- hp:=objectlibrary.newasmsymboltype('Ltext'+ToStr(IncludeCount),AB_LOCAL,AT_FUNCTION);
- if currpass=1 then
- begin
- hp.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- objectlibrary.UsedAsmSymbolListInsert(hp);
- end
- else
- objectdata.writesymbol(hp);
- { emit stabs }
- if (infile.path^<>'') then
- EmitStabs('"'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+tostr(curr_n)+
- ',0,0,Ltext'+ToStr(IncludeCount));
- EmitStabs('"'+lower(FixFileName(infile.name^))+'",'+tostr(curr_n)+
- ',0,0,Ltext'+ToStr(IncludeCount));
- inc(includecount);
- { force new line info }
- stabslastfileinfo.line:=-1;
- end;
- end;
- { line changed ? }
- if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
- emitlineinfostabs(n_line,fileinfo.line);
- stabslastfileinfo:=fileinfo;
- end;
- procedure TInternalAssembler.StartFileLineInfo;
- var
- fileinfo : tfileposinfo;
- begin
- FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
- n_line:=n_textline;
- funcname:=nil;
- linecount:=1;
- includecount:=0;
- fileinfo.fileindex:=1;
- fileinfo.line:=1;
- WriteFileLineInfo(fileinfo);
- end;
- procedure TInternalAssembler.EndFileLineInfo;
- var
- hp : tasmsymbol;
- store_sec : TSection;
- begin
- if not ((cs_debuginfo in aktmoduleswitches) or
- (cs_gdb_lineinfo in aktglobalswitches)) then
- exit;
- store_sec:=objectalloc.currsec;
- objectalloc.seTSection(sec_code);
- hp:=objectlibrary.newasmsymboltype('Letext',AB_LOCAL,AT_FUNCTION);
- if currpass=1 then
- begin
- hp.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- objectlibrary.UsedAsmSymbolListInsert(hp);
- end
- else
- objectdata.writesymbol(hp);
- EmitStabs('"",'+tostr(n_sourcefile)+',0,0,Letext');
- objectalloc.seTSection(store_sec);
- end;
- {$endif GDB}
- function TInternalAssembler.MaybeNextList(var hp:Tai):boolean;
- begin
- { maybe end of list }
- while not assigned(hp) do
- begin
- if currlistidx<lists then
- begin
- inc(currlistidx);
- currlist:=list[currlistidx];
- hp:=Tai(currList.first);
- end
- else
- begin
- MaybeNextList:=false;
- exit;
- end;
- end;
- MaybeNextList:=true;
- end;
- function TInternalAssembler.TreePass0(hp:Tai):Tai;
- var
- l : longint;
- begin
- while assigned(hp) do
- begin
- case hp.typ of
- ait_align :
- begin
- { always use the maximum fillsize in this pass to avoid possible
- short jumps to become out of range }
- Tai_align(hp).fillsize:=Tai_align(hp).aligntype;
- objectalloc.sectionalloc(Tai_align(hp).fillsize);
- end;
- ait_datablock :
- begin
- if not SmartAsm then
- begin
- if not Tai_datablock(hp).is_global then
- begin
- l:=Tai_datablock(hp).size;
- if l>2 then
- objectalloc.sectionalign(4)
- else if l>1 then
- objectalloc.sectionalign(2);
- objectalloc.sectionalloc(Tai_datablock(hp).size);
- end;
- end
- else
- begin
- l:=Tai_datablock(hp).size;
- if l>2 then
- objectalloc.sectionalign(4)
- else if l>1 then
- objectalloc.sectionalign(2);
- objectalloc.sectionalloc(Tai_datablock(hp).size);
- end;
- end;
- ait_const_32bit :
- objectalloc.sectionalloc(4);
- ait_const_16bit :
- objectalloc.sectionalloc(2);
- ait_const_8bit :
- objectalloc.sectionalloc(1);
- ait_real_80bit :
- objectalloc.sectionalloc(10);
- ait_real_64bit :
- objectalloc.sectionalloc(8);
- ait_real_32bit :
- objectalloc.sectionalloc(4);
- ait_comp_64bit :
- objectalloc.sectionalloc(8);
- ait_const_rva,
- ait_const_symbol :
- objectalloc.sectionalloc(4);
- ait_section:
- objectalloc.seTSection(Tai_section(hp).sec);
- ait_symbol :
- Tai_symbol(hp).sym.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- ait_label :
- Tai_label(hp).l.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- ait_string :
- objectalloc.sectionalloc(Tai_string(hp).len);
- ait_instruction :
- begin
- {$ifdef i386}
- {$ifndef NOAG386BIN}
- { reset instructions which could change in pass 2 }
- Taicpu(hp).resetpass2;
- objectalloc.sectionalloc(Taicpu(hp).Pass1(objectalloc.sectionsize));
- {$endif NOAG386BIN}
- {$endif i386}
- end;
- ait_cut :
- if SmartAsm then
- break;
- end;
- hp:=Tai(hp.next);
- end;
- TreePass0:=hp;
- end;
- function TInternalAssembler.TreePass1(hp:Tai):Tai;
- var
- InlineLevel,
- l : longint;
- {$ifdef i386}
- {$ifndef NOAG386BIN}
- i : longint;
- {$endif NOAG386BIN}
- {$endif i386}
- begin
- inlinelevel:=0;
- while assigned(hp) do
- begin
- {$ifdef GDB}
- { write stabs, no line info for inlined code }
- if (inlinelevel=0) and
- ((cs_debuginfo in aktmoduleswitches) or
- (cs_gdb_lineinfo in aktglobalswitches)) then
- begin
- if (objectalloc.currsec<>sec_none) and
- not(hp.typ in SkipLineInfo) then
- WriteFileLineInfo(tailineinfo(hp).fileinfo);
- end;
- {$endif GDB}
- case hp.typ of
- ait_align :
- begin
- { here we must determine the fillsize which is used in pass2 }
- Tai_align(hp).fillsize:=align(objectalloc.sectionsize,Tai_align(hp).aligntype)-
- objectalloc.sectionsize;
- objectalloc.sectionalloc(Tai_align(hp).fillsize);
- end;
- ait_datablock :
- begin
- if objectalloc.currsec<>sec_bss then
- Message(asmw_e_alloc_data_only_in_bss);
- if not SmartAsm then
- begin
- if Tai_datablock(hp).is_global then
- begin
- Tai_datablock(hp).sym.setaddress(currpass,sec_none,Tai_datablock(hp).size,Tai_datablock(hp).size);
- { force to be common/external, must be after setaddress as that would
- set it to AS_GLOBAL }
- Tai_datablock(hp).sym.currbind:=AB_COMMON;
- end
- else
- begin
- l:=Tai_datablock(hp).size;
- if l>2 then
- objectalloc.sectionalign(4)
- else if l>1 then
- objectalloc.sectionalign(2);
- Tai_datablock(hp).sym.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,
- Tai_datablock(hp).size);
- objectalloc.sectionalloc(Tai_datablock(hp).size);
- end;
- end
- else
- begin
- l:=Tai_datablock(hp).size;
- if l>2 then
- objectalloc.sectionalign(4)
- else if l>1 then
- objectalloc.sectionalign(2);
- Tai_datablock(hp).sym.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,Tai_datablock(hp).size);
- objectalloc.sectionalloc(Tai_datablock(hp).size);
- end;
- objectlibrary.UsedAsmSymbolListInsert(Tai_datablock(hp).sym);
- end;
- ait_const_32bit :
- objectalloc.sectionalloc(4);
- ait_const_16bit :
- objectalloc.sectionalloc(2);
- ait_const_8bit :
- objectalloc.sectionalloc(1);
- ait_real_80bit :
- objectalloc.sectionalloc(10);
- ait_real_64bit :
- objectalloc.sectionalloc(8);
- ait_real_32bit :
- objectalloc.sectionalloc(4);
- ait_comp_64bit :
- objectalloc.sectionalloc(8);
- ait_const_rva,
- ait_const_symbol :
- begin
- objectalloc.sectionalloc(4);
- objectlibrary.UsedAsmSymbolListInsert(Tai_const_symbol(hp).sym);
- end;
- ait_section:
- begin
- objectalloc.seTSection(Tai_section(hp).sec);
- {$ifdef GDB}
- case Tai_section(hp).sec of
- sec_code : n_line:=n_textline;
- sec_data : n_line:=n_dataline;
- sec_bss : n_line:=n_bssline;
- else
- n_line:=n_dataline;
- end;
- stabslastfileinfo.line:=-1;
- {$endif GDB}
- end;
- {$ifdef GDB}
- ait_stabn :
- begin
- if assigned(Tai_stabn(hp).str) then
- convertstabs(Tai_stabn(hp).str);
- end;
- ait_stabs :
- begin
- if assigned(Tai_stabs(hp).str) then
- convertstabs(Tai_stabs(hp).str);
- end;
- ait_stab_function_name :
- begin
- if assigned(Tai_stab_function_name(hp).str) then
- begin
- funcname:=objectlibrary.getasmsymbol(strpas(Tai_stab_function_name(hp).str));
- objectlibrary.UsedAsmSymbolListInsert(funcname);
- end
- else
- funcname:=nil;
- end;
- ait_force_line :
- stabslastfileinfo.line:=0;
- {$endif}
- ait_symbol :
- begin
- Tai_symbol(hp).sym.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- objectlibrary.UsedAsmSymbolListInsert(Tai_symbol(hp).sym);
- end;
- ait_symbol_end :
- begin
- if target_info.system in [system_i386_linux,system_i386_beos] then
- begin
- Tai_symbol_end(hp).sym.size:=objectalloc.sectionsize-Tai_symbol_end(hp).sym.address;
- objectlibrary.UsedAsmSymbolListInsert(Tai_symbol_end(hp).sym);
- end;
- end;
- ait_label :
- begin
- Tai_label(hp).l.setaddress(currpass,objectalloc.currsec,objectalloc.sectionsize,0);
- objectlibrary.UsedAsmSymbolListInsert(Tai_label(hp).l);
- end;
- ait_string :
- objectalloc.sectionalloc(Tai_string(hp).len);
- ait_instruction :
- begin
- {$ifdef i386}
- {$ifndef NOAG386BIN}
- objectalloc.sectionalloc(Taicpu(hp).Pass1(objectalloc.sectionsize));
- { fixup the references }
- for i:=1 to Taicpu(hp).ops do
- begin
- with Taicpu(hp).oper[i-1]^ do
- begin
- case typ of
- top_ref :
- begin
- if assigned(ref^.symbol) then
- objectlibrary.UsedAsmSymbolListInsert(ref^.symbol);
- end;
- top_symbol :
- begin
- objectlibrary.UsedAsmSymbolListInsert(sym);
- end;
- end;
- end;
- end;
- {$endif NOAG386BIN}
- {$endif i386}
- end;
- ait_direct :
- Message(asmw_f_direct_not_supported);
- ait_cut :
- if SmartAsm then
- break;
- ait_marker :
- if tai_marker(hp).kind=InlineStart then
- inc(InlineLevel)
- else if tai_marker(hp).kind=InlineEnd then
- dec(InlineLevel);
- end;
- hp:=Tai(hp.next);
- end;
- TreePass1:=hp;
- end;
- function TInternalAssembler.TreePass2(hp:Tai):Tai;
- var
- fillbuffer : tfillbuffer;
- InlineLevel,
- l : longint;
- {$ifdef i386}
- co : comp;
- {$endif i386}
- begin
- inlinelevel:=0;
- { main loop }
- while assigned(hp) do
- begin
- {$ifdef GDB}
- { write stabs, no line info for inlined code }
- if (inlinelevel=0) and
- ((cs_debuginfo in aktmoduleswitches) or
- (cs_gdb_lineinfo in aktglobalswitches)) then
- begin
- if (objectdata.currsec<>sec_none) and
- not(hp.typ in SkipLineInfo) then
- WriteFileLineInfo(tailineinfo(hp).fileinfo);
- end;
- {$endif GDB}
- case hp.typ of
- ait_align :
- begin
- if objectdata.currsec=sec_bss then
- objectdata.alloc(Tai_align(hp).fillsize)
- else
- objectdata.writebytes(Tai_align(hp).calculatefillbuf(fillbuffer)^,Tai_align(hp).fillsize);
- end;
- ait_section :
- begin
- objectdata.defaulTSection(Tai_section(hp).sec);
- {$ifdef GDB}
- case Tai_section(hp).sec of
- sec_code : n_line:=n_textline;
- sec_data : n_line:=n_dataline;
- sec_bss : n_line:=n_bssline;
- else
- n_line:=n_dataline;
- end;
- stabslastfileinfo.line:=-1;
- {$endif GDB}
- end;
- ait_symbol :
- begin
- objectdata.writesymbol(Tai_symbol(hp).sym);
- objectoutput.exportsymbol(Tai_symbol(hp).sym);
- end;
- ait_datablock :
- begin
- objectdata.writesymbol(Tai_datablock(hp).sym);
- objectoutput.exportsymbol(Tai_datablock(hp).sym);
- if SmartAsm or (not Tai_datablock(hp).is_global) then
- begin
- l:=Tai_datablock(hp).size;
- if l>2 then
- objectdata.allocalign(4)
- else if l>1 then
- objectdata.allocalign(2);
- objectdata.alloc(Tai_datablock(hp).size);
- end;
- end;
- ait_const_32bit :
- objectdata.writebytes(Tai_const(hp).value,4);
- ait_const_16bit :
- objectdata.writebytes(Tai_const(hp).value,2);
- ait_const_8bit :
- objectdata.writebytes(Tai_const(hp).value,1);
- ait_real_80bit :
- objectdata.writebytes(Tai_real_80bit(hp).value,10);
- ait_real_64bit :
- objectdata.writebytes(Tai_real_64bit(hp).value,8);
- ait_real_32bit :
- objectdata.writebytes(Tai_real_32bit(hp).value,4);
- ait_comp_64bit :
- begin
- {$ifdef i386}
- {$ifdef FPC}
- co:=comp(Tai_comp_64bit(hp).value);
- {$else}
- co:=Tai_comp_64bit(hp).value;
- {$endif}
- objectdata.writebytes(co,8);
- {$endif i386}
- end;
- ait_string :
- objectdata.writebytes(Tai_string(hp).str^,Tai_string(hp).len);
- ait_const_rva :
- objectdata.writereloc(Tai_const_symbol(hp).offset,4,
- Tai_const_symbol(hp).sym,RELOC_RVA);
- ait_const_symbol :
- objectdata.writereloc(Tai_const_symbol(hp).offset,4,
- Tai_const_symbol(hp).sym,RELOC_ABSOLUTE);
- ait_label :
- begin
- objectdata.writesymbol(Tai_label(hp).l);
- { exporting shouldn't be necessary as labels are local,
- but it's better to be on the safe side (PFV) }
- objectoutput.exportsymbol(Tai_label(hp).l);
- end;
- {$ifdef i386}
- {$ifndef NOAG386BIN}
- ait_instruction :
- Taicpu(hp).Pass2(objectdata);
- {$endif NOAG386BIN}
- {$endif i386}
- {$ifdef GDB}
- ait_stabn :
- convertstabs(Tai_stabn(hp).str);
- ait_stabs :
- convertstabs(Tai_stabs(hp).str);
- ait_stab_function_name :
- if assigned(Tai_stab_function_name(hp).str) then
- funcname:=objectlibrary.getasmsymbol(strpas(Tai_stab_function_name(hp).str))
- else
- funcname:=nil;
- ait_force_line :
- stabslastfileinfo.line:=0;
- {$endif}
- ait_cut :
- if SmartAsm then
- break;
- ait_marker :
- if tai_marker(hp).kind=InlineStart then
- inc(InlineLevel)
- else if tai_marker(hp).kind=InlineEnd then
- dec(InlineLevel);
- end;
- hp:=Tai(hp.next);
- end;
- TreePass2:=hp;
- end;
- procedure TInternalAssembler.writetree;
- var
- hp : Tai;
- label
- doexit;
- begin
- objectalloc.reseTSections;
- objectalloc.seTSection(sec_code);
- objectdata:=objectoutput.newobjectdata(Objfile);
- objectdata.defaulTSection(sec_code);
- { reset the asmsymbol list }
- objectlibrary.CreateUsedAsmsymbolList;
- { Pass 0 }
- currpass:=0;
- objectalloc.seTSection(sec_code);
- { start with list 1 }
- currlistidx:=1;
- currlist:=list[currlistidx];
- hp:=Tai(currList.first);
- while assigned(hp) do
- begin
- hp:=TreePass0(hp);
- MaybeNextList(hp);
- end;
- { leave if errors have occured }
- if errorcount>0 then
- goto doexit;
- { Pass 1 }
- currpass:=1;
- objectalloc.reseTSections;
- objectalloc.seTSection(sec_code);
- {$ifdef GDB}
- StartFileLineInfo;
- {$endif GDB}
- { start with list 1 }
- currlistidx:=1;
- currlist:=list[currlistidx];
- hp:=Tai(currList.first);
- while assigned(hp) do
- begin
- hp:=TreePass1(hp);
- MaybeNextList(hp);
- end;
- {$ifdef GDB}
- EndFileLineInfo;
- {$endif GDB}
- { check for undefined labels and reset }
- objectlibrary.UsedAsmSymbolListCheckUndefined;
- { set section sizes }
- objectdata.seTSectionsizes(objectalloc.secsize);
- { leave if errors have occured }
- if errorcount>0 then
- goto doexit;
- { Pass 2 }
- currpass:=2;
- {$ifdef GDB}
- StartFileLineInfo;
- {$endif GDB}
- { start with list 1 }
- currlistidx:=1;
- currlist:=list[currlistidx];
- hp:=Tai(currList.first);
- while assigned(hp) do
- begin
- hp:=TreePass2(hp);
- MaybeNextList(hp);
- end;
- {$ifdef GDB}
- EndFileLineInfo;
- {$endif GDB}
- { don't write the .o file if errors have occured }
- if errorcount=0 then
- begin
- { write objectfile }
- objectoutput.startobjectfile(ObjFile);
- objectoutput.writeobjectfile(objectdata);
- objectdata.free;
- objectdata:=nil;
- end;
- doexit:
- { reset the used symbols back, must be after the .o has been
- written }
- objectlibrary.UsedAsmsymbolListReset;
- objectlibrary.DestroyUsedAsmsymbolList;
- end;
- procedure TInternalAssembler.writetreesmart;
- var
- hp : Tai;
- starTSec : TSection;
- place: tcutplace;
- begin
- objectalloc.reseTSections;
- objectalloc.seTSection(sec_code);
- NextSmartName(cut_normal);
- objectdata:=objectoutput.newobjectdata(Objfile);
- objectdata.defaulTSection(sec_code);
- starTSec:=sec_code;
- { start with list 1 }
- currlistidx:=1;
- currlist:=list[currlistidx];
- hp:=Tai(currList.first);
- while assigned(hp) do
- begin
- { reset the asmsymbol list }
- objectlibrary.CreateUsedAsmSymbolList;
- { Pass 0 }
- currpass:=0;
- objectalloc.reseTSections;
- objectalloc.seTSection(starTSec);
- TreePass0(hp);
- { leave if errors have occured }
- if errorcount>0 then
- exit;
- { Pass 1 }
- currpass:=1;
- objectalloc.reseTSections;
- objectalloc.seTSection(starTSec);
- {$ifdef GDB}
- StartFileLineInfo;
- {$endif GDB}
- TreePass1(hp);
- {$ifdef GDB}
- EndFileLineInfo;
- {$endif GDB}
- { check for undefined labels }
- objectlibrary.UsedAsmSymbolListCheckUndefined;
- { set section sizes }
- objectdata.seTSectionsizes(objectalloc.secsize);
- { leave if errors have occured }
- if errorcount>0 then
- exit;
- { Pass 2 }
- currpass:=2;
- objectoutput.startobjectfile(Objfile);
- objectdata.defaulTSection(starTSec);
- {$ifdef GDB}
- StartFileLineInfo;
- {$endif GDB}
- hp:=TreePass2(hp);
- {$ifdef GDB}
- EndFileLineInfo;
- {$endif GDB}
- { leave if errors have occured }
- if errorcount>0 then
- exit;
- { write the current objectfile }
- objectoutput.writeobjectfile(objectdata);
- objectdata.free;
- objectdata:=nil;
- { reset the used symbols back, must be after the .o has been
- written }
- objectlibrary.UsedAsmsymbolListReset;
- objectlibrary.DestroyUsedAsmsymbolList;
- { end of lists? }
- if not MaybeNextList(hp) then
- break;
- { save section for next loop }
- { this leads to a problem if starTSec is sec_none !! PM }
- starTSec:=objectalloc.currsec;
- { we will start a new objectfile so reset everything }
- { The place can still change in the next while loop, so don't init }
- { the writer yet (JM) }
- if (hp.typ=ait_cut) then
- place := Tai_cut(hp).place
- else
- place := cut_normal;
- { avoid empty files }
- while assigned(hp) and
- (Tai(hp).typ in [ait_marker,ait_comment,ait_section,ait_cut]) do
- begin
- if Tai(hp).typ=ait_section then
- starTSec:=Tai_section(hp).sec
- else if (Tai(hp).typ=ait_cut) then
- place := Tai_cut(hp).place;
- hp:=Tai(hp.next);
- end;
- if not MaybeNextList(hp) then
- break;
- { start next objectfile }
- NextSmartName(place);
- objectdata:=objectoutput.newobjectdata(Objfile);
- { there is a problem if starTSec is sec_none !! PM }
- if starTSec=sec_none then
- starTSec:=sec_code;
- end;
- end;
- procedure TInternalAssembler.MakeObject;
- procedure addlist(p:TAAsmoutput);
- begin
- inc(lists);
- list[lists]:=p;
- end;
- begin
- if cs_debuginfo in aktmoduleswitches then
- addlist(debuglist);
- addlist(codesegment);
- addlist(datasegment);
- addlist(consts);
- addlist(rttilist);
- if assigned(resourcestringlist) then
- addlist(resourcestringlist);
- addlist(bsssegment);
- if assigned(importssection) then
- addlist(importssection);
- if assigned(exportssection) and not UseDeffileForExport then
- addlist(exportssection);
- if assigned(resourcesection) then
- addlist(resourcesection);
- if SmartAsm then
- writetreesmart
- else
- writetree;
- end;
- {*****************************************************************************
- Generate Assembler Files Main Procedure
- *****************************************************************************}
- Procedure GenerateAsm(smart:boolean);
- var
- a : TAssembler;
- begin
- if not assigned(CAssembler[target_asm.id]) then
- Message(asmw_f_assembler_output_not_supported);
- a:=CAssembler[target_asm.id].Create(smart);
- a.MakeObject;
- a.Free;
- end;
- Procedure OnlyAsm;
- var
- a : TExternalAssembler;
- begin
- a:=TExternalAssembler.Create(false);
- a.DoAssemble;
- a.Free;
- end;
- {*****************************************************************************
- Init/Done
- *****************************************************************************}
- procedure RegisterAssembler(const r:tasminfo;c:TAssemblerClass);
- var
- t : tasm;
- begin
- t:=r.id;
- if assigned(asminfos[t]) then
- writeln('Warning: Assembler is already registered!')
- else
- Getmem(asminfos[t],sizeof(tasminfo));
- asminfos[t]^:=r;
- CAssembler[t]:=c;
- end;
- procedure InitAssembler;
- begin
- { target_asm is already set by readarguments }
- initoutputformat:=target_asm.id;
- aktoutputformat:=target_asm.id;
- end;
- procedure DoneAssembler;
- begin
- end;
- end.
- {
- $Log$
- Revision 1.58 2003-10-21 15:15:36 peter
- * taicpu_abstract.oper[] changed to pointers
- Revision 1.57 2003/10/03 14:16:48 marco
- * -XP<prefix> support
- Revision 1.56 2003/09/30 19:54:23 peter
- * better link on target support
- Revision 1.55 2003/09/23 17:56:05 peter
- * locals and paras are allocated in the code generation
- * tvarsym.localloc contains the location of para/local when
- generating code for the current procedure
- Revision 1.54 2003/09/03 15:55:00 peter
- * NEWRA branch merged
- Revision 1.53.2.1 2003/09/01 21:02:55 peter
- * sparc updates for new tregister
- Revision 1.53 2003/07/04 22:40:58 pierre
- * add support for constant offset in stabs address, needed by threadvar debugging support
- Revision 1.52 2003/04/23 13:48:07 peter
- * m68k fix
- Revision 1.51 2003/04/22 14:33:38 peter
- * removed some notes/hints
- Revision 1.50 2003/03/10 18:16:00 olle
- * niceified comments
- Revision 1.49 2003/01/10 21:49:00 marco
- * more hasunix fixes
- Revision 1.48 2002/11/24 18:21:49 carl
- - remove some unused defines
- Revision 1.47 2002/11/17 16:31:55 carl
- * memory optimization (3-4%) : cleanup of tai fields,
- cleanup of tdef and tsym fields.
- * make it work for m68k
- Revision 1.46 2002/11/15 01:58:46 peter
- * merged changes from 1.0.7 up to 04-11
- - -V option for generating bug report tracing
- - more tracing for option parsing
- - errors for cdecl and high()
- - win32 import stabs
- - win32 records<=8 are returned in eax:edx (turned off by default)
- - heaptrc update
- - more info for temp management in .s file with EXTDEBUG
- Revision 1.45 2002/10/30 21:01:14 peter
- * always include lineno after fileswitch. valgrind requires this
- Revision 1.44 2002/09/05 19:29:42 peter
- * memdebug enhancements
- Revision 1.43 2002/08/20 16:55:38 peter
- * don't write (stabs)line info when inlining a procedure
- Revision 1.42 2002/08/12 15:08:39 carl
- + stab register indexes for powerpc (moved from gdb to cpubase)
- + tprocessor enumeration moved to cpuinfo
- + linker in target_info is now a class
- * many many updates for m68k (will soon start to compile)
- - removed some ifdef or correct them for correct cpu
- Revision 1.41 2002/08/11 14:32:26 peter
- * renamed current_library to objectlibrary
- Revision 1.40 2002/08/11 13:24:10 peter
- * saving of asmsymbols in ppu supported
- * asmsymbollist global is removed and moved into a new class
- tasmlibrarydata that will hold the info of a .a file which
- corresponds with a single module. Added librarydata to tmodule
- to keep the library info stored for the module. In the future the
- objectfiles will also be stored to the tasmlibrarydata class
- * all getlabel/newasmsymbol and friends are moved to the new class
- Revision 1.39 2002/07/26 21:15:37 florian
- * rewrote the system handling
- Revision 1.38 2002/07/10 07:24:40 jonas
- * memory leak fixes from Sergey Korshunoff
- Revision 1.37 2002/07/01 18:46:21 peter
- * internal linker
- * reorganized aasm layer
- Revision 1.36 2002/05/18 13:34:05 peter
- * readded missing revisions
- Revision 1.35 2002/05/16 19:46:35 carl
- + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
- + try to fix temp allocation (still in ifdef)
- + generic constructor calls
- + start of tassembler / tmodulebase class cleanup
- Revision 1.33 2002/04/10 08:07:55 jonas
- * fix for the ie9999 under Linux (patch from Peter)
- Revision 1.32 2002/04/07 13:19:14 carl
- + more documentation
- Revision 1.31 2002/04/04 19:05:54 peter
- * removed unused units
- * use tlocation.size in cg.a_*loc*() routines
- Revision 1.30 2002/04/02 17:11:27 peter
- * tlocation,treference update
- * LOC_CONSTANT added for better constant handling
- * secondadd splitted in multiple routines
- * location_force_reg added for loading a location to a register
- of a specified size
- * secondassignment parses now first the right and then the left node
- (this is compatible with Kylix). This saves a lot of push/pop especially
- with string operations
- * adapted some routines to use the new cg methods
- }
|