示例#1
0
        public void Import(Instruction instruction, ImportContext context, IILImporterProxy importer)
        {
            int index         = GetIndex(instruction);
            var localNumber   = importer.ParameterCount + index;
            var localVariable = importer.LocalVariableTable[localNumber];
            var node          = new LocalVariableEntry(localNumber, localVariable.Kind, localVariable.ExactSize);

            importer.PushExpression(node);
        }
示例#2
0
        public void Import(Instruction instruction, ImportContext context, IILImporterProxy importer)
        {
            var index  = GetIndex(instruction);
            var lclNum = MapIlArgNum(index, importer.ReturnBufferArgIndex);

            var argument = importer.LocalVariableTable[lclNum];
            var node     = new LocalVariableEntry(lclNum, argument.Kind, argument.ExactSize);

            importer.PushExpression(node);
        }
示例#3
0
 private static void ReadLocalVariables(MethodEntry entry, MethodSymbols symbols)
 {
     LocalVariableEntry[] locals = entry.GetLocals();
     for (int i = 0; i < locals.Length; i++)
     {
         LocalVariableEntry local    = locals[i];
         VariableDefinition variable = symbols.Variables[local.Index];
         variable.Name = local.Name;
     }
 }
示例#4
0
文件: MethodDef.cs 项目: mdae/MonoRT
        public LocalVariableEntry[] GetLocalVars()
        {
            System.IO.MemoryStream str = new System.IO.MemoryStream();
            int i          = 0;
            int num_locals = ((Hashtable)named_local_tables [current_scope_depth]).Count;

            LocalVariableEntry[] locals = new LocalVariableEntry[num_locals];

            foreach (Local local in local_list)
            {
                if (local.Name != null)                    // only named variables
                {
                    locals[i++] = new LocalVariableEntry(local.Slot, local.Name, 0);
                }
            }
            return(locals);
        }
示例#5
0
        public void Import(Instruction instruction, ImportContext context, IILImporterProxy importer)
        {
            var methodDefOrRef = instruction.Operand as IMethodDefOrRef;
            var methodToCall   = methodDefOrRef.ResolveMethodDefThrow();

            var declType = methodToCall.DeclaringType;

            var objType = declType.ToTypeSig();
            var objKind = objType.GetStackValueKind();
            var objSize = objType.GetExactSize();

            if (declType.IsValueType)
            {
                // Allocate memory on the stack for the value type as a temp local variable
                var lclNum        = importer.GrabTemp(objKind, objSize);
                var newObjThisPtr = new LocalVariableAddressEntry(lclNum);

                // Call the valuetype constructor
                CallImporter.ImportCall(instruction, context, importer, newObjThisPtr);

                var node = new LocalVariableEntry(lclNum, objKind, objSize);
                importer.PushExpression(node);
            }
            else
            {
                // Allocate memory for object
                var op1 = new AllocObjEntry((int)declType.ClassSize, objKind);

                // Store allocated memory address into a temp local variable
                var lclNum = importer.GrabTemp(objKind, objSize);
                var asg    = new StoreLocalVariableEntry(lclNum, false, op1);
                importer.ImportAppendTree(asg);

                // Call the constructor
                var newObjThisPtr = new LocalVariableEntry(lclNum, objKind, objSize);
                CallImporter.ImportCall(instruction, context, importer, newObjThisPtr);

                // Push a local variable entry corresponding to the object here
                var node = new LocalVariableEntry(lclNum, objKind, objSize);
                importer.PushExpression(node);
            }
        }
示例#6
0
 private static void ReadLocalVariables(MethodEntry entry, MethodBody body, Scope[] scopes)
 {
     LocalVariableEntry[] locals = entry.GetLocals();
     LocalVariableEntry[] array  = locals;
     for (int i = 0; i < array.Length; i++)
     {
         LocalVariableEntry local    = array[i];
         VariableDefinition variable = body.Variables[local.Index];
         variable.Name = local.Name;
         int index = local.BlockIndex;
         if (index >= 0 && index < scopes.Length)
         {
             Scope scope = scopes[index];
             if (scope != null)
             {
                 scope.Variables.Add(variable);
             }
         }
     }
 }
