예제 #1
0
파일: SUT.cs 프로젝트: istolboff/FixedTrie
        public MemoryAllocator()
        {
            _buffer = new byte[32 * 1024];

            var wholeBufferRegion = new BufferRegion(_buffer, regionLength: _buffer.Length, regionStart: 0);

            var(firtsFreeBlockReferenceHolder, initialFreeBlock) = wholeBufferRegion.Split(sizeof(short));

            var theOnlyFreeBlock = AllocationBlock.SetupBlock(initialFreeBlock, true);

            new FreeBlock(theOnlyFreeBlock).NextFreeBlockReference.Reset();

            _referenceToFirstFreeBlock = new MemoryReference(firtsFreeBlockReferenceHolder);
            _referenceToFirstFreeBlock.Set(theOnlyFreeBlock);
        }
예제 #2
0
        private int DrawMethod(Graphics g, MethodBody body, List <Line> lines, int x, int y, int lineOffset, int maxLines)
        {
            int addressx = x + _gutterWidth + 1;
            int codex    = addressx + _addressWidth + 1 + 6;
            int opcodex  = codex + _labelWidth / 3 + 6;
            int operandx = opcodex + _opcodeWidth;
            int refx     = 300;

            Brush codeBrush    = this.Enabled ? _instrFontBrush : _disabledFontBrush;
            Brush addressBrush = this.Enabled ? _addressFontBrush : _disabledFontBrush;

            // -- lines --
            for (int n = lineOffset; n < lines.Count; n++)
            {
                Line        line  = lines[n];
                Instruction instr = line.Instruction;

                if (body.UserTop + n == _highlightedLine)
                {
                    g.FillRectangle(SystemBrushes.GradientInactiveCaption, codex, y, this.ClientRectangle.Width - codex - 5, _lineHeight + 2);
                }

                switch (line.Type)
                {
                case LineType.Header:
                {
                    string fullName = string.Format("// {0}::{1}", body.Module.Name, body.Name);
                    g.DrawString(fullName, _font, _commentFontBrush, codex, y);
                    g.DrawLine(_commentLinePen, codex + (_charSize.Width * (fullName.Length + 1)), y + (_charSize.Height / 2.0f), this.ClientRectangle.Width - 10, y + (_charSize.Height / 2.0f));
                }
                break;

                case LineType.Footer:
                {
                }
                break;

                case LineType.Label:
                {
                    g.DrawString(instr.Label.Name + ":", _font, _labelFontBrush, codex, y, _stringFormat);
                }
                break;

                case LineType.Instruction:
                {
                    // Gutter
                    if (instr.Breakpoint != null)
                    {
                        Image icon = (instr.Breakpoint.Enabled == true) ? _breakpointOnIcon : _breakpointOffIcon;
                        g.DrawImage(icon, x + 2, y, 15, 15);
                    }
                    if ((_debugger.State != DebuggerState.Running) && (_debugger.PC == instr.Address))
                    {
                        g.DrawImage(_statementIcon, x + 3, y, 14, 15);
                    }

                    // Address
                    g.DrawString(string.Format("{0:X8}", instr.Address), _font, addressBrush, addressx + 6, y, _stringFormat);

                    // Instruction
                    int realx = operandx;
                    if (instr.Code == 0x0)
                    {
                        g.DrawString("nop", _font, _disabledFontBrush, opcodex, y, _stringFormat);
                    }
                    else
                    {
                        if (instr.Opcode == null)
                        {
                            g.DrawString("UNKNOWN", _font, codeBrush, opcodex, y, _stringFormat);
                        }
                        else
                        {
                            g.DrawString(instr.Opcode.ToString(), _font, codeBrush, opcodex, y, _stringFormat);

                            // Operands
                            for (int m = 0; m < instr.Operands.Length; m++)
                            {
                                Operand op        = instr.Operands[m];
                                string  resolved  = instr.GetResolvedOperandString(op, this.UseHex);
                                Brush   fontBrush = codeBrush;
                                switch (op.Type)
                                {
                                case OperandType.BranchTarget:
                                    fontBrush = _referenceFontBrush;
                                    break;

                                case OperandType.JumpTarget:
                                    fontBrush = _referenceFontBrush;
                                    break;
                                }
                                g.DrawString(resolved, _font, fontBrush, realx, y, _stringFormat);
                                realx += ( int )_charSize.Width * resolved.Length;

                                bool last = (m == instr.Operands.Length - 1);
                                if (last == false)
                                {
                                    g.DrawString(", ", _font, codeBrush, realx - 2, y, _stringFormat);
                                    realx += ( int )_charSize.Width * 2 - 2;
                                }
                            }
                        }
                    }

                    MemoryReference memRef = instr.Reference as MemoryReference;
                    if (memRef != null)
                    {
                        Variable var = _debugger.DebugHost.Database.FindSymbol(memRef.Address) as Variable;
                        string   name;
                        if ((var != null) && (var.Name != null))
                        {
                            name = var.Name;
                        }
                        else
                        {
                            name = memRef.Address.ToString("X8");
                        }
                        g.DrawString(name, _font, _referenceFontBrush, refx, y, _stringFormat);
                    }

                    // Annotations
                    //if( instr.Annotation != null )
                    //	g.DrawString( instr.Annotation, _font, _referenceFontBrush, realx + 10, y, _stringFormat );

                    // Comments
                    // TODO _commentFontBrush
                }
                break;
                }

                y += _lineHeight;

                maxLines--;
                if (maxLines == 0)
                {
                    break;
                }
            }

            return(y);
        }