コード例 #1
0
        public DynamicMethodTokenResolver(DynamicMethod dynamicMethod)
        {
            var resolverField = typeof(DynamicMethod).GetField(
                "m_resolver", BindingFlags.Instance | BindingFlags.NonPublic);
            var resolver = resolverField?.GetValue(dynamicMethod);

            if (resolver == null)
            {
                throw new ArgumentException("The dynamic method's IL has not been finalized.");
            }

            tokenResolver = (TokenResolver)resolver.GetType()
                            .GetMethod("ResolveToken", BindingFlags.Instance | BindingFlags.NonPublic)
                            .CreateDelegate(typeof(TokenResolver), resolver);
            stringResolver    = (StringResolver)resolver.GetType().GetMethod("GetStringLiteral", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(StringResolver), resolver);
            signatureResolver = (SignatureResolver)resolver.GetType().GetMethod("ResolveSignature", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(SignatureResolver), resolver);

            getTypeFromHandleUnsafe = (GetTypeFromHandleUnsafe)typeof(Type).GetMethod("GetTypeFromHandleUnsafe", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null).CreateDelegate(typeof(GetTypeFromHandleUnsafe), null);
            var runtimeType = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeType");

            var runtimeMethodHandleInternal = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeMethodHandleInternal");

            getMethodBase = runtimeType.GetMethod("GetMethodBase", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, runtimeMethodHandleInternal }, null);
            runtimeMethodHandleInternalCtor = runtimeMethodHandleInternal.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null);

            var runtimeFieldInfoStub = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeFieldInfoStub");

            runtimeFieldHandleStubCtor = runtimeFieldInfoStub.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(IntPtr), typeof(object) }, null);
            getFieldInfo = runtimeType.GetMethod("GetFieldInfo", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, typeof(RuntimeTypeHandle).Assembly.GetType("System.IRuntimeFieldInfo") }, null);
        }
コード例 #2
0
        public AssemblyLoader()
        {
            _signatureResolver = new SignatureResolver(this);

            _assemblyTable = new AssemblyTable(this);

            Const             = new ConstantTable(this);
            Files             = new FileTable(this);
            ManifestResources = new ManifestResourceTable(this);

            Modules = new ModuleTable(this);

            ModuleRefs   = new ModuleRefTable(this);
            AssemblyRefs = new AssemblyRefTable(this);

            TypeRefs    = new TypeRefTable(this);
            MemberRefs  = new MemberRefTable(this);
            _typeSpec   = new TypeSpecTable(this);
            _methodSpec = new MethodSpecTable(this);

            Parameters        = new ParamTable(this);
            Fields            = new FieldTable(this);
            Properties        = new PropertyTable(this);
            Events            = new EventTable(this);
            GenericParameters = new GenericParamTable(this);

            Methods = new MethodTable(this);
            Types   = new TypeTable(this);
        }
