1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.nabla.automatic.arithmetic; |
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 | |
import org.objectweb.asm.tree.VarInsnNode; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 1 | public class DRemTransformer12 implements InstructionsTransformer { |
37 | |
|
38 | |
|
39 | 1 | private static class LazyHolder { |
40 | |
|
41 | 1 | private static final InstructionsTransformer INSTANCE = new DRemTransformer12(); |
42 | |
} |
43 | |
|
44 | |
|
45 | |
|
46 | 1 | private DRemTransformer12() { |
47 | 1 | } |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
public static InstructionsTransformer getInstance() { |
54 | 1 | return LazyHolder.INSTANCE; |
55 | |
} |
56 | |
|
57 | |
|
58 | |
public InsnList getReplacement(final AbstractInsnNode insn, |
59 | |
final MethodDifferentiator methodDifferentiator) |
60 | |
throws DifferentiationException { |
61 | |
|
62 | 1 | final int tmp1 = methodDifferentiator.getTmp(1); |
63 | 1 | final int tmp2 = methodDifferentiator.getTmp(2); |
64 | 1 | final int tmp3 = methodDifferentiator.getTmp(3); |
65 | 1 | final int tmp4 = methodDifferentiator.getTmp(4); |
66 | 1 | final InsnList list = new InsnList(); |
67 | |
|
68 | |
|
69 | 1 | list.add(new VarInsnNode(Opcodes.DSTORE, tmp1)); |
70 | 1 | list.add(new VarInsnNode(Opcodes.DSTORE, tmp2)); |
71 | 1 | list.add(new VarInsnNode(Opcodes.DSTORE, tmp3)); |
72 | 1 | list.add(new VarInsnNode(Opcodes.DSTORE, tmp4)); |
73 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp4)); |
74 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp2)); |
75 | 1 | list.add(new InsnNode(Opcodes.DREM)); |
76 | 1 | list.add(new InsnNode(Opcodes.DUP2)); |
77 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp4)); |
78 | 1 | list.add(new InsnNode(Opcodes.DSUB)); |
79 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp2)); |
80 | 1 | list.add(new InsnNode(Opcodes.DDIV)); |
81 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp1)); |
82 | 1 | list.add(new InsnNode(Opcodes.DMUL)); |
83 | 1 | list.add(new VarInsnNode(Opcodes.DLOAD, tmp3)); |
84 | 1 | list.add(new InsnNode(Opcodes.DADD)); |
85 | |
|
86 | 1 | return list; |
87 | |
|
88 | |
} |
89 | |
|
90 | |
} |