-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
303 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
format ELF64 executable 3 | ||
entry main | ||
segment gnustack | ||
segment executable | ||
fib: | ||
sub rsp, 20 | ||
jmp fib_label_1 | ||
fib_label_1: | ||
jmp fib_label_begin | ||
fib_label_begin: | ||
jmp fib_label_4 | ||
fib_label_end: | ||
mov r14, [rsp+0] | ||
add rsp, 20 | ||
mov rax, r14 | ||
ret | ||
fib_label_4: | ||
jmp fib_label_begin | ||
main: | ||
sub rsp, 4 | ||
jmp main_label_1 | ||
main_label_1: | ||
mov r14, [rsp+0] | ||
add rsp, 4 | ||
mov rax, 60 | ||
mov rdi, r14 | ||
syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
format ELF64 | ||
section '.text' executable | ||
function_fib: | ||
goto label_1 | ||
label_1: | ||
goto label_begin | ||
label_begin: | ||
goto label_4 | ||
label_end: | ||
label_4: | ||
goto label_begin | ||
function_main: | ||
goto label_1 | ||
label_1: | ||
format ELF64 executable 3 | ||
entry main | ||
segment gnustack | ||
segment executable | ||
fib: | ||
sub rsp, 20 | ||
jmp fib_label_1 | ||
fib_label_1: | ||
jmp fib_label_begin | ||
fib_label_begin: | ||
jmp fib_label_4 | ||
fib_label_end: | ||
mov rax, [rsp+12] | ||
add rsp, 20 | ||
ret | ||
fib_label_4: | ||
jmp fib_label_begin | ||
main: | ||
sub rsp, 4 | ||
jmp main_label_1 | ||
main_label_1: | ||
mov rdi, 3 | ||
call fib | ||
mov [rsp+0], rax | ||
mov rax, 60 | ||
mov rdi, [rsp+0] | ||
add rsp, 4 | ||
syscall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ function fib, 1 | |
function main, 0 | ||
param 3 | ||
a = call fib, 1 | ||
ret a | ||
ret a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use std::collections::HashSet; | ||
use crate::{fe::ast::*, mw::pass::AstPass}; | ||
|
||
pub struct AsmValidationPass; | ||
|
||
impl AstPass for AsmValidationPass { | ||
fn apply(&self, nodes: &mut Vec<AstNode>) { | ||
if nodes.len() == 0 {return;} | ||
let mut function_names: HashSet<String> = HashSet::new(); | ||
for node in nodes.iter() { | ||
if let AstNode::Function(function_node) = node { | ||
function_names.insert(function_node.name.clone()); | ||
} else { | ||
node.loc().error(String::from("expected top level function instruction")); | ||
} | ||
} | ||
if !function_names.contains(&String::from("main")) { | ||
nodes[0].loc().program_error(String::from("program entry point aka function 'main' not found")); | ||
} | ||
} | ||
fn name(&self) -> String {String::from("asm_validation_pass")} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
use crate::{fe::ast::AstNode, mw::pass::*}; | ||
use crate::cli::CliOptions; | ||
use crate::mw::validate_iden_pass::ValidateIdenPass; | ||
use crate::mw::add_goto_pass::AddGotoPass; | ||
use crate::mw::asm_validation_pass::AsmValidationPass; | ||
|
||
const PASS_MAX_APPLICATION_LIMIT: usize = 1; | ||
|
||
pub fn run_default_ast_pass_manager(nodes: &mut Vec<AstNode>) { | ||
pub fn run_default_ast_pass_manager(nodes: &mut Vec<AstNode>, options: &CliOptions) { | ||
let mut ast_pass_manager: AstPassManager = AstPassManager::new(); | ||
ast_pass_manager.add(AsmValidationPass{}); | ||
ast_pass_manager.add(ValidateIdenPass{}); | ||
ast_pass_manager.add(AddGotoPass{}); | ||
|
||
for _ in 0..PASS_MAX_APPLICATION_LIMIT { | ||
let prev_nodes: Vec<AstNode> = nodes.clone(); | ||
ast_pass_manager.run(nodes); | ||
ast_pass_manager.run(nodes, options); | ||
if prev_nodes == *nodes {break;} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.