PageRenderTime 304ms CodeModel.GetById 140ms app.highlight 4ms RepoModel.GetById 157ms app.codeStats 0ms

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