Example #1
0
        protected Node Transform(Node node, BasicBlock block, TypeSystem typeSystem, ExpressionVariables variables)
        {
            var newNode = new InstructionNode(node.Instruction, block);

            // todo: determine result type
            // todo: determine size

            int operandIndex = 0;

            foreach (var nodeOperand in node.ParentNodes)
            {
                if (nodeOperand.NodeType == NodeType.Expression)
                {
                    // todo: expressions
                }
                else if (nodeOperand.NodeType == NodeType.FixedIntegerConstant)
                {
                    // todo
                }
                else if (nodeOperand.NodeType == NodeType.FixedDoubleConstant)
                {
                    // todo
                }
                else if (nodeOperand.NodeType == NodeType.ConstantVariable)
                {
                    newNode.SetOperand(operandIndex++, variables.GetOperand(nodeOperand.Alias));
                    continue;
                }
                else if (nodeOperand.NodeType == NodeType.PhyiscalRegister)
                {
                    var type = typeSystem.BuiltIn.I4;                       // todo
                    Operand.CreateCPURegister(type, node.PhysicalRegister);
                    continue;
                }
                else if (nodeOperand.NodeType == NodeType.VirtualRegister)
                {
                    newNode.SetOperand(operandIndex++, variables.GetOperand(nodeOperand.Alias));
                    continue;
                }
                else if (nodeOperand.NodeType == NodeType.OperandVariable)
                {
                    newNode.SetOperand(operandIndex++, variables.GetOperand(nodeOperand.Alias));
                    continue;
                }

                throw new CompilerException("Error");
            }

            return(null);
        }
Example #2
0
        protected bool ValidateOperand(Operand operand, ExpressionVariables variables)
        {
            if (operand == null)
            {
                return(false);
            }

            if (NodeType == NodeType.Instruction)
            {
                return(false);
            }

            if (NodeType == NodeType.PhyiscalRegister && operand.IsCPURegister && operand.Register == PhysicalRegister)
            {
                return(true);
            }

            if (NodeType == NodeType.VirtualRegister && operand.IsVirtualRegister)
            {
                return(true);
            }

            if (NodeType == NodeType.FixedIntegerConstant && operand.IsResolvedConstant && operand.ConstantUnsignedLongInteger == ConstantInteger)
            {
                return(true);
            }

            if (NodeType == NodeType.ConstantVariable && operand.IsConstant)
            {
                var variableOperand = variables.GetOperand(Alias);

                if (variableOperand == null)
                {
                    variables.SetOperand(Alias, operand);
                    return(true);
                }
                else
                {
                    return(variableOperand.ConstantUnsignedInteger == operand.ConstantUnsignedInteger);
                }
            }

            if (NodeType == NodeType.OperandVariable)
            {
                var variableOperand = variables.GetOperand(Alias);

                if (variableOperand == null)
                {
                    variables.SetOperand(Alias, operand);
                    return(true);
                }
                else
                {
                    return(variableOperand == operand);
                }
            }

            if (NodeType == NodeType.TypeVariable)
            {
                var variableType = variables.GetType(Alias);

                if (variableType == null)
                {
                    variables.SetType(Alias, operand.Type);
                    return(true);
                }
                else
                {
                    return(variableType == operand.Type);
                }
            }

            return(false);
        }