Check-in [020581c952]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Streamline returnFromInvoke a tiny bit.
Timelines: family | ancestors | descendants | both | kbk-nre
Files: files | file ages | folders
SHA3-256:020581c952a7b21d9b9eb06f60e1b20249e534e2003799022040101179f3274e
User & Date: kbk 2018-04-25 00:47:20
Context
2018-04-25
00:59
Improve commentary check-in: 7a5af13a50 user: kbk tags: kbk-nre
00:47
Streamline returnFromInvoke a tiny bit. check-in: 020581c952 user: kbk tags: kbk-nre
2018-04-24
03:39
Use llvmtcl 3.9 (release) features to provide the target platform information before starting to generate code in a module, and to do 'sizeof' and 'alignof' correctly. mrtest::* now compile correctly. check-in: c2b79891aa user: kbk tags: kbk-nre
Changes

Changes to codegen/compile.tcl.

1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
....
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446

	set arguments [lassign $operation opcode tgt corohandle origname]
	set rettype [dict get $vtypes $tgt]
	set vname [my LocalVarName $tgt]
	set called [my ResolveInvoke $rettype $origname $arguments]
	if {$called ne {}} {
	    my IssueNREReturnFromInvokedFunction \
		$rettype $tgt $corohandle $callframe $origname $arguments $vname
	    return {}
	} else {
	    set arguments [linsert $arguments[set arguments ""] 0 $origname]
	    set i -1
	    my IssueNREReturnFromInvokedCommand \
		$rettype $tgt $corohandle $callframe $arguments $vname
	    ;				# objc will still contain
................................................................................
    #   arguments - List of quadcode values representing the arguments
    #	vname - LLVM name to assign to the result of the call
    #
    # Results:
    #	None.

    method IssueNREReturnFromInvokedFunction {rettype tgt corohandle callframe
					      origname arguments vname} {

	# Built-in types that are handled here.
	set BASETYPES {ZEROONE INT DOUBLE NUMERIC STRING}
	set ts [lmap t $BASETYPES {Type $t?}]
	set tgttype [my ValueTypes $tgt]

	# Get the name of the function to call
	set fname [lindex $origname 1]
	set callee [my GenerateFunctionName $fname arguments $arguments]

	# Emit the sequence that destroys the LLVM coroutine and returns the
	# result as 'retval'
	lassign [my returnedFromCoro $rettype $callee $corohandle] \
	    retcode retval

	# Handle the return

	if {$tgttype eq "FAIL"} {
	    # This procedure only ever fails.
	    $b store $retval $errorCode







|







 







|






<
<
<
<


|







1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
....
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432




1433
1434
1435
1436
1437
1438
1439
1440
1441
1442

	set arguments [lassign $operation opcode tgt corohandle origname]
	set rettype [dict get $vtypes $tgt]
	set vname [my LocalVarName $tgt]
	set called [my ResolveInvoke $rettype $origname $arguments]
	if {$called ne {}} {
	    my IssueNREReturnFromInvokedFunction \
		$rettype $tgt $corohandle $callframe $vname
	    return {}
	} else {
	    set arguments [linsert $arguments[set arguments ""] 0 $origname]
	    set i -1
	    my IssueNREReturnFromInvokedCommand \
		$rettype $tgt $corohandle $callframe $arguments $vname
	    ;				# objc will still contain
................................................................................
    #   arguments - List of quadcode values representing the arguments
    #	vname - LLVM name to assign to the result of the call
    #
    # Results:
    #	None.

    method IssueNREReturnFromInvokedFunction {rettype tgt corohandle callframe
					      vname} {

	# Built-in types that are handled here.
	set BASETYPES {ZEROONE INT DOUBLE NUMERIC STRING}
	set ts [lmap t $BASETYPES {Type $t?}]
	set tgttype [my ValueTypes $tgt]





	# Emit the sequence that destroys the LLVM coroutine and returns the
	# result as 'retval'
	lassign [my returnedFromCoro $rettype $corohandle] \
	    retcode retval

	# Handle the return

	if {$tgttype eq "FAIL"} {
	    # This procedure only ever fails.
	    $b store $retval $errorCode

Changes to codegen/coro.tcl.

290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
...
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
}
 
# TclCompiler method CoroPromiseType --
#
#	Generates the LLVM type that represents the coroutine promise for
#	the current NRE function

oo::define TclCompiler method CoroPromiseType {{rettype {}} {realname {}}} {
    if {$realname eq {}} {
	set realname [my GenerateFunctionName $cmd typecodes $paramTypes]
    }
    if {$rettype eq {}} {
	set rettype $returnType
    }
    set typestr named 
    append typestr \{ $realname .promise
    append typestr , status:int32
    append typestr , retval: [nameOfType $rettype]
    append typestr \}
    return [Type $typestr]
}
 
# Builder method launchCoroRunner --
................................................................................
#	rettype - The function's return type
#	callee - The name of the function that has been called
#
# Results:
#	Returns a list of two LLVM value refs: the status code and the
#	return value.

oo::define TclCompiler method returnedFromCoro {rettype callee corohandle} {

    # Retrieve the coroutine promise from the coroutine handle

    set handle [my LoadOrLiteral $corohandle]
    set ptype [my CoroPromiseType $rettype $callee]
    set alignment [Const [$m alignof $ptype] int32]
    set paddr_raw [$b call [$m intrinsic coro.promise] \
		       [list $handle $alignment [Const false bool]] \
		       "promise.addr.raw"]
    set paddr [$b cast(ptr) $paddr_raw $ptype "promise.addr"]

    # Retrieve the return code and return value of the called procedure
................................................................................
#
# Results:
#	Returns the LLVM value reference to the result of the wrapped function

oo::define Builder method NRReturnToThunk {handle resType} {
    set promiseType named{$resType.promise,int32,$resType}
    set alignment [$m alignof [Type $promiseType]]
    puts "promise = $promiseType"
    puts "alignof(promise) = $alignment"
    puts "sizeof(promise) = [$m sizeof [Type $promiseType]]"
    set llvm.coro.promise [$m intrinsic coro.promise]
    set promiseAddrRaw [my call ${llvm.coro.promise} \
			    [list $handle [Const $alignment int32] \
				 [Const false bool]] "promise.addr.raw"]
    set promiseAddr [my cast(ptr) $promiseAddrRaw $promiseType]
    set value [my load [my gep $promiseAddr 0 1] "value"]
    set llvm.coro.destroy [$m intrinsic coro.destroy]







|
<
<
<




|







 







|




|







 







<
<
<







290
291
292
293
294
295
296
297



298
299
300
301
302
303
304
305
306
307
308
309
...
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
...
395
396
397
398
399
400
401



402
403
404
405
406
407
408
}
 
# TclCompiler method CoroPromiseType --
#
#	Generates the LLVM type that represents the coroutine promise for
#	the current NRE function

oo::define TclCompiler method CoroPromiseType {{rettype {}}} {



    if {$rettype eq {}} {
	set rettype $returnType
    }
    set typestr named 
    append typestr \{ [nameOfType $rettype] .promise
    append typestr , status:int32
    append typestr , retval: [nameOfType $rettype]
    append typestr \}
    return [Type $typestr]
}
 
# Builder method launchCoroRunner --
................................................................................
#	rettype - The function's return type
#	callee - The name of the function that has been called
#
# Results:
#	Returns a list of two LLVM value refs: the status code and the
#	return value.

oo::define TclCompiler method returnedFromCoro {rettype corohandle} {

    # Retrieve the coroutine promise from the coroutine handle

    set handle [my LoadOrLiteral $corohandle]
    set ptype [my CoroPromiseType $rettype]
    set alignment [Const [$m alignof $ptype] int32]
    set paddr_raw [$b call [$m intrinsic coro.promise] \
		       [list $handle $alignment [Const false bool]] \
		       "promise.addr.raw"]
    set paddr [$b cast(ptr) $paddr_raw $ptype "promise.addr"]

    # Retrieve the return code and return value of the called procedure
................................................................................
#
# Results:
#	Returns the LLVM value reference to the result of the wrapped function

oo::define Builder method NRReturnToThunk {handle resType} {
    set promiseType named{$resType.promise,int32,$resType}
    set alignment [$m alignof [Type $promiseType]]



    set llvm.coro.promise [$m intrinsic coro.promise]
    set promiseAddrRaw [my call ${llvm.coro.promise} \
			    [list $handle [Const $alignment int32] \
				 [Const false bool]] "promise.addr.raw"]
    set promiseAddr [my cast(ptr) $promiseAddrRaw $promiseType]
    set value [my load [my gep $promiseAddr 0 1] "value"]
    set llvm.coro.destroy [$m intrinsic coro.destroy]