/JIT/opcodes/name.cc

http://unladen-swallow.googlecode.com/ · C++ · 62 lines · 53 code · 9 blank · 0 comment · 0 complexity · 407f7b2d5f4fc1cea02ecba4250c6420 MD5 · raw file

  1. #include "Python.h"
  2. #include "JIT/opcodes/name.h"
  3. #include "JIT/llvm_fbuilder.h"
  4. #include "llvm/BasicBlock.h"
  5. #include "llvm/Function.h"
  6. #include "llvm/Instructions.h"
  7. using llvm::BasicBlock;
  8. using llvm::ConstantInt;
  9. using llvm::Function;
  10. using llvm::Type;
  11. using llvm::Value;
  12. namespace py {
  13. OpcodeName::OpcodeName(LlvmFunctionBuilder *fbuilder) :
  14. fbuilder_(fbuilder), state_(fbuilder->state())
  15. {
  16. }
  17. void
  18. OpcodeName::LOAD_NAME(int index)
  19. {
  20. Value *result = this->state_->CreateCall(
  21. this->state_->GetGlobalFunction<PyObject *(PyFrameObject*, int)>(
  22. "_PyEval_LoadName"),
  23. this->fbuilder_->frame(),
  24. ConstantInt::get(
  25. PyTypeBuilder<int>::get(this->fbuilder_->context()), index));
  26. this->fbuilder_->PropagateExceptionOnNull(result);
  27. this->fbuilder_->Push(result);
  28. }
  29. void
  30. OpcodeName::STORE_NAME(int index)
  31. {
  32. Value *to_store = this->fbuilder_->Pop();
  33. Value *err = this->state_->CreateCall(
  34. this->state_->GetGlobalFunction<int(PyFrameObject*, int, PyObject*)>(
  35. "_PyEval_StoreName"),
  36. this->fbuilder_->frame(),
  37. ConstantInt::get(
  38. PyTypeBuilder<int>::get(this->fbuilder_->context()), index),
  39. to_store);
  40. this->fbuilder_->PropagateExceptionOnNonZero(err);
  41. }
  42. void
  43. OpcodeName::DELETE_NAME(int index)
  44. {
  45. Value *err = this->state_->CreateCall(
  46. this->state_->GetGlobalFunction<int(PyFrameObject*, int)>(
  47. "_PyEval_DeleteName"),
  48. this->fbuilder_->frame(),
  49. ConstantInt::get(
  50. PyTypeBuilder<int>::get(this->fbuilder_->context()), index));
  51. this->fbuilder_->PropagateExceptionOnNonZero(err);
  52. }
  53. }