Ver código fonte

Use proper types for version and statistics

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8541 8c9fc860-2736-0410-a75d-ab315db34111
negelef 6 anos atrás
pai
commit
ab6c93f5ea
3 arquivos alterados com 32 adições e 33 exclusões
  1. 4 4
      source/FoxGenericObjectFile.Mod
  2. 7 7
      source/GenericLinker.Mod
  3. 21 22
      source/ObjectFile.Mod

+ 4 - 4
source/FoxGenericObjectFile.Mod

@@ -467,9 +467,9 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 	BEGIN NEW(objectFileFormat); RETURN objectFileFormat
 	END Get;
 
-	PROCEDURE ReadHeader(reader: Streams.Reader; VAR binary: BOOLEAN; VAR poolMap: ObjectFile.PoolMap; VAR offers, requires: ObjectFile.NameList): LONGINT;
+	PROCEDURE ReadHeader(reader: Streams.Reader; VAR binary: BOOLEAN; VAR poolMap: ObjectFile.PoolMap; VAR offers, requires: ObjectFile.NameList): WORD;
 	VAR ch: CHAR; string: ARRAY 32 OF CHAR;
-	VAR version: LONGINT;
+	VAR version: WORD;
 	BEGIN
 		reader.String(string);
 		binary := string="FoxOFB";
@@ -597,7 +597,7 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 		fileName: Files.FileName; file: Files.File; reader: Files.Reader; writer: Streams.Writer;
 		section: ObjectFile.Section; binary: BOOLEAN; poolMap, poolMapDummy: ObjectFile.PoolMap;
 		offers, requires: ObjectFile.NameList;
-		version: LONGINT;
+		version: WORD;
 	BEGIN
 		IF context.arg.GetString(fileName) THEN
 			file := Files.Old(fileName);
@@ -632,7 +632,7 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 		 dest: Files.FileName;
 		 writer: Files.Writer;
 		 name: ObjectFile.SegmentedName;
-		 version: LONGINT;
+		 version: WORD;
 		 offers, requires: ObjectFile.NameList;
 	BEGIN
 		NEW(sectionList);

+ 7 - 7
source/GenericLinker.Mod

@@ -358,17 +358,17 @@ VAR
 	END Arrange;
 
 	PROCEDURE Patch (block: Block);
-	VAR arrangement: Arrangement; i: LONGINT;
+	VAR arrangement: Arrangement; i: SIZE;
 
 		PROCEDURE PatchFixup (CONST fixup: ObjectFile.Fixup);
-		VAR reference: Block; target, address: Address; i: LONGINT;
+		VAR reference: Block; target, address: Address; i: SIZE;
 
 			PROCEDURE PatchPattern (CONST pattern: ObjectFile.FixupPattern);
 			BEGIN arrangement.Patch (target, address, pattern.offset, pattern.bits, block.unit); address := ASH (address, -pattern.bits);
 			END PatchPattern;
 
 			PROCEDURE CheckBits(pattern: ObjectFile.Pattern; offset: LONGINT);
-			VAR i, nobits,remainder: LONGINT; minval, maxval: ObjectFile.Unit; name: ObjectFile.SectionName; number: ARRAY 32 OF CHAR;
+			VAR i: SIZE; nobits, remainder: LONGINT; minval, maxval: ObjectFile.Unit; name: ObjectFile.SectionName; number: ARRAY 32 OF CHAR;
 			BEGIN
 				nobits := 0;
 				FOR i := 0 TO pattern.patterns-1 DO
@@ -391,7 +391,7 @@ VAR
 			END CheckBits;
 
 			PROCEDURE ApplyPatch(pattern: ObjectFile.Pattern; CONST patch: ObjectFile.Patch);
-			VAR j: LONGINT;
+			VAR j: SIZE;
 			BEGIN
 				target := block.address + patch.offset;
 				address := reference.address + patch.displacement;
@@ -476,7 +476,7 @@ BEGIN
 END GetPriority;
 
 PROCEDURE Header(reader: Streams.Reader; linker: Linker; VAR binary: BOOLEAN; VAR poolMap: ObjectFile.PoolMap; VAR offers, requires: ObjectFile.NameList): LONGINT;
