Browse Source

Includes reordering, GCC conversion warnings enabled

Includes order as described in Coding Standards of cpp-ethereum project.
GCC warnings about lossy conversions enabled.
cl-refactor
Paweł Bylica 10 years ago
parent
commit
93cb4866fd
  1. 2
      CMakeLists.txt
  2. 9
      libevmjit/Arith256.cpp
  3. 1
      libevmjit/Arith256.h
  4. 5
      libevmjit/BasicBlock.cpp
  5. 4
      libevmjit/BasicBlock.h
  6. 7
      libevmjit/Cache.cpp
  7. 4
      libevmjit/Cache.h
  8. 1
      libevmjit/Common.h
  9. 29
      libevmjit/Compiler.cpp
  10. 1
      libevmjit/Compiler.h
  11. 98
      libevmjit/CompilerHelper.cpp
  12. 154
      libevmjit/CompilerHelper.h
  13. 77
      libevmjit/Endianness.cpp
  14. 50
      libevmjit/Endianness.h
  15. 1
      libevmjit/ExecStats.cpp
  16. 4
      libevmjit/ExecStats.h
  17. 17
      libevmjit/ExecutionEngine.cpp
  18. 4
      libevmjit/ExecutionEngine.h
  19. 9
      libevmjit/Ext.cpp
  20. 4
      libevmjit/Ext.h
  21. 8
      libevmjit/GasMeter.cpp
  22. 1
      libevmjit/GasMeter.h
  23. 1
      libevmjit/Instruction.h
  24. 9
      libevmjit/Memory.cpp
  25. 1
      libevmjit/Memory.h
  26. 1
      libevmjit/Runtime.cpp
  27. 79
      libevmjit/Runtime.h
  28. 1
      libevmjit/RuntimeData.h
  29. 1
      libevmjit/RuntimeManager.h
  30. 7
      libevmjit/Stack.cpp
  31. 1
      libevmjit/Stack.h
  32. 3
      libevmjit/Type.h
  33. 8
      libevmjit/preprocessor/llvm_includes_end.h
  34. 13
      libevmjit/preprocessor/llvm_includes_start.h

2
CMakeLists.txt

@ -7,7 +7,7 @@ set(CMAKE_AUTOMOC OFF)
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
else()
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wno-unknown-pragmas -Wextra")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Wconversion")
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")

9
libevmjit/Arith256.cpp

