Files
revng-revng/lib/Support/BasicBlockID.cpp
T
Alessandro Di Federico 1429b526ab Introduce libtcg
This commit drops libptc in favor of its new form libtcg.

It brings several improvements, among which:

* The QEMU version we work on has been upgraded.
* CPUStateAccessAnalysis has been reimplemented in a way that makes it
  easier to debug and solves some limitations (e.g., tracking leaking
  pointers).
* Identification of pieces of the CPU state that are read by each helper
  and fixing access to the CPU state is now performed at build-time.
* We no longer mmap the code we need to translate, dropping all the
  issues related to code that needed to be mapped where something is
  already present.
* We now have two distinct flavors of helper modules: the full one and
  the "slim" one. The latter contains the definition only of functions
  we intend to inline. It is used in most of the pipeline, a good thing
  since we spend less time optimizing code we don't really care about.
  The full module is only used on the re-compilation branch of the
  pipeline.
* We no longer split the `cpu_loop` function.
* We change MetaAddress to rely on architectures from `model::` as
  opposed to the LLVM ones.
* We no longer attach debug info to LLVM IR containing the original
  assembly.
* We now verify that the lifted code only contains code we expect.
2025-10-31 17:25:03 +01:00

58 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 (Parts.empty() || 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(model::Architecture::Values Architecture) const {
std::string Result = Start.toString(Architecture);
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());
}