2008-09-10 23:11:03 -04:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-09-11 03:05:22 -04:00
|
|
|
USING: assocs accessors arrays kernel sequences namespaces
|
2008-09-15 05:22:12 -04:00
|
|
|
math compiler.cfg.registers compiler.cfg.instructions.syntax ;
|
2008-09-15 02:54:48 -04:00
|
|
|
IN: compiler.cfg.instructions
|
2008-09-10 23:11:03 -04:00
|
|
|
|
|
|
|
! Virtual CPU instructions, used by CFG and machine IRs
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
TUPLE: %cond-branch < insn src ;
|
|
|
|
TUPLE: %unary < insn dst src ;
|
|
|
|
TUPLE: %nullary < insn dst ;
|
2008-09-10 23:11:03 -04:00
|
|
|
|
|
|
|
! Stack operations
|
2008-09-15 03:59:24 -04:00
|
|
|
INSN: %load-literal < %nullary obj ;
|
|
|
|
INSN: %peek < %nullary loc ;
|
|
|
|
INSN: %replace src loc ;
|
2008-09-10 23:11:03 -04:00
|
|
|
INSN: %inc-d n ;
|
|
|
|
INSN: %inc-r n ;
|
|
|
|
|
|
|
|
! Calling convention
|
|
|
|
INSN: %return ;
|
|
|
|
|
|
|
|
! Subroutine calls
|
|
|
|
INSN: %call word ;
|
|
|
|
INSN: %jump word ;
|
2008-09-15 03:59:24 -04:00
|
|
|
INSN: %intrinsic quot regs ;
|
2008-09-10 23:11:03 -04:00
|
|
|
|
|
|
|
! Jump tables
|
|
|
|
INSN: %dispatch-label label ;
|
|
|
|
INSN: %dispatch ;
|
|
|
|
|
|
|
|
! Boxing and unboxing
|
|
|
|
INSN: %copy < %unary ;
|
|
|
|
INSN: %copy-float < %unary ;
|
|
|
|
INSN: %unbox-float < %unary ;
|
|
|
|
INSN: %unbox-f < %unary ;
|
|
|
|
INSN: %unbox-alien < %unary ;
|
|
|
|
INSN: %unbox-byte-array < %unary ;
|
|
|
|
INSN: %unbox-any-c-ptr < %unary ;
|
|
|
|
INSN: %box-float < %unary ;
|
|
|
|
INSN: %box-alien < %unary ;
|
|
|
|
|
|
|
|
INSN: %gc ;
|
|
|
|
|
|
|
|
! FFI
|
|
|
|
INSN: %alien-invoke params ;
|
|
|
|
INSN: %alien-indirect params ;
|
|
|
|
INSN: %alien-callback params ;
|
|
|
|
|
2008-09-15 02:54:48 -04:00
|
|
|
GENERIC: defs-vregs ( insn -- seq )
|
2008-09-10 23:11:03 -04:00
|
|
|
GENERIC: uses-vregs ( insn -- seq )
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
M: %nullary defs-vregs dst>> >vreg 1array ;
|
|
|
|
M: %unary defs-vregs dst>> >vreg 1array ;
|
2008-09-15 02:54:48 -04:00
|
|
|
M: insn defs-vregs drop f ;
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
M: %replace uses-vregs src>> >vreg 1array ;
|
|
|
|
M: %unary uses-vregs src>> >vreg 1array ;
|
2008-09-15 03:59:24 -04:00
|
|
|
M: insn uses-vregs drop f ;
|
2008-09-15 02:54:48 -04:00
|
|
|
|
|
|
|
! M: %intrinsic uses-vregs vregs>> values ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
|
|
|
! Instructions used by CFG IR only.
|
|
|
|
INSN: %prologue ;
|
|
|
|
INSN: %epilogue ;
|
|
|
|
INSN: %frame-required n ;
|
|
|
|
|
|
|
|
INSN: %branch ;
|
|
|
|
INSN: %branch-f < %cond-branch ;
|
|
|
|
INSN: %branch-t < %cond-branch ;
|
|
|
|
INSN: %if-intrinsic quot vregs ;
|
2008-09-15 03:59:24 -04:00
|
|
|
INSN: %boolean-intrinsic quot vregs dst ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
2008-09-15 03:59:24 -04:00
|
|
|
M: %cond-branch uses-vregs src>> 1array ;
|
2008-09-15 02:54:48 -04:00
|
|
|
|
|
|
|
! M: %if-intrinsic uses-vregs vregs>> values ;
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
M: %boolean-intrinsic defs-vregs dst>> 1array ;
|
2008-09-15 02:54:48 -04:00
|
|
|
|
|
|
|
! M: %boolean-intrinsic uses-vregs
|
|
|
|
! [ vregs>> values ] [ out>> ] bi suffix ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
|
|
|
! Instructions used by machine IR only.
|
|
|
|
INSN: _prologue n ;
|
|
|
|
INSN: _epilogue n ;
|
|
|
|
|
|
|
|
TUPLE: label id ;
|
|
|
|
|
|
|
|
INSN: _label label ;
|
|
|
|
|
|
|
|
: <label> ( -- label ) \ <label> counter label boa ;
|
|
|
|
: define-label ( name -- ) <label> swap set ;
|
|
|
|
|
|
|
|
: resolve-label ( label/name -- )
|
|
|
|
dup label? [ get ] unless _label ;
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
TUPLE: _cond-branch < insn src label ;
|
2008-09-11 03:05:22 -04:00
|
|
|
|
|
|
|
INSN: _branch label ;
|
|
|
|
INSN: _branch-f < _cond-branch ;
|
|
|
|
INSN: _branch-t < _cond-branch ;
|
|
|
|
INSN: _if-intrinsic label quot vregs ;
|
|
|
|
|
2008-09-15 05:22:12 -04:00
|
|
|
M: _cond-branch uses-vregs src>> >vreg 1array ;
|
2008-09-15 02:54:48 -04:00
|
|
|
! M: _if-intrinsic uses-vregs vregs>> values ;
|
2008-09-15 03:59:24 -04:00
|
|
|
|
|
|
|
INSN: _spill src n ;
|
|
|
|
INSN: _reload dst n ;
|