@ -1,13 +1,14 @@
#include "Arith256.h"
#include "Type.h"
#include "Endianness.h"
#include <iostream>
#include <iomanip>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include <iostream>
#include <iomanip>
#include "Type.h"
#include "Endianness.h"
namespace dev
{

1
libevmjit/Arith256.h

@ -1,4 +1,5 @@
#pragma once
#include "CompilerHelper.h"
namespace dev

5
libevmjit/BasicBlock.cpp

@ -1,5 +1,6 @@
#include "BasicBlock.h"
#include "Type.h"
#include <iostream>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/CFG.h>
@ -9,7 +10,7 @@
#include <llvm/Support/raw_os_ostream.h>
#include "preprocessor/llvm_includes_end.h"
#include <iostream>
#include "Type.h"
namespace dev
{

4
libevmjit/BasicBlock.h

@ -1,7 +1,9 @@
#pragma once
#include <vector>
#include "Common.h"
#include "Stack.h"
#include <vector>
namespace dev
{

7
libevmjit/Cache.cpp

@ -1,5 +1,7 @@
#include "Cache.h"
#include "ExecutionEngine.h"
#include <iostream>
#include <cassert>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h>
@ -10,8 +12,7 @@
#include <llvm/Support/raw_os_ostream.h>
#include "preprocessor/llvm_includes_end.h"
#include <cassert>
#include <iostream>
#include "ExecutionEngine.h"
namespace dev
{

4
libevmjit/Cache.h

@ -1,7 +1,9 @@
#pragma once
#include <llvm/ExecutionEngine/ObjectCache.h>
#include <memory>
#include <llvm/ExecutionEngine/ObjectCache.h>
namespace dev
{
namespace eth

1
libevmjit/Common.h

@ -1,4 +1,5 @@
#pragma once
#include <vector>
#include <tuple>
#include <cstdint>

29
libevmjit/Compiler.cpp

@ -1,14 +1,9 @@
#include "Compiler.h"
#include "Instruction.h"
#include "Type.h"
#include "Memory.h"
#include "Stack.h"
#include "Ext.h"
#include "GasMeter.h"
#include "Utils.h"
#include "Endianness.h"
#include "Arith256.h"
#include "RuntimeManager.h"
#include <functional>
#include <fstream>
#include <chrono>
#include <sstream>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/ADT/PostOrderIterator.h>
@ -20,10 +15,16 @@
#include <llvm/Transforms/Scalar.h>
#include "preprocessor/llvm_includes_end.h"
#include <functional>
#include <fstream>
#include <chrono>
#include <sstream>
#include "Instruction.h"
#include "Type.h"
#include "Memory.h"
#include "Stack.h"
#include "Ext.h"
#include "GasMeter.h"
#include "Utils.h"
#include "Endianness.h"
#include "Arith256.h"
#include "RuntimeManager.h"
namespace dev
{

1
libevmjit/Compiler.h

@ -1,4 +1,5 @@
#pragma once
#include "Common.h"
#include "BasicBlock.h"

98
libevmjit/CompilerHelper.cpp

@ -1,47 +1,51 @@
#include "CompilerHelper.h"
#include "RuntimeManager.h"
#include <llvm/IR/Module.h>
namespace dev
{
namespace eth
{
namespace jit
{
CompilerHelper::CompilerHelper(llvm::IRBuilder<>& _builder) :
m_builder(_builder)
{}
llvm::Module* CompilerHelper::getModule()
{
assert(m_builder.GetInsertBlock());
assert(m_builder.GetInsertBlock()->getParent()); // BB must be in a function
return m_builder.GetInsertBlock()->getParent()->getParent();
}
llvm::Function* CompilerHelper::getMainFunction()
{
// TODO: Rename or change semantics of getMainFunction() function
assert(m_builder.GetInsertBlock());
auto mainFunc = m_builder.GetInsertBlock()->getParent();
assert(mainFunc);
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
return mainFunc;
return nullptr;
}
llvm::CallInst* CompilerHelper::createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args)
{
return getBuilder().CreateCall(_func, {_args.begin(), _args.size()});
}
RuntimeHelper::RuntimeHelper(RuntimeManager& _runtimeManager):
CompilerHelper(_runtimeManager.getBuilder()),
m_runtimeManager(_runtimeManager)
{}
}
}
}
#include "CompilerHelper.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h>
#include "preprocessor/llvm_includes_end.h"
#include "RuntimeManager.h"
namespace dev
{
namespace eth
{
namespace jit
{
CompilerHelper::CompilerHelper(llvm::IRBuilder<>& _builder) :
m_builder(_builder)
{}
llvm::Module* CompilerHelper::getModule()
{
assert(m_builder.GetInsertBlock());
assert(m_builder.GetInsertBlock()->getParent()); // BB must be in a function
return m_builder.GetInsertBlock()->getParent()->getParent();
}
llvm::Function* CompilerHelper::getMainFunction()
{
// TODO: Rename or change semantics of getMainFunction() function
assert(m_builder.GetInsertBlock());
auto mainFunc = m_builder.GetInsertBlock()->getParent();
assert(mainFunc);
if (mainFunc == &mainFunc->getParent()->getFunctionList().front()) // Main function is the first one in module
return mainFunc;
return nullptr;
}
llvm::CallInst* CompilerHelper::createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args)
{
return getBuilder().CreateCall(_func, {_args.begin(), _args.size()});
}
RuntimeHelper::RuntimeHelper(RuntimeManager& _runtimeManager):
CompilerHelper(_runtimeManager.getBuilder()),
m_runtimeManager(_runtimeManager)
{}
}
}
}

154
libevmjit/CompilerHelper.h

@ -1,79 +1,79 @@
#pragma once
#pragma once
#include "preprocessor/llvm_includes_start.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IRBuilder.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
/// Base class for compiler helpers like Memory, GasMeter, etc.
class CompilerHelper
{
protected:
CompilerHelper(llvm::IRBuilder<>& _builder);
CompilerHelper(const CompilerHelper&) = delete;
CompilerHelper& operator=(CompilerHelper) = delete;
/// Reference to the IR module being compiled
llvm::Module* getModule();
/// Reference to the main module function
llvm::Function* getMainFunction();
/// Reference to parent compiler IR builder
llvm::IRBuilder<>& m_builder;
llvm::IRBuilder<>& getBuilder() { return m_builder; }
llvm::CallInst* createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args);
friend class RuntimeHelper;
};
/// Compiler helper that depends on runtime data
class RuntimeHelper : public CompilerHelper
{
protected:
RuntimeHelper(RuntimeManager& _runtimeManager);
RuntimeManager& getRuntimeManager() { return m_runtimeManager; }
private:
RuntimeManager& m_runtimeManager;
};
/// Saves the insert point of the IR builder and restores it when destructed
struct InsertPointGuard
{
InsertPointGuard(llvm::IRBuilder<>& _builder) :
m_builder(_builder),
m_insertBB(m_builder.GetInsertBlock()),
m_insertPt(m_builder.GetInsertPoint())
{}
InsertPointGuard(const InsertPointGuard&) = delete;
void operator=(InsertPointGuard) = delete;
~InsertPointGuard()
{
m_builder.SetInsertPoint(m_insertBB, m_insertPt);
}
private:
llvm::IRBuilder<>& m_builder;
llvm::BasicBlock* m_insertBB;
llvm::BasicBlock::iterator m_insertPt;
};
}
}
}
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
class RuntimeManager;
/// Base class for compiler helpers like Memory, GasMeter, etc.
class CompilerHelper
{
protected:
CompilerHelper(llvm::IRBuilder<>& _builder);
CompilerHelper(const CompilerHelper&) = delete;
CompilerHelper& operator=(CompilerHelper) = delete;
/// Reference to the IR module being compiled
llvm::Module* getModule();
/// Reference to the main module function
llvm::Function* getMainFunction();
/// Reference to parent compiler IR builder
llvm::IRBuilder<>& m_builder;
llvm::IRBuilder<>& getBuilder() { return m_builder; }
llvm::CallInst* createCall(llvm::Function* _func, std::initializer_list<llvm::Value*> const& _args);
friend class RuntimeHelper;
};
/// Compiler helper that depends on runtime data
class RuntimeHelper : public CompilerHelper
{
protected:
RuntimeHelper(RuntimeManager& _runtimeManager);
RuntimeManager& getRuntimeManager() { return m_runtimeManager; }
private:
RuntimeManager& m_runtimeManager;
};
/// Saves the insert point of the IR builder and restores it when destructed
struct InsertPointGuard
{
InsertPointGuard(llvm::IRBuilder<>& _builder) :
m_builder(_builder),
m_insertBB(m_builder.GetInsertBlock()),
m_insertPt(m_builder.GetInsertPoint())
{}
InsertPointGuard(const InsertPointGuard&) = delete;
void operator=(InsertPointGuard) = delete;
~InsertPointGuard()
{
m_builder.SetInsertPoint(m_insertBB, m_insertPt);
}
private:
llvm::IRBuilder<>& m_builder;
llvm::BasicBlock* m_insertBB;
llvm::BasicBlock::iterator m_insertPt;
};
}
}
}

