x86_64 compiler + elf output (can compile code that returns exit code)
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
use crate::parser::{Node, cursor::Token};
|
||||
use crate::{
|
||||
backend::arch::x86_64::Asm,
|
||||
parser::{Node, cursor::Token},
|
||||
};
|
||||
|
||||
pub mod x86_64;
|
||||
|
||||
pub enum AsmBlock {
|
||||
X86_64(x86_64::Asm),
|
||||
X86_64(Asm),
|
||||
}
|
||||
|
||||
impl Node for AsmBlock {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
backend::arch::x86_64::RegMode,
|
||||
backend::arch::x86_64::*,
|
||||
io::{CompilerMsg, Span},
|
||||
parser::{
|
||||
Node,
|
||||
@@ -7,20 +7,6 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
pub struct Asm {
|
||||
instrs: Vec<Instr>,
|
||||
}
|
||||
|
||||
pub enum Instr {
|
||||
Mov { dst: RegMode, src: RegImm },
|
||||
Int { code: u64 },
|
||||
}
|
||||
|
||||
pub enum RegImm {
|
||||
Reg(RegMode),
|
||||
Imm(u64),
|
||||
}
|
||||
|
||||
impl Node for Asm {
|
||||
fn parse(ctx: &mut crate::parser::ParseCtx) -> Result<Self, crate::io::CompilerMsg> {
|
||||
let mut instrs = Vec::new();
|
||||
@@ -38,7 +24,9 @@ impl Node for Asm {
|
||||
let Token::Lit(LitTy::Number(num)) = ctx.expect_next()? else {
|
||||
return Err("Expected an immediate".into());
|
||||
};
|
||||
let code = parse_imm(&num, ctx.span)?;
|
||||
let code = parse_imm(&num, ctx.span)?
|
||||
.try_into()
|
||||
.map_err(|_| CompilerMsg::from("Immediate must be a u8"))?;
|
||||
instrs.push(Instr::Int { code });
|
||||
}
|
||||
_ => {
|
||||
@@ -65,8 +53,7 @@ pub fn parse_imm(mut s: &str, span: Span) -> Result<u64, CompilerMsg> {
|
||||
radix = 16;
|
||||
s = &s[2..];
|
||||
}
|
||||
u64::from_str_radix(s, radix)
|
||||
.map_err(|_| CompilerMsg::from(("invalid immediate", span)))
|
||||
u64::from_str_radix(s, radix).map_err(|_| CompilerMsg::from(("invalid immediate", span)))
|
||||
}
|
||||
|
||||
pub fn parse_rmi(ctx: &mut crate::parser::ParseCtx) -> Result<RegImm, CompilerMsg> {
|
||||
|
||||
Reference in New Issue
Block a user