asm done with parsing and linking. codegen all that's left
This commit is contained in:
+18
-6
@@ -9,11 +9,14 @@ use std::{
|
||||
use common::prelude::Instruction;
|
||||
|
||||
use crate::{
|
||||
model::{Node, Token, TokenType},
|
||||
expand::expand_pseudo_ops,
|
||||
model::{Node, Symbol, Token, TokenType},
|
||||
parser::{Parser, Program},
|
||||
resolver::resolve_dependencies,
|
||||
resolver::{resolve_dependencies, resolve_symbols},
|
||||
};
|
||||
|
||||
pub mod codegen;
|
||||
pub mod expand;
|
||||
pub mod lexer;
|
||||
pub mod model;
|
||||
pub mod parser;
|
||||
@@ -31,8 +34,11 @@ pub fn assemble(src: &Path) -> Vec<Instruction> {
|
||||
Err(err) => println!("BIG ERROR {err:?}"),
|
||||
}
|
||||
|
||||
for node in program.nodes {
|
||||
println!("{node:?}");
|
||||
let mut nodes = program.nodes;
|
||||
resolve_symbols(&mut nodes).unwrap();
|
||||
|
||||
for node in nodes {
|
||||
println!("{node}");
|
||||
}
|
||||
|
||||
vec![]
|
||||
@@ -71,7 +77,7 @@ fn prepare_dependency(
|
||||
"{:20} {:20}",
|
||||
"Expanding PseudoInstructions", filename
|
||||
));
|
||||
let nodes = Parser::expand_pseudo_ops(nodes, file_hash)?;
|
||||
let nodes = expand_pseudo_ops(nodes, file_hash)?;
|
||||
|
||||
program.add_module(nodes);
|
||||
|
||||
@@ -110,6 +116,8 @@ pub enum AssembleError {
|
||||
UnexpectedEof,
|
||||
InvalidFile(PathBuf),
|
||||
UnexpectedToken(Token, TokenType),
|
||||
InvalidArg,
|
||||
UndefinedSymbol(Symbol),
|
||||
}
|
||||
|
||||
impl fmt::Display for AssembleError {
|
||||
@@ -121,6 +129,10 @@ impl fmt::Display for AssembleError {
|
||||
}
|
||||
AssembleError::UnexpectedEof => write!(f, "Unexpected end of file"),
|
||||
AssembleError::InvalidFile(path) => write!(f, "Invalid file {path:?}"),
|
||||
AssembleError::InvalidArg => write!(f, "Invalid argument"),
|
||||
AssembleError::UndefinedSymbol(symbol) => {
|
||||
write!(f, "Undefined symbol {symbol}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +230,7 @@ macro_rules! expect_type {
|
||||
other => {
|
||||
let expected_type = expect_type!(@get_first_type $($variant),+);
|
||||
Err(AssembleError::UnexpectedToken(
|
||||
other.clone(),
|
||||
other.clone().clone(),
|
||||
expected_type,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user