Skip to content

Commit

Permalink
Remove features, add PioVersion and IrqIndexMode
Browse files Browse the repository at this point in the history
  • Loading branch information
CBJamo committed Oct 1, 2024
1 parent a587e90 commit 3d81f47
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 485 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ repository = "https://github.com/rp-rs/pio-rs"
[workspace]
members = ["pio-proc", "pio-parser"]

[features]
rp2350 = ["pio-proc/rp2350", "pio-parser/rp2350"]

[dependencies]
arrayvec = { version = "0.7", default-features = false }
paste = "1.0"
Expand Down
3 changes: 0 additions & 3 deletions pio-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ description = "Raspberry Silicon PIO asm parser"
license = "MIT"
repository = "https://github.com/rp-rs/pio-rs"

[features]
rp2350 = ["pio/rp2350"]

[dependencies]
lalrpop-util = { version = "0.21.0", features = ["lexer"] }
pio = { path = "..", version = "0.2.1" }
Expand Down
11 changes: 1 addition & 10 deletions pio-parser/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
fn main() {
#[cfg(not(feature = "rp2350"))]
lalrpop::Configuration::new()
.set_out_dir(std::env::var("OUT_DIR").unwrap())
.process_file("src/rp2040.lalrpop")
.unwrap();
#[cfg(feature = "rp2350")]
lalrpop::Configuration::new()
.set_out_dir(std::env::var("OUT_DIR").unwrap())
.process_file("src/rp2350.lalrpop")
.unwrap();
lalrpop::process_root().unwrap();
}
47 changes: 7 additions & 40 deletions pio-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@
#![allow(clippy::upper_case_acronyms)]

use pio::{
InSource, Instruction, InstructionOperands, JmpCondition, MovDestination, MovOperation,
MovSource, OutDestination, ProgramWithDefines, SetDestination, WaitSource,
InSource, Instruction, InstructionOperands, IrqIndexMode, JmpCondition, MovDestination,
MovOperation, MovRxIndex, MovSource, OutDestination, ProgramWithDefines, SetDestination,
WaitSource,
};

#[cfg(feature = "rp2350")]
use pio::MovRxIndex;

use std::collections::HashMap;

mod parser {
#![allow(clippy::all)]
#![allow(unused)]
#[cfg(not(feature = "rp2350"))]
include!(concat!(env!("OUT_DIR"), "/src/rp2040.rs"));
#[cfg(feature = "rp2350")]
include!(concat!(env!("OUT_DIR"), "/src/rp2350.rs"));
include!(concat!(env!("OUT_DIR"), "/pio.rs"));
}

#[derive(Debug)]
Expand Down Expand Up @@ -97,28 +92,21 @@ pub(crate) enum ParsedMovDestination {
PINS,
X,
Y,
#[cfg(feature = "rp2350")]
PINDIRS,
EXEC,
PC,
ISR,
OSR,
#[cfg(feature = "rp2350")]
RXFIFOY,
#[cfg(feature = "rp2350")]
RXFIFO0,
#[cfg(feature = "rp2350")]
RXFIFO1,
#[cfg(feature = "rp2350")]
RXFIFO2,
#[cfg(feature = "rp2350")]
RXFIFO3,
}

#[derive(Debug)]
enum MovDestInternal {
Mov(MovDestination),
#[cfg(feature = "rp2350")]
Fifo(MovRxIndex),
}

Expand All @@ -128,21 +116,15 @@ impl From<ParsedMovDestination> for MovDestInternal {
ParsedMovDestination::PINS => MovDestInternal::Mov(MovDestination::PINS),
ParsedMovDestination::X => MovDestInternal::Mov(MovDestination::X),
ParsedMovDestination::Y => MovDestInternal::Mov(MovDestination::Y),
#[cfg(feature = "rp2350")]
ParsedMovDestination::PINDIRS => MovDestInternal::Mov(MovDestination::PINDIRS),
ParsedMovDestination::EXEC => MovDestInternal::Mov(MovDestination::EXEC),
ParsedMovDestination::PC => MovDestInternal::Mov(MovDestination::PC),
ParsedMovDestination::ISR => MovDestInternal::Mov(MovDestination::ISR),
ParsedMovDestination::OSR => MovDestInternal::Mov(MovDestination::OSR),
#[cfg(feature = "rp2350")]
ParsedMovDestination::RXFIFOY => MovDestInternal::Fifo(MovRxIndex::RXFIFOY),
#[cfg(feature = "rp2350")]
ParsedMovDestination::RXFIFO0 => MovDestInternal::Fifo(MovRxIndex::RXFIFO0),
#[cfg(feature = "rp2350")]
ParsedMovDestination::RXFIFO1 => MovDestInternal::Fifo(MovRxIndex::RXFIFO1),
#[cfg(feature = "rp2350")]
ParsedMovDestination::RXFIFO2 => MovDestInternal::Fifo(MovRxIndex::RXFIFO2),
#[cfg(feature = "rp2350")]
ParsedMovDestination::RXFIFO3 => MovDestInternal::Fifo(MovRxIndex::RXFIFO3),
}
}
Expand All @@ -157,22 +139,16 @@ pub(crate) enum ParsedMovSource {
STATUS,
ISR,
OSR,
#[cfg(feature = "rp2350")]
RXFIFOY,
#[cfg(feature = "rp2350")]
RXFIFO0,
#[cfg(feature = "rp2350")]
RXFIFO1,
#[cfg(feature = "rp2350")]
RXFIFO2,
#[cfg(feature = "rp2350")]
RXFIFO3,
}

