mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-27 14:34:58 +00:00
Use std::unique_ptr to manage MCBasicBlocks in MCFunction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206242 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
508bd63046
commit
a8ae0ad11f
@ -17,6 +17,7 @@
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -88,13 +89,12 @@ class MCFunction {
|
||||
|
||||
std::string Name;
|
||||
MCModule *ParentModule;
|
||||
typedef std::vector<MCBasicBlock*> BasicBlockListTy;
|
||||
typedef std::vector<std::unique_ptr<MCBasicBlock>> BasicBlockListTy;
|
||||
BasicBlockListTy Blocks;
|
||||
|
||||
// MCModule owns the function.
|
||||
friend class MCModule;
|
||||
MCFunction(StringRef Name, MCModule *Parent);
|
||||
~MCFunction();
|
||||
|
||||
public:
|
||||
/// \brief Create an MCBasicBlock backed by Insts and add it to this function.
|
||||
@ -126,10 +126,10 @@ public:
|
||||
const_iterator end() const { return Blocks.end(); }
|
||||
iterator end() { return Blocks.end(); }
|
||||
|
||||
const MCBasicBlock* front() const { return Blocks.front(); }
|
||||
MCBasicBlock* front() { return Blocks.front(); }
|
||||
const MCBasicBlock* back() const { return Blocks.back(); }
|
||||
MCBasicBlock* back() { return Blocks.back(); }
|
||||
const MCBasicBlock* front() const { return Blocks.front().get(); }
|
||||
MCBasicBlock* front() { return Blocks.front().get(); }
|
||||
const MCBasicBlock* back() const { return Blocks.back().get(); }
|
||||
MCBasicBlock* back() { return Blocks.back().get(); }
|
||||
|
||||
/// \brief Find the basic block, if any, that starts at \p StartAddr.
|
||||
const MCBasicBlock *find(uint64_t StartAddr) const;
|
||||
|
@ -20,21 +20,16 @@ MCFunction::MCFunction(StringRef Name, MCModule *Parent)
|
||||
: Name(Name), ParentModule(Parent)
|
||||
{}
|
||||
|
||||
MCFunction::~MCFunction() {
|
||||
for (iterator I = begin(), E = end(); I != E; ++I)
|
||||
delete *I;
|
||||
}
|
||||
|
||||
MCBasicBlock &MCFunction::createBlock(const MCTextAtom &TA) {
|
||||
MCBasicBlock *MCBB = new MCBasicBlock(TA, this);
|
||||
Blocks.push_back(MCBB);
|
||||
return *MCBB;
|
||||
std::unique_ptr<MCBasicBlock> MCBB(new MCBasicBlock(TA, this));
|
||||
Blocks.push_back(std::move(MCBB));
|
||||
return *Blocks.back();
|
||||
}
|
||||
|
||||
MCBasicBlock *MCFunction::find(uint64_t StartAddr) {
|
||||
for (const_iterator I = begin(), E = end(); I != E; ++I)
|
||||
if ((*I)->getInsts()->getBeginAddr() == StartAddr)
|
||||
return *I;
|
||||
return I->get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -336,16 +336,16 @@ void MCModule2YAML::dumpFunction(const MCFunction *MCF) {
|
||||
F.Name = MCF->getName();
|
||||
for (MCFunction::const_iterator BBI = MCF->begin(), BBE = MCF->end();
|
||||
BBI != BBE; ++BBI) {
|
||||
const MCBasicBlock *MCBB = *BBI;
|
||||
const MCBasicBlock &MCBB = **BBI;
|
||||
F.BasicBlocks.resize(F.BasicBlocks.size() + 1);
|
||||
MCModuleYAML::BasicBlock &BB = F.BasicBlocks.back();
|
||||
BB.Address = MCBB->getInsts()->getBeginAddr();
|
||||
for (MCBasicBlock::pred_const_iterator PI = MCBB->pred_begin(),
|
||||
PE = MCBB->pred_end();
|
||||
BB.Address = MCBB.getInsts()->getBeginAddr();
|
||||
for (MCBasicBlock::pred_const_iterator PI = MCBB.pred_begin(),
|
||||
PE = MCBB.pred_end();
|
||||
PI != PE; ++PI)
|
||||
BB.Preds.push_back((*PI)->getInsts()->getBeginAddr());
|
||||
for (MCBasicBlock::succ_const_iterator SI = MCBB->succ_begin(),
|
||||
SE = MCBB->succ_end();
|
||||
for (MCBasicBlock::succ_const_iterator SI = MCBB.succ_begin(),
|
||||
SE = MCBB.succ_end();
|
||||
SI != SE; ++SI)
|
||||
BB.Succs.push_back((*SI)->getInsts()->getBeginAddr());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user