public LlvmGlobal CreateGlobal(string identifier, LlvmType type) { // Create and wrap the global value reference. LlvmGlobal reference = new LlvmGlobal(LLVM.AddGlobal(this.reference, type.Unwrap(), identifier)); // Return the reference. return(reference); }
public static LlvmValue Int(LlvmType type, long value) { // Create the value. Must be an unsigned integer. ulong transformedValue = (ulong)Math.Abs(value); // Determine whether to flip to negative or stay in positive. bool flip = value < 0; // Create, wrap and return the constant. return(LLVM.ConstInt(type.Unwrap(), transformedValue, flip).Wrap()); }
public LlvmValue CreateAlloca(LlvmType type, string resultIdentifier) { // Invoke the native function and capture the resulting reference. LLVMValueRef reference = LLVM.BuildAlloca(this.reference, type.Unwrap(), resultIdentifier); // Register the instruction. this.instructions.Add(reference.Wrap()); // Wrap and return the reference. return(new LlvmValue(reference)); }
public LlvmFunction CreateFunction(string identifier, LlvmType type) { // Create the function. LLVMValueRef function = LLVM.AddFunction(this.reference, identifier, type.Unwrap()); // Add and wrap the function. LlvmFunction reference = new LlvmFunction(this, function); // Cache the function locally. this.functions.Add(identifier, reference); // Return the function. return(reference); }
public LlvmType CreateStruct(string identifier, LlvmType[] body) { // Create the struct. LlvmType @struct = LLVM.StructCreateNamed(this.Context, identifier).Wrap(); // TODO: Packed parameter? // Set the body. LLVM.StructSetBody(@struct.Unwrap(), body.Unwrap(), false); // Save struct locally. this.structs.Add(identifier, @struct); // Return the resulting struct. return(@struct); }
public static LlvmValue Array(LlvmType elementType, LlvmValue[] values) { // Create, wrap and return the constant. return(LLVM.ConstArray(elementType.Unwrap(), values.Unwrap()).Wrap()); }
public static LlvmType Function(LlvmType returnType, LlvmType[] arguments, bool continuousArguments = false) { // Create and wrap the function type. return(LLVM.FunctionType(returnType.Unwrap(), arguments.Unwrap(), continuousArguments).Wrap()); }