Browse Source

Fixed a critical bug with MinosObjectFile plus type guards.
Metadata=simple: format changed. Might have effect on code using methods.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6431 8c9fc860-2736-0410-a75d-ab315db34111

felixf 9 years ago
parent
commit
07a477a151
2 changed files with 25 additions and 15 deletions
  1. 19 12
      source/FoxIntermediateBackend.Mod
  2. 6 3
      source/FoxMinosObjectFile.Mod

+ 19 - 12
source/FoxIntermediateBackend.Mod

@@ -2191,6 +2191,13 @@ TYPE
 					BreqL(trueL,left,right);
 					BreqL(trueL,left,right);
 					Emit(Mov(position,left,IntermediateCode.Memory(addressType,left,0)));
 					Emit(Mov(position,left,IntermediateCode.Memory(addressType,left,0)));
 					BrneL(repeatL,left,nil);
 					BrneL(repeatL,left,nil);
+				ELSIF meta.simple THEN
+					level := type(SyntaxTree.RecordType).Level();
+					(* get type desc tag of level relative to base tag *)
+					offset := (meta.BaseTypesTableOffset - level) * addressType.sizeInBits;
+					IntermediateCode.AddOffset(left,ToMemoryUnits(system,offset));
+					IntermediateCode.MakeMemory(left,addressType);
+					BreqL(trueL,left,right);
 				ELSE
 				ELSE
 					level := type(SyntaxTree.RecordType).Level();
 					level := type(SyntaxTree.RecordType).Level();
 					(* get type desc tag of level relative to base tag *)
 					(* get type desc tag of level relative to base tag *)
