Explorar o código

Fix messages to tokenbuufer writing to zvoid problems with PPU

git-svn-id: trunk@18957 -
pierre %!s(int64=14) %!d(string=hai) anos
pai
achega
637a4671d9
Modificáronse 3 ficheiros con 96 adicións e 11 borrados
  1. 3 2
      compiler/globals.pas
  2. 66 5
      compiler/scanner.pas
  3. 27 4
      compiler/utils/ppudump.pp

+ 3 - 2
compiler/globals.pas

@@ -121,7 +121,6 @@ interface
          debugswitches   : tdebugswitches;
          { 0: old behaviour for sets <=256 elements
            >0: round to this size }
-         pmessage : pmessagestaterecord;
          setalloc,
          packenum        : shortint;
 
@@ -144,6 +143,8 @@ interface
 {$if defined(ARM) or defined(AVR)}
         controllertype   : tcontrollertype;
 {$endif defined(ARM) or defined(AVR)}
+         { WARNING: this pointer cannot be written as such in record token }
+         pmessage : pmessagestaterecord;
        end;
 
     const
@@ -361,7 +362,6 @@ interface
         genwpoptimizerswitches : [];
         dowpoptimizerswitches : [];
         debugswitches : [];
-        pmessage : nil;
 
         setalloc : 0;
         packenum : 4;
@@ -433,6 +433,7 @@ interface
 {$if defined(ARM) or defined(AVR)}
         controllertype : ct_none;
 {$endif defined(ARM) or defined(AVR)}
+        pmessage : nil;
       );
 
     var

+ 66 - 5
compiler/scanner.pas

@@ -76,7 +76,12 @@ interface
 
        tcompile_time_predicate = function(var valuedescr: String) : Boolean;
 
-       tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
+       tspecialgenerictoken =
+         (ST_LOADSETTINGS,
+          ST_LINE,
+          ST_COLUMN,
+          ST_FILEINDEX,
+          ST_LOADMESSAGES);
 
        { tscannerfile }
 
@@ -115,7 +120,7 @@ interface
 
           { last settings we stored }
           last_settings : tsettings;
-
+          last_message : pmessagestaterecord;
           { last filepos we stored }
           last_filepos,
           { if nexttoken<>NOTOKEN, then nexttokenpos holds its filepos }
@@ -2049,6 +2054,7 @@ In case not, the value returned can be arbitrary.
           internalerror(200511173);
         recordtokenbuf:=buf;
         fillchar(last_settings,sizeof(last_settings),0);
+        last_message:=nil;
         fillchar(last_filepos,sizeof(last_filepos),0);
       end;
 
@@ -2080,7 +2086,8 @@ In case not, the value returned can be arbitrary.
         t : ttoken;
         s : tspecialgenerictoken;
         len : sizeint;
-        b : byte;
+        b,msgnb : byte;
+        pmsg : pmessagestaterecord;
       begin
         if not assigned(recordtokenbuf) then
           internalerror(200511176);
@@ -2092,10 +2099,39 @@ In case not, the value returned can be arbitrary.
             s:=ST_LOADSETTINGS;
             writetoken(t);
             recordtokenbuf.write(s,1);
-            recordtokenbuf.write(current_settings,sizeof(current_settings));
+            recordtokenbuf.write(current_settings,
+              sizeof(current_settings)-sizeof(pointer));
             last_settings:=current_settings;
           end;
 
+        if current_settings.pmessage<>last_message then
+          begin
+            { use a special token to record it }
+            s:=ST_LOADMESSAGES;
+            writetoken(t);
+            recordtokenbuf.write(s,1);
+            msgnb:=0;
+            pmsg:=current_settings.pmessage;
+            while assigned(pmsg) do
+              begin
+                if msgnb=255 then
+                  { Too many messages }
+                  internalerror(2011090401);
+                inc(msgnb);
+                pmsg:=pmsg^.next;
+              end;
+            recordtokenbuf.write(msgnb,1);
+            pmsg:=current_settings.pmessage;
+            while assigned(pmsg) do
+              begin
+                { What about endianess here? }
+                recordtokenbuf.write(pmsg^.value,sizeof(longint));
+                recordtokenbuf.write(pmsg^.state,sizeof(tmsgstate));
+                pmsg:=pmsg^.next;
+              end;
+            last_message:=current_settings.pmessage;
+          end;
+
         { file pos changes? }
         if current_tokenpos.line<>last_filepos.line then
           begin
