Пример #1
0
 public void insertAfter(DNode at, DNode node)
 {
     node.next = at;
     node.prev = at.prev;
     at.prev.next = node;
     at.prev = node;
 }
Пример #2
0
 public void remove(DNode node)
 {
     node.prev.next = node.next;
     node.next.prev = node.prev;
     node.next = null;
     node.prev = null;
 }
Пример #3
0
 public void replace(DNode at, DNode with)
 {
     with.prev = at.prev;
     with.next = at.next;
     at.prev.next = with;
     at.next.prev = with;
     at.prev = null;
     at.next = null;
 }
Пример #4
0
 public AbstractStack(AbstractStack other)
 {
     stack_ = new List<StackEntry>();
     for (int i = 0; i < other.stack_.Count; i++)
         stack_.Add(new StackEntry(other.stack_[i].declaration, other.stack_[i].assignment));
     args_ = new StackEntry[other.args_.Length];
     for (int i = 0; i < args_.Length; i++)
         args_[i] = new StackEntry(other.args_[i].declaration, other.args_[i].assignment);
     pri_ = other.pri_;
     alt_ = other.alt_;
 }
Пример #5
0
 public StackEntry(DDeclareLocal decl, DNode assn)
 {
     declaration = decl;
     assignment = assn;
 }
Пример #6
0
 public void add(DNode node)
 {
     insertBefore(head_, node);
 }
Пример #7
0
 public void replace(NodeList.iterator_base where, DNode with)
 {
     with.setBlock(this);
     nodes_.replace(where, with);
 }
Пример #8
0
 public iterator(DNode node)
     : base(node)
 {
 }
Пример #9
0
 public reverse_iterator(DNode node)
     : base(node)
 {
 }
Пример #10
0
 public Node(DNode expression)
 {
     expression_ = expression;
 }
Пример #11
0
        private string buildExpression(DNode node)
        {
            switch (node.type)
            {
            case NodeType.Constant:
                return(buildConstant((DConstant)node));

            case NodeType.Boolean:
                return(buildBoolean((DBoolean)node));

            case NodeType.Float:
                return(buildFloat((DFloat)node));

            case NodeType.Character:
                return(buildCharacter((DCharacter)node));

            case NodeType.Function:
                return(buildFunction((DFunction)node));

            case NodeType.Load:
                return(buildLoad((DLoad)node));

            case NodeType.String:
                return(buildString(((DString)node).value));

            case NodeType.LocalRef:
                return(buildLocalRef((DLocalRef)node));

            case NodeType.ArrayRef:
                return(buildArrayRef((DArrayRef)node));

            case NodeType.Unary:
                return(buildUnary((DUnary)node));

            case NodeType.Binary:
                return(buildBinary((DBinary)node));

            case NodeType.SysReq:
                return(buildSysReq((DSysReq)node));

            case NodeType.Call:
                return(buildCall((DCall)node));

            case NodeType.DeclareLocal:
            {
                var local = (DDeclareLocal)node;
                return(local.var.name);
            }

            case NodeType.TempName:
            {
                var name = (DTempName)node;
                return(name.name);
            }

            case NodeType.Global:
            {
                var global = (DGlobal)node;
                return(global.var.name);
            }

            case NodeType.InlineArray:
            {
                return(buildInlineArray((DInlineArray)node));
            }

            default:
                throw new Exception("waT");
            }
        }
Пример #12
0
 public void replace(iterator_base where, DNode with)
 {
     replace(where.node, with);
     where.node = with;
 }
Пример #13
0
 public iterator_base(DNode node)
 {
     node_ = node;
 }
Пример #14
0
 public reverse_iterator(DNode node)
     : base(node)
 {
 }
Пример #15
0
 public void add(DNode node)
 {
     insertBefore(head_, node);
 }
Пример #16
0
 public NodeList()
 {
     head_      = new DSentinel();
     head_.prev = head_;
     head_.next = head_;
 }
Пример #17
0
 public iterator(DNode node)
     : base(node)
 {
 }
Пример #18
0
 public void replace(DNode where, DNode with)
 {
     with.setBlock(this);
     nodes_.replace(where, with);
 }
Пример #19
0
 public void prepend(DNode node)
 {
     node.setBlock(this);
     nodes_.insertBefore(nodes_.last, node);
 }
