@@ -13,6 +13,10 @@ class QAST::Operations {
13
13
my % hll_box ;
14
14
my % hll_unbox ;
15
15
16
+ # What we know about inlinability.
17
+ my % core_inlinability ;
18
+ my % hll_inlinability ;
19
+
16
20
# Compiles an operation to POST.
17
21
method compile_op ($ qastcomp , $ hll , $ op ) {
18
22
my $ name := $ op . op;
@@ -27,6 +31,7 @@ class QAST::Operations {
27
31
pir::die(" No registered operation handler for '$ name '" );
28
32
}
29
33
34
+ # Compiles a PIR operation.
30
35
method compile_pirop ($ qastcomp , $ op_name , @ op_args ) {
31
36
if nqp :: index ($ op_name , ' ' ) {
32
37
$ op_name := nqp :: join (' __' , nqp :: split (' ' , $ op_name ));
@@ -39,31 +44,57 @@ class QAST::Operations {
39
44
}
40
45
41
46
# Adds a core op handler.
42
- method add_core_op ($ op , $ handler , : $ inlinable ) {
47
+ method add_core_op ($ op , $ handler , : $ inlinable = 0 ) {
43
48
% core_ops {$ op } := $ handler ;
49
+ self . set_core_op_inlinability($ op , $ inlinable );
44
50
}
45
51
46
52
# Adds a HLL op handler.
47
- method add_hll_op ($ hll , $ op , $ handler , : $ inlinable ) {
53
+ method add_hll_op ($ hll , $ op , $ handler , : $ inlinable = 0 ) {
48
54
% hll_ops {$ hll } := {} unless % hll_ops {$ hll };
49
55
% hll_ops {$ hll }{$ op } := $ handler ;
56
+ self . set_hll_op_inlinability($ hll , $ op , $ inlinable );
50
57
}
51
58
52
59
# Adds a core op that maps to a PIR op.
53
- method add_core_pirop_mapping ($ op , $ pirop , $ sig , : $ inlinable ) {
60
+ method add_core_pirop_mapping ($ op , $ pirop , $ sig , : $ inlinable = 0 ) {
54
61
my $ pirop_mapper := pirop_mapper($ pirop , $ sig );
55
62
% core_ops {$ op } := -> $ qastcomp , $ op {
56
63
$ pirop_mapper ($ qastcomp , $ op . op, $ op . list)
57
64
};
65
+ self . set_core_op_inlinability($ op , $ inlinable );
58
66
}
59
67
60
68
# Adds a HLL op that maps to a PIR op.
61
- method add_hll_pirop_mapping ($ hll , $ op , $ pirop , $ sig , : $ inlinable ) {
69
+ method add_hll_pirop_mapping ($ hll , $ op , $ pirop , $ sig , : $ inlinable = 0 ) {
62
70
my $ pirop_mapper := pirop_mapper($ pirop , $ sig );
63
71
% hll_ops {$ hll } := {} unless % hll_ops {$ hll };
64
72
% hll_ops {$ hll }{$ op } := -> $ qastcomp , $ op {
65
73
$ pirop_mapper ($ qastcomp , $ op . op, $ op . list)
66
74
};
75
+ self . set_hll_op_inlinability($ hll , $ op , $ inlinable );
76
+ }
77
+
78
+ # Sets op inlinability at a core level.
79
+ method set_core_op_inlinability ($ op , $ inlinable ) {
80
+ % core_inlinability {$ op } := $ inlinable ;
81
+ }
82
+
83
+ # Sets op inlinability at a HLL level. (Can override at HLL level whether
84
+ # or not the HLL overrides the op itself.)
85
+ method set_hll_op_inlinability ($ hll , $ op , $ inlinable ) {
86
+ % hll_inlinability {$ hll } := {} unless % hll_inlinability {$ hll };
87
+ % hll_inlinability {$ hll }{$ op } := $ inlinable ;
88
+ }
89
+
90
+ # Checks if an op is consdiered inlinable.
91
+ method is_inlinable ($ hll , $ op ) {
92
+ if nqp ::existskey(% hll_inlinability , $ hll ) {
93
+ if nqp ::existskey(% hll_inlinability {$ hll }, $ op ) {
94
+ return % hll_inlinability {$ hll }{$ op };
95
+ }
96
+ }
97
+ return % core_inlinability {$ op } // 0 ;
67
98
}
68
99
69
100
# Adds a HLL box handler.
0 commit comments