Sfoglia il codice sorgente

Patched port arrays -- works now for static and semidynamic arrays of ports.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6524 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 anni fa
parent
commit
94a7f96688
2 ha cambiato i file con 28 aggiunte e 36 eliminazioni
  1. 7 7
      source/FoxIntermediateBackend.Mod
  2. 21 29
      source/FoxIntermediateLinker.Mod

+ 7 - 7
source/FoxIntermediateBackend.Mod

@@ -348,7 +348,7 @@ TYPE
 		END VisitOperator;
 
 		PROCEDURE VisitVariable(x: SyntaxTree.Variable);
-		VAR name: Basic.SegmentedName; irv: IntermediateCode.Section; align: LONGINT;
+		VAR name: Basic.SegmentedName; irv: IntermediateCode.Section; align, i: LONGINT;
 		BEGIN
 			IF x.externalName # NIL THEN RETURN END;
 			IF (currentScope IS SyntaxTree.ModuleScope) OR (currentScope IS SyntaxTree.CellScope) & ~backend.cellsAreObjects THEN
@@ -361,7 +361,9 @@ TYPE
 					irv.Emit(Reserve(x.position, ToMemoryUnits(system, system.addressSize)));
 					Basic.SuffixSegmentedName (name, Basic.MakeString ("@len"));
 					irv := implementationVisitor.NewSection(module.allSections, Sections.VarSection, name,NIL,dump);
-					irv.Emit(Reserve(x.position, DynamicDim(x.type) * ToMemoryUnits(system, system.addressSize)));
+					FOR i := 0 TO DynamicDim(x.type)-1 DO
+						irv.Emit(Reserve(x.position, ToMemoryUnits(system, system.addressSize)));
+					END;
 				ELSE
 					irv.Emit(Reserve(x.position,ToMemoryUnits(system,system.SizeOf(x.type))));
 					IF ~x.fixed THEN
@@ -6843,8 +6845,7 @@ TYPE
 						type := type(SyntaxTree.ArrayType).arrayBase.resolved;
 					END;
 					IF (type IS SyntaxTree.PortType) THEN (* port found *)
-						(*!!! check port arrays !! *)
-						Global.GetSymbolName(variable,name);
+						Global.GetSymbolNameInScope(variable,x.cellScope,name);
 						Variable(name,variable);
 					END;
 					variable := variable.nextVariable;
@@ -6926,8 +6927,7 @@ TYPE
 				Emit(Push(position,op.op));
 				ReleaseOperand(op);
 
-				
-				Basic.GetString(property.name, name);
+				Global.GetSymbolNameInScope(property, cellType.cellScope , name);
 				PushConstString(name);
 				
 				IF SemanticChecker.IsStringType(property.type) OR (property.type.resolved IS SyntaxTree.IntegerType) THEN 
@@ -9076,7 +9076,7 @@ TYPE
 					IF (x.scope IS SyntaxTree.ModuleScope) OR (x.scope IS SyntaxTree.CellScope) & ~backend.cellsAreObjects THEN
 						ReleaseIntermediateOperand(result.tag);
 						Global.GetSymbolSegmentedName(x,name);
