public void GetBytes_LoadStringInstruction() { var instruction = new LoadStringInstruction("helloWorld"); var expectedBytes = InstructionByteBuilder.Create() .Opcode(Opcode.Load, LoadKind.String, "helloWorld") .AsSpan(); Assert.True(expectedBytes.SequenceEqual(instruction.GetBytes())); }
protected override void VisitLoadStringInstruction(LoadStringInstruction instruction) { var cilString = new CilString(instruction.StringValue); var reference = ManagedMemory.Store(cilString); ControlState.EvaluationStack.PushValue(reference); ControlState.MoveToNextInstruction(); }
public override CILInstructionString BuildNode(ParseTreeNode node) { CILInstructionString result = null; var instrStringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_STRING); var ldstrParseTreeNode = instrStringParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldstr); if (ldstrParseTreeNode != null) { result = new LoadStringInstruction(); } if (result != null) { var compQstringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.compQstring); result.StringValue = CompQstringParseTreeNodeHelper.GetValue(compQstringParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction string."); }
public void ToString_LoadStringInstruction() { var loadInstruction = new LoadStringInstruction("helloWorld"); Assert.Equal("ldstr helloWorld", loadInstruction.ToString()); }
public void VisitLoadString(LoadStringInstruction instruction) => IncrementCallCount(nameof(VisitLoadString));
protected abstract void VisitLoadStringInstruction(LoadStringInstruction instruction);