ILGenerator.cs 19 KB

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