Website Summary Files Commits Branches @commit @diff @stats
path: root / assembler / src / main.rs
blob: a28270953f60ae77cc95014ceb6f5874dfb0d563 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mod lexer;
mod parser;

use std::fs::File;
use std::io::{BufRead, BufReader};

use parser::Program;

pub(crate) type Word = i64;
static PROGRAM_START: usize = 10;

fn main() {
    let file_path = "./example.s";

    /* Read */
    let file = File::open(file_path).unwrap();
    let lines = BufReader::new(file).lines();

    /* Lex */
    let mut tokens = Vec::new();
    for line in lines.map_while(Result::ok) {
        tokens.extend(lexer::split(line));
    }

    println!("{:#?}", tokens);

    /* Parse */
    let mut prog = Program::new(tokens);

    /* Intermediate code gen */
    prog.remove_definition_addresses();
    prog.collapse_instructions();

    println!("{:#?}", prog);
    /* Machine code gen */
    prog.instructions_to_constants(PROGRAM_START);
    println!("{:#?}", prog);

}