forked from OSchip/llvm-project
Create Strings.cpp and move string manipulation functions to that file.
llvm-svn: 274109
This commit is contained in:
parent
518cbc7cc3
commit
93c9af425e
|
@ -16,6 +16,7 @@ add_lld_library(lldELF
|
|||
OutputSections.cpp
|
||||
Relocations.cpp
|
||||
ScriptParser.cpp
|
||||
Strings.cpp
|
||||
SymbolListFile.cpp
|
||||
SymbolTable.cpp
|
||||
Symbols.cpp
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "InputFiles.h"
|
||||
#include "InputSection.h"
|
||||
#include "LinkerScript.h"
|
||||
#include "Strings.h"
|
||||
#include "SymbolListFile.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "Target.h"
|
||||
|
@ -402,7 +403,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
|
|||
Config->BuildId = BuildIdKind::None;
|
||||
} else if (S.startswith("0x")) {
|
||||
Config->BuildId = BuildIdKind::Hexstring;
|
||||
Config->BuildIdVector = parseHexstring(S.substr(2));
|
||||
Config->BuildIdVector = parseHex(S.substr(2));
|
||||
} else {
|
||||
error("unknown --build-id style: " + S);
|
||||
}
|
||||
|
|
|
@ -88,22 +88,6 @@ std::string elf::getVersionString() {
|
|||
return "LLD " + Version + " " + Repo + "\n";
|
||||
}
|
||||
|
||||
// Converts a hex string (e.g. "0x123456") to a vector.
|
||||
std::vector<uint8_t> elf::parseHexstring(StringRef S) {
|
||||
if (S.find_first_not_of("0123456789abcdefABCDEF") != StringRef::npos ||
|
||||
S.size() % 2) {
|
||||
error("malformed hexstring: " + S);
|
||||
return {};
|
||||
}
|
||||
std::vector<uint8_t> V;
|
||||
for (; !S.empty(); S = S.substr(2)) {
|
||||
int I;
|
||||
S.substr(0, 2).getAsInteger(16, I);
|
||||
V.push_back(I);
|
||||
}
|
||||
return V;
|
||||
}
|
||||
|
||||
// Makes a given pathname an absolute path first, and then remove
|
||||
// beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
|
||||
// assuming that the current directory is "/home/john/bar".
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "InputSection.h"
|
||||
#include "OutputSections.h"
|
||||
#include "ScriptParser.h"
|
||||
#include "Strings.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/ELF.h"
|
||||
|
@ -286,30 +287,6 @@ int LinkerScript<ELFT>::compareSections(StringRef A, StringRef B) {
|
|||
return I < J ? -1 : 1;
|
||||
}
|
||||
|
||||
// Returns true if S matches T. S can contain glob meta-characters.
|
||||
// The asterisk ('*') matches zero or more characters, and the question
|
||||
// mark ('?') matches one character.
|
||||
bool elf::globMatch(StringRef S, StringRef T) {
|
||||
for (;;) {
|
||||
if (S.empty())
|
||||
return T.empty();
|
||||
if (S[0] == '*') {
|
||||
S = S.substr(1);
|
||||
if (S.empty())
|
||||
// Fast path. If a pattern is '*', it matches anything.
|
||||
return true;
|
||||
for (size_t I = 0, E = T.size(); I < E; ++I)
|
||||
if (globMatch(S, T.substr(I)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (T.empty() || (S[0] != T[0] && S[0] != '?'))
|
||||
return false;
|
||||
S = S.substr(1);
|
||||
T = T.substr(1);
|
||||
}
|
||||
}
|
||||
|
||||
class elf::ScriptParser : public ScriptParserBase {
|
||||
typedef void (ScriptParser::*Handler)();
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
bool globMatch(StringRef S, StringRef T);
|
||||
|
||||
// Parses a linker script. Calling this function updates
|
||||
// Config and ScriptConfig.
|
||||
void readLinkerScript(MemoryBufferRef MB);
|
||||
|
|
|
@ -161,18 +161,3 @@ size_t ScriptParserBase::getPos() {
|
|||
const char *Tok = Tokens[Pos - 1].data();
|
||||
return StringRef(Begin, Tok - Begin).count('\n') + 1;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> ScriptParserBase::parseHex(StringRef S) {
|
||||
std::vector<uint8_t> Hex;
|
||||
while (!S.empty()) {
|
||||
StringRef B = S.substr(0, 2);
|
||||
S = S.substr(2);
|
||||
uint8_t H;
|
||||
if (B.getAsInteger(16, H)) {
|
||||
setError("not a hexadecimal value: " + B);
|
||||
return {};
|
||||
}
|
||||
Hex.push_back(H);
|
||||
}
|
||||
return Hex;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,6 @@ protected:
|
|||
size_t getPos();
|
||||
void printErrorPos();
|
||||
|
||||
std::vector<uint8_t> parseHex(StringRef S);
|
||||
|
||||
StringRef Input;
|
||||
std::vector<StringRef> Tokens;
|
||||
size_t Pos = 0;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
//===- Strings.cpp -------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Linker
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Strings.h"
|
||||
#include "Error.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace lld;
|
||||
using namespace lld::elf;
|
||||
|
||||
// Returns true if S matches T. S can contain glob meta-characters.
|
||||
// The asterisk ('*') matches zero or more characters, and the question
|
||||
// mark ('?') matches one character.
|
||||
bool elf::globMatch(StringRef S, StringRef T) {
|
||||
for (;;) {
|
||||
if (S.empty())
|
||||
return T.empty();
|
||||
if (S[0] == '*') {
|
||||
S = S.substr(1);
|
||||
if (S.empty())
|
||||
// Fast path. If a pattern is '*', it matches anything.
|
||||
return true;
|
||||
for (size_t I = 0, E = T.size(); I < E; ++I)
|
||||
if (globMatch(S, T.substr(I)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
if (T.empty() || (S[0] != T[0] && S[0] != '?'))
|
||||
return false;
|
||||
S = S.substr(1);
|
||||
T = T.substr(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Converts a hex string (e.g. "deadbeef") to a vector.
|
||||
std::vector<uint8_t> elf::parseHex(StringRef S) {
|
||||
std::vector<uint8_t> Hex;
|
||||
while (!S.empty()) {
|
||||
StringRef B = S.substr(0, 2);
|
||||
S = S.substr(2);
|
||||
uint8_t H;
|
||||
if (B.getAsInteger(16, H)) {
|
||||
error("not a hexadecimal value: " + B);
|
||||
return {};
|
||||
}
|
||||
Hex.push_back(H);
|
||||
}
|
||||
return Hex;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
//===- Strings.h ------------------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Linker
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLD_COFF_STRINGS_H
|
||||
#define LLD_COFF_STRINGS_H
|
||||
|
||||
#include "lld/Core/LLVM.h"
|
||||
#include <vector>
|
||||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
bool globMatch(StringRef S, StringRef T);
|
||||
std::vector<uint8_t> parseHex(StringRef S);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -18,6 +18,7 @@
|
|||
#include "Config.h"
|
||||
#include "Error.h"
|
||||
#include "LinkerScript.h"
|
||||
#include "Strings.h"
|
||||
#include "Symbols.h"
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#include "llvm/Support/StringSaver.h"
|
||||
|
|
Loading…
Reference in New Issue