77
libevmjit/Endianness.cpp

@ -1,38 +1,39 @@
#include "Endianness.h"
#include "Type.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
union tester
{
unsigned int x;
unsigned char isLE;
};
if (tester{1}.isLE)
{
// FIXME: Disabled because of problems with BYTE
//if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(_word))
// return _builder.getInt(constant->getValue().byteSwap());
// OPT: Cache func declaration?
auto bswapFunc = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::Word);
return _builder.CreateCall(bswapFunc, _word);
}
return _word;
}
}
}
}
#include "Endianness.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include "Type.h"
namespace dev
{
namespace eth
{
namespace jit
{
llvm::Value* Endianness::bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word)
{
union tester
{
unsigned int x;
unsigned char isLE;
};
if (tester{1}.isLE)
{
// FIXME: Disabled because of problems with BYTE
//if (auto constant = llvm::dyn_cast<llvm::ConstantInt>(_word))
// return _builder.getInt(constant->getValue().byteSwap());
// OPT: Cache func declaration?
auto bswapFunc = llvm::Intrinsic::getDeclaration(_builder.GetInsertBlock()->getParent()->getParent(), llvm::Intrinsic::bswap, Type::Word);
return _builder.CreateCall(bswapFunc, _word);
}
return _word;
}
}
}
}

