-
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
1 parent
beb28f3
commit 45765e9
Showing
23 changed files
with
827 additions
and
477 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
target/ | ||
test_crate/artifacts/ | ||
test_crates/test_crate/artifacts/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 @@ | ||
[package] | ||
name = "spade-macro" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
description.workspace = true | ||
readme.workspace = true | ||
license.workspace = true | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
verilog-macro-builder = { path = "../../verilog/verilog-macro-builder/" } | ||
proc-macro2 = "1.0.93" | ||
syn.workspace = true | ||
quote = "1.0.38" | ||
toml = "0.8.19" | ||
camino.workspace = true |
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,57 @@ | ||
use std::env; | ||
|
||
use camino::Utf8PathBuf; | ||
use proc_macro::TokenStream; | ||
use verilog_macro_builder::{build_verilated_struct, MacroArgs}; | ||
|
||
fn search_for_swim_toml(mut start: Utf8PathBuf) -> Option<Utf8PathBuf> { | ||
while !start.as_str().is_empty() { | ||
if start.join("swim.toml").is_file() { | ||
return Some(start.join("swim.toml")); | ||
} | ||
start.pop(); | ||
} | ||
None | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn spade(args: TokenStream, item: TokenStream) -> TokenStream { | ||
let args = syn::parse_macro_input!(args as MacroArgs); | ||
|
||
let manifest_directory = Utf8PathBuf::from( | ||
env::var("CARGO_MANIFEST_DIR").expect("Please use CARGO"), | ||
); | ||
let Some(swim_toml) = search_for_swim_toml(manifest_directory) else { | ||
return syn::Error::new_spanned( | ||
args.source_path, | ||
"Could not find swim.toml", | ||
) | ||
.into_compile_error() | ||
.into(); | ||
}; | ||
|
||
let verilog_args = MacroArgs { | ||
source_path: { | ||
let mut source_path = swim_toml.clone(); | ||
source_path.pop(); | ||
source_path.push("build/spade.sv"); | ||
|
||
// TODO: parse spade file directory and remove this | ||
if !source_path.is_file() { | ||
return syn::Error::new_spanned( | ||
args.source_path, | ||
"Please run swim build or similar", | ||
) | ||
.into_compile_error() | ||
.into(); | ||
} | ||
|
||
syn::LitStr::new(source_path.as_str(), args.source_path.span()) | ||
}, | ||
name: args.name, | ||
clock_port: args.clock_port, | ||
reset_port: args.reset_port, | ||
}; | ||
|
||
build_verilated_struct(verilog_args, item.into(), "spade").into() | ||
} |
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,15 @@ | ||
[package] | ||
name = "spade" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
description.workspace = true | ||
readme.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
verilog = { path = "../../verilog/verilog/" } | ||
spade-macro = { path = "../spade-macro/" } | ||
camino.workspace = true | ||
snafu.workspace = true |
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,52 @@ | ||
pub use spade_macro::spade; | ||
pub use verilog::__reexports; | ||
|
||
use std::env::current_dir; | ||
|
||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use snafu::{whatever, ResultExt, Whatever}; | ||
use verilog::{VerilatorRuntime, __reexports::verilator::VerilatedModel}; | ||
|
||
fn search_for_swim_toml(mut start: Utf8PathBuf) -> Option<Utf8PathBuf> { | ||
while !start.as_str().is_empty() { | ||
if start.join("swim.toml").is_file() { | ||
return Some(start.join("swim.toml")); | ||
} | ||
start.pop(); | ||
} | ||
None | ||
} | ||
|
||
pub struct SpadeRuntime { | ||
verilator_runtime: VerilatorRuntime, | ||
} | ||
|
||
impl SpadeRuntime { | ||
pub fn new(artifact_directory: &Utf8Path) -> Result<Self, Whatever> { | ||
let Some(swim_toml_path) = search_for_swim_toml( | ||
current_dir() | ||
.whatever_context("Failed to get current directory")? | ||
.try_into() | ||
.whatever_context( | ||
"Failed to convert current directory to UTF-8", | ||
)?, | ||
) else { | ||
whatever!("Failed to find swim.toml"); | ||
}; | ||
|
||
let mut spade_sv_path = swim_toml_path; | ||
spade_sv_path.pop(); | ||
spade_sv_path.push("build/spade.sv"); | ||
|
||
Ok(Self { | ||
verilator_runtime: VerilatorRuntime::new( | ||
artifact_directory, | ||
&[&spade_sv_path], | ||
)?, | ||
}) | ||
} | ||
|
||
pub fn create_model<M: VerilatedModel>(&mut self) -> Result<M, Whatever> { | ||
self.verilator_runtime.create_model() | ||
} | ||
} |
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
File renamed without changes.
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 @@ | ||
build/ |
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,4 @@ | ||
#[no_mangle] | ||
entity main(#[no_mangle] out: inv &int<8>) { | ||
set out = 42; | ||
} |
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,2 @@ | ||
[spade] | ||
commit = "86ebf2f41fd79aaab13c486c697136777d812803" |
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 @@ | ||
name = "test_swim" |
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 @@ | ||
artifacts/ |
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,13 @@ | ||
[package] | ||
name = "test_swim_crate" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
description.workspace = true | ||
readme.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
snafu.workspace = true | ||
spade = { path = "../../../spade/spade/" } |
Oops, something went wrong.