-VAR ch: CHAR; version: LONGINT; string: ARRAY 32 OF CHAR;
+VAR ch: CHAR; version: WORD; string: ARRAY 32 OF CHAR;
 BEGIN
 	reader.String(string);
 	binary := string="FoxOFB";
@@ -513,13 +513,13 @@ BEGIN
 END Header;
 
 PROCEDURE OffersRequires*(reader: Streams.Reader; VAR offers, requires: ObjectFile.NameList);
-VAR binary: BOOLEAN; poolMap: ObjectFile.PoolMap;  version: LONGINT;
+VAR binary: BOOLEAN; poolMap: ObjectFile.PoolMap;  version: WORD;
 BEGIN
 	version := Header(reader, NIL, binary, poolMap, offers, requires);
 END OffersRequires;
 
 PROCEDURE Process* (reader: Streams.Reader; linker: Linker);
-VAR section: ObjectFile.Section; binary: BOOLEAN; poolMap: ObjectFile.PoolMap; offers, requires: ObjectFile.NameList; version: LONGINT;
+VAR section: ObjectFile.Section; binary: BOOLEAN; poolMap: ObjectFile.PoolMap; offers, requires: ObjectFile.NameList; version: WORD;
 BEGIN
 	version := Header(reader, linker, binary, poolMap, offers, requires);
 	WHILE reader.Peek () # 0X DO

+ 21 - 22
source/ObjectFile.Mod

@@ -246,18 +246,18 @@ VAR
 
 
 
-	statHeaders, statHeadersSize: LONGINT;
-	statFixups, statFixupsSize, statFixupPatterns, statFixupPatches: LONGINT;
-	statAliases, statAliasesSize: LONGINT;
-	statSegments, statSegmentsSize: LONGINT;
+	statHeaders, statHeadersSize: SIZE;
+	statFixups, statFixupsSize, statFixupPatterns, statFixupPatches: SIZE;
+	statAliases, statAliasesSize: SIZE;
+	statSegments, statSegmentsSize: SIZE;
 
-	statCodeSections, statCodeSectionsSize: LONGINT;
-	statDataSections, statDataSectionsSize: LONGINT;
-	statConstSections, statConstSectionsSize: LONGINT;
-	statInitSections, statInitSectionsSize: LONGINT;
-	statBodySections, statBodySectionsSize: LONGINT;
+	statCodeSections, statCodeSectionsSize: SIZE;
+	statDataSections, statDataSectionsSize: SIZE;
+	statConstSections, statConstSectionsSize: SIZE;
+	statInitSections, statInitSectionsSize: SIZE;
+	statBodySections, statBodySectionsSize: SIZE;
 
-	statSections, statSectionsTotalSize: LONGINT;
+	statSections, statSectionsTotalSize: SIZE;
 
 
 	PROCEDURE IsCode* (type: SectionType): BOOLEAN;
@@ -519,7 +519,7 @@ VAR
 		writer.Ln;
 	END WriteSectionTextual;
 
-	PROCEDURE ReadSectionTextual (reader: Streams.Reader; version: LONGINT; VAR section: Section);
+	PROCEDURE ReadSectionTextual (reader: Streams.Reader; version: WORD; VAR section: Section);
 	VAR i, size: LONGINT; char: CHAR; relocatibility: INTEGER; priority: LONGINT;
 
 		PROCEDURE ReadValueIdentifier (VAR value: INTEGER; CONST identifiers: ARRAY OF ARRAY OF CHAR);
@@ -889,7 +889,7 @@ VAR
 		END;
 	END WriteSectionBinary;
 
-	PROCEDURE ReadSectionBinary (reader: Streams.Reader; version: LONGINT; VAR section: Section; poolMap: PoolMap);
+	PROCEDURE ReadSectionBinary (reader: Streams.Reader; version: WORD; VAR section: Section; poolMap: PoolMap);
 	VAR i, size: LONGINT; relocatibility: INTEGER; ch: CHAR; priority: LONGINT;
 	CONST ByteSize=8;
 
