Skip to content

Commit

Permalink
Fuck around and find out: trying to come up with a design for the shi…
Browse files Browse the repository at this point in the history
…n asm tool
  • Loading branch information
DCNick3 committed Jun 22, 2023
1 parent 96128c5 commit 6f8fbc4
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 15 deletions.
118 changes: 118 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ authors = ["DCNick3"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
shin-core = { path = "../shin-core" }
shin-asm = { path = "../shin-asm" }

anyhow = { workspace = true }
clap = { version = "4.0.15", features = ["derive"] }
Expand Down
5 changes: 4 additions & 1 deletion shin-asm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ authors = ["DCNick3"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
shin-core = { path = "../shin-core" }
shin-core = { path = "../shin-core" }

pest = "2.6.0"
pest_derive = "2.6.0"
16 changes: 16 additions & 0 deletions shin-asm/src/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use shin_core::format::scenario::instructions::MemoryAddress;

pub enum Preserve {
// TODO: instead of "just" a MemoryAddress, the user should be able to use aliases
Single(MemoryAddress),
Range(MemoryAddress, MemoryAddress),
}

pub struct Preserves(pub Vec<Preserve>);

pub struct Function {
pub arg_aliases: Vec<String>, // TODO
pub preserves: Preserves,
}

// struct S
18 changes: 4 additions & 14 deletions shin-asm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
use shin_core::format::scenario::instructions::MemoryAddress;
#[macro_use]

Check warning on line 1 in shin-asm/src/lib.rs

View workflow job for this annotation

GitHub Actions / build

unused `#[macro_use]` import
extern crate pest_derive;

pub enum Preserve {
Single(MemoryAddress),
Range(MemoryAddress, MemoryAddress),
}

pub struct Preserves(pub Vec<Preserve>);

pub struct Function {
pub arg_aliases: Vec<String>, // TODO
pub preserves: Preserves,
}

// struct S
pub mod ast;
pub mod parser;
33 changes: 33 additions & 0 deletions shin-asm/src/parser/grammar.pest
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
WHITESPACE = _{ " " | "\t" }
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }

digit = @{ '0'..'9' }

identifier = @{ XID_START ~ XID_CONTINUE* }

integer = @{
"-" ~ digit+
| digit+
}
float = @{
"-" ~ digit+ ~ "." ~ digit+
| digit+ ~ "." ~ digit+
}

register_name_inner = @{ digit | "a" ~ digit | identifier }
register_name = @{ "%" ~ register_name_inner }

label_specifier = { identifier ~ ":" }

// TODO: lists..
expr = { float | integer | register_name | identifier }

generic_instruction_argument = {
expr ~ "," |
expr
}
generic_instruction = {
identifier ~ (generic_instruction_argument)*
}


23 changes: 23 additions & 0 deletions shin-asm/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mod syntax_kind;

use pest::Parser;

Check warning on line 3 in shin-asm/src/parser/mod.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `pest::Parser`
use pest_derive::Parser;

#[derive(Parser)]
#[grammar = "parser/grammar.pest"]
struct ShinAsmParser;

#[cfg(test)]
mod test {
use super::{Rule, ShinAsmParser};
use pest::Parser;

#[test]
fn test() {
let pairs = ShinAsmParser::parse(Rule::identifier, "test").unwrap();
let pairs = ShinAsmParser::parse(Rule::identifier, "a123").unwrap();
let pairs = ShinAsmParser::parse(Rule::generic_instruction, "aboba 123.0, 12").unwrap();
// let pairs = ShinAsmParser::parse(Rule::, "123").unwrap();
println!("{:#?}", pairs);
}
}
Loading

0 comments on commit 6f8fbc4

Please sign in to comment.