Example #1
0
 /// <summary>
 /// Open a new scope.
 /// </summary>
 public void OpenScope()
 {
     currentScope = new Scope(currentScope, thisMeth);
     AddToBuffer(new OpenScope(currentScope));
     //Console.WriteLine("Open scope on " + currentScope._thisMeth.Name());
 }
Example #2
0
 /// <summary>
 /// The constructor to build a new CloseScope instruction.
 /// </summary>
 /// <param name="scope">The scope to close.</param>
 public CloseScope(Scope scope)
 {
     size = 0;
        _scope = scope;
 }
Example #3
0
 internal Scope(Scope parent, MethodDef thisMeth)
 {
     _thisMeth = thisMeth;
        _parent = parent;
 }
Example #4
0
 /// <summary>
 /// Close the current scope.
 /// </summary>
 public void CloseScope()
 {
     //Console.WriteLine("Close scope on " + currentScope._thisMeth.Name());
     AddToBuffer(new CloseScope(currentScope));
     currentScope = currentScope._parent;
 }
Example #5
0
        //public void ReadPDB() {
        //  PDBReader reader = new PDBReader(this.fileName);
        //  foreach (ClassDef cDef in GetClasses())
        //    foreach (MethodDef mDef in cDef.GetMethods()) {
        //      CILInstructions buffer = mDef.GetCodeBuffer();
        //      PDBMethod meth = reader.GetMethod((int) mDef.Token());
        //      if (meth == null)
        //        continue; // no symbols for this method
        //      PDBSequencePoint[] spList = meth.SequencePoints;
        //      MergeBuffer mergeBuffer = new MergeBuffer(buffer.GetInstructions());
        //      PDBScope outer = meth.Scope;
        //      buffer.currentScope = ReadPDBScope(outer, mergeBuffer, null, mDef);
        //      foreach (PDBSequencePoint sp in spList) {
        //        PDBDocument doc = sp.Document;
        //        mergeBuffer.Add(new Line((uint) sp.Line, (uint) sp.Column, (uint) sp.EndLine, (uint) sp.EndColumn,
        //          SourceFile.GetSourceFile(doc.URL, doc.Language, doc.LanguageVendor, doc.DocumentType)),
        //          (uint) sp.Offset);
        //      }
        //      buffer.SetInstructions(mergeBuffer.Instructions);
        //    }
        // }
        private Scope ReadPDBScope(PDBScope scope, MergeBuffer mergeBuffer, Scope parent, MethodDef thisMeth)
        {
            Scope thisScope = new Scope(parent, thisMeth);

            if (parent != null) mergeBuffer.Add(new OpenScope(thisScope), (uint) scope.StartOffset);

            foreach (PDBVariable var in scope.Variables)
                thisScope.AddLocalBinding(var.Name, var.Address);

            foreach (PDBScope child in scope.Children)
                ReadPDBScope(child, mergeBuffer, thisScope, thisMeth);

            if (parent != null) mergeBuffer.Add(new CloseScope(thisScope), (uint) scope.EndOffset);

            return thisScope;
        }
Example #6
0
        /// <summary>
        /// Write out the scopes and the locals to the PDB file.
        /// </summary>
        /// <param name="symWriter">The symbol writer for this file.</param>
        /// <param name="scope">The scope to write out.</param>
        private void WriteScopeAndLocals(SymbolWriter symWriter, Scope scope)
        {
            // Open the scope
            symWriter.OpenScope(scope.OffsetStart);

            // Add each local variable
            foreach (LocalBinding lb in scope.Locals) {
                symWriter.DefineLocalVariable2(
                    lb.Name,
                    0,
                    lb.Token.GetToken(),
                    1,
                    lb.Index,
                    0,
                    0,
                    lb.OffsetStart,
                    lb.OffsetEnd
                );
            }

            // Add each constants
            /* For now don't add constants.  Doesn't work. AKB 09-01-2007
            foreach (ConstantBinding cb in scope.Constants) {
                symWriter.DefineConstant(
                    cb.Name,
                    cb.Value,
                    cb.GetSig()
                );
            }
            */

            // Add any child scopes
            foreach (Scope childScope in scope.ChildScopes)
                WriteScopeAndLocals(symWriter, childScope);

            // Close the scope
            symWriter.CloseScope(scope.OffsetEnd);
        }
Example #7
0
        /// <summary>
        /// Open a new scope.
        /// </summary>
        /// <param name="offset">Offset as to where the scope should start.</param>
        public void OpenScope(int offset)
        {
            // Make sure we are in a method
            if (currentMethod == null)
                throw new Exception("You can not open a scope before opening a method.");

            // Create and add the new scope
            Scope scope = new Scope();
            scope.OffsetStart = offset;
            scope.ParentScope = currentScope;

            // Check if this is the first/root scope or a child scope.
            if (currentScope == null) {

                // Check to make sure we don't try to create two root scopes.
                if (currentMethod.Scope != null)
                    throw new Exception("Only one top-most scope is permitted.");

                currentMethod.Scope = scope;
            } else {
                currentScope.ChildScopes.Add(scope);
            }

            // Set the current scope
            currentScope = scope;
        }
Example #8
0
        /// <summary>
        /// Close the current scope at the given offset.
        /// </summary>
        /// <param name="offset">The offset of where to close the scope.</param>
        public void CloseScope(int offset)
        {
            // Make sure a scope is open
            if (currentScope == null)
                throw new Exception("You can not close a scope now, none are open.");

            // Set the end offset for this scope and close it.
            currentScope.OffsetEnd = offset;
            currentScope = currentScope.ParentScope;
        }
Example #9
0
 /// <summary>
 /// Create a new OpenScope instruction.
 /// </summary>
 /// <param name="scope">The scope that is being opened.</param>
 public OpenScope(Scope scope)
 {
     size = 0;
        _scope = scope;
 }