- static std::string getValidSymbolName(const std::string &S) {
- std::string Result;
-
- // Symbol names in Sparc assembly language have these rules:
- // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
- // (b) A name beginning in "." is treated as a local name.
- //
- if (isdigit(S[0]))
- Result = "ll";
-
- for (unsigned i = 0; i < S.size(); ++i) {
- char C = S[i];
- if (C == '_' || C == '.' || C == '$' || isalpha(C) || isdigit(C))
- Result += C;
- else {
- Result += '_';
- Result += char('0' + ((unsigned char)C >> 4));
- Result += char('0' + (C & 0xF));
- }
- }
- return Result;
- }
-
- // getID - Return a valid identifier for the specified value. Base it on
- // the name of the identifier if possible (qualified by the type), and
- // use a numbered value based on prefix otherwise.
- // FPrefix is always prepended to the output identifier.
- //
- std::string getID(const Value *V, const char *Prefix,
- const char *FPrefix = 0)
- {
- std::string Result = FPrefix ? FPrefix : ""; // "Forced prefix"
-
- Result += V->hasName() ? V->getName() : std::string(Prefix);
-
- // Qualify all internal names with a unique id.
- if (!isExternal(V)) {
- int valId = idTable->Table.getSlot(V);
- if (valId == -1) {
- GlobalIdTable::ValIdMapConstIterator I = idTable->valToIdMap.find(V);
- if (I == idTable->valToIdMap.end())
- valId = idTable->valToIdMap[V] = idTable->valToIdMap.size();
- else
- valId = I->second;
- }
- Result = Result + "_" + itostr(valId);
-
- // Replace or prefix problem characters in the name
- Result = getValidSymbolName(Result);
- }
-
- return Result;
- }
-
- // getID Wrappers - Ensure consistent usage...
+ // getID Wrappers - Ensure consistent usage
+ // Symbol names in Sparc assembly language have these rules:
+ // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
+ // (b) A name beginning in "." is treated as a local name.