#[derive(Debug)]
enum MovSrcInternal {
Mov(MovSource),
#[cfg(feature = "rp2350")]
Fifo(MovRxIndex),
}

Expand All @@ -186,15 +162,10 @@ impl From<ParsedMovSource> for MovSrcInternal {
ParsedMovSource::STATUS => MovSrcInternal::Mov(MovSource::STATUS),
ParsedMovSource::ISR => MovSrcInternal::Mov(MovSource::ISR),
ParsedMovSource::OSR => MovSrcInternal::Mov(MovSource::OSR),
#[cfg(feature = "rp2350")]
ParsedMovSource::RXFIFOY => MovSrcInternal::Fifo(MovRxIndex::RXFIFOY),
#[cfg(feature = "rp2350")]
ParsedMovSource::RXFIFO0 => MovSrcInternal::Fifo(MovRxIndex::RXFIFO0),
#[cfg(feature = "rp2350")]
ParsedMovSource::RXFIFO1 => MovSrcInternal::Fifo(MovRxIndex::RXFIFO1),
#[cfg(feature = "rp2350")]
ParsedMovSource::RXFIFO2 => MovSrcInternal::Fifo(MovRxIndex::RXFIFO2),
#[cfg(feature = "rp2350")]
ParsedMovSource::RXFIFO3 => MovSrcInternal::Fifo(MovRxIndex::RXFIFO3),
}
}
Expand Down Expand Up @@ -237,7 +208,7 @@ pub(crate) enum ParsedOperands<'input> {
clear: bool,
wait: bool,
index: Value<'input>,
relative: bool,
index_mode: IrqIndexMode,
},
SET {
destination: SetDestination,
Expand Down Expand Up @@ -290,11 +261,9 @@ impl<'i> ParsedOperands<'i> {
let source_internal = (*source).into();
let dest_internal = (*destination).into();
match (source_internal, dest_internal) {
#[cfg(feature = "rp2350")]
(MovSrcInternal::Mov(MovSource::ISR), MovDestInternal::Fifo(index)) => {
InstructionOperands::MOVTORX { index }
}
#[cfg(feature = "rp2350")]
(MovSrcInternal::Fifo(index), MovDestInternal::Mov(MovDestination::OSR)) => {
InstructionOperands::MOVFROMRX { index }
}
Expand All @@ -303,20 +272,19 @@ impl<'i> ParsedOperands<'i> {
op: *op,
source: s,
},
#[cfg(feature = "rp2350")]
(d, s) => panic!("Illegal Mov src/dest combination: {:?} {:?}", d, s),
}
}
ParsedOperands::IRQ {
clear,
wait,
index,
relative,
index_mode,
} => InstructionOperands::IRQ {
clear: *clear,
wait: *wait,
index: index.reify(state) as u8,
relative: *relative,
index_mode: *index_mode,
},
ParsedOperands::SET { destination, data } => InstructionOperands::SET {
destination: *destination,
Expand Down Expand Up @@ -557,7 +525,6 @@ fn test() {
}

#[test]
#[cfg(feature = "rp2350")]
fn test_rp2350() {
let p = Parser::<32>::parse_program(
"
Expand Down
14 changes: 12 additions & 2 deletions pio-parser/src/rp2350.lalrpop → pio-parser/src/pio.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use ::pio::{
MovOperation,
MovSource,
SetDestination,
IrqIndexMode,
};
use crate::{
Line,
Expand Down Expand Up @@ -188,7 +189,7 @@ BaseInstruction: ParsedOperands<'input> = {
},
source: s,
},
"irq" <m:IrqModifier?> <v:Value> <r:"rel"?> => ParsedOperands::IRQ {
"irq" <m:IrqModifier?> <v:Value> <r:IrqIndexMode?> => ParsedOperands::IRQ {
clear: match m {
Some(m) => m.0,
None => false,
Expand All @@ -198,7 +199,10 @@ BaseInstruction: ParsedOperands<'input> = {
None => false,
},
index: v,
relative: r.is_some(),
index_mode: match r {
Some(m) => m,
None => IrqIndexMode::DIRECT
}
},
"set" <d:SetDestination> ","? <v:Value> => ParsedOperands::SET {
destination: d,
Expand Down Expand Up @@ -291,6 +295,12 @@ IrqModifier: (bool, bool) = {
"clear" => (true, false),
};

IrqIndexMode: IrqIndexMode = {
"prev" => IrqIndexMode::PREV,
"rel" => IrqIndexMode::REL,
"next" => IrqIndexMode::NEXT,
}

SetDestination: SetDestination = {
"pins" => SetDestination::PINS,
"x" => SetDestination::X,
Expand Down
Loading

0 comments on commit 3d81f47

Please sign in to comment.