IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
EmitIntrinsicContext.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2008-2013 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24
25using IKVM.ByteCode;
26
28using InstructionFlags = IKVM.Runtime.ClassFile.Method.InstructionFlags;
29
30namespace IKVM.Runtime
31{
32
34 {
35
36 internal readonly RuntimeJavaMethod Method;
37 internal readonly RuntimeByteCodeJavaType.FinishContext Context;
38 internal readonly CodeEmitter Emitter;
39 readonly CodeInfo ma;
40 internal readonly int OpcodeIndex;
41 internal readonly RuntimeJavaMethod Caller;
42 internal readonly ClassFile ClassFile;
43 internal readonly Instruction[] Code;
44 internal readonly InstructionFlags[] Flags;
45 internal bool NonLeaf = true;
46
47 internal EmitIntrinsicContext(RuntimeJavaMethod method, RuntimeByteCodeJavaType.FinishContext context, CodeEmitter ilgen, CodeInfo ma, int opcodeIndex, RuntimeJavaMethod caller, ClassFile classFile, Instruction[] code, InstructionFlags[] flags)
48 {
49 this.Method = method;
50 this.Context = context;
51 this.Emitter = ilgen;
52 this.ma = ma;
53 this.OpcodeIndex = opcodeIndex;
54 this.Caller = caller;
55 this.ClassFile = classFile;
56 this.Code = code;
57 this.Flags = flags;
58 }
59
60 internal bool MatchRange(int offset, int length)
61 {
62 if (OpcodeIndex + offset < 0)
63 return false;
64
65 if (OpcodeIndex + offset + length > Code.Length)
66 return false;
67
68 // we check for branches *into* the range, the start of the range may be a branch target
69 for (int i = OpcodeIndex + offset + 1, end = OpcodeIndex + offset + length; i < end; i++)
70 if ((Flags[i] & InstructionFlags.BranchTarget) != 0)
71 return false;
72
73 return true;
74 }
75
76 internal bool Match(int offset, NormalizedByteCode opcode)
77 {
78 return Code[OpcodeIndex + offset].NormalizedOpCode == opcode;
79 }
80
81 internal bool Match(int offset, NormalizedByteCode opcode, int arg)
82 {
83 return Code[OpcodeIndex + offset].NormalizedOpCode == opcode && Code[OpcodeIndex + offset].Arg1 == arg;
84 }
85
86 internal RuntimeJavaType GetStackTypeWrapper(int offset, int pos)
87 {
88 return ma.GetStackTypeWrapper(OpcodeIndex + offset, pos);
89 }
90
91 internal ClassFile.ConstantPoolItemMI GetMethodref(int offset)
92 {
93 return ClassFile.GetMethodref(Code[OpcodeIndex + offset].Arg1);
94 }
95
96 internal ClassFile.ConstantPoolItemFieldref GetFieldref(int offset)
97 {
98 return ClassFile.GetFieldref(Code[OpcodeIndex + offset].Arg1);
99 }
100
101 internal RuntimeJavaType GetClassLiteral(int offset)
102 {
103 return ClassFile.GetConstantPoolClassType(new ClassConstantHandle(checked((ushort)Code[OpcodeIndex + offset].Arg1)));
104 }
105
106 internal string GetStringLiteral(int offset)
107 {
108 return ClassFile.GetConstantPoolConstantString(new StringConstantHandle(checked((ushort)Code[OpcodeIndex + offset].Arg1)));
109 }
110
111 internal ClassFile.ConstantType GetConstantType(int offset)
112 {
113 return ClassFile.GetConstantPoolConstantType(new ConstantHandle(ConstantKind.Unknown, checked((ushort)Code[OpcodeIndex + offset].Arg1)));
114 }
115
116 internal void PatchOpCode(int offset, NormalizedByteCode opc)
117 {
118 Code[OpcodeIndex + offset].PatchOpCode(opc);
119 }
120
121 }
122
123}
IKVM.Runtime.ClassFile.Method.InstructionFlags InstructionFlags
Definition atomic.cs:37
IKVM.Runtime.ClassFile.Method.Instruction Instruction
Definition compiler.cs:44