diff dmd/mars.c @ 735:eee9efe5b51f

Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked. Added untested support for Thumb target.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 27 Oct 2008 17:37:34 +0100
parents 6dcab994ddc3
children 4ac97ec7c18e
line wrap: on
line diff
--- a/dmd/mars.c	Mon Oct 27 16:36:59 2008 +0100
+++ b/dmd/mars.c	Mon Oct 27 17:37:34 2008 +0100
@@ -186,7 +186,7 @@
 \n\
 Codegen control:\n\
   -m<arch>       emit code specific to <arch> being one of:\n\
-                 x86 x86-64 ppc32 ppc64\n\
+                 x86 x86-64 ppc32 ppc64 arm thumb\n\
   -t<os>         emit code specific to <os> being one of:\n\
                  Linux, Windows, MacOSX, FreeBSD\n\
 \n\
@@ -830,6 +830,8 @@
             global.params.llvmArch = "ppc32";
     #elif defined(__arm__)
         global.params.llvmArch = "arm";
+    #elif defined(__thumb__)
+        global.params.llvmArch = "thumb";
     #else
     #error
     #endif
@@ -840,7 +842,6 @@
         global.params.isLE = true;
         global.params.is64bit = false;
         global.params.cpu = ARCHx86;
-        //global.params.data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64";
         if (global.params.useInlineAsm) {
             VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86");
         }
@@ -850,21 +851,18 @@
         global.params.isLE = true;
         global.params.is64bit = true;
         global.params.cpu = ARCHx86_64;
-        //global.params.data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else if (strcmp(global.params.llvmArch,"ppc32")==0) {
         VersionCondition::addPredefinedGlobalIdent("PPC");
         global.params.isLE = false;
         global.params.is64bit = false;
         global.params.cpu = ARCHppc;
-        //global.params.data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else if (strcmp(global.params.llvmArch,"ppc64")==0) {
         VersionCondition::addPredefinedGlobalIdent("PPC64");
         global.params.isLE = false;
         global.params.is64bit = true;
         global.params.cpu = ARCHppc_64;
-        //global.params.data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64";
     }
     else if (strcmp(global.params.llvmArch,"arm")==0) {
         VersionCondition::addPredefinedGlobalIdent("ARM");
@@ -872,6 +870,12 @@
         global.params.is64bit = false;
         global.params.cpu = ARCHarm;
     }
+    else if (strcmp(global.params.llvmArch,"thumb")==0) {
+        VersionCondition::addPredefinedGlobalIdent("Thumb");
+        global.params.isLE = true;
+        global.params.is64bit = false;
+        global.params.cpu = ARCHthumb;
+    }
     else {
         assert(0 && "Invalid arch");
     }
@@ -927,6 +931,12 @@
 
     Logger::println("Target triple: %s", global.params.targetTriple);
 
+    // build a minimal data layout so llvm can find the target
+    global.params.dataLayout = global.params.isLE
+        ? (char*)(global.params.is64bit ? "e-p:64:64" : "e-p:32:32")
+        : (char*)(global.params.is64bit ? "E-p:64:64" : "E-p:32:32");
+    Logger::println("Layout: %s", global.params.dataLayout);
+
     // Initialization
     Type::init();
     Id::initialize();