Selaa lähdekoodia

Use proper type for counting elements

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@8544 8c9fc860-2736-0410-a75d-ab315db34111
negelef 6 vuotta sitten
vanhempi
commit
d60418f613

+ 3 - 3
source/FoxBinaryCode.Mod

@@ -76,7 +76,7 @@ TYPE
 		mode-: INTEGER; (* fixup mode: relative or absolute *)
 		displacement-: Unit; (* displacement of the fixup ('source') *)
 		scale-: ObjectFile.Bits; (* exponent of scale factor (factor=2^scale) *)
-		patterns-: LONGINT;
+		patterns-: SIZE;
 		pattern-: FixupPatterns; (* patterns describing the fixup format, cf. above *)
 		offset-: Unit;
 
@@ -492,7 +492,7 @@ TYPE
 		END GetBits;
 
 		PROCEDURE ApplyFixup*(fixup: Fixup): BOOLEAN;
-		VAR address,i: LONGINT;
+		VAR address: LONGINT; i: SIZE;
 
 			PROCEDURE PatchPattern (CONST pattern: ObjectFile.FixupPattern);
 			BEGIN
@@ -503,7 +503,7 @@ TYPE
 			END PatchPattern;
 
 			PROCEDURE CheckBits(): BOOLEAN;
-			VAR nobits,remainder,i: LONGINT;
+			VAR nobits,remainder: LONGINT; i: SIZE;
 			BEGIN
 				nobits := 0;
 				FOR i := 0 TO fixup.patterns-1 DO

+ 5 - 5
source/FoxGenericObjectFile.Mod

@@ -384,11 +384,11 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 
 
 	PROCEDURE CopyFixups(sections: Sections.SectionList; from, to: BinaryCode.Section; offset: LONGINT);
-	VAR fixup: BinaryCode.Fixup; i: INTEGER; index: LONGINT;	fixupList: ObjectFile.Fixups; fixups: LONGINT;
+	VAR fixup: BinaryCode.Fixup; i, index, fixups: SIZE; fixupList: ObjectFile.Fixups;
 		aliasSymbol: ObjectFile.Identifier; aliasOffset: LONGINT;
 
 		PROCEDURE PatchFixup (fixup: BinaryCode.Fixup; fixupOffset, targetOffset: LONGINT);
-		VAR target, address: ObjectFile.Unit; j: LONGINT;
+		VAR target, address: ObjectFile.Unit; j: SIZE;
 
 			PROCEDURE PatchPattern (CONST pattern: ObjectFile.FixupPattern);
 			BEGIN
