blob: cee55f4f260fe3c67324cac7d58fa208be76e5fa [file] [log] [blame]
Sanjiv Gupta09bb4202008-05-13 09:02:57 +00001//===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Sanjiv Gupta31c64c22008-05-14 06:50:01 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Sanjiv Gupta09bb4202008-05-13 09:02:57 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the entry points for global functions defined in
11// the LLVM PIC16 back-end.
12//
13//===----------------------------------------------------------------------===//
14
Sanjiv Gupta085ae4f2008-11-19 11:00:54 +000015#ifndef LLVM_TARGET_PIC16_H
16#define LLVM_TARGET_PIC16_H
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000017
Edwin Török675d5622009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bill Wendling5ed22ac2009-04-29 23:29:43 +000019#include "llvm/Target/TargetMachine.h"
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000020#include <cassert>
Sanjiv Guptaca549b72009-05-10 05:23:47 +000021#include <sstream>
Nick Lewycky9fb109a2009-05-08 06:22:25 +000022#include <cstring>
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000023#include <string>
Sanjiv Guptabc179d12010-04-07 03:36:01 +000024#include <vector>
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000025
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000026namespace llvm {
27 class PIC16TargetMachine;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000028 class FunctionPass;
29 class MachineCodeEmitter;
David Greene302008d2009-07-14 20:18:05 +000030 class formatted_raw_ostream;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000031
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000032namespace PIC16CC {
33 enum CondCodes {
34 EQ,
35 NE,
36 LT,
37 LE,
38 GT,
Sanjiv Gupta691e8132009-01-21 05:44:05 +000039 GE,
40 ULT,
41 UGT,
42 ULE,
43 UGE
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000044 };
45}
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000046
47 enum PIC16SectionType {
48 CODE,
49 UDATA,
50 IDATA,
51 ROMDATA,
52 UDATA_OVR,
53 UDATA_SHR
Chris Lattner7f504882009-08-21 23:12:15 +000054 };
55
Sanjiv Guptabc179d12010-04-07 03:36:01 +000056 class ESNames {
57 std::vector<char*> stk;
58 ESNames() {}
59 public:
60 ~ESNames() {
61 std::vector<char*>::iterator it = stk.end();
62 it--;
63 while(stk.end() != stk.begin())
64 {
65 char* p = *it;
66 delete [] p;
67 it--;
68 stk.pop_back();
69 }
70 }
Chris Lattner7f504882009-08-21 23:12:15 +000071
Sanjiv Guptabc179d12010-04-07 03:36:01 +000072 // External symbol names require memory to live till the program end.
73 // So we have to allocate it and keep. Push all such allocations into a
74 // vector so that they get freed up on termination.
75 inline static const char *createESName (const std::string &name) {
76 static ESNames esn;
77 char *tmpName = new char[name.size() + 1];
78 memcpy(tmpName, name.c_str(), name.size() + 1);
79 esn.stk.push_back(tmpName);
80 return tmpName;
81 }
Sanjiv Gupta03fb67c2009-05-08 04:50:14 +000082
Sanjiv Guptabc179d12010-04-07 03:36:01 +000083 };
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000084
85 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
86 switch (CC) {
Edwin Törökbd448e32009-07-14 16:55:14 +000087 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000088 case PIC16CC::NE: return "ne";
89 case PIC16CC::EQ: return "eq";
90 case PIC16CC::LT: return "lt";
Sanjiv Gupta691e8132009-01-21 05:44:05 +000091 case PIC16CC::ULT: return "lt";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000092 case PIC16CC::LE: return "le";
Sanjiv Gupta0c878bb2009-06-03 13:36:44 +000093 case PIC16CC::ULE: return "le";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000094 case PIC16CC::GT: return "gt";
Sanjiv Gupta691e8132009-01-21 05:44:05 +000095 case PIC16CC::UGT: return "gt";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000096 case PIC16CC::GE: return "ge";
Sanjiv Gupta0c878bb2009-06-03 13:36:44 +000097 case PIC16CC::UGE: return "ge";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000098 }
99 }
100
Sanjiv Gupta691e8132009-01-21 05:44:05 +0000101 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
102 switch (CC) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000103 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta691e8132009-01-21 05:44:05 +0000104 case PIC16CC::NE:
105 case PIC16CC::EQ:
106 case PIC16CC::LT:
107 case PIC16CC::LE:
108 case PIC16CC::GE:
109 case PIC16CC::GT:
110 return true;
111 case PIC16CC::ULT:
112 case PIC16CC::UGT:
113 case PIC16CC::ULE:
114 case PIC16CC::UGE:
115 return false; // condition codes for unsigned comparison.
116 }
117 }
118
Sanjiv Gupta4affaea2009-01-13 19:18:47 +0000119
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +0000120
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000121 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
Daniel Dunbarc680b012009-07-25 06:49:55 +0000122 // Banksel optimizer pass.
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +0000123 FunctionPass *createPIC16MemSelOptimizerPass();
Daniel Dunbar0b0441e2009-07-18 23:03:22 +0000124
125 extern Target ThePIC16Target;
126 extern Target TheCooperTarget;
127
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000128} // end namespace llvm;
129
130// Defines symbolic names for PIC16 registers. This defines a mapping from
131// register name to register number.
132#include "PIC16GenRegisterNames.inc"
133
134// Defines symbolic names for the PIC16 instructions.
135#include "PIC16GenInstrNames.inc"
136
137#endif