Index: include/coge/dragonegg/CrossTarget.h =================================================================== --- include/coge/dragonegg/CrossTarget.h (revision 0) +++ include/coge/dragonegg/CrossTarget.h (revision 555) @@ -0,0 +1,59 @@ +//==----- CrossTarget.h - Cross-Compilation Target hooks for GCC to LLVM conversion -----*- C++ -*-==// +// +// Copyright (C) 2014 Cognitive Electronics, Inc. +// +// This file is part of DragonEgg. +// +// DragonEgg is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation; either version 2, or (at your option) any later version. +// +// DragonEgg is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +// A PARTICULAR PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// DragonEgg; see the file COPYING. If not, write to the Free Software +// Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. +// +//===----------------------------------------------------------------------===// +// This file declares some target-specific hooks for GCC to LLVM conversion. +// It was derived from llvm-arm-target.h and arm.h on llvm-gcc.4.2. +//===----------------------------------------------------------------------===// + +#ifndef DRAGONEGG_CROSSTARGET_H +#define DRAGONEGG_CROSSTARGET_H + + +/* + * The Cognitive target is a strictly-cross one. It happens to be hosted on + * x86_64 Linux, but there is not a Cognitive target implemented in GCC, and it is + * unlikely that one will ever be implemented. + * + * As it is a cross-only target which emits .ll, we need to have the correct + * emitted target triple and datalayout appear in the .ll file. + * + * The datalayout needs to be in sync with what appears in the CogE target of LLVM + */ + +#define LLVM_CROSS_TARGET_TRIPLE "coge-cognitive-linux-elf" +#define LLVM_CROSS_TARGET_DATALAYOUT \ + "e" \ + "-p:64:64:64" \ + "-i1:8:8" \ + "-i8:8:8" \ + "-i16:16:16" \ + "-i32:32:32" \ + "-i64:64:64" \ + "-i128:128:128" \ + "-f32:32:32" \ + "-f64:64:64" \ + "-v64:64:64" \ + "-v128:128:128" \ + "-n64" \ + "-s0:64:64" \ + "-a0:0:64" \ + "-S128" + + +#endif /* DRAGONEGG_CROSSTARGET_H */ Index: src/Backend.cpp =================================================================== --- src/Backend.cpp (revision 554) +++ src/Backend.cpp (working copy) @@ -53,6 +53,10 @@ #include "llvm/Support/PluginLoader.h" #endif +#ifdef CROSS_TARGET +#include "CrossTarget.h" +#endif + // System headers #include @@ -573,9 +577,18 @@ // Install information about the target triple and data layout into the module // for optimizer use. +#ifdef LLVM_CROSS_TARGET_TRIPLE + TheModule->setTargetTriple(LLVM_CROSS_TARGET_TRIPLE); +#else TheModule->setTargetTriple(TargetTriple); +#endif + +#ifdef LLVM_CROSS_TARGET_DATALAYOUT + TheModule->setDataLayout(LLVM_CROSS_TARGET_DATALAYOUT); +#else TheModule->setDataLayout( TheTarget->getDataLayout()->getStringRepresentation()); +#endif } /// flag_default_initialize_globals - Whether global variables with no explicit Index: Makefile =================================================================== --- Makefile (revision 554) +++ Makefile (working copy) @@ -13,6 +13,7 @@ # it. Instead you can do an LLVM build and point LLVM_CONFIG to the copy of # llvm-config that was created during the build. LLVM_CONFIG?=llvm-config +CROSS_TARGET?= # Location of this Makefile, useful if you want separate source and object # directories. @@ -109,6 +110,9 @@ # NOTE: The following flags can only be used after TARGET_UTIL has been built. TARGET_HEADERS+=-I$(INCLUDE_DIR)/$(shell $(TARGET_UTIL) -p) \ -I$(INCLUDE_DIR)/$(shell $(TARGET_UTIL) -o) +ifdef CROSS_TARGET +TARGET_HEADERS+=-I$(INCLUDE_DIR)/$(CROSS_TARGET)/dragonegg -DCROSS_TARGET=$(CROSS_TARGET) +endif ifdef VERBOSE LIT_ARGS+=-v