Пример #20
0
 public DReturn(DNode value) : base(value)
 {
 }
Пример #21
0
 public void replace(DNode where, DNode with)
 {
     with.setBlock(this);
     nodes_.replace(where, with);
 }
Пример #22
0
        private string buildLoadStoreRef(DNode node)
        {
            switch (node.type)
            {
                case NodeType.TempName:
                    {
                        DTempName temp = (DTempName)node;
                        return temp.name;
                    }

                case NodeType.DeclareLocal:
                    {
                        DDeclareLocal local = (DDeclareLocal)node;
                        return local.var.name;
                    }

                case NodeType.ArrayRef:
                    return buildArrayRef((DArrayRef)node);

                case NodeType.LocalRef:
                    {
                        DLocalRef lref = (DLocalRef)node;
                        DDeclareLocal local = lref.local;
                        if (local.var.type == VariableType.ArrayReference || local.var.type == VariableType.Array)
                            return local.var.name + "[0]";
                        if (local.var.type == VariableType.Reference)
                            return local.var.name;
                        throw new Exception("unknown local ref");
                    }

                case NodeType.Global:
                    {
                        DGlobal global = (DGlobal)node;
                        if (global.var == null)
                            return "__unk";
                        return global.var.name;
                    }

                case NodeType.Load:
                    {
                        DLoad load = (DLoad)node;

                        Debug.Assert(load.from.type == NodeType.DeclareLocal ||
                                        load.from.type == NodeType.ArrayRef ||
                                        load.from.type == NodeType.Global);
                        return buildLoadStoreRef(load.from);
                    }

                default:
                    throw new Exception("unknown load");
            }
        }
Пример #23
0
 private void propagateInputs(DNode lhs, DNode rhs)
 {
     lhs.typeSet.addTypes(rhs.typeSet);
     rhs.typeSet.addTypes(lhs.typeSet);
 }
Пример #24
0
        private string buildExpression(DNode node)
        {
            switch (node.type)
            {
                case NodeType.Constant:
                    return buildConstant((DConstant)node);

                case NodeType.Boolean:
                    return buildBoolean((DBoolean)node);

                case NodeType.Float:
                    return buildFloat((DFloat)node);

                case NodeType.Character:
                    return buildCharacter((DCharacter)node);

                case NodeType.Function:
                    return buildFunction((DFunction)node);

                case NodeType.Load:
                    return buildLoad((DLoad)node);

                case NodeType.String:
                    return buildString(((DString)node).value);

                case NodeType.LocalRef:
                    return buildLocalRef((DLocalRef)node);

                case NodeType.ArrayRef:
                    return buildArrayRef((DArrayRef)node);

                case NodeType.Unary:
                    return buildUnary((DUnary)node);

                case NodeType.Binary:
                    return buildBinary((DBinary)node);

                case NodeType.SysReq:
                    return buildSysReq((DSysReq)node);

                case NodeType.Call:
                    return buildCall((DCall)node);

                case NodeType.DeclareLocal:
                    {
                        DDeclareLocal local = (DDeclareLocal)node;
                        return local.var.name;
                    }

                case NodeType.TempName:
                    {
                        DTempName name = (DTempName)node;
                        return name.name;
                    }

                case NodeType.Global:
                    {
                        DGlobal global = (DGlobal)node;
                        return global.var.name;
                    }

                case NodeType.InlineArray:
                    {
                        return buildInlineArray((DInlineArray)node);
                    }

                default:
                    throw new Exception("waT");
            }
        }
Пример #25
0
 private static DNode GuessArrayBase(DNode op1, DNode op2)
 {
     if (op1.usedAsArrayIndex)
         return op2;
     if (op2.usedAsArrayIndex)
         return op1;
     if (op1.type == NodeType.ArrayRef ||
         op1.type == NodeType.LocalRef ||
         IsArray(op1.typeSet))
     {
         return op1;
     }
     if (op2.type == NodeType.ArrayRef ||
         op2.type == NodeType.LocalRef ||
         IsArray(op2.typeSet))
     {
         return op2;
     }
     return null;
 }
Пример #26
0
 public void add(DNode node)
 {
     node.setBlock(this);
     nodes_.add(node);
 }
