mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
MC CFG: Keep pointer to parent MCModule in created MCFunctions.
Also, drive-by cleaning around createFunction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188875 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -74,21 +74,22 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Represents a function in machine code, containing MCBasicBlocks.
|
/// \brief Represents a function in machine code, containing MCBasicBlocks.
|
||||||
/// MCFunctions are created using MCModule::createFunction.
|
/// MCFunctions are created by MCModule.
|
||||||
class MCFunction {
|
class MCFunction {
|
||||||
MCFunction (const MCFunction&) LLVM_DELETED_FUNCTION;
|
MCFunction (const MCFunction&) LLVM_DELETED_FUNCTION;
|
||||||
MCFunction& operator=(const MCFunction&) LLVM_DELETED_FUNCTION;
|
MCFunction& operator=(const MCFunction&) LLVM_DELETED_FUNCTION;
|
||||||
|
|
||||||
std::string Name;
|
std::string Name;
|
||||||
|
MCModule *ParentModule;
|
||||||
typedef std::vector<MCBasicBlock*> BasicBlockListTy;
|
typedef std::vector<MCBasicBlock*> BasicBlockListTy;
|
||||||
BasicBlockListTy Blocks;
|
BasicBlockListTy Blocks;
|
||||||
|
|
||||||
// MCModule owns the function.
|
// MCModule owns the function.
|
||||||
friend class MCModule;
|
friend class MCModule;
|
||||||
MCFunction(StringRef Name);
|
MCFunction(StringRef Name, MCModule *Parent);
|
||||||
public:
|
|
||||||
~MCFunction();
|
~MCFunction();
|
||||||
|
|
||||||
|
public:
|
||||||
/// \brief Create an MCBasicBlock backed by Insts and add it to this function.
|
/// \brief Create an MCBasicBlock backed by Insts and add it to this function.
|
||||||
/// \param Insts Sequence of straight-line code backing the basic block.
|
/// \param Insts Sequence of straight-line code backing the basic block.
|
||||||
/// \returns The newly created basic block.
|
/// \returns The newly created basic block.
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class MCAtom;
|
class MCAtom;
|
||||||
|
class MCBasicBlock;
|
||||||
class MCDataAtom;
|
class MCDataAtom;
|
||||||
class MCFunction;
|
class MCFunction;
|
||||||
class MCObjectDisassembler;
|
class MCObjectDisassembler;
|
||||||
@@ -88,8 +89,8 @@ public:
|
|||||||
atom_iterator atom_end() { return Atoms.end(); }
|
atom_iterator atom_end() { return Atoms.end(); }
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// \name Create a new MCFunction.
|
/// \brief Create a new MCFunction.
|
||||||
MCFunction *createFunction(const StringRef &Name);
|
MCFunction *createFunction(StringRef Name);
|
||||||
|
|
||||||
/// \name Access to the owned function list.
|
/// \name Access to the owned function list.
|
||||||
/// @{
|
/// @{
|
||||||
|
@@ -9,15 +9,15 @@
|
|||||||
|
|
||||||
#include "llvm/MC/MCFunction.h"
|
#include "llvm/MC/MCFunction.h"
|
||||||
#include "llvm/MC/MCAtom.h"
|
#include "llvm/MC/MCAtom.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/MC/MCModule.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
// MCFunction
|
// MCFunction
|
||||||
|
|
||||||
MCFunction::MCFunction(StringRef Name)
|
MCFunction::MCFunction(StringRef Name, MCModule *Parent)
|
||||||
: Name(Name)
|
: Name(Name), ParentModule(Parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
MCFunction::~MCFunction() {
|
MCFunction::~MCFunction() {
|
||||||
|
@@ -54,9 +54,13 @@ void MCModule::remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd) {
|
|||||||
assert(*I == Atom && "Previous atom mapping was invalid!");
|
assert(*I == Atom && "Previous atom mapping was invalid!");
|
||||||
Atoms.erase(I);
|
Atoms.erase(I);
|
||||||
|
|
||||||
|
// FIXME: special case NewBegin == Atom->Begin
|
||||||
|
|
||||||
// Insert the new mapping.
|
// Insert the new mapping.
|
||||||
AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
|
AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
|
||||||
NewBegin, AtomComp);
|
NewBegin, AtomComp);
|
||||||
|
assert((NewI == atom_end() || (*NewI)->getBeginAddr() > Atom->End)
|
||||||
|
&& "Offset range already occupied!");
|
||||||
Atoms.insert(NewI, Atom);
|
Atoms.insert(NewI, Atom);
|
||||||
|
|
||||||
// Update the atom internal bounds.
|
// Update the atom internal bounds.
|
||||||
@@ -80,8 +84,8 @@ MCAtom *MCModule::findAtomContaining(uint64_t Addr) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MCFunction *MCModule::createFunction(const StringRef &Name) {
|
MCFunction *MCModule::createFunction(StringRef Name) {
|
||||||
Functions.push_back(new MCFunction(Name));
|
Functions.push_back(new MCFunction(Name, this));
|
||||||
return Functions.back();
|
return Functions.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user