Esempio n. 1
0
 /// <summary>
 /// Default ctor
 /// </summary>
 internal CodeReader(MethodDefinition method, CodeAttribute codeAttribute, byte[] code, ConstantPool cp)
 {
     this.method = method;
     this.codeAttribute = codeAttribute;
     this.code = code;
     this.cp = cp;
 }
Esempio n. 2
0
 internal ExceptionHandler(CodeAttribute code, int startPc, int endPc, int handlerPc, TypeReference catchType)
 {
     this.code = code;
     startPC = startPc;
     endPC = endPc;
     handlerPC = handlerPc;
     this.catchType = catchType;
 }
Esempio n. 3
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public AstBuilder(XModule module, MethodDefinition methodDef, XTypeDefinition declaringType, bool optimize)
 {
     this.module = module;
     typeSystem = module.TypeSystem;
     this.methodDef = methodDef;
     this.declaringType = declaringType;
     this.optimize = optimize;
     codeAttr = methodDef.Attributes.OfType<CodeAttribute>().FirstOrDefault();
     validExceptionHandlers = (codeAttr != null) ? codeAttr.ExceptionHandlers.Where(IsValid).ToList() : null;
 }
Esempio n. 4
0
        /// <summary>
        /// Read a Code attribute
        /// </summary>
        private CodeAttribute ReadCodeAttribute(MethodDefinition method, ConstantPool cp)
        {
            var maxStack = stream.ReadU2();
            var maxLocals = stream.ReadU2();
            var codeLength = (int)stream.ReadU4();
            var code = new byte[codeLength];
            stream.Read(code, 0, codeLength);
            var result = new CodeAttribute(method, cp, maxStack, maxLocals, code);

            var ecount = stream.ReadU2();
            for (var i = 0; i < ecount; i++)
            {
                var startPC = stream.ReadU2();
                var endPC = stream.ReadU2();
                var handlerPC = stream.ReadU2();
                var catchTypeIndex = stream.ReadU2();
                var catchType = (catchTypeIndex != 0) ? cp.GetEntry<ConstantPoolClass>(catchTypeIndex).Type : null;
                result.Add(new ExceptionHandler(result, startPC, endPC, handlerPC, catchType));
            }

            ReadAttributes(cp, result);

            return result;
        }
Esempio n. 5
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public SourceLocation(CodeAttribute code, Instruction instruction)
 {
     this.code = code;
     this.instruction = instruction;
 }
Esempio n. 6
0
        /// <summary>
        /// Mark all eachable items in argument as such.
        /// </summary>
        private static void Walk(ReachableContext context, CodeAttribute code)
        {
            if (code == null) 
                return;

            // Exception handlers
            foreach (var handler in code.ExceptionHandlers)
            {
                handler.CatchType.MarkReachable(context);
            }

            // Local variables
            /*foreach (var var in code.Variables)
                {
                    var.VariableType.MarkReachable(context);
                }*/

            // Instructions
            foreach (var ins in code.Instructions)
            {
                object operand = ins.Operand;
                if (operand != null)
                {
                    ConstantPoolClass cpClass;
                    ConstantPoolFieldRef cpField;
                    ConstantPoolMethodRef cpMethod;

                    if ((cpClass = operand as ConstantPoolClass) != null)
                    {
                        ClassFile cf;
                        if (cpClass.TryResolve(out cf))
                        {
                            cf.MarkReachable(context);
                        }
                    }
                    else if ((cpField = operand as ConstantPoolFieldRef) != null)
                    {
                        FieldDefinition fieldDef;
                        if (cpField.TryResolve(out fieldDef))
                        {
                            fieldDef.MarkReachable(context);
                        }
                    }
                    else if ((cpMethod = operand as ConstantPoolMethodRef) != null)
                    {
                        MethodDefinition method;
                        if (cpMethod.TryResolve(out method))
                        {
                            method.MarkReachable(context);
                        }
                        else
                        {
                            
                        }
                    }
                }

            }
        }