@@ -396,7 +396,7 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 			END PatchPattern;
 
 			PROCEDURE CheckBits(value: LONGINT; 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 fixup.patterns-1 DO
@@ -450,7 +450,7 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 	END CopyFixups;
 
 	PROCEDURE UpdateAliases (section: BinaryCode.Section;  fingerprinter: Fingerprinter.Fingerprinter);
-	VAR alias: BinaryCode.Alias; i: INTEGER; aliasList: ObjectFile.Aliases; aliases: LONGINT; index: LONGINT;
+	VAR alias: BinaryCode.Alias; aliasList: ObjectFile.Aliases; i, aliases, index: SIZE;
 	BEGIN
 		alias := section.aliasList.firstAlias; i := 0; aliases := 0; aliasList := NIL;
 		WHILE alias # NIL DO
@@ -504,7 +504,7 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 	VAR i: LONGINT; section: Sections.Section;
 
 		PROCEDURE ProcessSection(section: IntermediateCode.Section);
-		VAR i: LONGINT; fixup: BinaryCode.Fixup; alias: BinaryCode.Alias;
+		VAR i: SIZE; fixup: BinaryCode.Fixup; alias: BinaryCode.Alias;
 		BEGIN
 			IF (section.resolved # NIL)  & (section.alias = NIL)  THEN
 				poolMap.PutSegmentedName(section.resolved.os.identifier.name);

+ 2 - 2
source/GenericLinker.Mod

@@ -226,7 +226,7 @@ VAR
 
 
 	PROCEDURE AddSection* (CONST section: ObjectFile.Section);
-	VAR block, current, previous,newBlock: Block; name: ARRAY 256 OF CHAR; i: LONGINT; alias: ObjectFile.Alias;
+	VAR block, current, previous,newBlock: Block; name: ARRAY 256 OF CHAR; i: SIZE; alias: ObjectFile.Alias;
 	BEGIN
 		IF FindBlock (section.identifier) # NIL THEN ObjectFile.SegmentedNameToString(section.identifier.name,name); Error (name, "duplicated section"); RETURN; END;
 		NEW (block); ObjectFile.CopySection (section, block^); block.address := InvalidAddress; block.referenced := FALSE; block.used := FALSE;
@@ -307,7 +307,7 @@ VAR
 	END Link;
 
 	PROCEDURE Reference (block: Block; used: BOOLEAN);
-	VAR i: LONGINT;
+	VAR i: SIZE;
 
 		PROCEDURE ReferenceFixup (CONST fixup: ObjectFile.Fixup);
 		VAR reference: Block; str,name: ARRAY 256 OF CHAR;

+ 1 - 1
source/Linker.Mod

@@ -119,7 +119,7 @@ TYPE
 	END InitArrangement;
 
 	PROCEDURE Allocate* (CONST section: ObjectFile.Section): GenericLinker.Address;
-	VAR address, alignment: ObjectFile.Bits; i, j: LONGINT; name: ObjectFile.SegmentedName;
+	VAR address, alignment: ObjectFile.Bits; i, j: SIZE; name: ObjectFile.SegmentedName;
 	BEGIN
 		IF section.unit > maxUnitSize THEN maxUnitSize := section.unit END;
 		IF section.fixed THEN

+ 47 - 47
source/ObjectFile.Mod

@@ -64,7 +64,7 @@ TYPE
 	Pattern*= POINTER TO RECORD (* this is the same for many fixups *)
 		mode-: WORD;
 		scale-: Bits;
-		patterns-: LONGINT;
+		patterns-: SIZE;
 		pattern-: FixupPatterns
 	END;
 
@@ -76,8 +76,8 @@ TYPE
 	Fixup* = RECORD
 		identifier*: Identifier;
 		pattern-: Pattern;
-		index*: LONGINT;
-		patches*: LONGINT;
+		index*: SIZE;
+		patches*: SIZE;
 		patch*: Patches;
 	END;
 
@@ -96,9 +96,9 @@ TYPE
 		unit*: Bits;
 		fixed*: BOOLEAN;
 		alignment*: Unit;
-		fixups-: LONGINT;
+		fixups-: SIZE;
 		fixup-: Fixups;
-		aliases-: LONGINT;
+		aliases-: SIZE;
 		alias-: Aliases;
 		bits*: BitSets.BitSet;
 	END;
@@ -277,7 +277,7 @@ VAR
 	END CopyIdentifier;
 
 	PROCEDURE CopyPattern( source: Pattern; VAR dest: Pattern);
-	VAR i: LONGINT;
+	VAR i: SIZE;
 	BEGIN
 		NEW(dest);
 		dest.mode := source.mode;
@@ -289,8 +289,8 @@ VAR
 		END;
 	END CopyPattern;
 
-	PROCEDURE CopyPatches(sourcePatches: LONGINT; source: Patches; VAR destPatches: LONGINT; VAR dest: Patches);
-	VAR i: LONGINT;
+	PROCEDURE CopyPatches(sourcePatches: SIZE; source: Patches; VAR destPatches: SIZE; VAR dest: Patches);
+	VAR i: SIZE;
 	BEGIN
 		destPatches := sourcePatches;
 		NEW(dest, destPatches);
@@ -314,7 +314,7 @@ VAR
 
 
 	PROCEDURE CopySection* (CONST source: Section; VAR dest: Section);
-	VAR i: LONGINT;
+	VAR i: SIZE;
 	BEGIN
 		dest.type := source.type;
 		dest.identifier := source.identifier;
@@ -361,7 +361,7 @@ VAR
 		END;
 	END NibbleToCharacter;
 
-	PROCEDURE CharacterToNibble* (char: CHAR): LONGINT;
+	PROCEDURE CharacterToNibble* (char: CHAR): WORD;
 	BEGIN
 		IF ORD (char) >= ORD ('A') THEN
 			RETURN ORD (char) - (ORD ('A') - 10);
@@ -372,7 +372,7 @@ VAR
 
 	PROCEDURE WriteSectionTextual (writer: Streams.Writer; CONST section: Section);
 	CONST Separator = ' '; Tab = 09X;
-	VAR i,offset,start, len: LONGINT; size: Bits;
+	VAR i: SIZE; offset,start, len: LONGINT; size: Bits;
 
 		PROCEDURE WriteValueIdentifier (value: WORD; CONST identifiers: ARRAY OF ARRAY OF CHAR);
 		BEGIN
@@ -396,13 +396,13 @@ VAR
 		END WriteIdentifier;
 
 		PROCEDURE WritePattern(pattern: Pattern);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			WriteValueIdentifier (pattern.mode, modes);
 			writer.Char (Separator);
 			writer.Int (pattern.scale, 0);
 			writer.Char (Separator);
-			writer.Int (pattern.patterns, 0);
+			writer.Size (pattern.patterns);
 			writer.Char (Separator);
 			FOR i := 0 TO pattern.patterns - 1 DO
 				WriteFixupPattern (pattern.pattern[i]);
@@ -418,13 +418,13 @@ VAR
 		END WritePatch;
 
 		PROCEDURE WriteFixup (CONST fixup: Fixup);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			WriteIdentifier(fixup.identifier);
 			writer.Char (Separator);
 			WritePattern(fixup.pattern);
 			writer.Char(Separator);
-			writer.Int(fixup.patches,1);
+			writer.Size(fixup.patches);
 			writer.Char(Separator);
 			FOR i := 0 TO fixup.patches-1 DO
 				WritePatch(fixup.patch[i]);
@@ -497,9 +497,9 @@ VAR
 		writer.Int (section.alignment, 0);
 		writer.Char (Separator);
 
-		writer.Int (section.aliases, 0);
+		writer.Size (section.aliases);
 		writer.Char (Separator);
-		writer.Int (section.fixups, 0);
+		writer.Size (section.fixups);
 		writer.Char (Separator);
 		size := section.bits.GetSize ();
 		writer.Int (size DIV section.unit, 1);
@@ -520,7 +520,7 @@ VAR
 	END WriteSectionTextual;
 
 	PROCEDURE ReadSectionTextual (reader: Streams.Reader; version: WORD; VAR section: Section);
-	VAR i, size: LONGINT; char: CHAR; relocatibility, priority: WORD;
+	VAR i: SIZE; size: LONGINT; char: CHAR; relocatibility, priority: WORD;
 
 		PROCEDURE ReadValueIdentifier (VAR value: WORD; CONST identifiers: ARRAY OF ARRAY OF CHAR);
 		VAR identifier: ARRAY 10 OF CHAR;
@@ -547,12 +547,12 @@ VAR
 		END ReadIdentifier;
 
 		PROCEDURE ReadPattern(VAR pattern: Pattern);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			reader.SkipWhitespace;
 			ReadValueIdentifier (pattern.mode, modes);
 			reader.SkipWhitespace; reader.Int (pattern.scale, FALSE);
-			reader.SkipWhitespace; reader.Int (pattern.patterns, FALSE);
+			reader.SkipWhitespace; reader.Size (pattern.patterns, FALSE);
 
 			IF (pattern.pattern = NIL) OR (LEN (pattern.pattern) < pattern.patterns) THEN
 				NEW (pattern.pattern, pattern.patterns);
@@ -569,12 +569,12 @@ VAR
 		END ReadPatch;
 
 		PROCEDURE ReadFixup (VAR fixup: Fixup);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			reader.SkipWhitespace; ReadIdentifier (fixup.identifier);
 			IF fixup.pattern = NIL THEN NEW(fixup.pattern) END;
 			reader.SkipWhitespace; ReadPattern(fixup.pattern);
-			reader.SkipWhitespace; reader.Int (fixup.patches, FALSE);
+			reader.SkipWhitespace; reader.Size (fixup.patches, FALSE);
 			IF (fixup.patch = NIL) OR (LEN (fixup.patch) < fixup.patches) THEN
 				NEW (fixup.patch, fixup.patches);
 			END;
@@ -621,8 +621,8 @@ VAR
 				END;
 			END;
 		END;
-		reader.SkipWhitespace; reader.Int (section.aliases, FALSE);
-		reader.SkipWhitespace; reader.Int (section.fixups, FALSE);
+		reader.SkipWhitespace; reader.Size (section.aliases, FALSE);
+		reader.SkipWhitespace; reader.Size (section.fixups, FALSE);
 		reader.SkipWhitespace; reader.Int (size, FALSE); size := size * section.unit;
 		IF (section.aliases > 0) & ((section.alias = NIL) OR (LEN (section.alias) < section.aliases)) THEN
 			NEW (section.alias, section.aliases);
@@ -722,7 +722,7 @@ VAR
 	
 
 	PROCEDURE WriteSectionBinary (writer: Streams.Writer; CONST section: Section; poolMap: PoolMap);
-	VAR pos, i, offset, start, len: LONGINT; size: Bits;
+	VAR i: SIZE; pos, offset, start, len: LONGINT; size: Bits;
 	CONST ByteSize=8;
 
 		PROCEDURE WriteValueIdentifier (value: WORD; CONST identifiers: ARRAY OF ARRAY OF CHAR);
@@ -753,7 +753,7 @@ VAR
 		END WriteIdentifier;
 
 		PROCEDURE WritePattern(pattern: Pattern);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			WriteValueIdentifier (pattern.mode, modes);
 			writer.RawNum (pattern.scale);
@@ -771,7 +771,7 @@ VAR
 		END WritePatch;
 
 		PROCEDURE WriteFixup (CONST fixup: Fixup);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			INC(statFixups);
 			WriteIdentifier(fixup.identifier);
@@ -890,7 +890,7 @@ VAR
 	END WriteSectionBinary;
 
 	PROCEDURE ReadSectionBinary (reader: Streams.Reader; version: WORD; VAR section: Section; poolMap: PoolMap);
-	VAR i, size: LONGINT; relocatibility, priority: WORD; ch: CHAR;;
+	VAR i: SIZE; size: LONGINT; relocatibility, priority: WORD; ch: CHAR;;
 	CONST ByteSize=8;
 
 		PROCEDURE ReadValueIdentifier (VAR value: WORD; CONST identifiers: ARRAY OF ARRAY OF CHAR);
@@ -928,11 +928,11 @@ VAR
 		END ReadFixupPattern;
 
 		PROCEDURE ReadPattern(VAR pattern: Pattern);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			ReadValueIdentifier (pattern.mode, modes);
 			reader.RawNum (pattern.scale);
-			reader.RawNum (pattern.patterns);
+			reader.RawSize (pattern.patterns);
 			IF (pattern.pattern = NIL) OR (LEN (pattern.pattern) < pattern.patterns) THEN
 				NEW (pattern.pattern, pattern.patterns);
 			END;
@@ -948,12 +948,12 @@ VAR
 		END ReadPatch;
 
 		PROCEDURE ReadFixup (VAR fixup: Fixup);
-		VAR i: LONGINT;
+		VAR i: SIZE;
 		BEGIN
 			ReadIdentifier (fixup.identifier);
 			IF fixup.pattern = NIL THEN NEW(fixup.pattern) END;
 			ReadPattern(fixup.pattern);
-			reader.RawNum (fixup.patches);
+			reader.RawSize (fixup.patches);
 			IF fixup.patches > 0 THEN
 				IF (fixup.patch = NIL) OR (LEN (fixup.patch) < fixup.patches) THEN
 					NEW (fixup.patch, fixup.patches);
@@ -1026,8 +1026,8 @@ VAR
 				END;
 			END;
 		END;
-		reader.RawNum (section.aliases);
-		reader.RawNum (section.fixups);
+		reader.RawSize (section.aliases);
+		reader.RawSize (section.fixups);
 		reader.RawNum (size); size := size * section.unit;
 		IF (section.aliases > 0) &((section.alias = NIL) OR (LEN (section.alias) < section.aliases)) THEN
 			NEW (section.alias, section.aliases);
@@ -1073,20 +1073,20 @@ VAR
 		INC(statSections); INC(statSectionsTotalSize, writer.Pos()-pos);
 	END WriteSection;
 
-	PROCEDURE SetFixups*(VAR section: Section; fixups: LONGINT; fixup: Fixups);
+	PROCEDURE SetFixups*(VAR section: Section; fixups: SIZE; fixup: Fixups);
 	BEGIN
 		section.fixups := fixups;
 		section.fixup := fixup;
 	END SetFixups;
 
-	PROCEDURE SetAliases*(VAR section: Section; aliases: LONGINT; alias: Aliases);
+	PROCEDURE SetAliases*(VAR section: Section; aliases: SIZE; alias: Aliases);
 	BEGIN
 		section.aliases := aliases;
 		section.alias := alias;
 	END SetAliases;
 
-	PROCEDURE AddPatch*(VAR patches: LONGINT; VAR patch: Patches; disp, ofs: LONGINT);
-	VAR newPatch: Patches; newPatches:LONGINT; i: LONGINT;
+	PROCEDURE AddPatch*(VAR patches: SIZE; VAR patch: Patches; disp, ofs: LONGINT);
+	VAR newPatch: Patches; newPatches, i: SIZE;
 	BEGIN
 		FOR i := 0 TO patches-1 DO
 			ASSERT(patch[i].offset # ofs);
@@ -1105,8 +1105,8 @@ VAR
 		patches := newPatches;
 	END AddPatch;
 
-	PROCEDURE SameFixupPattern(patterns: LONGINT; left, right: FixupPatterns): BOOLEAN;
-	VAR i: LONGINT;
+	PROCEDURE SameFixupPattern(patterns: SIZE; left, right: FixupPatterns): BOOLEAN;
+	VAR i: SIZE;
 	BEGIN
 		FOR i := 0 TO patterns-1 DO
 			IF (left[i].offset # right[i].offset) OR (left[i].bits # right[i].bits) THEN RETURN FALSE END;
@@ -1114,15 +1114,15 @@ VAR
 		RETURN TRUE
 	END SameFixupPattern;
 	
-	PROCEDURE HasPattern(pat: Pattern; mode, scale: LONGINT; patterns: LONGINT; pattern: FixupPatterns): BOOLEAN;
+	PROCEDURE HasPattern(pat: Pattern; mode, scale: LONGINT; patterns: SIZE; pattern: FixupPatterns): BOOLEAN;
 	BEGIN
 		RETURN (pat.mode = mode) & (pat.scale = scale) & (pat.patterns = patterns) & SameFixupPattern(patterns, pat.pattern, pattern);
 	END HasPattern;
 
 
 	(*
-	PROCEDURE AddPatch(VAR patches: LONGINT; VAR patch: Patches; mode: WORD; displacement, scale: LONGINT; patterns: LONGINT; pattern: FixupPatterns; offset: LONGINT);
-	VAR i: LONGINT; newPatches: LONGINT; newPatch: Patches; len: LONGINT;
+	PROCEDURE AddPatch(VAR patches: SIZE; VAR patch: Patches; mode: WORD; displacement, scale: LONGINT; patterns: SIZE; pattern: FixupPatterns; offset: LONGINT);
+	VAR i, newPatches, len: SIZE; newPatch: Patches;
 	BEGIN
 		FOR i := 0 TO patches-1 DO
 			len := LEN(patch);
@@ -1158,8 +1158,8 @@ VAR
 	END AddPatch;
 	*)
 
-	PROCEDURE AddFixup*(VAR fixups: LONGINT; VAR fixup: Fixups; CONST name: SegmentedName; fingerprint: Fingerprint; mode: WORD; scale: LONGINT; patterns: LONGINT; pattern: FixupPatterns): LONGINT;
-	VAR i: LONGINT; newFixups, index: LONGINT; newFixup: Fixups;
+	PROCEDURE AddFixup*(VAR fixups: SIZE; VAR fixup: Fixups; CONST name: SegmentedName; fingerprint: Fingerprint; mode: WORD; scale: LONGINT; patterns: SIZE; pattern: FixupPatterns): SIZE;
+	VAR i, newFixups, index: SIZE; newFixup: Fixups;
 	BEGIN
 		FOR i := 0 TO fixups-1 DO
 			IF (fixup[i].identifier.fingerprint = fingerprint) & (name =fixup[i].identifier.name) & HasPattern(fixup[i].pattern, mode, scale, patterns, pattern) THEN
@@ -1188,8 +1188,8 @@ VAR
 		RETURN index;
 	END AddFixup;
 
-	PROCEDURE AddAlias*(VAR aliases: LONGINT; VAR alias: Aliases; CONST name: SegmentedName; fingerprint: Fingerprint; offset: LONGINT): LONGINT;
-	VAR i: LONGINT; newAliases, index: LONGINT; newAlias: Aliases;
+	PROCEDURE AddAlias*(VAR aliases: SIZE; VAR alias: Aliases; CONST name: SegmentedName; fingerprint: Fingerprint; offset: LONGINT): SIZE;
+	VAR i, newAliases, index: SIZE; newAlias: Aliases;
 	BEGIN
 		newAliases := aliases+1;
 		IF (alias = NIL) OR (LEN(alias) < newAliases) THEN