VMFactory.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. This file is part of cpp-ethereum.
  3. cpp-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. cpp-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "VMFactory.h"
  15. #include <libdevcore/Assertions.h>
  16. #include "VM.h"
  17. #if ETH_EVMJIT
  18. #include "JitVM.h"
  19. #include "SmartVM.h"
  20. #endif
  21. namespace dev
  22. {
  23. namespace eth
  24. {
  25. namespace
  26. {
  27. auto g_kind = VMKind::Interpreter;
  28. }
  29. void VMFactory::setKind(VMKind _kind)
  30. {
  31. g_kind = _kind;
  32. }
  33. std::unique_ptr<VMFace> VMFactory::create()
  34. {
  35. return create(g_kind);
  36. }
  37. std::unique_ptr<VMFace> VMFactory::create(VMKind _kind)
  38. {
  39. #if ETH_EVMJIT
  40. switch (_kind)
  41. {
  42. default:
  43. case VMKind::Interpreter:
  44. return std::unique_ptr<VMFace>(new VM);
  45. case VMKind::JIT:
  46. return std::unique_ptr<VMFace>(new JitVM);
  47. case VMKind::Smart:
  48. return std::unique_ptr<VMFace>(new SmartVM);
  49. }
  50. #else
  51. asserts(_kind == VMKind::Interpreter && "JIT disabled in build configuration");
  52. return std::unique_ptr<VMFace>(new VM);
  53. #endif
  54. }
  55. }
  56. }