예제 #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
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 public void replace(iterator_base where, DNode with)
 {
     replace(where.node, with);
     where.node = with;
 }
예제 #13
0
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 public iterator_base(DNode node)
 {
     node_ = node;
 }
예제 #14
0
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 public reverse_iterator(DNode node)
     : base(node)
 {
 }
예제 #15
0
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 public void add(DNode node)
 {
     insertBefore(head_, node);
 }
예제 #16
0
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 public NodeList()
 {
     head_      = new DSentinel();
     head_.prev = head_;
     head_.next = head_;
 }
예제 #17
0
파일: NodeList.cs 프로젝트: z4cH3r/Spedit
 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
파일: Nodes.cs 프로젝트: not1ce111/Spedit
 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
파일: NodeBlock.cs 프로젝트: z4cH3r/Spedit
 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");
            }
        }