From ab9465df1b35bd1bf2759d506e15f74a721c8ac1 Mon Sep 17 00:00:00 2001 From: pierre Date: Wed, 7 Apr 1999 15:39:29 +0000 Subject: [PATCH] + double_checksum code added --- compiler/files.pas | 77 +++++++++++++++++++++++++-- compiler/pmodules.pas | 117 ++++++++++++++++++++++++++++++++++++------ compiler/ppu.pas | 88 +++++++++++++++++++++++++++++-- compiler/symdef.inc | 25 +++++++-- compiler/symppu.inc | 66 ++++++++++++++++++++++-- 5 files changed, 345 insertions(+), 28 deletions(-) diff --git a/compiler/files.pas b/compiler/files.pas index e381acdc9a..0fd27675e9 100644 --- a/compiler/files.pas +++ b/compiler/files.pas @@ -125,6 +125,10 @@ unit files; tmodule = object(tlinkedlist_item) ppufile : pppufile; { the PPU file } crc, +{$ifdef Double_checksum} + interface_crc : longint; + do_reload_ppu : boolean; +{$endif def Double_checksum} flags : longint; { the PPU flags } compiled, { unit is already compiled } @@ -154,7 +158,7 @@ unit files; linkunitfiles, linkofiles : tstringcontainer; used_units : tlinkedlist; - + dependent_units : tlinkedlist; localunitsearchpath, { local searchpaths } localobjectsearchpath, localincludesearchpath, @@ -171,6 +175,10 @@ unit files; exefilename, { fullname of the exefile } asmprefix, { prefix for the smartlink asmfiles } mainsource : pstring; { name of the main sourcefile } +{$ifdef Test_Double_checksum} + crc_array : pointer; + crc_size : longint; +{$endif def Test_Double_checksum} constructor init(const s:string;_is_unit:boolean); destructor done;virtual; @@ -185,6 +193,9 @@ unit files; unitid : word; name : pstring; checksum : longint; +{$ifdef Double_checksum} + interface_checksum : longint; +{$endif def Double_checksum} loaded : boolean; in_uses, in_interface, @@ -195,6 +206,12 @@ unit files; destructor done;virtual; end; + pdependent_unit = ^tdependent_unit; + tdependent_unit = object(tlinkedlist_item) + u : pmodule; + constructor init(_u : pmodule); + end; + var main_module : pmodule; { Main module of the program } current_module : pmodule; { Current module which is compiled } @@ -209,6 +226,9 @@ unit files; implementation uses +{$ifdef Double_checksum} + comphook, +{$endif Double_checksum} dos,verbose,systems, symtable,scanner; @@ -713,7 +733,7 @@ uses exit; end; { check for allowed PPU versions } - if not (ppufile^.GetPPUVersion = 15) then + if not (ppufile^.GetPPUVersion = CurrentPPUVersion) then begin dispose(ppufile,done); Message1(unit_u_ppu_invalid_version,tostr(ppufile^.GetPPUVersion)); @@ -736,6 +756,9 @@ uses { Load values to be access easier } flags:=ppufile^.header.flags; crc:=ppufile^.header.checksum; +{$ifdef Double_checksum} + interface_crc:=ppufile^.header.interface_checksum; +{$endif def Double_checksum} { Show Debug info } Message1(unit_u_ppu_time,filetimestring(ppufiletime)); Message1(unit_u_ppu_flags,tostr(flags)); @@ -898,6 +921,10 @@ uses end; procedure tmodule.reset; + + var + pm : pdependent_unit; + begin if assigned(scanner) then pscannerfile(scanner)^.invalid:=true; @@ -929,6 +956,19 @@ uses _exports^.init; used_units.done; used_units.init; + { all units that depend on this one must be recompiled ! } +{$ifdef Double_checksum} + pm:=pdependent_unit(dependent_units.first); + while assigned(pm) do + begin + pm^.u^.do_reload_ppu:=true; + def_comment(v_warning,'Reloading '+pm^.u^.mainsource^+' needed because '+ + mainsource^+' is reloaded'); + pm:=pdependent_unit(pm^.next); + end; +{$endif Double_checksum} + dependent_units.done; + dependent_units.init; resourcefiles.done; resourcefiles.init_no_double; linkunitfiles.done; @@ -950,6 +990,9 @@ uses loaded_from:=nil; flags:=0; crc:=0; +{$ifdef Double_checksum} + interface_crc:=0; +{$endif def Double_checksum} unitcount:=1; end; @@ -998,6 +1041,7 @@ uses localincludesearchpath:=nil; locallibrarysearchpath:=nil; used_units.init; + dependent_units.init; new(sourcefiles,init); resourcefiles.init_no_double; linkunitfiles.init_no_double; @@ -1012,6 +1056,10 @@ uses loaded_from:=nil; flags:=0; crc:=0; +{$ifdef Double_checksum} + interface_crc:=0; + do_reload_ppu:=false; +{$endif def Double_checksum} unitcount:=1; inc(global_unit_count); unit_index:=global_unit_count; @@ -1055,6 +1103,7 @@ uses dispose(sourcefiles,done); sourcefiles:=nil; used_units.done; + dependent_units.done; resourcefiles.done; linkunitfiles.done; linkofiles.done; @@ -1098,6 +1147,9 @@ uses loaded:=true; name:=stringdup(_u^.modulename^); checksum:=_u^.crc; +{$ifdef Double_checksum} + interface_checksum:=_u^.interface_crc; +{$endif def Double_checksum} unitid:=0; end; @@ -1111,6 +1163,13 @@ uses loaded:=false; name:=stringdup(n); checksum:=c; +{$ifdef Double_checksum} + if not in_interface then + begin + interface_checksum:=c; + checksum:=0; + end; +{$endif def Double_checksum} unitid:=0; end; @@ -1121,10 +1180,22 @@ uses inherited done; end; +{**************************************************************************** + TDENPENDENT_UNIT + ****************************************************************************} + + constructor tdependent_unit.init(_u : pmodule); + begin + u:=_u; + end; + end. { $Log$ - Revision 1.88 1999-03-25 16:55:29 peter + Revision 1.89 1999-04-07 15:39:29 pierre + + double_checksum code added + + Revision 1.88 1999/03/25 16:55:29 peter + unitpath,librarypath,includepath,objectpath directives Revision 1.87 1999/02/16 00:48:23 peter diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index 7e062e6121..38f78d9c9c 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -22,7 +22,8 @@ } unit pmodules; -{.$define TEST_IMPL does not work well } +{ define TEST_IMPL does not work well } +{ replaced by $define Double_checksum} { other way to get correct type info, in test (PM) } {$define New_GDB} @@ -126,7 +127,14 @@ unit pmodules; fixseg(codesegment,sec_code); fixseg(datasegment,sec_data); fixseg(bsssegment,sec_bss); + { we should use .rdata section for these two no ? } + { .rdata is a read only data section (PM) } + fixseg(rttilist,sec_data); fixseg(consts,sec_data); +{$ifdef GDB} + if assigned(debuglist) then + fixseg(debuglist,sec_code); +{$endif GDB} end; @@ -226,8 +234,10 @@ unit pmodules; var pu : pused_unit; loaded_unit : pmodule; + load_refs : boolean; nextmapentry : longint; begin + load_refs:=true; { init the map } new(current_module^.map); fillchar(current_module^.map^,sizeof(tunitmap),#0); @@ -248,11 +258,20 @@ unit pmodules; { register unit in used units } pu^.u:=loaded_unit; pu^.loaded:=true; + { doubles are not important for that list PM } + pu^.u^.dependent_units.concat(new(pdependent_unit,init(current_module))); { need to recompile the current unit ? } if loaded_unit^.crc<>pu^.checksum then begin Message2(unit_u_recompile_crc_change,current_module^.modulename^,pu^.name^); current_module^.do_compile:=true; + { if the checksum was known but has changed then + we should also recompile the loaded unit ! } + if (pu^.checksum<>0) and (loaded_unit^.sources_avail) then + begin + Message2(unit_u_recompile_crc_change,loaded_unit^.modulename^,current_module^.modulename^); + loaded_unit^.do_compile:=true; + end; dispose(current_module^.map); current_module^.map:=nil; exit; @@ -292,17 +311,22 @@ unit pmodules; { register unit in used units } pu^.u:=loaded_unit; pu^.loaded:=true; -{$ifdef TEST_IMPL} +{$ifdef Double_checksum} { need to recompile the current unit ? } - if loaded_unit^.crc<>pu^.checksum then - begin - Message2(unit_u_recompile_crc_change,current_module^.modulename^,pu^.name^); - current_module^.do_compile:=true; - dispose(current_module^.map); - current_module^.map:=nil; - exit; - end; -{$endif TEST_IMPL} + if (loaded_unit^.interface_crc<>pu^.interface_checksum) then + { checksum change whereas it was already known + loade_unit was changed so we need to recompile this unit } + begin + {if (loaded_unit^.sources_avail) then + begin + loaded_unit^.do_compile:=true; + end; } + Message2(unit_u_recompile_crc_change,loaded_unit^.modulename^,current_module^.modulename^); + loaded_unit^.do_compile:=true; + if(pu^.interface_checksum<>0) then + load_refs:=false; + end; +{$endif def Double_checksum} { setup the map entry for deref } {$ifndef NEWMAP} current_module^.map^[nextmapentry]:=loaded_unit^.globalsymtable; @@ -316,7 +340,7 @@ unit pmodules; pu:=pused_unit(pu^.next); end; { load browser info if stored } - if ((current_module^.flags and uf_has_browser)<>0) then + if ((current_module^.flags and uf_has_browser)<>0) and load_refs then punitsymtable(current_module^.globalsymtable)^.load_symtable_refs; { remove the map, it's not needed anymore } dispose(current_module^.map); @@ -426,12 +450,37 @@ unit pmodules; end; end; break; + end +{$ifdef Double_checksum} + else if hp^.do_reload_ppu then + begin + { remove the old unit } + loaded_units.remove(hp); + scanner:=hp^.scanner; + name:=hp^.modulename^; + hp^.reset; + hp^.do_reload_ppu:=false; + hp^.scanner:=scanner; + { try to reopen ppu } + hp^.search_unit(name,false); + { try to load the unit a second time first } + current_module:=hp; + current_module^.in_second_compile:=true; + { now realy load the ppu } + loadppufile; + { set compiled flag } + current_module^.compiled:=true; end; +{$endif Double_checksum} { the next unit } hp:=pmodule(hp^.next); end; { the unit is not in the symtable stack } - if (not assigned(st)) then + if (not assigned(st)) +{$ifdef Double_checksum} + or (assigned(hp) and hp^.do_reload_ppu) +{$endif Double_checksum} + then begin if assigned(hp) then begin @@ -439,6 +488,9 @@ unit pmodules; loaded_units.remove(hp); scanner:=hp^.scanner; hp^.reset; +{$ifdef Double_checksum} + hp^.do_reload_ppu:=false; +{$endif Double_checksum} hp^.scanner:=scanner; { try to reopen ppu } hp^.search_unit(s,false); @@ -703,11 +755,23 @@ unit pmodules; procedure gen_main_procsym(const name:string;options:longint;st:psymtable); +{$ifdef Double_checksum} + var + stt : psymtable; +{$endif Double_checksum} begin {Generate a procsym for main} make_ref:=false; aktprocsym:=new(Pprocsym,init(name)); +{$ifdef Double_checksum} + {Try to insert in in static symtable ! } + stt:=symtablestack; + symtablestack:=st; +{$endif Double_checksum} aktprocsym^.definition:=new(Pprocdef,init); +{$ifdef Double_checksum} + symtablestack:=stt; +{$endif Double_checksum} aktprocsym^.definition^.options:=aktprocsym^.definition^.options or options; aktprocsym^.definition^.setmangledname(target_os.cprefix+name); aktprocsym^.definition^.forwarddef:=false; @@ -751,6 +815,9 @@ unit pmodules; {$ifdef GDB} pu : pused_unit; {$endif GDB} +{$ifdef Double_checksum} + store_crc : longint; +{$endif def Double_checksum} s1,s2 : ^string; {Saves stack space} begin consume(_UNIT); @@ -891,6 +958,13 @@ unit pmodules; write_gdb_info; {$endIf Def New_GDB} +{$ifdef Double_CheckSum} +{$ifdef Test_Double_checksum} + if (Errorcount=0) then + writeunitas(current_module^.ppufilename^,punitsymtable(symtablestack),true); +{$endif Test_Double_checksum} +{$endif Double_CheckSum} + { Parse the implementation section } consume(_IMPLEMENTATION); current_module^.in_implementation:=true; @@ -1059,9 +1133,19 @@ unit pmodules; if cs_local_browser in aktmoduleswitches then current_module^.localsymtable:=refsymtable; { Write out the ppufile } +{$ifdef Double_checksum} + store_crc:=current_module^.interface_crc; +{$endif def Double_checksum} if (Errorcount=0) then - writeunitas(current_module^.ppufilename^,punitsymtable(symtablestack)); + writeunitas(current_module^.ppufilename^,punitsymtable(symtablestack),false); +{$ifdef Double_checksum} +{$ifdef Test_Double_checksum} + if store_crc<>current_module^.interface_crc then + Def_comment(V_Warning,current_module^.ppufilename^+' CRC changed '+ + tostr(store_crc)+'<>'+tostr(current_module^.interface_crc)); +{$endif def TestDouble_checksum} +{$endif def Double_checksum} { must be done only after local symtable ref stores !! } closecurrentppu; {$ifdef GDB} @@ -1255,7 +1339,10 @@ unit pmodules; end. { $Log$ - Revision 1.105 1999-03-26 00:05:38 peter + Revision 1.106 1999-04-07 15:39:30 pierre + + double_checksum code added + + Revision 1.105 1999/03/26 00:05:38 peter * released valintern + deffile is now removed when compiling is finished * ^( compiles now correct diff --git a/compiler/ppu.pas b/compiler/ppu.pas index 6ecf7868f1..6aadbd901a 100644 --- a/compiler/ppu.pas +++ b/compiler/ppu.pas @@ -26,7 +26,23 @@ unit ppu; interface +{$ifdef Test_Double_checksum} +var + CRCFile : text; const + CRC_array_Size = 20000; +type + tcrc_array = array[0..crc_array_size] of longint; + pcrc_array = ^tcrc_array; +{$endif Test_Double_checksum} + +const +{$ifndef Double_checksum} + CurrentPPUVersion=15; +{$else Double_checksum} + CurrentPPUVersion=16; +{$endif def Double_checksum} + { buffer sizes } maxentrysize = 1024; {$ifdef TP} @@ -126,6 +142,9 @@ type flags : longint; size : longint; { size of the ppufile without header } checksum : longint; { checksum for this ppufile } +{$ifdef Double_checksum} + interface_checksum : longint; +{$endif def Double_checksum} end; tppuentry=packed record @@ -144,6 +163,18 @@ type header : tppuheader; size,crc : longint; +{$ifdef Double_checksum} +{$ifdef Test_Double_checksum} + crcindex : longint; + crc_index : longint; + crc_test : pcrc_array; +{$endif def Test_Double_checksum} + interface_crc : longint; + do_interface_crc : boolean; + { used to calculate interface_crc + before implementation } + crc_only : boolean; +{$endif def Double_checksum} do_crc, change_endian : boolean; @@ -196,6 +227,11 @@ type implementation +{$ifdef Test_Double_checksum} + uses + comphook; + +{$endif def Test_Double_checksum} {***************************************************************************** Crc 32 *****************************************************************************} @@ -279,6 +315,9 @@ constructor tppufile.init(fn:string); begin fname:=fn; change_endian:=false; +{$ifdef Double_checksum} + crc_only:=false; +{$endif Double_checksum} Mode:=0; NewHeader; Error:=false; @@ -345,7 +384,11 @@ begin Id[3]:='U'; Ver[1]:='0'; Ver[2]:='1'; +{$ifndef Double_checksum} Ver[3]:='5'; +{$else Double_checksum} + Ver[3]:='6'; +{$endif def Double_checksum} end; end; @@ -638,6 +681,10 @@ begin bufidx:=0; {reset} crc:=$ffffffff; +{$ifdef Double_checksum} + interface_crc:=$ffffffff; + do_interface_crc:=true; +{$endif def Double_checksum} Error:=false; do_crc:=true; size:=0; @@ -749,8 +796,40 @@ end; procedure tppufile.putdata(var b;len:longint); begin if do_crc then - crc:=UpdateCrc32(crc,b,len); - writedata(b,len); + begin + crc:=UpdateCrc32(crc,b,len); +{$ifdef Double_checksum} + if do_interface_crc then + begin + interface_crc:=UpdateCrc32(interface_crc,b,len); +{$ifdef Test_Double_checksum} + if crc_only then + begin + crc_test^[crc_index]:=interface_crc; +{$ifdef Test_Double_checksum_write} + Writeln(CRCFile,interface_crc); +{$endif Test_Double_checksum_write} + if crc_indexinterface_crc) then + Def_comment(V_Warning,'CRC changed'); +{$ifdef Test_Double_checksum_write} + Writeln(CRCFile,interface_crc); +{$endif Test_Double_checksum_write} + inc(crcindex); + end; +{$endif def Test_Double_checksum} + end; + end; + if not crc_only then +{$else not def Double_checksum} + end; +{$endif def Double_checksum} + writedata(b,len); inc(entryidx,len); end; @@ -795,7 +874,10 @@ end; end. { $Log$ - Revision 1.25 1999-03-02 13:49:18 peter + Revision 1.26 1999-04-07 15:39:31 pierre + + double_checksum code added + + Revision 1.25 1999/03/02 13:49:18 peter * renamed loadunit_int -> loadunit Revision 1.24 1999/02/22 13:07:00 pierre diff --git a/compiler/symdef.inc b/compiler/symdef.inc index 4cbff9ae3b..1710a86254 100644 --- a/compiler/symdef.inc +++ b/compiler/symdef.inc @@ -1521,9 +1521,11 @@ deftype:=formaldef; registerdef:=stregdef; { formaldef must be registered at unit level !! } - if registerdef and assigned(current_module) and - assigned(current_module^.globalsymtable) then - psymtable(current_module^.globalsymtable)^.registerdef(@self); + if registerdef and assigned(current_module) then + if assigned(current_module^.localsymtable) then + psymtable(current_module^.localsymtable)^.registerdef(@self) + else if assigned(current_module^.globalsymtable) then + psymtable(current_module^.globalsymtable)^.registerdef(@self); savesize:=target_os.size_of_pointer; end; @@ -2103,8 +2105,14 @@ begin inherited write; writedefref(retdef); +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=false; +{$endif def Double_checksum} writebyte(fpu_used); writelong(options); +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=true; +{$endif def Double_checksum} hp:=para1; count:=0; while assigned(hp) do @@ -2453,6 +2461,9 @@ Const local_symtable_index : longint = $8001; procedure tprocdef.write; begin inherited write; +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=false; +{$endif def Double_checksum} {$ifdef i386} writebyte(usedregisters); {$endif i386} @@ -2465,6 +2476,9 @@ Const local_symtable_index : longint = $8001; {$endif alpha} writestring(mangledname); writelong(extnumber); +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=true; +{$endif def Double_checksum} if (options and pooperator) = 0 then writedefref(nextoverloaded) else @@ -3409,7 +3423,10 @@ Const local_symtable_index : longint = $8001; { $Log$ - Revision 1.98 1999-03-06 17:24:16 peter + Revision 1.99 1999-04-07 15:39:32 pierre + + double_checksum code added + + Revision 1.98 1999/03/06 17:24:16 peter * reset savesize in tdef.init Revision 1.97 1999/03/01 13:45:04 pierre diff --git a/compiler/symppu.inc b/compiler/symppu.inc index 8df4b36eea..c5cb6341ab 100644 --- a/compiler/symppu.inc +++ b/compiler/symppu.inc @@ -167,19 +167,32 @@ hp:=pused_unit(current_module^.used_units.first); while assigned(hp) do begin +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=hp^.in_interface; +{$endif Double_checksum} current_ppu^.putstring(hp^.name^); - { the checksum should not affect the crc of this unit ! (PFV) } current_ppu^.do_crc:=false; +{$ifndef Double_checksum} + { the checksum should not affect the crc of this unit ! (PFV) } current_ppu^.putlongint(hp^.checksum); +{$else Double_checksum} + if hp^.in_interface then + current_ppu^.putlongint(hp^.checksum) + else + current_ppu^.putlongint(hp^.interface_checksum); +{$endif def Double_checksum} current_ppu^.do_crc:=true; current_ppu^.putbyte(byte(hp^.in_interface)); hp:=pused_unit(hp^.next); end; +{$ifdef Double_checksum} + current_ppu^.do_interface_crc:=true; +{$endif Double_checksum} current_ppu^.writeentry(ibloadunit); end; - procedure writeunitas(const s : string;unittable : punitsymtable); + procedure writeunitas(const s : string;unittable : punitsymtable;only_crc : boolean); begin Message1(unit_u_ppu_write,s); @@ -207,11 +220,33 @@ 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); +{$ifdef Double_checksum} + 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} +{$endif Double_checksum} + current_ppu^.change_endian:=source_os.endian<>target_os.endian; { write symbols and definitions } unittable^.writeasunit; @@ -221,6 +256,9 @@ { create and write header } current_ppu^.header.size:=current_ppu^.size; current_ppu^.header.checksum:=current_ppu^.crc; +{$ifdef Double_checksum} + current_module^.interface_crc:=current_ppu^.interface_crc; +{$endif def Double_checksum} current_ppu^.header.compiler:=wordversion; current_ppu^.header.cpu:=word(target_cpu); current_ppu^.header.target:=word(target_info.target); @@ -228,10 +266,29 @@ current_ppu^.writeheader; { save crc in current_module also } current_module^.crc:=current_ppu^.crc; +{$ifdef Double_checksum} + 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} +{$endif def Double_checksum} 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); @@ -451,7 +508,10 @@ { $Log$ - Revision 1.34 1999-03-02 13:49:19 peter + 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