Commit 088a6bba authored by nagayama15's avatar nagayama15

rustcの出力するLLVM IRから実行可能ファイルを生成するデモを追加

parent deca457d
include ../common.mk
.PHONY: all test clean
all:
${MAKE} -C fizzbuzz all
${MAKE} -C 8cc all
${MAKE} -C zlib all
${MAKE} -C fizzbuzz all
${MAKE} -C 8cc all
${MAKE} -C zlib all
${MAKE} -C fizzbuzz-rs all
test:
${MAKE} -C fizzbuzz test
${MAKE} -C 8cc test
${MAKE} -C zlib test
${MAKE} -C fizzbuzz test
${MAKE} -C 8cc test
${MAKE} -C zlib test
${MAKE} -C fizzbuzz-rs test
include ../../common.mk
LDFLAGS := \
-pthread \
-lbacktrace \
-ldl \
-ljemalloc
all: ${BIN_DIR}/fizzbuzz.out #${BIN_DIR}/fizzbuzz-wm.out
${BIN_DIR}/fizzbuzz.out: ${OBJ_DIR}/fizzbuzz.ll ${OBJ_DIR}/probestack.o
@mkdir -p ${@D}
clang -o $@ $^ ${LDFLAGS}
${OBJ_DIR}/fizzbuzz.ll: fizzbuzz.rs
@mkdir -p ${@D}
rustc -O -Clto --emit=llvm-ir -o $@ $<
${OBJ_DIR}/probestack.o: probestack.s
@mkdir -p ${@D}
clang -o $@ -c $<
fn main() {
(1 ..= 50).for_each(|i| match (i % 3, i % 5) {
(0, 0) => println!("Fizz Buzz"),
(0, _) => println!("Fizz"),
(_, 0) => println!("Buzz"),
(_, _) => println!("{}", i),
});
}
# To avoid undefined reference to `__rust_probestack`.
# From https://github.com/rust-lang-nursery/compiler-builtins/blob/master/src/probestack.rs
.global __rust_probestack
__rust_probestack:
mov %rax, %r11
cmp $0x1000, %r11
jna 3f
2:
sub $0x1000, %rsp
test %rsp, 8(%rsp)
sub $0x1000, %r11
cmp $0x1000, %r11
ja 2b
3:
sub %r11, %rsp
test %rsp, 8(%rsp)
add %rax, %rsp
ret
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment