Browse Source

Added support for 64-bit fingerprints

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8522 8c9fc860-2736-0410-a75d-ab315db34111
negelef 6 years ago
parent
commit
f7dd7cdb70

+ 17 - 34
source/FoxFingerprinter.Mod

@@ -812,21 +812,23 @@ TYPE
 
 		(* fp = fp & (HugeInt | Number) *)
 		PROCEDURE VisitIntegerValue*(x: SyntaxTree.IntegerValue);
-		BEGIN FPHugeInt(SELF.fp,x.value)
+		BEGIN FPNumber(SELF.fp,x.value)
 		END VisitIntegerValue;
 
 		(* fp = fp & (HugeInt | Number) *)
 		PROCEDURE VisitEnumerationValue*(x: SyntaxTree.EnumerationValue);
-		BEGIN FPHugeInt(SELF.fp,x.value)
+		BEGIN FPNumber(SELF.fp,x.value)
 		END VisitEnumerationValue;
 
 		(* fp = fp & ORD(char) *)
 		PROCEDURE VisitCharacterValue*(x: SyntaxTree.CharacterValue);
-		BEGIN FPNumber(SELF.fp,ORD(x.value)) END VisitCharacterValue;
+		BEGIN FPNumber(SELF.fp,ORD(x.value))
+		END VisitCharacterValue;
 
 		(* fp = fp & Set *)
 		PROCEDURE VisitSetValue*(x: SyntaxTree.SetValue);
-		BEGIN FPHugeInt(SELF.fp,SYSTEM.VAL(HUGEINT,x.value)) END VisitSetValue;
+		BEGIN FPSet(SELF.fp,x.value)
+		END VisitSetValue;
 
 		PROCEDURE VisitMathArrayExpression*(x: SyntaxTree.MathArrayExpression);
 		VAR element: SyntaxTree.Expression; i: LONGINT;
@@ -845,20 +847,17 @@ TYPE
 
 		(* fp = fp & (Real | LongReal) *)
 		PROCEDURE VisitRealValue*(x: SyntaxTree.RealValue);
-		BEGIN
-			IF x.type.sizeInBits=32 THEN FPReal(SELF.fp,SHORT(x.value))
-			ELSE FPLongReal(SELF.fp,x.value)
-			END;
+		BEGIN FPReal(SELF.fp,x.value);
 		END VisitRealValue;
 
 		PROCEDURE VisitComplexValue*(x: SyntaxTree.ComplexValue);
 		BEGIN
-			FPLongReal(SELF.fp,x.realValue);
-			FPLongReal(SELF.fp,x.imagValue);
+			FPReal(SELF.fp,x.realValue);
+			FPReal(SELF.fp,x.imagValue);
 		END VisitComplexValue;
 		
 		PROCEDURE VisitNilValue*(x: SyntaxTree.NilValue);
-		BEGIN IF x.type.sizeInBits = 64 THEN FPHugeInt(SELF.fp, 0) ELSE FPNumber(SELF.fp, 0) END;
+		BEGIN FPNumber(SELF.fp, 0);
 		END VisitNilValue;
 
 		(* fp = fp & String *)
@@ -1315,37 +1314,21 @@ TYPE
 	END IsOberonProcedure;
 
 	(* fp = fp <*> val *)
-	PROCEDURE FPNumber*(VAR fp: Basic.Fingerprint; val: LONGINT);
+	PROCEDURE FPNumber*(VAR fp: Basic.Fingerprint; val: HUGEINT);
 	BEGIN
-		fp:=SYSTEM.VAL(LONGINT, SYSTEM.VAL(SET, ROT(fp, 7)) / SYSTEM.VAL(SET, val))
+		fp:=SYSTEM.VAL(Basic.Fingerprint, SYSTEM.VAL(SET64, ROT(fp, 7)) / SYSTEM.VAL(SET64, val))
 	END FPNumber;
 
 	(* fp = fp <*> set *)
-	PROCEDURE FPSet*(VAR fp: Basic.Fingerprint; set: SET);
-	BEGIN FPNumber(fp, SYSTEM.VAL(LONGINT, set))
+	PROCEDURE FPSet*(VAR fp: Basic.Fingerprint; set: SET64);
+	BEGIN FPNumber(fp, SYSTEM.VAL(HUGEINT, set))
 	END FPSet;
 
 	(* fp = fp <*> real *)
-	PROCEDURE FPReal*(VAR fp: Basic.Fingerprint; real: REAL);
-	BEGIN FPNumber(fp, SYSTEM.VAL(LONGINT, real))
+	PROCEDURE FPReal*(VAR fp: Basic.Fingerprint; real: LONGREAL);
+	BEGIN FPNumber(fp, SYSTEM.VAL(HUGEINT, real))
 	END FPReal;
 