@@ -1054,7 +1054,7 @@ VAR
 		END;
 	END ReadSectionBinary;
 
-	PROCEDURE ReadSection*(reader: Streams.Reader; version: LONGINT; VAR section: Section; binary: BOOLEAN; poolMap: PoolMap);
+	PROCEDURE ReadSection*(reader: Streams.Reader; version: WORD; VAR section: Section; binary: BOOLEAN; poolMap: PoolMap);
 	BEGIN
 		IF binary THEN
 			ReadSectionBinary(reader,version, section,poolMap)
@@ -1212,7 +1212,7 @@ VAR
 	END AddAlias;
 
 	PROCEDURE StringToSegmentedName*(CONST name: ARRAY OF CHAR; VAR segmentedName: SegmentedName);
-	VAR i,j,segment: LONGINT; n: SectionName;
+	VAR i, j, segment: SIZE; n: SectionName;
 	BEGIN
 		(* convert a string of the form A.B.C.suffix to [S(A), S(B), S(C), S(suffix)] *)
 		segment := 0; i := 0;
@@ -1235,7 +1235,7 @@ VAR
 	END StringToSegmentedName;
 
 	PROCEDURE SegmentedNameToString*(CONST segmentedName: SegmentedName; VAR name: ARRAY OF CHAR);
-	VAR i,j, segment: LONGINT; n: SectionName;
+	VAR i, j, segment: SIZE; n: SectionName;
 	BEGIN
 		i := 0; segment := 0;
 		WHILE (segment < LEN(segmentedName)) & (segmentedName[segment] >= 0) DO
@@ -1251,8 +1251,8 @@ VAR
 	END SegmentedNameToString;
 	
 	(* result = 0 : equal strings, result < 0: s1 before s2, result > 0 : s1 after s2 (alphanumerically) *)
-	PROCEDURE CompareSegmentedNames*(CONST s1, s2: SegmentedName): LONGINT;
-	VAR n1, n2: SectionName; index: LONGINT; ch1, ch2: CHAR;
+	PROCEDURE CompareSegmentedNames*(CONST s1, s2: SegmentedName): WORD;
+	VAR n1, n2: SectionName; index: SIZE; ch1, ch2: CHAR;
 	BEGIN
 		SegmentedNameToString(s1,n1);
 		SegmentedNameToString(s2,n2);
@@ -1267,9 +1267,8 @@ VAR
 		RETURN ORD(ch1) - ORD(ch2);
 	END CompareSegmentedNames;
 
-
 	OPERATOR "="*(CONST l,r: SegmentedName): BOOLEAN;
-	VAR i: LONGINT;
+	VAR i: SIZE;
 	BEGIN
 		i := 0; WHILE (i < LEN(l)) & (l[i] = r[i]) & (l[i] # -1)  DO INC(i) END; RETURN (i = LEN(l)) OR (l[i] = r[i]);
 	END "=";
@@ -1295,7 +1294,7 @@ VAR
 	END ":=";
 
 	OPERATOR "="*(CONST l: SegmentedName; CONST r: ARRAY OF CHAR): BOOLEAN;
-	VAR i,j,segment: LONGINT; n: SectionName;
+	VAR i, j, segment: SIZE; n: SectionName;
 	BEGIN
 		i := 0; segment := 0;
 		WHILE (segment < LEN(l)) DO
@@ -1333,13 +1332,13 @@ VAR
 	END "#";
 
 	OPERATOR "#"*(CONST l,r: SegmentedName): BOOLEAN;
-	VAR i: LONGINT;
+	VAR i: SIZE;
 	BEGIN
 		i := 0; WHILE (i<LEN(l)) & (l[i] = r[i]) & (l[i] # -1)  DO INC(i) END; RETURN (i<LEN(l)) & (l[i] # r[i]);
 	END "#";
 
 	PROCEDURE Statistics*;
-	VAR sections: LONGINT; sectionsContentSize: LONGINT;
+	VAR sections, sectionsContentSize: SIZE;
 	BEGIN
 		TRACE(statHeaders, statHeadersSize);
 		TRACE(statFixups, statFixupsSize, statFixupPatterns, statFixupPatches);