ソースを参照

Added a make library functionality fo FoxGenericObjectFile: object files can be put together in a single library file subsequently usable for static linking. This makes it more comfortable to link at the command line.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@6471 8c9fc860-2736-0410-a75d-ab315db34111
felixf 9 年 前
コミット
5766b0b081
3 ファイル変更73 行追加1 行削除
  1. 50 0
      source/FoxGenericObjectFile.Mod
  2. 16 0
      source/ObjectFile.Mod
  3. 7 1
      source/StaticLinker.Mod

+ 50 - 0
source/FoxGenericObjectFile.Mod

@@ -570,6 +570,56 @@ TYPE ObjectFileFormat* = OBJECT (Formats.ObjectFileFormat)
 			context.error.String("no file specificed"); context.error.Ln
 		END;
 	END Show;
+	
+	PROCEDURE MakeLibrary*(context: Commands.Context);
+	VAR
+		fileName: Files.FileName; file: Files.File; reader: Files.Reader; (*writer: Streams.Writer;*)
+		binary: BOOLEAN; poolMap, poolMapDummy: ObjectFile.PoolMap;
+		bs: BinaryCode.Section;
+		is: IntermediateCode.Section;
+		sectionList: Sections.SectionList;
+		section: ObjectFile.Section;
+		 i: LONGINT;
+		 dest: Files.FileName;
+		 writer: Files.Writer;
+		 name: ObjectFile.SegmentedName;
+	BEGIN
+		NEW(sectionList);
+		IF context.arg.GetString(dest) THEN
+		(*writer := Basic.GetWriter(Basic.GetDebugWriter(fileName));*)
+		WHILE context.arg.GetString(fileName) DO
+			file := Files.Old(fileName);
+			IF file # NIL THEN
+				NEW(reader,file,0);
+				ReadHeader(reader, binary, poolMap);
+				WHILE reader.Peek () # 0X DO
+					ObjectFile.InitSection(section);
+					ObjectFile.ReadSection (reader, section, binary, poolMap);
+					NEW(bs, SHORTINT(section.type) ,section.priority,section.unit,name, FALSE, FALSE);
+					bs.os := section;
+					NEW(is, SHORTINT(bs.os.type), SHORTINT(bs.os.priority), bs.os.identifier.name,NIL, FALSE);
+					is.SetResolved(bs);
+					sectionList.AddSection(is);
+					
+					
+					reader.SkipWhitespace;
+				END;
+			ELSE
+				context.error.String("file not found "); context.error.String(fileName); context.error.Ln
+			END;
+		END;
+		file := Files.New(dest);
+		Files.OpenWriter(writer, file, 0);
+		WriteHeader(writer, TRUE, sectionList, poolMapDummy, NIL);
+		FOR i := 0 TO sectionList.Length()-1 DO
+			is := sectionList.GetSection(i)(IntermediateCode.Section);
+			ObjectFile.WriteSection(writer, is.resolved.os, TRUE, poolMapDummy); (* binary *)
+		END;
+		writer.Update;
+		Files.Register(file);
+		END;
+	END MakeLibrary;
+	
 
 	PROCEDURE Statistics*;
 	VAR iterator: Basic.IntIterator; stat: SectionStat; index: StringPool.Index; any: ANY;

+ 16 - 0
source/ObjectFile.Mod

@@ -332,6 +332,22 @@ VAR
 		NEW (dest.bits, source.bits.GetSize ());
 		BitSets.CopyBits (source.bits, 0, dest.bits, 0, source.bits.GetSize ());
 	END CopySection;
+	
+	PROCEDURE InitSection*(VAR dest: Section);
+	BEGIN
+		dest.type := 0;
+		dest.identifier.name := "";
+		dest.identifier.fingerprint := 0;
+		dest.unit := 0;
+		dest.fixed := FALSE;
+		dest.alignment := 0;
+		dest.priority := 0;
+		dest.fixups:= 0;
+		dest.aliases := 0;
+		dest.fixup := NIL;
+		dest.alias := NIL;
+		dest.bits := NIL;
+	END InitSection;
 
 	PROCEDURE NibbleToCharacter* (value: LONGINT): CHAR;
 	BEGIN

+ 7 - 1
source/StaticLinker.Mod

@@ -181,8 +181,14 @@ VAR fileName: Files.FileName; file: Files.File; reader: Files.Reader;
 BEGIN
 	linker.Information (moduleName, "processing");
 	IF path # "" THEN Files.JoinPath (path, moduleName, fileName); ELSE COPY(moduleName,fileName); END;
-	Files.JoinExtension (fileName, extension, fileName);
 	file := Files.Old (fileName);
+	IF file = NIL THEN (* try with extension *)
+		Files.JoinExtension (fileName, extension, fileName);
+		file := Files.Old (fileName);
+	END;
+	IF file = NIL THEN (* try without extension *)
+		
+	END;
 	IF file = NIL THEN linker.Error (fileName, "failed to open file"); RETURN; END;
 	Files.OpenReader (reader, file, 0);
 	GenericLinker.Process (reader, linker) ;