public Main() { StackMap <int, string> map = new StackMap <int, string>(); map.Push(1, "one"); map.Push(2, "two"); map.Push(3, "three"); map.Push(4, "four"); map.Push(5, "five"); Console.WriteLine(map.Peek()); while (!map.IsEmpty()) { Console.WriteLine(map.Pop()); Console.WriteLine(map.Count()); } }
public void Write(JavaWriter wtr, JavaAttribute.Code codeAttr) { wtr.Where.Push("method body"); int codeLength = FillInstructions(wtr); if (codeLength > 0xFFFE) { throw wtr.Where.Exception("output method is too large"); } var labelToOffsetMap = FillJumpTargets(wtr); codeAttr.code = new byte[codeLength]; FillCodeAttr(codeAttr.code); codeAttr.maxStack = (ushort)MaxStack; codeAttr.maxLocals = (ushort)MaxLocals; WriteExceptionData(codeAttr, labelToOffsetMap); if (StackMap != null) { var attr = StackMap.ToAttribute(wtr, labelToOffsetMap); if (attr != null) { codeAttr.attributes.Put(attr); } } if (DebugLocals != null) { var attr = new JavaAttribute.LocalVariableTable(DebugLocals, codeLength); codeAttr.attributes.Put(attr); } FillLineNumbers(codeAttr); wtr.Where.Pop(); }
public void Print(IndentedText txt) { if (Instructions.Count == 0) { return; } if (instMnemonics == null) { InitializeMnemonics(); } var excStrings = PrepareExceptions(); int line = 0; string lineText; if (Instructions.Count > 0 && Instructions[0]?.Line != 0) { line = Instructions[0].Line; lineText = "line " + line + ", "; } else { lineText = string.Empty; } txt.Write(" ---------- {0}stack={1}, locals={2}, args_size={3}", lineText, MaxStack, MaxLocals, (Method.Parameters?.Count ?? 0)); txt.NewLine(); int offset = 0; foreach (var inst in Instructions) { if (inst.Line != 0 && inst.Line != line) { line = inst.Line; txt.Write(" ---------- line {0}", line); txt.NewLine(); } if (excStrings.TryGetValue(offset, out var strs)) { txt.AdjustIndent(+4); foreach (var s in strs) { txt.Write(s); txt.NewLine(); } txt.AdjustIndent(-4); } if (StackMap != null) { var(strLocals, strStack) = StackMap.FrameToString((ushort)offset); if (strLocals != null) { txt.Write($" locals = [ {strLocals} ]"); txt.NewLine(); } if (strStack != null) { txt.Write($" stack = [ {strStack} ]"); txt.NewLine(); } } byte op; if (inst.Bytes != null) { op = inst.Bytes[0]; txt.Write("{0:X4} {1:X2}", offset, op); for (int i = 1; i < inst.Bytes.Length; i++) { txt.Write(" {0:X2}", inst.Bytes[i]); } for (int i = inst.Bytes.Length; i < 5; i++) { txt.Write(" "); } txt.Write(" "); } else { op = inst.Opcode; txt.Write("L.{0:X4} {1:X2}", inst.Label, op); for (int i = 1; i < 5; i++) { txt.Write(" "); } txt.Write(" "); } if (op == 0xC4) { PrintInstructionWide(txt, inst, offset); } else { switch (instOperandType[op] & 0xF0) { case 0x80: PrintInstructionConst(txt, inst, offset); break; case 0x40: PrintInstructionJump(txt, inst, offset); break; case 0x20: PrintInstructionMisc1(txt, inst, offset); break; case 0x10: PrintInstructionNarrow(txt, inst, offset); break; case 0x00: PrintInstructionMisc0(txt, inst, offset); break; default: txt.Write("unknown opcode kind"); break; } } txt.NewLine(); if (inst.Bytes != null) { offset += inst.Bytes.Length; } } }