コード例 #1
0
ファイル: Compiler.cs プロジェクト: prepare/AsmJit
        private void BeginFunction(VariableType[] args, VariableType ret, CallingConvention callingConvention)
        {
            _function = new FunctionNode(CreateLabelNode(), CreateLabelNode(), args, ret, callingConvention);

            AddNode(_function);
            AddNode(_function.Entry);
            var node = _currentNode;

            AddNode(_function.Exit);            // Add function exit / epilog marker.
            AddNode(_function.End);             // Add function end.
            SetCurrentNode(node);
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: prepare/AsmJit
        public static CodeContext <T> CreateContext <T>(CallingConvention convention = CallingConvention.Default)
        {
            var t = typeof(T);

            var  args = new Type[0];
            Type ret  = null;
            Type delType;

            if (t == typeof(Action))
            {
                delType = DelegateCreator.NewDelegateType(args);
            }
            else if (Utils.Actions.Contains(t.GetGenericTypeDefinition()))
            {
                var gargs = t.GetGenericArguments();
                args    = new Type[gargs.Length].InitializeWith(i => gargs[i]);
                delType = DelegateCreator.NewDelegateType(args);
            }
            else if (Utils.Funcs.Contains(t.GetGenericTypeDefinition()))
            {
                var gargs = t.GetGenericArguments();
                args    = new Type[gargs.Length - 1].InitializeWith(i => gargs[i]);
                ret     = gargs.Last();
                delType = DelegateCreator.NewDelegateType(ret, args);
            }
            else
            {
                throw new ArgumentException();
            }

            var compiler = new Compiler();
            var ctx      = new CodeContext <T>(compiler, delType);

            compiler._codeContext   = ctx;
            compiler._codeProcessor = new CodeProcessor(compiler._assembler, compiler, compiler._codeContext);

            compiler.BeginFunction(args.Select(a => a.GetVariableType()).ToArray(), ret.GetVariableType(), convention);
            return(ctx);
        }