diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs | 352 |
1 files changed, 352 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs new file mode 100644 index 0000000..3b0a1ff --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs | |||
@@ -0,0 +1,352 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | /* Original code: Tedd Hansen */ | ||
29 | using System; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Reflection; | ||
33 | using System.Reflection.Emit; | ||
34 | |||
35 | namespace OpenSim.Region.Scripting.LSL | ||
36 | { | ||
37 | partial class LSO_Parser | ||
38 | { | ||
39 | //LSO_Enums MyLSO_Enums = new LSO_Enums(); | ||
40 | |||
41 | internal bool LSL_PROCESS_OPCODE(ILGenerator il) | ||
42 | { | ||
43 | |||
44 | byte bp1; | ||
45 | UInt32 u32p1; | ||
46 | UInt16 opcode = br_read(1)[0]; | ||
47 | Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); | ||
48 | string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); | ||
49 | switch ((LSO_Enums.Operation_Table)opcode) | ||
50 | { | ||
51 | |||
52 | case LSO_Enums.Operation_Table.POP: | ||
53 | case LSO_Enums.Operation_Table.POPL: | ||
54 | case LSO_Enums.Operation_Table.POPV: | ||
55 | case LSO_Enums.Operation_Table.POPQ: | ||
56 | case LSO_Enums.Operation_Table.POPIP: | ||
57 | case LSO_Enums.Operation_Table.POPBP: | ||
58 | case LSO_Enums.Operation_Table.POPSP: | ||
59 | case LSO_Enums.Operation_Table.POPSLR: | ||
60 | // ignore -- builds callframe | ||
61 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);"); | ||
62 | il.Emit(OpCodes.Pop); | ||
63 | break; | ||
64 | case LSO_Enums.Operation_Table.POPARG: | ||
65 | Common.SendToDebug("Instruction " + idesc + ": Ignored"); | ||
66 | Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack "); | ||
67 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
68 | break; | ||
69 | |||
70 | // LONG | ||
71 | case LSO_Enums.Operation_Table.STORE: | ||
72 | case LSO_Enums.Operation_Table.STORES: | ||
73 | case LSO_Enums.Operation_Table.STOREL: | ||
74 | case LSO_Enums.Operation_Table.STOREV: | ||
75 | case LSO_Enums.Operation_Table.STOREQ: | ||
76 | case LSO_Enums.Operation_Table.STOREG: | ||
77 | case LSO_Enums.Operation_Table.STOREGS: | ||
78 | case LSO_Enums.Operation_Table.STOREGL: | ||
79 | case LSO_Enums.Operation_Table.STOREGV: | ||
80 | case LSO_Enums.Operation_Table.STOREGQ: | ||
81 | case LSO_Enums.Operation_Table.LOADP: | ||
82 | case LSO_Enums.Operation_Table.LOADSP: | ||
83 | case LSO_Enums.Operation_Table.LOADLP: | ||
84 | case LSO_Enums.Operation_Table.LOADVP: | ||
85 | case LSO_Enums.Operation_Table.LOADQP: | ||
86 | case LSO_Enums.Operation_Table.PUSH: | ||
87 | case LSO_Enums.Operation_Table.PUSHS: | ||
88 | case LSO_Enums.Operation_Table.PUSHL: | ||
89 | case LSO_Enums.Operation_Table.PUSHV: | ||
90 | case LSO_Enums.Operation_Table.PUSHQ: | ||
91 | case LSO_Enums.Operation_Table.PUSHG: | ||
92 | case LSO_Enums.Operation_Table.PUSHGS: | ||
93 | case LSO_Enums.Operation_Table.PUSHGL: | ||
94 | case LSO_Enums.Operation_Table.PUSHGV: | ||
95 | case LSO_Enums.Operation_Table.PUSHGQ: | ||
96 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
97 | break; | ||
98 | // None | ||
99 | case LSO_Enums.Operation_Table.PUSHIP: | ||
100 | case LSO_Enums.Operation_Table.PUSHBP: | ||
101 | case LSO_Enums.Operation_Table.PUSHSP: | ||
102 | // Push Stack Top (Memory Address) to stack | ||
103 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");"); | ||
104 | Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); | ||
105 | il.Emit(OpCodes.Ldc_I4, myHeader.SP); | ||
106 | break; | ||
107 | // BYTE | ||
108 | case LSO_Enums.Operation_Table.PUSHARGB: | ||
109 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
110 | break; | ||
111 | // INTEGER | ||
112 | case LSO_Enums.Operation_Table.PUSHARGI: | ||
113 | // TODO: What is size of integer? | ||
114 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
115 | Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");"); | ||
116 | Common.SendToDebug("Param1: " + u32p1); | ||
117 | il.Emit(OpCodes.Ldc_I4, u32p1); | ||
118 | break; | ||
119 | // FLOAT | ||
120 | case LSO_Enums.Operation_Table.PUSHARGF: | ||
121 | // TODO: What is size of float? | ||
122 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
123 | break; | ||
124 | // STRING | ||
125 | case LSO_Enums.Operation_Table.PUSHARGS: | ||
126 | string s = Read_String(); | ||
127 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");"); | ||
128 | Common.SendToDebug("Param1: " + s); | ||
129 | il.Emit(OpCodes.Ldstr, s); | ||
130 | break; | ||
131 | // VECTOR z,y,x | ||
132 | case LSO_Enums.Operation_Table.PUSHARGV: | ||
133 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
134 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
135 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
136 | break; | ||
137 | // ROTATION s,z,y,x | ||
138 | case LSO_Enums.Operation_Table.PUSHARGQ: | ||
139 | Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
140 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
141 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
142 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
143 | break; | ||
144 | // LONG | ||
145 | case LSO_Enums.Operation_Table.PUSHARGE: | ||
146 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
147 | //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");"); | ||
148 | Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)"); | ||
149 | //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)"); | ||
150 | Common.SendToDebug("Param1: " + u32p1); | ||
151 | //il.Emit(OpCodes.ldc_i4, u32p1); | ||
152 | //if (u32p1 > 0) { | ||
153 | //for (int _ic=0; _ic < u32p1; _ic++) | ||
154 | //{ | ||
155 | // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);"); | ||
156 | // il.Emit(OpCodes.Ldnull); | ||
157 | //} | ||
158 | break; | ||
159 | // BYTE | ||
160 | case LSO_Enums.Operation_Table.ADD: | ||
161 | bp1 = br_read(1)[0]; | ||
162 | Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString()); | ||
163 | Common.SendToDebug("Param1: " + bp1); | ||
164 | switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1) | ||
165 | { | ||
166 | case LSO_Enums.OpCode_Add_TypeDefs.String: | ||
167 | Common.SendToDebug("Instruction " + idesc | ||
168 | + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));"); | ||
169 | il.Emit(OpCodes.Call, typeof(System.String).GetMethod | ||
170 | ("Concat", new Type[] { typeof(object), typeof(object) })); | ||
171 | |||
172 | break; | ||
173 | case LSO_Enums.OpCode_Add_TypeDefs.UInt32: | ||
174 | default: | ||
175 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);"); | ||
176 | il.Emit(OpCodes.Add); | ||
177 | break; | ||
178 | } | ||
179 | |||
180 | |||
181 | //il.Emit(OpCodes.Add, p1); | ||
182 | break; | ||
183 | case LSO_Enums.Operation_Table.SUB: | ||
184 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);"); | ||
185 | bp1 = br_read(1)[0]; | ||
186 | Common.SendToDebug("Param1: " + bp1); | ||
187 | il.Emit(OpCodes.Sub); | ||
188 | //il.Emit(OpCodes.Sub, p1); | ||
189 | break; | ||
190 | case LSO_Enums.Operation_Table.MUL: | ||
191 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);"); | ||
192 | bp1 = br_read(1)[0]; | ||
193 | Common.SendToDebug("Param1: " + bp1); | ||
194 | il.Emit(OpCodes.Mul); | ||
195 | //il.Emit(OpCodes.Mul, p1); | ||
196 | break; | ||
197 | case LSO_Enums.Operation_Table.DIV: | ||
198 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);"); | ||
199 | bp1 = br_read(1)[0]; | ||
200 | Common.SendToDebug("Param1: " + bp1); | ||
201 | il.Emit(OpCodes.Div); | ||
202 | //il.Emit(OpCodes.Div, p1); | ||
203 | break; | ||
204 | case LSO_Enums.Operation_Table.EQ: | ||
205 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);"); | ||
206 | bp1 = br_read(1)[0]; | ||
207 | Common.SendToDebug("Param1: " + bp1); | ||
208 | il.Emit(OpCodes.Ceq); | ||
209 | //il.Emit(OpCodes.Ceq, p1); | ||
210 | break; | ||
211 | case LSO_Enums.Operation_Table.NEQ: | ||
212 | case LSO_Enums.Operation_Table.LEQ: | ||
213 | case LSO_Enums.Operation_Table.GEQ: | ||
214 | case LSO_Enums.Operation_Table.LESS: | ||
215 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);"); | ||
216 | bp1 = br_read(1)[0]; | ||
217 | Common.SendToDebug("Param1: " + bp1); | ||
218 | il.Emit(OpCodes.Clt_Un); | ||
219 | //il.Emit(OpCodes.Clt, p1); | ||
220 | break; | ||
221 | case LSO_Enums.Operation_Table.GREATER: | ||
222 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);"); | ||
223 | bp1 = br_read(1)[0]; | ||
224 | Common.SendToDebug("Param1: " + bp1); | ||
225 | il.Emit(OpCodes.Cgt_Un); | ||
226 | //il.Emit(OpCodes.Cgt, p1); | ||
227 | break; | ||
228 | case LSO_Enums.Operation_Table.MOD: | ||
229 | case LSO_Enums.Operation_Table.BOOLOR: | ||
230 | bp1 = br_read(1)[0]; | ||
231 | Common.SendToDebug("Param1: " + bp1); | ||
232 | break; | ||
233 | // LONG | ||
234 | case LSO_Enums.Operation_Table.JUMP: | ||
235 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
236 | break; | ||
237 | // BYTE, LONG | ||
238 | case LSO_Enums.Operation_Table.JUMPIF: | ||
239 | case LSO_Enums.Operation_Table.JUMPNIF: | ||
240 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
241 | Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
242 | break; | ||
243 | // LONG | ||
244 | case LSO_Enums.Operation_Table.STATE: | ||
245 | bp1 = br_read(1)[0]; | ||
246 | //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack | ||
247 | //il.Emit(OpCodes.Ldc_I4, 0); // Push index position | ||
248 | //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value | ||
249 | //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | ||
250 | break; | ||
251 | case LSO_Enums.Operation_Table.CALL: | ||
252 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
253 | break; | ||
254 | // BYTE | ||
255 | case LSO_Enums.Operation_Table.CAST: | ||
256 | bp1 = br_read(1)[0]; | ||
257 | Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); | ||
258 | Common.SendToDebug("Param1: " + bp1); | ||
259 | switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) | ||
260 | { | ||
261 | case LSO_Enums.OpCode_Cast_TypeDefs.String: | ||
262 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));"); | ||
263 | //il.Emit(OpCodes.Box, typeof (UInt32)); | ||
264 | il.Emit(OpCodes.Calli, typeof(Common).GetMethod | ||
265 | ("Cast_ToString", new Type[] { typeof(object) })); | ||
266 | |||
267 | //il.Emit(OpCodes.Box, typeof(System.UInt32) ); | ||
268 | //il.Emit(OpCodes.Box, typeof(string)); | ||
269 | |||
270 | //il.Emit(OpCodes.Conv_R8); | ||
271 | //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod | ||
272 | // ("ToString", new Type[] { typeof(float) })); | ||
273 | |||
274 | break; | ||
275 | default: | ||
276 | Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); | ||
277 | break; | ||
278 | } | ||
279 | break; | ||
280 | // LONG | ||
281 | case LSO_Enums.Operation_Table.STACKTOS: | ||
282 | case LSO_Enums.Operation_Table.STACKTOL: | ||
283 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
284 | break; | ||
285 | // BYTE | ||
286 | case LSO_Enums.Operation_Table.PRINT: | ||
287 | case LSO_Enums.Operation_Table.CALLLIB: | ||
288 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
289 | break; | ||
290 | // SHORT | ||
291 | case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: | ||
292 | // TODO: What is size of short? | ||
293 | UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); | ||
294 | Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); | ||
295 | Common.SendToDebug("Param1: " + U16p1); | ||
296 | switch ((LSO_Enums.BuiltIn_Functions)U16p1) | ||
297 | { | ||
298 | case LSO_Enums.BuiltIn_Functions.llSay: | ||
299 | Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() | ||
300 | + ": Mapped to internal function"); | ||
301 | |||
302 | //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\""); | ||
303 | //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString", | ||
304 | // new Type[] { typeof(string), typeof(UInt32), typeof(string) } | ||
305 | //)); | ||
306 | |||
307 | |||
308 | //il.Emit(OpCodes.Pop); | ||
309 | //il.Emit(OpCodes.Call, | ||
310 | // typeof(Console).GetMethod("WriteLine", | ||
311 | // new Type[] { typeof(string) } | ||
312 | //)); | ||
313 | |||
314 | |||
315 | il.Emit(OpCodes.Call, | ||
316 | typeof(Common).GetMethod("SendToLog", | ||
317 | new Type[] { typeof(string) } | ||
318 | )); | ||
319 | |||
320 | |||
321 | |||
322 | //il.Emit(OpCodes.Pop); | ||
323 | |||
324 | //il.Emit(OpCodes.Ldind_I2, 0); | ||
325 | |||
326 | //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) })); | ||
327 | //il.EmitCalli(OpCodes.Calli, | ||
328 | //il.Emit(OpCodes.Call, typeof().GetMethod | ||
329 | // ("llSay", new Type[] { typeof(UInt32), typeof(string) })); | ||
330 | break; | ||
331 | default: | ||
332 | Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED"); | ||
333 | break; | ||
334 | } | ||
335 | |||
336 | //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:"); | ||
337 | //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);"); | ||
338 | //il.Emit(OpCodes.Ldc_I4, 0); | ||
339 | break; | ||
340 | |||
341 | // RETURN | ||
342 | case LSO_Enums.Operation_Table.RETURN: | ||
343 | |||
344 | Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete."); | ||
345 | return true; | ||
346 | break; | ||
347 | } | ||
348 | return false; | ||
349 | } | ||
350 | |||
351 | } | ||
352 | } | ||