Пример #1
0
        private static IReadOnlyDictionary <string, TypeMember> CreateMembers(GlobalCompilationContext ctx)
        {
            var global = ctx.GlobalNamespace;

            return(new Dictionary <string, TypeMember>(2)
            {
                {
                    "allocate_fn",
                    new TypeMember
                    {
                        Index = 0,
                        Name = "allocate_fn",
                        Type = PointerType.Create(FunctionType.Create(global.Types["void*"], new[] { global.Types["u32"] }, false, ctx)),
                    }
                },

                {
                    "free_fn",
                    new TypeMember
                    {
                        Index = 1,
                        Name = "free_fn",
                        Type = PointerType.Create(FunctionType.Create(global.Types["void"], new [] { global.Types["void*"] }, false, ctx))
                    }
                }
            });
        }
Пример #2
0
        public Module(string name, DirectoryInfo rootDirectory, GlobalCompilationContext context)
        {
            Name          = name;
            Context       = context;
            LlvmModule    = LLVMModuleRef.CreateWithName(name);
            StrConstants  = new Dictionary <string, Value>();
            Constants     = new Dictionary <LLVMValueRef, Value>();
            RootNamespace = new Namespace(this, rootDirectory);

            _foreignFunctions = new Dictionary <Function, Function>();
        }
Пример #3
0
        private static LLVMTypeRef CreateLlvmType(GlobalCompilationContext ctx)
        {
            var type = ctx.LlvmContext.CreateNamedStruct("__allocator_vtable");
            Span <LLVMTypeRef> members = stackalloc LLVMTypeRef[]
            {
                LLVMTypeRef.CreatePointer(LLVMTypeRef.CreateFunction(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), new[] { LLVMTypeRef.Int32 }), 0),
                LLVMTypeRef.CreatePointer(LLVMTypeRef.CreateFunction(LLVMTypeRef.Void, new[] { LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0) }), 0),
            };

            type.StructSetBody(members, false);
            return(type);
        }
Пример #4
0
 public AllocatorVTable(GlobalCompilationContext ctx)
     : base("__allocator_vtable", ctx.GlobalNamespace, CreateLlvmType(ctx), CreateMembers(ctx), TypeFlags.Unsafe)
 {
 }
Пример #5
0
 private FunctionType(LLVMTypeRef llvmType, Type returnType, Type[] paramTypes, GlobalCompilationContext ctx)
     : base(GetName(returnType, paramTypes), ctx.GlobalNamespace, llvmType)
     => (ReturnType, ParamTypes) = (returnType, paramTypes);
Пример #6
0
 public HeapAllocator(GlobalCompilationContext ctx)
     : base("Heap", ctx, ctx.GlobalNamespace)
 {
 }
Пример #7
0
 public External(GlobalCompilationContext ctx)
     : base(ctx, "External", Compilation.Flags.Unsafe)
 {
 }
Пример #8
0
 public VarArgs(GlobalCompilationContext ctx)
     : base("VarArg", ctx.GlobalNamespace, Compilation.Flags.VarArgs | Compilation.Flags.Unsafe)
 {
 }
Пример #9
0
 public CCompat(GlobalCompilationContext ctx, string name, Flags subsequentFlags = Compilation.Flags.None)
     : base(name, ctx.GlobalNamespace, subsequentFlags | Compilation.Flags.CCompat)
 {
 }
Пример #10
0
 public CCompat(GlobalCompilationContext ctx)
     : base("CCompat", ctx.GlobalNamespace, Compilation.Flags.CCompat)
 {
 }
Пример #11
0
 public Unsafe(GlobalCompilationContext ctx)
     : base("Unsafe", ctx.GlobalNamespace, Compilation.Flags.Unsafe)
 {
 }
Пример #12
0
 protected Allocator(string name, GlobalCompilationContext ctx, Namespace ns) : base(name, ns)
 {
     CompilationContext = ctx;
     VtablePtrName      = $"__vtable_{GetMangledName()}";
 }
Пример #13
0
 public StackAllocator(GlobalCompilationContext ctx)
     : base("Stack", ctx, ctx.GlobalNamespace)
 {
 }