forked from OSchip/llvm-project
IR: Extract a function 'printLLVMNameWithoutPrefix' from 'PrintLLVMName'. NFC.
This commit extracts the code that prints out a name of an LLVM value without a prefix from a function 'PrintLLVMName' into a publicly accessible function named 'printLLVMNameWithoutPrefix'. This change would be useful for MIR serialization, as it would allow the MIR printer to reuse this function to print out the names of the external symbol machine operands. Reviewers: Duncan P. N. Exon Smith llvm-svn: 242803
This commit is contained in:
parent
34d17fb54d
commit
2b7f265048
|
@ -47,6 +47,12 @@ FunctionPass *createPrintFunctionPass(raw_ostream &OS,
|
|||
BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
|
||||
const std::string &Banner = "");
|
||||
|
||||
/// Print out a name of an LLVM value without any prefixes.
|
||||
///
|
||||
/// The name is surrounded with ""'s and escaped if it has any special or
|
||||
/// non-printable characters in it.
|
||||
void printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name);
|
||||
|
||||
/// \brief Pass for printing a Module as LLVM's text IR assembly.
|
||||
///
|
||||
/// Note: This pass is for use with the new pass manager. Use the create...Pass
|
||||
|
|
|
@ -343,18 +343,8 @@ enum PrefixType {
|
|||
NoPrefix
|
||||
};
|
||||
|
||||
/// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
|
||||
/// prefixed with % (if the string only contains simple characters) or is
|
||||
/// surrounded with ""'s (if it has special chars in it). Print it out.
|
||||
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
|
||||
void llvm::printLLVMNameWithoutPrefix(raw_ostream &OS, StringRef Name) {
|
||||
assert(!Name.empty() && "Cannot get empty name!");
|
||||
switch (Prefix) {
|
||||
case NoPrefix: break;
|
||||
case GlobalPrefix: OS << '@'; break;
|
||||
case ComdatPrefix: OS << '$'; break;
|
||||
case LabelPrefix: break;
|
||||
case LocalPrefix: OS << '%'; break;
|
||||
}
|
||||
|
||||
// Scan the name to see if it needs quotes first.
|
||||
bool NeedsQuotes = isdigit(static_cast<unsigned char>(Name[0]));
|
||||
|
@ -386,9 +376,31 @@ static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
|
|||
OS << '"';
|
||||
}
|
||||
|
||||
/// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
|
||||
/// prefixed with % (if the string only contains simple characters) or is
|
||||
/// surrounded with ""'s (if it has special chars in it). Print it out.
|
||||
/// Turn the specified name into an 'LLVM name', which is either prefixed with %
|
||||
/// (if the string only contains simple characters) or is surrounded with ""'s
|
||||
/// (if it has special chars in it). Print it out.
|
||||
static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
|
||||
switch (Prefix) {
|
||||
case NoPrefix:
|
||||
break;
|
||||
case GlobalPrefix:
|
||||
OS << '@';
|
||||
break;
|
||||
case ComdatPrefix:
|
||||
OS << '$';
|
||||
break;
|
||||
case LabelPrefix:
|
||||
break;
|
||||
case LocalPrefix:
|
||||
OS << '%';
|
||||
break;
|
||||
}
|
||||
printLLVMNameWithoutPrefix(OS, Name);
|
||||
}
|
||||
|
||||
/// Turn the specified name into an 'LLVM name', which is either prefixed with %
|
||||
/// (if the string only contains simple characters) or is surrounded with ""'s
|
||||
/// (if it has special chars in it). Print it out.
|
||||
static void PrintLLVMName(raw_ostream &OS, const Value *V) {
|
||||
PrintLLVMName(OS, V->getName(),
|
||||
isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
|
||||
|
|
Loading…
Reference in New Issue