/// <summary> /// Duplicates the element at the top of the stack. /// </summary> public void Dup() { var var = new VariableRef(StackCounter - 1, VariableRefType.Stack); var targetVar = new VariableRef(StackCounter++, VariableRefType.Stack); SetValue(targetVar, GetValue(var)); }
/// <summary> /// Loads a variable. This can be an argument or a local reference. /// </summary> /// <param name="block">The current basic block.</param> /// <param name="builder">The current builder.</param> /// <param name="var">The variable reference.</param> private void LoadVariable( Block block, IRBuilder builder, VariableRef var) { Debug.Assert( var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local); var addressOrValue = block.GetValue(var); var type = variableTypes[var]; if (variables.Contains(var)) { block.Push(CreateLoad( builder, addressOrValue, type.Item1, type.Item2)); } else { block.Push(LoadOntoEvaluationStack( builder, addressOrValue, type.Item2)); } }
/// <summary> /// Pops a value from the execution stack. /// </summary> /// <returns>The popped value.</returns> public Value Pop() { var var = new VariableRef(--StackCounter, VariableRefType.Stack); var value = GetValue(var); CodeGenerator.SSABuilder.RemoveValue(CFGNode, var); return(value); }
/// <summary> /// Loads a variable address. This can be an argument or a local reference. /// </summary> /// <param name="var">The variable reference.</param> private void LoadVariableAddress(VariableRef var) { Location.Assert( var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local); // Check whether we can load the address of a non-SSA value Location.Assert(variables.Contains(var)); var address = Block.GetValue(var); Block.Push(address); }
/// <summary> /// Loads a variable address. This can be an argument or a local reference. /// </summary> /// <param name="block">The current basic block.</param> /// <param name="builder">The current builder.</param> /// <param name="var">The variable reference.</param> private void LoadVariableAddress( Block block, IRBuilder builder, VariableRef var) { Debug.Assert( var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local); Debug.Assert(variables.Contains(var), "Cannot load address of SSA value"); var address = block.GetValue(var); block.Push(address); }
/// <summary> /// Stores a value to the given variable slot. /// </summary> /// <param name="var">The variable reference.</param> private void StoreVariable(VariableRef var) { Location.Assert( var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local); var variableType = variableTypes[var]; var storeValue = Block.Pop( variableType.Item1, variableType.Item2); if (variables.Contains(var)) { var address = Block.GetValue(var); Builder.CreateStore(Location, address, storeValue); } else { Block.SetValue(var, storeValue); } }
/// <summary> /// Stores a value to the argument with index idx. /// </summary> /// <param name="block">The current basic block.</param> /// <param name="builder">The current builder.</param> /// <param name="var">The variable reference.</param> private void StoreVariable( Block block, IRBuilder builder, VariableRef var) { Debug.Assert( var.RefType == VariableRefType.Argument || var.RefType == VariableRefType.Local); var variableType = variableTypes[var]; var storeValue = block.Pop(variableType.Item1, variableType.Item2); if (variables.Contains(var)) { var address = block.GetValue(var); builder.CreateStore(address, storeValue); } else { block.SetValue(var, storeValue); } }
/// <summary> /// Pushes the value of the given type onto the execution stack. /// </summary> /// <param name="value">The value to push.</param> public void Push(Value value) { var newStackSlot = new VariableRef(StackCounter++, VariableRefType.Stack); SetValue(newStackSlot, value); }
public Value GetValue(VariableRef var) => CodeGenerator.SSABuilder.GetValue(CFGNode, var);
public void SetValue(VariableRef var, Value value) => CodeGenerator.SSABuilder.SetValue(CFGNode, var, value);
public Value GetValue(VariableRef var) => CodeGenerator.SSABuilder.GetValue(BasicBlock, var);
public void SetValue(VariableRef var, Value value) => CodeGenerator.SSABuilder.SetValue(BasicBlock, var, value);