/JIT/opcodes/container.h

http://unladen-swallow.googlecode.com/ · C Header · 67 lines · 37 code · 16 blank · 14 comment · 0 complexity · e7340ccb1ac5085e7925e319be1386ed MD5 · raw file

  1. // -*- C++ -*-
  2. #ifndef OPCODE_CONTAINER_H_
  3. #define OPCODE_CONTAINER_H_
  4. #ifndef __cplusplus
  5. #error This header expects to be included only in C++ source
  6. #endif
  7. #include "llvm/Support/IRBuilder.h"
  8. #include "llvm/Support/TargetFolder.h"
  9. namespace py {
  10. class LlvmFunctionBuilder;
  11. class LlvmFunctionState;
  12. // This class contains most opcodes related to containers.
  13. // BINARY_SUBSCR can be found in OpcodeBinops.
  14. class OpcodeContainer
  15. {
  16. public:
  17. OpcodeContainer(LlvmFunctionBuilder *fbuilder);
  18. void BUILD_TUPLE(int size);
  19. void BUILD_LIST(int size);
  20. void BUILD_MAP(int size);
  21. void UNPACK_SEQUENCE(int size);
  22. void STORE_SUBSCR();
  23. void DELETE_SUBSCR();
  24. void STORE_MAP();
  25. void LIST_APPEND();
  26. // IMPORT_NAME is a bit of a stretch, but container is the closest group.
  27. // It imports something from a container/module.
  28. void IMPORT_NAME();
  29. private:
  30. typedef llvm::IRBuilder<true, llvm::TargetFolder> BuilderT;
  31. // Helper method for building a new sequence from items on the stack.
  32. // 'size' is the number of items to build, 'createname' the Python/C API
  33. // function to call to create the sequence, and 'getitemslot' is called
  34. // to get each item's address (GetListItemSlot or GetTupleItemSlot.)
  35. void BuildSequenceLiteral(
  36. int size, const char *createname,
  37. llvm::Value *(LlvmFunctionState::*getitemslot)(llvm::Value *, int));
  38. // _safe is guaranteed to work; _list_int is specialized for indexing a list
  39. // with an int.
  40. void STORE_SUBSCR_safe();
  41. void STORE_SUBSCR_list_int();
  42. // A fast version that avoids the import machinery if sys.modules and other
  43. // modules haven't changed. Returns false if the attempt to optimize failed;
  44. // the safe version in IMPORT_NAME() will be used.
  45. bool IMPORT_NAME_fast();
  46. LlvmFunctionBuilder *fbuilder_;
  47. LlvmFunctionState *state_;
  48. BuilderT &builder_;
  49. };
  50. }
  51. #endif /* OPCODE_CONTAINER_H_ */