diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-11-27 00:03:19 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-11-27 00:03:19 +0000 |
| commit | 5de2204fe84a89604a31253a299ab265dee76934 (patch) | |
| tree | 142e5dd065732bf4cc8775f69ce0979230836e51 /llvm/lib/Target/Sparc | |
| parent | f679703feb9c4702a55f41caec15d5adf997cac9 (diff) | |
| download | bcm5719-llvm-5de2204fe84a89604a31253a299ab265dee76934.tar.gz bcm5719-llvm-5de2204fe84a89604a31253a299ab265dee76934.zip | |
Create a new #include "Support/..." directory structure to move things
from "llvm/Support/..." that are not llvm dependant.
Move files and fix #includes
llvm-svn: 1400
Diffstat (limited to 'llvm/lib/Target/Sparc')
| -rw-r--r-- | llvm/lib/Target/Sparc/EmitAssembly.cpp | 67 | ||||
| -rw-r--r-- | llvm/lib/Target/Sparc/SparcInstrSelection.cpp | 4 |
2 files changed, 66 insertions, 5 deletions
diff --git a/llvm/lib/Target/Sparc/EmitAssembly.cpp b/llvm/lib/Target/Sparc/EmitAssembly.cpp index 618fb6dc30f..3edeb962039 100644 --- a/llvm/lib/Target/Sparc/EmitAssembly.cpp +++ b/llvm/lib/Target/Sparc/EmitAssembly.cpp @@ -19,8 +19,8 @@ #include "llvm/BasicBlock.h" #include "llvm/Method.h" #include "llvm/Module.h" -#include "llvm/Support/HashExtras.h" -#include "llvm/Support/StringExtras.h" +#include "Support/StringExtras.h" +#include "Support/HashExtras.h" #include <locale.h> namespace { @@ -161,6 +161,69 @@ private : } }; + +// Can we treat the specified array as a string? Only if it is an array of +// ubytes or non-negative sbytes. +// +static bool isStringCompatible(ConstPoolArray *CPA) { + const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType(); + if (ETy == Type::UByteTy) return true; + if (ETy != Type::SByteTy) return false; + + for (unsigned i = 0; i < CPA->getNumOperands(); ++i) + if (cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() < 0) + return false; + + return true; +} + +// toOctal - Convert the low order bits of X into an octal letter +static inline char toOctal(int X) { + return (X&7)+'0'; +} + +// getAsCString - Return the specified array as a C compatible string, only if +// the predicate isStringCompatible is true. +// +static string getAsCString(ConstPoolArray *CPA) { + if (isStringCompatible(CPA)) { + string Result; + const Type *ETy = cast<ArrayType>(CPA->getType())->getElementType(); + Result = "\""; + for (unsigned i = 0; i < CPA->getNumOperands(); ++i) { + unsigned char C = (ETy == Type::SByteTy) ? + (unsigned char)cast<ConstPoolSInt>(CPA->getOperand(i))->getValue() : + (unsigned char)cast<ConstPoolUInt>(CPA->getOperand(i))->getValue(); + + if (isprint(C)) { + Result += C; + } else { + switch(C) { + case '\a': Result += "\\a"; break; + case '\b': Result += "\\b"; break; + case '\f': Result += "\\f"; break; + case '\n': Result += "\\n"; break; + case '\r': Result += "\\r"; break; + case '\t': Result += "\\t"; break; + case '\v': Result += "\\v"; break; + default: + Result += '\\'; + Result += toOctal(C >> 6); + Result += toOctal(C >> 3); + Result += toOctal(C >> 0); + break; + } + } + } + Result += "\""; + + return Result; + } else { + return CPA->getStrValue(); + } +} + + inline bool SparcAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum) { diff --git a/llvm/lib/Target/Sparc/SparcInstrSelection.cpp b/llvm/lib/Target/Sparc/SparcInstrSelection.cpp index c1b8aa38c87..631d6090184 100644 --- a/llvm/lib/Target/Sparc/SparcInstrSelection.cpp +++ b/llvm/lib/Target/Sparc/SparcInstrSelection.cpp @@ -16,7 +16,6 @@ #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/InstrForest.h" #include "llvm/CodeGen/InstrSelection.h" -#include "llvm/Support/MathExtras.h" #include "llvm/DerivedTypes.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" @@ -24,10 +23,9 @@ #include "llvm/BasicBlock.h" #include "llvm/Method.h" #include "llvm/ConstPoolVals.h" +#include "Support/MathExtras.h" #include <math.h> -//******************** Internal Data Declarations ************************/ - //************************* Forward Declarations ***************************/ |