50
libevmjit/Endianness.h

@ -1,25 +1,25 @@
#pragma once
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IRBuilder.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
struct Endianness
{
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
static llvm::Value* toNative(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
private:
static llvm::Value* bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}
#pragma once
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IRBuilder.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth
{
namespace jit
{
struct Endianness
{
static llvm::Value* toBE(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
static llvm::Value* toNative(llvm::IRBuilder<>& _builder, llvm::Value* _word) { return bswapIfLE(_builder, _word); }
private:
static llvm::Value* bswapIfLE(llvm::IRBuilder<>& _builder, llvm::Value* _word);
};
}
}
}

1
libevmjit/ExecStats.cpp

@ -1,4 +1,5 @@
#include "ExecStats.h"
#include <iostream>
#include <iomanip>
#include <cassert>

4
libevmjit/ExecStats.h

@ -1,7 +1,9 @@
#pragma once
#include "ExecutionEngine.h"
#include <chrono>
#include "ExecutionEngine.h"
namespace dev
{
namespace eth

17
libevmjit/ExecutionEngine.cpp

@ -1,9 +1,8 @@
#include "ExecutionEngine.h"
#include "Runtime.h"
#include "Compiler.h"
#include "Cache.h"
#include "ExecStats.h"
#include "BuildInfo.gen.h"
#include <array>
#include <cstdlib> // env options
#include <iostream>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Module.h>
@ -15,9 +14,11 @@
#include <llvm/Support/Host.h>
#include "preprocessor/llvm_includes_end.h"
#include <array>
#include <cstdlib> // env options
#include <iostream>
#include "Runtime.h"
#include "Compiler.h"
#include "Cache.h"
#include "ExecStats.h"
#include "BuildInfo.gen.h"
namespace dev
{

4
libevmjit/ExecutionEngine.h

@ -1,7 +1,9 @@
#pragma once
#include "RuntimeData.h"
#include <memory>
#include "RuntimeData.h"
namespace dev
{
namespace eth

9
libevmjit/Ext.cpp

@ -1,13 +1,14 @@
#include "Ext.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include "RuntimeManager.h"
#include "Memory.h"
#include "Type.h"
#include "Endianness.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth

4
libevmjit/Ext.h

@ -1,7 +1,9 @@
#pragma once
#include "CompilerHelper.h"
#include <array>
#include "CompilerHelper.h"
namespace dev
{
namespace eth

8
libevmjit/GasMeter.cpp

@ -1,11 +1,11 @@
#include "GasMeter.h"
#include "Ext.h"
#include "RuntimeManager.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include "Ext.h"
#include "RuntimeManager.h"
namespace dev
{

1
libevmjit/GasMeter.h

@ -1,4 +1,5 @@
#pragma once
#include "CompilerHelper.h"
#include "Instruction.h"

1
libevmjit/Instruction.h

@ -1,4 +1,5 @@
#pragma once
#include "Common.h"
namespace llvm

9
libevmjit/Memory.cpp

@ -1,14 +1,15 @@
#include "Memory.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
#include "Type.h"
#include "Runtime.h"
#include "GasMeter.h"
#include "Endianness.h"
#include "RuntimeManager.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/IntrinsicInst.h>
#include "preprocessor/llvm_includes_end.h"
namespace dev
{
namespace eth

1
libevmjit/Memory.h

@ -1,4 +1,5 @@
#pragma once
#include "CompilerHelper.h"
namespace dev

1
libevmjit/Runtime.cpp

@ -1,4 +1,5 @@
#include "Runtime.h"
#include <cassert>
namespace dev

79
libevmjit/Runtime.h

@ -1,39 +1,40 @@
#pragma once
#include "RuntimeData.h"
namespace dev
{
namespace eth
{
namespace jit
{
using StackImpl = std::vector<i256>;
using MemoryImpl = bytes;
class Runtime
{
public:
Runtime(RuntimeData* _data, Env* _env);
Runtime(const Runtime&) = delete;
Runtime& operator=(const Runtime&) = delete;
StackImpl& getStack() { return m_stack; }
MemoryImpl& getMemory() { return m_memory; }
bytes_ref getReturnData() const;
private:
RuntimeData& m_data; ///< Pointer to data. Expected by compiled contract.
Env& m_env; ///< Pointer to environment proxy. Expected by compiled contract.
void* m_currJmpBuf = nullptr; ///< Pointer to jump buffer. Expected by compiled contract.
byte* m_memoryData = nullptr;
i256 m_memorySize;
StackImpl m_stack;
MemoryImpl m_memory;
};
}
}
}
#pragma once
#include "RuntimeData.h"
namespace dev
{
namespace eth
{
namespace jit
{
using StackImpl = std::vector<i256>;
using MemoryImpl = bytes;
class Runtime
{
public:
Runtime(RuntimeData* _data, Env* _env);
Runtime(const Runtime&) = delete;
Runtime& operator=(const Runtime&) = delete;
StackImpl& getStack() { return m_stack; }
MemoryImpl& getMemory() { return m_memory; }
bytes_ref getReturnData() const;
private:
RuntimeData& m_data; ///< Pointer to data. Expected by compiled contract.
Env& m_env; ///< Pointer to environment proxy. Expected by compiled contract.
void* m_currJmpBuf = nullptr; ///< Pointer to jump buffer. Expected by compiled contract.
byte* m_memoryData = nullptr;
i256 m_memorySize;
StackImpl m_stack;
MemoryImpl m_memory;
};
}
}
}

1
libevmjit/RuntimeData.h

@ -1,4 +1,5 @@
#pragma once
#include "Common.h"
namespace dev

1
libevmjit/RuntimeManager.h

@ -1,4 +1,5 @@
#pragma once
#include "CompilerHelper.h"
#include "Type.h"
#include "RuntimeData.h"

7
libevmjit/Stack.cpp

@ -1,8 +1,11 @@
#include "Stack.h"
#include "RuntimeManager.h"
#include "Runtime.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Function.h>
#include "preprocessor/llvm_includes_end.h"
#include "RuntimeManager.h"
#include "Runtime.h"
namespace dev
{

1
libevmjit/Stack.h

@ -1,4 +1,5 @@
#pragma once
#include "CompilerHelper.h"
namespace dev

3
libevmjit/Type.h

@ -1,11 +1,12 @@
#pragma once
#include "Common.h"
#include "preprocessor/llvm_includes_start.h"
#include <llvm/IR/Type.h>
#include <llvm/IR/Constants.h>
#include "preprocessor/llvm_includes_end.h"
#include "Common.h"
namespace dev
{
namespace eth

8
libevmjit/preprocessor/llvm_includes_end.h

@ -1,3 +1,5 @@
#pragma warning(pop)
#pragma GCC diagnostic pop
#if defined(_MSC_VER)
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif

13
libevmjit/preprocessor/llvm_includes_start.h

@ -1,5 +1,8 @@
#pragma warning(push)
#pragma warning(disable: 4267 4244 4800)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4267 4244 4800)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wconversion"
#endif

Loading…
Cancel
Save