@@ -5610,7 +5617,7 @@ TYPE
 					ELSE
 					ELSE
 						source := NewSection(module.importedSections, Sections.ConstSection,name,td,commentPrintout # NIL);
 						source := NewSection(module.importedSections, Sections.ConstSection,name,td,commentPrintout # NIL);
 					END;
 					END;
-					IF backend.cooperative THEN
+					IF backend.cooperative OR meta.simple THEN
 						offset := 0;
 						offset := 0;
 					ELSE
 					ELSE
 						IF x IS SyntaxTree.CellType THEN
 						IF x IS SyntaxTree.CellType THEN
@@ -10533,15 +10540,15 @@ TYPE
 		PROCEDURE &InitMetaDataGenerator(implementationVisitor: ImplementationVisitor; declarationVisitor: DeclarationVisitor; simple: BOOLEAN);
 		PROCEDURE &InitMetaDataGenerator(implementationVisitor: ImplementationVisitor; declarationVisitor: DeclarationVisitor; simple: BOOLEAN);
 		BEGIN
 		BEGIN
 			IF implementationVisitor.backend.cooperative THEN
 			IF implementationVisitor.backend.cooperative THEN
-				TypeTags := MAX(LONGINT); (* only 3 extensions allowed *)
+				TypeTags := MAX(LONGINT); 
 				BaseTypesTableOffset := 0;
 				BaseTypesTableOffset := 0;
 				MethodTableOffset := 2;
 				MethodTableOffset := 2;
 				TypeRecordBaseOffset := 0;			
 				TypeRecordBaseOffset := 0;			
 			ELSIF simple THEN
 			ELSIF simple THEN
 				TypeTags := 3; (* only 3 extensions allowed *)
 				TypeTags := 3; (* only 3 extensions allowed *)
-				BaseTypesTableOffset := -1;
-				MethodTableOffset := -TypeTags+BaseTypesTableOffset;
-				TypeRecordBaseOffset := TypeTags;
+				BaseTypesTableOffset := 3;
+				MethodTableOffset := BaseTypesTableOffset+1;
+				TypeRecordBaseOffset := 0;
 			ELSE
 			ELSE
 				TypeTags := 16;
 				TypeTags := 16;
 				BaseTypesTableOffset := -2; (* typeInfo and size field *)
 				BaseTypesTableOffset := -2; (* typeInfo and size field *)
@@ -10562,7 +10569,7 @@ TYPE
 
 
 		PROCEDURE GetTypeRecordBaseOffset(numberMethods: LONGINT): LONGINT;
 		PROCEDURE GetTypeRecordBaseOffset(numberMethods: LONGINT): LONGINT;
 		BEGIN
 		BEGIN
-			IF implementationVisitor.backend.cooperative THEN RETURN 0 ELSE RETURN TypeRecordBaseOffset + numberMethods END;
+			IF implementationVisitor.backend.cooperative OR simple THEN RETURN 0 ELSE RETURN TypeRecordBaseOffset + numberMethods END;
 		END GetTypeRecordBaseOffset;
 		END GetTypeRecordBaseOffset;
 
 
 		PROCEDURE HeapBlock(CONST moduleName, typeName: ARRAY OF CHAR; section: IntermediateCode.Section; dataAdrOffset: LONGINT);
 		PROCEDURE HeapBlock(CONST moduleName, typeName: ARRAY OF CHAR; section: IntermediateCode.Section; dataAdrOffset: LONGINT);
@@ -12286,16 +12293,16 @@ TYPE
 					ELSE
 					ELSE
 						(*
 						(*
 							simple:
 							simple:
-											methods
-											tag(2)
+							td adr --> size
 											tag(1)
 											tag(1)
-							td adr --->	tag(0)
-							td adr --->	size
+											tag(2)
+											tag(3)
+							methods -> 
 						*)
 						*)
-						MethodTable;
-						TdTable(TypeTags);
 						Info(source, "record size");
 						Info(source, "record size");
 						Address(source, ToMemoryUnits(module.system,module.system.SizeOf(recordType)));
 						Address(source, ToMemoryUnits(module.system,module.system.SizeOf(recordType)));
+						TdTable(TypeTags);
+						MethodTable;
 						source.SetReferenced(FALSE);
 						source.SetReferenced(FALSE);
 					END;
 					END;
 			END NewTypeDescriptor;
 			END NewTypeDescriptor;

+ 6 - 3
source/FoxMinosObjectFile.Mod

@@ -85,7 +85,7 @@ TYPE
 	(*
 	(*
 		this procedure converts the section-based representation of fixups into a symbol based representation
 		this procedure converts the section-based representation of fixups into a symbol based representation
 	*)
 	*)
-	PROCEDURE GetFixups(module: Sections.Module; symbol: Sections.Section; VAR first: Fixup): LONGINT;
+	PROCEDURE GetFixups(diagnostics: Diagnostics.Diagnostics; module: Sections.Module; symbol: Sections.Section; VAR first: Fixup): LONGINT;
 	VAR temp: Fixup; fixup: BinaryCode.Fixup; nr :LONGINT; i: LONGINT; section: Sections.Section; sectionList: Sections.SectionList;
 	VAR temp: Fixup; fixup: BinaryCode.Fixup; nr :LONGINT; i: LONGINT; section: Sections.Section; sectionList: Sections.SectionList;
 
 
 		PROCEDURE Do;
 		PROCEDURE Do;
@@ -102,6 +102,9 @@ TYPE
 							temp.fixup := fixup;
 							temp.fixup := fixup;
 							temp.fixupSection := section;
 							temp.fixupSection := section;
 							temp.nextFixup := first;
 							temp.nextFixup := first;
+							IF fixup.displacement # 0 THEN
+								diagnostics.Error(module.moduleName,Diagnostics.Invalid, Diagnostics.Invalid,"Fixups with displacement # 0 not supported in Minos Object File.");
+							END;
 							first := temp;
 							first := temp;
 						END;
 						END;
 						fixup := fixup.nextFixup;
 						fixup := fixup.nextFixup;
@@ -366,7 +369,7 @@ TYPE
 						fixup := binarySection.fixupList.firstFixup;
 						fixup := binarySection.fixupList.firstFixup;
 						WHILE fixup # NIL DO
 						WHILE fixup # NIL DO
 							IF (fixup.mode = BinaryCode.Relative)  & InModule(fixup.symbol.name) THEN
 							IF (fixup.mode = BinaryCode.Relative)  & InModule(fixup.symbol.name) THEN
-								HALT(100); (* should already be resolved *)
+								diagnostics.Error(module.moduleName,Diagnostics.Invalid, Diagnostics.Invalid,"Relative self fixup not supported by Minos Object File.");
 							ELSIF (fixup.mode = BinaryCode.Absolute) & InModule(fixup.symbol.name) THEN
 							ELSIF (fixup.mode = BinaryCode.Absolute) & InModule(fixup.symbol.name) THEN
 								this := section.offset  + fixup.offset; (* location of the fixup *)
 								this := section.offset  + fixup.offset; (* location of the fixup *)
 								(*
 								(*
@@ -440,7 +443,7 @@ TYPE
 				FOR i := 1 TO numberEntries DO
 				FOR i := 1 TO numberEntries DO
 					section := entries[i];
 					section := entries[i];
 					IF section # NIL THEN
 					IF section # NIL THEN
-						numberFixups := GetFixups(module, section, first);
+						numberFixups := GetFixups(diagnostics, module, section, first);
 						IF Trace THEN
 						IF Trace THEN
 							D.Int(numberFixups,1); D.String(" fixups "); Basic.WriteSegmentedName(D.Log, section.name); D.Ln;
 							D.Int(numberFixups,1); D.String(" fixups "); Basic.WriteSegmentedName(D.Log, section.name); D.Ln;
 						END;
 						END;