コード例 #3
0
        public ExecutionContext(Computer computer, SignatureResolver resolver)
        {
            Computer          = computer;
            SignatureResolver = resolver;
            Instructions      = new InstructionEnumerator();

            FrameDebugInfo mainFrame
                = new FrameDebugInfo(Instructions, FunctionSignature.Main);

            Memory = new Memory(new SprakConverter(resolver, this), mainFrame);

            Reset();
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: Seti-0/NSprak
        public Compiler()
        {
            // At some point this should be configurable.
            List <Library> libraries = new List <Library>
            {
                Library.Core
            };

            _assignmentLookup = new AssignmentResolver(libraries);
            _signatureLookup  = new SignatureResolver(libraries, _assignmentLookup);

            _signatureLookup.SpecifyOperationBindings(new List <OperationBinding>());
        }
コード例 #5
0
        public void ResolvedSignaturesMatchEtwSignatures(Platform platform)
        {
            string source = GetSampleSource();

            var model          = RoslynCompiler.GetSemanticModel(source);
            var analyzerResult = RoslynCompiler.Run("Tests.Model.SignatureResolverSamples.cs", platform);

            var jitType   = analyzerResult.CallGraph.GetJitType("Tests.Model.SignatureResolverSamples");
            var innerType = analyzerResult.CallGraph.GetJitType("Tests.Model.SignatureResolverSamples+InnerClass");

            foreach (SyntaxNode node in model.SyntaxTree.GetRoot().DescendantNodes())
            {
                if (!(node is ConstructorDeclarationSyntax || node is MethodDeclarationSyntax))
                {
                    continue;
                }

                var methodSymbol = model.GetDeclaredSymbol(node);

                string signature = SignatureResolver.BuildSignature((IMethodSymbol)methodSymbol);

                MethodGroup jitMethodGroup;
                if (jitType.Methods.ContainsKey(methodSymbol.Name))
                {
                    jitMethodGroup = jitType.Methods[methodSymbol.Name];
                }
                else
                {
                    jitMethodGroup = innerType.Methods[methodSymbol.Name];
                }
                var overload = jitMethodGroup.GetAllMethods().FirstOrDefault(m => m.Signature == signature);
                if (overload == null)
                {
                    var    allMethods = jitMethodGroup.GetAllMethods().ToList();
                    string expected;
                    if (allMethods.Count == 1)
                    {
                        expected = allMethods[0].Signature;
                    }
                    else
                    {
                        expected = string.Join("\r\n", allMethods.Select(m => m.Signature));
                    }

                    Assert.Fail("Method: " + methodSymbol.Name + "\r\nExpected / Actual:\r\n" + expected + "\r\n" + signature + "\r\n");
                }
            }
        }
コード例 #6
0
        public Executor(Computer computer)
        {
            // At some point the list of library names should be stored
            // in the executable... but there is only one library at the moment.
            List <Library> libraries = new List <Library>
            {
                Library.Core
            };

            AssignmentResolver assignments = new AssignmentResolver(libraries);
            SignatureResolver  signatures  = new SignatureResolver(libraries, assignments);

            signatures.SpecifyUserFunctions(computer.Executable.FunctionDeclarations);
            signatures.SpecifyOperationBindings(new List <OperationBinding>());

            _context = new ExecutionContext(computer, signatures);

            _context.Reset();
            State = ExecutorState.Idle;
        }
コード例 #7
0
        public DynamicMethodTokenResolver(DynamicMethod dynamicMethod)
        {
            object resolver = typeof(DynamicMethod).GetField("m_resolver", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dynamicMethod);

            _tokenResolver     = (TokenResolver)resolver.GetType().GetMethod("_resolveToken", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(TokenResolver), resolver);
            _stringResolver    = (StringResolver)resolver.GetType().GetMethod("GetStringLiteral", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(StringResolver), resolver);
            _signatureResolver = (SignatureResolver)resolver.GetType().GetMethod("ResolveSignature", BindingFlags.Instance | BindingFlags.NonPublic).CreateDelegate(typeof(SignatureResolver), resolver);

            _getTypeFromHandleUnsafe = (GetTypeFromHandleUnsafe)typeof(Type).GetMethod("GetTypeFromHandleUnsafe", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null).CreateDelegate(typeof(GetTypeFromHandleUnsafe), null);
            Type runtimeType = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeType");

            Type runtimeMethodHandleInternal = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeMethodHandleInternal");

            _getMethodBase = runtimeType.GetMethod("GetMethodBase", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, runtimeMethodHandleInternal }, null);
            _runtimeMethodHandleInternalCtor = runtimeMethodHandleInternal.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(IntPtr) }, null);

            Type runtimeFieldInfoStub = typeof(RuntimeTypeHandle).Assembly.GetType("System.RuntimeFieldInfoStub");

            _runtimeFieldHandleStubCtor = runtimeFieldInfoStub.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null, new[] { typeof(IntPtr), typeof(object) }, null);
            _getFieldInfo = runtimeType.GetMethod("GetFieldInfo", BindingFlags.Static | BindingFlags.NonPublic, null, new[] { runtimeType, typeof(RuntimeTypeHandle).Assembly.GetType("System.IRuntimeFieldInfo") }, null);
        }
コード例 #8
0
ファイル: Compiler.cs プロジェクト: Seti-0/NSprak
 public CompilationEnvironment(Messenger messages, SignatureResolver signatureLookup, AssignmentResolver assignmentLookup)
 {
     Messages         = messages;
     SignatureLookup  = signatureLookup;
     AssignmentLookup = assignmentLookup;
 }
コード例 #9
0
ファイル: SprakConverter.cs プロジェクト: Seti-0/NSprak
 public SprakConverter(SignatureResolver resolver, ExecutionContext context)
 {
     _resolver = resolver;
     _context  = context;
 }