blob: 08bb3e6f055b62092e11001da755bbcc44876a01 [file] [log] [blame]
Sanjiv Gupta0e687712008-05-13 09:02:57 +00001//===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Sanjiv Gupta2d4e7f72008-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 Gupta0e687712008-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 Guptab1b5ffd2008-11-19 11:00:54 +000015#ifndef LLVM_TARGET_PIC16_H
16#define LLVM_TARGET_PIC16_H
Sanjiv Gupta0e687712008-05-13 09:02:57 +000017
Torok Edwinc25e7582009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bill Wendling98a366d2009-04-29 23:29:43 +000019#include "llvm/Target/TargetMachine.h"
Sanjiv Gupta1b046942009-01-13 19:18:47 +000020#include <cassert>
Sanjiv Gupta211f3622009-05-10 05:23:47 +000021#include <sstream>
Nick Lewycky4a228862009-05-08 06:22:25 +000022#include <cstring>
Sanjiv Guptad8d27f42009-05-06 08:02:01 +000023#include <string>
Sanjiv Guptad49baef2010-04-07 03:36:01 +000024#include <vector>
Sanjiv Gupta1b046942009-01-13 19:18:47 +000025
Sanjiv Gupta0e687712008-05-13 09:02:57 +000026namespace llvm {
27 class PIC16TargetMachine;
Sanjiv Gupta0e687712008-05-13 09:02:57 +000028 class FunctionPass;
29 class MachineCodeEmitter;
David Greene71847812009-07-14 20:18:05 +000030 class formatted_raw_ostream;
Sanjiv Gupta0e687712008-05-13 09:02:57 +000031
Sanjiv Gupta1b046942009-01-13 19:18:47 +000032namespace PIC16CC {
33 enum CondCodes {
34 EQ,
35 NE,
36 LT,
37 LE,
38 GT,
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000039 GE,
40 ULT,
41 UGT,
42 ULE,
43 UGE
Sanjiv Gupta1b046942009-01-13 19:18:47 +000044 };
45}
Sanjiv Gupta753ec152009-10-15 19:26:25 +000046
47 enum PIC16SectionType {
48 CODE,
49 UDATA,
50 IDATA,
51 ROMDATA,
52 UDATA_OVR,
53 UDATA_SHR
Chris Lattner35a27c82009-08-21 23:12:15 +000054 };
55
Sanjiv Guptad49baef2010-04-07 03:36:01 +000056 class ESNames {
57 std::vector<char*> stk;
58 ESNames() {}
59 public:
60 ~ESNames() {
Dan Gohman6d3b9222010-07-28 17:15:36 +000061 while (!stk.empty())
Sanjiv Guptad49baef2010-04-07 03:36:01 +000062 {
Dan Gohman6d3b9222010-07-28 17:15:36 +000063 char* p = stk.back();
Sanjiv Guptad49baef2010-04-07 03:36:01 +000064 delete [] p;
Sanjiv Guptad49baef2010-04-07 03:36:01 +000065 stk.pop_back();
66 }
67 }
Chris Lattner35a27c82009-08-21 23:12:15 +000068
Sanjiv Guptad49baef2010-04-07 03:36:01 +000069 // External symbol names require memory to live till the program end.
70 // So we have to allocate it and keep. Push all such allocations into a
71 // vector so that they get freed up on termination.
72 inline static const char *createESName (const std::string &name) {
73 static ESNames esn;
74 char *tmpName = new char[name.size() + 1];
75 memcpy(tmpName, name.c_str(), name.size() + 1);
76 esn.stk.push_back(tmpName);
77 return tmpName;
78 }
Sanjiv Gupta573eb5e2009-05-08 04:50:14 +000079
Sanjiv Guptad49baef2010-04-07 03:36:01 +000080 };
Sanjiv Gupta1b046942009-01-13 19:18:47 +000081
82 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
83 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +000084 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta1b046942009-01-13 19:18:47 +000085 case PIC16CC::NE: return "ne";
86 case PIC16CC::EQ: return "eq";
87 case PIC16CC::LT: return "lt";
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000088 case PIC16CC::ULT: return "lt";
Sanjiv Gupta1b046942009-01-13 19:18:47 +000089 case PIC16CC::LE: return "le";
Sanjiv Gupta703e2352009-06-03 13:36:44 +000090 case PIC16CC::ULE: return "le";
Sanjiv Gupta1b046942009-01-13 19:18:47 +000091 case PIC16CC::GT: return "gt";
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000092 case PIC16CC::UGT: return "gt";
Sanjiv Gupta1b046942009-01-13 19:18:47 +000093 case PIC16CC::GE: return "ge";
Sanjiv Gupta703e2352009-06-03 13:36:44 +000094 case PIC16CC::UGE: return "ge";
Sanjiv Gupta1b046942009-01-13 19:18:47 +000095 }
96 }
97
Sanjiv Gupta08b9b052009-01-21 05:44:05 +000098 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
99 switch (CC) {
Torok Edwinc23197a2009-07-14 16:55:14 +0000100 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta08b9b052009-01-21 05:44:05 +0000101 case PIC16CC::NE:
102 case PIC16CC::EQ:
103 case PIC16CC::LT:
104 case PIC16CC::LE:
105 case PIC16CC::GE:
106 case PIC16CC::GT:
107 return true;
108 case PIC16CC::ULT:
109 case PIC16CC::UGT:
110 case PIC16CC::ULE:
111 case PIC16CC::UGE:
112 return false; // condition codes for unsigned comparison.
113 }
114 }
115
Sanjiv Gupta1b046942009-01-13 19:18:47 +0000116
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000117
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000118 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
Daniel Dunbar0c795d62009-07-25 06:49:55 +0000119 // Banksel optimizer pass.
Sanjiv Guptad8d27f42009-05-06 08:02:01 +0000120 FunctionPass *createPIC16MemSelOptimizerPass();
Daniel Dunbar4cb1e132009-07-18 23:03:22 +0000121
122 extern Target ThePIC16Target;
123 extern Target TheCooperTarget;
124
Sanjiv Gupta0e687712008-05-13 09:02:57 +0000125} // end namespace llvm;
126
127// Defines symbolic names for PIC16 registers. This defines a mapping from
128// register name to register number.
129#include "PIC16GenRegisterNames.inc"
130
131// Defines symbolic names for the PIC16 instructions.
132#include "PIC16GenInstrNames.inc"
133
134#endif