feat(launcher): Process.*, Http.save_to/received/expected, App.window_hide/show
Process.spawn/poll/kill/free - non-blocking child processes with no shell: posix_spawn on macOS (process.ll), CreateProcessW with MSVC-quoted arguments and no console window on Windows (process_win.ll), linked only when a program uses Process.*. Http.save_to streams a response body into a file (NSURLSession with a run-time delegate class on macOS, the WinHTTP read loop on Windows); Http.received / Http.expected report progress while it is pending. Freeing a pending request cancels it and parks the slot until the worker has finished. App.window_hide / App.window_show take the game's window off the screen and back without closing it; the run goes on while hidden. Docs, examples, tests and a changeset. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
c1db0d71ed
commit
43d5eb5b88
31 changed files with 89274 additions and 86727 deletions
|
|
@ -21,6 +21,15 @@
|
|||
; http_done(slot) -> bool http_status(slot) -> int
|
||||
; http_body(slot) -> ptr http_blen(slot) -> int
|
||||
; http_header(slot, name) -> cstr http_free(slot)
|
||||
;
|
||||
; Streaming (Http.save_to), which a synchronous NSURLConnection cannot do:
|
||||
; hs_save_to(slot, path) hs_received(slot) -> int
|
||||
; hs_expected(slot) -> int hs_cancel(slot)
|
||||
; A slot given a path before hs_send is sent through one shared NSURLSession whose
|
||||
; delegate - a class built at run time, like cocoa.ll's view - appends each chunk to the
|
||||
; file as it arrives (URLSession:dataTask:didReceiveData:) and publishes the status and the
|
||||
; done flag when the task ends (URLSession:task:didCompleteWithError:). The callbacks run
|
||||
; on the session's own serial queue; the byte counters are atomics the poller reads.
|
||||
; ============================================================================
|
||||
|
||||
declare ptr @objc_getClass(ptr)
|
||||
|
|
@ -31,6 +40,15 @@ declare void @free(ptr)
|
|||
declare ptr @memcpy(ptr, ptr, i64)
|
||||
declare i32 @pthread_create(ptr, ptr, ptr, ptr)
|
||||
declare i32 @pthread_detach(ptr)
|
||||
declare ptr @strdup(ptr)
|
||||
declare ptr @fopen(ptr, ptr)
|
||||
declare i64 @fwrite(ptr, i64, i64, ptr)
|
||||
declare i32 @fclose(ptr)
|
||||
declare ptr @objc_allocateClassPair(ptr, ptr, i64)
|
||||
declare void @objc_registerClassPair(ptr)
|
||||
declare i8 @class_addMethod(ptr, ptr, ptr, ptr)
|
||||
declare ptr @objc_autoreleasePoolPush()
|
||||
declare void @objc_autoreleasePoolPop(ptr)
|
||||
|
||||
@.h_nsurl = private unnamed_addr constant [6 x i8] c"NSURL\00"
|
||||
@.h_nsstr = private unnamed_addr constant [9 x i8] c"NSString\00"
|
||||
|
|
@ -59,6 +77,26 @@ declare i32 @pthread_detach(ptr)
|
|||
@.h_rel = private unnamed_addr constant [8 x i8] c"release\00"
|
||||
@.h_empty = private unnamed_addr constant [1 x i8] c"\00"
|
||||
|
||||
@.h_nsobj = private unnamed_addr constant [9 x i8] c"NSObject\00"
|
||||
@.h_dlgcls = private unnamed_addr constant [18 x i8] c"LudicHttpDelegate\00"
|
||||
@.h_sesscl = private unnamed_addr constant [13 x i8] c"NSURLSession\00"
|
||||
@.h_cfgcl = private unnamed_addr constant [26 x i8] c"NSURLSessionConfiguration\00"
|
||||
@.h_defcfg = private unnamed_addr constant [28 x i8] c"defaultSessionConfiguration\00"
|
||||
@.h_swc = private unnamed_addr constant [49 x i8] c"sessionWithConfiguration:delegate:delegateQueue:\00"
|
||||
@.h_dtwr = private unnamed_addr constant [21 x i8] c"dataTaskWithRequest:\00"
|
||||
@.h_resume = private unnamed_addr constant [7 x i8] c"resume\00"
|
||||
@.h_cancel = private unnamed_addr constant [7 x i8] c"cancel\00"
|
||||
@.h_respg = private unnamed_addr constant [9 x i8] c"response\00"
|
||||
@.h_cbexp = private unnamed_addr constant [30 x i8] c"countOfBytesExpectedToReceive\00"
|
||||
@.h_ecl = private unnamed_addr constant [22 x i8] c"expectedContentLength\00"
|
||||
@.h_seldat = private unnamed_addr constant [36 x i8] c"URLSession:dataTask:didReceiveData:\00"
|
||||
@.h_seldon = private unnamed_addr constant [38 x i8] c"URLSession:task:didCompleteWithError:\00"
|
||||
@.h_enc5 = private unnamed_addr constant [7 x i8] c"v@:@@@\00"
|
||||
@.h_rts = private unnamed_addr constant [20 x i8] c"respondsToSelector:\00"
|
||||
@.h_wb = private unnamed_addr constant [3 x i8] c"wb\00"
|
||||
@.h_aenc = private unnamed_addr constant [16 x i8] c"Accept-Encoding\00"
|
||||
@.h_ident = private unnamed_addr constant [9 x i8] c"identity\00"
|
||||
|
||||
; HTTP_SLOTS = 8
|
||||
@H_req = internal global [8 x ptr] zeroinitializer
|
||||
@H_resp = internal global [8 x ptr] zeroinitializer
|
||||
|
|
@ -66,6 +104,15 @@ declare i32 @pthread_detach(ptr)
|
|||
@H_blen = internal global [8 x i32] zeroinitializer
|
||||
@H_status = internal global [8 x i32] zeroinitializer
|
||||
@H_done = internal global [8 x i32] zeroinitializer
|
||||
; streaming (Http.save_to)
|
||||
@H_path = internal global [8 x ptr] zeroinitializer ; strdup'd file path, set before send
|
||||
@H_file = internal global [8 x ptr] zeroinitializer ; FILE* while the task runs
|
||||
@H_task = internal global [8 x ptr] zeroinitializer ; the retained NSURLSessionDataTask
|
||||
@H_recv = internal global [8 x i32] zeroinitializer ; body bytes written (atomic)
|
||||
@H_exp = internal global [8 x i32] zeroinitializer ; Content-Length or -1 (atomic)
|
||||
@H_werr = internal global [8 x i32] zeroinitializer ; a write to the file failed
|
||||
@H_strm = internal global [8 x i32] zeroinitializer ; this slot was sent streaming
|
||||
@H_sess = internal global ptr null ; the shared streaming session
|
||||
|
||||
; --- request construction ---------------------------------------------------
|
||||
|
||||
|
|
@ -218,6 +265,14 @@ entry:
|
|||
store ptr null, ptr %respp
|
||||
%reqp = getelementptr [8 x ptr], ptr @H_req, i32 0, i32 %slot
|
||||
store ptr %req, ptr %reqp
|
||||
%pathp = getelementptr [8 x ptr], ptr @H_path, i32 0, i32 %slot
|
||||
%path = load ptr, ptr %pathp
|
||||
%strm = icmp ne ptr %path, null
|
||||
br i1 %strm, label %stream, label %thread
|
||||
stream:
|
||||
call void @hs_stream_start(i32 %slot, ptr %req, ptr %path)
|
||||
ret void
|
||||
thread:
|
||||
%tid = alloca i64
|
||||
%arg = inttoptr i32 %slot to ptr
|
||||
%rc = call i32 @pthread_create(ptr %tid, ptr null, ptr @hs_worker, ptr %arg)
|
||||
|
|
@ -265,10 +320,16 @@ entry:
|
|||
%nores = icmp eq ptr %resp, null
|
||||
br i1 %nores, label %empty, label %ask
|
||||
ask:
|
||||
; only an HTTP response has headers (a file:// one does not)
|
||||
%sel_vh = call ptr @sel_registerName(ptr @.h_vhdr)
|
||||
%sel_rts = call ptr @sel_registerName(ptr @.h_rts)
|
||||
%has = call i8 (ptr, ptr, ptr) @objc_msgSend(ptr %resp, ptr %sel_rts, ptr %sel_vh)
|
||||
%nohdr = icmp eq i8 %has, 0
|
||||
br i1 %nohdr, label %empty, label %lookup
|
||||
lookup:
|
||||
%strcls = call ptr @objc_getClass(ptr @.h_nsstr)
|
||||
%sel_u = call ptr @sel_registerName(ptr @.h_utf8)
|
||||
%ns = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %strcls, ptr %sel_u, ptr %name)
|
||||
%sel_vh = call ptr @sel_registerName(ptr @.h_vhdr)
|
||||
%val = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %resp, ptr %sel_vh, ptr %ns)
|
||||
%noval = icmp eq ptr %val, null
|
||||
br i1 %noval, label %empty, label %tocstr
|
||||
|
|
@ -302,5 +363,346 @@ rr:
|
|||
store ptr null, ptr %rp
|
||||
br label %out
|
||||
out:
|
||||
call void @hs_stream_free(i32 %slot)
|
||||
ret void
|
||||
}
|
||||
|
||||
; --- streaming (Http.save_to) -------------------------------------------------
|
||||
|
||||
define void @hs_save_to(i32 %slot, ptr %path) {
|
||||
entry:
|
||||
%pp = getelementptr [8 x ptr], ptr @H_path, i32 0, i32 %slot
|
||||
%old = load ptr, ptr %pp
|
||||
%had = icmp ne ptr %old, null
|
||||
br i1 %had, label %drop, label %set
|
||||
drop:
|
||||
call void @free(ptr %old)
|
||||
br label %set
|
||||
set:
|
||||
%cp = call ptr @strdup(ptr %path)
|
||||
store ptr %cp, ptr %pp
|
||||
ret void
|
||||
}
|
||||
|
||||
define i32 @hs_received(i32 %slot) {
|
||||
entry:
|
||||
%p = getelementptr [8 x i32], ptr @H_recv, i32 0, i32 %slot
|
||||
%v = load atomic i32, ptr %p acquire, align 4
|
||||
ret i32 %v
|
||||
}
|
||||
|
||||
define i32 @hs_expected(i32 %slot) {
|
||||
entry:
|
||||
%p = getelementptr [8 x i32], ptr @H_exp, i32 0, i32 %slot
|
||||
%v = load atomic i32, ptr %p acquire, align 4
|
||||
ret i32 %v
|
||||
}
|
||||
|
||||
; Stop a running streaming task; its completion callback then publishes status 0. An
|
||||
; in-memory request cannot be interrupted and simply runs to its end.
|
||||
define void @hs_cancel(i32 %slot) {
|
||||
entry:
|
||||
%sp = getelementptr [8 x i32], ptr @H_strm, i32 0, i32 %slot
|
||||
%s = load i32, ptr %sp
|
||||
%is = icmp ne i32 %s, 0
|
||||
br i1 %is, label %task, label %out
|
||||
task:
|
||||
%tp = getelementptr [8 x ptr], ptr @H_task, i32 0, i32 %slot
|
||||
%t = load ptr, ptr %tp
|
||||
%not = icmp eq ptr %t, null
|
||||
br i1 %not, label %out, label %go
|
||||
go:
|
||||
%sel = call ptr @sel_registerName(ptr @.h_cancel)
|
||||
%r = call ptr (ptr, ptr) @objc_msgSend(ptr %t, ptr %sel)
|
||||
br label %out
|
||||
out:
|
||||
ret void
|
||||
}
|
||||
|
||||
define internal void @hs_stream_free(i32 %slot) {
|
||||
entry:
|
||||
%tp = getelementptr [8 x ptr], ptr @H_task, i32 0, i32 %slot
|
||||
%t = load ptr, ptr %tp
|
||||
%not = icmp eq ptr %t, null
|
||||
br i1 %not, label %file, label %rel
|
||||
rel:
|
||||
%sel = call ptr @sel_registerName(ptr @.h_rel)
|
||||
%r = call ptr (ptr, ptr) @objc_msgSend(ptr %t, ptr %sel)
|
||||
store ptr null, ptr %tp
|
||||
br label %file
|
||||
file:
|
||||
%fp = getelementptr [8 x ptr], ptr @H_file, i32 0, i32 %slot
|
||||
%f = load ptr, ptr %fp
|
||||
%nof = icmp eq ptr %f, null
|
||||
br i1 %nof, label %path, label %close
|
||||
close:
|
||||
%c = call i32 @fclose(ptr %f)
|
||||
store ptr null, ptr %fp
|
||||
br label %path
|
||||
path:
|
||||
%pp = getelementptr [8 x ptr], ptr @H_path, i32 0, i32 %slot
|
||||
%p = load ptr, ptr %pp
|
||||
%nop = icmp eq ptr %p, null
|
||||
br i1 %nop, label %out, label %freep
|
||||
freep:
|
||||
call void @free(ptr %p)
|
||||
store ptr null, ptr %pp
|
||||
br label %out
|
||||
out:
|
||||
%sp = getelementptr [8 x i32], ptr @H_strm, i32 0, i32 %slot
|
||||
store i32 0, ptr %sp
|
||||
ret void
|
||||
}
|
||||
|
||||
; the slot whose task this is, or -1
|
||||
define internal i32 @hs_slot_of(ptr %task) {
|
||||
entry:
|
||||
br label %loop
|
||||
loop:
|
||||
%i = phi i32 [ 0, %entry ], [ %i1, %next ]
|
||||
%tp = getelementptr [8 x ptr], ptr @H_task, i32 0, i32 %i
|
||||
%t = load ptr, ptr %tp
|
||||
%hit = icmp eq ptr %t, %task
|
||||
br i1 %hit, label %found, label %next
|
||||
next:
|
||||
%i1 = add i32 %i, 1
|
||||
%more = icmp slt i32 %i1, 8
|
||||
br i1 %more, label %loop, label %none
|
||||
found:
|
||||
ret i32 %i
|
||||
none:
|
||||
ret i32 -1
|
||||
}
|
||||
|
||||
; -URLSession:dataTask:didReceiveData: - append the chunk, count it, note the length
|
||||
define internal void @hs_dlg_data(ptr %self, ptr %cmd, ptr %session, ptr %task, ptr %data) {
|
||||
entry:
|
||||
%slot = call i32 @hs_slot_of(ptr %task)
|
||||
%bad = icmp slt i32 %slot, 0
|
||||
br i1 %bad, label %out, label %file
|
||||
file:
|
||||
%fp = getelementptr [8 x ptr], ptr @H_file, i32 0, i32 %slot
|
||||
%f = load ptr, ptr %fp
|
||||
%nof = icmp eq ptr %f, null
|
||||
br i1 %nof, label %out, label %write
|
||||
write:
|
||||
%sel_len = call ptr @sel_registerName(ptr @.h_length)
|
||||
%n = call i64 (ptr, ptr) @objc_msgSend(ptr %data, ptr %sel_len)
|
||||
%sel_by = call ptr @sel_registerName(ptr @.h_bytes)
|
||||
%b = call ptr (ptr, ptr) @objc_msgSend(ptr %data, ptr %sel_by)
|
||||
%w = call i64 @fwrite(ptr %b, i64 1, i64 %n, ptr %f)
|
||||
%short = icmp ne i64 %w, %n
|
||||
br i1 %short, label %failed, label %count
|
||||
failed:
|
||||
%ep = getelementptr [8 x i32], ptr @H_werr, i32 0, i32 %slot
|
||||
store i32 1, ptr %ep
|
||||
%sel_c = call ptr @sel_registerName(ptr @.h_cancel)
|
||||
%rc = call ptr (ptr, ptr) @objc_msgSend(ptr %task, ptr %sel_c)
|
||||
br label %count
|
||||
count:
|
||||
%rp = getelementptr [8 x i32], ptr @H_recv, i32 0, i32 %slot
|
||||
%r0 = load atomic i32, ptr %rp acquire, align 4
|
||||
%w32 = trunc i64 %w to i32
|
||||
%r1 = add i32 %r0, %w32
|
||||
store atomic i32 %r1, ptr %rp release, align 4
|
||||
%sel_x = call ptr @sel_registerName(ptr @.h_cbexp)
|
||||
%x = call i64 (ptr, ptr) @objc_msgSend(ptr %task, ptr %sel_x)
|
||||
%x32 = trunc i64 %x to i32
|
||||
%neg = icmp slt i64 %x, 0
|
||||
%xv = select i1 %neg, i32 -1, i32 %x32
|
||||
%xp = getelementptr [8 x i32], ptr @H_exp, i32 0, i32 %slot
|
||||
store atomic i32 %xv, ptr %xp release, align 4
|
||||
br label %out
|
||||
out:
|
||||
ret void
|
||||
}
|
||||
|
||||
; -URLSession:task:didCompleteWithError: - close the file, publish status and done
|
||||
define internal void @hs_dlg_done(ptr %self, ptr %cmd, ptr %session, ptr %task, ptr %error) {
|
||||
entry:
|
||||
%slot = call i32 @hs_slot_of(ptr %task)
|
||||
%bad = icmp slt i32 %slot, 0
|
||||
br i1 %bad, label %out, label %close
|
||||
close:
|
||||
%fp = getelementptr [8 x ptr], ptr @H_file, i32 0, i32 %slot
|
||||
%f = load ptr, ptr %fp
|
||||
%nof = icmp eq ptr %f, null
|
||||
br i1 %nof, label %judge, label %doclose
|
||||
doclose:
|
||||
%cr = call i32 @fclose(ptr %f)
|
||||
store ptr null, ptr %fp
|
||||
%cfail = icmp ne i32 %cr, 0
|
||||
br i1 %cfail, label %markw, label %judge
|
||||
markw:
|
||||
%ep0 = getelementptr [8 x i32], ptr @H_werr, i32 0, i32 %slot
|
||||
store i32 1, ptr %ep0
|
||||
br label %judge
|
||||
judge:
|
||||
%ep = getelementptr [8 x i32], ptr @H_werr, i32 0, i32 %slot
|
||||
%we = load i32, ptr %ep
|
||||
%werr = icmp ne i32 %we, 0
|
||||
%neterr = icmp ne ptr %error, null
|
||||
%failed = or i1 %werr, %neterr
|
||||
br i1 %failed, label %publish, label %resp
|
||||
resp:
|
||||
%sel_r = call ptr @sel_registerName(ptr @.h_respg)
|
||||
%rs = call ptr (ptr, ptr) @objc_msgSend(ptr %task, ptr %sel_r)
|
||||
%nors = icmp eq ptr %rs, null
|
||||
br i1 %nors, label %publish, label %keep
|
||||
keep:
|
||||
%sel_ret = call ptr @sel_registerName(ptr @.h_retain)
|
||||
%rr = call ptr (ptr, ptr) @objc_msgSend(ptr %rs, ptr %sel_ret)
|
||||
%respp = getelementptr [8 x ptr], ptr @H_resp, i32 0, i32 %slot
|
||||
store ptr %rs, ptr %respp
|
||||
; a file:// URL answers with a plain NSURLResponse, which has no status code: one that
|
||||
; completed without an error is reported as 200
|
||||
%sel_st = call ptr @sel_registerName(ptr @.h_status)
|
||||
%sel_rts = call ptr @sel_registerName(ptr @.h_rts)
|
||||
%ishttp = call i8 (ptr, ptr, ptr) @objc_msgSend(ptr %rs, ptr %sel_rts, ptr %sel_st)
|
||||
%nothttp = icmp eq i8 %ishttp, 0
|
||||
br i1 %nothttp, label %plain, label %httpst
|
||||
plain:
|
||||
br label %setst
|
||||
httpst:
|
||||
%st64 = call i64 (ptr, ptr) @objc_msgSend(ptr %rs, ptr %sel_st)
|
||||
%st0 = trunc i64 %st64 to i32
|
||||
br label %setst
|
||||
setst:
|
||||
%st = phi i32 [ 200, %plain ], [ %st0, %httpst ]
|
||||
%stp = getelementptr [8 x i32], ptr @H_status, i32 0, i32 %slot
|
||||
store i32 %st, ptr %stp
|
||||
; an empty body never reached didReceiveData: take the length from the response
|
||||
%xp = getelementptr [8 x i32], ptr @H_exp, i32 0, i32 %slot
|
||||
%x0 = load atomic i32, ptr %xp acquire, align 4
|
||||
%unk = icmp slt i32 %x0, 0
|
||||
br i1 %unk, label %fromresp, label %publish
|
||||
fromresp:
|
||||
%sel_e = call ptr @sel_registerName(ptr @.h_ecl)
|
||||
%e64 = call i64 (ptr, ptr) @objc_msgSend(ptr %rs, ptr %sel_e)
|
||||
%e32 = trunc i64 %e64 to i32
|
||||
%eneg = icmp slt i64 %e64, 0
|
||||
%ev = select i1 %eneg, i32 -1, i32 %e32
|
||||
store atomic i32 %ev, ptr %xp release, align 4
|
||||
br label %publish
|
||||
publish:
|
||||
%rp = getelementptr [8 x i32], ptr @H_recv, i32 0, i32 %slot
|
||||
%got = load atomic i32, ptr %rp acquire, align 4
|
||||
%blenp = getelementptr [8 x i32], ptr @H_blen, i32 0, i32 %slot
|
||||
store i32 %got, ptr %blenp
|
||||
%donep = getelementptr [8 x i32], ptr @H_done, i32 0, i32 %slot
|
||||
store atomic i32 1, ptr %donep release, align 4
|
||||
br label %out
|
||||
out:
|
||||
ret void
|
||||
}
|
||||
|
||||
; The one session every streaming request goes through, made on first use (hs_send runs on
|
||||
; the game thread only). Its delegate is an instance of a class built here.
|
||||
define internal ptr @hs_session() {
|
||||
entry:
|
||||
%have = load ptr, ptr @H_sess
|
||||
%got = icmp ne ptr %have, null
|
||||
br i1 %got, label %ready, label %make
|
||||
ready:
|
||||
ret ptr %have
|
||||
make:
|
||||
%cls0 = call ptr @objc_getClass(ptr @.h_dlgcls)
|
||||
%exists = icmp ne ptr %cls0, null
|
||||
br i1 %exists, label %inst, label %build
|
||||
build:
|
||||
%super = call ptr @objc_getClass(ptr @.h_nsobj)
|
||||
%nc = call ptr @objc_allocateClassPair(ptr %super, ptr @.h_dlgcls, i64 0)
|
||||
%sd = call ptr @sel_registerName(ptr @.h_seldat)
|
||||
%m1 = call i8 @class_addMethod(ptr %nc, ptr %sd, ptr @hs_dlg_data, ptr @.h_enc5)
|
||||
%sc = call ptr @sel_registerName(ptr @.h_seldon)
|
||||
%m2 = call i8 @class_addMethod(ptr %nc, ptr %sc, ptr @hs_dlg_done, ptr @.h_enc5)
|
||||
call void @objc_registerClassPair(ptr %nc)
|
||||
br label %inst
|
||||
inst:
|
||||
%cls = phi ptr [ %cls0, %make ], [ %nc, %build ]
|
||||
%sel_a = call ptr @sel_registerName(ptr @.h_alloc)
|
||||
%d0 = call ptr (ptr, ptr) @objc_msgSend(ptr %cls, ptr %sel_a)
|
||||
%sel_i = call ptr @sel_registerName(ptr @.h_init)
|
||||
%dlg = call ptr (ptr, ptr) @objc_msgSend(ptr %d0, ptr %sel_i)
|
||||
%cfgcls = call ptr @objc_getClass(ptr @.h_cfgcl)
|
||||
%sel_dc = call ptr @sel_registerName(ptr @.h_defcfg)
|
||||
%cfg = call ptr (ptr, ptr) @objc_msgSend(ptr %cfgcls, ptr %sel_dc)
|
||||
%sesscls = call ptr @objc_getClass(ptr @.h_sesscl)
|
||||
%sel_sw = call ptr @sel_registerName(ptr @.h_swc)
|
||||
%sess = call ptr (ptr, ptr, ptr, ptr, ptr) @objc_msgSend(ptr %sesscls, ptr %sel_sw, ptr %cfg, ptr %dlg, ptr null)
|
||||
%none = icmp eq ptr %sess, null
|
||||
br i1 %none, label %fail, label %hold
|
||||
hold:
|
||||
; the session retains its delegate; it is kept for the life of the program
|
||||
%sel_ret = call ptr @sel_registerName(ptr @.h_retain)
|
||||
%rs = call ptr (ptr, ptr) @objc_msgSend(ptr %sess, ptr %sel_ret)
|
||||
store ptr %sess, ptr @H_sess
|
||||
ret ptr %sess
|
||||
fail:
|
||||
ret ptr null
|
||||
}
|
||||
|
||||
; Send `req` on `slot` as a streaming download into `path`. The file is created first; if
|
||||
; it cannot be, or the task cannot be made, the request finishes at once with status 0.
|
||||
define internal void @hs_stream_start(i32 %slot, ptr %req, ptr %path) {
|
||||
entry:
|
||||
%pool = call ptr @objc_autoreleasePoolPush()
|
||||
%sp = getelementptr [8 x i32], ptr @H_strm, i32 0, i32 %slot
|
||||
store i32 1, ptr %sp
|
||||
%rp = getelementptr [8 x i32], ptr @H_recv, i32 0, i32 %slot
|
||||
store atomic i32 0, ptr %rp release, align 4
|
||||
%xp = getelementptr [8 x i32], ptr @H_exp, i32 0, i32 %slot
|
||||
store atomic i32 -1, ptr %xp release, align 4
|
||||
%ep = getelementptr [8 x i32], ptr @H_werr, i32 0, i32 %slot
|
||||
store i32 0, ptr %ep
|
||||
%sel_rel = call ptr @sel_registerName(ptr @.h_rel)
|
||||
%f = call ptr @fopen(ptr %path, ptr @.h_wb)
|
||||
%nof = icmp eq ptr %f, null
|
||||
br i1 %nof, label %finish, label %opened
|
||||
opened:
|
||||
%fp = getelementptr [8 x ptr], ptr @H_file, i32 0, i32 %slot
|
||||
store ptr %f, ptr %fp
|
||||
; the bytes on disk are the bytes the counter reports: ask for no transfer compression
|
||||
; unless the caller chose an encoding
|
||||
%strcls = call ptr @objc_getClass(ptr @.h_nsstr)
|
||||
%sel_u = call ptr @sel_registerName(ptr @.h_utf8)
|
||||
%aen = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %strcls, ptr %sel_u, ptr @.h_aenc)
|
||||
%sel_vh = call ptr @sel_registerName(ptr @.h_vhdr)
|
||||
%cur = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %req, ptr %sel_vh, ptr %aen)
|
||||
%unset = icmp eq ptr %cur, null
|
||||
br i1 %unset, label %setenc, label %session
|
||||
setenc:
|
||||
%idn = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %strcls, ptr %sel_u, ptr @.h_ident)
|
||||
%sel_sh = call ptr @sel_registerName(ptr @.h_shdr)
|
||||
%r0 = call ptr (ptr, ptr, ptr, ptr) @objc_msgSend(ptr %req, ptr %sel_sh, ptr %idn, ptr %aen)
|
||||
br label %session
|
||||
session:
|
||||
%sess = call ptr @hs_session()
|
||||
%nosess = icmp eq ptr %sess, null
|
||||
br i1 %nosess, label %closefile, label %mktask
|
||||
mktask:
|
||||
%sel_dt = call ptr @sel_registerName(ptr @.h_dtwr)
|
||||
%task = call ptr (ptr, ptr, ptr) @objc_msgSend(ptr %sess, ptr %sel_dt, ptr %req)
|
||||
%notask = icmp eq ptr %task, null
|
||||
br i1 %notask, label %closefile, label %run
|
||||
run:
|
||||
%sel_ret = call ptr @sel_registerName(ptr @.h_retain)
|
||||
%rt = call ptr (ptr, ptr) @objc_msgSend(ptr %task, ptr %sel_ret)
|
||||
%tp = getelementptr [8 x ptr], ptr @H_task, i32 0, i32 %slot
|
||||
store ptr %task, ptr %tp
|
||||
%rr = call ptr (ptr, ptr) @objc_msgSend(ptr %req, ptr %sel_rel)
|
||||
%sel_go = call ptr @sel_registerName(ptr @.h_resume)
|
||||
%g = call ptr (ptr, ptr) @objc_msgSend(ptr %task, ptr %sel_go)
|
||||
call void @objc_autoreleasePoolPop(ptr %pool)
|
||||
ret void
|
||||
closefile:
|
||||
%c = call i32 @fclose(ptr %f)
|
||||
store ptr null, ptr %fp
|
||||
br label %finish
|
||||
finish:
|
||||
%rr2 = call ptr (ptr, ptr) @objc_msgSend(ptr %req, ptr %sel_rel)
|
||||
%donep = getelementptr [8 x i32], ptr @H_done, i32 0, i32 %slot
|
||||
store atomic i32 1, ptr %donep release, align 4
|
||||
call void @objc_autoreleasePoolPop(ptr %pool)
|
||||
ret void
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue