func (v *Codegen) primitiveTypeToLLVMType(typ ast.PrimitiveType) llvm.Type { switch typ { case ast.PRIMITIVE_int, ast.PRIMITIVE_uint, ast.PRIMITIVE_uintptr: return v.targetData.IntPtrType() case ast.PRIMITIVE_s8, ast.PRIMITIVE_u8: return llvm.IntType(8) case ast.PRIMITIVE_s16, ast.PRIMITIVE_u16: return llvm.IntType(16) case ast.PRIMITIVE_s32, ast.PRIMITIVE_u32: return llvm.IntType(32) case ast.PRIMITIVE_s64, ast.PRIMITIVE_u64: return llvm.IntType(64) case ast.PRIMITIVE_s128, ast.PRIMITIVE_u128: return llvm.IntType(128) case ast.PRIMITIVE_f32: return llvm.FloatType() case ast.PRIMITIVE_f64: return llvm.DoubleType() case ast.PRIMITIVE_f128: return llvm.FP128Type() case ast.PRIMITIVE_bool: return llvm.IntType(1) case ast.PRIMITIVE_void: return llvm.VoidType() default: panic("Unimplemented primitive type in LLVM codegen") } }
func (v *Codegen) functionTypeToLLVMType(typ ast.FunctionType, ptr bool, gcon *ast.GenericContext) llvm.Type { numOfParams := len(typ.Parameters) if typ.Receiver != nil { numOfParams++ } params := make([]llvm.Type, 0, numOfParams) if typ.Receiver != nil { params = append(params, v.typeRefToLLVMTypeWithOuter(typ.Receiver, gcon)) } for _, par := range typ.Parameters { params = append(params, v.typeRefToLLVMTypeWithOuter(par, gcon)) } var returnType llvm.Type // oo theres a type, let's try figure it out if typ.Return != nil { returnType = v.typeRefToLLVMTypeWithOuter(typ.Return, gcon) } else { returnType = llvm.VoidType() } // create the function type funcType := llvm.FunctionType(returnType, params, typ.IsVariadic) if ptr { funcType = llvm.PointerType(funcType, 0) } return funcType }