blob: e46c9b242e3c8e4e3325d7b70aabc888abe8896d [file] [log] [blame]
Sanjiv Gupta4394c232008-05-13 09:02:57 +00001//===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Sanjiv Gupta1f8c9ef2008-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 Gupta4394c232008-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 Gupta2ae21ee2008-11-19 11:00:54 +000015#ifndef LLVM_TARGET_PIC16_H
16#define LLVM_TARGET_PIC16_H
Sanjiv Gupta4394c232008-05-13 09:02:57 +000017
Torok Edwin56d06592009-07-11 20:10:48 +000018#include "llvm/Support/ErrorHandling.h"
Bill Wendling026e5d72009-04-29 23:29:43 +000019#include "llvm/Target/TargetMachine.h"
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000020#include <cassert>
Sanjiv Gupta258f8512009-05-10 05:23:47 +000021#include <sstream>
Nick Lewycky2f6bddd2009-05-08 06:22:25 +000022#include <cstring>
Sanjiv Gupta960ae062009-05-06 08:02:01 +000023#include <string>
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000024
Sanjiv Gupta4394c232008-05-13 09:02:57 +000025namespace llvm {
26 class PIC16TargetMachine;
Sanjiv Gupta4394c232008-05-13 09:02:57 +000027 class FunctionPass;
28 class MachineCodeEmitter;
David Greenea31f96c2009-07-14 20:18:05 +000029 class formatted_raw_ostream;
Sanjiv Gupta4394c232008-05-13 09:02:57 +000030
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000031namespace PIC16CC {
32 enum CondCodes {
33 EQ,
34 NE,
35 LT,
36 LE,
37 GT,
Sanjiv Guptaf7373372009-01-21 05:44:05 +000038 GE,
39 ULT,
40 UGT,
41 ULE,
42 UGE
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000043 };
44}
Sanjiv Guptaa07cae62009-10-15 19:26:25 +000045
46 enum PIC16SectionType {
47 CODE,
48 UDATA,
49 IDATA,
50 ROMDATA,
51 UDATA_OVR,
52 UDATA_SHR
Chris Lattner773416e2009-08-21 23:12:15 +000053 };
54
Chris Lattner773416e2009-08-21 23:12:15 +000055
Sanjiv Gupta258f8512009-05-10 05:23:47 +000056 // External symbol names require memory to live till the program end.
57 // So we have to allocate it and keep.
58 inline static const char *createESName (const std::string &name) {
59 char *tmpName = new char[name.size() + 1];
60 strcpy (tmpName, name.c_str());
61 return tmpName;
62 }
Sanjiv Gupta89e72b92009-05-08 04:50:14 +000063
Sanjiv Gupta960ae062009-05-06 08:02:01 +000064
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000065
66 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
67 switch (CC) {
Torok Edwinfbcc6632009-07-14 16:55:14 +000068 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000069 case PIC16CC::NE: return "ne";
70 case PIC16CC::EQ: return "eq";
71 case PIC16CC::LT: return "lt";
Sanjiv Guptaf7373372009-01-21 05:44:05 +000072 case PIC16CC::ULT: return "lt";
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000073 case PIC16CC::LE: return "le";
Sanjiv Guptaa53241a2009-06-03 13:36:44 +000074 case PIC16CC::ULE: return "le";
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000075 case PIC16CC::GT: return "gt";
Sanjiv Guptaf7373372009-01-21 05:44:05 +000076 case PIC16CC::UGT: return "gt";
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000077 case PIC16CC::GE: return "ge";
Sanjiv Guptaa53241a2009-06-03 13:36:44 +000078 case PIC16CC::UGE: return "ge";
Sanjiv Gupta45da8b72009-01-13 19:18:47 +000079 }
80 }
81
Sanjiv Guptaf7373372009-01-21 05:44:05 +000082 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
83 switch (CC) {
Torok Edwinfbcc6632009-07-14 16:55:14 +000084 default: llvm_unreachable("Unknown condition code");
Sanjiv Guptaf7373372009-01-21 05:44:05 +000085 case PIC16CC::NE:
86 case PIC16CC::EQ:
87 case PIC16CC::LT:
88 case PIC16CC::LE:
89 case PIC16CC::GE:
90 case PIC16CC::GT:
91 return true;
92 case PIC16CC::ULT:
93 case PIC16CC::UGT:
94 case PIC16CC::ULE:
95 case PIC16CC::UGE:
96 return false; // condition codes for unsigned comparison.
97 }
98 }
99
Sanjiv Gupta45da8b72009-01-13 19:18:47 +0000100
Sanjiv Gupta960ae062009-05-06 08:02:01 +0000101
Sanjiv Gupta4394c232008-05-13 09:02:57 +0000102 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
Daniel Dunbar5680b4f2009-07-25 06:49:55 +0000103 // Banksel optimizer pass.
Sanjiv Gupta960ae062009-05-06 08:02:01 +0000104 FunctionPass *createPIC16MemSelOptimizerPass();
Daniel Dunbar67038c12009-07-18 23:03:22 +0000105
106 extern Target ThePIC16Target;
107 extern Target TheCooperTarget;
108
Sanjiv Gupta4394c232008-05-13 09:02:57 +0000109} // end namespace llvm;
110
111// Defines symbolic names for PIC16 registers. This defines a mapping from
112// register name to register number.
113#include "PIC16GenRegisterNames.inc"
114
115// Defines symbolic names for the PIC16 instructions.
116#include "PIC16GenInstrNames.inc"
117
118#endif