Commit 1ea3bab5 authored by nagayama15's avatar nagayama15

テストパスを追加

parent af1bb13f
......@@ -4,3 +4,4 @@
*.so
*.dll
*.o
*.ll
CXX := g++
CXXFLAGS := \
-std=c++17 \
-Wall \
-Wextra \
-pedantic \
-Werror \
$(shell llvm-config-6.0 --cxxflags)
LDFLAGS := \
$(shell llvm-config-6.0 --ldflags) \
$(shell llvm-config-6.0 --libs)
.PHONY: all clean
all: testpass.so
testpass.so: src/nykk/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";
return false;
}
}
#ifndef INCLUDE_NYKK_TESTPASS_HPP
#define INCLUDE_NYKK_TESTPASS_HPP
#include <llvm/Pass.h>
namespace nykk
{
class TestPass
: public llvm::FunctionPass
{
public:
static char ID; // For LLVM.
explicit TestPass();
// Uncopyable, unmovable.
TestPass(const TestPass&) =delete;
TestPass(TestPass&&) =delete;
TestPass& operator=(const TestPass&) =delete;
TestPass& operator=(TestPass&&) =delete;
~TestPass() =default;
/**
* @brief Initialization before pass is run.
*
* @param module Reference of the module.
*
* @return ?
*/
bool doInitialization(llvm::Module& module) override;
/**
* @brief Finalization after pass is run.
*
* @param module Reference of the module.
*
* @return ?
*/
bool doFinalization(llvm::Module& module) override;
/**
* @brief Processes functions.
*
* @param func Reference to the function.
*
* @return `true` if the function was changed.
*/
bool runOnFunction(llvm::Function& func) override;
};
}
#endif
#include <stdio.h>
int main(void)
{
for (int i = 1; i <= 50; i++)
{
if (i % (3 * 5) == 0)
{
printf("Fizz Buzz\n");
}
else if (i % 3 == 0)
{
printf("Fizz\n");
}
else if (i % 5 == 0)
{
printf("Buzz\n");
}
else
{
printf("%d\n", i);
}
}
}
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