From 55c493f350a87a4cf8cf1b023c57c7c0f1760173 Mon Sep 17 00:00:00 2001 From: Goren Barak Date: Thu, 16 Nov 2023 19:05:34 -0500 Subject: [PATCH] updated readme --- .gitignore | 1 + .images/slang_logo.png | Bin 0 -> 10195 bytes README.md | 2 +- src/codegen/#fasm.rs# | 102 +++++++++++++++++++++++++++++++++++++++++ src/codegen/.#fasm.rs | 1 + 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 .images/slang_logo.png create mode 100644 src/codegen/#fasm.rs# create mode 120000 src/codegen/.#fasm.rs diff --git a/.gitignore b/.gitignore index c2a9b6f..1ded937 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target tags +TAGS diff --git a/.images/slang_logo.png b/.images/slang_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..65149c55b2b38325bda7e9167780e22c148f1828 GIT binary patch literal 10195 zcmeHt=Q~{O*Y+m3)kL{71PPIZXoF}8QA3*E1%u2)9YhacI*pEt4v<13+wA{?W*+=X9560SnQu)pC}dpNK$E` zPV1knSy}*iX5dK!0AEFFsPi7@vH^gIH74qk)%WPQsojJBxBLIkJ5#Mn1M}Zo(^RU+ z7*y-a$JN)PdNU0=Mp=+(c(oVlF&=vFF`q)oXK_W_qa%!-cn4b49ehd$pb#wLOT8|; z&2P1N4v$wpsGc~N2S|M0S>iS}5$dt=LEHuB!^=R=fQa$yHO+6e)T2A2^EwjDJ{Z-0 zEhL1@;ZuA`RV)tL41hg|5!|1>vt+_y3K~2v;O<`S`mDX{5X@m;<*@}n59lhk(DSlK zE*u2Mu2^n4f910@$ziTQba!ljVm=4xUTdL$ofK^EVnL6RBKpeE0J>Z)^bEgGS6=-d zQ6>|V!tz8p>>GWP!Owu^-|RNo2IvgEm3YNb2btFnmPVnqhr%xoXd+IS!2NHQL3s0(Rg1@|8=G|L`lcmbs)Vgzy zzLLr4RV4=C*#pl=UZ+%(BRGduz87$s{gN9Hd=SOr%kgPpp{WF2v?b9HvjOF>h0^E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E~cXYY{S)AW89EgBt=2Rg# zBN~6W6$`9SZdR$aU9reO?`>!}nb(c$X|5R@t0rKMjS-DjPGWVtRgR;1*+D<;)cZm?rRTN*AgC()i+$b7Ck0cAGoRQUE?htKE+MTC%T)x zD6+0LW4m3JAih_&TcebTPA={QhLvob-Y$}Ut*%OZc392WIpH?X76?3ha_ zbYrVwdBfDbV8(r&GLSgPrZ{csA=2y9!vG>~TJbFn2W~8!l;rJNk$unmZ%jS$C_c&{ z?QS71g8fSLIVfXX1|f^Gm#=GSBWrH^d-V(-x9{$RbgzY^SfUp{rS^gDYj-%rv%+2qUx)FrW2Q~7%)a&EA>XF3;&uWLX)wrUJ*A|3sh05ylKViycGTtFw}LZrQy2Tl%2=)pk(XBp;J1aG zEhMBev5XjBwy2C>-C3zo(_Z-GYHD#bZhjJCy0!QBrcw0Hlu}LO1bSp=$US^yFsKxv z^u{bDj~UGI?0gw^&X^J+g?5qZ>T4J?m*06(?{A})nNZA&Ys$UnFY7$`r?BPpugqHm z5D7=#bNSuXO@}T65x)#PhH|{j*zyJPgY~60x#BCHRu7S@jzY^k;iob<=wBFt? zm@wyAyqnm46I)g}4S%1kB&|k`%Obp~$(i5Zz746V+4jUlCkqIn&6Q9r!>?@OL zWgHsmRlB&F@;gP!u3w%NxUc1z_7o!}9V7#UFEv3P+STZ%&;$1$d8VD?uoY@&lNwMI^_H2=4>=zoi@{-4*E9jm String { + let mut asm_text = String::new(); + let mut asm_data = String::new(); + + asm_text.push_str("format ELF64 executable 3\n"); + asm_text.push_str("segment readable executable\n"); + asm_text.push_str("entry _start\n"); + asm_text.push_str("_start:\n"); + asm_data.push_str("segment readable writeable\n"); + match expr { + Expr::MathExpr(e) => { + asm_text.push_str(format!("\tmov r10, {:?}\n", e.left).as_str()); + asm_text.push_str(format!("\tmov r11, {:?}\n", e.right).as_str()); + match e.operator { + // If the operator is addition. + MathOperator::OP_ADD => { + asm_text.push_str("\tadd r10, r11\n"); + asm_text.push_str("\tmov rax, r10\n"); + }, + // If the operator is multiplication. + MathOperator::OP_MULT => { + asm_text.push_str("\timul r10, r11\n"); + asm_text.push_str("\tmov rax, r10\n"); + }, + // If the operator is division. + MathOperator::OP_DIV => { + asm_text.push_str("\tmov rax, r10\n"); + asm_text.push_str("\tmov rdx, r11\n"); + asm_text.push_str("\tidiv r10, r11\n"); + asm_text.push_str("\tmov rax, r10\n"); + }, + // If the operators is subtraction. + MathOperator::OP_SUB => { + asm_text.push_str("\tsub r10, r11\n"); + asm_text.push_str("\tmov rax, r10\n"); + }, + // If the operator is modulo. + MathOperator::OP_MOD => { + asm_text.push_str("\tmov rax, r10\n"); + asm_text.push_str("\tmov rdx, r11\n"); + asm_text.push_str("\tidiv r10, r11\n"); + asm_text.push_str("\tmov rax, rdx\n"); + + } + } + }, + + Expr::FunCall(e) => { + for (i, p) in e.params.iter().enumerate() { + match i { + 0 => { + // First parameter. Put in %rdi. + asm_text.push_str(format!("\tmov rdi, {:?}\n", p.value).as_str()); + }, + + 1 => { + // Second parameter. Put in %rsi. + asm_text.push_str(format!("\tmov rsi, {:?}\n", p.value).as_str()); + }, + + 2 => { + // Third parameter. Put in %rdx. + asm_text.push_str(format!("\tmov rdx, {:?}\n", p.value).as_str()); + }, + + 3 => { + // Fourth parameter. Put in %rcx. + asm_text.push_str(format!("\tmov rcx, {:?}\n", p.value).as_str()); + }, + + 4 => { + // Fifth parameter. Put in %r8. + asm_text.push_str(format!("\tmov r8, {:?}\n", p.value).as_str()); + }, + + 5 => { + // Sixth parameter. Put in %r9. + asm_text.push_str(format!("\tmov r9, {:?}\n", p.value).as_str()); + }, + + _ => { + // Parameters after the sixth parameter are pushed to the stack. + asm_text.push_str(format!("\tpush {:?}\n", p.value).as_str()); + } + } + } + + asm_text.push_str(format!("call {:?}", e.name).as_str()); + }, + + Expr::VarDefenition(e) => { + asm_data.push_str(format!("{} dq {:?}", e.name, e.value).as_str()); + }, + + _ => unimplemented!("sorry unimplemented"), + } + let asm = format!("{}{}", asm_text, asm_data); + println!("{}", asm); + asm +} diff --git a/src/codegen/.#fasm.rs b/src/codegen/.#fasm.rs new file mode 120000 index 0000000..f430d80 --- /dev/null +++ b/src/codegen/.#fasm.rs @@ -0,0 +1 @@ +goren@goren.13806:1700158488 \ No newline at end of file