2003-02-04 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ILGenerator.cs
1
2 //
3 // System.Reflection.Emit/ILGenerator.cs
4 //
5 // Author:
6 //   Paolo Molaro (lupus@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
11 using System;
12 using System.Collections;
13 using System.Diagnostics.SymbolStore;
14 using System.Runtime.InteropServices;
15
16 namespace System.Reflection.Emit {
17
18         internal struct ILExceptionBlock {
19                 public const int CATCH = 0;
20                 public const int FILTER = 1;
21                 public const int FINALLY = 2;
22                 public const int FAULT = 4;
23
24                 internal Type extype;
25                 internal int type;
26                 internal int start;
27                 internal int len;
28                 internal int filter_offset;
29                 
30                 internal void Debug () {
31 #if NO
32                         System.Console.Write ("\ttype="+type.ToString()+" start="+start.ToString()+" len="+len.ToString());
33                         if (extype != null)
34                                 System.Console.WriteLine (" extype="+extype.ToString());
35                         else
36                                 System.Console.WriteLine ("");
37 #endif
38                 }
39         }
40         internal struct ILExceptionInfo {
41                 ILExceptionBlock[] handlers;
42                 internal int start;
43                 int len;
44                 internal Label end;
45
46                 internal int NumHandlers () {
47                         return handlers.Length;
48                 }
49                 
50                 internal void AddCatch (Type extype, int offset) {
51                         int i;
52                         End (offset);
53                         add_block (offset);
54                         i = handlers.Length - 1;
55                         handlers [i].type = ILExceptionBlock.CATCH;
56                         handlers [i].start = offset;
57                         handlers [i].extype = extype;
58                 }
59
60                 internal void AddFinally (int offset) {
61                         int i;
62                         End (offset);
63                         add_block (offset);
64                         i = handlers.Length - 1;
65                         handlers [i].type = ILExceptionBlock.FINALLY;
66                         handlers [i].start = offset;
67                         handlers [i].extype = null;
68                 }
69
70                 internal void End (int offset) {
71                         if (handlers == null)
72                                 return;
73                         int i = handlers.Length - 1;
74                         if (i >= 0)
75                                 handlers [i].len = offset - handlers [i].start;
76                 }
77
78                 internal int LastClauseType () {
79                         if (handlers != null)
80                                 return handlers [handlers.Length-1].type;
81                         else
82                                 return ILExceptionBlock.CATCH;
83                 }
84
85                 internal void Debug (int b) {
86 #if NO
87                         System.Console.WriteLine ("Handler {0} at {1}, len: {2}", b, start, len);
88                         for (int i = 0; i < handlers.Length; ++i)
89                                 handlers [i].Debug ();
90 #endif
91                 }
92
93                 void add_block (int offset) {
94                         if (handlers != null) {
95                                 int i = handlers.Length;
96                                 ILExceptionBlock[] new_b = new ILExceptionBlock [i + 1];
97                                 System.Array.Copy (handlers, new_b, i);
98                                 handlers = new_b;
99                                 handlers [i].len = offset - handlers [i].start;
100                         } else {
101                                 handlers = new ILExceptionBlock [1];
102                                 len = offset - start;
103                         }
104                 }
105         }
106         
107         internal struct ILTokenInfo {
108                 public MemberInfo member;
109                 public int code_pos;
110         }
111
112         public class ILGenerator: Object {
113                 private struct LabelFixup {
114                         public int size;
115                         public int pos;                 // the location of the fixup
116                         public int label_base;  // the base address for this fixup
117                         public int label_idx;
118                 };
119                 static Type void_type = typeof (void);
120                 private byte[] code;
121                 private MethodBase mbuilder; /* a MethodBuilder or ConstructorBuilder */
122                 private int code_len;
123                 private int max_stack;
124                 private int cur_stack;
125                 private LocalBuilder[] locals;
126                 private ILExceptionInfo[] ex_handlers;
127                 private int num_token_fixups;
128                 private ILTokenInfo[] token_fixups;
129                 private int[] label_to_addr;
130                 private int num_labels;
131                 private LabelFixup[] fixups;
132                 private int num_fixups;
133                 private ModuleBuilder module;
134                 private AssemblyBuilder abuilder;
135                 private ISymbolWriter sym_writer;
136                 private Stack scopes;
137                 private int cur_block;
138                 private Stack open_blocks;
139
140                 internal ILGenerator (MethodBase mb, int size) {
141                         if (size < 0)
142                                 size = 128;
143                         code_len = 0;
144                         code = new byte [size];
145                         mbuilder = mb;
146                         cur_stack = max_stack = 0;
147                         num_fixups = num_labels = 0;
148                         label_to_addr = new int [8];
149                         fixups = new LabelFixup [8];
150                         token_fixups = new ILTokenInfo [8];
151                         num_token_fixups = 0;
152                         if (mb is MethodBuilder) {
153                                 module = (ModuleBuilder)((MethodBuilder)mb).TypeBuilder.Module;
154                         } else if (mb is ConstructorBuilder) {
155                                 module = (ModuleBuilder)((ConstructorBuilder)mb).TypeBuilder.Module;
156                         }
157                         abuilder = (AssemblyBuilder)module.Assembly;
158                         sym_writer = module.GetSymWriter ();
159                         open_blocks = new Stack ();
160                 }
161
162                 private void add_token_fixup (MemberInfo mi) {
163                         if (num_token_fixups == token_fixups.Length) {
164                                 ILTokenInfo[] ntf = new ILTokenInfo [num_token_fixups * 2];
165                                 token_fixups.CopyTo (ntf, 0);
166                                 token_fixups = ntf;
167                         }
168                         token_fixups [num_token_fixups].member = mi;
169                         token_fixups [num_token_fixups++].code_pos = code_len;
170                 }
171
172                 private void make_room (int nbytes) {
173                         if (code_len + nbytes < code.Length)
174                                 return;
175                         byte[] new_code = new byte [(code_len + nbytes) * 2 + 128];
176                         System.Array.Copy (code, 0, new_code, 0, code.Length);
177                         code = new_code;
178                 }
179                 private void emit_int (int val) {
180                         code [code_len++] = (byte) (val & 0xFF);
181                         code [code_len++] = (byte) ((val >> 8) & 0xFF);
182                         code [code_len++] = (byte) ((val >> 16) & 0xFF);
183                         code [code_len++] = (byte) ((val >> 24) & 0xFF);
184                 }
185                 /* change to pass by ref to avoid copy */
186                 private void ll_emit (OpCode opcode) {
187                         /* 
188                          * there is already enough room allocated in code.
189                          */
190                         // access op1 and op2 directly since the Value property is useless
191                         if (opcode.Size == 2)
192                                 code [code_len++] = opcode.op1;
193                         code [code_len++] = opcode.op2;
194                         /*
195                          * We should probably keep track of stack needs here.
196                          * Or we may want to run the verifier on the code before saving it
197                          * (this may be needed anyway when the ILGenerator is not used...).
198                          */
199                         switch (opcode.StackBehaviourPush) {
200                         case StackBehaviour.Push1:
201                         case StackBehaviour.Pushi:
202                         case StackBehaviour.Pushi8:
203                         case StackBehaviour.Pushr4:
204                         case StackBehaviour.Pushr8:
205                         case StackBehaviour.Pushref:
206                         case StackBehaviour.Varpush: /* again we are conservative and assume it pushes 1 */
207                                 cur_stack ++;
208                                 break;
209                         case StackBehaviour.Push1_push1:
210                                 cur_stack += 2;
211                                 break;
212                         }
213                         if (max_stack < cur_stack)
214                                 max_stack = cur_stack;
215                         /* 
216                          * Note that we adjust for the pop behaviour _after_ setting max_stack.
217                          */
218                         switch (opcode.StackBehaviourPop) {
219                         case StackBehaviour.Varpop:
220                                 break; /* we are conservative and assume it doesn't decrease the stack needs */
221                         case StackBehaviour.Pop1:
222                         case StackBehaviour.Popi:
223                         case StackBehaviour.Popref:
224                                 cur_stack --;
225                                 break;
226                         case StackBehaviour.Pop1_pop1:
227                         case StackBehaviour.Popi_pop1:
228                         case StackBehaviour.Popi_popi:
229                         case StackBehaviour.Popi_popi8:
230                         case StackBehaviour.Popi_popr4:
231                         case StackBehaviour.Popi_popr8:
232                         case StackBehaviour.Popref_pop1:
233                         case StackBehaviour.Popref_popi:
234                                 cur_stack -= 2;
235                                 break;
236                         case StackBehaviour.Popi_popi_popi:
237                         case StackBehaviour.Popref_popi_popi:
238                         case StackBehaviour.Popref_popi_popi8:
239                         case StackBehaviour.Popref_popi_popr4:
240                         case StackBehaviour.Popref_popi_popr8:
241                         case StackBehaviour.Popref_popi_popref:
242                                 cur_stack -= 3;
243                                 break;
244                         }
245                 }
246
247                 private static int target_len (OpCode opcode) {
248                         if (opcode.operandType == OperandType.InlineBrTarget)
249                                 return 4;
250                         return 1;
251                 }
252
253                 private void InternalEndClause () {
254                         switch (ex_handlers [cur_block].LastClauseType ()) {
255                         case ILExceptionBlock.CATCH:
256                                 // how could we optimize code size here?
257                                 Emit (OpCodes.Leave, ex_handlers [cur_block].end);
258                                 break;
259                         case ILExceptionBlock.FAULT:
260                         case ILExceptionBlock.FINALLY:
261                                 Emit (OpCodes.Endfinally);
262                                 break;
263                         case ILExceptionBlock.FILTER:
264                                 Emit (OpCodes.Endfilter);
265                                 break;
266                         }
267                 }
268
269                 public virtual void BeginCatchBlock (Type exceptionType) {
270                         if (open_blocks.Count <= 0)
271                                 throw new NotSupportedException ("Not in an exception block");
272                         InternalEndClause ();
273                         ex_handlers [cur_block].AddCatch (exceptionType, code_len);
274                         cur_stack = 1; // the exception object is on the stack by default
275                         if (max_stack < cur_stack)
276                                 max_stack = cur_stack;
277                         //System.Console.WriteLine ("Begin catch Block: {0} {1}",exceptionType.ToString(), max_stack);
278                         //throw new NotImplementedException ();
279                 }
280                 public virtual void BeginExceptFilterBlock () {
281                         throw new NotImplementedException ();
282                 }
283                 public virtual Label BeginExceptionBlock () {
284                         //System.Console.WriteLine ("Begin Block");
285                         
286                         if (ex_handlers != null) {
287                                 cur_block = ex_handlers.Length;
288                                 ILExceptionInfo[] new_ex = new ILExceptionInfo [cur_block + 1];
289                                 System.Array.Copy (ex_handlers, new_ex, cur_block);
290                                 ex_handlers = new_ex;
291                         } else {
292                                 ex_handlers = new ILExceptionInfo [1];
293                                 cur_block = 0;
294                         }
295                         open_blocks.Push (cur_block);
296                         ex_handlers [cur_block].start = code_len;
297                         return ex_handlers [cur_block].end = DefineLabel ();
298                 }
299                 public virtual void BeginFaultBlock() {
300                         if (open_blocks.Count <= 0)
301                                 throw new NotSupportedException ("Not in an exception block");
302                         //System.Console.WriteLine ("Begin fault Block");
303                         //throw new NotImplementedException ();
304                 }
305                 public virtual void BeginFinallyBlock() {
306                         if (open_blocks.Count <= 0)
307                                 throw new NotSupportedException ("Not in an exception block");
308                         InternalEndClause ();
309                         //System.Console.WriteLine ("Begin finally Block");
310                         ex_handlers [cur_block].AddFinally (code_len);
311                 }
312                 public virtual void BeginScope () {
313                         if (sym_writer != null) {
314                                 if (scopes == null)
315                                         scopes = new Stack ();
316                                 scopes.Push (sym_writer.OpenScope (code_len));
317                         }
318                 }
319                 public LocalBuilder DeclareLocal (Type localType) {
320                         LocalBuilder res = new LocalBuilder (module, localType, this);
321                         if (locals != null) {
322                                 LocalBuilder[] new_l = new LocalBuilder [locals.Length + 1];
323                                 System.Array.Copy (locals, new_l, locals.Length);
324                                 new_l [locals.Length] = res;
325                                 locals = new_l;
326                         } else {
327                                 locals = new LocalBuilder [1];
328                                 locals [0] = res;
329                         }
330                         res.position = (uint)(locals.Length - 1);
331                         return res;
332                 }
333                 public virtual Label DefineLabel () {
334                         if (num_labels >= label_to_addr.Length) {
335                                 int[] new_l = new int [label_to_addr.Length * 2];
336                                 System.Array.Copy (label_to_addr, new_l, label_to_addr.Length);
337                                 label_to_addr = new_l;
338                         }
339                         label_to_addr [num_labels] = -1;
340                         return new Label (num_labels++);
341                 }
342                 public virtual void Emit (OpCode opcode) {
343                         make_room (2);
344                         ll_emit (opcode);
345                 }
346                 public virtual void Emit (OpCode opcode, Byte val) {
347                         make_room (3);
348                         ll_emit (opcode);
349                         code [code_len++] = val;
350                 }
351                 public virtual void Emit (OpCode opcode, ConstructorInfo constructor) {
352                         int token = abuilder.GetToken (constructor);
353                         make_room (6);
354                         ll_emit (opcode);
355                         if (constructor is ConstructorBuilder)
356                                 add_token_fixup (constructor);
357                         emit_int (token);
358                         ParameterInfo[] mparams = constructor.GetParameters();
359                         if (mparams != null)
360                                 cur_stack -= mparams.Length;
361                 }
362                 public virtual void Emit (OpCode opcode, double val) {
363                         byte[] s = System.BitConverter.GetBytes (val);
364                         make_room (10);
365                         ll_emit (opcode);
366                         if (BitConverter.IsLittleEndian){
367                                 System.Array.Copy (s, 0, code, code_len, 8);
368                                 code_len += 8;
369                         } else {
370                                 code [code_len++] = s [7];
371                                 code [code_len++] = s [6];
372                                 code [code_len++] = s [5];
373                                 code [code_len++] = s [4];
374                                 code [code_len++] = s [3];
375                                 code [code_len++] = s [2];
376                                 code [code_len++] = s [1];
377                                 code [code_len++] = s [0];                              
378                         }
379                 }
380                 public virtual void Emit (OpCode opcode, FieldInfo field) {
381                         int token = abuilder.GetToken (field);
382                         make_room (6);
383                         ll_emit (opcode);
384                         if (field is FieldBuilder)
385                                 add_token_fixup (field);
386                         emit_int (token);
387                 }
388                 public virtual void Emit (OpCode opcode, Int16 val) {
389                         make_room (4);
390                         ll_emit (opcode);
391                         code [code_len++] = (byte) (val & 0xFF);
392                         code [code_len++] = (byte) ((val >> 8) & 0xFF);
393                 }
394                 public virtual void Emit (OpCode opcode, int val) {
395                         make_room (6);
396                         ll_emit (opcode);
397                         emit_int (val);
398                 }
399                 public virtual void Emit (OpCode opcode, long val) {
400                         make_room (10);
401                         ll_emit (opcode);
402                         code [code_len++] = (byte) (val & 0xFF);
403                         code [code_len++] = (byte) ((val >> 8) & 0xFF);
404                         code [code_len++] = (byte) ((val >> 16) & 0xFF);
405                         code [code_len++] = (byte) ((val >> 24) & 0xFF);
406                         code [code_len++] = (byte) ((val >> 32) & 0xFF);
407                         code [code_len++] = (byte) ((val >> 40) & 0xFF);
408                         code [code_len++] = (byte) ((val >> 48) & 0xFF);
409                         code [code_len++] = (byte) ((val >> 56) & 0xFF);
410                 }
411                 public virtual void Emit (OpCode opcode, Label label) {
412                         int tlen = target_len (opcode);
413                         make_room (6);
414                         ll_emit (opcode);
415                         if (num_fixups >= fixups.Length) {
416                                 LabelFixup[] newf = new LabelFixup [fixups.Length + 16];
417                                 System.Array.Copy (fixups, newf, fixups.Length);
418                                 fixups = newf;
419                         }
420                         fixups [num_fixups].size = tlen;
421                         fixups [num_fixups].pos = code_len;
422                         fixups [num_fixups].label_base = code_len;
423                         fixups [num_fixups].label_idx = label.label;
424                         num_fixups++;
425                         code_len += tlen;
426
427                 }
428                 public virtual void Emit (OpCode opcode, Label[] labels) {
429                         /* opcode needs to be switch. */
430                         int count = labels.Length;
431                         make_room (6 + count * 4);
432                         ll_emit (opcode);
433                         int switch_base = code_len + count*4;
434                         emit_int (count);
435                         if (num_fixups + count >= fixups.Length) {
436                                 LabelFixup[] newf = new LabelFixup [fixups.Length + count + 16];
437                                 System.Array.Copy (fixups, newf, fixups.Length);
438                                 fixups = newf;
439                         }
440                         for (int i = 0; i < count; ++i) {
441                                 fixups [num_fixups].size = 4;
442                                 fixups [num_fixups].pos = code_len;
443                                 fixups [num_fixups].label_base = switch_base;
444                                 fixups [num_fixups].label_idx = labels [i].label;
445                                 num_fixups++;
446                                 code_len += 4;
447                         }
448                 }
449                 public virtual void Emit (OpCode opcode, LocalBuilder lbuilder) {
450                         uint pos = lbuilder.position;
451                         bool load_addr = false;
452                         bool is_store = false;
453                         make_room (6);
454
455                         if (lbuilder.ilgen != this)
456                                 throw new Exception ("Trying to emit a local from a different ILGenerator.");
457
458                         /* inline the code from ll_emit () to optimize il code size */
459                         if (opcode.StackBehaviourPop == StackBehaviour.Pop1) {
460                                 cur_stack --;
461                                 is_store = true;
462                         } else {
463                                 cur_stack++;
464                                 if (cur_stack > max_stack)
465                                         max_stack = cur_stack;
466                                 load_addr = opcode.StackBehaviourPush == StackBehaviour.Pushi;
467                         }
468                         if (load_addr) {
469                                 if (pos < 256) {
470                                         code [code_len++] = (byte)0x12;
471                                         code [code_len++] = (byte)pos;
472                                 } else {
473                                         code [code_len++] = (byte)0xfe;
474                                         code [code_len++] = (byte)0x0d;
475                                         code [code_len++] = (byte)(pos & 0xff);
476                                         code [code_len++] = (byte)((pos >> 8) & 0xff);
477                                 }
478                         } else {
479                                 if (is_store) {
480                                         if (pos < 4) {
481                                                 code [code_len++] = (byte)(0x0a + pos);
482                                         } else if (pos < 256) {
483                                                 code [code_len++] = (byte)0x13;
484                                                 code [code_len++] = (byte)pos;
485                                         } else {
486                                                 code [code_len++] = (byte)0xfe;
487                                                 code [code_len++] = (byte)0x0e;
488                                                 code [code_len++] = (byte)(pos & 0xff);
489                                                 code [code_len++] = (byte)((pos >> 8) & 0xff);
490                                         }
491                                 } else {
492                                         if (pos < 4) {
493                                                 code [code_len++] = (byte)(0x06 + pos);
494                                         } else if (pos < 256) {
495                                                 code [code_len++] = (byte)0x11;
496                                                 code [code_len++] = (byte)pos;
497                                         } else {
498                                                 code [code_len++] = (byte)0xfe;
499                                                 code [code_len++] = (byte)0x0c;
500                                                 code [code_len++] = (byte)(pos & 0xff);
501                                                 code [code_len++] = (byte)((pos >> 8) & 0xff);
502                                         }
503                                 }
504                         }
505                 }
506                 public virtual void Emit (OpCode opcode, MethodInfo method) {
507                         if (method == null)
508                                 throw new ArgumentNullException ("method");
509
510                         int token = abuilder.GetToken (method);
511                         make_room (6);
512                         ll_emit (opcode);
513                         if (method is MethodBuilder)
514                                 add_token_fixup (method);
515                         emit_int (token);
516                         if (method.ReturnType != void_type)
517                                 cur_stack ++;
518                         ParameterInfo[] mparams = method.GetParameters();
519                         if (mparams != null)
520                                 cur_stack -= mparams.Length;
521                 }
522                 [CLSCompliant(false)]
523                 public void Emit (OpCode opcode, sbyte val) {
524                         make_room (3);
525                         ll_emit (opcode);
526                         code [code_len++] = (byte)val;
527                 }
528
529                 public virtual void Emit (OpCode opcode, SignatureHelper shelper) {
530                         int token = abuilder.GetToken (shelper);
531                         make_room (6);
532                         ll_emit (opcode);
533                         emit_int (token);
534                 }
535                 public virtual void Emit (OpCode opcode, float val) {
536                         byte[] s = System.BitConverter.GetBytes (val);
537                         make_room (6);
538                         ll_emit (opcode);
539                         if (BitConverter.IsLittleEndian){
540                                 System.Array.Copy (s, 0, code, code_len, 4);
541                                 code_len += 4;
542                         } else {
543                                 code [code_len++] = s [3];
544                                 code [code_len++] = s [2];
545                                 code [code_len++] = s [1];
546                                 code [code_len++] = s [0];                              
547                         }
548                 }
549                 public virtual void Emit (OpCode opcode, string val) {
550                         int token = abuilder.GetToken (val);
551                         make_room (6);
552                         ll_emit (opcode);
553                         emit_int (token);
554                 }
555                 public virtual void Emit (OpCode opcode, Type type) {
556                         make_room (6);
557                         ll_emit (opcode);
558                         if (type is TypeBuilder)
559                                 add_token_fixup (type);
560                         emit_int (abuilder.GetToken (type));
561                 }
562
563                 public void EmitCall (OpCode opcode, MethodInfo methodinfo, Type[] optionalParamTypes) {
564                         throw new NotImplementedException ();
565                 }
566
567                 public void EmitCalli (OpCode opcode, CallingConvention unmanagedCallConv, Type returnType, Type[] paramTypes) {
568                         SignatureHelper helper 
569                                 = SignatureHelper.GetMethodSigHelper (module, 0, unmanagedCallConv, returnType, paramTypes);
570                         Emit (opcode, helper);
571                 }
572
573                 public void EmitCalli (OpCode opcode, CallingConventions callConv, Type returnType, Type[] paramTypes, Type[] optionalParamTypes) {
574                         if (optionalParamTypes != null)
575                                 throw new NotImplementedException ();
576
577                         SignatureHelper helper 
578                                 = SignatureHelper.GetMethodSigHelper (module, callConv, 0, returnType, paramTypes);
579                         Emit (opcode, helper);
580                 }
581                 
582                 public virtual void EmitWriteLine (FieldInfo field) {
583                         throw new NotImplementedException ();
584                 }
585                 public virtual void EmitWriteLine (LocalBuilder lbuilder) {
586                         throw new NotImplementedException ();
587                 }
588                 public virtual void EmitWriteLine (string val) {
589                         Emit (OpCodes.Ldstr, val);
590                         Emit (OpCodes.Call, 
591                                   typeof (Console).GetMethod ("WriteLine",
592                                                                                           new Type[1] { typeof(string)}));
593                 }
594
595                 public virtual void EndExceptionBlock () {
596                         if (open_blocks.Count <= 0)
597                                 throw new NotSupportedException ("Not in an exception block");
598                         InternalEndClause ();
599                         MarkLabel (ex_handlers [cur_block].end);
600                         ex_handlers [cur_block].End (code_len);
601                         ex_handlers [cur_block].Debug (cur_block);
602                         //System.Console.WriteLine ("End Block {0} (handlers: {1})", cur_block, ex_handlers [cur_block].NumHandlers ());
603                         open_blocks.Pop ();
604                         if (open_blocks.Count > 0)
605                                 cur_block = (int)open_blocks.Peek ();
606                         //Console.WriteLine ("curblock restored to {0}", cur_block);
607                         //throw new NotImplementedException ();
608                 }
609                 public virtual void EndScope () {
610                         if (sym_writer != null) {
611                                 sym_writer.CloseScope (code_len);
612                                 if (scopes == null)
613                                         throw new InvalidOperationException ();
614                                 scopes.Pop ();
615                         }
616                 }
617                 public virtual void MarkLabel (Label loc) {
618                         if (loc.label < 0 || loc.label >= num_labels)
619                                 throw new System.ArgumentException ("The label is not valid");
620                         if (label_to_addr [loc.label] >= 0)
621                                 throw new System.ArgumentException ("The label was already defined");
622                         label_to_addr [loc.label] = code_len;
623                 }
624                 public virtual void MarkSequencePoint (ISymbolDocumentWriter document, int startLine,
625                                                        int startColumn, int endLine, int endColumn) {
626                         if (sym_writer == null)
627                                 return;
628
629                         int[] offsets = { code_len };
630                         int[] startLines = { startLine };
631                         int[] startColumns = { startColumn };
632                         int[] endLines = { endLine };
633                         int[] endColumns = { endColumn };
634
635                         sym_writer.DefineSequencePoints (document, offsets, startLines, startColumns,
636                                                          endLines, endColumns);
637                 }
638                 public virtual void ThrowException (Type exceptionType) {
639                         throw new NotImplementedException ();
640                 }
641                 public void UsingNamespace (String usingNamespace) {
642                         throw new NotImplementedException ();
643                 }
644
645                 internal void label_fixup () {
646                         int i;
647                         for (i = 0; i < num_fixups; ++i) {
648                                 int diff = label_to_addr [fixups [i].label_idx] - fixups [i].label_base;
649                                 if (fixups [i].size == 1) {
650                                         code [fixups [i].pos] = (byte)((sbyte) diff - 1);
651                                 } else {
652                                         int old_cl = code_len;
653                                         code_len = fixups [i].pos;
654                                         emit_int (diff - 4);
655                                         code_len = old_cl;
656                                 }
657                         }
658                 }
659         }
660 }