Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WideningTransformer |
|
| 1.0;1 | ||||
WideningTransformer$1 |
|
| 1.0;1 | ||||
WideningTransformer$LazyHolder |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.nabla.automatic.instructions; | |
18 | ||
19 | import org.apache.commons.nabla.automatic.analysis.InstructionsTransformer; | |
20 | import org.apache.commons.nabla.automatic.analysis.MethodDifferentiator; | |
21 | import org.apache.commons.nabla.core.DifferentiationException; | |
22 | import org.objectweb.asm.Opcodes; | |
23 | import org.objectweb.asm.tree.AbstractInsnNode; | |
24 | import org.objectweb.asm.tree.InsnList; | |
25 | import org.objectweb.asm.tree.InsnNode; | |
26 | ||
27 | /** Differentiation transformer for promoting a double on the stack | |
28 | * to a differential pair. | |
29 | * <p>Some instructions pushing a double on the stack simply need to | |
30 | * be completed by pushing a 0 afterwards to form a differential pair | |
31 | * representing a constant value. These instructions are replaced by | |
32 | * a copy of themselves followed by a DCONST_0 instruction.</p> | |
33 | */ | |
34 | 1 | public class WideningTransformer implements InstructionsTransformer { |
35 | ||
36 | /** Holder for the singleton instance.*/ | |
37 | 2 | private static class LazyHolder { |
38 | /** The singleton instance. */ | |
39 | 1 | private static final InstructionsTransformer INSTANCE = new WideningTransformer(); |
40 | } | |
41 | ||
42 | /** Hidden constructor. | |
43 | */ | |
44 | 1 | private WideningTransformer() { |
45 | 1 | } |
46 | ||
47 | /** Get the singleton instance. | |
48 | * <p>We use here the Initialization on Demand Holder idiom.</p> | |
49 | * @return the singleton instance | |
50 | */ | |
51 | public static InstructionsTransformer getInstance() { | |
52 | 2 | return LazyHolder.INSTANCE; |
53 | } | |
54 | ||
55 | /** {@inheritDoc} */ | |
56 | public InsnList getReplacement(final AbstractInsnNode insn, | |
57 | final MethodDifferentiator methodDifferentiator) | |
58 | throws DifferentiationException { | |
59 | 2 | final InsnList list = new InsnList(); |
60 | 2 | list.add(methodDifferentiator.clone(insn)); |
61 | 2 | list.add(new InsnNode(Opcodes.DCONST_0)); |
62 | 2 | return list; |
63 | } | |
64 | ||
65 | } |