@@ -2207,6 +2243,8 @@ In case not, the value returned can be arbitrary.
       var
         wlen : sizeint;
         specialtoken : tspecialgenerictoken;
+        i,mesgnb : byte;
+        pmsg,prevmsg : pmessagestaterecord;
       begin
         if not assigned(replaytokenbuf) then
           internalerror(200511177);
@@ -2282,7 +2320,30 @@ In case not, the value returned can be arbitrary.
                 else
                   case specialtoken of
                     ST_LOADSETTINGS:
-                      replaytokenbuf.read(current_settings,sizeof(current_settings));
+                      replaytokenbuf.read(current_settings,
+                        sizeof(current_settings)-sizeof(pointer));
+                    ST_LOADMESSAGES:
+                      begin
+                        current_settings.pmessage:=nil;
+                        replaytokenbuf.read(mesgnb,sizeof(mesgnb));
+                        if mesgnb>0 then
+                          Comment(V_Error,'Message recordind not yet supported');
+                        for i:=1 to mesgnb do
+                          begin
+                            new(pmsg);
+                            if i=1 then
+                              begin
+                                current_settings.pmessage:=pmsg;
+                                prevmsg:=nil;
+                              end
+                            else
+                              prevmsg^.next:=pmsg;
+                            replaytokenbuf.read(pmsg^.value,sizeof(longint));
+                            replaytokenbuf.read(pmsg^.state,sizeof(tmsgstate));
+                            pmsg^.next:=nil;
+                            prevmsg:=pmsg;
+                          end;
+                      end;
                     ST_LINE:
                       begin
                         replaytokenbuf.read(current_tokenpos.line,sizeof(current_tokenpos.line));

+ 27 - 4
compiler/utils/ppudump.pp

@@ -156,9 +156,15 @@ const
   thus widecharsize seems to always be 2 bytes }
 
   widecharsize : longint = 2;
-type
 
-  tspecialgenerictoken = (ST_LOADSETTINGS,ST_LINE,ST_COLUMN,ST_FILEINDEX);
+{ This type is defined in scanner.pas unit }
+type
+  tspecialgenerictoken = (
+    ST_LOADSETTINGS,
+    ST_LINE,
+    ST_COLUMN,
+    ST_FILEINDEX,
+    ST_LOADMESSAGES);
 
 
 var
@@ -866,6 +872,7 @@ type
     str  : string[30];
   end;
   ptoken=^ttoken;
+  pmsgstate =^tmsgstate;
 const
   defopt : array[1..ord(high(tdefoption))] of tdefopt=(
      (mask:df_unique;         str:'Unique Type'),
@@ -884,12 +891,13 @@ const
   );
 var
   defstates  : tdefstates;
-  i      : longint;
+  i, nb, msgvalue, mesgnb : longint;
   first  : boolean;
   tokenbufsize : longint;
   tokenbuf : pbyte;
   idtoken,
   token : ttoken;
+  state : tmsgstate;
   len : sizeint;
   wstring : widestring;
   astring : ansistring;
@@ -1015,7 +1023,22 @@ begin
                       begin
                         inc(i);
                         write('Settings');
-                        inc(i,sizeof(tsettings));
+                        { This does not load pmessage pointer }
+                        inc(i,sizeof(tsettings)-sizeof(pointer));
+                      end;
+                    ST_LOADMESSAGES:
+                      begin
+                        inc(i);
+                        write('Messages:');
+                        mesgnb:=tokenbuf[i];
+                        inc(i);
+                        for nb:=1 to mesgnb do
+                          begin
+                            msgvalue:=plongint(@tokenbuf[i])^;
+                            inc(i,sizeof(sizeint));
+                            state:=pmsgstate(@tokenbuf[i])^;
+                            inc(i,sizeof(tmsgstate));
+                          end;
                       end;
                     ST_LINE:
                       begin