Browse Source

Macros grouping PUSH, DUP and SWAP switch cases

cl-refactor
Paweł Bylica 10 years ago
parent
commit
f1ea6c9257
  1. 102
      evmcc/Compiler.cpp
  2. 67
      evmcc/Utils.h

102
evmcc/Compiler.cpp

@ -14,6 +14,7 @@
#include "Memory.h" #include "Memory.h"
#include "Ext.h" #include "Ext.h"
#include "GasMeter.h" #include "GasMeter.h"
#include "Utils.h"
namespace evmcc namespace evmcc
{ {
@ -48,38 +49,8 @@ void Compiler::createBasicBlocks(const dev::bytes& bytecode)
auto inst = static_cast<Instruction>(*curr); auto inst = static_cast<Instruction>(*curr);
switch (inst) switch (inst)
{ {
case Instruction::PUSH1:
case Instruction::PUSH2: case Instruction::ANY_PUSH:
case Instruction::PUSH3:
case Instruction::PUSH4:
case Instruction::PUSH5:
case Instruction::PUSH6:
case Instruction::PUSH7:
case Instruction::PUSH8:
case Instruction::PUSH9:
case Instruction::PUSH10:
case Instruction::PUSH11:
case Instruction::PUSH12:
case Instruction::PUSH13:
case Instruction::PUSH14:
case Instruction::PUSH15:
case Instruction::PUSH16:
case Instruction::PUSH17:
case Instruction::PUSH18:
case Instruction::PUSH19:
case Instruction::PUSH20:
case Instruction::PUSH21:
case Instruction::PUSH22:
case Instruction::PUSH23:
case Instruction::PUSH24:
case Instruction::PUSH25:
case Instruction::PUSH26:
case Instruction::PUSH27:
case Instruction::PUSH28:
case Instruction::PUSH29:
case Instruction::PUSH30:
case Instruction::PUSH31:
case Instruction::PUSH32:
{ {
auto numBytes = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::PUSH1) + 1; auto numBytes = static_cast<size_t>(inst) - static_cast<size_t>(Instruction::PUSH1) + 1;
auto next = curr + numBytes + 1; auto next = curr + numBytes + 1;
@ -477,38 +448,7 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
break; break;
} }
case Instruction::PUSH1: case Instruction::ANY_PUSH:
case Instruction::PUSH2:
case Instruction::PUSH3:
case Instruction::PUSH4:
case Instruction::PUSH5:
case Instruction::PUSH6:
case Instruction::PUSH7:
case Instruction::PUSH8:
case Instruction::PUSH9:
case Instruction::PUSH10:
case Instruction::PUSH11:
case Instruction::PUSH12:
case Instruction::PUSH13:
case Instruction::PUSH14:
case Instruction::PUSH15:
case Instruction::PUSH16:
case Instruction::PUSH17:
case Instruction::PUSH18:
case Instruction::PUSH19:
case Instruction::PUSH20:
case Instruction::PUSH21:
case Instruction::PUSH22:
case Instruction::PUSH23:
case Instruction::PUSH24:
case Instruction::PUSH25:
case Instruction::PUSH26:
case Instruction::PUSH27:
case Instruction::PUSH28:
case Instruction::PUSH29:
case Instruction::PUSH30:
case Instruction::PUSH31:
case Instruction::PUSH32:
{ {
auto numBytes = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::PUSH1) + 1; auto numBytes = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::PUSH1) + 1;
auto value = llvm::APInt(256, 0); auto value = llvm::APInt(256, 0);
@ -523,44 +463,14 @@ std::unique_ptr<llvm::Module> Compiler::compile(const dev::bytes& bytecode)
break; break;
} }
case Instruction::DUP1: case Instruction::ANY_DUP:
case Instruction::DUP2:
case Instruction::DUP3:
case Instruction::DUP4:
case Instruction::DUP5:
case Instruction::DUP6:
case Instruction::DUP7:
case Instruction::DUP8:
case Instruction::DUP9:
case Instruction::DUP10:
case Instruction::DUP11:
case Instruction::DUP12:
case Instruction::DUP13:
case Instruction::DUP14:
case Instruction::DUP15:
case Instruction::DUP16:
{ {
auto index = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::DUP1); auto index = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::DUP1);
stack.dup(index); stack.dup(index);
break; break;
} }
case Instruction::SWAP1: case Instruction::ANY_SWAP:
case Instruction::SWAP2:
case Instruction::SWAP3:
case Instruction::SWAP4:
case Instruction::SWAP5:
case Instruction::SWAP6:
case Instruction::SWAP7:
case Instruction::SWAP8:
case Instruction::SWAP9:
case Instruction::SWAP10:
case Instruction::SWAP11:
case Instruction::SWAP12:
case Instruction::SWAP13:
case Instruction::SWAP14:
case Instruction::SWAP15:
case Instruction::SWAP16:
{ {
auto index = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::SWAP1) + 1; auto index = static_cast<size_t>(inst)-static_cast<size_t>(Instruction::SWAP1) + 1;
stack.swap(index); stack.swap(index);

67
evmcc/Utils.h

@ -44,4 +44,71 @@ private:
void operator=(InsertPointGuard) = delete; void operator=(InsertPointGuard) = delete;
}; };
#define ANY_PUSH PUSH1: \
case Instruction::PUSH2: \
case Instruction::PUSH3: \
case Instruction::PUSH4: \
case Instruction::PUSH5: \
case Instruction::PUSH6: \
case Instruction::PUSH7: \
case Instruction::PUSH8: \
case Instruction::PUSH9: \
case Instruction::PUSH10: \
case Instruction::PUSH11: \
case Instruction::PUSH12: \
case Instruction::PUSH13: \
case Instruction::PUSH14: \
case Instruction::PUSH15: \
case Instruction::PUSH16: \
case Instruction::PUSH17: \
case Instruction::PUSH18: \
case Instruction::PUSH19: \
case Instruction::PUSH20: \
case Instruction::PUSH21: \
case Instruction::PUSH22: \
case Instruction::PUSH23: \
case Instruction::PUSH24: \
case Instruction::PUSH25: \
case Instruction::PUSH26: \
case Instruction::PUSH27: \
case Instruction::PUSH28: \
case Instruction::PUSH29: \
case Instruction::PUSH30: \
case Instruction::PUSH31: \
case Instruction::PUSH32
#define ANY_DUP DUP1: \
case Instruction::DUP2: \
case Instruction::DUP3: \
case Instruction::DUP4: \
case Instruction::DUP5: \
case Instruction::DUP6: \
case Instruction::DUP7: \
case Instruction::DUP8: \
case Instruction::DUP9: \
case Instruction::DUP10: \
case Instruction::DUP11: \
case Instruction::DUP12: \
case Instruction::DUP13: \
case Instruction::DUP14: \
case Instruction::DUP15: \
case Instruction::DUP16
#define ANY_SWAP SWAP1: \
case Instruction::SWAP2: \
case Instruction::SWAP3: \
case Instruction::SWAP4: \
case Instruction::SWAP5: \
case Instruction::SWAP6: \
case Instruction::SWAP7: \
case Instruction::SWAP8: \
case Instruction::SWAP9: \
case Instruction::SWAP10: \
case Instruction::SWAP11: \
case Instruction::SWAP12: \
case Instruction::SWAP13: \
case Instruction::SWAP14: \
case Instruction::SWAP15: \
case Instruction::SWAP16
} }
Loading…
Cancel
Save