123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761 |
- {
- $Id$
- Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
- Implementation of the reading of PPU Files for the symtable
- 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.
- ****************************************************************************
- }
- const
- {$ifdef FPC}
- ppubufsize=32768;
- {$ELSE}
- {$IFDEF USEOVERLAY}
- ppubufsize=512;
- {$ELSE}
- ppubufsize=4096;
- {$ENDIF}
- {$ENDIF}
- {*****************************************************************************
- PPU Writing
- *****************************************************************************}
- procedure writebyte(b:byte);
- begin
- current_ppu^.putbyte(b);
- end;
- procedure writeword(w:word);
- begin
- current_ppu^.putword(w);
- end;
- procedure writelong(l:longint);
- begin
- current_ppu^.putlongint(l);
- end;
- procedure writereal(d:bestreal);
- begin
- current_ppu^.putreal(d);
- end;
- procedure writestring(const s:string);
- begin
- current_ppu^.putstring(s);
- end;
- procedure writenormalset(var s); {You cannot pass an array[0..31] of byte!}
- begin
- current_ppu^.putdata(s,sizeof(tnormalset));
- end;
- procedure writecontainer(var p:tstringcontainer;id:byte;hold,strippath:boolean);
- var
- hcontainer : tstringcontainer;
- s : string;
- begin
- if hold then
- hcontainer.init;
- while not p.empty do
- begin
- s:=p.get;
- if strippath then
- current_ppu^.putstring(SplitFileName(s))
- else
- current_ppu^.putstring(s);
- if hold then
- hcontainer.insert(s);
- end;
- current_ppu^.writeentry(id);
- if hold then
- p:=hcontainer;
- end;
- procedure writeposinfo(const p:tfileposinfo);
- begin
- current_ppu^.putword(p.fileindex);
- current_ppu^.putlongint(p.line);
- current_ppu^.putword(p.column);
- end;
- {$ifndef OLDDEREF}
- procedure writederef(p : psymtableentry);
- begin
- if p=nil then
- current_ppu^.putbyte(ord(derefnil))
- else
- begin
- { Static symtable ? }
- if p^.owner^.symtabletype=staticsymtable then
- begin
- current_ppu^.putbyte(ord(derefaktstatic));
- current_ppu^.putword(p^.indexnr);
- end
- { Local record/object symtable ? }
- else if (p^.owner=aktrecordsymtable) then
- begin
- current_ppu^.putbyte(ord(derefaktrecord));
- current_ppu^.putword(p^.indexnr);
- end
- else
- { else if p^.owner^.unitid>$8000 then
- current_ppu^.putword(p^.owner^.unitid) }
- begin
- current_ppu^.putbyte(ord(dereflocal));
- current_ppu^.putword(p^.indexnr);
- { Current unit symtable ? }
- repeat
- if not assigned(p) then
- internalerror(556655);
- case p^.owner^.symtabletype of
- unitsymtable :
- begin
- current_ppu^.putbyte(ord(derefunit));
- current_ppu^.putword(p^.owner^.unitid);
- break;
- end;
- objectsymtable,
- recordsymtable :
- begin
- current_ppu^.putbyte(ord(derefrecord));
- current_ppu^.putword(p^.indexnr);
- p:=p^.owner^.defowner;
- end;
- else
- internalerror(556656);
- end;
- until false;
- end;
- end;
- end;
- {$else}
- procedure writedefref(p : pdef);
- begin
- if p=nil then
- current_ppu^.putlongint(-1)
- else
- begin
- if p^.owner^.symtabletype=staticsymtable then
- current_ppu^.putword($fffe)
- else if (p^.owner=aktrecordsymtable) then
- current_ppu^.putword($ffff)
- else if p^.owner^.unitid>$8000 then
- current_ppu^.putword(p^.owner^.unitid)
- else
- current_ppu^.putword(p^.owner^.unitid);
- current_ppu^.putword(p^.indexnr);
- end;
- end;
- procedure writesymref(p : psym);
- begin
- if p=nil then
- current_ppu^.putlongint(-1)
- else
- begin
- if p^.owner^.symtabletype=staticsymtable then
- current_ppu^.putword($fffe)
- else if (p^.owner=aktrecordsymtable) then
- current_ppu^.putword($ffff)
- else if p^.owner^.unitid>$8000 then
- current_ppu^.putword(p^.owner^.unitid)
- else
- current_ppu^.putword(p^.owner^.unitid);
- current_ppu^.putword(p^.indexnr);
- end;
- end;
- {$endif}
- procedure writesourcefiles;
- var
- hp : pinputfile;
- begin
- { second write the used source files }
- current_ppu^.do_crc:=false;
- hp:=current_module^.sourcefiles^.files;
- while assigned(hp) do
- begin
- { only name and extension }
- current_ppu^.putstring(hp^.name^);
- hp:=hp^.ref_next;
- end;
- current_ppu^.writeentry(ibsourcefiles);
- current_ppu^.do_crc:=true;
- end;
- procedure writeusedunit;
- var
- hp : pused_unit;
- begin
- numberunits;
- hp:=pused_unit(current_module^.used_units.first);
- while assigned(hp) do
- begin
- current_ppu^.do_interface_crc:=hp^.in_interface;
- current_ppu^.putstring(hp^.name^);
- { the checksum should not affect the crc of this unit ! (PFV) }
- current_ppu^.do_crc:=false;
- current_ppu^.putlongint(hp^.checksum);
- current_ppu^.putlongint(hp^.interface_checksum);
- current_ppu^.do_crc:=true;
- current_ppu^.putbyte(byte(hp^.in_interface));
- hp:=pused_unit(hp^.next);
- end;
- current_ppu^.do_interface_crc:=true;
- current_ppu^.writeentry(ibloadunit);
- end;
- procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean);
- begin
- Message1(unit_u_ppu_write,s);
- { create unit flags }
- with Current_Module^ do
- begin
- if (((cs_create_staticlib in aktmoduleswitches) or
- (cs_smartlink in aktmoduleswitches)) and
- (SplitName(ppufilename^)<>SplitName(staticlibfilename^))) or
- ((cs_create_sharedlib in aktmoduleswitches) and
- (SplitName(ppufilename^)<>SplitName(sharedlibfilename^))) then
- flags:=flags or uf_in_library;
- if cs_smartlink in aktmoduleswitches then
- flags:=flags or uf_smartlink;
- {$ifdef GDB}
- if cs_gdb_dbx in aktglobalswitches then
- flags:=flags or uf_has_dbx;
- {$endif GDB}
- if target_os.endian=endian_big then
- flags:=flags or uf_big_endian;
- if cs_browser in aktmoduleswitches then
- flags:=flags or uf_has_browser;
- if cs_local_browser in aktmoduleswitches then
- flags:=flags or uf_local_browser;
- end;
- {$ifdef Test_Double_checksum_write}
- If only_crc then
- Assign(CRCFile,s+'.INT')
- else
- Assign(CRCFile,s+'.IMP');
- Rewrite(CRCFile);
- {$endif def Test_Double_checksum_write}
- { open ppufile }
- current_ppu:=new(pppufile,init(s));
- if not current_ppu^.create then
- Message(unit_f_ppu_cannot_write);
- current_ppu^.crc_only:=only_crc;
- {$ifdef Test_Double_checksum}
- if only_crc then
- begin
- new(current_ppu^.crc_test);
- end
- else
- begin
- current_ppu^.crc_test:=Current_Module^.crc_array;
- current_ppu^.crc_index:=Current_Module^.crc_size;
- end;
- {$endif def Test_Double_checksum}
- current_ppu^.change_endian:=source_os.endian<>target_os.endian;
- { write symbols and definitions }
- unittable^.writeasunit;
- { flush to be sure }
- current_ppu^.flush;
- { create and write header }
- current_ppu^.header.size:=current_ppu^.size;
- current_ppu^.header.checksum:=current_ppu^.crc;
- current_ppu^.header.interface_checksum:=current_ppu^.interface_crc;
- current_ppu^.header.compiler:=wordversion;
- current_ppu^.header.cpu:=word(target_cpu);
- current_ppu^.header.target:=word(target_info.target);
- current_ppu^.header.flags:=current_module^.flags;
- current_ppu^.writeheader;
- { save crc in current_module also }
- current_module^.crc:=current_ppu^.crc;
- current_module^.interface_crc:=current_ppu^.interface_crc;
- if only_crc then
- begin
- {$ifdef Test_Double_checksum}
- Current_Module^.crc_array:=current_ppu^.crc_test;
- current_ppu^.crc_test:=nil;
- Current_Module^.crc_size:=current_ppu^.crc_index;
- {$endif def Test_Double_checksum}
- closecurrentppu;
- end;
- {$ifdef Test_Double_checksum_write}
- close(CRCFile);
- {$endif Test_Double_checksum_write}
- end;
- procedure closecurrentppu;
- begin
- {$ifdef Test_Double_checksum}
- if assigned(current_ppu^.crc_test) then
- dispose(current_ppu^.crc_test);
- {$endif Test_Double_checksum}
- { close }
- current_ppu^.close;
- dispose(current_ppu,done);
- current_ppu:=nil;
- end;
- {*****************************************************************************
- PPU Reading
- *****************************************************************************}
- function readbyte:byte;
- begin
- readbyte:=current_ppu^.getbyte;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readword:word;
- begin
- readword:=current_ppu^.getword;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readlong:longint;
- begin
- readlong:=current_ppu^.getlongint;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readreal : bestreal;
- begin
- readreal:=current_ppu^.getreal;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readstring : string;
- begin
- readstring:=current_ppu^.getstring;
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readnormalset(var s); {You cannot pass an array [0..31] of byte.}
- begin
- current_ppu^.getdata(s,sizeof(tnormalset));
- if current_ppu^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readcontainer(var p:tstringcontainer);
- begin
- while not current_ppu^.endofentry do
- p.insert(current_ppu^.getstring);
- end;
- procedure readposinfo(var p:tfileposinfo);
- begin
- p.fileindex:=current_ppu^.getword;
- p.line:=current_ppu^.getlongint;
- p.column:=current_ppu^.getword;
- end;
- {$ifndef OLDDEREF}
- function readderef : pderef;
- var
- hp,p : pderef;
- b : tdereftype;
- begin
- p:=nil;
- repeat
- hp:=p;
- b:=tdereftype(current_ppu^.getbyte);
- case b of
- derefnil :
- break;
- derefunit,
- derefaktrecord,
- derefaktstatic :
- begin
- new(p);
- p^.dereftype:=b;
- p^.index:=current_ppu^.getword;
- p^.next:=hp;
- break;
- end;
- dereflocal,
- derefrecord :
- begin
- new(p);
- p^.dereftype:=derefrecord;
- p^.index:=current_ppu^.getword;
- p^.next:=hp;
- end;
- end;
- until false;
- readderef:=p;
- end;
- {$else}
- function readdefref : pdef;
- var
- hd : pdef;
- begin
- longint(hd):=current_ppu^.getword;
- longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
- readdefref:=hd;
- end;
- function readsymref : psym;
- var
- hd : psym;
- begin
- longint(hd):=current_ppu^.getword;
- longint(hd):=longint(hd) or (longint(current_ppu^.getword) shl 16);
- readsymref:=hd;
- end;
- {$endif}
- procedure readsourcefiles;
- var
- temp,hs : string;
- incfile_found : boolean;
- ppufiletime,
- source_time : longint;
- hp : pinputfile;
- begin
- ppufiletime:=getnamedfiletime(current_module^.ppufilename^);
- current_module^.sources_avail:=true;
- while not current_ppu^.endofentry do
- begin
- hs:=current_ppu^.getstring;
- temp:='';
- if (current_module^.flags and uf_in_library)<>0 then
- begin
- current_module^.sources_avail:=false;
- temp:=' library';
- end
- else if pos('Macro ',hs)=1 then
- begin
- { we don't want to find this file }
- { but there is a problem with file indexing !! }
- temp:='';
- end
- else
- begin
- { check the date of the source files }
- Source_Time:=GetNamedFileTime(current_module^.path^+hs);
- incfile_found:=false;
- if (Source_Time=-1) then
- begin
- temp:=search(hs,includesearchpath,incfile_found);
- if incfile_found then
- begin
- hs:=temp+hs;
- Source_Time:=GetNamedFileTime(hs);
- end
- end
- else
- hs:=current_module^.path^+hs;
- if Source_Time=-1 then
- begin
- current_module^.sources_avail:=false;
- temp:=' not found';
- end
- else
- begin
- { time newer? But only allow if the file is not searched
- in the include path (PFV), else you've problems with
- units which use the same includefile names }
- if incfile_found then
- temp:=' found'
- else
- begin
- temp:=' time '+filetimestring(source_time);
- if (source_time>ppufiletime) then
- begin
- current_module^.do_compile:=true;
- temp:=temp+' *'
- end;
- end;
- end;
- new(hp,init(hs));
- { the indexing is wrong here PM }
- current_module^.sourcefiles^.register_file(hp);
- end;
- Message1(unit_u_ppu_source,hs+temp);
- end;
- { main source is always the last }
- stringdispose(current_module^.mainsource);
- current_module^.mainsource:=stringdup(hs);
- { the indexing is corrected here PM }
- current_module^.sourcefiles^.inverse_register_indexes;
- { check if we want to rebuild every unit, only if the sources are
- available }
- if do_build and current_module^.sources_avail then
- current_module^.do_compile:=true;
- end;
- procedure readloadunit;
- var
- hs : string;
- intfchecksum,
- checksum : longint;
- in_interface : boolean;
- begin
- while not current_ppu^.endofentry do
- begin
- hs:=current_ppu^.getstring;
- checksum:=current_ppu^.getlongint;
- intfchecksum:=current_ppu^.getlongint;
- in_interface:=(current_ppu^.getbyte<>0);
- current_module^.used_units.concat(new(pused_unit,init_to_load(hs,checksum,intfchecksum,in_interface)));
- end;
- end;
- procedure load_interface;
- var
- b : byte;
- begin
- { read interface part }
- repeat
- b:=current_ppu^.readentry;
- case b of
- ibmodulename : begin
- stringdispose(current_module^.modulename);
- current_module^.modulename:=stringdup(current_ppu^.getstring);
- end;
- ibsourcefiles : readsourcefiles;
- ibloadunit : readloadunit;
- iblinksharedlibs : readcontainer(current_module^.LinkSharedLibs);
- iblinkstaticlibs : readcontainer(current_module^.LinkStaticLibs);
- iblinkunitfiles : readcontainer(current_module^.LinkUnitFiles);
- iblinkofiles : readcontainer(current_module^.LinkOFiles);
- ibendinterface : break;
- else
- Message1(unit_f_ppu_invalid_entry,tostr(b));
- end;
- until false;
- end;
- {
- $Log$
- Revision 1.40 1999-05-13 21:59:44 peter
- * removed oldppu code
- * warning if objpas is loaded from uses
- * first things for new deref writing
- Revision 1.39 1999/05/04 21:45:06 florian
- * changes to compile it with Delphi 4.0
- Revision 1.38 1999/04/26 13:31:51 peter
- * release storenumber,double_checksum
- Revision 1.37 1999/04/21 09:43:53 peter
- * storenumber works
- * fixed some typos in double_checksum
- + incompatible types type1 and type2 message (with storenumber)
- Revision 1.36 1999/04/14 09:15:01 peter
- * first things to store the symbol/def number in the ppu
- Revision 1.35 1999/04/07 15:39:35 pierre
- + double_checksum code added
- Revision 1.34 1999/03/02 13:49:19 peter
- * renamed loadunit_int -> loadunit
- Revision 1.33 1999/02/23 18:29:25 pierre
- * win32 compilation error fix
- + some work for local browser (not cl=omplete yet)
- Revision 1.32 1999/02/22 13:07:08 pierre
- + -b and -bl options work !
- + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
- is not enabled when quitting global section
- * local vars and procedures are not yet stored into PPU
- Revision 1.31 1999/02/16 00:48:25 peter
- * save in the ppu if linked with obj file instead of using the
- library flag, so the .inc files are also checked
- Revision 1.30 1999/02/05 08:54:30 pierre
- + linkofiles splitted inot linkofiles and linkunitfiles
- because linkofiles must be stored with directory
- to enabled linking of different objects with same name
- in a different directory
- Revision 1.29 1999/01/20 10:16:46 peter
- * don't update crc when writing objs,libs and sources
- Revision 1.28 1999/01/12 14:25:35 peter
- + BrowserLog for browser.log generation
- + BrowserCol for browser info in TCollections
- * released all other UseBrowser
- Revision 1.27 1998/12/08 10:18:14 peter
- + -gh for heaptrc unit
- Revision 1.26 1998/11/26 14:36:02 peter
- * set also library flag if smartlinking and outputname is different
- Revision 1.25 1998/10/26 09:35:47 peter
- * don't count includefiles which are found in the includepath for a
- recompile.
- Revision 1.24 1998/10/20 08:06:59 pierre
- * several memory corruptions due to double freemem solved
- => never use p^.loc.location:=p^.left^.loc.location;
- + finally I added now by default
- that ra386dir translates global and unit symbols
- + added a first field in tsymtable and
- a nextsym field in tsym
- (this allows to obtain ordered type info for
- records and objects in gdb !)
- Revision 1.23 1998/10/16 13:37:24 florian
- + switch -FD added to specify the path for utilities
- Revision 1.22 1998/10/14 13:38:24 peter
- * fixed path with staticlib/objects in ppufiles
- Revision 1.21 1998/10/14 10:45:10 pierre
- * ppu problems for m68k fixed (at least in cross compiling)
- * one last memory leak for sysamiga fixed
- * the amiga RTL compiles now completely !!
- Revision 1.20 1998/10/13 13:10:30 peter
- * new style for m68k/i386 infos and enums
- Revision 1.19 1998/10/08 23:29:07 peter
- * -vu shows unit info, -vt shows tried/used files
- Revision 1.18 1998/09/28 16:57:27 pierre
- * changed all length(p^.value_str^) into str_length(p)
- to get it work with and without ansistrings
- * changed sourcefiles field of tmodule to a pointer
- Revision 1.17 1998/09/22 17:13:53 pierre
- + browsing updated and developed
- records and objects fields are also stored
- Revision 1.16 1998/09/22 15:40:56 peter
- * some extra ifdef GDB
- Revision 1.15 1998/09/21 08:45:23 pierre
- + added vmt_offset in tobjectdef.write for fututre use
- (first steps to have objects without vmt if no virtual !!)
- + added fpu_used field for tabstractprocdef :
- sets this level to 2 if the functions return with value in FPU
- (is then set to correct value at parsing of implementation)
- THIS MIGHT refuse some code with FPU expression too complex
- that were accepted before and even in some cases
- that don't overflow in fact
- ( like if f : float; is a forward that finally in implementation
- only uses one fpu register !!)
- Nevertheless I think that it will improve security on
- FPU operations !!
- * most other changes only for UseBrowser code
- (added symtable references for record and objects)
- local switch for refs to args and local of each function
- (static symtable still missing)
- UseBrowser still not stable and probably broken by
- the definition hash array !!
- Revision 1.14 1998/09/01 07:54:24 pierre
- * UseBrowser a little updated (might still be buggy !!)
- * bug in psub.pas in function specifier removed
- * stdcall allowed in interface and in implementation
- (FPC will not yet complain if it is missing in either part
- because stdcall is only a dummy !!)
- Revision 1.13 1998/08/17 10:10:11 peter
- - removed OLDPPU
- Revision 1.12 1998/08/17 09:17:53 peter
- * static/shared linking updates
- Revision 1.11 1998/08/16 20:32:49 peter
- * crcs of used units are not important for the current crc, reduces the
- amount of recompiles
- Revision 1.10 1998/08/13 10:57:30 peter
- * constant sets are now written correctly to the ppufile
- Revision 1.9 1998/08/11 15:31:41 peter
- * write extended to ppu file
- * new version 0.99.7
- Revision 1.8 1998/08/10 14:50:29 peter
- + localswitches, moduleswitches, globalswitches splitting
- Revision 1.7 1998/07/14 14:47:07 peter
- * released NEWINPUT
- Revision 1.6 1998/07/07 11:20:14 peter
- + NEWINPUT for a better inputfile and scanner object
- Revision 1.5 1998/06/24 14:48:39 peter
- * ifdef newppu -> ifndef oldppu
- Revision 1.4 1998/06/16 08:56:32 peter
- + targetcpu
- * cleaner pmodules for newppu
- Revision 1.3 1998/06/13 00:10:17 peter
- * working browser and newppu
- * some small fixes against crashes which occured in bp7 (but not in
- fpc?!)
- Revision 1.2 1998/05/28 14:40:28 peter
- * fixes for newppu, remake3 works now with it
- Revision 1.1 1998/05/27 19:45:09 peter
- * symtable.pas splitted into includefiles
- * symtable adapted for $ifdef NEWPPU
- }
|