protected override void GetStrings(LabelBuilder builder) { foreach (RWSDDataNode node in Children[0].Children) { builder.Add((uint)node.Index, node._name); } }
protected override void GetStrings(LabelBuilder builder) { foreach (RSEQLabelNode node in Children) { builder.Add(node.Id, node._name); } }
private void EmitBranchPlaceholder(OpCodes branchOperation, LabelBuilder target) { byte[] code = new byte[5]; code[0] = (byte)branchOperation; _code.Add(code); _branches[_code.Count - 1] = target; }
private void VisitFrameBeforeLeftBorderNodes(Frame frame) { LabelBuilder unwrapFailed = _builder.CreateLabel(), end = _builder.CreateLabel(); _frameData[frame] = new FrameData(unwrapFailed, end); }
private static void CompileSelectReference(FunctionCompiler compiler, FunctionalNode selectReferenceNode) { LabelBuilder falseLabel = compiler._builder.CreateLabel(), endLabel = compiler._builder.CreateLabel(); VariableReference input1 = selectReferenceNode.InputTerminals.ElementAt(1).GetTrueVariable(), input2 = selectReferenceNode.InputTerminals.ElementAt(2).GetTrueVariable(), selector = selectReferenceNode.InputTerminals.ElementAt(0).GetTrueVariable(), selectedReference = selectReferenceNode.OutputTerminals.ElementAt(1).GetTrueVariable(); compiler.LoadLocalAllocationReference(selectedReference); compiler.LoadValueAsReference(selector); compiler._builder.EmitDerefInteger(); compiler._builder.EmitBranchIfFalse(falseLabel); // true compiler.LoadValueAsReference(input1); compiler._builder.EmitBranch(endLabel); // false compiler._builder.SetLabel(falseLabel); compiler.LoadValueAsReference(input2); // end compiler._builder.SetLabel(endLabel); compiler._builder.EmitStorePointer(); }
public void LabelBuildersContextCanBeAccessedByAccessor() { var sut = LabelBuilder.FromWebSensingMedia(1); var accessor = Assert.IsAssignableFrom <IContextAccessor <Label> >(sut); Assert.NotNull(accessor.Context); Assert.IsType <Label>(accessor.Context); }
public override int OnCalculateSize(bool force) { builder = new LabelBuilder(); foreach (RSEQLabelNode node in Children) builder.Add(node.Id, node._name); _audioLen = 0; return _headerLen = 0x20 + _dataBuffer.Length + builder.GetSize(); }
private static unsafe Jsm.ExecutableSegment MakeScript(Operation *operation, UInt16 count) { List <JsmInstruction> instructions = new List <JsmInstruction>(count / 2); LabeledStack stack = new LabeledStack(); LabelBuilder labelBuilder = new LabelBuilder(count); for (Int32 i = 0; i < count; i++) { Jsm.Opcode opcode = operation->Opcode; Int32 parameter = operation->Parameter; operation++; stack.CurrentLabel = i; IJsmExpression expression = Jsm.Expression.TryMake(opcode, parameter, stack); if (expression != null) { stack.Push(expression); continue; } JsmInstruction instruction = JsmInstruction.TryMake(opcode, parameter, stack); if (instruction != null) { labelBuilder.TraceInstruction(i, stack.CurrentLabel, new IndexedInstruction(instructions.Count, instruction)); instructions.Add(instruction); continue; } throw new NotSupportedException(opcode.ToString()); } if (stack.Count != 0) { throw new InvalidProgramException("Stack unbalanced."); } if (!(instructions.First() is LBL)) { throw new InvalidProgramException("Script must start with a label."); } if (!(instructions.Last() is IRET)) { throw new InvalidProgramException("Script must end with a return."); } // Switch from opcodes to instructions HashSet <Int32> labelIndices = labelBuilder.Commit(); // Merge similar instructions instructions = InstructionMerger.Merge(instructions, labelIndices); // Combine instructions to logical blocks IReadOnlyList <Jsm.IJsmControl> controls = Jsm.Control.Builder.Build(instructions); // Arrange instructions by segments and return root return(Jsm.Segment.Builder.Build(instructions, controls)); }
public override int OnCalculateSize(bool force) { builder = new LabelBuilder(); foreach (RSEQLabelNode node in Children) { builder.Add(node.Id, node._name); } _audioLen = 0; return(_headerLen = 0x20 + _dataBuffer.Length + builder.GetSize()); }
public void LabelBuildersResetMethodResetsLabel() { var sut = LabelBuilder.FromWebSensingMedia(1) .AddText(new TextElement()); sut.Reset(); var label = sut.Build(); Assert.Empty(label.Content); }
public void SetLabel(LabelBuilder label) { if (!_labels.ContainsKey(label)) { _labels.Add(label, _code.Count); } else { throw new InvalidOperationException("Label has already been set"); } }
private void DrawForm() { Controls.Clear(); SuspendLayout(); var window = new TableLayoutPanel() { Height = ClientSize.Height, Width = ClientSize.Width, BackgroundImage = Resources.BG, BackgroundImageLayout = ImageLayout.Stretch }; var height = (int)(window.Height * 0.85); var castle1 = CastleBuilder.BuildTower(height, LeftBottom); var wall1 = CastleBuilder.BuildWall(height, LeftBottom); var castle2 = CastleBuilder.BuildTower(height, RightBottom); var wall2 = CastleBuilder.BuildWall(height, RightBottom); for (var i = 0; i < 8; i++) { window.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 12.4f)); } window.RowStyles.Add(new RowStyle(SizeType.Percent, 58)); window.RowStyles.Add(new RowStyle(SizeType.Percent, 7)); window.RowStyles.Add(new RowStyle(SizeType.Percent, 10)); window.RowStyles.Add(new RowStyle(SizeType.Percent, 25)); // Castles building window.Controls.Add(castle2, 6, 0); window.Controls.Add(castle1, 1, 0); window.Controls.Add(wall1, 2, 0); window.Controls.Add(wall2, 5, 0); // HP buildings window.Controls.Add(LabelBuilder.CreateHealthBar("tower1", _game.Player1.Castle.TowerHealth), 1, 1); window.Controls.Add(LabelBuilder.CreateHealthBar("tower2", _game.Player2.Castle.TowerHealth), 6, 1); window.Controls.Add(LabelBuilder.CreateHealthBar("wall1", _game.Player1.Castle.WallHealth), 2, 1); window.Controls.Add(LabelBuilder.CreateHealthBar("wall2", _game.Player2.Castle.WallHealth), 5, 1); // Resources building window.Controls.Add(DrawResources("res1", _game.Player1.Resources, ContentAlignment.TopLeft, _player1Color), 0, 0); window.Controls.Add(DrawResources("res2", _game.Player1.Resources, ContentAlignment.TopRight, _player2Color), 7, 0); // Drawing Deck DrawDeck(_game.CurrentPlayer, window, (_game.CurrentPlayer == _game.Player1) ? _player1Color : _player2Color); Controls.Add(window); ResumeLayout(false); }
public override unsafe void Export(string outPath) { LabelBuilder labl; int lablLen, size; VoidPtr addr; Rebuild(); if (_audioSource != DataSource.Empty) { //Get strings labl = new LabelBuilder(); GetStrings(labl); lablLen = (labl.Count == 0) ? 0 : labl.GetSize(); size = WorkingUncompressed.Length + lablLen + _audioSource.Length; using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { stream.SetLength(size); using (FileMap map = FileMap.FromStreamInternal(stream, FileMapProtect.ReadWrite, 0, size)) { addr = map.Address; //Write header Memory.Move(addr, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length); addr += WorkingUncompressed.Length; //Write strings if (lablLen > 0) { labl.Write(addr); } addr += lablLen; //Write data Memory.Move(addr, _audioSource.Address, (uint)_audioSource.Length); } } } else { base.Export(outPath); } }
public override void Export(string outPath) { LabelBuilder labl; int lablLen, size; VoidPtr addr; Rebuild(); //Get strings labl = new LabelBuilder(); GetStrings(labl); lablLen = labl.Count == 0 ? 0 : labl.GetSize(); size = WorkingUncompressed.Length + lablLen + _audioSource.Length; using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { stream.SetLength(size); using (FileMap map = FileMap.FromStreamInternal(stream, FileMapProtect.ReadWrite, 0, size)) { addr = map.Address; //Write headers MoveRawUncompressed(addr, WorkingUncompressed.Length); addr += WorkingUncompressed.Length; //Write strings if (lablLen > 0) { labl.Write(addr); } addr += lablLen; //Write sound data int audioLen = _audioSource.Length; Memory.Move(addr, _audioSource.Address, (uint)audioLen); _audioSource.Close(); _audioSource = new DataSource(addr, audioLen); } } }
private void VisitLoopBeforeLeftBorderNodes(Compiler.Nodes.Loop loop) { LabelBuilder start = _builder.CreateLabel(), end = _builder.CreateLabel(); LoopConditionTunnel loopCondition = loop.BorderNodes.OfType <LoopConditionTunnel>().First(); Terminal loopConditionInput = loopCondition.InputTerminals.ElementAt(0); VariableReference loopConditionVariable = loopConditionInput.GetTrueVariable(); _loopData[loop] = new LoopData(start, end, loopConditionVariable); if (!loopConditionInput.IsConnected) { // if loop condition was unwired, initialize it to true LoadLocalAllocationReference(loopConditionVariable); _builder.EmitLoadIntegerImmediate(1); _builder.EmitStoreInteger(); } _builder.SetLabel(start); }
public void DrawDeck(Player player, TableLayoutPanel window, Color playerColor) { for (var i = 1; i < 7; i++) { var card = new TableLayoutPanel() { Name = "card" + i, Dock = DockStyle.Fill, BackColor = player.Cursor == i - 1 ? playerColor : Color.Transparent, Margin = new Padding(0), Padding = new Padding(0) }; card.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); card.RowStyles.Add(new RowStyle(SizeType.Percent, 50)); card.Controls.Add(new Label { Name = "name", Text = player.Deck[i - 1].Description, Dock = DockStyle.Fill, BackColor = _game.CurrentPlayer.Deck[i - 1].Color, Font = new Font("Arial", 8, FontStyle.Bold), MaximumSize = new Size(ClientSize.Width / 8 - 10, 0), AutoSize = true, TextAlign = ContentAlignment.MiddleCenter, Margin = new Padding(5, 5, 5, 0) }, 0, 0); var costsFormat = player.Deck[i - 1].Cost .Select(e => Tuple.Create(e.Key, $"{e.Key}: {e.Value}")) .ToList(); var costs = LabelBuilder.CreateLabelList("costs", costsFormat, ContentAlignment.MiddleLeft, new Font("Arial", 8, FontStyle.Bold), _game.CurrentPlayer.Deck[i - 1].Color); costs.Padding = new Padding(0); costs.Margin = new Padding(5, 0, 5, 5); costs.MaximumSize = new Size(ClientSize.Width / 8 - 10, 0); card.Controls.Add(costs, 0, 1); window.Controls.Add(card, i, 3); } }
public void EmitBranchIfFalse(LabelBuilder target) { EmitBranchPlaceholder(OpCodes.BranchIfFalse, target); }
protected LabelBuilder GetOrAddLabel(int streamIndex) => _labels.TryGetValue(streamIndex, out var value) ? value : (_labels[streamIndex] = new LabelBuilder($"IL_{streamIndex:X04}"));
public void LabelBuildersBuildMethodReturnsLabel() { Assert.IsType <Label>(LabelBuilder.FromWebSensingMedia(1).Build()); }
protected virtual void GetStrings(LabelBuilder builder) { }
public FrameData(LabelBuilder unwrapFailed, LabelBuilder end) { UnwrapFailed = unwrapFailed; End = end; }
public LoopData(LabelBuilder start, LabelBuilder end, VariableReference loopCondition) { Start = start; End = end; LoopCondition = loopCondition; }
protected override void GetStrings(LabelBuilder builder) { foreach (RWSDDataNode node in Children[0].Children) builder.Add((uint)node.Index, node._name); }
public TableLayoutPanel DrawResources(string name, Dictionary <string, Resource> res, ContentAlignment align, Color bg) { return(LabelBuilder.CreateLabelList(name, res .Select(e => Tuple.Create(e.Key, $"{e.Key}:\n{e.Value.Count} (+{e.Value.Source})")) .ToList(), align, new Font("Arial", 12, FontStyle.Bold), bg)); }
protected override void GetStrings(LabelBuilder builder) { foreach (RSEQLabelNode node in Children[0].Children) builder.Add(node.Id, node._name); }
protected virtual partial void DisassembleNextOpCode(int currentIndex, short opcode) { switch (opcode) { case OpCodeConst.Nop: { PushOperation(Inst.Nop()); } return; case OpCodeConst.Break: { PushOperation(Inst.Break()); } return; case OpCodeConst.Ldarg_0: { PushOperation(Inst.Ldarg_0()); } return; case OpCodeConst.Ldarg_1: { PushOperation(Inst.Ldarg_1()); } return; case OpCodeConst.Ldarg_2: { PushOperation(Inst.Ldarg_2()); } return; case OpCodeConst.Ldarg_3: { PushOperation(Inst.Ldarg_3()); } return; case OpCodeConst.Ldloc_0: { PushOperation(Inst.Ldloc_0()); } return; case OpCodeConst.Ldloc_1: { PushOperation(Inst.Ldloc_1()); } return; case OpCodeConst.Ldloc_2: { PushOperation(Inst.Ldloc_2()); } return; case OpCodeConst.Ldloc_3: { PushOperation(Inst.Ldloc_3()); } return; case OpCodeConst.Stloc_0: { PushOperation(Inst.Stloc_0()); } return; case OpCodeConst.Stloc_1: { PushOperation(Inst.Stloc_1()); } return; case OpCodeConst.Stloc_2: { PushOperation(Inst.Stloc_2()); } return; case OpCodeConst.Stloc_3: { PushOperation(Inst.Stloc_3()); } return; case OpCodeConst.Ldarg_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Ldarg_S(value)); } return; case OpCodeConst.Ldarga_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Ldarga_S(value)); } return; case OpCodeConst.Starg_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Starg_S(value)); } return; case OpCodeConst.Ldloc_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Ldloc_S(value)); } return; case OpCodeConst.Ldloca_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Ldloca_S(value)); } return; case OpCodeConst.Stloc_S: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Stloc_S(value)); } return; case OpCodeConst.Ldnull: { PushOperation(Inst.Ldnull()); } return; case OpCodeConst.Ldc_I4_M1: { PushOperation(Inst.Ldc_I4_M1()); } return; case OpCodeConst.Ldc_I4_0: { PushOperation(Inst.Ldc_I4_0()); } return; case OpCodeConst.Ldc_I4_1: { PushOperation(Inst.Ldc_I4_1()); } return; case OpCodeConst.Ldc_I4_2: { PushOperation(Inst.Ldc_I4_2()); } return; case OpCodeConst.Ldc_I4_3: { PushOperation(Inst.Ldc_I4_3()); } return; case OpCodeConst.Ldc_I4_4: { PushOperation(Inst.Ldc_I4_4()); } return; case OpCodeConst.Ldc_I4_5: { PushOperation(Inst.Ldc_I4_5()); } return; case OpCodeConst.Ldc_I4_6: { PushOperation(Inst.Ldc_I4_6()); } return; case OpCodeConst.Ldc_I4_7: { PushOperation(Inst.Ldc_I4_7()); } return; case OpCodeConst.Ldc_I4_8: { PushOperation(Inst.Ldc_I4_8()); } return; case OpCodeConst.Ldc_I4_S: { var value = ReadStreamHead <sbyte>(); PushOperation(Inst.Ldc_I4_S(value)); } return; case OpCodeConst.Ldc_I4: { var value = ReadStreamHead <int>(); PushOperation(Inst.Ldc_I4(value)); } return; case OpCodeConst.Ldc_I8: { var value = ReadStreamHead <long>(); PushOperation(Inst.Ldc_I8(value)); } return; case OpCodeConst.Ldc_R4: { var value = ReadStreamHead <float>(); PushOperation(Inst.Ldc_R4(value)); } return; case OpCodeConst.Ldc_R8: { var value = ReadStreamHead <double>(); PushOperation(Inst.Ldc_R8(value)); } return; case OpCodeConst.Dup: { PushOperation(Inst.Dup()); } return; case OpCodeConst.Pop: { PushOperation(Inst.Pop()); } return; case OpCodeConst.Jmp: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Jmp(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Jmp(ctor)); } } return; case OpCodeConst.Call: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Call(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Call(ctor)); } } return; case OpCodeConst.Calli: { // var sig = Method.DeclaringType.Module.ResolveSignature(ReadStreamHead<int>()); // PushOperation(Inst.Calli(sig)); throw new NotSupportedException(); } return; case OpCodeConst.Ret: { PushOperation(Inst.Ret()); } return; case OpCodeConst.Br_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Br_S(GetOrAddLabel(currentIndex + OpCodes.Br_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Brfalse_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Brfalse_S(GetOrAddLabel(currentIndex + OpCodes.Brfalse_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Brtrue_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Brtrue_S(GetOrAddLabel(currentIndex + OpCodes.Brtrue_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Beq_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Beq_S(GetOrAddLabel(currentIndex + OpCodes.Beq_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bge_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Bge_S(GetOrAddLabel(currentIndex + OpCodes.Bge_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bgt_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Bgt_S(GetOrAddLabel(currentIndex + OpCodes.Bgt_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Ble_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Ble_S(GetOrAddLabel(currentIndex + OpCodes.Ble_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Blt_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Blt_S(GetOrAddLabel(currentIndex + OpCodes.Blt_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bne_Un_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Bne_Un_S(GetOrAddLabel(currentIndex + OpCodes.Bne_Un_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bge_Un_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Bge_Un_S(GetOrAddLabel(currentIndex + OpCodes.Bge_Un_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bgt_Un_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Bgt_Un_S(GetOrAddLabel(currentIndex + OpCodes.Bgt_Un_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Ble_Un_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Ble_Un_S(GetOrAddLabel(currentIndex + OpCodes.Ble_Un_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Blt_Un_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Blt_Un_S(GetOrAddLabel(currentIndex + OpCodes.Blt_Un_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Br: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Br(GetOrAddLabel(currentIndex + OpCodes.Br.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Brfalse: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Brfalse(GetOrAddLabel(currentIndex + OpCodes.Brfalse.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Brtrue: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Brtrue(GetOrAddLabel(currentIndex + OpCodes.Brtrue.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Beq: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Beq(GetOrAddLabel(currentIndex + OpCodes.Beq.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bge: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Bge(GetOrAddLabel(currentIndex + OpCodes.Bge.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bgt: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Bgt(GetOrAddLabel(currentIndex + OpCodes.Bgt.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Ble: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Ble(GetOrAddLabel(currentIndex + OpCodes.Ble.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Blt: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Blt(GetOrAddLabel(currentIndex + OpCodes.Blt.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bne_Un: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Bne_Un(GetOrAddLabel(currentIndex + OpCodes.Bne_Un.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bge_Un: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Bge_Un(GetOrAddLabel(currentIndex + OpCodes.Bge_Un.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Bgt_Un: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Bgt_Un(GetOrAddLabel(currentIndex + OpCodes.Bgt_Un.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Ble_Un: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Ble_Un(GetOrAddLabel(currentIndex + OpCodes.Ble_Un.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Blt_Un: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Blt_Un(GetOrAddLabel(currentIndex + OpCodes.Blt_Un.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Switch: { var labels = new LabelBuilder[ReadStreamHead <int>()]; for (var i = 0; i < labels.Length; ++i) { labels[i] = GetOrAddLabel(currentIndex + 4 * (1 + labels.Length) + ReadStreamHead <int>()); } PushOperation(Inst.Switch(labels)); } return; case OpCodeConst.Ldind_I1: { PushOperation(Inst.Ldind_I1()); } return; case OpCodeConst.Ldind_U1: { PushOperation(Inst.Ldind_U1()); } return; case OpCodeConst.Ldind_I2: { PushOperation(Inst.Ldind_I2()); } return; case OpCodeConst.Ldind_U2: { PushOperation(Inst.Ldind_U2()); } return; case OpCodeConst.Ldind_I4: { PushOperation(Inst.Ldind_I4()); } return; case OpCodeConst.Ldind_U4: { PushOperation(Inst.Ldind_U4()); } return; case OpCodeConst.Ldind_I8: { PushOperation(Inst.Ldind_I8()); } return; case OpCodeConst.Ldind_I: { PushOperation(Inst.Ldind_I()); } return; case OpCodeConst.Ldind_R4: { PushOperation(Inst.Ldind_R4()); } return; case OpCodeConst.Ldind_R8: { PushOperation(Inst.Ldind_R8()); } return; case OpCodeConst.Ldind_Ref: { PushOperation(Inst.Ldind_Ref()); } return; case OpCodeConst.Stind_Ref: { PushOperation(Inst.Stind_Ref()); } return; case OpCodeConst.Stind_I1: { PushOperation(Inst.Stind_I1()); } return; case OpCodeConst.Stind_I2: { PushOperation(Inst.Stind_I2()); } return; case OpCodeConst.Stind_I4: { PushOperation(Inst.Stind_I4()); } return; case OpCodeConst.Stind_I8: { PushOperation(Inst.Stind_I8()); } return; case OpCodeConst.Stind_R4: { PushOperation(Inst.Stind_R4()); } return; case OpCodeConst.Stind_R8: { PushOperation(Inst.Stind_R8()); } return; case OpCodeConst.Add: { PushOperation(Inst.Add()); } return; case OpCodeConst.Sub: { PushOperation(Inst.Sub()); } return; case OpCodeConst.Mul: { PushOperation(Inst.Mul()); } return; case OpCodeConst.Div: { PushOperation(Inst.Div()); } return; case OpCodeConst.Div_Un: { PushOperation(Inst.Div_Un()); } return; case OpCodeConst.Rem: { PushOperation(Inst.Rem()); } return; case OpCodeConst.Rem_Un: { PushOperation(Inst.Rem_Un()); } return; case OpCodeConst.And: { PushOperation(Inst.And()); } return; case OpCodeConst.Or: { PushOperation(Inst.Or()); } return; case OpCodeConst.Xor: { PushOperation(Inst.Xor()); } return; case OpCodeConst.Shl: { PushOperation(Inst.Shl()); } return; case OpCodeConst.Shr: { PushOperation(Inst.Shr()); } return; case OpCodeConst.Shr_Un: { PushOperation(Inst.Shr_Un()); } return; case OpCodeConst.Neg: { PushOperation(Inst.Neg()); } return; case OpCodeConst.Not: { PushOperation(Inst.Not()); } return; case OpCodeConst.Conv_I1: { PushOperation(Inst.Conv_I1()); } return; case OpCodeConst.Conv_I2: { PushOperation(Inst.Conv_I2()); } return; case OpCodeConst.Conv_I4: { PushOperation(Inst.Conv_I4()); } return; case OpCodeConst.Conv_I8: { PushOperation(Inst.Conv_I8()); } return; case OpCodeConst.Conv_R4: { PushOperation(Inst.Conv_R4()); } return; case OpCodeConst.Conv_R8: { PushOperation(Inst.Conv_R8()); } return; case OpCodeConst.Conv_U4: { PushOperation(Inst.Conv_U4()); } return; case OpCodeConst.Conv_U8: { PushOperation(Inst.Conv_U8()); } return; case OpCodeConst.Callvirt: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Callvirt(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Callvirt(ctor)); } } return; case OpCodeConst.Cpobj: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Cpobj(type)); } return; case OpCodeConst.Ldobj: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Ldobj(type)); } return; case OpCodeConst.Ldstr: { var str = Method.DeclaringType.Module.ResolveString(ReadStreamHead <int>()); PushOperation(Inst.Ldstr(str)); } return; case OpCodeConst.Newobj: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Newobj(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Newobj(ctor)); } } return; case OpCodeConst.Castclass: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Castclass(type)); } return; case OpCodeConst.Isinst: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Isinst(type)); } return; case OpCodeConst.Conv_R_Un: { PushOperation(Inst.Conv_R_Un()); } return; case OpCodeConst.Unbox: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Unbox(type)); } return; case OpCodeConst.Throw: { PushOperation(Inst.Throw()); } return; case OpCodeConst.Ldfld: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Ldfld(fld)); } return; case OpCodeConst.Ldflda: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Ldflda(fld)); } return; case OpCodeConst.Stfld: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Stfld(fld)); } return; case OpCodeConst.Ldsfld: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Ldsfld(fld)); } return; case OpCodeConst.Ldsflda: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Ldsflda(fld)); } return; case OpCodeConst.Stsfld: { var fld = Method.DeclaringType.Module.ResolveField(ReadStreamHead <int>()); PushOperation(Inst.Stsfld(fld)); } return; case OpCodeConst.Stobj: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Stobj(type)); } return; case OpCodeConst.Conv_Ovf_I1_Un: { PushOperation(Inst.Conv_Ovf_I1_Un()); } return; case OpCodeConst.Conv_Ovf_I2_Un: { PushOperation(Inst.Conv_Ovf_I2_Un()); } return; case OpCodeConst.Conv_Ovf_I4_Un: { PushOperation(Inst.Conv_Ovf_I4_Un()); } return; case OpCodeConst.Conv_Ovf_I8_Un: { PushOperation(Inst.Conv_Ovf_I8_Un()); } return; case OpCodeConst.Conv_Ovf_U1_Un: { PushOperation(Inst.Conv_Ovf_U1_Un()); } return; case OpCodeConst.Conv_Ovf_U2_Un: { PushOperation(Inst.Conv_Ovf_U2_Un()); } return; case OpCodeConst.Conv_Ovf_U4_Un: { PushOperation(Inst.Conv_Ovf_U4_Un()); } return; case OpCodeConst.Conv_Ovf_U8_Un: { PushOperation(Inst.Conv_Ovf_U8_Un()); } return; case OpCodeConst.Conv_Ovf_I_Un: { PushOperation(Inst.Conv_Ovf_I_Un()); } return; case OpCodeConst.Conv_Ovf_U_Un: { PushOperation(Inst.Conv_Ovf_U_Un()); } return; case OpCodeConst.Box: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Box(type)); } return; case OpCodeConst.Newarr: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Newarr(type)); } return; case OpCodeConst.Ldlen: { PushOperation(Inst.Ldlen()); } return; case OpCodeConst.Ldelema: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Ldelema(type)); } return; case OpCodeConst.Ldelem_I1: { PushOperation(Inst.Ldelem_I1()); } return; case OpCodeConst.Ldelem_U1: { PushOperation(Inst.Ldelem_U1()); } return; case OpCodeConst.Ldelem_I2: { PushOperation(Inst.Ldelem_I2()); } return; case OpCodeConst.Ldelem_U2: { PushOperation(Inst.Ldelem_U2()); } return; case OpCodeConst.Ldelem_I4: { PushOperation(Inst.Ldelem_I4()); } return; case OpCodeConst.Ldelem_U4: { PushOperation(Inst.Ldelem_U4()); } return; case OpCodeConst.Ldelem_I8: { PushOperation(Inst.Ldelem_I8()); } return; case OpCodeConst.Ldelem_I: { PushOperation(Inst.Ldelem_I()); } return; case OpCodeConst.Ldelem_R4: { PushOperation(Inst.Ldelem_R4()); } return; case OpCodeConst.Ldelem_R8: { PushOperation(Inst.Ldelem_R8()); } return; case OpCodeConst.Ldelem_Ref: { PushOperation(Inst.Ldelem_Ref()); } return; case OpCodeConst.Stelem_I: { PushOperation(Inst.Stelem_I()); } return; case OpCodeConst.Stelem_I1: { PushOperation(Inst.Stelem_I1()); } return; case OpCodeConst.Stelem_I2: { PushOperation(Inst.Stelem_I2()); } return; case OpCodeConst.Stelem_I4: { PushOperation(Inst.Stelem_I4()); } return; case OpCodeConst.Stelem_I8: { PushOperation(Inst.Stelem_I8()); } return; case OpCodeConst.Stelem_R4: { PushOperation(Inst.Stelem_R4()); } return; case OpCodeConst.Stelem_R8: { PushOperation(Inst.Stelem_R8()); } return; case OpCodeConst.Stelem_Ref: { PushOperation(Inst.Stelem_Ref()); } return; case OpCodeConst.Ldelem: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Ldelem(type)); } return; case OpCodeConst.Stelem: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Stelem(type)); } return; case OpCodeConst.Unbox_Any: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Unbox_Any(type)); } return; case OpCodeConst.Conv_Ovf_I1: { PushOperation(Inst.Conv_Ovf_I1()); } return; case OpCodeConst.Conv_Ovf_U1: { PushOperation(Inst.Conv_Ovf_U1()); } return; case OpCodeConst.Conv_Ovf_I2: { PushOperation(Inst.Conv_Ovf_I2()); } return; case OpCodeConst.Conv_Ovf_U2: { PushOperation(Inst.Conv_Ovf_U2()); } return; case OpCodeConst.Conv_Ovf_I4: { PushOperation(Inst.Conv_Ovf_I4()); } return; case OpCodeConst.Conv_Ovf_U4: { PushOperation(Inst.Conv_Ovf_U4()); } return; case OpCodeConst.Conv_Ovf_I8: { PushOperation(Inst.Conv_Ovf_I8()); } return; case OpCodeConst.Conv_Ovf_U8: { PushOperation(Inst.Conv_Ovf_U8()); } return; case OpCodeConst.Refanyval: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Refanyval(type)); } return; case OpCodeConst.Ckfinite: { PushOperation(Inst.Ckfinite()); } return; case OpCodeConst.Mkrefany: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Mkrefany(type)); } return; case OpCodeConst.Ldtoken: { switch (Method.Module.ResolveMember(ReadStreamHead <int>())) { case Type type: PushOperation(Inst.Ldtoken(type)); break; case MethodInfo method: PushOperation(Inst.Ldtoken(method)); break; case FieldInfo field: PushOperation(Inst.Ldtoken(field)); break; default: throw new InvalidOperationException(); } throw new NotSupportedException(); } return; case OpCodeConst.Conv_U2: { PushOperation(Inst.Conv_U2()); } return; case OpCodeConst.Conv_U1: { PushOperation(Inst.Conv_U1()); } return; case OpCodeConst.Conv_I: { PushOperation(Inst.Conv_I()); } return; case OpCodeConst.Conv_Ovf_I: { PushOperation(Inst.Conv_Ovf_I()); } return; case OpCodeConst.Conv_Ovf_U: { PushOperation(Inst.Conv_Ovf_U()); } return; case OpCodeConst.Add_Ovf: { PushOperation(Inst.Add_Ovf()); } return; case OpCodeConst.Add_Ovf_Un: { PushOperation(Inst.Add_Ovf_Un()); } return; case OpCodeConst.Mul_Ovf: { PushOperation(Inst.Mul_Ovf()); } return; case OpCodeConst.Mul_Ovf_Un: { PushOperation(Inst.Mul_Ovf_Un()); } return; case OpCodeConst.Sub_Ovf: { PushOperation(Inst.Sub_Ovf()); } return; case OpCodeConst.Sub_Ovf_Un: { PushOperation(Inst.Sub_Ovf_Un()); } return; case OpCodeConst.Endfinally: { PushOperation(Inst.Endfinally()); } return; case OpCodeConst.Leave: { var offset = ReadStreamHead <int>(); PushOperation(Inst.Leave(GetOrAddLabel(currentIndex + OpCodes.Leave.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Leave_S: { var offset = ReadStreamHead <sbyte>(); PushOperation(Inst.Leave_S(GetOrAddLabel(currentIndex + OpCodes.Leave_S.GetTotalByteSize(offset) + offset))); } return; case OpCodeConst.Stind_I: { PushOperation(Inst.Stind_I()); } return; case OpCodeConst.Conv_U: { PushOperation(Inst.Conv_U()); } return; case OpCodeConst.Arglist: { PushOperation(Inst.Arglist()); } return; case OpCodeConst.Ceq: { PushOperation(Inst.Ceq()); } return; case OpCodeConst.Cgt: { PushOperation(Inst.Cgt()); } return; case OpCodeConst.Cgt_Un: { PushOperation(Inst.Cgt_Un()); } return; case OpCodeConst.Clt: { PushOperation(Inst.Clt()); } return; case OpCodeConst.Clt_Un: { PushOperation(Inst.Clt_Un()); } return; case OpCodeConst.Ldftn: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Ldftn(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Ldftn(ctor)); } } return; case OpCodeConst.Ldvirtftn: { var callable = Method.DeclaringType.Module.ResolveMethod(ReadStreamHead <int>()); if (callable is MethodInfo meth) { PushOperation(Inst.Ldvirtftn(meth)); } else if (callable is ConstructorInfo ctor) { PushOperation(Inst.Ldvirtftn(ctor)); } } return; case OpCodeConst.Ldarg: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Ldarg(value)); } return; case OpCodeConst.Ldarga: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Ldarga(value)); } return; case OpCodeConst.Starg: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Starg(value)); } return; case OpCodeConst.Ldloc: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Ldloc(value)); } return; case OpCodeConst.Ldloca: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Ldloca(value)); } return; case OpCodeConst.Stloc: { var value = ReadStreamHead <ushort>(); PushOperation(Inst.Stloc(value)); } return; case OpCodeConst.Localloc: { PushOperation(Inst.Localloc()); } return; case OpCodeConst.Endfilter: { PushOperation(Inst.Endfilter()); } return; case OpCodeConst.Unaligned: { var value = ReadStreamHead <byte>(); PushOperation(Inst.Unaligned(value)); } return; case OpCodeConst.Volatile: { PushOperation(Inst.Volatile()); } return; case OpCodeConst.Tailcall: { PushOperation(Inst.Tailcall()); } return; case OpCodeConst.Initobj: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Initobj(type)); } return; case OpCodeConst.Constrained: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Constrained(type)); } return; case OpCodeConst.Cpblk: { PushOperation(Inst.Cpblk()); } return; case OpCodeConst.Initblk: { PushOperation(Inst.Initblk()); } return; case OpCodeConst.Rethrow: { PushOperation(Inst.Rethrow()); } return; case OpCodeConst.Sizeof: { var type = Method.DeclaringType.Module.ResolveType(ReadStreamHead <int>()); PushOperation(Inst.Sizeof(type)); } return; case OpCodeConst.Refanytype: { PushOperation(Inst.Refanytype()); } return; case OpCodeConst.Readonly: { PushOperation(Inst.Readonly()); } return; default: throw new NotImplementedException(); } }
public unsafe override void Export(string outPath) { LabelBuilder labl; int lablLen, size; VoidPtr addr; Rebuild(); if (_audioSource != DataSource.Empty) { //Get strings labl = new LabelBuilder(); GetStrings(labl); lablLen = (labl.Count == 0) ? 0 : labl.GetSize(); size = WorkingUncompressed.Length + lablLen + _audioSource.Length; using (FileStream stream = new FileStream(outPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { stream.SetLength(size); using (FileMap map = FileMap.FromStreamInternal(stream, FileMapProtect.ReadWrite, 0, size)) { addr = map.Address; //Write header Memory.Move(addr, WorkingUncompressed.Address, (uint)WorkingUncompressed.Length); addr += WorkingUncompressed.Length; //Write strings if (lablLen > 0) labl.Write(addr); addr += lablLen; //Write data Memory.Move(addr, _audioSource.Address, (uint)_audioSource.Length); } } } else base.Export(outPath); }