| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| #include "ppport.h" |
| 5 |
|
| |
| 6 |
|
| #include "hook_op_annotation.h" |
| 7 |
|
| |
| 8 |
|
| #define __PACKAGE__ "B::Hooks::OP::Annotation" |
| 9 |
|
| #include "optable.h" |
| 10 |
|
| |
| 11 |
|
| #define OP_ANNOTATION_INITIAL_SIZE 2 |
| 12 |
|
| #define OP_ANNOTATION_THRESHOLD 0.65 |
| 13 |
|
| |
| 14 |
|
| STATIC void op_annotation_free(pTHX_ OPAnnotation *annotation); |
| 15 |
|
| |
| 16 |
0 |
| void op_annotate(OPAnnotationGroup table, OP * op, void *data, OPAnnotationDtor dtor) { |
| 17 |
0 |
| (void)op_annotation_new(table, op, data, dtor); |
| 18 |
0 |
| } |
| 19 |
|
| |
| 20 |
|
| /* the data and/or destructor can be assigned later */ |
| 21 |
0 |
| OPAnnotation * op_annotation_new(OPAnnotationGroup table, OP * op, void *data, OPAnnotationDtor dtor) { |
| 22 |
|
| OPAnnotation *annotation, *old; |
| 23 |
|
| |
| 24 |
0 |
▶ | if (!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!table) { |
0 |
0 |
0 |
|
| 25 |
0 |
| croak("B::Hooks::OP::Annotation: no annotation group supplied"); |
| 26 |
|
| } |
| 27 |
|
| |
| 28 |
0 |
▶ | if (!op) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!op) { |
0 |
0 |
0 |
|
| 29 |
0 |
| croak("B::Hooks::OP::Annotation: no OP supplied"); |
| 30 |
|
| } |
| 31 |
|
| |
| 32 |
0 |
| Newx(annotation, 1, OPAnnotation); |
| 33 |
|
| |
| 34 |
0 |
▶ | if (!annotation) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!annotation) { |
0 |
0 |
0 |
|
| 35 |
0 |
| croak("B::Hooks::OP::Annotation: can't allocate annotation"); |
| 36 |
|
| } |
| 37 |
|
| |
| 38 |
0 |
| annotation->data = data; |
| 39 |
0 |
| annotation->dtor = dtor; |
| 40 |
0 |
| annotation->op_ppaddr = op->op_ppaddr; |
| 41 |
|
| |
| 42 |
0 |
| old = OPTable_store(table, op, annotation); |
| 43 |
|
| |
| 44 |
0 |
▶ | if (old) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (old) { |
0 |
0 |
0 |
|
| 45 |
0 |
| op_annotation_free(aTHX_ old); |
| 46 |
|
| } |
| 47 |
|
| |
| 48 |
0 |
| return annotation; |
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| /* get the annotation for the current OP from the hash table */ |
| 52 |
0 |
| OPAnnotation *op_annotation_get(OPAnnotationGroup table, OP *op) { |
| 53 |
|
| OPAnnotation *annotation; |
| 54 |
|
| |
| 55 |
0 |
▶ | if (!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!table) { |
0 |
0 |
0 |
|
| 56 |
0 |
| croak("B::Hooks::OP::Annotation: no annotation group supplied"); |
| 57 |
|
| } |
| 58 |
|
| |
| 59 |
0 |
▶ | if (!op) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!op) { |
0 |
0 |
0 |
|
| 60 |
0 |
| croak("B::Hooks::OP::Annotation: no OP supplied"); |
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
0 |
| annotation = OPTable_fetch(table, op); |
| 64 |
|
| |
| 65 |
0 |
▶ | if (!annotation) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!annotation) { |
0 |
0 |
0 |
|
| 66 |
0 |
| croak("can't retrieve annotation: OP not found"); |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
0 |
| return annotation; |
| 70 |
|
| } |
| 71 |
|
| |
| 72 |
0 |
| void op_annotation_delete(pTHX_ OPAnnotationGroup table, OP *op) { |
| 73 |
|
| OPAnnotation *annotation; |
| 74 |
|
| |
| 75 |
0 |
▶ | if (!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!table) { |
0 |
0 |
0 |
|
| 76 |
0 |
| croak("B::Hooks::OP::Annotation: no annotation group supplied"); |
| 77 |
|
| } |
| 78 |
|
| |
| 79 |
0 |
| annotation = OPTable_delete(table, op); |
| 80 |
|
| |
| 81 |
0 |
▶ | if (!annotation) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!annotation) { |
0 |
0 |
0 |
|
| 82 |
0 |
| croak("B::Hooks::OP::Annotation: can't delete annotation: OP not found"); |
| 83 |
|
| } |
| 84 |
|
| |
| 85 |
0 |
| op_annotation_free(aTHX_ annotation); |
| 86 |
0 |
| } |
| 87 |
|
| |
| 88 |
0 |
| STATIC void op_annotation_free(pTHX_ OPAnnotation *annotation) { |
| 89 |
0 |
▶ | if (!annotation) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!annotation) { |
0 |
0 |
0 |
|
| 90 |
0 |
| croak("B::Hooks::OP::Annotation: no annotation supplied"); |
| 91 |
|
| } |
| 92 |
|
| |
| 93 |
0 |
▶ | if (annotation->data && annotation->dtor) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (annotation->data && annotation->dtor) { |
0 |
0 |
0 |
| if (annotation->data && annotation->dtor) { |
0 |
0 |
0 |
|
| 94 |
0 |
| annotation->dtor(aTHX_ annotation->data); |
| 95 |
|
| } |
| 96 |
|
| |
| 97 |
0 |
| Safefree(annotation); |
| 98 |
0 |
| } |
| 99 |
|
| |
| 100 |
0 |
| OPAnnotationGroup op_annotation_group_new() { |
| 101 |
|
| OPAnnotationGroup table; |
| 102 |
|
| |
| 103 |
0 |
| table = OPTable_new(OP_ANNOTATION_INITIAL_SIZE, OP_ANNOTATION_THRESHOLD); |
| 104 |
|
| |
| 105 |
0 |
▶ | if (!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!table) { |
0 |
0 |
0 |
|
| 106 |
0 |
| croak("B::Hooks::OP::Annotation: can't allocate annotation group"); |
| 107 |
|
| } |
| 108 |
|
| |
| 109 |
0 |
| return table; |
| 110 |
|
| } |
| 111 |
|
| |
| 112 |
0 |
| void op_annotation_group_free(pTHX_ OPAnnotationGroup table) { |
| 113 |
0 |
▶ | if (!table) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!table) { |
0 |
0 |
0 |
|
| 114 |
0 |
| croak("B::Hooks::OP::Annotation: no annotation group supplied"); |
| 115 |
|
| } |
| 116 |
|
| |
| 117 |
0 |
| OPTable_clear(aTHX_ table, op_annotation_free); |
| 118 |
0 |
| OPTable_free(table); |
| 119 |
0 |
| } |
| 120 |
|
| |
| 121 |
|
| MODULE = B::Hooks::OP::Annotation PACKAGE = B::Hooks::OP::Annotation |
| 122 |
|
| |
| 123 |
|
| PROTOTYPES: DISABLE |