Untitled


SUBMITTED BY: Guest

DATE: Sept. 8, 2013, 1:33 p.m.

FORMAT: Text only

SIZE: 1.3 kB

HITS: 907

  1. // opcode.h
  2. // feltételezve, hogy a getvar, result, stb. definiálva van. nyilván lehet komplexebb módon is, de ez egy példa
  3. DEFINE_OPCODE(add, Result() = GetVar(0) + GetVar(1))
  4. DEFINE_OPCODE(sub, Result() = GetVar(0) - GetVar(1))
  5. DEFINE_OPCODE(jmp, InstructionPointer() = GetVar(0))
  6. // akármi.cpp
  7. // opcode function definitions
  8. #define DEFINE_OPCODE(name, ...) \
  9. void opcode_##name() { \
  10. __VA_ARGS__ ; \
  11. }
  12. #include "opcode.h"
  13. #undef DEFINE_OPCODE
  14. // ez csak kis extra
  15. // enum class c++11 feature de mindegy
  16. enum class Opcodes {
  17. #define DEFINE_OPCODE(name, ...) \
  18. name ,
  19. #include "opcode.h"
  20. #undef DEFINE_OPCODE
  21. Count };
  22. // nem tudom a függvény pointer pontos szintaxisát de ez az lesz
  23. std::vector<(void)*()> opcodes;
  24. void InitializeOpcodes() {
  25. #define DEFINE_OPCODE(name, ...) \
  26. opcodes.push_back(name); \
  27. assert(opcodes.count() == Opcodes::name + 1);
  28. #include "opcode.h"
  29. #undef DEFINE_OPCODE
  30. assert(opcodes.count() == Opcodes::Count);
  31. }
  32. // ezután pl opcodes[Opcodes::add] egy pointer lesz az opcode_add() függvényre
  33. // nyilván a függvényeknek át kell adni valamilyen paramétert (asm stream), azt nem vettem ebbe bele

comments powered by Disqus