mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
7d235f4fd0
Also do some basic cleanup: capitalize first letters, add `.` at the end of the sentences, and so on.
57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
/// \file BasicBlockID.cpp
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
#include "llvm/ADT/APInt.h"
|
|
#include "llvm/ADT/SmallVector.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/ADT/Twine.h"
|
|
|
|
#include "revng/Support/BasicBlockID.h"
|
|
#include "revng/Support/IRHelpers.h"
|
|
|
|
BasicBlockID BasicBlockID::fromString(llvm::StringRef Text) {
|
|
using namespace llvm;
|
|
SmallVector<StringRef, 2> Parts;
|
|
Text.split(Parts, "-");
|
|
|
|
if (not(Parts.size() == 1 or Parts.size() == 2))
|
|
return BasicBlockID::invalid();
|
|
|
|
auto Start = MetaAddress::fromString(Parts[0]);
|
|
if (not Start.isValid())
|
|
return BasicBlockID::invalid();
|
|
|
|
uint64_t InliningIndex = 0;
|
|
|
|
if (Parts.size() == 2) {
|
|
APInt APIndex;
|
|
bool Failure = Parts[1].getAsInteger(10, APIndex);
|
|
if (Failure or APIndex.getBitWidth() > 64)
|
|
return BasicBlockID::invalid();
|
|
InliningIndex = APIndex.getLimitedValue();
|
|
}
|
|
|
|
return BasicBlockID(Start, InliningIndex);
|
|
}
|
|
|
|
std::string BasicBlockID::toString() const {
|
|
std::string Result = Start.toString();
|
|
|
|
if (isInlined()) {
|
|
Result += "-" + llvm::Twine(InliningIndex).str();
|
|
}
|
|
|
|
return Result;
|
|
}
|
|
|
|
BasicBlockID BasicBlockID::fromValue(llvm::Value *V) {
|
|
return BasicBlockID::fromString(extractFromConstantStringPtr(V));
|
|
}
|
|
|
|
llvm::Constant *BasicBlockID::toValue(llvm::Module *M) const {
|
|
return getUniqueString(M, toString());
|
|
}
|