diff gen/main.cpp @ 1021:d1ec9ff0e9ba

Implemented basic -m32 and -m64 options.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Sun, 01 Mar 2009 22:27:03 +0100
parents 55051098d9fc
children abfe71f5b911
line wrap: on
line diff
--- a/gen/main.cpp	Sun Mar 01 20:22:10 2009 +0100
+++ b/gen/main.cpp	Sun Mar 01 22:27:03 2009 +0100
@@ -337,8 +337,24 @@
     }
 
     // create a proper target
+
+    // check -m32/64 sanity
+    if (m32bits && m64bits)
+        error("cannot use both -m32 and -m64 options");
+    else if ((m32bits || m64bits) && (mArch != 0 || !mTargetTriple.empty()))
+        error("-m32 and -m64 switches cannot be used together with -march and -mtriple switches");
+    if (global.errors)
+        fatal();
+
     llvm::Module mod("dummy");
 
+    // override triple if needed
+    const char* defaultTriple = DEFAULT_TARGET_TRIPLE;
+    if ((sizeof(void*) == 4 && m64bits) || (sizeof(void*) == 8 && m32bits))
+    {
+        defaultTriple = DEFAULT_ALT_TARGET_TRIPLE;
+    }
+
     // did the user override the target triple?
     if (mTargetTriple.empty())
     {
@@ -347,7 +363,7 @@
             error("you must specify a target triple as well with -mtriple when using the -march option");
             fatal();
         }
-        global.params.targetTriple = DEFAULT_TARGET_TRIPLE;
+        global.params.targetTriple = defaultTriple;
     }
     else
     {