Exemplo n.º 1
0
 private static IEnumerable <DeclarationNode> FunctionAttributeToDeclarations(LinkableFunctionAttribute attribute)
 {
     for (int i = 0, ilen = attribute.ArgumentCount; i < ilen; ++i)
     {
         yield return(new DeclarationNode(new TypeSpecifierParseNode("int", PointerMode.NotAPointer), "", new VoidExpressionNode())); // TODO: Type specifier
     }
 }
Exemplo n.º 2
0
        private bool ProcessSimpleBinding(
            LinkableFunctionAttribute attribute,
            MethodInfo method,
            ParameterInfo[] parameters,
            object?target)
        {
            if (method.ReturnType != typeof(void))
            {
                return(false);
            }
            if (parameters.Length != 2 ||
                parameters[0].ParameterType != typeof(IVMBindingContext) ||
                parameters[1].ParameterType != typeof(ArgumentSource))
            {
                return(false);
            }

            VMFunctionDelegate impl;

            if (_includeImplementations)
            {
                impl = CreateDelegate <VMFunctionDelegate>(method, target);
            }
            else
            {
                impl = NoOpBindingInstance;
            }

            AddBinding(method, attribute, impl);
            return(true);
        }
Exemplo n.º 3
0
        private void AddBinding(MethodInfo method, LinkableFunctionAttribute attribute, VMFunctionDelegate implementation)
        {
            FunctionDefinitionNode def = new FunctionDefinitionNode(
                name: attribute.Name ?? method.Name,
                returnType: new TypeSpecifierParseNode("int", PointerMode.NotAPointer), // TODO
                parameters: FunctionAttributeToDeclarations(attribute),
                body: new BodyNode(),
                isExported: true,
                isDrop: false
                );

            Binding binding = new Binding {
                Prototype      = def,
                Implementation = new VMFunction {
                    ReturnValueSize    = sizeof(int),                         // TODO
                    ArgumentMemorySize = def.Parameters.Length * sizeof(int), // TODO
                    Delegate           = implementation
                }
            };

            _bindings[method.Name] = binding;

            Symbol symbol = new Symbol();

            symbol.Node       = def;
            symbol.SourceFile = method.Module.FullyQualifiedName;
            _tokenMap[def]    = symbol;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to import the given method with the given target.
        /// Returns true if the method was imported, otherwise false.
        /// </summary>
        public bool ImportMethod(MethodInfo method, object?target = null)
        {
            object[] attribs = method.GetCustomAttributes(typeof(LinkableFunctionAttribute), inherit: false);
            if (attribs.Length == 0)
            {
                return(false);
            }

            LinkableFunctionAttribute attribute = (LinkableFunctionAttribute)attribs[0];

            ParameterInfo[] parameters = method.GetParameters();

            if (ProcessSimpleBinding(attribute, method, parameters, target))
            {
                return(true);
            }

            _errors.Add($"Could not import method {method.Name}, please check that it's signature is compatible.");
            return(false);
        }