1 //===-- PIC16.h - Top-level interface for PIC16 representation --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the entry points for global functions defined in
11 // the LLVM PIC16 back-end.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_PIC16_H
16 #define LLVM_TARGET_PIC16_H
18 #include "llvm/Target/TargetMachine.h"
25 class PIC16TargetMachine;
27 class MachineCodeEmitter;
44 // A Central object to manage all ABI naming conventions.
47 // Map the name of the symbol to its section name.
49 // ------------------------------------------------------
50 // Global variables do not have any '.' in their names.
51 // they are prefixed with @
52 // These are maily function names and global variable names.
53 // -------------------------------------------------------
54 // Functions and auto variables.
55 // Names are mangled as <prefix><funcname>.<id>.<varname>
56 // Where prefix is a special char '@' and id is any one of
58 // .auto. - an automatic var of a function.
59 // .temp. - temproray data of a function.
60 // .ret. - return value label for a function.
61 // .frame. - Frame label for a function where retval, args
62 // and temps are stored.
63 // .args. - Label used to pass arguments to a direct call.
64 // Example - Function name: @foo
65 // Its frame: @foo.frame.
66 // Its retval: @foo.ret.
67 // Its local vars: @foo.auto.a
68 // Its temp data: @foo.temp.
69 // Its arg passing: @foo.args.
70 //----------------------------------------------
71 // Libcall - compiler generated libcall names must have a .lib.
72 // This id will be used to emit extern decls for libcalls.
73 // Example - libcall name: @sra_i8.lib.
74 // To pass args: @sra_i8.args.
75 // To return val: @sra_i8.ret.
76 //----------------------------------------------
93 inline static const char *getIDName(IDs id) {
95 default: assert(0 && "Unknown id");
96 case PREFIX_SYMBOL: return "@";
97 case FUNC_AUTOS: return ".auto.";
98 case FUNC_FRAME: return ".frame.";
99 case FUNC_TEMPS: return ".temp.";
100 case FUNC_ARGS: return ".args.";
101 case FUNC_RET: return ".ret.";
102 case FRAME_SECTION: return "fpdata";
103 case AUTOS_SECTION: return "fadata";
107 inline static IDs getID(const std::string &Sym) {
108 if (Sym.find(getIDName(FUNC_TEMPS)))
111 if (Sym.find(getIDName(FUNC_FRAME)))
114 if (Sym.find(getIDName(FUNC_RET)))
117 if (Sym.find(getIDName(FUNC_ARGS)))
120 if (Sym.find(getIDName(FUNC_AUTOS)))
123 if (Sym.find(getIDName(LIBCALL)))
126 // It does not have any ID. So its a global.
127 assert (0 && "Could not determine ID symbol type");
130 // Get func name from a mangled name.
131 // In all cases func name is the first component before a '.'.
132 static inline std::string getFuncNameForSym(const std::string &Sym) {
133 const char *prefix = getIDName (PREFIX_SYMBOL);
135 // If this name has a prefix, func name start after prfix in that case.
136 size_t func_name_start = 0;
137 if (Sym.find(prefix, 0, strlen(prefix)) != std::string::npos)
138 func_name_start = strlen(prefix);
140 // Position of the . after func name. That's where func name ends.
141 size_t func_name_end = Sym.find ('.', func_name_start);
143 return Sym.substr (func_name_start, func_name_end);
146 // Form a section name given the section type and func name.
148 getSectionNameForFunc (const std::string &Fname, const IDs sec_id) {
149 std::string sec_id_string = getIDName(sec_id);
150 return sec_id_string + "." + Fname + ".#";
153 // Get the section for the given external symbol names.
154 // This tries to find the type (ID) of the symbol from its mangled name
155 // and return appropriate section name for it.
156 static inline std::string getSectionNameForSym(const std::string &Sym) {
157 std::string SectionName;
159 IDs id = getID (Sym);
160 std::string Fname = getFuncNameForSym (Sym);
163 default : assert (0 && "Could not determine external symbol type");
168 return getSectionNameForFunc (Fname, FRAME_SECTION);
171 return getSectionNameForFunc (Fname, AUTOS_SECTION);
175 }; // class PIC16ABINames.
180 inline static const char *PIC16CondCodeToString(PIC16CC::CondCodes CC) {
182 default: assert(0 && "Unknown condition code");
183 case PIC16CC::NE: return "ne";
184 case PIC16CC::EQ: return "eq";
185 case PIC16CC::LT: return "lt";
186 case PIC16CC::ULT: return "lt";
187 case PIC16CC::LE: return "le";
188 case PIC16CC::GT: return "gt";
189 case PIC16CC::UGT: return "gt";
190 case PIC16CC::GE: return "ge";
194 inline static bool isSignedComparison(PIC16CC::CondCodes CC) {
196 default: assert(0 && "Unknown condition code");
208 return false; // condition codes for unsigned comparison.
214 FunctionPass *createPIC16ISelDag(PIC16TargetMachine &TM);
215 FunctionPass *createPIC16CodePrinterPass(raw_ostream &OS,
216 PIC16TargetMachine &TM,
217 CodeGenOpt::Level OptLevel,
219 // Banksel optimzer pass.
220 FunctionPass *createPIC16MemSelOptimizerPass();
221 std::string getSectionNameForSym(const std::string &Sym);
222 } // end namespace llvm;
224 // Defines symbolic names for PIC16 registers. This defines a mapping from
225 // register name to register number.
226 #include "PIC16GenRegisterNames.inc"
228 // Defines symbolic names for the PIC16 instructions.
229 #include "PIC16GenInstrNames.inc"