Commit 0a126b1c authored by nagayama15's avatar nagayama15

ディレクトリ構造を変更

parent 1f5c48fc
......@@ -16,10 +16,8 @@ LDFLAGS := \
all: testpass.so
testpass.so: src/nykk/TestPass.o
testpass.so: src/nykk/pass/TestPass.o
${CXX} ${CXXFLAGS} -shared -o $@ $< ${LDFLAGS}
src/nykk/TestPass.o: src/nykk/TestPass.cpp src/nykk/TestPass.hpp
clean:
${RM} *.so src/*/*.o
#include "TestPass.hpp"
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/raw_ostream.h>
// Register pass.
llvm::RegisterPass<nykk::TestPass> g_test_pass {
"testpass",
"Test pass",
};
namespace nykk
{
// Pass id.
char TestPass::ID;
// Constructor of TestPass.
TestPass::TestPass()
: FunctionPass(ID)
{
}
// Initialization before pass is run
bool TestPass::doInitialization(llvm::Module& module)
{
llvm::errs() << __FUNCTION__ << " : " << module.getName() << "\n";
return false;
}
// Finalization after pass is run
bool TestPass::doFinalization(llvm::Module& module)
{
llvm::errs() << __FUNCTION__ << " : " << module.getName() << "\n";
return false;
}
// Processes functions.
bool TestPass::runOnFunction(llvm::Function& func)
{
llvm::errs() << __FUNCTION__ << " : " << func.getName() << "\n";
llvm::errs() << " " << "bbs : " << func.getBasicBlockList().size() << "\n";
if (func.getBasicBlockList().size() < 3)
{
return false;
}
// Swap 2nd and 3rd basic blocks.
llvm::BasicBlock& entry_bb = func.getEntryBlock();
llvm::BasicBlock* bb1 = entry_bb.getNextNode();
llvm::BasicBlock* bb2 = bb1->getNextNode();
bb1->moveAfter(bb2);
return true;
}
}
#ifndef INCLUDE_NYKK_TESTPASS_HPP
#define INCLUDE_NYKK_TESTPASS_HPP
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include <llvm/Pass.h>
#include <llvm/Support/raw_ostream.h>
namespace nykk
namespace
{
class TestPass
: public llvm::FunctionPass
{
public:
static char ID; // For LLVM.
static char ID; // Needed for LLVM.
explicit TestPass();
/**
* @brief Constructor.
*/
explicit TestPass()
: FunctionPass(ID)
{
}
// Uncopyable, unmovable.
TestPass(const TestPass&) =delete;
......@@ -29,7 +35,12 @@ namespace nykk
*
* @return ?
*/
bool doInitialization(llvm::Module& module) override;
bool doInitialization(llvm::Module& module) override
{
llvm::errs() << __FUNCTION__ << " : " << module.getName() << "\n";
return false;
}
/**
* @brief Finalization after pass is run.
......@@ -38,7 +49,12 @@ namespace nykk
*
* @return ?
*/
bool doFinalization(llvm::Module& module) override;
bool doFinalization(llvm::Module& module) override
{
llvm::errs() << __FUNCTION__ << " : " << module.getName() << "\n";
return false;
}
/**
* @brief Processes functions.
......@@ -47,8 +63,32 @@ namespace nykk
*
* @return `true` if the function was changed.
*/
bool runOnFunction(llvm::Function& func) override;
bool runOnFunction(llvm::Function& func) override
{
llvm::errs() << __FUNCTION__ << " : " << func.getName() << "\n";
llvm::errs() << " " << "bbs : " << func.getBasicBlockList().size() << "\n";
if (func.getBasicBlockList().size() < 3)
{
return false;
}
// Swap 2nd and 3rd basic blocks.
llvm::BasicBlock& entry_bb = func.getEntryBlock();
llvm::BasicBlock* bb1 = entry_bb.getNextNode();
llvm::BasicBlock* bb2 = bb1->getNextNode();
bb1->moveAfter(bb2);
return true;
}
};
}
#endif
char TestPass::ID;
// Register pass.
llvm::RegisterPass<TestPass> test_pass_registry {
"testpass",
"Test pass",
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment