ILGenerator.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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. cur_stack = 1; // the exception object is on the stack by default
  254. if (max_stack < cur_stack)
  255. max_stack = cur_stack;
  256. //System.Console.WriteLine ("Begin catch Block: {0} {1}",exceptionType.ToString(), max_stack);
  257. //throw new NotImplementedException ();
  258. }
  259. public virtual void BeginExceptFilterBlock () {
  260. throw new NotImplementedException ();
  261. }
  262. public virtual Label BeginExceptionBlock () {
  263. //System.Console.WriteLine ("Begin Block");
  264. if (ex_handlers != null) {
  265. cur_block = ex_handlers.Length;
  266. ILExceptionInfo[] new_ex = new ILExceptionInfo [cur_block + 1];
  267. System.Array.Copy (ex_handlers, new_ex, cur_block);
  268. ex_handlers = new_ex;
  269. } else {
  270. ex_handlers = new ILExceptionInfo [1];
  271. cur_block = 0;
  272. }
  273. open_blocks.Push (cur_block);
  274. ex_handlers [cur_block].start = code_len;
  275. return ex_handlers [cur_block].end = DefineLabel ();
  276. }
  277. public virtual void BeginFaultBlock() {
  278. if (open_blocks.Count <= 0)
  279. throw new NotSupportedException ("Not in an exception block");
  280. //System.Console.WriteLine ("Begin fault Block");
  281. //throw new NotImplementedException ();
  282. }
  283. public virtual void BeginFinallyBlock() {
  284. if (open_blocks.Count <= 0)
  285. throw new NotSupportedException ("Not in an exception block");
  286. InternalEndClause ();
  287. //System.Console.WriteLine ("Begin finally Block");
  288. ex_handlers [cur_block].AddFinally (code_len);
  289. }
  290. public virtual void BeginScope () {
  291. if (sym_writer != null)
  292. scopes.Push (sym_writer.OpenScope (code_len));
  293. }
  294. public LocalBuilder DeclareLocal (Type localType) {
  295. LocalBuilder res = new LocalBuilder (module, localType, this);
  296. if (locals != null) {
  297. LocalBuilder[] new_l = new LocalBuilder [locals.Length + 1];
  298. System.Array.Copy (locals, new_l, locals.Length);
  299. new_l [locals.Length] = res;
  300. locals = new_l;
  301. } else {
  302. locals = new LocalBuilder [1];
  303. locals [0] = res;
  304. }
  305. res.position = (uint)(locals.Length - 1);
  306. return res;
  307. }
  308. public virtual Label DefineLabel () {
  309. if (num_labels >= label_to_addr.Length) {
  310. int[] new_l = new int [label_to_addr.Length * 2];
  311. System.Array.Copy (label_to_addr, new_l, label_to_addr.Length);
  312. label_to_addr = new_l;
  313. }
  314. label_to_addr [num_labels] = -1;
  315. return new Label (num_labels++);
  316. }
  317. public virtual void Emit (OpCode opcode) {
  318. make_room (2);
  319. ll_emit (opcode);
  320. }
  321. public virtual void Emit (OpCode opcode, Byte val) {
  322. make_room (3);
  323. ll_emit (opcode);
  324. code [code_len++] = val;
  325. }
  326. public virtual void Emit (OpCode opcode, ConstructorInfo constructor) {
  327. int token = abuilder.GetToken (constructor);
  328. make_room (6);
  329. ll_emit (opcode);
  330. if (constructor is ConstructorBuilder)
  331. add_token_fixup (constructor);
  332. emit_int (token);
  333. ParameterInfo[] mparams = constructor.GetParameters();
  334. if (mparams != null)
  335. cur_stack -= mparams.Length;
  336. }
  337. public virtual void Emit (OpCode opcode, double val) {
  338. byte[] s = System.BitConverter.GetBytes (val);
  339. make_room (10);
  340. ll_emit (opcode);
  341. if (BitConverter.IsLittleEndian){
  342. System.Array.Copy (s, 0, code, code_len, 8);
  343. code_len += 8;
  344. } else {
  345. code [code_len++] = s [7];
  346. code [code_len++] = s [6];
  347. code [code_len++] = s [5];
  348. code [code_len++] = s [4];
  349. code [code_len++] = s [3];
  350. code [code_len++] = s [2];
  351. code [code_len++] = s [1];
  352. code [code_len++] = s [0];
  353. }
  354. }
  355. public virtual void Emit (OpCode opcode, FieldInfo field) {
  356. int token = abuilder.GetToken (field);
  357. make_room (6);
  358. ll_emit (opcode);
  359. if (field is FieldBuilder)
  360. add_token_fixup (field);
  361. emit_int (token);
  362. }
  363. public virtual void Emit (OpCode opcode, Int16 val) {
  364. make_room (4);
  365. ll_emit (opcode);
  366. code [code_len++] = (byte) (val & 0xFF);
  367. code [code_len++] = (byte) ((val >> 8) & 0xFF);
  368. }
  369. public virtual void Emit (OpCode opcode, int val) {
  370. make_room (6);
  371. ll_emit (opcode);
  372. emit_int (val);
  373. }
  374. public virtual void Emit (OpCode opcode, long val) {
  375. make_room (10);
  376. ll_emit (opcode);
  377. code [code_len++] = (byte) (val & 0xFF);
  378. code [code_len++] = (byte) ((val >> 8) & 0xFF);
  379. code [code_len++] = (byte) ((val >> 16) & 0xFF);
  380. code [code_len++] = (byte) ((val >> 24) & 0xFF);
  381. code [code_len++] = (byte) ((val >> 32) & 0xFF);
  382. code [code_len++] = (byte) ((val >> 40) & 0xFF);
  383. code [code_len++] = (byte) ((val >> 48) & 0xFF);
  384. code [code_len++] = (byte) ((val >> 56) & 0xFF);
  385. }
  386. public virtual void Emit (OpCode opcode, Label label) {
  387. int tlen = target_len (opcode);
  388. make_room (6);
  389. ll_emit (opcode);
  390. if (num_fixups >= fixups.Length) {
  391. LabelFixup[] newf = new LabelFixup [fixups.Length + 16];
  392. System.Array.Copy (fixups, newf, fixups.Length);
  393. fixups = newf;
  394. }
  395. fixups [num_fixups].size = tlen;
  396. fixups [num_fixups].pos = code_len;
  397. fixups [num_fixups].label_base = code_len;
  398. fixups [num_fixups].label_idx = label.label;
  399. num_fixups++;
  400. code_len += tlen;
  401. }
  402. public virtual void Emit (OpCode opcode, Label[] labels) {
  403. /* opcode needs to be switch. */
  404. int count = labels.Length;
  405. make_room (6 + count * 4);
  406. ll_emit (opcode);
  407. int switch_base = code_len + count*4;
  408. emit_int (count);
  409. if (num_fixups + count >= fixups.Length) {
  410. LabelFixup[] newf = new LabelFixup [fixups.Length + count + 16];
  411. System.Array.Copy (fixups, newf, fixups.Length);
  412. fixups = newf;
  413. }
  414. for (int i = 0; i < count; ++i) {
  415. fixups [num_fixups].size = 4;
  416. fixups [num_fixups].pos = code_len;
  417. fixups [num_fixups].label_base = switch_base;
  418. fixups [num_fixups].label_idx = labels [i].label;
  419. num_fixups++;
  420. code_len += 4;
  421. }
  422. }
  423. public virtual void Emit (OpCode opcode, LocalBuilder lbuilder) {
  424. uint pos = lbuilder.position;
  425. bool load_addr = false;
  426. bool is_store = false;
  427. make_room (6);
  428. if (lbuilder.ilgen != this)
  429. throw new Exception ("Trying to emit a local from a different ILGenerator.");
  430. /* inline the code from ll_emit () to optimize il code size */
  431. if (opcode.StackBehaviourPop == StackBehaviour.Pop1) {
  432. cur_stack --;
  433. is_store = true;
  434. } else {
  435. cur_stack++;
  436. if (cur_stack > max_stack)
  437. max_stack = cur_stack;
  438. load_addr = opcode.StackBehaviourPush == StackBehaviour.Pushi;
  439. }
  440. if (load_addr) {
  441. if (pos < 256) {
  442. code [code_len++] = (byte)0x12;
  443. code [code_len++] = (byte)pos;
  444. } else {
  445. code [code_len++] = (byte)0xfe;
  446. code [code_len++] = (byte)0x0d;
  447. code [code_len++] = (byte)(pos & 0xff);
  448. code [code_len++] = (byte)((pos >> 8) & 0xff);
  449. }
  450. } else {
  451. if (is_store) {
  452. if (pos < 4) {
  453. code [code_len++] = (byte)(0x0a + pos);
  454. } else if (pos < 256) {
  455. code [code_len++] = (byte)0x13;
  456. code [code_len++] = (byte)pos;
  457. } else {
  458. code [code_len++] = (byte)0xfe;
  459. code [code_len++] = (byte)0x0e;
  460. code [code_len++] = (byte)(pos & 0xff);
  461. code [code_len++] = (byte)((pos >> 8) & 0xff);
  462. }
  463. } else {
  464. if (pos < 4) {
  465. code [code_len++] = (byte)(0x06 + pos);
  466. } else if (pos < 256) {
  467. code [code_len++] = (byte)0x11;
  468. code [code_len++] = (byte)pos;
  469. } else {
  470. code [code_len++] = (byte)0xfe;
  471. code [code_len++] = (byte)0x0c;
  472. code [code_len++] = (byte)(pos & 0xff);
  473. code [code_len++] = (byte)((pos >> 8) & 0xff);
  474. }
  475. }
  476. }
  477. }
  478. public virtual void Emit (OpCode opcode, MethodInfo method) {
  479. int token = abuilder.GetToken (method);
  480. make_room (6);
  481. ll_emit (opcode);
  482. if (method is MethodBuilder)
  483. add_token_fixup (method);
  484. emit_int (token);
  485. if (method.ReturnType != void_type)
  486. cur_stack ++;
  487. ParameterInfo[] mparams = method.GetParameters();
  488. if (mparams != null)
  489. cur_stack -= mparams.Length;
  490. }
  491. [CLSCompliant(false)]
  492. public void Emit (OpCode opcode, sbyte val) {
  493. make_room (3);
  494. ll_emit (opcode);
  495. code [code_len++] = (byte)val;
  496. }
  497. [MonoTODO]
  498. public virtual void Emit (OpCode opcode, SignatureHelper shelper) {
  499. int token = 0; // FIXME: request a token from the modulebuilder
  500. make_room (6);
  501. ll_emit (opcode);
  502. emit_int (token);
  503. }
  504. public virtual void Emit (OpCode opcode, float val) {
  505. byte[] s = System.BitConverter.GetBytes (val);
  506. make_room (6);
  507. ll_emit (opcode);
  508. if (BitConverter.IsLittleEndian){
  509. System.Array.Copy (s, 0, code, code_len, 4);
  510. code_len += 4;
  511. } else {
  512. code [code_len++] = s [3];
  513. code [code_len++] = s [2];
  514. code [code_len++] = s [1];
  515. code [code_len++] = s [0];
  516. }
  517. }
  518. public virtual void Emit (OpCode opcode, string val) {
  519. int token = abuilder.GetToken (val);
  520. make_room (6);
  521. ll_emit (opcode);
  522. emit_int (token);
  523. }
  524. public virtual void Emit (OpCode opcode, Type type) {
  525. make_room (6);
  526. ll_emit (opcode);
  527. if (type is TypeBuilder)
  528. add_token_fixup (type);
  529. emit_int (abuilder.GetToken (type));
  530. }
  531. public void EmitCall (OpCode opcode, MethodInfo methodinfo, Type[] optionalParamTypes) {
  532. throw new NotImplementedException ();
  533. }
  534. public void EmitCalli (OpCode opcode, CallingConventions call_conv, Type returnType, Type[] paramTypes, Type[] optionalParamTypes) {
  535. throw new NotImplementedException ();
  536. }
  537. public virtual void EmitWriteLine (FieldInfo field) {
  538. throw new NotImplementedException ();
  539. }
  540. public virtual void EmitWriteLine (LocalBuilder lbuilder) {
  541. throw new NotImplementedException ();
  542. }
  543. public virtual void EmitWriteLine (string val) {
  544. throw new NotImplementedException ();
  545. }
  546. public virtual void EndExceptionBlock () {
  547. if (open_blocks.Count <= 0)
  548. throw new NotSupportedException ("Not in an exception block");
  549. InternalEndClause ();
  550. MarkLabel (ex_handlers [cur_block].end);
  551. ex_handlers [cur_block].End (code_len);
  552. ex_handlers [cur_block].Debug (cur_block);
  553. //System.Console.WriteLine ("End Block {0} (handlers: {1})", cur_block, ex_handlers [cur_block].NumHandlers ());
  554. open_blocks.Pop ();
  555. if (open_blocks.Count > 0)
  556. cur_block = (int)open_blocks.Peek ();
  557. //Console.WriteLine ("curblock restored to {0}", cur_block);
  558. //throw new NotImplementedException ();
  559. }
  560. public virtual void EndScope () {
  561. if (sym_writer != null) {
  562. sym_writer.CloseScope (code_len);
  563. scopes.Pop ();
  564. }
  565. }
  566. public virtual void MarkLabel (Label loc) {
  567. if (loc.label < 0 || loc.label >= num_labels)
  568. throw new System.ArgumentException ("The label is not valid");
  569. if (label_to_addr [loc.label] >= 0)
  570. throw new System.ArgumentException ("The label was already defined");
  571. label_to_addr [loc.label] = code_len;
  572. }
  573. public virtual void MarkSequencePoint (ISymbolDocumentWriter document, int startLine,
  574. int startColumn, int endLine, int endColumn) {
  575. if (sym_writer == null)
  576. return;
  577. int[] offsets = { code_len };
  578. int[] startLines = { startLine };
  579. int[] startColumns = { startColumn };
  580. int[] endLines = { endLine };
  581. int[] endColumns = { endColumn };
  582. sym_writer.DefineSequencePoints (document, offsets, startLines, startColumns,
  583. endLines, endColumns);
  584. }
  585. public virtual void ThrowException (Type exceptionType) {
  586. throw new NotImplementedException ();
  587. }
  588. public void UsingNamespace (String usingNamespace) {
  589. throw new NotImplementedException ();
  590. }
  591. internal void label_fixup () {
  592. int i;
  593. for (i = 0; i < num_fixups; ++i) {
  594. int diff = label_to_addr [fixups [i].label_idx] - fixups [i].label_base;
  595. if (fixups [i].size == 1) {
  596. code [fixups [i].pos] = (byte)((sbyte) diff - 1);
  597. } else {
  598. int old_cl = code_len;
  599. code_len = fixups [i].pos;
  600. emit_int (diff - 4);
  601. code_len = old_cl;
  602. }
  603. }
  604. }
  605. }
  606. }