Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[[bin]]
name = "descendc"
path = "src/main.rs"

[dependencies.peg]
version = "0.8.0"

Expand All @@ -16,5 +20,24 @@ features = ["color"]
[dependencies.descend_derive]
path = "./descend_derive"

[dependencies.clap]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give a brief overview over what these dependencies are used for, so that we can gauge how important they are?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • clap: Declarative API for defining and parsing the command-line arguments.
  • which: Used to check for the presence of system executables (nvcc, clang-format).
  • predicates: Facilitates expressive assertions in the cli_test.rs (verifying output contains expected text).
  • assert_cmd: Assists in testing command-line applications and enables CLI integration tests (as used in cli_test.rs).
  • log and env_logger: Provides a consistent logging API and allows for configurable logging output. I used it to switch between general information and debug-level output in the CLI. Simple println-style outputs would work as well.
  • anyhow: Simplifies error handling by performing type erasure for errors. It wraps concrete error types in a trait object, allowing you to propagate errors without having to specify their types explicitly. I used it as a neat way to provide error messages, but it may won't be applicable when we merge PR #31 and does not align with the use of custom error types. I will remove this dependency and change the error handling.

version = "4.3"
features = ["derive"]

[dependencies.which]
version = "7.0.2"

[dependencies.log]
version = "0.4.27"

[dependencies.env_logger]
version = "0.11.7"

[dependencies.predicates]
version= "3.1.3"

[dependencies.assert_cmd]
version = "2.0.16"

[workspace]
members = ["descend_derive"]
members = ["descend_derive"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ codegen

cuda-examples/
---------------------
* Contains handwritte or generated CUDA programs
* Contains handwritten or generated CUDA programs
* Contains `descend.cuh`; the header file which is required in order to compile Descend programs,
that were translated to CUDA, with `nvcc` (contains for example the implementation of `exec`)

Expand Down
88 changes: 88 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,91 @@ impl std::fmt::Debug for ErrorReported {
write!(f, "Aborting due to previous error.")
}
}

impl std::fmt::Display for ErrorReported {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Aborting due to a previous error.")
}
}

#[derive(Debug)]
pub struct NVCCError {
message: String,
}

impl NVCCError {
pub fn new<S: Into<String>>(message: S) -> Self {
NVCCError {
message: message.into(),
}
}

pub fn emit(&self) -> ErrorReported {
println!("{}", self.to_string());
ErrorReported
}

fn to_string(&self) -> String {
let label = format!("{}", self.message);
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some(&label),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![],
opt: default_format(),
};
DisplayList::from(snippet).to_string()
}
}

impl std::fmt::Display for NVCCError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "NVCC Error: {}", self.message)
}
}

impl std::error::Error for NVCCError {}

#[derive(Debug)]
pub struct ExecutableError {
message: String,
}

impl ExecutableError {
pub fn new<S: Into<String>>(message: S) -> Self {
ExecutableError {
message: message.into(),
}
}

pub fn emit(&self) -> ErrorReported {
println!("{}", self.to_string());
ErrorReported
}

fn to_string(&self) -> String {
let label = format!("{}", self.message);
let snippet = Snippet {
title: Some(Annotation {
id: None,
label: Some(&label),
annotation_type: AnnotationType::Error,
}),
footer: vec![],
slices: vec![],
opt: default_format(),
};
DisplayList::from(snippet).to_string()
}
}

impl std::fmt::Display for ExecutableError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Executable Error: {}", self.message)
}
}

impl std::error::Error for ExecutableError {}
Loading