blob: 1558d01e2cd9294c6ef9895a5232fc0752ab31a1 [file] [log] [blame]
Anton Korobeynikov37171572009-05-03 12:57:15 +00001//===-- MSP430TargetMachine.cpp - Define TargetMachine for MSP430 ---------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Top-level implementation for the MSP430 target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "MSP430.h"
15#include "MSP430TargetAsmInfo.h"
16#include "MSP430TargetMachine.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/CodeGen/Passes.h"
20#include "llvm/Target/TargetAsmInfo.h"
21#include "llvm/Target/TargetMachineRegistry.h"
22
23using namespace llvm;
24
25/// MSP430TargetMachineModule - Note that this is used on hosts that
26/// cannot link in a library unless there are references into the
27/// library. In particular, it seems that it is not possible to get
28/// things to work on Win32 without this. Though it is unused, do not
29/// remove it.
30extern "C" int MSP430TargetMachineModule;
31int MSP430TargetMachineModule = 0;
32
33
34// Register the targets
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000035extern Target TheMSP430Target;
Anton Korobeynikov37171572009-05-03 12:57:15 +000036static RegisterTarget<MSP430TargetMachine>
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000037X(TheMSP430Target, "msp430", "MSP430 [experimental]");
Anton Korobeynikov37171572009-05-03 12:57:15 +000038
Bob Wilsonebbc1c42009-06-23 23:59:40 +000039// Force static initialization.
Daniel Dunbar946686a2009-07-15 23:17:20 +000040extern "C" void LLVMInitializeMSP430Target() {
41 TargetRegistry::RegisterAsmPrinter(TheMSP430Target,
42 &createMSP430CodePrinterPass);
43}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000044
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000045MSP430TargetMachine::MSP430TargetMachine(const Target &T,
46 const Module &M,
Anton Korobeynikov37171572009-05-03 12:57:15 +000047 const std::string &FS) :
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000048 LLVMTargetMachine(T),
Anton Korobeynikov37171572009-05-03 12:57:15 +000049 Subtarget(*this, M, FS),
Anton Korobeynikov82f38642009-05-03 12:58:05 +000050 // FIXME: Check TargetData string.
Anton Korobeynikov37171572009-05-03 12:57:15 +000051 DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"),
52 InstrInfo(*this), TLInfo(*this),
Anton Korobeynikovaeafc4f2009-05-03 13:11:20 +000053 FrameInfo(TargetFrameInfo::StackGrowsDown, 2, -2) { }
Anton Korobeynikov37171572009-05-03 12:57:15 +000054
Anton Korobeynikov37171572009-05-03 12:57:15 +000055const TargetAsmInfo *MSP430TargetMachine::createTargetAsmInfo() const {
56 return new MSP430TargetAsmInfo(*this);
57}
58
Anton Korobeynikov0d370dc2009-05-03 13:19:42 +000059bool MSP430TargetMachine::addInstSelector(PassManagerBase &PM,
60 CodeGenOpt::Level OptLevel) {
Anton Korobeynikov37171572009-05-03 12:57:15 +000061 // Install an instruction selector.
Anton Korobeynikov0d370dc2009-05-03 13:19:42 +000062 PM.add(createMSP430ISelDag(*this, OptLevel));
Anton Korobeynikov37171572009-05-03 12:57:15 +000063 return false;
64}
65
Anton Korobeynikovd2d87ce2009-05-03 13:01:23 +000066bool MSP430TargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Anton Korobeynikov0d370dc2009-05-03 13:19:42 +000067 CodeGenOpt::Level OptLevel,
68 bool Verbose,
David Greene302008d2009-07-14 20:18:05 +000069 formatted_raw_ostream &Out) {
Daniel Dunbar946686a2009-07-15 23:17:20 +000070 FunctionPass *Printer = getTarget().createAsmPrinter(Out, *this, Verbose);
71 if (!Printer)
72 llvm_report_error("unable to create assembly printer");
73 PM.add(Printer);
Anton Korobeynikov37171572009-05-03 12:57:15 +000074 return false;
75}
Anton Korobeynikovd2d87ce2009-05-03 13:01:23 +000076