-	(* fp = fp <*> low <*> high *)
-	PROCEDURE FPLongReal*(VAR fp: Basic.Fingerprint; lr: LONGREAL);
-		VAR l, h: LONGINT;
-	BEGIN
-		SYSTEM.GET(ADDRESSOF(lr)+4, l); SYSTEM.GET(ADDRESSOF(lr), h);
-		FPNumber(fp, l); FPNumber(fp, h);
-	END FPLongReal;
-
-	(* fp = fp <*> low <*> high *)
-	PROCEDURE FPHugeInt*(VAR fp: Basic.Fingerprint; huge: HUGEINT);
-	VAR l, h: LONGINT;
-	BEGIN
-		SYSTEM.GET(ADDRESSOF(huge)+4, l); SYSTEM.GET(ADDRESSOF(huge), h);
-		FPNumber(fp, l); FPNumber(fp, h);
-	END FPHugeInt;
-
 	(* fp = fp -> String *)
 	PROCEDURE FPName*(VAR fp: Basic.Fingerprint; x: SyntaxTree.Identifier);
 	VAR name: Scanner.IdentifierString;
@@ -1367,7 +1350,7 @@ TYPE
 		ELSIF SyntaxTree.PublicRead IN vis THEN  FPNumber(fp, fpExternR)
 		ELSIF SyntaxTree.Internal * vis #{} THEN  FPNumber(fp, fpIntern)
 		ELSE
-			FPNumber(fp, fpOther + SYSTEM.VAL(LONGINT, vis))
+			FPNumber(fp, fpOther + SYSTEM.VAL(WORD, vis))
 		END
 	END FPVisibility;
 

+ 42 - 39
source/FoxIntermediateBackend.Mod

@@ -12651,6 +12651,13 @@ TYPE
 			IntermediateCode.InitImmediate(op,IntermediateCode.GetType(module.system, module.system.longintType),value);
 			section.Emit(Data(Basic.invalidPosition,op));
 		END Longint;
+
+		PROCEDURE Hugeint(section: IntermediateCode.Section; value: HUGEINT);
+		VAR op: IntermediateCode.Operand;
+		BEGIN
+			IntermediateCode.InitImmediate(op,IntermediateCode.GetType(module.system, module.system.hugeintType),value);
+			section.Emit(Data(Basic.invalidPosition,op));
+		END Hugeint;
 		
 		PROCEDURE PatchSize(section: IntermediateCode.Section; pc: LONGINT; value: LONGINT);
 		VAR op,noOperand: IntermediateCode.Operand;
@@ -13018,49 +13025,45 @@ TYPE
 	ExportArray* = POINTER {UNSAFE} TO ARRAY OF ExportDesc;
 	*)
 	
