Add cretonne_module

This commit is contained in:
bjorn3 2018-06-19 19:51:29 +02:00
parent 9f4f9eb1d7
commit 9d40131d81
4 changed files with 801 additions and 147 deletions

622
Cargo.lock generated
View file

@ -1,18 +1,99 @@
[[package]]
name = "cretonne"
name = "aho-corasick"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-frontend 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "atty"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace-sys"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "bitflags"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clap"
version = "2.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-frontend 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne-codegen"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-entity 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-entity 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -20,15 +101,63 @@ dependencies = [
[[package]]
name = "cretonne-entity"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cretonne-frontend"
version = "0.11.0"
name = "cretonne-faerie"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-module 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"faerie 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"goblin 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne-frontend"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne-module"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-entity 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne-native"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"raw-cpuid 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cretonne-simplejit"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-module 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-native 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"region 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -36,11 +165,51 @@ name = "dtoa"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "env_logger"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "errno"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "faerie"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"goblin 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
"indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"scroll 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"string-interner 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "failure"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -54,21 +223,229 @@ dependencies = [
"synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "goblin"
version = "0.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"scroll 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "goblin"
version = "0.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"scroll 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "humantime"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "indexmap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "itoa"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "lazy_static"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "mach"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quick-error"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quote"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "raw-cpuid"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "region"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"errno 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustc-demangle"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc_codegen_cretonne"
version = "0.1.0"
dependencies = [
"cretonne 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-faerie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-module 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"cretonne-simplejit 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scroll"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"scroll_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scroll"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"scroll_derive 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scroll_derive"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "scroll_derive"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -86,6 +463,38 @@ dependencies = [
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "string-interner"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "strsim"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "structopt"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "structopt-derive"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.11.11"
@ -96,6 +505,16 @@ dependencies = [
"unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "syn"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "synom"
version = "0.11.3"
@ -123,25 +542,200 @@ dependencies = [
"serde_json 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termcolor"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "textwrap"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ucd-util"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "utf8-ranges"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wincolor"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum cretonne 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83e1f8d40914cb726d41a49df9554f200b47f36a03c46e5d6044e9dc8a8a47cd"
"checksum cretonne-codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "312ba69a70bebc54789bd0e28414987b5bcd1173263f6afbd0ee8519b84da4ac"
"checksum cretonne-entity 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0be57790fb6db92704951e37981f5e0121e7bfa077c7b48177317bf63795ba4"
"checksum cretonne-frontend 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "14b0fe88b2bc5b71df2ce460761063da21731926e6b554c84d8b937de6640875"
"checksum aho-corasick 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d6531d44de723825aa81398a6415283229725a00fa30713812ab9323faa82fc4"
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1"
"checksum backtrace 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbdd17cd962b570302f5297aea8648d5923e22e555c2ed2d8b2e34eca646bf6d"
"checksum backtrace-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "bff67d0c06556c0b8e6b5f090f0eac52d950d9dfd1d35ba04e4ca3543eaf6a7e"
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
"checksum cretonne 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "03610d69c786a211347d0be3f7da59cb03b025ef2cd83f66ea98103728f42ecc"
"checksum cretonne-codegen 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8e7e43ab7952e998ea8da4bcda3b53d398396b9b691df44a040be5486a4935ef"
"checksum cretonne-entity 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4109dcfc0c7b8e11ad92a702d3f5df435d2782012118aa75566d2d0db586da3a"
"checksum cretonne-faerie 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e8d665b4ac93c254f79e861696db5a1297133c8c8603e5cd06b26250568a9cb0"
"checksum cretonne-frontend 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e0238865d537393f73598542a906dadfe85fcf070c293cdf882ece170d197455"
"checksum cretonne-module 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "232354804f19cb12bf2ac6f715d26df81a7242b3693a1a6cd2774ff89311e283"
"checksum cretonne-native 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "66d768de850f29bbb2cda9eeed168369c66263bee9068ca1b9af28000216116c"
"checksum cretonne-simplejit 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "54d9e73a7f5bb0529be747a86a164e087c96edfd89e30b6d6f92653b70fc9943"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum env_logger 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0e6e40ebb0e66918a37b38c7acab4e10d299e0463fe2af5d29b9cc86710cfd2a"
"checksum errno 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c858c42ac0b88532f48fca88b0ed947cad4f1f64d904bcd6c9f138f7b95d70"
"checksum faerie 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ffaaaa682748ec082a384edbf1d468ce10ad1b39dcfa3a8c3c0dbc5e6cff754c"
"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82"
"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b"
"checksum goblin 0.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2a5fea7ad351be7398e08003ea92a16bbba9a23c2a0c95d4e37d178276508217"
"checksum goblin 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "5e3ba9fec4dc9a09553388bff2724d3bf06bd64013539f2d3e1e3838eefb310a"
"checksum humantime 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0484fda3e7007f2a4a0d9c3a703ca38c71c54c55602ce4660c419fd32e188c9e"
"checksum indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08173ba1e906efb6538785a8844dd496f5d34f0a2d88038e95195172fc667220"
"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
"checksum mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2fd13ee2dd61cc82833ba05ade5a30bb3d63f7ced605ef827063c63078302de9"
"checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d"
"checksum plain 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
"checksum proc-macro2 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "effdb53b25cdad54f8f48843d67398f7ef2e14f12c1b4cb4effc549a6462a4d6"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a"
"checksum quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e44651a0dc4cdd99f71c83b561e221f714912d11af1a4dff0631f923d53af035"
"checksum raw-cpuid 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "233ec1847057cf4d4591a0d76908aa12812140b11ea7d7d05b4c38cadb069c31"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum regex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75ecf88252dce580404a22444fc7d626c01815debba56a7f4f536772a5ff19d3"
"checksum regex-syntax 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05b06a75f5217880fc5e905952a42750bf44787e56a6c6d6852ed0992f5e1d54"
"checksum region 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f9d3f2bb4b7085e6996e2765b56b783bd8f3a8a4ea5b95683063ca13cded993"
"checksum rustc-demangle 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "76d7ba1feafada44f2d38eed812bd2489a03c0f5abb975799251518b68848649"
"checksum scroll 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b13864e1e0b3ed661d7206d512b8d1c4970f7fd9de23ae4e9b4331f0c25559e8"
"checksum scroll 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "66f024a8cc5e456eb870f688dbd899c84f61190c82c7a911e40f926941969074"
"checksum scroll_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a67086db2a44e94311fc4c02ec3f4751bda0fca9d87fd4e1bfe1cef55e9411d"
"checksum scroll_derive 0.9.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f9a353f5dd99e42ff097d5a61db3257aa2c7127d76a3fa8287b642ef9ae0f7c5"
"checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95"
"checksum serde_json 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)" = "fc97cccc2959f39984524026d760c08ef0dd5f0f5948c8d31797dbfae458c875"
"checksum string-interner 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abb38a0d8fe673c40b10b6b75abcb076a958cc10fb894f14993d9737c4c87000"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum structopt 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8e9ad6a11096cbecdcca0cc6aa403fdfdbaeda2fb3323a39c98e6a166a1e45a"
"checksum structopt-derive 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4cbce8ccdc62166bd594c14396a3242bf94c337a51dbfa9be1076dd74b3db2af"
"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad"
"checksum syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c67da57e61ebc7b7b6fff56bb34440ca3a83db037320b0507af4c10368deda7d"
"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6"
"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd"
"checksum target-lexicon 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "71b0a95ba4eff593189d912039fba46ce6ca1876ea6c16830e15340919d0a250"
"checksum termcolor 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "adc4587ead41bf016f11af03e55a624c06568b5a19db4e90fde573d805074f83"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693"
"checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963"
"checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd"
"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
"checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767"

View file

@ -7,4 +7,7 @@ authors = ["bjorn3 <bjorn3@users.noreply.github.com>"]
crate-type = ["dylib"]
[dependencies]
cretonne = "0.11.0"
cretonne = "0.12.0"
cretonne-module = "0.12.0"
cretonne-simplejit = "0.12.0"
cretonne-faerie = "0.12.0"

View file

@ -2,24 +2,26 @@ use syntax::ast::{IntTy, UintTy};
use rustc_mir::monomorphize::MonoItem;
use cretonne::prelude::*;
//use cretonne::codegen::Context;
use cretonne::codegen::ir::{
ExternalName,
FuncRef,
function::Function,
};
use cretonne_module::{Module, Backend, FuncId, Linkage};
use cretonne_simplejit::{SimpleJITBuilder, SimpleJITBackend};
use std::any::Any;
use std::collections::HashMap;
use prelude::*;
pub struct Translated {
f: Function,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct Variable(Local);
type CurrentBackend = SimpleJITBackend;
impl EntityRef for Variable {
fn new(u: usize) -> Self {
Variable(Local::new(u))
@ -37,35 +39,35 @@ enum CValue {
}
impl CValue {
fn force_stack<'a, 'tcx: 'a>(self, ccx: &mut CodegenCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Value {
fn force_stack<'a, 'tcx: 'a>(self, fx: &mut FunctionCx<'a, 'tcx>, ty: Ty<'tcx>) -> Value {
match self {
CValue::ByRef(value) => value,
CValue::ByVal(value) => {
let layout = ccx.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
let stack_slot = ccx.bcx.create_stack_slot(StackSlotData {
let layout = fx.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: layout.size.bytes() as u32,
offset: None,
});
ccx.bcx.ins().stack_store(value, stack_slot, 0);
ccx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
fx.bcx.ins().stack_store(value, stack_slot, 0);
fx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
}
CValue::Func(func) => {
let func = ccx.bcx.ins().func_addr(types::I64, func);
CValue::ByVal(func).force_stack(ccx, ty)
let func = fx.bcx.ins().func_addr(types::I64, func);
CValue::ByVal(func).force_stack(fx, ty)
}
}
}
fn load_value<'a, 'tcx: 'a>(self, ccx: &mut CodegenCtxt<'a, 'tcx>, ty: Ty<'tcx>) -> Value {
fn load_value<'a, 'tcx: 'a>(self, fx: &mut FunctionCx<'a, 'tcx>, ty: Ty<'tcx>) -> Value {
match self {
CValue::ByRef(value) => {
let cton_ty = cton_type_from_ty(ty).unwrap();
ccx.bcx.ins().load(cton_ty, MemFlags::new(), value, 0)
fx.bcx.ins().load(cton_ty, MemFlags::new(), value, 0)
}
CValue::ByVal(value) => value,
CValue::Func(func) => {
ccx.bcx.ins().func_addr(types::I64, func)
fx.bcx.ins().func_addr(types::I64, func)
}
}
}
@ -75,7 +77,15 @@ pub fn trans_crate<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Box<Any> {
let link_meta = ::build_link_meta(tcx.crate_hash(LOCAL_CRATE));
let metadata = tcx.encode_metadata(&link_meta);
let mut translated_mono_items = Vec::new();
let module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
//let mut context = Context::new();
let mut cx = CodegenCx {
tcx,
module,
def_id_fn_id_map: HashMap::new(),
};
let cx = &mut cx;
for mono_item in
collector::collect_crate_mono_items(
@ -83,51 +93,72 @@ pub fn trans_crate<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Box<Any> {
collector::MonoItemCollectionMode::Eager
).0 {
match mono_item {
MonoItem::Fn(Instance {
def: InstanceDef::Item(def_id),
substs,
}) => {
let sig = tcx.fn_sig(def_id);
let sig = tcx.subst_and_normalize_erasing_regions(substs, ParamEnv::reveal_all(), &sig);
let mut f = Function::with_name_signature(ext_name_from_did(def_id), cton_sig_from_fn_sig(sig.skip_binder()));
MonoItem::Fn(inst) => match inst {
Instance {
def: InstanceDef::Item(def_id),
substs,
} => {
let sig = tcx.fn_sig(def_id);
let sig = cton_sig_from_fn_sig(tcx, sig, substs);
let func_id = {
let module = &mut cx.module;
*cx.def_id_fn_id_map.entry(inst).or_insert_with(|| {
module.declare_function(&tcx.absolute_item_path_str(def_id), Linkage::Local, &sig).unwrap()
})
};
trans_fn(tcx, &mut f, def_id, substs);
let mut f = Function::with_name_signature(ext_name_from_did(def_id), sig);
let flags = settings::Flags::new(settings::builder());
let verify_error: String = ::cretonne::codegen::verify_function(&f, &flags)
.map(|_| String::new())
.unwrap_or_else(|err| format!("\n\ncretonne error: {}", err));
trans_fn(cx, &mut f, def_id, substs);
let mut mir = ::std::io::Cursor::new(Vec::new());
::rustc_mir::util::write_mir_pretty(tcx, Some(def_id), &mut mir).unwrap();
let mut cton = String::new();
::cretonne::codegen::write_function(&mut cton, &f, None).unwrap();
tcx.sess.warn(&format!("{:?}:\n\n{}\n\n{}{}", def_id, String::from_utf8_lossy(&mir.into_inner()), cton, verify_error));
let flags = settings::Flags::new(settings::builder());
let verify_error: String = ::cretonne::codegen::verify_function(&f, &flags)
.map(|_| String::new())
.unwrap_or_else(|err| format!("\n\ncretonne error: {}", err));
translated_mono_items.push(Translated {
f,
});
let mut mir = ::std::io::Cursor::new(Vec::new());
::rustc_mir::util::write_mir_pretty(cx.tcx, Some(def_id), &mut mir).unwrap();
let mut cton = String::new();
::cretonne::codegen::write_function(&mut cton, &f, None).unwrap();
tcx.sess.warn(&format!("{:?}:\n\n{}\n\n{}{}", def_id, String::from_utf8_lossy(&mir.into_inner()), cton, verify_error));
//context.func = f;
//cx.module.define_function(func_id, &mut context).unwrap();
//context.clear();
}
_ => {}
}
_ => {}
}
}
//cx.module.finalize_all();
//cx.module.finish();
Box::new(::OngoingCodegen {
metadata: metadata,
translated_mono_items,
//translated_module: Module::new(::cretonne_faerie::FaerieBuilder::new(,
crate_name: tcx.crate_name(LOCAL_CRATE),
})
}
struct CodegenCtxt<'a, 'tcx: 'a> {
struct CodegenCx<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
module: Module<CurrentBackend>,
def_id_fn_id_map: HashMap<Instance<'tcx>, FuncId>,
}
struct FunctionCx<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
module: &'a mut Module<CurrentBackend>,
def_id_fn_id_map: &'a mut HashMap<Instance<'tcx>, FuncId>,
bcx: FunctionBuilder<'a, Variable>,
mir: &'tcx Mir<'tcx>,
ebb_map: HashMap<BasicBlock, Ebb>,
args_map: HashMap<Local, Value>,
}
impl<'f, 'tcx> CodegenCtxt<'f, 'tcx> {
impl<'f, 'tcx> FunctionCx<'f, 'tcx> {
fn get_ebb(&self, bb: BasicBlock) -> Ebb {
*self.ebb_map.get(&bb).unwrap()
}
@ -139,10 +170,20 @@ impl<'f, 'tcx> CodegenCtxt<'f, 'tcx> {
LocalKind::Temp | LocalKind::Var => self.bcx.use_var(Variable(local)),
}
}
fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
let tcx = self.tcx;
let module = &mut self.module;
let func_id = *self.def_id_fn_id_map.entry(inst).or_insert_with(|| {
let sig = cton_sig_from_instance(tcx, inst);
module.declare_function(&tcx.absolute_item_path_str(inst.def_id()), Linkage::Local, &sig).unwrap()
});
module.declare_func_in_func(func_id, &mut self.bcx.func)
}
}
fn trans_fn<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &mut Function, def_id: DefId, substs: &Substs<'tcx>) {
let mir = tcx.optimized_mir(def_id);
fn trans_fn<'a, 'tcx: 'a>(cx: &mut CodegenCx<'a, 'tcx>, f: &mut Function, def_id: DefId, substs: &Substs<'tcx>) {
let mir = cx.tcx.optimized_mir(def_id);
let mut func_ctx = FunctionBuilderContext::new();
let mut bcx: FunctionBuilder<Variable> = FunctionBuilder::new(f, &mut func_ctx);
@ -160,7 +201,7 @@ fn trans_fn<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &mut Function, def_id:
}
for local in mir.vars_and_temps_iter() {
let layout = tcx.layout_of(ParamEnv::reveal_all().and(mir.local_decls[local].ty)).unwrap();
let layout = cx.tcx.layout_of(ParamEnv::reveal_all().and(mir.local_decls[local].ty)).unwrap();
let stack_slot = bcx.create_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: layout.size.bytes() as u32,
@ -173,63 +214,65 @@ fn trans_fn<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &mut Function, def_id:
}
bcx.ins().jump(*ebb_map.get(&START_BLOCK).unwrap(), &[]);
let mut ccx = CodegenCtxt {
tcx,
let mut fx = FunctionCx {
tcx: cx.tcx,
module: &mut cx.module,
def_id_fn_id_map: &mut cx.def_id_fn_id_map,
bcx,
mir,
ebb_map,
args_map,
};
let ccx = &mut ccx;
let fx = &mut fx;
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
let ebb = ccx.get_ebb(bb);
ccx.bcx.switch_to_block(ebb);
let ebb = fx.get_ebb(bb);
fx.bcx.switch_to_block(ebb);
for stmt in &bb_data.statements {
trans_stmt(ccx, stmt);
trans_stmt(fx, stmt);
}
match &bb_data.terminator().kind {
TerminatorKind::Goto { target } => {
let ebb = ccx.get_ebb(*target);
ccx.bcx.ins().jump(ebb, &[]);
let ebb = fx.get_ebb(*target);
fx.bcx.ins().jump(ebb, &[]);
}
TerminatorKind::Return => {
ccx.bcx.ins().return_(&[]);
fx.bcx.ins().return_(&[]);
}
TerminatorKind::Assert { cond, expected, msg: _, target, cleanup: _ } => {
let cond_ty = cond.ty(&ccx.mir.local_decls, ccx.tcx);
let cond = trans_operand(ccx, cond).load_value(ccx, cond_ty);
let target = ccx.get_ebb(*target);
let cond_ty = cond.ty(&fx.mir.local_decls, fx.tcx);
let cond = trans_operand(fx, cond).load_value(fx, cond_ty);
let target = fx.get_ebb(*target);
if *expected {
ccx.bcx.ins().brz(cond, target, &[]);
fx.bcx.ins().brz(cond, target, &[]);
} else {
ccx.bcx.ins().brnz(cond, target, &[]);
fx.bcx.ins().brnz(cond, target, &[]);
}
ccx.bcx.ins().trap(TrapCode::User(!0));
fx.bcx.ins().trap(TrapCode::User(!0));
}
TerminatorKind::SwitchInt { discr, switch_ty, values, targets } => {
let discr_ty = discr.ty(&ccx.mir.local_decls, ccx.tcx);
let discr = trans_operand(ccx, discr).load_value(ccx, discr_ty);
let discr_ty = discr.ty(&fx.mir.local_decls, fx.tcx);
let discr = trans_operand(fx, discr).load_value(fx, discr_ty);
let mut jt_data = JumpTableData::new();
for (i, value) in values.iter().enumerate() {
let ebb = ccx.get_ebb(targets[i]);
let ebb = fx.get_ebb(targets[i]);
jt_data.set_entry(*value as usize, ebb);
}
let mut jump_table = ccx.bcx.create_jump_table(jt_data);
ccx.bcx.ins().br_table(discr, jump_table);
let otherwise_ebb = ccx.get_ebb(targets[targets.len() - 1]);
ccx.bcx.ins().jump(otherwise_ebb, &[]);
let mut jump_table = fx.bcx.create_jump_table(jt_data);
fx.bcx.ins().br_table(discr, jump_table);
let otherwise_ebb = fx.get_ebb(targets[targets.len() - 1]);
fx.bcx.ins().jump(otherwise_ebb, &[]);
}
TerminatorKind::Call { func, args, destination, cleanup: _ } => {
let func_ty = func.ty(&ccx.mir.local_decls, ccx.tcx);
let func = trans_operand(ccx, func);
let func_ty = func.ty(&fx.mir.local_decls, fx.tcx);
let func = trans_operand(fx, func);
let return_place = if let Some((place, _)) = destination {
trans_place(ccx, place)
trans_place(fx, place)
} else {
ccx.bcx.ins().iconst(types::I64, 0)
fx.bcx.ins().iconst(types::I64, 0)
};
let args = Some(return_place)
.into_iter()
@ -237,36 +280,35 @@ fn trans_fn<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &mut Function, def_id:
args
.into_iter()
.map(|arg| {
let ty = arg.ty(&ccx.mir.local_decls, ccx.tcx);
let arg = trans_operand(ccx, arg);
arg.force_stack(ccx, ty)
let ty = arg.ty(&fx.mir.local_decls, fx.tcx);
let arg = trans_operand(fx, arg);
arg.force_stack(fx, ty)
})
).collect::<Vec<_>>();
match func {
CValue::Func(func) => {
ccx.bcx.ins().call(func, &args);
fx.bcx.ins().call(func, &args);
}
func => {
let func = func.load_value(ccx, func_ty);
let func = func.load_value(fx, func_ty);
let sig = match func_ty.sty {
TypeVariants::TyFnDef(def_id, _substs) => ccx.tcx.fn_sig(def_id),
TypeVariants::TyFnDef(def_id, _substs) => fx.tcx.fn_sig(def_id),
TypeVariants::TyFnPtr(fn_sig) => fn_sig,
_ => bug!("Calling non function type {:?}", func_ty),
};
let sig = ccx.tcx.subst_and_normalize_erasing_regions(substs, ParamEnv::reveal_all(), &sig);
let sig = ccx.bcx.import_signature(cton_sig_from_fn_sig(sig.skip_binder()));
ccx.bcx.ins().call_indirect(sig, func, &args);
let sig = fx.bcx.import_signature(cton_sig_from_fn_sig(fx.tcx, sig, substs));
fx.bcx.ins().call_indirect(sig, func, &args);
}
}
if let Some((_, dest)) = *destination {
let ret_ebb = ccx.get_ebb(dest);
ccx.bcx.ins().jump(ret_ebb, &[]);
let ret_ebb = fx.get_ebb(dest);
fx.bcx.ins().jump(ret_ebb, &[]);
} else {
ccx.bcx.ins().trap(TrapCode::User(!0));
fx.bcx.ins().trap(TrapCode::User(!0));
}
}
TerminatorKind::Resume | TerminatorKind::Abort | TerminatorKind::Unreachable => {
ccx.bcx.ins().trap(TrapCode::User(!0));
fx.bcx.ins().trap(TrapCode::User(!0));
}
TerminatorKind::Yield { .. } |
TerminatorKind::FalseEdges { .. } |
@ -279,34 +321,34 @@ fn trans_fn<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, f: &mut Function, def_id:
}
}
ccx.bcx.seal_all_blocks();
ccx.bcx.finalize();
fx.bcx.seal_all_blocks();
fx.bcx.finalize();
}
fn trans_stmt<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, stmt: &Statement<'tcx>) {
fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, stmt: &Statement<'tcx>) {
match &stmt.kind {
StatementKind::Assign(place, rval) => {
let ty = place.ty(&ccx.mir.local_decls, ccx.tcx).to_ty(ccx.tcx);
let lval = trans_place(ccx, place);
let rval = trans_rval(ccx, rval);
do_memcpy(ccx, lval, rval, ty);
let ty = place.ty(&fx.mir.local_decls, fx.tcx).to_ty(fx.tcx);
let lval = trans_place(fx, place);
let rval = trans_rval(fx, rval);
do_memcpy(fx, lval, rval, ty);
}
StatementKind::StorageLive(_) | StatementKind::StorageDead(_) | StatementKind::Nop => {}
_ => unimplemented!("stmt {:?}", stmt),
}
}
fn trans_place<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, place: &Place<'tcx>) -> Value {
fn trans_place<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, place: &Place<'tcx>) -> Value {
match place {
Place::Local(local) => ccx.get_local(*local),
Place::Local(local) => fx.get_local(*local),
Place::Projection(projection) => {
let base = trans_place(ccx, &projection.base);
let base = trans_place(fx, &projection.base);
match projection.elem {
ProjectionElem::Field(field, ty) => {
let layout = ccx.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
let layout = fx.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
let field_offset = layout.fields.offset(field.index());
let field_offset = ccx.bcx.ins().iconst(types::I64, field_offset.bytes() as i64);
ccx.bcx.ins().iadd(base, field_offset)
let field_offset = fx.bcx.ins().iconst(types::I64, field_offset.bytes() as i64);
fx.bcx.ins().iadd(base, field_offset)
}
_ => unimplemented!("projection {:?}", projection),
}
@ -315,70 +357,71 @@ fn trans_place<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, place: &Place<'tcx
}
}
fn trans_rval<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, rval: &Rvalue<'tcx>) -> Value {
fn trans_rval<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, rval: &Rvalue<'tcx>) -> Value {
match rval {
Rvalue::Use(operand) => {
let operand_ty = operand.ty(&ccx.mir.local_decls, ccx.tcx);
trans_operand(ccx, operand).force_stack(ccx, operand_ty)
let operand_ty = operand.ty(&fx.mir.local_decls, fx.tcx);
trans_operand(fx, operand).force_stack(fx, operand_ty)
},
Rvalue::CheckedBinaryOp(bin_op, lhs, rhs) => {
match bin_op {
BinOp::Mul => {
let ty = lhs.ty(&ccx.mir.local_decls, ccx.tcx);
let lhs_ty = lhs.ty(&ccx.mir.local_decls, ccx.tcx);
let lhs = trans_operand(ccx, lhs).load_value(ccx, lhs_ty);
let rhs_ty = rhs.ty(&ccx.mir.local_decls, ccx.tcx);
let rhs = trans_operand(ccx, rhs).load_value(ccx, rhs_ty);
match ty.sty {
let ty = lhs.ty(&fx.mir.local_decls, fx.tcx);
let lhs_ty = lhs.ty(&fx.mir.local_decls, fx.tcx);
let lhs = trans_operand(fx, lhs).load_value(fx, lhs_ty);
let rhs_ty = rhs.ty(&fx.mir.local_decls, fx.tcx);
let rhs = trans_operand(fx, rhs).load_value(fx, rhs_ty);
let res = match ty.sty {
TypeVariants::TyUint(_) => {
ccx.bcx.ins().imul(lhs, rhs)
fx.bcx.ins().imul(lhs, rhs)
}
_ => unimplemented!(),
}
};
let layout = fx.tcx.layout_of(ParamEnv::empty().and(rval.ty(&fx.mir.local_decls, fx.tcx))).unwrap();
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
kind: StackSlotKind::ExplicitSlot,
size: layout.size.bytes() as u32,
offset: None,
});
fx.bcx.ins().stack_store(res, stack_slot, 1);
fx.bcx.ins().stack_addr(types::I64, stack_slot, 1)
}
bin_op => unimplemented!("checked bin op {:?} {:?} {:?}", bin_op, lhs, rhs),
}
}
Rvalue::Cast(CastKind::ReifyFnPointer, operand, ty) => {
let operand = trans_operand(ccx, operand);
operand.force_stack(ccx, ty)
let operand = trans_operand(fx, operand);
operand.force_stack(fx, ty)
}
Rvalue::Cast(CastKind::UnsafeFnPointer, operand, ty) => {
trans_operand(ccx, operand).force_stack(ccx, ty)
trans_operand(fx, operand).force_stack(fx, ty)
}
rval => unimplemented!("rval {:?}", rval),
}
}
fn trans_operand<'a, 'tcx>(ccx: &mut CodegenCtxt<'a, 'tcx>, operand: &Operand<'tcx>) -> CValue {
fn trans_operand<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx>, operand: &Operand<'tcx>) -> CValue {
match operand {
Operand::Move(place) |
Operand::Copy(place) => CValue::ByRef(trans_place(ccx, place)),
Operand::Copy(place) => CValue::ByRef(trans_place(fx, place)),
Operand::Constant(const_) => {
match const_.literal {
Literal::Value { value } => {
let layout = ccx.tcx.layout_of(ParamEnv::empty().and(const_.ty)).unwrap();
let layout = fx.tcx.layout_of(ParamEnv::empty().and(const_.ty)).unwrap();
match const_.ty.sty {
TypeVariants::TyUint(_) => {
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
let iconst = ccx.bcx.ins().iconst(cton_type_from_ty(const_.ty).unwrap(), bits as u64 as i64);
let iconst = fx.bcx.ins().iconst(cton_type_from_ty(const_.ty).unwrap(), bits as u64 as i64);
CValue::ByVal(iconst)
}
TypeVariants::TyInt(_) => {
let bits = value.to_scalar().unwrap().to_bits(layout.size).unwrap();
let iconst = ccx.bcx.ins().iconst(cton_type_from_ty(const_.ty).unwrap(), bits as i128 as i64);
let iconst = fx.bcx.ins().iconst(cton_type_from_ty(const_.ty).unwrap(), bits as i128 as i64);
CValue::ByVal(iconst)
}
TypeVariants::TyFnDef(def_id, substs) => {
let ext_name = ext_name_from_did(def_id);
let sig = ccx.tcx.fn_sig(def_id);
let sig = ccx.tcx.subst_and_normalize_erasing_regions(substs, ParamEnv::reveal_all(), &sig);
let sig = ccx.bcx.import_signature(cton_sig_from_fn_sig(sig.skip_binder()));
CValue::Func(ccx.bcx.import_function(ExtFuncData {
name: ext_name,
signature: sig,
colocated: false,
}))
let func_ref = fx.get_function_ref(Instance::new(def_id, substs));
CValue::Func(func_ref)
}
_ => unimplemented!("value {:?} ty {:?}", value, const_.ty),
}
@ -386,12 +429,11 @@ fn trans_operand<'a, 'tcx>(ccx: &mut CodegenCtxt<'a, 'tcx>, operand: &Operand<'t
_ => unimplemented!()
}
}
operand => unimplemented!("operand {:?}", operand),
}
}
fn do_memcpy<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, to: Value, from: Value, ty: Ty<'tcx>) {
let layout = ccx.tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap();
fn do_memcpy<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, to: Value, from: Value, ty: Ty<'tcx>) {
let layout = fx.tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap();
let size = layout.size.bytes() as i32;
let ty = match size {
2 => Some(types::I16),
@ -400,12 +442,12 @@ fn do_memcpy<'a, 'tcx: 'a>(ccx: &mut CodegenCtxt<'a, 'tcx>, to: Value, from: Val
_ => None,
};
if let Some(ty) = ty {
let data = ccx.bcx.ins().load(ty, MemFlags::new(), from, 0);
ccx.bcx.ins().store(MemFlags::new(), data, to, 0);
let data = fx.bcx.ins().load(ty, MemFlags::new(), from, 0);
fx.bcx.ins().store(MemFlags::new(), data, to, 0);
} else {
for i in 0..size {
let byte = ccx.bcx.ins().load(types::I8, MemFlags::new(), from, i);
ccx.bcx.ins().store(MemFlags::new(), byte, to, i);
let byte = fx.bcx.ins().load(types::I8, MemFlags::new(), from, i);
fx.bcx.ins().store(MemFlags::new(), byte, to, i);
}
}
}
@ -414,9 +456,21 @@ fn ext_name_from_did(def_id: DefId) -> ExternalName {
ExternalName::user(def_id.krate.as_u32(), def_id.index.as_raw_u32())
}
fn cton_sig_from_fn_sig(sig: &FnSig) -> Signature {
fn cton_sig_from_fn_sig<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sig: PolyFnSig<'tcx>, substs: &Substs<'tcx>) -> Signature {
let sig = tcx.subst_and_normalize_erasing_regions(substs, ParamEnv::reveal_all(), &sig);
cton_sig_from_mono_fn_sig(sig)
}
fn cton_sig_from_instance<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, inst: Instance<'tcx>) -> Signature {
let fn_ty = inst.ty(tcx);
let sig = fn_ty.fn_sig(tcx);
cton_sig_from_mono_fn_sig(sig)
}
fn cton_sig_from_mono_fn_sig<'a ,'tcx: 'a>(sig: PolyFnSig<'tcx>) -> Signature {
let sig = sig.skip_binder();
let inputs = sig.inputs();
let output = sig.output();
let _output = sig.output();
assert!(!sig.variadic, "Variadic function are not yet supported");
let call_conv = match sig.abi {
_ => CallConv::SystemV,

View file

@ -9,6 +9,9 @@ extern crate rustc_incremental;
extern crate rustc_data_structures;
extern crate cretonne;
extern crate cretonne_module;
extern crate cretonne_simplejit;
extern crate cretonne_faerie;
use syntax::symbol::Symbol;
use rustc::session::{
@ -34,7 +37,7 @@ mod base;
mod prelude {
pub use rustc::session::Session;
pub use rustc::hir::def_id::{DefId, LOCAL_CRATE};
pub use rustc::ty::{TyCtxt, Ty, TypeVariants, Instance, InstanceDef, ParamEnv, FnSig, subst::Substs};
pub use rustc::ty::{TyCtxt, Ty, TypeVariants, Instance, InstanceDef, ParamEnv, FnSig, PolyFnSig, subst::Substs};
pub use rustc::mir::*;
pub use rustc_mir::monomorphize::collector;
pub use rustc_data_structures::{
@ -49,7 +52,7 @@ struct CretonneCodegenBackend(());
struct OngoingCodegen {
metadata: EncodedMetadata,
translated_mono_items: Vec<base::Translated>,
//translated_module: Module<cretonne_faerie::FaerieBackend>,
crate_name: Symbol,
}