1 //===-- llvm/Support/Mangler.h - Self-contained name mangler ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Unified name mangler for various backends.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_MANGLER_H
15 #define LLVM_SUPPORT_MANGLER_H
17 #include "llvm/Support/IncludeFile.h"
29 /// Prefix - This string is added to each symbol that is emitted, unless the
30 /// symbol is marked as not needing this prefix.
33 /// UseQuotes - If this is set, the target accepts global names in quotes,
34 /// e.g. "foo bar" is a legal name. This syntax is used instead of escaping
35 /// the space character. By default, this is false.
38 /// Memo - This is used to remember the name that we assign a value.
40 std::map<const Value*, std::string> Memo;
42 /// Count - This simple counter is used to unique value names.
46 /// TypeMap - If the client wants us to unique types, this keeps track of the
47 /// current assignments and TypeCounter keeps track of the next id to assign.
48 std::map<const Type*, unsigned> TypeMap;
51 /// This keeps track of which global values have had their names
52 /// mangled in the current module.
54 std::set<const GlobalValue*> MangledGlobals;
56 /// AcceptableChars - This bitfield contains a one for each character that is
57 /// allowed to be part of an unmangled name.
58 unsigned AcceptableChars[256/32];
61 // Mangler ctor - if a prefix is specified, it will be prepended onto all
63 Mangler(Module &M, const char *Prefix = "");
65 /// setUseQuotes - If UseQuotes is set to true, this target accepts quoted
66 /// strings for assembler labels.
67 void setUseQuotes(bool Val) { UseQuotes = Val; }
69 /// Acceptable Characters - This allows the target to specify which characters
70 /// are acceptable to the assembler without being mangled. By default we
71 /// allow letters, numbers, '_', '$', and '.', which is what GAS accepts.
72 void markCharAcceptable(unsigned char X) {
73 AcceptableChars[X/32] |= 1 << (X&31);
75 void markCharUnacceptable(unsigned char X) {
76 AcceptableChars[X/32] &= ~(1 << (X&31));
78 bool isCharAcceptable(unsigned char X) const {
79 return (AcceptableChars[X/32] & (1 << (X&31))) != 0;
82 /// getTypeID - Return a unique ID for the specified LLVM type.
84 unsigned getTypeID(const Type *Ty);
86 /// getValueName - Returns the mangled name of V, an LLVM Value,
87 /// in the current module.
89 std::string getValueName(const GlobalValue *V);
90 std::string getValueName(const Value *V);
92 /// makeNameProper - We don't want identifier names with ., space, or
93 /// - in them, so we mangle these characters into the strings "d_",
94 /// "s_", and "D_", respectively. This is a very simple mangling that
95 /// doesn't guarantee unique names for values. getValueName already
96 /// does this for you, so there's no point calling it on the result
97 /// from getValueName.
99 std::string makeNameProper(const std::string &x, const char *Prefix = "");
102 void InsertName(GlobalValue *GV, std::map<std::string, GlobalValue*> &Names);
105 } // End llvm namespace
107 // Force the Mangler.cpp file to be linked when this header is #included
108 FORCE_DEFINING_FILE_TO_BE_LINKED(Mangler)
110 #endif // LLVM_SUPPORT_MANGLER_H