blob: 8d067de676b69c19239dce9da597dda260fa37d4 [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 Gupta4affaea2009-01-13 19:18:47 +000024
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000025namespace llvm {
26 class PIC16TargetMachine;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000027 class FunctionPass;
28 class MachineCodeEmitter;
David Greene302008d2009-07-14 20:18:05 +000029 class formatted_raw_ostream;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000030
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000031namespace PIC16CC {
32 enum CondCodes {
33 EQ,
34 NE,
35 LT,
36 LE,
37 GT,
Sanjiv Gupta691e8132009-01-21 05:44:05 +000038 GE,
39 ULT,
40 UGT,
41 ULE,
42 UGE
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000043 };
44}
Sanjiv Guptaac2620e2009-10-15 19:26:25 +000045
46 enum PIC16SectionType {
47 CODE,
48 UDATA,
49 IDATA,
50 ROMDATA,
51 UDATA_OVR,
52 UDATA_SHR
Chris Lattner7f504882009-08-21 23:12:15 +000053 };
54
Chris Lattner7f504882009-08-21 23:12:15 +000055
Sanjiv Guptaca549b72009-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.
Benjamin Kramerd65ad3c62010-01-28 18:04:38 +000058 // FIXME: Don't leak the allocated strings.
Sanjiv Guptaca549b72009-05-10 05:23:47 +000059 inline static const char *createESName (const std::string &name) {
60 char *tmpName = new char[name.size() + 1];
Benjamin Kramerd65ad3c62010-01-28 18:04:38 +000061 memcpy(tmpName, name.c_str(), name.size() + 1);
Sanjiv Guptaca549b72009-05-10 05:23:47 +000062 return tmpName;
63 }
Sanjiv Gupta03fb67c2009-05-08 04:50:14 +000064
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +000065
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000066
67 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
68 switch (CC) {
Edwin Törökbd448e32009-07-14 16:55:14 +000069 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000070 case PIC16CC::NE: return "ne";
71 case PIC16CC::EQ: return "eq";
72 case PIC16CC::LT: return "lt";
Sanjiv Gupta691e8132009-01-21 05:44:05 +000073 case PIC16CC::ULT: return "lt";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000074 case PIC16CC::LE: return "le";
Sanjiv Gupta0c878bb2009-06-03 13:36:44 +000075 case PIC16CC::ULE: return "le";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000076 case PIC16CC::GT: return "gt";
Sanjiv Gupta691e8132009-01-21 05:44:05 +000077 case PIC16CC::UGT: return "gt";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000078 case PIC16CC::GE: return "ge";
Sanjiv Gupta0c878bb2009-06-03 13:36:44 +000079 case PIC16CC::UGE: return "ge";
Sanjiv Gupta4affaea2009-01-13 19:18:47 +000080 }
81 }
82
Sanjiv Gupta691e8132009-01-21 05:44:05 +000083 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
84 switch (CC) {
Edwin Törökbd448e32009-07-14 16:55:14 +000085 default: llvm_unreachable("Unknown condition code");
Sanjiv Gupta691e8132009-01-21 05:44:05 +000086 case PIC16CC::NE:
87 case PIC16CC::EQ:
88 case PIC16CC::LT:
89 case PIC16CC::LE:
90 case PIC16CC::GE:
91 case PIC16CC::GT:
92 return true;
93 case PIC16CC::ULT:
94 case PIC16CC::UGT:
95 case PIC16CC::ULE:
96 case PIC16CC::UGE:
97 return false; // condition codes for unsigned comparison.
98 }
99 }
100
Sanjiv Gupta4affaea2009-01-13 19:18:47 +0000101
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +0000102
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000103 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
Daniel Dunbarc680b012009-07-25 06:49:55 +0000104 // Banksel optimizer pass.
Sanjiv Guptabb4a5c72009-05-06 08:02:01 +0000105 FunctionPass *createPIC16MemSelOptimizerPass();
Daniel Dunbar0b0441e2009-07-18 23:03:22 +0000106
107 extern Target ThePIC16Target;
108 extern Target TheCooperTarget;
109
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000110} // end namespace llvm;
111
112// Defines symbolic names for PIC16 registers. This defines a mapping from
113// register name to register number.
114#include "PIC16GenRegisterNames.inc"
115
116// Defines symbolic names for the PIC16 instructions.
117#include "PIC16GenInstrNames.inc"
118
119#endif