Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <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));
            }
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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);
            }
        }
Ejemplo n.º 7
0
        /// <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);
            }
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
 public Value GetValue(VariableRef var) =>
 CodeGenerator.SSABuilder.GetValue(CFGNode, var);
Ejemplo n.º 10
0
 public void SetValue(VariableRef var, Value value) =>
 CodeGenerator.SSABuilder.SetValue(CFGNode, var, value);
Ejemplo n.º 11
0
 public Value GetValue(VariableRef var) =>
 CodeGenerator.SSABuilder.GetValue(BasicBlock, var);
Ejemplo n.º 12
0
 public void SetValue(VariableRef var, Value value) =>
 CodeGenerator.SSABuilder.SetValue(BasicBlock, var, value);