Ver código fonte

* ppudump: JSON output of sets and set constants.

git-svn-id: trunk@24394 -
yury 12 anos atrás
pai
commit
679a8d9dd6
2 arquivos alterados com 82 adições e 14 exclusões
  1. 27 10
      compiler/utils/ppuutils/ppudump.pp
  2. 55 4
      compiler/utils/ppuutils/ppuout.pp

+ 27 - 10
compiler/utils/ppuutils/ppudump.pp

@@ -2182,8 +2182,10 @@ begin
                constpointer :
                  begin
                    write  ([space,'  PointerType : ']);
-                   readderef('');
-                   writeln([space,'        Value : ',getaint])
+                   readderef('',constdef.TypeRef);
+                   constdef.ConstType:=ctInt;
+                   constdef.VInt:=getaint;
+                   writeln([space,'        Value : ',constdef.VInt])
                  end;
                conststring,
                constresourcestring :
@@ -2238,8 +2240,9 @@ begin
                  end;
                constset :
                  begin
+                   constdef.ConstType:=ctSet;
                    write ([space,'      Set Type : ']);
-                   readderef('');
+                   readderef('',constdef.TypeRef);
                    for i:=1to 4 do
                     begin
                       write ([space,'        Value : ']);
@@ -2247,13 +2250,19 @@ begin
                        begin
                          if j>1 then
                           write(',');
-                         write(hexstr(getbyte,2));
+                         b:=getbyte;
+                         write(hexstr(b,2));
+                         constdef.VSet[i*j-1]:=b;
                        end;
                       writeln;
                     end;
                  end;
                constnil:
-                 writeln([space,' NIL pointer.']);
+                 begin
+                   writeln([space,' NIL pointer.']);
+                   constdef.ConstType:=ctPtr;
+                   constdef.VInt:=0;
+                 end;
                constwstring :
                  begin
                    initwidestring(pw);
@@ -2498,6 +2507,7 @@ var
   objdef: TPpuObjectDef absolute def;
   arrdef: TPpuArrayDef absolute def;
   enumdef: TPpuEnumDef absolute def;
+  setdef: TPpuSetDef absolute def;
 begin
   with ppufile do
    begin
@@ -2506,6 +2516,7 @@ begin
      if readentry<>ibstartdefs then
       Writeln('!! ibstartdefs not found');
      repeat
+       def:=nil;
        b:=readentry;
        case b of
 
@@ -2887,12 +2898,16 @@ begin
 
          ibsetdef :
            begin
-             readcommondef('Set definition',defoptions);
+             setdef:=TPpuSetDef.Create(ParentDef);
+             readcommondef('Set definition',defoptions,setdef);
              write  ([space,'     Element type : ']);
-             readderef('');
-             writeln([space,'             Size : ',getaint]);
-             writeln([space,'         Set Base : ',getaint]);
-             writeln([space,'          Set Max : ',getaint]);
+             readderef('',setdef.ElType);
+             setdef.Size:=getaint;
+             writeln([space,'             Size : ',setdef.Size]);
+             setdef.SetBase:=getaint;
+             writeln([space,'         Set Base : ',setdef.SetBase]);
+             setdef.SetMax:=getaint;
+             writeln([space,'          Set Max : ',setdef.SetMax]);
            end;
 
          ibvariantdef :
@@ -2926,6 +2941,8 @@ begin
              SetHasErrors;
            end;
        end;
+       if (def <> nil) and (def.Parent = nil) then
+         def.Free;
        if not EndOfEntry then
          HasMoreInfos;
      until false;

+ 55 - 4
compiler/utils/ppuutils/ppuout.pp

@@ -204,7 +204,7 @@ type
     constructor Create(AParent: TPpuContainerDef); override;
   end;
 
-  TPpuConstType = (ctInt, ctFloat, ctStr);
+  TPpuConstType = (ctInt, ctFloat, ctStr, ctSet, ctPtr);
 
   { TPpuConstDef }
   TPpuConstDef = class(TPpuDef)
@@ -216,6 +216,7 @@ type
     VInt: Int64;
     VFloat: extended;
     VStr: string;
+    VSet: array[0..31] of byte;
     constructor Create(AParent: TPpuContainerDef); override;
     destructor Destroy; override;
   end;
@@ -319,13 +320,24 @@ type
   protected
     procedure BeforeWriteItems(Output: TPpuOutput); override;
   public
-    ElLow, ElHigh: Int64;
+    ElLow, ElHigh: integer;
     Size: byte;
     CopyFrom: TPpuRef;
     constructor Create(AParent: TPpuContainerDef); override;
     destructor Destroy; override;
   end;
 
+  { TPpuSetDef }
+  TPpuSetDef = class(TPpuDef)
+  protected
+    procedure WriteDef(Output: TPpuOutput); override;
+  public
+    ElType: TPpuRef;
+    SetBase, SetMax: integer;
+    Size: byte;
+    constructor Create(AParent: TPpuContainerDef); override;
+    destructor Destroy; override;
+  end;
 
 implementation
 
@@ -354,7 +366,7 @@ const
     ('dynamic');
 
   ConstTypeNames: array[TPpuConstType] of string =
-    ('int', 'float', 'string');
+    ('int', 'float', 'string', 'set', 'pointer');
 
   SymIdBit = $80000000;
   InvalidId = cardinal(-1);
@@ -365,6 +377,32 @@ begin
   Result:=Id and SymIdBit <> 0;
 end;
 
+{ TPpuSetDef }
+
+procedure TPpuSetDef.WriteDef(Output: TPpuOutput);
+begin
+  inherited WriteDef(Output);
+  with Output do begin
+    WriteInt('Size', Size);
+    WriteInt('Base', SetBase);
+    WriteInt('Max', SetMax);
+  end;
+  ElType.Write(Output, 'ElType');
+end;
+
+constructor TPpuSetDef.Create(AParent: TPpuContainerDef);
+begin
+  inherited Create(AParent);
+  DefType:=dtSet;
+  ElType:=TPpuRef.Create;
+end;
+
+destructor TPpuSetDef.Destroy;
+begin
+  ElType.Free;
+  inherited Destroy;
+end;
+
 { TPpuEnumDef }
 
 procedure TPpuEnumDef.BeforeWriteItems(Output: TPpuOutput);
@@ -397,7 +435,8 @@ end;
 
 procedure TPpuConstDef.WriteDef(Output: TPpuOutput);
 var
-  s: string;
+  s, ss: string;
+  i: integer;
 begin
   inherited WriteDef(Output);
   with Output do begin
@@ -410,6 +449,18 @@ begin
         WriteFloat(s, VFloat);
       ctStr:
         WriteStr(s, VStr);
+      ctPtr:
+        if VInt = 0 then
+          WriteNull(s)
+        else
+          WriteStr(s, hexStr(QWord(VInt), SizeOf(pointer)*2));
+      ctSet:
+        begin
+          ss:='';
+          for i:=Low(VSet) to High(VSet) do
+            ss:=ss + hexStr(VSet[i], 2);
+          WriteStr(s, ss);
+        end;
     end;
   end;
   if not TypeRef.IsNull then