Initial commit

I should've made a git repo for this much sooner, oops :p
This commit is contained in:
ry755 2022-01-26 22:21:21 -08:00 committed by Ry
commit eeafe0cbb2
4 changed files with 1424 additions and 0 deletions

189
Cargo.lock generated Normal file
View File

@ -0,0 +1,189 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
dependencies = [
"byte-tools",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fox32asm"
version = "0.1.0"
dependencies = [
"lazy_static",
"pest",
"pest_derive",
]
[[package]]
name = "generic-array"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [
"typenum",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "pest"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
dependencies = [
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
dependencies = [
"maplit",
"pest",
"sha-1",
]
[[package]]
name = "proc-macro2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "sha-1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
dependencies = [
"block-buffer",
"digest",
"fake-simd",
"opaque-debug",
]
[[package]]
name = "syn"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "typenum"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
[[package]]
name = "ucd-trie"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "fox32asm"
version = "0.1.0"
edition = "2021"
[dependencies]
lazy_static = "1.4.0"
pest = "2.1.3"
pest_derive = "2.1.0"

145
src/fox32.pest Normal file
View File

@ -0,0 +1,145 @@
WHITESPACE = _{ " " | "\t" | "\n" | "\r" | "\x0B" | "\x0C" | "\xA0" | SPACE_SEPARATOR }
COMMENT = _{ ";" ~ (!"\n" ~ ANY)* }
assembly = {
SOI ~ (origin | include_bin | data | constant | label | instruction)* ~ EOI
}
origin = {
origin_padding |
origin_no_padding
}
origin_padding = { "org.pad" ~ operand_value }
origin_no_padding = { "org" ~ operand_value }
include_bin = { "#include_bin" ~ immediate_str }
data = {
data_byte |
data_half |
data_word |
data_str
}
data_byte = { "data.8" ~ operand_value }
data_half = { "data.16" ~ operand_value }
data_word = { "data.32" ~ operand_value }
data_str = { "data.str" ~ immediate_str }
constant = { "const" ~ constant_name ~ operand_value }
constant_name = ${label_name ~ ":"}
label = ${ label_name ~ ":" }
label_name = @{ label_name_chars+ }
label_name_chars = @{ ASCII_ALPHANUMERIC | "_" }
operand = {
"[" ~ operand_value_ptr ~ "]" |
operand_value
}
operand_value_ptr = {
operand_value
}
operand_value = {
register |
immediate_bin |
immediate_hex |
immediate_dec |
immediate_char |
label_name
}
size = @{
".8" |
".16" |
".32"
}
condition = @{
"ifz" |
"ifnz" |
"ifc" |
"ifnc"
}
instruction = {
condition? ~ instruction_conditional
}
instruction_conditional = {
instruction_zero |
instruction_one ~ size? ~ operand |
instruction_two ~ size? ~ operand ~ "," ~ operand
}
instruction_zero = @{
"nop" |
"halt" |
"brk" |
"reti" |
"ret" |
"ise" |
"icl"
}
instruction_one = @{
"inc" |
"dec" |
"not" |
"jmp" |
"call" |
"loop" |
"rjmp" |
"rcall" |
"rloop" |
"push" |
"pop"
}
instruction_two = @{
"add" |
"sub" |
"mul" |
"pow" |
"div" |
"rem" |
"and" |
"or" |
"xor" |
"sla" |
"sra" |
"srl" |
"rol" |
"ror" |
"bse" |
"bcl" |
"bts" |
"cmp" |
"movz" |
"mov" |
"rta" |
"in" |
"out"
}
immediate_bin = ${ "0b" ~ body_bin }
body_bin = @{ ASCII_BIN_DIGIT+ }
immediate_hex = ${ "0x" ~ body_hex }
body_hex = @{ ASCII_HEX_DIGIT+ }
immediate_dec = ${ body_dec }
body_dec = @{ ASCII_DIGIT+ }
immediate_char = ${ "'" ~ body_char ~ "'" }
body_char = @{ '\x00'..'\x7F' }
immediate_str = ${ "\"" ~ body_str ~ "\"" }
body_str = @{ body_str_chars* }
body_str_chars = {
!("\"" | "\\") ~ ANY
| "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t")
| "\\" ~ ("u" ~ ASCII_HEX_DIGIT{4})
}
register = ${ "r" ~ register_num }
register_num = @{ ASCII_DIGIT+ | "sp" }

1081
src/main.rs Normal file

File diff suppressed because it is too large Load Diff