Browse Source

Added basic support for inferring the default platform from the preferred object file extension used by the machine. Specifying the -p or --platform option is in many cases no longer necessary when targeting the same platform as the compiler is running on.

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7529 8c9fc860-2736-0410-a75d-ab315db34111
negelef 7 years ago
parent
commit
559e616556
2 changed files with 24 additions and 4 deletions
  1. 5 2
      source/FoxCompiler.Mod
  2. 19 2
      source/Options.Mod

+ 5 - 2
source/FoxCompiler.Mod

@@ -5,7 +5,7 @@ IMPORT
 	Basic := FoxBasic, Scanner := FoxScanner, Parser := FoxParser,
 	SemanticChecker := FoxSemanticChecker, SyntaxTree := FoxSyntaxTree, Formats := FoxFormats,
 	Streams, Commands,Diagnostics, Options, Kernel, Printout := FoxPrintout, Backend := FoxBackend,Strings, Global := FoxGlobal,
-	Frontend := FoxFrontend,	Files;
+	Frontend := FoxFrontend, Files, Machine;
 
 CONST
 	(* flags *)
@@ -545,7 +545,7 @@ TYPE
 	
 BEGIN
 	NEW(platforms);
-	defaultPlatform := "";
+
 	(* platform definitions hard coded for the common cases -- maybe (parts of it) should be outsourced to a file ?*)
 	DoAddPlatform("Win32","-b=AMD --objectFile=Binary --symbolFile=Binary --objectFileExtension=.Obw --symbolFileExtension=.Obw");
 	DoAddPlatform("Win32G","-b=AMD --objectFile=Generic --symbolFile=Textual --newObjectFile --mergeSections --objectFileExtension=.GofW --symbolFileExtension=.SymW --preciseGC --trackLeave --writeBarriers");
@@ -560,4 +560,7 @@ BEGIN
 	DoAddPlatform("A2Coop","-b=AMD --cooperative --objectFile=Generic --newObjectFile --traceModule=Trace --mergeSections");
 	DoAddPlatform("ARMA2","-b=ARM --objectFile=Generic --newObjectFile --symbolFile=Textual --mergeSections");
 	DoAddPlatform("Linux32G","-b=AMD --objectFile=Generic --newObjectFile --traceModule=Trace --symbolFile=Textual --objectFileExtension=.GofU --symbolFileExtension=.SymU --preciseGC");
+
+	(* infer platform from default object file extension *)
+	platforms.Find("objectFileExtension", Machine.DefaultObjectFileExtension, defaultPlatform);
 END Compiler.

+ 19 - 2
source/Options.Mod

@@ -665,7 +665,24 @@ TYPE
 			END;
 
 		END Show;
-		
+
+		PROCEDURE Find*(CONST option, value: ARRAY OF CHAR; VAR name: ARRAY OF CHAR);
+		VAR default: Default; pattern: Name; pos, i: LONGINT;
+		BEGIN
+			default := head; pattern := "--";
+			Strings.Concat(pattern, option, pattern);
+			Strings.Concat(pattern, "=", pattern);
+			WHILE (default # NIL) DO
+				pos := Strings.Pos(pattern, default.defaults^);
+				IF pos # -1 THEN
+					pos := Strings.Find(default.defaults^, pos, '=') + 1; i := 0;
+					WHILE (default.defaults[pos] # 0X) & (value[i] # 0X) & (default.defaults[pos] = value[i]) DO INC(pos); INC(i) END;
+					IF ((default.defaults[pos] = 0X) OR (default.defaults[pos] = ' ')) & (value[i] = 0X) THEN COPY(default.name, name); RETURN END;
+				END;
+				default := default.next;
+			END;
+			name := "";
+		END Find;
 
 	END Defaults; 
 
@@ -767,4 +784,4 @@ Options.Test -afds -b --fdas ~
 
 Options.Test -f  -s=fds ~
 
-SystemTools.Free Options ~
+SystemTools.Free Options ~