comparison gen/main.cpp @ 1518:26d061e61b02

Initialize LLVM target and asmprinter for the native and extra targets. Uses some CMake hackery to get the native LLVM target name, since it only provides a conveniance function for initializing the native target and not the native asmprinter.
author Christian Kamm <kamm incasoftware de>
date Fri, 26 Jun 2009 21:02:23 +0200
parents 7d3b47852a7a
children 982eb70e83b2
comparison
equal deleted inserted replaced
1517:a7a9e461512a 1518:26d061e61b02
2 2
3 // some things are taken from llvm's llc tool 3 // some things are taken from llvm's llc tool
4 // which uses the llvm license 4 // which uses the llvm license
5 5
6 #include "gen/llvm.h" 6 #include "gen/llvm.h"
7 #include "gen/llvm-version.h"
7 #include "llvm/LinkAllVMCore.h" 8 #include "llvm/LinkAllVMCore.h"
8 #include "llvm/Linker.h" 9 #include "llvm/Linker.h"
9 #include "llvm/System/Signals.h" 10 #include "llvm/System/Signals.h"
10 #include "llvm/Target/SubtargetFeature.h" 11 #include "llvm/Target/SubtargetFeature.h"
11 #include "llvm/Target/TargetMachine.h" 12 #include "llvm/Target/TargetMachine.h"
12 #include "llvm/Target/TargetOptions.h" 13 #include "llvm/Target/TargetOptions.h"
13 #include "llvm/Target/TargetMachineRegistry.h" 14 #include "llvm/Target/TargetMachineRegistry.h"
15 #if LLVM_REV >= 73610
16 #include "llvm/Target/TargetSelect.h"
17 #endif
14 18
15 #include <stdio.h> 19 #include <stdio.h>
16 #include <stdlib.h> 20 #include <stdlib.h>
17 #include <assert.h> 21 #include <assert.h>
18 #include <limits.h> 22 #include <limits.h>
419 global.params.targetTriple = mTargetTriple.c_str(); 423 global.params.targetTriple = mTargetTriple.c_str();
420 } 424 }
421 425
422 mod.setTargetTriple(global.params.targetTriple); 426 mod.setTargetTriple(global.params.targetTriple);
423 427
424 // Allocate target machine. First, check whether the user has 428 // Allocate target machine.
425 // explicitly specified an architecture to compile for. 429
430 // first initialize llvm
431 #if LLVM_REV >= 73610
432 #define LLVM_TARGET(A) LLVMInitialize##A##Target(); LLVMInitialize##A##AsmPrinter();
433 // this is defined to be LLVM_TARGET(target name 1) LLVM_TARGET(target name 2) ...
434 LDC_TARGETS
435 #undef LLVM_TARGET
436 #endif
437
438 // Check whether the user has explicitly specified an architecture to compile for.
426 if (mArch == 0) 439 if (mArch == 0)
427 { 440 {
428 std::string Err; 441 std::string Err;
429 mArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err); 442 mArch = llvm::TargetMachineRegistry::getClosestStaticTargetForModule(mod, Err);
430 if (mArch == 0) 443 if (mArch == 0)