AsmPrinter.h revision 05548eb174dd694b651de334b73197a62e5071f1
1a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner//===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===// 2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 3a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner// The LLVM Compiler Infrastructure 4a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner// 57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source 67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details. 7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman// 8a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner//===----------------------------------------------------------------------===// 9a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner// 10563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey// This file contains a class to be used as the base class for target specific 11563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey// asm writers. This class primarily handles common functionality used by 12563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey// all asm writers. 13a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner// 14a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner//===----------------------------------------------------------------------===// 15a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 16a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner#ifndef LLVM_CODEGEN_ASMPRINTER_H 17a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner#define LLVM_CODEGEN_ASMPRINTER_H 18a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 19a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner#include "llvm/CodeGen/MachineFunctionPass.h" 20190f3ba2aa58dc2e73a5f90dff15015a1ffa226bChris Lattner#include "llvm/Support/DataTypes.h" 2115404d060ba8b604c03b9223a0f2e2abcd0fddedRafael Espindola#include <set> 22a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 23a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattnernamespace llvm { 24a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner class Constant; 25c884db47f1a1d5449b749e6528292451e49025e4Jeff Cohen class ConstantArray; 26ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner class GlobalVariable; 278b0a8c84da2030ee8f4440d5b60a8033de691222Anton Korobeynikov class GlobalAlias; 282d2cec1e9e93a388bd8448f4bad661ac89a49de3Evan Cheng class MachineConstantPoolEntry; 29d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng class MachineConstantPoolValue; 3006816127fd35d4942a092479e9f30279eb050b0bEvan Cheng class MachineModuleInfo; 31563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey class Mangler; 32563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey class TargetAsmInfo; 3384bc5427d6883f73cfeae3da640acd011d35c006Chris Lattner class Type; 34a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 35563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey /// AsmPrinter - This class is intended to be used as a driving class for all 36563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey /// asm writers. 37a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner class AsmPrinter : public MachineFunctionPass { 381997473cf72957d0e70322e2fe6fe2ab141c58a6Devang Patel static char ID; 39794fd75c67a2cdc128d67342c6d88a504d186896Devang Patel 40347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// FunctionNumber - This provides a unique ID for each function emitted in 41347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// this translation unit. It is autoincremented by SetupMachineFunction, 42347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// and can be accessed with getFunctionNumber() and 43347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// IncrementFunctionNumber(). 44347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// 45347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng unsigned FunctionNumber; 46347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng 4706816127fd35d4942a092479e9f30279eb050b0bEvan Cheng /// MachineModuleInfo - This is needed because printDeclare() has to insert 4806816127fd35d4942a092479e9f30279eb050b0bEvan Cheng /// DebugVariable entries into the dwarf table. This is a short term hack 4906816127fd35d4942a092479e9f30279eb050b0bEvan Cheng /// that ought be fixed soon. 5006816127fd35d4942a092479e9f30279eb050b0bEvan Cheng MachineModuleInfo *MMI; 5106816127fd35d4942a092479e9f30279eb050b0bEvan Cheng 5215404d060ba8b604c03b9223a0f2e2abcd0fddedRafael Espindola protected: 5315404d060ba8b604c03b9223a0f2e2abcd0fddedRafael Espindola // Necessary for external weak linkage support 5415404d060ba8b604c03b9223a0f2e2abcd0fddedRafael Espindola std::set<const GlobalValue*> ExtWeakSymbols; 5515404d060ba8b604c03b9223a0f2e2abcd0fddedRafael Espindola 56b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey public: 57a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// Output stream on which we're printing assembly code. 58a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// 59a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner std::ostream &O; 60a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 61a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// Target machine description. 62a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// 63a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner TargetMachine &TM; 64563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey 65563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey /// Target Asm Printer information. 66563321a2582851c653d0863e8e0bba3d483734f9Jim Laskey /// 67a0f3d17daac73c9c71aad497b298cbe82848f726Jim Laskey const TargetAsmInfo *TAI; 68a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 69a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// Name-mangler for global names. 70a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// 71a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner Mangler *Mang; 72a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 73a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// Cache of mangled name for current function. This is recalculated at the 74a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// beginning of each call to runOnMachineFunction(). 75a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// 76a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner std::string CurrentFnName; 7797e32e3239c0f065698f8c004b2b3009162f5ed6Chris Lattner 7889d67faf30ed1a8b5364f53c9a0f5e07a9a0719cJim Laskey /// CurrentSection - The current section we are emitting to. This is 7989d67faf30ed1a8b5364f53c9a0f5e07a9a0719cJim Laskey /// controlled and used by the SwitchSection method. 8089d67faf30ed1a8b5364f53c9a0f5e07a9a0719cJim Laskey std::string CurrentSection; 81fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng 82fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng /// IsInTextSection - True if the current section we are emitting to is a 83fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng /// text section. 84fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng bool IsInTextSection; 85b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey 86b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey protected: 87a0f3d17daac73c9c71aad497b298cbe82848f726Jim Laskey AsmPrinter(std::ostream &o, TargetMachine &TM, const TargetAsmInfo *T); 88ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner 89a7cea6f599418a579ab5ce66413fba7efa8bf581Jim Laskey public: 90f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// SwitchToTextSection - Switch to the specified section of the executable 91f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// if we are not already in it! If GV is non-null and if the global has an 92e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// explicitly requested section, we switch to the section indicated for the 93e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// global instead of NewSection. 94e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// 95e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// If the new section is an empty string, this method forgets what the 96e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// current section is, but does not emit a .section directive. 97e2b1f1188fd8c28977b5cf2a6842fc7bbb008713Chris Lattner /// 98f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// This method is used when about to emit executable code. 99f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// 100b52cf1f1947513c1079a08763594fbb5721e80b5Anton Korobeynikov void SwitchToTextSection(const char *NewSection, const GlobalValue *GV = NULL); 101d5ab7e1c54c961b447395f17b569acdf18776c5aChris Lattner 102f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// SwitchToDataSection - Switch to the specified section of the executable 103f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// if we are not already in it! If GV is non-null and if the global has an 104f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// explicitly requested section, we switch to the section indicated for the 105f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// global instead of NewSection. 106f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// 107f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// If the new section is an empty string, this method forgets what the 108f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// current section is, but does not emit a .section directive. 109f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// 110f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// This method is used when about to emit data. For most assemblers, this 111f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// is the same as the SwitchToTextSection method, but not all assemblers 112f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// are the same. 113f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner /// 114b52cf1f1947513c1079a08763594fbb5721e80b5Anton Korobeynikov void SwitchToDataSection(const char *NewSection, const GlobalValue *GV = NULL); 115f668ffc4c2cf3da8ef0948b316d971c4b41b0e05Chris Lattner 116a1a19f803c8fef05db627a8b73c909a50306e9d6Jim Laskey /// getGlobalLinkName - Returns the asm/link name of of the specified 117a1a19f803c8fef05db627a8b73c909a50306e9d6Jim Laskey /// global variable. Should be overridden by each target asm printer to 118a1a19f803c8fef05db627a8b73c909a50306e9d6Jim Laskey /// generate the appropriate value. 11999e41eed6d8b89b2ba4807625d13d08d85ea493dJim Laskey virtual const std::string getGlobalLinkName(const GlobalVariable *GV) const; 120a1a19f803c8fef05db627a8b73c909a50306e9d6Jim Laskey 121bda9b0ec7bd6974cebf751ecd23c5434b34054e9Jim Laskey /// EmitExternalGlobal - Emit the external reference to a global variable. 122bda9b0ec7bd6974cebf751ecd23c5434b34054e9Jim Laskey /// Should be overridden if an indirect reference should be used. 123bda9b0ec7bd6974cebf751ecd23c5434b34054e9Jim Laskey virtual void EmitExternalGlobal(const GlobalVariable *GV); 124bda9b0ec7bd6974cebf751ecd23c5434b34054e9Jim Laskey 1256e19896999f9297db38e1a1a66d9bef0e2f09776Bill Wendling /// getCurrentFunctionEHName - Called to return (and cache) the 1266e19896999f9297db38e1a1a66d9bef0e2f09776Bill Wendling /// CurrentFnEHName. 1276e19896999f9297db38e1a1a66d9bef0e2f09776Bill Wendling /// 128ce613280f987584df15ada06c5cf4809b203da46Bill Wendling std::string getCurrentFunctionEHName(const MachineFunction *MF); 1296e19896999f9297db38e1a1a66d9bef0e2f09776Bill Wendling 130a7cea6f599418a579ab5ce66413fba7efa8bf581Jim Laskey protected: 131ce2247755e56f99a2377b64a1a9d393726582b85Gordon Henriksen /// getAnalysisUsage - Record analysis usage. 132ce2247755e56f99a2377b64a1a9d393726582b85Gordon Henriksen /// 133ce2247755e56f99a2377b64a1a9d393726582b85Gordon Henriksen void getAnalysisUsage(AnalysisUsage &AU) const; 134ce2247755e56f99a2377b64a1a9d393726582b85Gordon Henriksen 135a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// doInitialization - Set up the AsmPrinter when we are working on a new 136a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// module. If your pass overrides this, it must make sure to explicitly 137a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// call this implementation. 138a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner bool doInitialization(Module &M); 139a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 140a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// doFinalization - Shut down the asmprinter. If you override this in your 141a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// pass, you must make sure to call it explicitly. 142a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner bool doFinalization(Module &M); 1433ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner 1443ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// PrintSpecial - Print information related to the specified machine instr 1453ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// that is independent of the operand, and may be independent of the instr 1463ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// itself. This can be useful for portably encoding the comment character 1473ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// or other bits of target-specific knowledge into the asmstrings. The 1483ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// syntax used is ${:comment}. Targets can override this to add support 1493ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner /// for their own strange codes. 1503ce9b67e0c0f171c6d09c19407930ce6989f1b9dChris Lattner virtual void PrintSpecial(const MachineInstr *MI, const char *Code); 15147cf4eda9faa3c0b063337d0eb4ea83aba8cb329Chris Lattner 15247cf4eda9faa3c0b063337d0eb4ea83aba8cb329Chris Lattner /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM 15347cf4eda9faa3c0b063337d0eb4ea83aba8cb329Chris Lattner /// instruction, using the specified assembler variant. Targets should 154b44b5094110508e2381615b15077b388364f7e8aChris Lattner /// override this to format as appropriate. This method can return true if 15547cf4eda9faa3c0b063337d0eb4ea83aba8cb329Chris Lattner /// the operand is erroneous. 15647cf4eda9faa3c0b063337d0eb4ea83aba8cb329Chris Lattner virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, 157f483e58212d018f8b2ec760f59089e72defab5cfChris Lattner unsigned AsmVariant, const char *ExtraCode); 158b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey 159b44b5094110508e2381615b15077b388364f7e8aChris Lattner /// PrintAsmMemoryOperand - Print the specified operand of MI, an INLINEASM 160b44b5094110508e2381615b15077b388364f7e8aChris Lattner /// instruction, using the specified assembler variant as an address. 161b44b5094110508e2381615b15077b388364f7e8aChris Lattner /// Targets should override this to format as appropriate. This method can 162b44b5094110508e2381615b15077b388364f7e8aChris Lattner /// return true if the operand is erroneous. 163b44b5094110508e2381615b15077b388364f7e8aChris Lattner virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, 164b44b5094110508e2381615b15077b388364f7e8aChris Lattner unsigned AsmVariant, 165b44b5094110508e2381615b15077b388364f7e8aChris Lattner const char *ExtraCode); 166b44b5094110508e2381615b15077b388364f7e8aChris Lattner 1671279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner /// getSectionForFunction - Return the section that we should emit the 1681279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner /// specified function body into. This defaults to 'TextSection'. This 1691279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner /// should most likely be overridden by the target to put linkonce/weak 1701279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner /// functions into special sections. 1711279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner virtual std::string getSectionForFunction(const Function &F) const; 1721279b7c2a9849b499d5997d7efb5c0d6e902ca62Chris Lattner 1736fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner /// SetupMachineFunction - This should be called when a new MachineFunction 174a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// is being processed from runOnMachineFunction. 1756fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner void SetupMachineFunction(MachineFunction &MF); 17697e32e3239c0f065698f8c004b2b3009162f5ed6Chris Lattner 177347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// getFunctionNumber - Return a unique ID for the current function. 178347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// 179347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng unsigned getFunctionNumber() const { return FunctionNumber; } 180347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng 181347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// IncrementFunctionNumber - Increase Function Number. AsmPrinters should 182347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// not normally call this, as the counter is automatically bumped by 183347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng /// SetupMachineFunction. 184347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng void IncrementFunctionNumber() { FunctionNumber++; } 185347d39f1fd8ad825a7ec5b8a3dce816723a56d42Evan Cheng 186ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// EmitConstantPool - Print to the current output stream assembly 187ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// representations of the constants in the constant pool MCP. This is 188ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// used to print out constants which have been "spilled to memory" by 189ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// the code generator. 190ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// 1912d2cec1e9e93a388bd8448f4bad661ac89a49de3Evan Cheng void EmitConstantPool(MachineConstantPool *MCP); 192a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 19337efe6764568a3829fee26aba532283131d1a104Nate Begeman /// EmitJumpTableInfo - Print assembly representations of the jump tables 19437efe6764568a3829fee26aba532283131d1a104Nate Begeman /// used by the current function to the current output stream. 19537efe6764568a3829fee26aba532283131d1a104Nate Begeman /// 1961da31ee472b9615d7329c656e2cc17c419ed7c95Chris Lattner void EmitJumpTableInfo(MachineJumpTableInfo *MJTI, MachineFunction &MF); 19737efe6764568a3829fee26aba532283131d1a104Nate Begeman 198ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// EmitSpecialLLVMGlobal - Check to see if the specified global is a 199ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// special global used by LLVM. If so, emit it and return true, otherwise 200ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner /// do nothing and return false. 201ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner bool EmitSpecialLLVMGlobal(const GlobalVariable *GV); 202a1a19f803c8fef05db627a8b73c909a50306e9d6Jim Laskey 203f9e56198a39a08272c072211722b3c97ef88853cJim Laskey public: 204f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey //===------------------------------------------------------------------===// 205f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// LEB 128 number encoding. 206f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 207f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// PrintULEB128 - Print a series of hexidecimal values(separated by commas) 208f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// representing an unsigned leb128 value. 209f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void PrintULEB128(unsigned Value) const; 210f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 211f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// SizeULEB128 - Compute the number of bytes required for an unsigned 212f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// leb128 value. 213f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey static unsigned SizeULEB128(unsigned Value); 214f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 215f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// PrintSLEB128 - Print a series of hexidecimal values(separated by commas) 216f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// representing a signed leb128 value. 217f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void PrintSLEB128(int Value) const; 218f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 219f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// SizeSLEB128 - Compute the number of bytes required for a signed leb128 220f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// value. 221f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey static unsigned SizeSLEB128(int Value); 222f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 223f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey //===------------------------------------------------------------------===// 224f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey // Emission and print routines 225f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey // 226f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 227f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// PrintHex - Print a value as a hexidecimal value. 228f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// 229f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void PrintHex(int Value) const; 230f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 231f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EOL - Print a newline character to asm stream. If a comment is present 232f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// then it will be printed first. Comments should not contain '\n'. 233bda9b0ec7bd6974cebf751ecd23c5434b34054e9Jim Laskey void EOL() const; 234f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EOL(const std::string &Comment) const; 235f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 236f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an 237f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// unsigned leb128 value. 238f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitULEB128Bytes(unsigned Value) const; 239f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 240f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitSLEB128Bytes - print an assembler byte data directive to compose a 241f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// signed leb128 value. 242f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitSLEB128Bytes(int Value) const; 243f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 244f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitInt8 - Emit a byte directive and value. 245f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// 246f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitInt8(int Value) const; 247f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 248f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitInt16 - Emit a short directive and value. 249f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// 250f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitInt16(int Value) const; 251f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 252f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitInt32 - Emit a long directive and value. 253f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// 254f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitInt32(int Value) const; 255f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 256f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitInt64 - Emit a long long directive and value. 257f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// 258f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitInt64(uint64_t Value) const; 259f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 260f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// EmitString - Emit a string with quotes and a null terminator. 261f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey /// Special characters are emitted properly. 262181b6c9cb5def44658d15848e34c5c45d973f065Reid Spencer /// @verbatim (Eg. '\t') @endverbatim 263f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey void EmitString(const std::string &String) const; 264f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 265189f80dc253664627253b2d2cb07d0714feb12baDan Gohman /// EmitFile - Emit a .file directive. 266189f80dc253664627253b2d2cb07d0714feb12baDan Gohman void EmitFile(unsigned Number, const std::string &Name) const; 267189f80dc253664627253b2d2cb07d0714feb12baDan Gohman 268f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey //===------------------------------------------------------------------===// 269f1cdea1d021068f5c9e118d68321ce28fcea63faJim Laskey 2706fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner /// EmitAlignment - Emit an alignment directive to the specified power of 271bfddc2030a7e67b9e0c42276525d6932375ff261Chris Lattner /// two boundary. For example, if you pass in 3 here, you will get an 8 272a1ab72daadbdc5b499ce7e7e97c4b80efad46736Chris Lattner /// byte alignment. If a global value is specified, and if that global has 2733a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// an explicit alignment requested, it will unconditionally override the 2743a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// alignment request. However, if ForcedAlignBits is specified, this value 2753a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// has final say: the ultimate alignment will be the max of ForcedAlignBits 27605548eb174dd694b651de334b73197a62e5071f1Evan Cheng /// and the alignment computed with NumBits and the global. If UseFillExpr 27705548eb174dd694b651de334b73197a62e5071f1Evan Cheng /// is true, it also emits an optional second value FillValue which the 27805548eb174dd694b651de334b73197a62e5071f1Evan Cheng /// assembler uses to fill gaps to match alignment for text sections if the 27905548eb174dd694b651de334b73197a62e5071f1Evan Cheng /// has specified a non-zero fill value. 2803a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// 2813a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// The algorithm is: 2823a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// Align = NumBits; 2833a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// if (GV && GV->hasalignment) Align = GV->getalignment(); 2843a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// Align = std::max(Align, ForcedAlignBits); 2853a4205367dc845d4cd804b47e061f8281777c9daChris Lattner /// 2863a4205367dc845d4cd804b47e061f8281777c9daChris Lattner void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0, 28705548eb174dd694b651de334b73197a62e5071f1Evan Cheng unsigned ForcedAlignBits = 0, 28805548eb174dd694b651de334b73197a62e5071f1Evan Cheng bool UseFillExpr = true) const; 289bfddc2030a7e67b9e0c42276525d6932375ff261Chris Lattner 2901b08bbca5592351a940bcd164bdec724ee954326Evan Cheng /// printLabel - This method prints a local label used by debug and 2911b08bbca5592351a940bcd164bdec724ee954326Evan Cheng /// exception handling tables. 2921b08bbca5592351a940bcd164bdec724ee954326Evan Cheng void printLabel(const MachineInstr *MI) const; 2931b08bbca5592351a940bcd164bdec724ee954326Evan Cheng void printLabel(unsigned Id) const; 2941b08bbca5592351a940bcd164bdec724ee954326Evan Cheng 295a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng /// printDeclare - This method prints a local variable declaration used by 296a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng /// debug tables. 297a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng void printDeclare(const MachineInstr *MI) const; 298a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng 299f9e56198a39a08272c072211722b3c97ef88853cJim Laskey protected: 3006fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner /// EmitZeros - Emit a block of zeros. 30130bad4af40d0126f888f601fb46d01e2b39dbc43Chris Lattner /// 302c6a057b04db506152c98355b51ba15d82a15b90aJeff Cohen void EmitZeros(uint64_t NumZeros) const; 303c884db47f1a1d5449b749e6528292451e49025e4Jeff Cohen 304c884db47f1a1d5449b749e6528292451e49025e4Jeff Cohen /// EmitString - Emit a zero-byte-terminated string constant. 305c884db47f1a1d5449b749e6528292451e49025e4Jeff Cohen /// 306c884db47f1a1d5449b749e6528292451e49025e4Jeff Cohen virtual void EmitString(const ConstantArray *CVA) const; 30730bad4af40d0126f888f601fb46d01e2b39dbc43Chris Lattner 3086fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner /// EmitConstantValueOnly - Print out the specified constant, without a 309a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner /// storage class. Only constants of first-class type are allowed here. 3106fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner void EmitConstantValueOnly(const Constant *CV); 31146d6126e669ab83383d47fb465d2a7d0c60169e5Chris Lattner 3126fe3acce749ee2b3714009064626f6c53b06dfb4Chris Lattner /// EmitGlobalConstant - Print a general LLVM constant to the .s file. 313ca0ed744852a7d9625572fbb793f65e81225a3e8Duncan Sands /// If Packed is false, pad to the ABI size. 314ca0ed744852a7d9625572fbb793f65e81225a3e8Duncan Sands void EmitGlobalConstant(const Constant* CV, bool Packed = false); 315d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng 316d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV); 317ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner 318e736ed19478f05811f08a56706e07fa4ab865401Chris Lattner /// printInlineAsm - This method formats and prints the specified machine 319e736ed19478f05811f08a56706e07fa4ab865401Chris Lattner /// instruction that is an inline asm. 320e736ed19478f05811f08a56706e07fa4ab865401Chris Lattner void printInlineAsm(const MachineInstr *MI) const; 32137efe6764568a3829fee26aba532283131d1a104Nate Begeman 32237efe6764568a3829fee26aba532283131d1a104Nate Begeman /// printBasicBlockLabel - This method prints the label for the specified 32337efe6764568a3829fee26aba532283131d1a104Nate Begeman /// MachineBasicBlock 324cdf38c4edb892c356cfaa3c09c57728bc8d6bfd0Nate Begeman virtual void printBasicBlockLabel(const MachineBasicBlock *MBB, 325fb8075d03f5c87bd57dcc9c5f2304f6b13c55aadEvan Cheng bool printAlign = false, 326cdf38c4edb892c356cfaa3c09c57728bc8d6bfd0Nate Begeman bool printColon = false, 327cdf38c4edb892c356cfaa3c09c57728bc8d6bfd0Nate Begeman bool printComment = true) const; 32852a51e38dc312aa262b0d771419afe1785f3cb22Nate Begeman 329cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng /// printPICJumpTableSetLabel - This method prints a set label for the 330cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng /// specified MachineBasicBlock for a jumptable entry. 331cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng virtual void printPICJumpTableSetLabel(unsigned uid, 332cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng const MachineBasicBlock *MBB) const; 333cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng virtual void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, 334cc41586b9d79532172b37e1f44a9077da4b73fc9Evan Cheng const MachineBasicBlock *MBB) const; 3359de1934099f4eedaeb2f3a023411b2cd3e0e1eaeAnton Korobeynikov virtual void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, 3369de1934099f4eedaeb2f3a023411b2cd3e0e1eaeAnton Korobeynikov const MachineBasicBlock *MBB, 3379de1934099f4eedaeb2f3a023411b2cd3e0e1eaeAnton Korobeynikov unsigned uid) const; 3389de1934099f4eedaeb2f3a023411b2cd3e0e1eaeAnton Korobeynikov 339d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng /// printDataDirective - This method prints the asm directive for the 340d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng /// specified type. 341d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng void printDataDirective(const Type *type); 342d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng 343ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner private: 344cb05af852f1d346ac07b84c74a930a5cdbd6d427Chris Lattner void EmitLLVMUsedList(Constant *List); 345ed13893ff729bc3b91697f6d80a3ba303782efccChris Lattner void EmitXXStructorList(Constant *List); 3462d2cec1e9e93a388bd8448f4bad661ac89a49de3Evan Cheng void EmitConstantPool(unsigned Alignment, const char *Section, 3472d2cec1e9e93a388bd8448f4bad661ac89a49de3Evan Cheng std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP); 348b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey 349a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner }; 350a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner} 351a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner 352a80ba71efe5be5012128e2db0dd29b024e00105aChris Lattner#endif 353