-		PROCEDURE ExportDesc2(
-			source: IntermediateCode.Section; 
-			namePool: IntermediateCode.Section;
-			fingerprinter: Fingerprinter.Fingerprinter;
-			symbol: Sections.Section;
-			name: StringPool.Index;
-			VAR patchAdr: LONGINT
-			): BOOLEAN;
-		VAR fingerprint: SyntaxTree.Fingerprint; 
-		BEGIN
-			(*IF  (implementationVisitor.backend.cooperative) & (symbol.symbol = NIL) OR (symbol.symbol # NIL) & (symbol.type # Sections.InitCodeSection)
-				& (symbol.type # Sections.InlineCodeSection)
-			THEN
-			*)
-			IF (symbol = NIL) OR ( (implementationVisitor.backend.cooperative) & (symbol.symbol = NIL) OR (symbol.symbol # NIL) & (symbol.type # Sections.InitCodeSection) & (symbol.type # Sections.EntryCodeSection)
-				& (symbol.type # Sections.ExitCodeSection)
-				& (symbol.type # Sections.InlineCodeSection))
-			THEN
+			PROCEDURE ExportDesc2(
+				source: IntermediateCode.Section; 
+				namePool: IntermediateCode.Section;
+				fingerprinter: Fingerprinter.Fingerprinter;
+				symbol: Sections.Section;
+				name: StringPool.Index;
+				VAR patchAdr: LONGINT
+				): BOOLEAN;
+			VAR fingerprint: SyntaxTree.Fingerprint; 
+			BEGIN
+				(*IF  (implementationVisitor.backend.cooperative) & (symbol.symbol = NIL) OR (symbol.symbol # NIL) & (symbol.type # Sections.InitCodeSection)
+					& (symbol.type # Sections.InlineCodeSection)
+				THEN
+				*)
+				IF (symbol = NIL) OR ( (implementationVisitor.backend.cooperative) & (symbol.symbol = NIL) OR (symbol.symbol # NIL) & (symbol.type # Sections.InitCodeSection) & (symbol.type # Sections.EntryCodeSection)
+					& (symbol.type # Sections.ExitCodeSection)
+					& (symbol.type # Sections.InlineCodeSection))
+				THEN
 
-				IF (symbol = NIL) OR (symbol # NIL) & (symbol.type # Sections.InlineCodeSection) THEN
-					IF (symbol # NIL) & (symbol.symbol # NIL) THEN 
-						fingerprint := fingerprinter.SymbolFP(symbol.symbol);
-						Longint(source,fingerprint.public);
-					ELSE
+					IF (symbol = NIL) OR (symbol # NIL) & (symbol.type # Sections.InlineCodeSection) THEN
+						IF (symbol # NIL) & (symbol.symbol # NIL) THEN 
+							fingerprint := fingerprinter.SymbolFP(symbol.symbol);
+							Hugeint(source,fingerprint.public);
+						ELSE
+							Hugeint(source, 0);
+						END;
+					
+						Symbol(source, namePool, DynamicName(namePool, name, poolMap), 0); (* reference to dynamic name *)
+						Symbol(source, symbol,0,0);
+						patchAdr := source.pc;
 						Longint(source, 0);
+						IF module.system.addressType.sizeInBits = 64 THEN Longint(source, 0); END;
+						Address(source,0);
 					END;
-					IF module.system.addressType.sizeInBits = 64 THEN Longint(source, 0);END;
-
-					
-					Symbol(source, namePool, DynamicName(namePool, name, poolMap), 0); (* reference to dynamic name *)
-					Symbol(source, symbol,0,0);
-					patchAdr := source.pc;
-					Longint(source, 0);
-					IF module.system.addressType.sizeInBits = 64 THEN Longint(source, 0); END;
-					Address(source,0);
+					RETURN TRUE
+				ELSE
+					RETURN FALSE
 				END;
-				RETURN TRUE
-			ELSE
-				RETURN FALSE
-			END;
-		END ExportDesc2;
-		
-		
+			END ExportDesc2;
 			
 			PROCEDURE Export(CONST sections: ARRAY OF Sections.Section);
 			VAR level, olevel, s: LONGINT; prev, this: Basic.SegmentedName; name: ARRAY 256 OF CHAR;

+ 2 - 2
source/FoxIntermediateCode.Mod

@@ -695,7 +695,7 @@ TYPE
 				w.RawLInt(operand.offset);
 			ELSIF operand.symbol.name # "" THEN
 				Basic.WriteSegmentedName(w,operand.symbol.name);
-				IF operand.symbol.fingerprint # 0 THEN w.RawLInt(operand.symbol.fingerprint);END;
+				IF operand.symbol.fingerprint # 0 THEN w.RawHInt(operand.symbol.fingerprint);END;
 				w.RawLInt(operand.symbolOffset);
 				w.RawLInt(operand.offset);
 			ELSE w.RawLInt(SHORT(operand.intValue));
@@ -708,7 +708,7 @@ TYPE
 		|ModeImmediate:
 			IF operand.symbol.name # "" THEN
 				Basic.WriteSegmentedName(w,operand.symbol.name);
-				IF operand.symbol.fingerprint # 0 THEN w.RawLInt(operand.symbol.fingerprint);END;
+				IF operand.symbol.fingerprint # 0 THEN w.RawHInt(operand.symbol.fingerprint);END;
 				w.RawLInt(operand.symbolOffset);
 				w.RawLInt(operand.offset);
 			ELSE

+ 2 - 2
source/FoxMinosObjectFile.Mod

@@ -413,7 +413,7 @@ TYPE
 		BEGIN
 			Global.ModuleFileName(module.module.name,module.module.context,moduleName);
 			fp := fingerprinter.SymbolFP(module.module);
-			w.RawString(moduleName); w.RawLInt(fp.public);
+			w.RawString(moduleName); w.RawLInt(LONGINT(fp.public));
 			w.RawLInt(FixSelf());
 			Imports;
 			Commands;
@@ -476,7 +476,7 @@ TYPE
 					END;
 					w.RawString(name);
 					fp := fingerprinter.SymbolFP(import.module);
-					w.RawLInt(fp.public);
+					w.RawLInt(LONGINT(fp.public));
 
 					(* get all imported entries of imported module *)
 					GetEntries(import.module.moduleScope, numberEntries, entries);

+ 1 - 1
source/FoxPrintout.Mod

@@ -399,7 +399,7 @@ TYPE
 		END FlagEnd;
 
 
-		PROCEDURE Value(identifier: SyntaxTree.Identifier; value: LONGINT; VAR first: BOOLEAN);
+		PROCEDURE Value(identifier: SyntaxTree.Identifier; value: HUGEINT; VAR first: BOOLEAN);
 		BEGIN
 			Flag(identifier,first);
 			w.String("("); w.Int(value,1); w.String(")");

+ 1 - 1
source/FoxSections.Mod

@@ -133,7 +133,7 @@ TYPE
 			Basic.WriteSegmentedName(w,name);
 			w.RawBool(fixed);
 			w.RawLInt(positionOrAlignment); 
-			w.RawLInt(fingerprint);
+			w.RawHInt(fingerprint);
 			w.RawLInt(bitsPerUnit);
 		END WriteRaw;
 

+ 5 - 5
source/Loader.Mod

@@ -286,7 +286,7 @@ TYPE
 							END;
 						END;
 					END;
-					modList.Put(scope.fp, adr)
+					modList.Put(SIZE(scope.fp), adr)
 				END;
 				FOR i := 0 TO scope.exports-1 DO
 					IF scope.dsc # NIL THEN TraverseScopes(scope.dsc[i],level+1) END;
@@ -332,7 +332,7 @@ TYPE
 				IF identifier.fingerprint = 0 THEN (* not identifiable via fingerprint *)
 					block := FindBlock^(identifier);
 				ELSE
-					any := hash.Get(identifier.fingerprint);
+					any := hash.Get(SYSTEM.VAL(SIZE, identifier.fingerprint));
 					IF any # NIL THEN block := any(GenericLinker.Block)  (* local block *) END;
 					IF (block # NIL) & (block.identifier.name # identifier.name) THEN (* local block, false or duplicate fingerprint *)
 						block := FindBlock^(identifier)
@@ -345,7 +345,7 @@ TYPE
 		PROCEDURE ExportBlock*(block: GenericLinker.Block);
 		BEGIN
 			IF block.identifier.fingerprint # 0 THEN
-				hash.Put(block.identifier.fingerprint, block)
+				hash.Put(SYSTEM.VAL(SIZE, block.identifier.fingerprint), block)
 			END;
 			IF (block.identifier.name[0] >= 0) & (block.identifier.name[1] >= 0)  THEN
 				IF (block.identifier.name[1] = InternalModuleName) & (block.identifier.name[2]<0) OR (block.identifier.name[2] = InternalModuleName) & (block.identifier.name[3] < 0) THEN
@@ -358,7 +358,7 @@ TYPE
 		VAR name: Modules.Name; res: WORD;
 			msg: ARRAY 128 OF CHAR; module: Modules.Module; adr: ADDRESS; m: HashTableInt;
 			s: ObjectFile.SectionName; isModule: BOOLEAN; identifier: ObjectFile.Identifier;
-			fp: LONGINT;
+			fp: HUGEINT;
 
 			PROCEDURE CheckName(n: StringPool.Index;  name {UNTRACED}: Modules.DynamicName): LONGINT;
 			VAR s: ObjectFile.SectionName; i: LONGINT;
@@ -457,7 +457,7 @@ TYPE
 				(*D.String("Loader Fatal error: did not find block "); s := identifier.name; D.String(s); D.Ln;*)
 				RETURN NIL;
 			ELSE (* found *)
-				importBlock.identifier.fingerprint := LONGINT(fp); importBlock.address := adr
+				importBlock.identifier.fingerprint := fp; importBlock.address := adr
 			END;
 			RETURN importBlock
 		END ImportBlock;

+ 1 - 1
source/Modules.Mod

@@ -52,7 +52,7 @@ TYPE
 	END;
 
 	ExportDesc* = RECORD
-		fp*: ADDRESS;
+		fp*: HUGEINT;
 		name* {UNTRACED}: DynamicName;
 		adr*: ADDRESS;
 		exports*: LONGINT; (* number of exports referenced by ExportArray *)

+ 3 - 3
source/ObjectFile.Mod

@@ -31,7 +31,7 @@ TYPE
 	Unit* = LONGINT;
 	Bits* = LONGINT;
 
-	Fingerprint* = LONGINT;
+	Fingerprint* = HUGEINT;
 
 	SectionType = INTEGER;
 
@@ -543,7 +543,7 @@ VAR
 			reader.SkipWhitespace;
 			reader.String(name);
 			StringToSegmentedName(name,identifier.name);
-			reader.SkipWhitespace; reader.Int (identifier.fingerprint,FALSE);
+			reader.SkipWhitespace; reader.HInt (identifier.fingerprint,FALSE);
 		END ReadIdentifier;
 
 		PROCEDURE ReadPattern(VAR pattern: Pattern);
@@ -920,7 +920,7 @@ VAR
 			WHILE i < LEN(identifier.name) DO
 				identifier.name[i] := -1; INC(i);
 			END;
-			 reader.RawNum (identifier.fingerprint);
+			 reader.RawHNum (identifier.fingerprint);
 		END ReadIdentifier;
 
 		PROCEDURE ReadFixupPattern (VAR pattern: FixupPattern);