123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542 |
- {
- $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
- *****************************************************************************}
- {$ifdef NEWPPU}
- procedure writebyte(b:byte);
- begin
- ppufile^.putbyte(b);
- end;
- procedure writeword(w:word);
- begin
- ppufile^.putword(w);
- end;
- procedure writelong(l:longint);
- begin
- ppufile^.putlongint(l);
- end;
- procedure writedouble(d:double);
- begin
- ppufile^.putdata(d,sizeof(double));
- end;
- procedure writestring(const s:string);
- begin
- ppufile^.putstring(s);
- end;
- procedure writeset(var s); {You cannot pass an array[0..31] of byte!}
- begin
- ppufile^.putdata(s,32);
- end;
- procedure writecontainer(var p:tstringcontainer;id:byte;hold:boolean);
- var
- hcontainer : tstringcontainer;
- s : string;
- begin
- if hold then
- hcontainer.init;
- while not p.empty do
- begin
- s:=p.get;
- ppufile^.putstring(s);
- if hold then
- hcontainer.insert(s);
- end;
- ppufile^.writeentry(id);
- if hold then
- p:=hcontainer;
- end;
- procedure writeposinfo(const p:tfileposinfo);
- begin
- writeword(p.fileindex);
- writelong(p.line);
- writeword(p.column);
- end;
- procedure writedefref(p : pdef);
- begin
- if p=nil then
- ppufile^.putlongint($ffffffff)
- else
- begin
- if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
- ppufile^.putword($ffff)
- else
- ppufile^.putword(p^.owner^.unitid);
- ppufile^.putword(p^.indexnb);
- end;
- end;
- procedure writesymref(p : psym);
- begin
- if p=nil then
- writelong($ffffffff)
- else
- begin
- if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
- writeword($ffff)
- else
- writeword(p^.owner^.unitid);
- writeword(p^.indexnb);
- end;
- end;
- procedure writeunitas(const s : string;unittable : punitsymtable);
- begin
- Message1(unit_u_ppu_write,s);
- { create unit flags }
- with Current_Module^ do
- begin
- if cs_smartlink in aktswitches then
- begin
- flags:=flags or uf_smartlink;
- if SplitName(ppufilename^)<>SplitName(libfilename^) then
- flags:=flags or uf_in_library;
- end;
- if use_dbx then
- flags:=flags or uf_has_dbx;
- if target_os.endian=en_big_endian then
- flags:=flags or uf_big_endian;
- {$ifdef UseBrowser}
- if cs_browser in aktswitches then
- flags:=flags or uf_has_browser;
- {$endif UseBrowser}
- end;
- { open ppufile }
- ppufile:=new(pppufile,init(s));
- ppufile^.change_endian:=source_os.endian<>target_os.endian;
- if not ppufile^.create then
- Message(unit_f_ppu_cannot_write);
- { write symbols and definitions }
- unittable^.writeasunit;
- { flush to be sure }
- ppufile^.flush;
- { create and write header }
- ppufile^.header.size:=ppufile^.size;
- ppufile^.header.checksum:=ppufile^.crc;
- ppufile^.header.compiler:=wordversion;
- ppufile^.header.target:=word(target_info.target);
- ppufile^.header.flags:=current_module^.flags;
- ppufile^.writeheader;
- { save crc in current_module also }
- current_module^.crc:=ppufile^.crc;
- { close }
- ppufile^.close;
- dispose(ppufile,done);
- end;
- {$else NEWPPU}
- procedure writebyte(b:byte);
- begin
- ppufile.write_data(b,1);
- end;
- procedure writeword(w:word);
- begin
- ppufile.write_data(w,2);
- end;
- procedure writelong(l:longint);
- begin
- ppufile.write_data(l,4);
- end;
- procedure writedouble(d:double);
- begin
- ppufile.write_data(d,sizeof(double));
- end;
- procedure writestring(s : string);
- begin
- ppufile.write_data(s,length(s)+1);
- end;
- procedure writeset(var s); {You cannot pass an array[0..31] of byte!}
- begin
- ppufile.write_data(s,32);
- end;
- procedure writecontainer(var p:tstringcontainer;id:byte;hold:boolean);
- var
- hcontainer : tstringcontainer;
- s : string;
- begin
- if hold then
- hcontainer.init;
- while not p.empty do
- begin
- writebyte(id);
- s:=p.get;
- writestring(s);
- if hold then
- hcontainer.insert(s);
- end;
- if hold then
- p:=hcontainer;
- end;
- procedure writeposinfo(const p:tfileposinfo);
- begin
- writeword(p.fileindex);
- writelong(p.line);
- writeword(p.column);
- end;
- procedure writedefref(p : pdef);
- begin
- if p=nil then
- writelong($ffffffff)
- else
- begin
- if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
- writeword($ffff)
- else
- writeword(p^.owner^.unitid);
- writeword(p^.indexnb);
- end;
- end;
- procedure writesymref(p : psym);
- begin
- if p=nil then
- writelong($ffffffff)
- else
- begin
- if (p^.owner^.symtabletype in [recordsymtable,objectsymtable]) then
- writeword($ffff)
- else
- writeword(p^.owner^.unitid);
- writeword(p^.indexnb);
- end;
- end;
- procedure writeunitas(const s : string;unittable : punitsymtable);
- {$ifdef UseBrowser}
- var
- pus : punitsymtable;
- {$endif UseBrowser}
- begin
- Message1(unit_u_ppu_write,s);
- { create unit flags }
- with Current_Module^ do
- begin
- if cs_smartlink in aktswitches then
- begin
- flags:=flags or uf_smartlink;
- if SplitName(ppufilename^)<>SplitName(libfilename^) then
- flags:=flags or uf_in_library;
- end;
- if use_dbx then
- flags:=flags or uf_has_dbx;
- if target_os.endian=en_big_endian then
- flags:=flags or uf_big_endian;
- {$ifdef UseBrowser}
- if use_browser then
- flags:=flags or uf_uses_browser;
- {$endif UseBrowser}
- end;
- { open en init ppufile }
- ppufile.init(s,ppubufsize);
- ppufile.change_endian:=source_os.endian<>target_os.endian;
- ppufile.rewrite;
- if ioresult<>0 then
- Message(unit_f_ppu_cannot_write);
- { create and write header }
- unitheader[8]:=char(byte(target_info.target));
- unitheader[9]:=char(current_module^.flags);
- ppufile.write_data(unitheader,sizeof(unitheader));
- ppufile.clear_crc;
- ppufile.do_crc:=true;
- unittable^.writeasunit;
- ppufile.flush;
- ppufile.do_crc:=false;
- {$ifdef UseBrowser}
- { write all new references to old unit elements }
- pus:=punitsymtable(unittable^.next);
- if use_browser then
- while assigned(pus) do
- begin
- if pus^.symtabletype = unitsymtable then
- pus^.write_external_references;
- pus:=punitsymtable(pus^.next);
- end;
- {$endif UseBrowser}
- { writes the checksum }
- ppufile.seek(10);
- current_module^.crc:=ppufile.getcrc;
- ppufile.write_data(current_module^.crc,4);
- ppufile.flush;
- ppufile.done;
- end;
- {$endif NEWPPU}
- {*****************************************************************************
- PPU Reading
- *****************************************************************************}
- {$ifdef NEWPPU}
- function readbyte:byte;
- begin
- readbyte:=ppufile^.getbyte;
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readword:word;
- begin
- readword:=ppufile^.getword;
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readlong:longint;
- begin
- readlong:=ppufile^.getlongint;
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- end;
- function readdouble : double;
- var
- d : double;
- begin
- ppufile^.getdata(d,sizeof(double));
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- readdouble:=d;
- end;
- function readstring : string;
- begin
- readstring:=ppufile^.getstring;
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readset(var s); {You cannot pass an array [0..31] of byte.}
- begin
- ppufile^.getdata(s,32);
- if ppufile^.error then
- Message(unit_f_ppu_read_error);
- end;
- procedure readcontainer(var p:tstringcontainer);
- begin
- while not current_module^.ppufile^.endofentry do
- p.insert(current_module^.ppufile^.getstring);
- end;
- procedure readposinfo(var p:tfileposinfo);
- begin
- p.fileindex:=readword;
- p.line:=readlong;
- p.column:=readword;
- end;
- function readdefref : pdef;
- var
- hd : pdef;
- begin
- longint(hd):=readword;
- longint(hd):=longint(hd) or (longint(readword) shl 16);
- readdefref:=hd;
- end;
- {$ifdef UseBrowser}
- function readsymref : psym;
- var
- hd : psym;
- begin
- longint(hd):=readword;
- longint(hd):=longint(hd) or (longint(readword) shl 16);
- readsymref:=hd;
- end;
- {$endif}
- {$else NEWPPU}
- function readbyte : byte;
- var
- count : longint;
- b : byte;
- begin
- current_module^.ppufile^.read_data(b,sizeof(byte),count);
- readbyte:=b;
- if count<>1 then
- Message(unit_f_ppu_read_error);
- end;
- function readword : word;
- var
- count : longint;
- w : word;
- begin
- current_module^.ppufile^.read_data(w,sizeof(word),count);
- readword:=w;
- if count<>sizeof(word) then
- Message(unit_f_ppu_read_error);
- end;
- function readlong : longint;
- var
- count,l : longint;
- begin
- current_module^.ppufile^.read_data(l,sizeof(longint),count);
- readlong:=l;
- if count<>sizeof(longint) then
- Message(unit_f_ppu_read_error);
- end;
- function readdouble : double;
- var
- count : longint;
- d : double;
- begin
- current_module^.ppufile^.read_data(d,sizeof(double),count);
- readdouble:=d;
- if count<>sizeof(double) then
- Message(unit_f_ppu_read_error);
- end;
- function readstring : string;
- var
- s : string;
- count : longint;
- begin
- s[0]:=char(readbyte);
- current_module^.ppufile^.read_data(s[1],ord(s[0]),count);
- if count<>ord(s[0]) then
- Message(unit_f_ppu_read_error);
- readstring:=s;
- end;
- {***SETCONST}
- procedure readset(var s); {You cannot pass an array [0..31] of byte.}
- var count:longint;
- begin
- current_module^.ppufile^.read_data(s,32,count);
- if count<>32 then
- Message(unit_f_ppu_read_error);
- end;
- {***}
- procedure readposinfo(var p:tfileposinfo);
- begin
- p.fileindex:=readword;
- p.line:=readlong;
- p.column:=readword;
- end;
- function readdefref : pdef;
- var
- hd : pdef;
- begin
- longint(hd):=readword;
- longint(hd):=longint(hd) or (longint(readword) shl 16);
- readdefref:=hd;
- end;
- {$ifdef UseBrowser}
- function readsymref : psym;
- var
- hd : psym;
- begin
- longint(hd):=readword;
- longint(hd):=longint(hd) or (longint(readword) shl 16);
- readsymref:=hd;
- end;
- {$endif UseBrowser}
- {$endif NEWPPU}
- {
- $Log$
- 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
- }
|