Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 1 | //===-- PIC16AsmPrinter.cpp - PIC16 LLVM assembly writer ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to PIC16 assembly language. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 15 | #include "PIC16AsmPrinter.h" |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 16 | #include "PIC16Section.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 17 | #include "PIC16TargetAsmInfo.h" |
Bill Wendling | cb819f1 | 2009-02-18 23:12:06 +0000 | [diff] [blame] | 18 | #include "llvm/DerivedTypes.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 19 | #include "llvm/Function.h" |
| 20 | #include "llvm/Module.h" |
Bill Wendling | cb819f1 | 2009-02-18 23:12:06 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/DwarfWriter.h" |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Sanjiv Gupta | 5274a4a | 2009-04-02 18:03:10 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/DwarfWriter.h" |
| 24 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Daniel Dunbar | 0c795d6 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetRegistry.h" |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetLoweringObjectFile.h" |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ErrorHandling.h" |
| 28 | #include "llvm/Support/FormattedStream.h" |
| 29 | #include "llvm/Support/Mangler.h" |
Benjamin Kramer | b8d222d | 2009-08-07 10:42:28 +0000 | [diff] [blame] | 30 | #include <cstring> |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 33 | #include "PIC16GenAsmWriter.inc" |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 34 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 35 | PIC16AsmPrinter::PIC16AsmPrinter(formatted_raw_ostream &O, TargetMachine &TM, |
| 36 | const TargetAsmInfo *T, bool V) |
| 37 | : AsmPrinter(O, TM, T, V), DbgInfo(O, T) { |
| 38 | PTLI = static_cast<const PIC16TargetLowering*>(TM.getTargetLowering()); |
| 39 | PTAI = static_cast<const PIC16TargetAsmInfo*>(T); |
Chris Lattner | f4b64f6 | 2009-07-28 03:20:34 +0000 | [diff] [blame] | 40 | PTOF = (PIC16TargetObjectFile*)&PTLI->getObjFileLowering(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 43 | bool PIC16AsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 44 | printInstruction(MI); |
| 45 | return true; |
| 46 | } |
| 47 | |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 48 | /// runOnMachineFunction - This emits the frame section, autos section and |
| 49 | /// assembly for each instruction. Also takes care of function begin debug |
| 50 | /// directive and file begin debug directive (if required) for the function. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 51 | /// |
| 52 | bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 53 | this->MF = &MF; |
| 54 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 55 | // This calls the base class function required to be called at beginning |
| 56 | // of runOnMachineFunction. |
| 57 | SetupMachineFunction(MF); |
| 58 | |
| 59 | // Get the mangled name. |
| 60 | const Function *F = MF.getFunction(); |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 61 | CurrentFnName = Mang->getMangledName(F); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 62 | |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 63 | // Emit the function frame (args and temps). |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 64 | EmitFunctionFrame(MF); |
| 65 | |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 66 | DbgInfo.BeginFunction(MF); |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 67 | |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 68 | // Emit the autos section of function. |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 69 | EmitAutos(CurrentFnName); |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 70 | |
| 71 | // Now emit the instructions of function in its code section. |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 72 | const MCSection *fCodeSection = |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 73 | getObjFileLowering().getSectionForFunction(CurrentFnName); |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 74 | // Start the Code Section. |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 75 | O << "\n"; |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 76 | SwitchToSection(fCodeSection); |
Sanjiv Gupta | c1fa70c | 2009-04-08 06:24:04 +0000 | [diff] [blame] | 77 | |
| 78 | // Emit the frame address of the function at the beginning of code. |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 79 | O << "\tretlw low(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; |
| 80 | O << "\tretlw high(" << PAN::getFrameLabel(CurrentFnName) << ")\n"; |
Sanjiv Gupta | 7836fc1 | 2009-04-08 05:38:48 +0000 | [diff] [blame] | 81 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 82 | // Emit function start label. |
| 83 | O << CurrentFnName << ":\n"; |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 84 | |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 85 | DebugLoc CurDL; |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 86 | O << "\n"; |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 87 | // Print out code for the function. |
| 88 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 89 | I != E; ++I) { |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 90 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 91 | // Print a label for the basic block. |
| 92 | if (I != MF.begin()) { |
| 93 | printBasicBlockLabel(I, true); |
| 94 | O << '\n'; |
| 95 | } |
Sanjiv Gupta | c1fa70c | 2009-04-08 06:24:04 +0000 | [diff] [blame] | 96 | |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 97 | // Print a basic block. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 98 | for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end(); |
| 99 | II != E; ++II) { |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 100 | |
Sanjiv Gupta | c1fa70c | 2009-04-08 06:24:04 +0000 | [diff] [blame] | 101 | // Emit the line directive if source line changed. |
| 102 | const DebugLoc DL = II->getDebugLoc(); |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 103 | if (!DL.isUnknown() && DL != CurDL) { |
| 104 | DbgInfo.ChangeDebugLoc(MF, DL); |
| 105 | CurDL = DL; |
Sanjiv Gupta | c1fa70c | 2009-04-08 06:24:04 +0000 | [diff] [blame] | 106 | } |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 107 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 108 | // Print the assembly for the instruction. |
Sanjiv Gupta | c1fa70c | 2009-04-08 06:24:04 +0000 | [diff] [blame] | 109 | printMachineInstruction(II); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 112 | |
| 113 | // Emit function end debug directives. |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 114 | DbgInfo.EndFunction(MF); |
Sanjiv Gupta | b65d1f2 | 2009-06-11 06:49:55 +0000 | [diff] [blame] | 115 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 116 | return false; // we didn't modify anything. |
| 117 | } |
| 118 | |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 119 | |
| 120 | // printOperand - print operand of insn. |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 121 | void PIC16AsmPrinter::printOperand(const MachineInstr *MI, int opNum) { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 122 | const MachineOperand &MO = MI->getOperand(opNum); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 123 | |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 124 | switch (MO.getType()) { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 125 | case MachineOperand::MO_Register: |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 126 | if (TargetRegisterInfo::isPhysicalRegister(MO.getReg())) |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 127 | O << TM.getRegisterInfo()->get(MO.getReg()).AsmName; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 128 | else |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 129 | llvm_unreachable("not implemented"); |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 130 | return; |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 131 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 132 | case MachineOperand::MO_Immediate: |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 133 | O << (int)MO.getImm(); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 134 | return; |
Sanjiv Gupta | 2010b3e | 2008-05-14 11:31:39 +0000 | [diff] [blame] | 135 | |
Sanjiv Gupta | 2bdf490 | 2009-04-20 16:59:35 +0000 | [diff] [blame] | 136 | case MachineOperand::MO_GlobalAddress: { |
Sanjiv Gupta | e409f0a | 2009-07-30 04:15:15 +0000 | [diff] [blame] | 137 | std::string Sname = Mang->getMangledName(MO.getGlobal()); |
| 138 | // FIXME: currently we do not have a memcpy def coming in the module |
| 139 | // by any chance, as we do not link in those as .bc lib. So these calls |
| 140 | // are always external and it is safe to emit an extern. |
| 141 | if (PAN::isMemIntrinsic(Sname)) { |
| 142 | LibcallDecls.push_back(createESName(Sname)); |
| 143 | } |
| 144 | |
| 145 | O << Sname; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 146 | break; |
Sanjiv Gupta | 2bdf490 | 2009-04-20 16:59:35 +0000 | [diff] [blame] | 147 | } |
| 148 | case MachineOperand::MO_ExternalSymbol: { |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 149 | const char *Sname = MO.getSymbolName(); |
| 150 | |
| 151 | // If its a libcall name, record it to decls section. |
| 152 | if (PAN::getSymbolTag(Sname) == PAN::LIBCALL) { |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 153 | LibcallDecls.push_back(Sname); |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Sanjiv Gupta | e409f0a | 2009-07-30 04:15:15 +0000 | [diff] [blame] | 156 | // Record a call to intrinsic to print the extern declaration for it. |
| 157 | std::string Sym = Sname; |
| 158 | if (PAN::isMemIntrinsic(Sym)) { |
| 159 | Sym = PAN::addPrefix(Sym); |
| 160 | LibcallDecls.push_back(createESName(Sym)); |
| 161 | } |
| 162 | |
| 163 | O << Sym; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 164 | break; |
Sanjiv Gupta | 2bdf490 | 2009-04-20 16:59:35 +0000 | [diff] [blame] | 165 | } |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 166 | case MachineOperand::MO_MachineBasicBlock: |
| 167 | printBasicBlockLabel(MO.getMBB()); |
| 168 | return; |
| 169 | |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 170 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 171 | llvm_unreachable(" Operand type not supported."); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Sanjiv Gupta | fa3f80a | 2009-06-11 06:55:48 +0000 | [diff] [blame] | 175 | /// printCCOperand - Print the cond code operand. |
| 176 | /// |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 177 | void PIC16AsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) { |
| 178 | int CC = (int)MI->getOperand(opNum).getImm(); |
| 179 | O << PIC16CondCodeToString((PIC16CC::CondCodes)CC); |
| 180 | } |
| 181 | |
Sanjiv Gupta | be7b97b | 2009-07-27 18:04:34 +0000 | [diff] [blame] | 182 | // This function is used to sort the decls list. |
| 183 | // should return true if s1 should come before s2. |
| 184 | static bool is_before(const char *s1, const char *s2) { |
Benjamin Kramer | b8d222d | 2009-08-07 10:42:28 +0000 | [diff] [blame] | 185 | return strcmp(s1, s2) <= 0; |
Sanjiv Gupta | be7b97b | 2009-07-27 18:04:34 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | // This is used by list::unique below. |
| 189 | // unique will filter out duplicates if it knows them. |
| 190 | static bool is_duplicate(const char *s1, const char *s2) { |
Benjamin Kramer | b8d222d | 2009-08-07 10:42:28 +0000 | [diff] [blame] | 191 | return !strcmp(s1, s2); |
Sanjiv Gupta | be7b97b | 2009-07-27 18:04:34 +0000 | [diff] [blame] | 192 | } |
| 193 | |
Sanjiv Gupta | fa3f80a | 2009-06-11 06:55:48 +0000 | [diff] [blame] | 194 | /// printLibcallDecls - print the extern declarations for compiler |
| 195 | /// intrinsics. |
| 196 | /// |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 197 | void PIC16AsmPrinter::printLibcallDecls(void) { |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 198 | // If no libcalls used, return. |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 199 | if (LibcallDecls.empty()) return; |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 200 | |
Sanjiv Gupta | 4291857 | 2009-05-12 06:52:41 +0000 | [diff] [blame] | 201 | O << TAI->getCommentString() << "External decls for libcalls - BEGIN." <<"\n"; |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 202 | // Remove duplicate entries. |
Sanjiv Gupta | be7b97b | 2009-07-27 18:04:34 +0000 | [diff] [blame] | 203 | LibcallDecls.sort(is_before); |
| 204 | LibcallDecls.unique(is_duplicate); |
| 205 | |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 206 | for (std::list<const char*>::const_iterator I = LibcallDecls.begin(); |
| 207 | I != LibcallDecls.end(); I++) { |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 208 | O << TAI->getExternDirective() << *I << "\n"; |
Sanjiv Gupta | e0b4b0e | 2009-05-11 08:52:04 +0000 | [diff] [blame] | 209 | O << TAI->getExternDirective() << PAN::getArgsLabel(*I) << "\n"; |
| 210 | O << TAI->getExternDirective() << PAN::getRetvalLabel(*I) << "\n"; |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 211 | } |
Sanjiv Gupta | 4291857 | 2009-05-12 06:52:41 +0000 | [diff] [blame] | 212 | O << TAI->getCommentString() << "External decls for libcalls - END." <<"\n"; |
Sanjiv Gupta | 0608b49 | 2009-05-11 06:01:38 +0000 | [diff] [blame] | 213 | } |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 214 | |
Sanjiv Gupta | fa3f80a | 2009-06-11 06:55:48 +0000 | [diff] [blame] | 215 | /// doInitialization - Perfrom Module level initializations here. |
| 216 | /// One task that we do here is to sectionize all global variables. |
| 217 | /// The MemSelOptimizer pass depends on the sectionizing. |
| 218 | /// |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 219 | bool PIC16AsmPrinter::doInitialization(Module &M) { |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 220 | bool Result = AsmPrinter::doInitialization(M); |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 221 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 222 | // FIXME:: This is temporary solution to generate the include file. |
| 223 | // The processor should be passed to llc as in input and the header file |
| 224 | // should be generated accordingly. |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 225 | O << "\n\t#include P16F1937.INC\n"; |
Sanjiv Gupta | 5274a4a | 2009-04-02 18:03:10 +0000 | [diff] [blame] | 226 | |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 227 | // Set the section names for all globals. |
| 228 | for (Module::global_iterator I = M.global_begin(), E = M.global_end(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 229 | I != E; ++I) |
Chris Lattner | 93b6db3 | 2009-08-08 23:39:42 +0000 | [diff] [blame] | 230 | if (!I->isDeclaration() && !I->hasAvailableExternallyLinkage()) { |
| 231 | const MCSection *S = getObjFileLowering().SectionForGlobal(I, Mang, TM); |
| 232 | |
| 233 | I->setSection(((const MCSectionPIC16*)S)->getName()); |
| 234 | } |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 235 | |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 236 | DbgInfo.BeginModule(M); |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 237 | EmitFunctionDecls(M); |
| 238 | EmitUndefinedVars(M); |
| 239 | EmitDefinedVars(M); |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 240 | EmitIData(M); |
| 241 | EmitUData(M); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 242 | EmitRomData(M); |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 243 | return Result; |
| 244 | } |
| 245 | |
Sanjiv Gupta | fa3f80a | 2009-06-11 06:55:48 +0000 | [diff] [blame] | 246 | /// Emit extern decls for functions imported from other modules, and emit |
| 247 | /// global declarations for function defined in this module and which are |
| 248 | /// available to other modules. |
| 249 | /// |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 250 | void PIC16AsmPrinter::EmitFunctionDecls(Module &M) { |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 251 | // Emit declarations for external functions. |
Sanjiv Gupta | dcb6da3 | 2009-06-13 17:35:54 +0000 | [diff] [blame] | 252 | O <<"\n"<<TAI->getCommentString() << "Function Declarations - BEGIN." <<"\n"; |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 253 | for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) { |
Sanjiv Gupta | 0f009d2 | 2009-07-23 02:11:04 +0000 | [diff] [blame] | 254 | if (I->isIntrinsic()) |
| 255 | continue; |
| 256 | |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 257 | std::string Name = Mang->getMangledName(I); |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 258 | if (Name.compare("@abort") == 0) |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 259 | continue; |
Sanjiv Gupta | 85be408 | 2009-04-14 02:49:52 +0000 | [diff] [blame] | 260 | |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 261 | if (!I->isDeclaration() && !I->hasExternalLinkage()) |
Sanjiv Gupta | af3fdb5 | 2009-05-10 16:18:39 +0000 | [diff] [blame] | 262 | continue; |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 263 | |
Sanjiv Gupta | e409f0a | 2009-07-30 04:15:15 +0000 | [diff] [blame] | 264 | // Do not emit memcpy, memset, and memmove here. |
| 265 | // Calls to these routines can be generated in two ways, |
| 266 | // 1. User calling the standard lib function |
| 267 | // 2. Codegen generating these calls for llvm intrinsics. |
| 268 | // In the first case a prototype is alread availale, while in |
| 269 | // second case the call is via and externalsym and the prototype is missing. |
| 270 | // So declarations for these are currently always getting printing by |
| 271 | // tracking both kind of references in printInstrunction. |
| 272 | if (I->isDeclaration() && PAN::isMemIntrinsic(Name)) continue; |
| 273 | |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 274 | const char *directive = I->isDeclaration() ? TAI->getExternDirective() : |
| 275 | TAI->getGlobalDirective(); |
| 276 | |
| 277 | O << directive << Name << "\n"; |
| 278 | O << directive << PAN::getRetvalLabel(Name) << "\n"; |
| 279 | O << directive << PAN::getArgsLabel(Name) << "\n"; |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 280 | } |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 281 | |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 282 | O << TAI->getCommentString() << "Function Declarations - END." <<"\n"; |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 283 | } |
Sanjiv Gupta | 2cc7531 | 2009-02-10 04:20:26 +0000 | [diff] [blame] | 284 | |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 285 | // Emit variables imported from other Modules. |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 286 | void PIC16AsmPrinter::EmitUndefinedVars(Module &M) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 287 | std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDecls->Items; |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 288 | if (!Items.size()) return; |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 289 | |
| 290 | O << "\n" << TAI->getCommentString() << "Imported Variables - BEGIN" << "\n"; |
| 291 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 292 | O << TAI->getExternDirective() << Mang->getMangledName(Items[j]) << "\n"; |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 293 | } |
| 294 | O << TAI->getCommentString() << "Imported Variables - END" << "\n"; |
| 295 | } |
| 296 | |
| 297 | // Emit variables defined in this module and are available to other modules. |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 298 | void PIC16AsmPrinter::EmitDefinedVars(Module &M) { |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 299 | std::vector<const GlobalVariable*> Items = PTOF->ExternalVarDefs->Items; |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 300 | if (!Items.size()) return; |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 301 | |
Chris Lattner | a46cb52 | 2009-07-21 17:20:18 +0000 | [diff] [blame] | 302 | O << "\n" << TAI->getCommentString() << "Exported Variables - BEGIN" << "\n"; |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 303 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 304 | O << TAI->getGlobalDirective() << Mang->getMangledName(Items[j]) << "\n"; |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 305 | } |
| 306 | O << TAI->getCommentString() << "Exported Variables - END" << "\n"; |
| 307 | } |
| 308 | |
| 309 | // Emit initialized data placed in ROM. |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 310 | void PIC16AsmPrinter::EmitRomData(Module &M) { |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 311 | // Print ROM Data section. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 312 | const std::vector<PIC16Section*> &ROSections = PTOF->ROSections; |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 313 | for (unsigned i = 0; i < ROSections.size(); i++) { |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 314 | const std::vector<const GlobalVariable*> &Items = ROSections[i]->Items; |
| 315 | if (!Items.size()) continue; |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 316 | O << "\n"; |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 317 | SwitchToSection(PTOF->ROSections[i]->S_); |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 318 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 319 | O << Mang->getMangledName(Items[j]); |
Sanjiv Gupta | 505996f | 2009-07-06 10:18:37 +0000 | [diff] [blame] | 320 | Constant *C = Items[j]->getInitializer(); |
| 321 | int AddrSpace = Items[j]->getType()->getAddressSpace(); |
| 322 | EmitGlobalConstant(C, AddrSpace); |
| 323 | } |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 324 | } |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 327 | bool PIC16AsmPrinter::doFinalization(Module &M) { |
Sanjiv Gupta | ad6585b | 2009-05-13 15:13:17 +0000 | [diff] [blame] | 328 | printLibcallDecls(); |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 329 | EmitRemainingAutos(); |
Sanjiv Gupta | bde7942 | 2009-06-16 09:45:18 +0000 | [diff] [blame] | 330 | DbgInfo.EndModule(M); |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 331 | O << "\n\t" << "END\n"; |
Chris Lattner | 40bbebd | 2009-07-21 18:38:57 +0000 | [diff] [blame] | 332 | return AsmPrinter::doFinalization(M); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 335 | void PIC16AsmPrinter::EmitFunctionFrame(MachineFunction &MF) { |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 336 | const Function *F = MF.getFunction(); |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 337 | std::string FuncName = Mang->getMangledName(F); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 338 | const TargetData *TD = TM.getTargetData(); |
Sanjiv Gupta | b1b5ffd | 2008-11-19 11:00:54 +0000 | [diff] [blame] | 339 | // Emit the data section name. |
| 340 | O << "\n"; |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 341 | |
Chris Lattner | a87dea4 | 2009-07-31 18:48:30 +0000 | [diff] [blame] | 342 | const MCSection *fPDataSection = |
Chris Lattner | 759b888 | 2009-08-06 16:27:28 +0000 | [diff] [blame] | 343 | getObjFileLowering().getSectionForFunctionFrame(CurrentFnName); |
Sanjiv Gupta | 2bdf490 | 2009-04-20 16:59:35 +0000 | [diff] [blame] | 344 | SwitchToSection(fPDataSection); |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 345 | |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 346 | // Emit function frame label |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 347 | O << PAN::getFrameLabel(CurrentFnName) << ":\n"; |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 348 | |
Sanjiv Gupta | 8f78fa8 | 2008-11-26 10:53:50 +0000 | [diff] [blame] | 349 | const Type *RetType = F->getReturnType(); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 350 | unsigned RetSize = 0; |
| 351 | if (RetType->getTypeID() != Type::VoidTyID) |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 352 | RetSize = TD->getTypeAllocSize(RetType); |
Sanjiv Gupta | 1b04694 | 2009-01-13 19:18:47 +0000 | [diff] [blame] | 353 | |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 354 | //Emit function return value space |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 355 | // FIXME: Do not emit RetvalLable when retsize is zero. To do this |
| 356 | // we will need to avoid printing a global directive for Retval label |
| 357 | // in emitExternandGloblas. |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 358 | if(RetSize > 0) |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 359 | O << PAN::getRetvalLabel(CurrentFnName) << " RES " << RetSize << "\n"; |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 360 | else |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 361 | O << PAN::getRetvalLabel(CurrentFnName) << ": \n"; |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 362 | |
| 363 | // Emit variable to hold the space for function arguments |
| 364 | unsigned ArgSize = 0; |
| 365 | for (Function::const_arg_iterator argi = F->arg_begin(), |
| 366 | arge = F->arg_end(); argi != arge ; ++argi) { |
| 367 | const Type *Ty = argi->getType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 368 | ArgSize += TD->getTypeAllocSize(Ty); |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 369 | } |
Sanjiv Gupta | 211f362 | 2009-05-10 05:23:47 +0000 | [diff] [blame] | 370 | |
| 371 | O << PAN::getArgsLabel(CurrentFnName) << " RES " << ArgSize << "\n"; |
Sanjiv Gupta | b84d5a4 | 2009-04-02 17:42:00 +0000 | [diff] [blame] | 372 | |
Sanjiv Gupta | 85be408 | 2009-04-14 02:49:52 +0000 | [diff] [blame] | 373 | // Emit temporary space |
| 374 | int TempSize = PTLI->GetTmpSize(); |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 375 | if (TempSize > 0) |
| 376 | O << PAN::getTempdataLabel(CurrentFnName) << " RES " << TempSize << '\n'; |
Sanjiv Gupta | 0e68771 | 2008-05-13 09:02:57 +0000 | [diff] [blame] | 377 | } |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 378 | |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 379 | void PIC16AsmPrinter::EmitIData(Module &M) { |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 380 | |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 381 | // Print all IDATA sections. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 382 | const std::vector<PIC16Section*> &IDATASections = PTOF->IDATASections; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 383 | for (unsigned i = 0; i < IDATASections.size(); i++) { |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 384 | O << "\n"; |
Sanjiv Gupta | 024e94c | 2009-07-06 18:07:06 +0000 | [diff] [blame] | 385 | if (IDATASections[i]->S_->getName().find("llvm.") != std::string::npos) |
| 386 | continue; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 387 | SwitchToSection(IDATASections[i]->S_); |
| 388 | std::vector<const GlobalVariable*> Items = IDATASections[i]->Items; |
| 389 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 390 | std::string Name = Mang->getMangledName(Items[j]); |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 391 | Constant *C = Items[j]->getInitializer(); |
| 392 | int AddrSpace = Items[j]->getType()->getAddressSpace(); |
| 393 | O << Name; |
| 394 | EmitGlobalConstant(C, AddrSpace); |
| 395 | } |
| 396 | } |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 397 | } |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 398 | |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 399 | void PIC16AsmPrinter::EmitUData(Module &M) { |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 400 | const TargetData *TD = TM.getTargetData(); |
| 401 | |
| 402 | // Print all BSS sections. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 403 | const std::vector<PIC16Section*> &BSSSections = PTOF->BSSSections; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 404 | for (unsigned i = 0; i < BSSSections.size(); i++) { |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 405 | O << "\n"; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 406 | SwitchToSection(BSSSections[i]->S_); |
| 407 | std::vector<const GlobalVariable*> Items = BSSSections[i]->Items; |
| 408 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 409 | std::string Name = Mang->getMangledName(Items[j]); |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 410 | Constant *C = Items[j]->getInitializer(); |
| 411 | const Type *Ty = C->getType(); |
Duncan Sands | 777d230 | 2009-05-09 07:06:46 +0000 | [diff] [blame] | 412 | unsigned Size = TD->getTypeAllocSize(Ty); |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 413 | |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 414 | O << Name << " RES " << Size << "\n"; |
Sanjiv Gupta | d8d27f4 | 2009-05-06 08:02:01 +0000 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 419 | void PIC16AsmPrinter::EmitAutos(std::string FunctName) { |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 420 | // Section names for all globals are already set. |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 421 | const TargetData *TD = TM.getTargetData(); |
| 422 | |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 423 | // Now print Autos section for this function. |
| 424 | std::string SectionName = PAN::getAutosSectionName(FunctName); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 425 | const std::vector<PIC16Section*> &AutosSections = PTOF->AutosSections; |
Sanjiv Gupta | 2364cfe | 2009-05-12 17:07:27 +0000 | [diff] [blame] | 426 | for (unsigned i = 0; i < AutosSections.size(); i++) { |
| 427 | O << "\n"; |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 428 | if (AutosSections[i]->S_->getName() == SectionName) { |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 429 | // Set the printing status to true |
| 430 | AutosSections[i]->setPrintedStatus(true); |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 431 | SwitchToSection(AutosSections[i]->S_); |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 432 | const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items; |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 433 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 434 | std::string VarName = Mang->getMangledName(Items[j]); |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 435 | Constant *C = Items[j]->getInitializer(); |
| 436 | const Type *Ty = C->getType(); |
| 437 | unsigned Size = TD->getTypeAllocSize(Ty); |
| 438 | // Emit memory reserve directive. |
| 439 | O << VarName << " RES " << Size << "\n"; |
Sanjiv Gupta | a57bc3b | 2009-05-22 13:58:45 +0000 | [diff] [blame] | 440 | } |
Sanjiv Gupta | dd4694b | 2009-05-28 18:24:11 +0000 | [diff] [blame] | 441 | break; |
Sanjiv Gupta | a57bc3b | 2009-05-22 13:58:45 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
Sanjiv Gupta | a57bc3b | 2009-05-22 13:58:45 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 446 | // Print autos that were not printed during the code printing of functions. |
| 447 | // As the functions might themselves would have got deleted by the optimizer. |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 448 | void PIC16AsmPrinter::EmitRemainingAutos() { |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 449 | const TargetData *TD = TM.getTargetData(); |
| 450 | |
| 451 | // Now print Autos section for this function. |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 452 | std::vector <PIC16Section *>AutosSections = PTOF->AutosSections; |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 453 | for (unsigned i = 0; i < AutosSections.size(); i++) { |
| 454 | |
| 455 | // if the section is already printed then don't print again |
| 456 | if (AutosSections[i]->isPrinted()) |
| 457 | continue; |
| 458 | |
| 459 | // Set status as printed |
| 460 | AutosSections[i]->setPrintedStatus(true); |
| 461 | |
| 462 | O << "\n"; |
| 463 | SwitchToSection(AutosSections[i]->S_); |
Chris Lattner | dc47146 | 2009-07-21 16:44:47 +0000 | [diff] [blame] | 464 | const std::vector<const GlobalVariable*> &Items = AutosSections[i]->Items; |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 465 | for (unsigned j = 0; j < Items.size(); j++) { |
Chris Lattner | b8158ac | 2009-07-14 18:17:16 +0000 | [diff] [blame] | 466 | std::string VarName = Mang->getMangledName(Items[j]); |
Sanjiv Gupta | b157f25 | 2009-06-09 15:31:19 +0000 | [diff] [blame] | 467 | Constant *C = Items[j]->getInitializer(); |
| 468 | const Type *Ty = C->getType(); |
| 469 | unsigned Size = TD->getTypeAllocSize(Ty); |
| 470 | // Emit memory reserve directive. |
| 471 | O << VarName << " RES " << Size << "\n"; |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
Daniel Dunbar | 0c795d6 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 476 | |
| 477 | extern "C" void LLVMInitializePIC16Target() { |
| 478 | // Register the targets |
| 479 | RegisterTargetMachine<PIC16TargetMachine> A(ThePIC16Target); |
| 480 | RegisterTargetMachine<CooperTargetMachine> B(TheCooperTarget); |
| 481 | RegisterAsmPrinter<PIC16AsmPrinter> C(ThePIC16Target); |
| 482 | RegisterAsmPrinter<PIC16AsmPrinter> D(TheCooperTarget); |
| 483 | } |