Пример #27
0
 public NodeList()
 {
     head_ = new DSentinel();
     head_.prev = head_;
     head_.next = head_;
 }
Пример #28
0
 public iterator_base(DNode node)
 {
     node_ = node;
 }
Пример #29
0
 public StackEntry(DDeclareLocal decl, DNode assn)
 {
     declaration = decl;
     assignment  = assn;
 }
Пример #30
0
 public void set(int offset, DNode value)
 {
     entry(offset).assignment = value;
 }
Пример #31
0
        private void writeStatement(DNode node)
        {
            switch (node.type)
            {
                case NodeType.DeclareLocal:
                    writeLocal((DDeclareLocal)node);
                    break;

                case NodeType.DeclareStatic:
                    writeStatic((DDeclareStatic)node);
                    break;

                case NodeType.Jump:
                case NodeType.JumpCondition:
                case NodeType.Return:
                case NodeType.Switch:
                    break;

                case NodeType.SysReq:
                    writeSysReq((DSysReq)node);
                    break;

                case NodeType.Call:
                    {
                        writeCall((DCall)node);
                        break;
                    }

                case NodeType.Store:
                    writeStore((DStore)node);
                    break;

                case NodeType.BoundsCheck:
                    break;

                case NodeType.TempName:
                    writeTempName((DTempName)node);
                    break;

                case NodeType.IncDec:
                    writeIncDec((DIncDec)node);
                    break;

                default:
                    throw new Exception(String.Format("unknown op ({0})", node.type.ToString()));
            }
        }
Пример #32
0
 public void prepend(DNode node)
 {
     node.setBlock(this);
     nodes_.insertBefore(nodes_.last, node);
 }
Пример #33
0
 public void replace(iterator_base where, DNode with)
 {
     replace(where.node, with);
     where.node = with;
 }
Пример #34
0
 private void propagateInputs(DNode lhs, DNode rhs)
 {
     lhs.typeSet.addTypes(rhs.typeSet);
     rhs.typeSet.addTypes(lhs.typeSet);
 }
Пример #35
0
 public void set(Register reg, DNode node)
 {
     if (reg == Register.Pri)
         pri_ = node;
     else
         alt_ = node;
 }
Пример #36
0
        public override void visit(DConstant node)
        {
            DNode replacement = null;

            if (node.typeSet.numTypes == 1)
            {
                var tu = node.typeSet[0];
                switch (tu.kind)
                {
                case TypeUnit.Kind.Cell:
                {
                    switch (tu.type.type)
                    {
                    case CellType.Bool:
                        replacement = new DBoolean(node.value != 0);
                        break;

                    case CellType.Character:
                        replacement = new DCharacter(Convert.ToChar(node.value));
                        break;

                    case CellType.Float:
                    {
                        //Debug.Assert(BitConverter.IsLittleEndian);
                        var bits = BitConverter.GetBytes(node.value);
                        var v    = BitConverter.ToSingle(bits, 0);
                        replacement = new DFloat(v);
                        break;
                    }

                    case CellType.Function:
                    {
                        var p        = graph_.file.publics[node.value >> 1];
                        var function = graph_.file.lookupFunction(p.address);
                        replacement = new DFunction(p.address, function);
                        break;
                    }

                    default:
                        return;
                    }
                    break;
                }

                case TypeUnit.Kind.Array:
                {
                    replacement = ConstantToReference(node, tu);
                    break;
                }

                default:
                    return;
                }
            }

            if (replacement == null && node.usedAsReference)
            {
                replacement = ConstantToReference(node, null);
            }

            if (replacement != null)
            {
                block_.nodes.insertAfter(node, replacement);
                node.replaceAllUsesWith(replacement);
            }
        }
Пример #37
0
        private void joinRegs(Register reg, DNode value)
        {
            if (value == null || stack_.reg(reg) == value)
                return;
            if (stack_.reg(reg) == null)
            {
                stack_.set(reg, value);
                return;
            }

            DPhi phi;
            DNode node = stack_.reg(reg);
            if (node.type != NodeType.Phi || node.block != this)
            {
                phi = new DPhi(node);
                stack_.set(reg, phi);
                add(phi);
            }
            else 
            {
                phi = (DPhi)node;
            }
            phi.addInput(value);
        }
