-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start FFI and custom calyx testbench
- Loading branch information
1 parent
0e880c7
commit 24b190a
Showing
22 changed files
with
729 additions
and
48 deletions.
There are no files selected for viewing
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,25 @@ | ||
[package] | ||
name = "calyx-ffi-macro" | ||
authors.workspace = true | ||
license-file.workspace = true | ||
keywords.workspace = true | ||
repository.workspace = true | ||
readme.workspace = true | ||
description.workspace = true | ||
categories.workspace = true | ||
homepage.workspace = true | ||
edition.workspace = true | ||
version.workspace = true | ||
rust-version.workspace = true | ||
|
||
[lib] | ||
proc-macro = true | ||
|
||
[dependencies] | ||
proc-macro2 = "1.0.86" | ||
quote = "1.0.36" | ||
syn = { version = "2.0.69", features = ["full", "visit"] } | ||
calyx-utils.workspace = true | ||
calyx-frontend.workspace = true | ||
calyx-ir.workspace = true | ||
# bigint = "4.4.3" |
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,50 @@ | ||
use std::{env, path::PathBuf, rc::Rc}; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
use crate::{parse::CalyxFFIMacroArgs, util}; | ||
|
||
pub struct CalyxComponent { | ||
ctx: Rc<calyx_ir::Context>, | ||
index: usize, | ||
} | ||
|
||
impl CalyxComponent { | ||
pub fn get(&self) -> &calyx_ir::Component { | ||
&self.ctx.components[self.index] | ||
} | ||
} | ||
|
||
pub fn parse_calyx_file( | ||
args: CalyxFFIMacroArgs, | ||
) -> Result<CalyxComponent, TokenStream> { | ||
// there has to be a better way to find lib | ||
let home_dir = env::var("HOME").expect("user home not set"); | ||
let mut lib_path = PathBuf::from(home_dir); | ||
lib_path.push(".calyx"); | ||
let ws = calyx_frontend::Workspace::construct( | ||
&Some(args.src.clone()), | ||
&lib_path, | ||
) | ||
.map_err(|err| util::compile_error(&args.src_attr_span, err.message()))?; | ||
let ctx = calyx_ir::from_ast::ast_to_ir(ws).map_err(|err| { | ||
util::compile_error(&args.src_attr_span, err.message()) | ||
})?; | ||
|
||
let comp_index = ctx | ||
.components | ||
.iter() | ||
.position(|comp| comp.name == args.comp) | ||
.ok_or(util::compile_error( | ||
&args.comp_attr_span, | ||
format!( | ||
"component '{}' does not exist in '{}'", | ||
args.comp, | ||
args.src.to_string_lossy() | ||
), | ||
))?; | ||
Ok(CalyxComponent { | ||
ctx: Rc::new(ctx), | ||
index: comp_index, | ||
}) | ||
} |
Oops, something went wrong.