44 lines
999 B
Rust
44 lines
999 B
Rust
use std::{any::Any, fs::File, io::{BufWriter, Write}};
|
|
use anyhow::Result;
|
|
use bfox_parser::types::token::Token;
|
|
use bfox_parser::types::token::TokenType;
|
|
|
|
use crate::AsmGen;
|
|
|
|
|
|
pub fn compile_x86_64_nasm(_asm_gen: &mut AsmGen, tokens: Vec<Token>, bw: &mut BufWriter<File>) -> Result<()>{
|
|
|
|
writeln!(bw, "BITS 64")?;
|
|
|
|
writeln!(bw, "section .bss")?;
|
|
writeln!(bw, " memory resb 30000")?;
|
|
writeln!(bw, " memory_ptr resb 1")?;
|
|
|
|
writeln!(bw, "section .data")?;
|
|
writeln!(bw, " input db 0")?;
|
|
|
|
writeln!(bw, "section .text")?;
|
|
writeln!(bw, "_start:")?;
|
|
|
|
writeln!(bw, " mov rdi, memory")?;
|
|
writeln!(bw, " mov [memory_ptr], rdi")?;
|
|
|
|
for t in tokens {
|
|
match t.typ {
|
|
|
|
TokenType::Add => {
|
|
writeln!(bw, " inc byte [rdi]")?;
|
|
}
|
|
|
|
ut => todo!("{ut:?}")
|
|
|
|
}
|
|
}
|
|
|
|
// Exit
|
|
writeln!(bw, " mov rax, 60")?;
|
|
writeln!(bw, " mov rdi, 0")?;
|
|
writeln!(bw, " syscall")?;
|
|
|
|
Ok(())
|
|
} |