Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tgymnich committed Sep 18, 2024
1 parent cb8d8db commit b43bcb1
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/device/intrinsics/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,26 @@ end
T_pint8 = LLVM.PointerType(LLVM.Int8Type())
T_pint8a2 = LLVM.PointerType(LLVM.Int8Type(), 2)



# create functions
param_types = LLVMType[convert(LLVMType, typ) for typ in arg_types]
llvm_f, llvm_ft = create_function(T_void, LLVMType[]; vararg=true)
mod = LLVM.parent(llvm_f)
wrapper_f, wrapper_ft = create_function(T_void, param_types)
mod = LLVM.parent(wrapper_f)

llvm_ft = LLVM.FunctionType(T_void, LLVMType[]; vararg=true)
llvm_f = LLVM.Function(mod, "vararg", llvm_ft)
push!(function_attributes(llvm_f), EnumAttribute("alwaysinline", 0))

# generate IR
@dispose builder=IRBuilder() begin
entry = BasicBlock(llvm_f, "entry")
position!(builder, entry)

str = globalstring_ptr!(builder, String(fmt), addrspace=2)
subsystem_str = globalstring_ptr!(builder, MTLLOG_SUBSYSTEM, addrspace=2)
category_str = globalstring_ptr!(builder, MTLLOG_CATEGRORY, addrspace=2)
log_type = LLVM.ConstantInt(T_int32, __METAL_OS_LOG_TYPE_DEBUG__)

# compute argsize
argtypes = LLVM.StructType(param_types)
Expand All @@ -103,16 +112,11 @@ end
va_start_fty = LLVM.FunctionType(T_void, [T_pint8])
va_start = LLVM.Function(mod, "llvm.va_start", va_start_fty)
call!(builder, va_start_fty, va_start, [buffer])

# invoke @air.os_log and return
subsystem_str = globalstring_ptr!(builder, MTLLOG_SUBSYSTEM, addrspace=2)
category_str = globalstring_ptr!(builder, MTLLOG_CATEGRORY, addrspace=2)
log_type = LLVM.ConstantInt(T_int32, __METAL_OS_LOG_TYPE_DEBUG__)
os_log_fty = LLVM.FunctionType(T_void, [T_pint8a2, T_pint8a2, T_int32, T_pint8a2, T_pint8, T_int64])
os_log = LLVM.Function(mod, "air.os_log", os_log_fty)

arg_ptr = load!(builder, T_pint8, alloc)

os_log_fty = LLVM.FunctionType(T_void, [T_pint8a2, T_pint8a2, T_int32, T_pint8a2, T_pint8, T_int64])
os_log = LLVM.Function(mod, "air.os_log", os_log_fty)
call!(builder, os_log_fty, os_log, [subsystem_str, category_str, log_type, str, arg_ptr, arg_size])

va_end_fty = LLVM.FunctionType(T_void, [T_pint8])
Expand All @@ -126,13 +130,11 @@ end
ret!(builder)
end

wrapper_f, wrapper_ft = create_function(T_void, param_types)

@dispose builder=IRBuilder() begin
entry = BasicBlock(wrapper_f, "entry")
position!(builder, entry)

# call!(builder, llvm_ft, llvm_f, collect(parameters(wrapper_f)))
call!(builder, llvm_ft, llvm_f, collect(parameters(wrapper_f)))

ret!(builder)
end
Expand Down

0 comments on commit b43bcb1

Please sign in to comment.