瀏覽代碼

improved reflection: can deal with global vars again

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6687 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 年之前
父節點
當前提交
90a6fa8342
共有 3 個文件被更改,包括 21 次插入8 次删除
  1. 16 5
      source/FoxIntermediateBackend.Mod
  2. 1 1
      source/GenericLoader.Mod
  3. 4 2
      source/Reflection.Mod

+ 16 - 5
source/FoxIntermediateBackend.Mod

@@ -11823,13 +11823,25 @@ TYPE
 				END Type;
 
 				PROCEDURE WriteVariable(variable: SyntaxTree.Variable; indirect: BOOLEAN);
-					VAR name: ARRAY 256 OF CHAR;
+					VAR name: ARRAY 256 OF CHAR; sn: Basic.SegmentedName;
 				BEGIN
 					IF variable.externalName # NIL THEN RETURN END;
 					IF indirect THEN Char(section,rfIndirect) ELSE Char(section,rfDirect) END;
 					variable.GetName(name);
 					Type(variable.type);
-					Longint(section,ToMemoryUnits(module.system,variable.offsetInBits));
+					IF (variable.scope # NIL) & (variable.scope IS SyntaxTree.ModuleScope) THEN
+						implementationVisitor.GetCodeSectionNameForSymbol(variable, sn);
+						NamedSymbol(section, sn,variable, 0,0);
+					ELSE
+						Size(section, ToMemoryUnits(module.system,variable.offsetInBits));
+					END;
+					(*
+					IF variable.scope IS SyntaxTree.ModuleScope THEN
+						Symbol(section, variable,0,0);
+					ELSE
+						Longint(section,ToMemoryUnits(module.system,variable.offsetInBits));
+					END;
+					*)
 					String(section,name);
 				END WriteVariable;
 
@@ -11921,18 +11933,17 @@ TYPE
 				END Procedure;
 
 				PROCEDURE Scope(s: Sections.Section);
+				VAR variable: SyntaxTree.Variable;
 				BEGIN
 					Char(section,0F8X);
 					Symbol(section,s,0,0); (* start *)
 					Symbol(section,s,s(IntermediateCode.Section).pc,0); (* end *)
 					String(section,"$$");
-					(* removed variables -- wrongly interpreted by Reflection
 					variable := module.module.moduleScope.firstVariable;
 					WHILE(variable # NIL) DO
 						WriteVariable(variable,FALSE);
 						variable := variable.nextVariable;
 					END;
-					*)
 				END Scope;
 
 				PROCEDURE ComputeSize(startPC, endPC: LONGINT): SIZE;
@@ -12225,7 +12236,7 @@ TYPE
 				name*: Name;
 				init, published: BOOLEAN;
 				refcnt*: LONGINT; (* counts loaded modules that import this module *)
-				sb*: ADDRESS; <- set to beginning of data section by loader
+				sb*: ADDRESS; <- should be zero as the static base in generic object file is indeed 0 !
 				entry*: POINTER TO ARRAY OF ADDRESS; <- not needed in new loader
 				command*: POINTER TO ARRAY OF Command;
 				ptrAdr*: POINTER TO ARRAY OF ADDRESS;

+ 1 - 1
source/GenericLoader.Mod

@@ -626,7 +626,7 @@ VAR
 				module.code := arrangement.code.bytes;
 
 				module.firstProc := arrangement.code.firstAddress;
-				module.sb := arrangement.data.firstAddress;
+				module.sb := 0 (*arrangement.data.firstAddress*); (* zero is correct ! *)
 				module.body := SYSTEM.VAL(Body, arrangement.bodyAddress);
 				
 				(*

+ 4 - 2
source/Reflection.Mod

@@ -151,13 +151,15 @@ VAR
 
 	(** Find global variables of mod (which may be NIL) and return it in the refs, refpos and base parameters for use by NextVar.  If not found, refpos returns -1. *)
 	PROCEDURE InitVar*(mod: Modules.Module; VAR refs: Modules.Bytes; VAR refpos: LONGINT; VAR base: ADDRESS);
-	VAR ch: CHAR; startpc: ADDRESS;
+	VAR ch: CHAR; startpc,pc,end: ADDRESS;
 	BEGIN
 		refpos := -1;
 		IF mod # NIL THEN
 			refs := mod.refs; base := mod.sb;
 			IF (refs # NIL) & (LEN(refs) # 0) THEN
-				refpos := FindProc(refs, 0, startpc);
+				IF FindProcByName(mod,"$$",pc,end) THEN
+					refpos := FindProc(refs, pc, startpc);
+				END;
 				IF refpos # -1 THEN
 					ch := refs[refpos]; INC(refpos);
 					WHILE ch # 0X DO ch := refs[refpos]; INC(refpos) END