compiling a prologue and epilogue on PowerPC
parent
15c55fcc17
commit
70d534d587
|
@ -31,6 +31,12 @@ SYMBOL: #target ( part of jump table )
|
|||
SYMBOL: #target-label
|
||||
SYMBOL: #end-dispatch
|
||||
|
||||
! on PowerPC, compiled definitions that make subroutine calls
|
||||
! must have a prologue and epilogue to set up and tear down the
|
||||
! link register.
|
||||
SYMBOL: #prologue
|
||||
SYMBOL: #epilogue
|
||||
|
||||
: linear, ( node -- )
|
||||
#! Add a node to the linear IR.
|
||||
[ node-op get node-param get ] bind cons , ;
|
||||
|
@ -50,7 +56,7 @@ SYMBOL: #end-dispatch
|
|||
#! jumps and labels, and turns dataflow IR nodes into
|
||||
#! lists where the first element is an operation, and the
|
||||
#! rest is arguments.
|
||||
[ (linearize) ] make-list ;
|
||||
[ [ #prologue ] , (linearize) ] make-list ;
|
||||
|
||||
: immediate? ( obj -- ? )
|
||||
#! fixnums and f have a pointerless representation, and
|
||||
|
@ -83,6 +89,8 @@ SYMBOL: #end-dispatch
|
|||
linearize-simple-label
|
||||
] "linearizer" set-word-prop
|
||||
|
||||
: return, [ #epilogue ] , [ #return ] , ;
|
||||
|
||||
: linearize-label ( node -- )
|
||||
#! Labels are tricky, because they might contain non-tail
|
||||
#! calls. So we push the address of the location right after
|
||||
|
@ -92,7 +100,7 @@ SYMBOL: #end-dispatch
|
|||
#! not contain non-tail recursive calls to itself.
|
||||
<label> dup #return-to swons , >r
|
||||
linearize-simple-label
|
||||
[ #return ] ,
|
||||
return,
|
||||
r> label, ;
|
||||
|
||||
#label [
|
||||
|
@ -136,3 +144,5 @@ SYMBOL: #end-dispatch
|
|||
] "linearizer" set-word-prop
|
||||
|
||||
#values [ drop ] "linearizer" set-word-prop
|
||||
|
||||
#return [ drop return, ] "linearizer" set-word-prop
|
||||
|
|
|
@ -3,4 +3,23 @@
|
|||
IN: compiler
|
||||
USING: assembler inference kernel words ;
|
||||
|
||||
! At the start of each word that calls a subroutine, we store
|
||||
! the link register in r0, then push r0 on the C stack.
|
||||
#prologue [
|
||||
drop
|
||||
0 MFLR
|
||||
0 1 -4 STWU
|
||||
] "generator" set-word-prop
|
||||
|
||||
! At the end of each word that calls a subroutine, we store
|
||||
! the previous link register value in r0 by popping it off the
|
||||
! stack, set the link register to the contents of r0, and jump
|
||||
! to the link register.
|
||||
#epilogue [
|
||||
drop
|
||||
0 1 0 LWZ
|
||||
1 1 4 ADDI
|
||||
0 MTLR
|
||||
] "generator" set-word-prop
|
||||
|
||||
#return [ drop BLR ] "generator" set-word-prop
|
||||
|
|
|
@ -92,6 +92,8 @@ SYMBOL: simplifying
|
|||
car cdr find-label cdr
|
||||
] "next-logical" set-word-prop
|
||||
|
||||
#epilogue [ cdr ] "next-logical" set-word-prop
|
||||
|
||||
: next-logical? ( op linear -- ? )
|
||||
next-logical dup [ car car = ] [ 2drop f ] ifte ;
|
||||
|
||||
|
|
|
@ -4,6 +4,10 @@ IN: compiler
|
|||
USING: alien assembler inference kernel kernel-internals lists
|
||||
math memory namespaces words ;
|
||||
|
||||
! Not used on x86
|
||||
#prologue [ drop ] "generator" set-word-prop
|
||||
#epilogue [ drop ] "generator" set-word-prop
|
||||
|
||||
\ slot [
|
||||
PEEK-DS
|
||||
2unlist type-tag >r cell * r> - EAX swap 2list EAX swap MOV
|
||||
|
|
Loading…
Reference in New Issue