コード例 #1
0
        public void SetName(string name)
        {
            bool rename = false;

            foreach (BasicBlock bb in parentFunction.GetBasicBlocks())
            {
                if (bb == this)
                {
                    continue;
                }

                if (bb.GetName() == name)
                {
                    rename = true;
                    break;
                }
            }

            if (rename)
            {
                // Try with new names until there's one new.
                int  extra = 1;
                bool next  = true;
                while (next)
                {
                    string newName = name + extra++;
                    next = false;

                    foreach (BasicBlock bb in parentFunction.GetBasicBlocks())
                    {
                        if (bb != this && bb.GetName() == newName)
                        {
                            // Try again with a new name.
                            next = true;
                            break;
                        }
                    }

                    // At last got a suitable name.
                    if (!next)
                    {
                        this.name = newName;
                        return;
                    }
                }
            }

            this.name = name;
        }
コード例 #2
0
ファイル: DebugEmitter.cs プロジェクト: MilkTool/chela
        public void AddFunction(Function function)
        {
            // Store the function.
            functions.Add(function);

            // Register the local scopes.
            for (int i = 0; i < function.GetLexicalScopeCount(); ++i)
            {
                LexicalScope scope = function.GetLexicalScope(i);

                // Register the position filename.
                TokenPosition pos = scope.Position;
                if (pos == null)
                {
                    pos = NullPosition;
                }
                AddFileName(pos.GetFileName());
            }

            // Register the variables names and positions.
            foreach (LocalVariable local in function.GetLocals())
            {
                // Register the local name.
                AddString(local.GetName());

                // Register the position filename
                TokenPosition localPos = local.Position;
                if (localPos == null)
                {
                    localPos = NullPosition;
                }
                AddFileName(localPos.GetFileName());
            }

            // Register the filenames.
            string lastFilename = null;

            foreach (BasicBlock bb in function.GetBasicBlocks())
            {
                foreach (Instruction instruction in bb.GetInstructions())
                {
                    // Ignore instructions without position.
                    TokenPosition position = instruction.GetPosition();
                    if (position == null)
                    {
                        position = NullPosition;
                    }

                    // Set the filename.
                    string filename = position.GetFileName();
                    if (position != null && lastFilename != filename)
                    {
                        AddFileName(filename);
                        lastFilename = filename;
                    }
                }
            }
        }
コード例 #3
0
ファイル: DebugEmitter.cs プロジェクト: ronsaldo/chela
        public void AddFunction(Function function)
        {
            // Store the function.
            functions.Add(function);

            // Register the local scopes.
            for(int i = 0; i < function.GetLexicalScopeCount(); ++i)
            {
                LexicalScope scope = function.GetLexicalScope(i);

                // Register the position filename.
                TokenPosition pos = scope.Position;
                if(pos == null)
                    pos = NullPosition;
                AddFileName(pos.GetFileName());
            }

            // Register the variables names and positions.
            foreach(LocalVariable local in function.GetLocals())
            {
                // Register the local name.
                AddString(local.GetName());

                // Register the position filename
                TokenPosition localPos = local.Position;
                if(localPos == null)
                    localPos = NullPosition;
                AddFileName(localPos.GetFileName());
            }

            // Register the filenames.
            string lastFilename = null;
            foreach(BasicBlock bb in function.GetBasicBlocks())
            {
                foreach(Instruction instruction in bb.GetInstructions())
                {
                    // Ignore instructions without position.
                    TokenPosition position = instruction.GetPosition();
                    if(position == null)
                        position = NullPosition;

                    // Set the filename.
                    string filename = position.GetFileName();
                    if(position != null && lastFilename != filename)
                    {
                        AddFileName(filename);
                        lastFilename = filename;
                    }
                }
            }
        }
コード例 #4
0
ファイル: DebugEmitter.cs プロジェクト: ronsaldo/chela
        private void EmitFunctionDebugInfo(ModuleWriter writer, Function function)
        {
            // Emit the function id.
            uint functionId = function.GetSerialId();
            writer.Write(functionId);

            // Emit the function position.
            EmitPosition(writer, function.Position);

            // Emit the lexical scopes.
            byte numscopes = (byte)function.GetLexicalScopeCount();
            writer.Write(numscopes);
            for(int i = 0; i < numscopes; ++i)
            {
                // Get the lexical scope.
                LexicalScope scope = function.GetLexicalScope(i);

                // Find the parent index.
                byte parentIndex = 0;
                LexicalScope parentScope = scope.GetParentScope() as LexicalScope;
                if(parentScope != null)
                    parentIndex = (byte)parentScope.Index;

                // Emit the parent scope.
                writer.Write(parentIndex);

                // Write the scope position.
                EmitPosition(writer, scope.Position);
            }

            // Emit the local data and positions.
            ushort localCount = (ushort)function.GetLocalCount();
            writer.Write(localCount);
            foreach(LocalVariable local in function.GetLocals())
            {
                // Get the local scope.
                byte localScope = 0;
                LexicalScope scope = local.GetParentScope() as LexicalScope;
                if(scope != null)
                    localScope = (byte)scope.Index;

                // Write the variable data.
                writer.Write(AddString(local.GetName()));
                writer.Write(localScope);
                writer.Write((byte)local.Type);
                writer.Write((byte)local.ArgumentIndex);
                EmitPosition(writer, local.Position);
            }

            // Emit each basic block position information.
            ushort blockCount = (ushort)function.GetBasicBlockCount();
            writer.Write(blockCount);
            foreach(BasicBlock bb in function.GetBasicBlocks())
                EmitBasicBlockDebugInfo(writer, bb);
        }
コード例 #5
0
ファイル: DebugEmitter.cs プロジェクト: MilkTool/chela
        private void EmitFunctionDebugInfo(ModuleWriter writer, Function function)
        {
            // Emit the function id.
            uint functionId = function.GetSerialId();

            writer.Write(functionId);

            // Emit the function position.
            EmitPosition(writer, function.Position);

            // Emit the lexical scopes.
            byte numscopes = (byte)function.GetLexicalScopeCount();

            writer.Write(numscopes);
            for (int i = 0; i < numscopes; ++i)
            {
                // Get the lexical scope.
                LexicalScope scope = function.GetLexicalScope(i);

                // Find the parent index.
                byte         parentIndex = 0;
                LexicalScope parentScope = scope.GetParentScope() as LexicalScope;
                if (parentScope != null)
                {
                    parentIndex = (byte)parentScope.Index;
                }

                // Emit the parent scope.
                writer.Write(parentIndex);

                // Write the scope position.
                EmitPosition(writer, scope.Position);
            }

            // Emit the local data and positions.
            ushort localCount = (ushort)function.GetLocalCount();

            writer.Write(localCount);
            foreach (LocalVariable local in function.GetLocals())
            {
                // Get the local scope.
                byte         localScope = 0;
                LexicalScope scope      = local.GetParentScope() as LexicalScope;
                if (scope != null)
                {
                    localScope = (byte)scope.Index;
                }

                // Write the variable data.
                writer.Write(AddString(local.GetName()));
                writer.Write(localScope);
                writer.Write((byte)local.Type);
                writer.Write((byte)local.ArgumentIndex);
                EmitPosition(writer, local.Position);
            }

            // Emit each basic block position information.
            ushort blockCount = (ushort)function.GetBasicBlockCount();

            writer.Write(blockCount);
            foreach (BasicBlock bb in function.GetBasicBlocks())
            {
                EmitBasicBlockDebugInfo(writer, bb);
            }
        }