aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-09-25 00:00:24 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-09-25 00:00:24 +0200
commitda91cbbd5bb8cb925dee4a5c6ab6d66588cb2c8f (patch)
tree3f1249d8d866bf76ba57a459f653e67539da7616
parent02a08e6037c860177e9cd0ad5234315c6542fcd6 (diff)
downloadllvm-kaleidoscope-rs-da91cbbd5bb8cb925dee4a5c6ab6d66588cb2c8f.tar.gz
llvm-kaleidoscope-rs-da91cbbd5bb8cb925dee4a5c6ab6d66588cb2c8f.zip
added external fn putchard, and added link flag to export symbols from elf file
-rw-r--r--.cargo/config2
-rw-r--r--src/main.rs11
2 files changed, 12 insertions, 1 deletions
diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..52e8b72
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,2 @@
+[build]
+rustflags = ["-C", "link-args=-rdynamic"]
diff --git a/src/main.rs b/src/main.rs
index 945d588..b660416 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,7 +7,16 @@ use llvm_kaleidoscope_rs::{
};
use std::collections::HashMap;
-use std::io::Read;
+use std::io::{Read, Write};
+
+#[no_mangle]
+#[inline(never)]
+pub extern "C" fn putchard(c: libc::c_double) -> f64 {
+ std::io::stdout()
+ .write(&[c as u8])
+ .expect("Failed to write to stdout!");
+ 0f64
+}
fn main_loop<I>(mut parser: Parser<I>)
where