示例#7
0
 public void Visit(LocalVariableEntry entry)
 {
     _sb.AppendLine($"t{entry.TreeID,-3} = lclVar {entry.Kind} V{entry.LocalNumber}");
 }
 public void Visit(LocalVariableEntry entry)
 {
     _genericStackEntryVisitor.Visit <LocalVariableEntry>(entry);
 }
示例#9
0
 public void Visit(LocalVariableEntry entry)
 {
     SetNext(entry);
 }
示例#10
0
        public static void ImportCall(Instruction instruction, ImportContext context, IILImporterProxy importer, StackEntry?newObjThis = null)
        {
            var methodDefOrRef = instruction.Operand as IMethodDefOrRef;
            var methodToCall   = methodDefOrRef.ResolveMethodDefThrow();

            var arguments     = new List <StackEntry>();
            var firstArgIndex = newObjThis != null ? 1 : 0;

            for (var i = firstArgIndex; i < methodToCall.Parameters.Count; i++)
            {
                var argument = importer.PopExpression();
                arguments.Add(argument);
            }
            // Add the this pointer if required, e.g. if part of newobj
            if (newObjThis != null)
            {
                arguments.Add(newObjThis);
            }
            arguments.Reverse();

            // Intrinsic calls
            if (methodToCall.IsIntrinsic())
            {
                if (!ImportIntrinsicCall(methodToCall, arguments, importer))
                {
                    throw new NotSupportedException("Unknown intrinsic");
                }
                return;
            }

            string targetMethod;

            if (methodToCall.IsPinvokeImpl)
            {
                targetMethod = methodToCall.ImplMap.Name;
            }
            else
            {
                targetMethod = context.NameMangler.GetMangledMethodName(methodToCall);
            }

            int returnBufferArgIndex = 0;
            var returnType           = methodToCall.ReturnType;

            if (methodToCall.HasReturnType)
            {
                if (returnType.IsStruct())
                {
                    returnBufferArgIndex = FixupCallStructReturn(returnType, arguments, importer, methodToCall.HasThis);
                }
            }

            int?returnTypeSize = methodToCall.HasReturnType ? returnType.GetExactSize() : null;

            var callNode = new CallEntry(targetMethod, arguments, returnType.GetStackValueKind(), returnTypeSize);

            if (!methodToCall.HasReturnType)
            {
                importer.ImportAppendTree(callNode);
            }
            else
            {
                if (returnType.IsStruct())
                {
                    importer.ImportAppendTree(callNode);

                    // Load return buffer to stack
                    var loadTemp = new LocalVariableEntry(returnBufferArgIndex, returnType.GetStackValueKind(), returnType.GetExactSize());
                    importer.PushExpression(loadTemp);
                }
                else
                {
                    importer.PushExpression(callNode);
                }
            }
        }
示例#11
0
        public MethodEntry DefineMethod(CompileUnitEntry comp_unit, int token,
						 ScopeVariable[] scope_vars, LocalVariableEntry[] locals,
						 LineNumberEntry[] lines, CodeBlockEntry[] code_blocks,
						 string real_name, MethodEntry.Flags flags,
						 int namespace_id)
        {
            if (reader != null)
                throw new InvalidOperationException ();

            MethodEntry method = new MethodEntry (
                this, comp_unit, token, scope_vars, locals, lines, code_blocks,
                real_name, flags, namespace_id);
            AddMethod (method);
            return method;
        }
示例#12
0
 public void Visit(LocalVariableEntry entry)
 {
     Print($"LCL_VAR {entry.Kind} V{entry.LocalNumber}");
 }