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)) } } }); }
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>(); }
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); }
public AllocatorVTable(GlobalCompilationContext ctx) : base("__allocator_vtable", ctx.GlobalNamespace, CreateLlvmType(ctx), CreateMembers(ctx), TypeFlags.Unsafe) { }
private FunctionType(LLVMTypeRef llvmType, Type returnType, Type[] paramTypes, GlobalCompilationContext ctx) : base(GetName(returnType, paramTypes), ctx.GlobalNamespace, llvmType) => (ReturnType, ParamTypes) = (returnType, paramTypes);
public HeapAllocator(GlobalCompilationContext ctx) : base("Heap", ctx, ctx.GlobalNamespace) { }
public External(GlobalCompilationContext ctx) : base(ctx, "External", Compilation.Flags.Unsafe) { }
public VarArgs(GlobalCompilationContext ctx) : base("VarArg", ctx.GlobalNamespace, Compilation.Flags.VarArgs | Compilation.Flags.Unsafe) { }
public CCompat(GlobalCompilationContext ctx, string name, Flags subsequentFlags = Compilation.Flags.None) : base(name, ctx.GlobalNamespace, subsequentFlags | Compilation.Flags.CCompat) { }
public CCompat(GlobalCompilationContext ctx) : base("CCompat", ctx.GlobalNamespace, Compilation.Flags.CCompat) { }
public Unsafe(GlobalCompilationContext ctx) : base("Unsafe", ctx.GlobalNamespace, Compilation.Flags.Unsafe) { }
protected Allocator(string name, GlobalCompilationContext ctx, Namespace ns) : base(name, ns) { CompilationContext = ctx; VtablePtrName = $"__vtable_{GetMangledName()}"; }
public StackAllocator(GlobalCompilationContext ctx) : base("Stack", ctx, ctx.GlobalNamespace) { }