Пример #38
0
 public Node(DNode expression)
 {
     expression_ = expression;
 }
Пример #39
0
 public void add(DNode node)
 {
     node.setBlock(this);
     nodes_.add(node);
 }
Пример #40
0
 public void append(DNode expression)
 {
     nodes_.Add(new Node(expression));
 }
Пример #41
0
 public void replace(NodeList.iterator_base where, DNode with)
 {
     with.setBlock(this);
     nodes_.replace(where, with);
 }
Пример #42
0
 public void set(int offset, DNode value)
 {
     entry(offset).assignment = value;
 }
Пример #43
0
 private static bool IsReallyLikelyArrayCompute(DNode node, DNode abase)
 {
     if (abase.type == NodeType.ArrayRef)
         return true;
     if (IsArray(abase.typeSet))
         return true;
     foreach (DUse use in node.uses)
     {
         if (use.node.type == NodeType.Store || use.node.type == NodeType.Load)
             return true;
     }
     return false;
 }
Пример #44
0
 private static bool IsArrayOpCandidate(DNode node)
 {
     if (node.type == NodeType.Load || node.type == NodeType.Store)
         return true;
     if (node.type == NodeType.Binary)
     {
         DBinary bin = (DBinary)node;
         return bin.spop == SPOpcode.add;
     }
     return false;
 }
Пример #45
0
 public void append(DNode expression)
 {
     nodes_.Add(new Node(expression));
 }
Пример #46
0
 private static Signature SignatureOf(DNode node)
 {
     if (node.type == NodeType.Call)
         return ((DCall)node).function;
     return ((DSysReq)node).native;
 }
Пример #47
0
        private void visitSignature(DNode call, Signature signature)
        {
            for (int i = 0; i < call.numOperands && i < signature.args.Length; i++)
            {
                DNode node = call.getOperand(i);
                Argument arg = i < signature.args.Length
                               ? signature.args[i]
                               : signature.args[signature.args.Length - 1];

                TypeUnit tu = TypeUnit.FromArgument(arg);
                if (tu != null)
                    node.addType(tu);
            }

            // Peek ahead for constants.
            if (signature.args.Length > 0 &&
                signature.args[signature.args.Length - 1].type == VariableType.Variadic)
            {
                for (int i = signature.args.Length - 1; i < call.numOperands; i++)
                {
                    DNode node = call.getOperand(i);
                    if (node.type != NodeType.Constant)
                        continue;

                    DConstant constNode = (DConstant)node;
                    Variable global = graph_.file.lookupGlobal(constNode.value);
                    if (global != null)
                    {
                        call.replaceOperand(i, new DGlobal(global));
                        continue;
                    }

                    // Guess a string...
                    call.replaceOperand(i, new DString(graph_.file.stringFromData(constNode.value)));
                }
            }
        }
Пример #48
0
        private string buildLoadStoreRef(DNode node)
        {
            switch (node.type)
            {
            case NodeType.TempName:
            {
                var temp = (DTempName)node;
                return(temp.name);
            }

            case NodeType.DeclareLocal:
            {
                var local = (DDeclareLocal)node;
                return(local.var.name);
            }

            case NodeType.ArrayRef:
                return(buildArrayRef((DArrayRef)node));

            case NodeType.LocalRef:
            {
                var lref  = (DLocalRef)node;
                var local = lref.local;
                if (local.var.type == VariableType.ArrayReference || local.var.type == VariableType.Array)
                {
                    return(local.var.name + "[0]");
                }

                if (local.var.type == VariableType.Reference)
                {
                    return(local.var.name);
                }

                throw new Exception("unknown local ref");
            }

            case NodeType.Global:
            {
                var global = (DGlobal)node;
                if (global.var == null)
                {
                    return("__unk");
                }

                return(global.var.name);
            }

            case NodeType.Load:
            {
                var load = (DLoad)node;

                Debug.Assert(load.from.type == NodeType.DeclareLocal ||
                             load.from.type == NodeType.ArrayRef ||
                             load.from.type == NodeType.Global);
                return(buildLoadStoreRef(load.from));
            }

            default:
                throw new Exception("unknown load");
            }
        }