PageRenderTime 125ms CodeModel.GetById 30ms app.highlight 70ms RepoModel.GetById 20ms app.codeStats 1ms

/JIT/PyBytecodeDispatch.cc

http://unladen-swallow.googlecode.com/
C++ | 660 lines | 568 code | 92 blank | 0 comment | 0 complexity | 89365320db518189a097449c2b96e744 MD5 | raw file
  1#include "Python.h"
  2#include "opcode.h"
  3
  4#include "JIT/PyBytecodeDispatch.h"
  5#include "JIT/llvm_fbuilder.h"
  6
  7#include "JIT/opcodes/attributes.h"
  8#include "JIT/opcodes/binops.h"
  9#include "JIT/opcodes/block.h"
 10#include "JIT/opcodes/call.h"
 11#include "JIT/opcodes/closure.h"
 12#include "JIT/opcodes/cmpops.h"
 13#include "JIT/opcodes/container.h"
 14#include "JIT/opcodes/control.h"
 15#include "JIT/opcodes/globals.h"
 16#include "JIT/opcodes/locals.h"
 17#include "JIT/opcodes/loop.h"
 18#include "JIT/opcodes/name.h"
 19#include "JIT/opcodes/slice.h"
 20#include "JIT/opcodes/stack.h"
 21#include "JIT/opcodes/unaryops.h"
 22
 23#include "llvm/BasicBlock.h"
 24
 25using llvm::BasicBlock;
 26
 27namespace py {
 28
 29PyBytecodeDispatch::PyBytecodeDispatch(LlvmFunctionBuilder *fbuilder) :
 30    fbuilder_(fbuilder)
 31{
 32}
 33
 34void
 35PyBytecodeDispatch::LOAD_CONST(int index)
 36{
 37    OpcodeLocals locals(fbuilder_);
 38    locals.LOAD_CONST(index);
 39}
 40
 41void
 42PyBytecodeDispatch::LOAD_GLOBAL(int name_index)
 43{
 44    OpcodeGlobals globals(fbuilder_);
 45    globals.LOAD_GLOBAL(name_index);
 46}
 47
 48void
 49PyBytecodeDispatch::STORE_GLOBAL(int name_index)
 50{
 51    OpcodeGlobals globals(fbuilder_);
 52    globals.STORE_GLOBAL(name_index);
 53}
 54
 55void
 56PyBytecodeDispatch::DELETE_GLOBAL(int name_index)
 57{
 58    OpcodeGlobals globals(fbuilder_);
 59    globals.DELETE_GLOBAL(name_index);
 60}
 61
 62void
 63PyBytecodeDispatch::LOAD_NAME(int index)
 64{
 65    OpcodeName name(fbuilder_);
 66    name.LOAD_NAME(index);
 67}
 68
 69void
 70PyBytecodeDispatch::STORE_NAME(int index)
 71{
 72    OpcodeName name(fbuilder_);
 73    name.STORE_NAME(index);
 74}
 75
 76void
 77PyBytecodeDispatch::DELETE_NAME(int index)
 78{
 79    OpcodeName name(fbuilder_);
 80    name.DELETE_NAME(index);
 81}
 82
 83void
 84PyBytecodeDispatch::LOAD_ATTR(int names_index)
 85{
 86    OpcodeAttributes attr(fbuilder_);
 87    attr.LOAD_ATTR(names_index);
 88}
 89
 90void
 91PyBytecodeDispatch::LOAD_METHOD(int names_index)
 92{
 93    OpcodeAttributes attr(fbuilder_);
 94    attr.LOAD_METHOD(names_index);
 95}
 96
 97void
 98PyBytecodeDispatch::STORE_ATTR(int names_index)
 99{
100    OpcodeAttributes attr(fbuilder_);
101    attr.STORE_ATTR(names_index);
102}
103
104void
105PyBytecodeDispatch::DELETE_ATTR(int index)
106{
107    OpcodeAttributes attr(fbuilder_);
108    attr.DELETE_ATTR(index);
109}
110
111void
112PyBytecodeDispatch::LOAD_FAST(int index)
113{
114    OpcodeLocals locals(fbuilder_);
115    locals.LOAD_FAST(index);
116}
117
118void
119PyBytecodeDispatch::WITH_CLEANUP()
120{
121    OpcodeBlock block(fbuilder_);
122    block.WITH_CLEANUP();
123}
124
125void
126PyBytecodeDispatch::LOAD_CLOSURE(int freevars_index)
127{
128    OpcodeClosure closure(fbuilder_);
129    closure.LOAD_CLOSURE(freevars_index);
130}
131
132void
133PyBytecodeDispatch::MAKE_CLOSURE(int num_defaults)
134{
135    OpcodeClosure closure(fbuilder_);
136    closure.MAKE_CLOSURE(num_defaults);
137}
138
139void
140PyBytecodeDispatch::CALL_FUNCTION(int oparg)
141{
142    OpcodeCall call(fbuilder_);
143    call.CALL_FUNCTION(oparg);
144}
145
146void
147PyBytecodeDispatch::CALL_METHOD(int oparg)
148{
149    OpcodeCall call(fbuilder_);
150    call.CALL_METHOD(oparg);
151}
152
153void
154PyBytecodeDispatch::CALL_FUNCTION_VAR(int oparg)
155{
156    OpcodeCall call(fbuilder_);
157    call.CALL_FUNCTION_VAR(oparg);
158}
159
160void
161PyBytecodeDispatch::CALL_FUNCTION_KW(int oparg)
162{
163    OpcodeCall call(fbuilder_);
164    call.CALL_FUNCTION_KW(oparg);
165}
166
167void
168PyBytecodeDispatch::CALL_FUNCTION_VAR_KW(int oparg)
169{
170    OpcodeCall call(fbuilder_);
171    call.CALL_FUNCTION_VAR_KW(oparg);
172}
173
174void
175PyBytecodeDispatch::IMPORT_NAME()
176{
177    OpcodeContainer cont(fbuilder_);
178    cont.IMPORT_NAME();
179}
180
181void
182PyBytecodeDispatch::LOAD_DEREF(int index)
183{
184    OpcodeClosure closure(fbuilder_);
185    closure.LOAD_DEREF(index);
186}
187
188void
189PyBytecodeDispatch::STORE_DEREF(int index)
190{
191    OpcodeClosure closure(fbuilder_);
192    closure.STORE_DEREF(index);
193}
194
195void
196PyBytecodeDispatch::JUMP_FORWARD(llvm::BasicBlock *target,
197                                 llvm::BasicBlock *fallthrough)
198{
199    OpcodeControl control(fbuilder_);
200    control.JUMP_FORWARD(target, fallthrough);
201}
202
203void
204PyBytecodeDispatch::JUMP_ABSOLUTE(llvm::BasicBlock *target,
205                                  llvm::BasicBlock *fallthrough)
206{
207    OpcodeControl control(fbuilder_);
208    control.JUMP_ABSOLUTE(target, fallthrough);
209}
210
211void
212PyBytecodeDispatch::POP_JUMP_IF_FALSE(unsigned target_idx,
213                                      unsigned fallthrough_idx,
214                                      BasicBlock *target,
215                                      BasicBlock *fallthrough)
216{
217    OpcodeControl control(fbuilder_);
218    control.POP_JUMP_IF_FALSE(target_idx, fallthrough_idx,
219                              target, fallthrough);
220}
221
222void
223PyBytecodeDispatch::POP_JUMP_IF_TRUE(unsigned target_idx,
224                                     unsigned fallthrough_idx,
225                                     BasicBlock *target,
226                                     BasicBlock *fallthrough)
227{
228    OpcodeControl control(fbuilder_);
229    control.POP_JUMP_IF_TRUE(target_idx, fallthrough_idx,
230                             target, fallthrough);
231}
232
233void
234PyBytecodeDispatch::JUMP_IF_FALSE_OR_POP(unsigned target_idx,
235                                         unsigned fallthrough_idx,
236                                         BasicBlock *target,
237                                         BasicBlock *fallthrough)
238{
239    OpcodeControl control(fbuilder_);
240    control.JUMP_IF_FALSE_OR_POP(target_idx, fallthrough_idx,
241                                 target, fallthrough);
242}
243
244void
245PyBytecodeDispatch::JUMP_IF_TRUE_OR_POP(unsigned target_idx,
246                                        unsigned fallthrough_idx,
247                                        BasicBlock *target,
248                                        BasicBlock *fallthrough)
249{
250    OpcodeControl control(fbuilder_);
251    control.JUMP_IF_TRUE_OR_POP(target_idx, fallthrough_idx,
252                                target, fallthrough);
253}
254
255void
256PyBytecodeDispatch::STORE_FAST(int index)
257{
258    OpcodeLocals locals(fbuilder_);
259    locals.STORE_FAST(index);
260}
261
262void
263PyBytecodeDispatch::DELETE_FAST(int index)
264{
265    OpcodeLocals locals(fbuilder_);
266    locals.DELETE_FAST(index);
267}
268
269void
270PyBytecodeDispatch::SETUP_LOOP(llvm::BasicBlock *target,
271                               int target_opindex,
272                               llvm::BasicBlock *fallthrough)
273{
274    OpcodeBlock block(fbuilder_);
275    block.SETUP_LOOP(target, target_opindex, fallthrough);
276}
277
278void
279PyBytecodeDispatch::GET_ITER()
280{
281    OpcodeLoop loop(fbuilder_);
282    loop.GET_ITER();
283}
284
285void
286PyBytecodeDispatch::FOR_ITER(llvm::BasicBlock *target,
287                             llvm::BasicBlock *fallthrough)
288{
289    OpcodeLoop loop(fbuilder_);
290    loop.FOR_ITER(target, fallthrough);
291}
292
293void
294PyBytecodeDispatch::POP_BLOCK()
295{
296    OpcodeBlock block(fbuilder_);
297    block.POP_BLOCK();
298}
299
300void
301PyBytecodeDispatch::SETUP_EXCEPT(llvm::BasicBlock *target,
302                                 int target_opindex,
303                                 llvm::BasicBlock *fallthrough)
304{
305    OpcodeBlock block(fbuilder_);
306    block.SETUP_EXCEPT(target, target_opindex, fallthrough);
307}
308
309void
310PyBytecodeDispatch::SETUP_FINALLY(llvm::BasicBlock *target,
311                                  int target_opindex,
312                                  llvm::BasicBlock *fallthrough)
313{
314    OpcodeBlock block(fbuilder_);
315    block.SETUP_FINALLY(target, target_opindex, fallthrough);
316}
317
318void
319PyBytecodeDispatch::END_FINALLY()
320{
321    OpcodeBlock block(fbuilder_);
322    block.END_FINALLY();
323}
324
325void
326PyBytecodeDispatch::CONTINUE_LOOP(llvm::BasicBlock *target,
327                                  int target_opindex,
328                                  llvm::BasicBlock *fallthrough)
329{
330    OpcodeLoop loop(fbuilder_);
331    loop.CONTINUE_LOOP(target, target_opindex, fallthrough);
332}
333
334void
335PyBytecodeDispatch::BREAK_LOOP()
336{
337    OpcodeLoop loop(fbuilder_);
338    loop.BREAK_LOOP();
339}
340
341void
342PyBytecodeDispatch::RETURN_VALUE()
343{
344    OpcodeControl control(fbuilder_);
345    control.RETURN_VALUE();
346}
347
348void
349PyBytecodeDispatch::YIELD_VALUE()
350{
351    OpcodeControl control(fbuilder_);
352    control.YIELD_VALUE();
353}
354
355void
356PyBytecodeDispatch::RAISE_VARARGS_ZERO()
357{
358    OpcodeControl control(fbuilder_);
359    control.RAISE_VARARGS_ZERO();
360}
361
362void
363PyBytecodeDispatch::RAISE_VARARGS_ONE()
364{
365    OpcodeControl control(fbuilder_);
366    control.RAISE_VARARGS_ONE();
367}
368
369void
370PyBytecodeDispatch::RAISE_VARARGS_TWO()
371{
372    OpcodeControl control(fbuilder_);
373    control.RAISE_VARARGS_TWO();
374}
375
376void
377PyBytecodeDispatch::RAISE_VARARGS_THREE()
378{
379    OpcodeControl control(fbuilder_);
380    control.RAISE_VARARGS_THREE();
381}
382
383void
384PyBytecodeDispatch::STORE_SUBSCR()
385{
386    OpcodeContainer cont(fbuilder_);
387    cont.STORE_SUBSCR();
388}
389
390void
391PyBytecodeDispatch::DELETE_SUBSCR()
392{
393    OpcodeContainer cont(fbuilder_);
394    cont.DELETE_SUBSCR();
395}
396
397#define BINOP_METH(OPCODE)              \
398void                                    \
399PyBytecodeDispatch::OPCODE()            \
400{                                       \
401    OpcodeBinops binops(fbuilder_);     \
402    binops.OPCODE();                    \
403}
404
405BINOP_METH(BINARY_ADD)
406BINOP_METH(BINARY_SUBTRACT)
407BINOP_METH(BINARY_MULTIPLY)
408BINOP_METH(BINARY_DIVIDE)
409BINOP_METH(BINARY_MODULO)
410BINOP_METH(BINARY_SUBSCR)
411
412BINOP_METH(BINARY_TRUE_DIVIDE)
413BINOP_METH(BINARY_LSHIFT)
414BINOP_METH(BINARY_RSHIFT)
415BINOP_METH(BINARY_OR)
416BINOP_METH(BINARY_XOR)
417BINOP_METH(BINARY_AND)
418BINOP_METH(BINARY_FLOOR_DIVIDE)
419
420BINOP_METH(INPLACE_ADD)
421BINOP_METH(INPLACE_SUBTRACT)
422BINOP_METH(INPLACE_MULTIPLY)
423BINOP_METH(INPLACE_TRUE_DIVIDE)
424BINOP_METH(INPLACE_DIVIDE)
425BINOP_METH(INPLACE_MODULO)
426BINOP_METH(INPLACE_LSHIFT)
427BINOP_METH(INPLACE_RSHIFT)
428BINOP_METH(INPLACE_OR)
429BINOP_METH(INPLACE_XOR)
430BINOP_METH(INPLACE_AND)
431BINOP_METH(INPLACE_FLOOR_DIVIDE)
432
433#undef BINOP_METH
434
435void
436PyBytecodeDispatch::BINARY_POWER()
437{
438    OpcodeBinops binops(fbuilder_);
439    binops.BINARY_POWER();
440}
441
442void
443PyBytecodeDispatch::INPLACE_POWER()
444{
445    OpcodeBinops binops(fbuilder_);
446    binops.INPLACE_POWER();
447}
448
449#define UNARYOP_METH(NAME)                              \
450void							\
451PyBytecodeDispatch::NAME()				\
452{							\
453    OpcodeUnaryops unary(fbuilder_);                    \
454    unary.NAME();                                       \
455}
456
457UNARYOP_METH(UNARY_CONVERT)
458UNARYOP_METH(UNARY_INVERT)
459UNARYOP_METH(UNARY_POSITIVE)
460UNARYOP_METH(UNARY_NEGATIVE)
461UNARYOP_METH(UNARY_NOT)
462#undef UNARYOP_METH
463
464void
465PyBytecodeDispatch::POP_TOP()
466{
467    OpcodeStack stack(fbuilder_);
468    stack.POP_TOP();
469}
470
471void
472PyBytecodeDispatch::DUP_TOP()
473{
474    OpcodeStack stack(fbuilder_);
475    stack.DUP_TOP();
476}
477
478void
479PyBytecodeDispatch::DUP_TOP_TWO()
480{
481    OpcodeStack stack(fbuilder_);
482    stack.DUP_TOP_TWO();
483}
484
485void
486PyBytecodeDispatch::DUP_TOP_THREE()
487{
488    OpcodeStack stack(fbuilder_);
489    stack.DUP_TOP_THREE();
490}
491
492void
493PyBytecodeDispatch::ROT_TWO()
494{
495    OpcodeStack stack(fbuilder_);
496    stack.ROT_TWO();
497}
498
499void
500PyBytecodeDispatch::ROT_THREE()
501{
502    OpcodeStack stack(fbuilder_);
503    stack.ROT_THREE();
504}
505
506void
507PyBytecodeDispatch::ROT_FOUR()
508{
509    OpcodeStack stack(fbuilder_);
510    stack.ROT_FOUR();
511}
512
513void
514PyBytecodeDispatch::COMPARE_OP(int cmp_op)
515{
516    OpcodeCmpops cmpops(fbuilder_);
517    cmpops.COMPARE_OP(cmp_op);
518}
519
520void
521PyBytecodeDispatch::LIST_APPEND()
522{
523    OpcodeContainer cont(fbuilder_);
524    cont.LIST_APPEND();
525}
526
527void
528PyBytecodeDispatch::STORE_MAP()
529{
530    OpcodeContainer cont(fbuilder_);
531    cont.STORE_MAP();
532}
533
534void
535PyBytecodeDispatch::BUILD_LIST(int size)
536{
537    OpcodeContainer cont(fbuilder_);
538    cont.BUILD_LIST(size);
539}
540
541void
542PyBytecodeDispatch::BUILD_TUPLE(int size)
543{
544    OpcodeContainer cont(fbuilder_);
545    cont.BUILD_TUPLE(size);
546}
547
548void
549PyBytecodeDispatch::BUILD_MAP(int size)
550{
551    OpcodeContainer cont(fbuilder_);
552    cont.BUILD_MAP(size);
553}
554
555void
556PyBytecodeDispatch::SLICE_BOTH()
557{
558    OpcodeSlice slice(fbuilder_);
559    slice.SLICE_BOTH();
560}
561
562void
563PyBytecodeDispatch::SLICE_LEFT()
564{
565    OpcodeSlice slice(fbuilder_);
566    slice.SLICE_LEFT();
567}
568
569void
570PyBytecodeDispatch::SLICE_RIGHT()
571{
572    OpcodeSlice slice(fbuilder_);
573    slice.SLICE_RIGHT();
574}
575
576void
577PyBytecodeDispatch::SLICE_NONE()
578{
579    OpcodeSlice slice(fbuilder_);
580    slice.SLICE_NONE();
581}
582
583void
584PyBytecodeDispatch::STORE_SLICE_BOTH()
585{
586    OpcodeSlice slice(fbuilder_);
587    slice.STORE_SLICE_BOTH();
588}
589
590void
591PyBytecodeDispatch::STORE_SLICE_LEFT()
592{
593    OpcodeSlice slice(fbuilder_);
594    slice.STORE_SLICE_LEFT();
595}
596
597void
598PyBytecodeDispatch::STORE_SLICE_RIGHT()
599{
600    OpcodeSlice slice(fbuilder_);
601    slice.STORE_SLICE_RIGHT();
602}
603
604void
605PyBytecodeDispatch::STORE_SLICE_NONE()
606{
607    OpcodeSlice slice(fbuilder_);
608    slice.STORE_SLICE_NONE();
609}
610
611void
612PyBytecodeDispatch::DELETE_SLICE_BOTH()
613{
614    OpcodeSlice slice(fbuilder_);
615    slice.DELETE_SLICE_BOTH();
616}
617
618void
619PyBytecodeDispatch::DELETE_SLICE_LEFT()
620{
621    OpcodeSlice slice(fbuilder_);
622    slice.DELETE_SLICE_LEFT();
623}
624
625void
626PyBytecodeDispatch::DELETE_SLICE_RIGHT()
627{
628    OpcodeSlice slice(fbuilder_);
629    slice.DELETE_SLICE_RIGHT();
630}
631
632void
633PyBytecodeDispatch::DELETE_SLICE_NONE()
634{
635    OpcodeSlice slice(fbuilder_);
636    slice.DELETE_SLICE_NONE();
637}
638
639void
640PyBytecodeDispatch::BUILD_SLICE_TWO()
641{
642    OpcodeSlice slice(fbuilder_);
643    slice.BUILD_SLICE_TWO();
644}
645
646void
647PyBytecodeDispatch::BUILD_SLICE_THREE()
648{
649    OpcodeSlice slice(fbuilder_);
650    slice.BUILD_SLICE_THREE();
651}
652
653void
654PyBytecodeDispatch::UNPACK_SEQUENCE(int size)
655{
656    OpcodeContainer cont(fbuilder_);
657    cont.UNPACK_SEQUENCE(size);
658}
659
660}