Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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());
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public static LlvmValue Array(LlvmType elementType, LlvmValue[] values)
 {
     // Create, wrap and return the constant.
     return(LLVM.ConstArray(elementType.Unwrap(), values.Unwrap()).Wrap());
 }
Esempio n. 7
0
 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());
 }