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