Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- PIC16TargetMachine.cpp - Define TargetMachine for PIC16 -----------===// |
| 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 PIC16 target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "PIC16.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 15 | #include "PIC16TargetAsmInfo.h" |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 16 | #include "PIC16TargetMachine.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/PassManager.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/Passes.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetAsmInfo.h" |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachineRegistry.h" |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | |
Oscar Fuentes | 92adc19 | 2008-11-15 21:36:30 +0000 | [diff] [blame] | 25 | /// PIC16TargetMachineModule - 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. |
| 30 | extern "C" int PIC16TargetMachineModule; |
| 31 | int PIC16TargetMachineModule = 0; |
| 32 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 33 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 34 | // Register the targets |
| 35 | static RegisterTarget<PIC16TargetMachine> |
Evan Cheng | 07213cb | 2008-11-26 18:00:00 +0000 | [diff] [blame] | 36 | X("pic16", "PIC16 14-bit [experimental]."); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 37 | static RegisterTarget<CooperTargetMachine> |
Evan Cheng | 07213cb | 2008-11-26 18:00:00 +0000 | [diff] [blame] | 38 | Y("cooper", "PIC16 Cooper [experimental]."); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 39 | |
| 40 | // PIC16TargetMachine - Traditional PIC16 Machine. |
| 41 | PIC16TargetMachine::PIC16TargetMachine(const Module &M, const std::string &FS, |
| 42 | bool Cooper) |
| 43 | : Subtarget(M, FS, Cooper), |
| 44 | DataLayout("e-p:16:8:8-i8:8:8-i16:8:8-i32:8:8"), |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 45 | InstrInfo(*this), TLInfo(*this), |
| 46 | FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0) { } |
| 47 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 48 | // CooperTargetMachine - Uses the same PIC16TargetMachine, but makes IsCooper |
| 49 | // as true. |
| 50 | CooperTargetMachine::CooperTargetMachine(const Module &M, const std::string &FS) |
| 51 | : PIC16TargetMachine(M, FS, true) {} |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 52 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 53 | |
| 54 | const TargetAsmInfo *PIC16TargetMachine::createTargetAsmInfo() const { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 55 | return new PIC16TargetAsmInfo(*this); |
| 56 | } |
| 57 | |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame^] | 58 | bool PIC16TargetMachine::addInstSelector(PassManagerBase &PM, |
| 59 | unsigned OptLevel) { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 60 | // Install an instruction selector. |
| 61 | PM.add(createPIC16ISelDag(*this)); |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | bool PIC16TargetMachine:: |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame^] | 66 | addAssemblyEmitter(PassManagerBase &PM, unsigned OptLevel, bool Verbose, |
Evan Cheng | 42bf74b | 2009-03-25 01:47:28 +0000 | [diff] [blame] | 67 | raw_ostream &Out) { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 68 | // Output assembly language. |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame^] | 69 | PM.add(createPIC16CodePrinterPass(Out, *this, OptLevel, Verbose)); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 70 | return false; |
| 71 | } |
| 72 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 73 | |