-						Basic.AppendToSegmentedName(name,"@len");
+						Basic.SuffixSegmentedName (name, Basic.MakeString ("@len"));
 						symbol := NewSection(module.allSections, Sections.VarSection, name,NIL ,commentPrintout # NIL);
 						IntermediateCode.InitAddress(result.tag, addressType, symbol.name,0 , 0);
 					ELSE

+ 21 - 29
source/FoxIntermediateLinker.Mod

@@ -84,60 +84,51 @@ TYPE
 		END EmitAt;
 		
 
-		PROCEDURE PatchIntegerValue*(CONST sectionName: ARRAY OF CHAR; index: LONGINT; value: HUGEINT);
+		PROCEDURE PatchIntegerValue*(CONST sectionName: ARRAY OF CHAR; index: LONGINT; value: HUGEINT; type: SyntaxTree.Type): BOOLEAN;
 		VAR instruction: IntermediateCode.Instruction; section: Sections.Section; op1: IntermediateCode.Operand;
-			size: HUGEINT;pooledName: Basic.SegmentedName;
+			pooledName: Basic.SegmentedName; itype: IntermediateCode.Type;
 		BEGIN
 			Basic.ToSegmentedName(sectionName, pooledName);
 			section := allSections.FindByName(pooledName);
-			IF section = NIL THEN RETURN END; (* nothing to patch *)
-			instruction := section(IntermediateCode.Section).instructions[0];
-			op1 := instruction.op1;
-			IF instruction.opcode = IntermediateCode.reserve THEN
-				size := section.bitsPerUnit * op1.intValue;
-			ELSIF instruction.opcode = IntermediateCode.data THEN
-				size := op1.type.sizeInBits
-			ELSE
-				HALT(100);
-			END;
-			IntermediateCode.InitImmediate(op1, IntermediateCode.NewType(IntermediateCode.SignedInteger, INTEGER(size)), value);
+			IF section = NIL THEN 
+				TRACE(sectionName);
+				RETURN FALSE 
+			END; (* nothing to patch *)
+			itype := IntermediateCode.GetType(backend.system, backend.system.booleanType);
+			IntermediateCode.InitImmediate(op1,itype, value);
 			IntermediateCode.InitInstruction1(instruction, 0,  IntermediateCode.data, op1);
 			EmitAt(section(IntermediateCode.Section),index, instruction);
+			RETURN TRUE;
 		END PatchIntegerValue;
 
-		PROCEDURE PatchBooleanValue*(CONST sectionName: ARRAY OF CHAR;index: LONGINT; value: BOOLEAN);
+		PROCEDURE PatchBooleanValue*(CONST sectionName: ARRAY OF CHAR;index: LONGINT; value: BOOLEAN): BOOLEAN;
 		VAR instruction: IntermediateCode.Instruction; section: Sections.Section; op1: IntermediateCode.Operand;
-			size: HUGEINT;pooledName: Basic.SegmentedName;
+			pooledName: Basic.SegmentedName; type: IntermediateCode.Type;
 		BEGIN
 			Basic.ToSegmentedName(sectionName, pooledName);
 			section := allSections.FindByName(pooledName);
-			IF section = NIL THEN RETURN END; (* nothing to patch *)
-			instruction := section(IntermediateCode.Section).instructions[0];
-			op1 := instruction.op1;
-			IF instruction.opcode = IntermediateCode.reserve THEN
-				size := section.bitsPerUnit * op1.intValue;
-			ELSIF instruction.opcode = IntermediateCode.data THEN
-				size := op1.type.sizeInBits
-			ELSE
-				HALT(100);
-			END;
+			IF section = NIL THEN RETURN FALSE END; (* nothing to patch *)
+			
+			type := IntermediateCode.GetType(backend.system, backend.system.booleanType);
+
 			IF value THEN
-				IntermediateCode.InitImmediate(op1, IntermediateCode.NewType(IntermediateCode.UnsignedInteger, INTEGER(size)), 1);
+				IntermediateCode.InitImmediate(op1, type, 1);
 			ELSE
-				IntermediateCode.InitImmediate(op1, IntermediateCode.NewType(IntermediateCode.UnsignedInteger, INTEGER(size)), 0);
+				IntermediateCode.InitImmediate(op1, type, 0);
 			END;
 			IntermediateCode.InitInstruction1(instruction, 0,  IntermediateCode.data, op1);
 			EmitAt(section(IntermediateCode.Section), index, instruction);
+			RETURN TRUE;
 		END PatchBooleanValue;
 
-		PROCEDURE PatchStringValue*(CONST sectionName: ARRAY OF CHAR; CONST value: ARRAY OF CHAR);
+		PROCEDURE PatchStringValue*(CONST sectionName: ARRAY OF CHAR; CONST value: ARRAY OF CHAR): BOOLEAN;
 		VAR instruction: IntermediateCode.Instruction; section: Sections.Section; op1: IntermediateCode.Operand;
 			pooledName: Basic.SegmentedName; type: IntermediateCode.Type;
 			char: CHAR; i: LONGINT; 
 		BEGIN
 			Basic.ToSegmentedName(sectionName, pooledName);
 			section := allSections.FindByName(pooledName);
-			IF section = NIL THEN RETURN END; (* nothing to patch *)
+			IF section = NIL THEN RETURN FALSE END; (* nothing to patch *)
 			section(IntermediateCode.Section).Reset;
 			type := IntermediateCode.GetType(backend.system, backend.system.characterType);
 			i := 0; 
@@ -148,6 +139,7 @@ TYPE
 				section(IntermediateCode.Section).Emit(instruction);
 				INC(i); 
 			UNTIL char = 0X; 
+			RETURN TRUE;
 		END PatchStringValue;