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   1387   
  1388   1388   	set arguments [lassign $operation opcode tgt corohandle origname]
  1389   1389   	set rettype [dict get $vtypes $tgt]
  1390   1390   	set vname [my LocalVarName $tgt]
  1391   1391   	set called [my ResolveInvoke $rettype $origname $arguments]
  1392   1392   	if {$called ne {}} {
  1393   1393   	    my IssueNREReturnFromInvokedFunction \
  1394         -		$rettype $tgt $corohandle $callframe $origname $arguments $vname
         1394  +		$rettype $tgt $corohandle $callframe $vname
  1395   1395   	    return {}
  1396   1396   	} else {
  1397   1397   	    set arguments [linsert $arguments[set arguments ""] 0 $origname]
  1398   1398   	    set i -1
  1399   1399   	    my IssueNREReturnFromInvokedCommand \
  1400   1400   		$rettype $tgt $corohandle $callframe $arguments $vname
  1401   1401   	    ;				# objc will still contain
................................................................................
  1419   1419       #   arguments - List of quadcode values representing the arguments
  1420   1420       #	vname - LLVM name to assign to the result of the call
  1421   1421       #
  1422   1422       # Results:
  1423   1423       #	None.
  1424   1424   
  1425   1425       method IssueNREReturnFromInvokedFunction {rettype tgt corohandle callframe
  1426         -					      origname arguments vname} {
         1426  +					      vname} {
  1427   1427   
  1428   1428   	# Built-in types that are handled here.
  1429   1429   	set BASETYPES {ZEROONE INT DOUBLE NUMERIC STRING}
  1430   1430   	set ts [lmap t $BASETYPES {Type $t?}]
  1431   1431   	set tgttype [my ValueTypes $tgt]
  1432   1432   
  1433         -	# Get the name of the function to call
  1434         -	set fname [lindex $origname 1]
  1435         -	set callee [my GenerateFunctionName $fname arguments $arguments]
  1436         -
  1437   1433   	# Emit the sequence that destroys the LLVM coroutine and returns the
  1438   1434   	# result as 'retval'
  1439         -	lassign [my returnedFromCoro $rettype $callee $corohandle] \
         1435  +	lassign [my returnedFromCoro $rettype $corohandle] \
  1440   1436   	    retcode retval
  1441   1437   
  1442   1438   	# Handle the return
  1443   1439   
  1444   1440   	if {$tgttype eq "FAIL"} {
  1445   1441   	    # This procedure only ever fails.
  1446   1442   	    $b store $retval $errorCode

Changes to codegen/coro.tcl.

   290    290   }
   291    291   
   292    292   # TclCompiler method CoroPromiseType --
   293    293   #
   294    294   #	Generates the LLVM type that represents the coroutine promise for
   295    295   #	the current NRE function
   296    296   
   297         -oo::define TclCompiler method CoroPromiseType {{rettype {}} {realname {}}} {
   298         -    if {$realname eq {}} {
   299         -	set realname [my GenerateFunctionName $cmd typecodes $paramTypes]
   300         -    }
          297  +oo::define TclCompiler method CoroPromiseType {{rettype {}}} {
   301    298       if {$rettype eq {}} {
   302    299   	set rettype $returnType
   303    300       }
   304    301       set typestr named 
   305         -    append typestr \{ $realname .promise
          302  +    append typestr \{ [nameOfType $rettype] .promise
   306    303       append typestr , status:int32
   307    304       append typestr , retval: [nameOfType $rettype]
   308    305       append typestr \}
   309    306       return [Type $typestr]
   310    307   }
   311    308   
   312    309   # Builder method launchCoroRunner --
................................................................................
   354    351   #	rettype - The function's return type
   355    352   #	callee - The name of the function that has been called
   356    353   #
   357    354   # Results:
   358    355   #	Returns a list of two LLVM value refs: the status code and the
   359    356   #	return value.
   360    357   
   361         -oo::define TclCompiler method returnedFromCoro {rettype callee corohandle} {
          358  +oo::define TclCompiler method returnedFromCoro {rettype corohandle} {
   362    359   
   363    360       # Retrieve the coroutine promise from the coroutine handle
   364    361   
   365    362       set handle [my LoadOrLiteral $corohandle]
   366         -    set ptype [my CoroPromiseType $rettype $callee]
          363  +    set ptype [my CoroPromiseType $rettype]
   367    364       set alignment [Const [$m alignof $ptype] int32]
   368    365       set paddr_raw [$b call [$m intrinsic coro.promise] \
   369    366   		       [list $handle $alignment [Const false bool]] \
   370    367   		       "promise.addr.raw"]
   371    368       set paddr [$b cast(ptr) $paddr_raw $ptype "promise.addr"]
   372    369   
   373    370       # Retrieve the return code and return value of the called procedure
................................................................................
   398    395   #
   399    396   # Results:
   400    397   #	Returns the LLVM value reference to the result of the wrapped function
   401    398   
   402    399   oo::define Builder method NRReturnToThunk {handle resType} {
   403    400       set promiseType named{$resType.promise,int32,$resType}
   404    401       set alignment [$m alignof [Type $promiseType]]
   405         -    puts "promise = $promiseType"
   406         -    puts "alignof(promise) = $alignment"
   407         -    puts "sizeof(promise) = [$m sizeof [Type $promiseType]]"
   408    402       set llvm.coro.promise [$m intrinsic coro.promise]
   409    403       set promiseAddrRaw [my call ${llvm.coro.promise} \
   410    404   			    [list $handle [Const $alignment int32] \
   411    405   				 [Const false bool]] "promise.addr.raw"]
   412    406       set promiseAddr [my cast(ptr) $promiseAddrRaw $promiseType]
   413    407       set value [my load [my gep $promiseAddr 0 1] "value"]
   414    408       set llvm.coro.destroy [$m intrinsic coro.destroy]