Files
revng-revng/codegenerator.h
T
Alessandro Di Federico f8dcd566ae Collect information about ELF segments
Instead of taking note of the executable ranges exclusively, keep track
of all the segments in `CodeGenerator`. `JumpTargetManager` instead will
keep track of executable areas only.

* Introduce the `SegmentInfo` struct, which simply holds essential
  information about the segment such as start and end address,
  permissions and a reference to the global variable holding its content.
* Update `CodeGenerator` to keep a vector of `SegmentInfo`.
* `JumpTargetManager`: polish the constructor and make it take the vector
  of `SegmentInfo`, from which the executable ranges are then extracted.
2016-01-12 18:47:15 +01:00

91 lines
2.5 KiB
C++

#ifndef _CODEGENERATOR_H
#define _CODEGENERATOR_H
// Standard includes
#include <cstdint>
#include <string>
#include <memory>
// LLVM includes
#include "llvm/ADT/ArrayRef.h"
// Local includes
#include "revamb.h"
// Forward declarations
namespace llvm {
class LLVMContext;
class Function;
class GlobalVariable;
class Module;
class Value;
class StructType;
class DataLayout;
namespace object {
class ObjectFile;
};
};
class DebugHelper;
/// Translates code from an architecture to LLVM IR.
class CodeGenerator {
public:
/// Create a new code generator translating code from an architecture to
/// another, writing the corresponding LLVM IR and debug source file of the
/// requested type to file.
///
/// \param Source source architecture.
/// \param Target target architecture.
/// \param OutputPath path where the generate LLVM IR must be saved.
/// \param HelpersPath path of the LLVM IR file containing the QEMU helpers.
/// \param DebugInfo type of debug information to generate.
/// \param DebugPath path where the debugging source file must be written.
CodeGenerator(std::string Input,
Architecture& Target,
std::string Output,
std::string Helpers,
DebugInfoType DebugInfo,
std::string Debug,
std::string LinkingInfoPath);
~CodeGenerator();
/// \brief Creates an LLVM function for the code in the specified memory area.
/// If debug information have been requested, the debug source files will be
/// create in this phase.
///
/// \param Name the name to give to the newly created function.
/// \param Code reference to memory area containing the code to translate.
void translate(uint64_t VirtualAddress,
std::string Name);
/// Serialize the generated LLVM IR to the specified output path.
void serialize();
private:
template<typename T>
void parseELF(llvm::object::ObjectFile *TheBinary,
std::string LinkingInfoPath);
private:
Architecture SourceArchitecture;
Architecture TargetArchitecture;
llvm::LLVMContext& Context;
std::unique_ptr<llvm::Module> TheModule;
std::unique_ptr<llvm::Module> HelpersModule;
std::string OutputPath;
std::unique_ptr<DebugHelper> Debug;
llvm::object::OwningBinary<llvm::object::Binary> BinaryHandle;
std::vector<SegmentInfo> Segments;
uint64_t EntryPoint;
unsigned OriginalInstrMDKind;
unsigned PTCInstrMDKind;
unsigned DbgMDKind;
};
#endif // _CODEGENERATOR_H