Skip to content

Commit

Permalink
chore: remove miden-diagnostics, start making midenc-session no-std-c…
Browse files Browse the repository at this point in the history
…ompatible
  • Loading branch information
bitwalker committed Aug 19, 2024
1 parent 6536250 commit c21bf07
Show file tree
Hide file tree
Showing 27 changed files with 1,116 additions and 303 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ publish = false
anyhow = "1.0"
bitflags = "2.4"
bitcode = { version = "0.6.3", default-features = false, features = ["serde"] }
clap = { version = "4.1", features = ["derive", "env"] }
clap = { version = "4.1", default-features = false, features = [
"derive",
"std",
"env",
] }
cranelift-entity = "0.108"
cranelift-bforest = "0.108"
env_logger = "0.11"
Expand Down Expand Up @@ -86,7 +90,6 @@ miden-stdlib = { version = "0.10.3" }
#miden-processor = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" }
#miden-stdlib = { git = "https://github.com/0xPolygonMiden/miden-vm", rev = "828557c28ca1d159bfe42195e7ea73256ce4aa06" }
midenc-codegen-masm = { path = "codegen/masm" }
miden-diagnostics = "0.1"
midenc-hir = { version = "0.0.1", path = "hir" }
midenc-hir-analysis = { version = "0.0.1", path = "hir-analysis" }
midenc-hir-macros = { version = "0.0.1", path = "hir-macros" }
Expand Down
7 changes: 2 additions & 5 deletions frontend-wasm/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::sync::Arc;

use midenc_hir::{
diagnostics::{ColorChoice, NullEmitter},
testing::TestContext,
};
use midenc_session::Options;
use midenc_hir::{diagnostics::NullEmitter, testing::TestContext};
use midenc_session::{ColorChoice, Options};

pub fn test_context() -> TestContext {
let options = Options::default().with_verbosity(midenc_session::Verbosity::Debug);
Expand Down
1 change: 0 additions & 1 deletion hir-transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ edition.workspace = true
[dependencies]
anyhow.workspace = true
inventory.workspace = true
miden-diagnostics.workspace = true
midenc-hir.workspace = true
midenc-hir-analysis.workspace = true
midenc-session.workspace = true
Expand Down
10 changes: 5 additions & 5 deletions hir/src/parser/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use midenc_session::{Options, Verbosity, Warnings};
use pretty_assertions::assert_eq;

use crate::{
diagnostics::{self, CaptureEmitter, DefaultEmitter, Emitter, EmitterBuffer, Report},
diagnostics::{self, Buffer, CaptureEmitter, DefaultEmitter, Emitter, IntoDiagnostic, Report},
parser::{ast::Module, Parser},
testing::TestContext,
};
Expand All @@ -16,7 +16,7 @@ struct SplitEmitter {
impl SplitEmitter {
#[inline]
pub fn new() -> Self {
use diagnostics::ColorChoice;
use midenc_session::ColorChoice;

Self {
capture: Default::default(),
Expand All @@ -31,16 +31,16 @@ impl SplitEmitter {
}
impl Emitter for SplitEmitter {
#[inline]
fn buffer(&self) -> EmitterBuffer {
fn buffer(&self) -> Buffer {
self.capture.buffer()
}

#[inline]
fn print(&self, buffer: EmitterBuffer) -> std::io::Result<()> {
fn print(&self, buffer: Buffer) -> Result<(), Report> {
use std::io::Write;

let mut copy = self.capture.buffer();
copy.write_all(buffer.as_slice())?;
copy.write_all(buffer.as_slice()).into_diagnostic()?;
self.capture.print(buffer)?;
self.default.print(copy)
}
Expand Down
1 change: 0 additions & 1 deletion midenc-compile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ intrusive-collections.workspace = true
inventory.workspace = true
midenc-codegen-masm.workspace = true
miden-assembly = { workspace = true, features = ["std"] }
miden-diagnostics.workspace = true
midenc-frontend-wasm.workspace = true
midenc-hir.workspace = true
midenc-hir-analysis.workspace = true
Expand Down
19 changes: 6 additions & 13 deletions midenc-compile/src/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{ffi::OsString, path::PathBuf, sync::Arc};

use clap::{builder::ArgPredicate, ColorChoice, Parser};
use clap::{builder::ArgPredicate, Parser};
use midenc_session::{
diagnostics::{ColorChoice as MDColorChoice, DefaultSourceManager, Emitter},
DebugInfo, InputFile, LinkLibrary, OptLevel, Options, OutputFile, OutputType, OutputTypeSpec,
OutputTypes, ProjectType, Session, TargetEnv, Verbosity, Warnings,
diagnostics::{DefaultSourceManager, Emitter},
ColorChoice, DebugInfo, InputFile, LinkLibrary, OptLevel, Options, OutputFile, OutputType,
OutputTypeSpec, OutputTypes, ProjectType, Session, TargetEnv, Verbosity, Warnings,
};

/// Compile a program from WebAssembly or Miden IR, to Miden Assembly.
Expand Down Expand Up @@ -409,7 +409,7 @@ impl Compiler {
.unwrap_or_else(|err| err.exit());

let inputs = inputs.into_iter().collect();
opts.into_session(inputs, emitter).with_arg_matches(compile_matches)
opts.into_session(inputs, emitter).with_extra_flags(compile_matches.into())
}

/// Use this configuration to obtain a [Session] used for compilation
Expand All @@ -422,13 +422,6 @@ impl Compiler {
.working_dir
.unwrap_or_else(|| std::env::current_dir().expect("no working directory available"));

// Map clap color choices to internal color choice
let color = match self.color {
ColorChoice::Auto => MDColorChoice::Auto,
ColorChoice::Always => MDColorChoice::Always,
ColorChoice::Never => MDColorChoice::Never,
};

// Determine if a specific output file has been requested
let output_file = match self.output_file {
Some(path) => Some(OutputFile::Real(path)),
Expand All @@ -454,7 +447,7 @@ impl Compiler {

// Consolidate all compiler options
let mut options = Options::new(self.name, self.target, project_type, cwd, self.sysroot)
.with_color(color)
.with_color(self.color)
.with_verbosity(self.verbosity)
.with_warnings(self.warn)
.with_debug_info(self.debug)
Expand Down
8 changes: 3 additions & 5 deletions midenc-compile/src/stages/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,19 @@ impl Stage for ParseStage {
input,
session,
&WasmTranslationConfig {
source_name: name.as_str().unwrap().to_string().into(),
source_name: name.as_str().to_string().into(),
..Default::default()
},
),
FileType::Wat => self.parse_hir_from_wat_bytes(
input,
session,
&WasmTranslationConfig {
source_name: name.as_str().unwrap().to_string().into(),
source_name: name.as_str().to_string().into(),
..Default::default()
},
),
FileType::Masm => {
self.parse_masm_from_bytes(name.as_str().unwrap(), input, session)
}
FileType::Masm => self.parse_masm_from_bytes(name.as_str(), input, session),
FileType::Mast => Err(Report::msg(
"invalid input: mast libraries are not supported as inputs, did you mean to \
use '-l'?",
Expand Down
4 changes: 2 additions & 2 deletions midenc-debug/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{ffi::OsString, path::PathBuf, sync::Arc};

use clap::{ColorChoice, Parser};
use midenc_session::{
diagnostics::{ColorChoice as MDColorChoice, DefaultSourceManager, Emitter},
InputFile, LinkLibrary, Options, ProjectType, Session, TargetEnv,
diagnostics::{DefaultSourceManager, Emitter},
ColorChoice as MDColorChoice, InputFile, LinkLibrary, Options, ProjectType, Session, TargetEnv,
};

/// Run a compiled Miden program with the Miden VM
Expand Down
13 changes: 2 additions & 11 deletions midenc-debug/src/ui/panes/source_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,9 @@ impl SourceCodePane {
fn enable_syntax_highlighting(&mut self, state: &State) {
use std::io::IsTerminal;

use midenc_session::diagnostics::ColorChoice;

let nocolor = match state.session.options.color {
ColorChoice::Always | ColorChoice::AlwaysAnsi => false,
ColorChoice::Never => true,
ColorChoice::Auto => match std::env::var("NO_COLOR") {
_ if !std::io::stdout().is_terminal() => true,
Ok(value) => !matches!(value.as_str(), "0" | "false"),
_ => false,
},
};
use midenc_session::ColorChoice;

let nocolor = !state.session.options.color.should_attempt_color();
if nocolor {
return;
}
Expand Down
9 changes: 8 additions & 1 deletion midenc-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ license.workspace = true
readme.workspace = true
edition.workspace = true

[features]
default = ["all"]
all = ["std", "debug"]
debug = ["dep:midenc-debug"]
std = ["alloc", "log/std", "clap/std", "clap/color", "clap/env"]
alloc = ["clap/help", "clap/usage", "clap/error-context", "clap/suggestions"]

[dependencies]
clap.workspace = true
log.workspace = true
midenc-hir.workspace = true
midenc-session.workspace = true
midenc-compile.workspace = true
midenc-debug.workspace = true
midenc-debug = { workspace = true, optional = true }
thiserror.workspace = true
6 changes: 5 additions & 1 deletion midenc-driver/src/midenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{ffi::OsString, path::PathBuf, rc::Rc, sync::Arc};
use clap::{ColorChoice, Parser, Subcommand};
use log::Log;
use midenc_compile as compile;
#[cfg(feature = "debug")]
use midenc_debug as debugger;
use midenc_hir::FunctionIdent;
use midenc_session::{
Expand Down Expand Up @@ -96,6 +97,7 @@ enum Commands {
/// Run a program under the interactive Miden VM debugger
///
/// This command starts a TUI-based interactive debugger with the given program loaded.
#[cfg(feature = "debug")]
Debug {
/// Specify the path to a Miden program file to execute.
///
Expand Down Expand Up @@ -180,9 +182,11 @@ impl Midenc {
if options.working_dir.is_none() {
options.working_dir = Some(cwd);
}
let session = options.into_session(vec![input], emitter).with_arg_matches(matches);
let session =
options.into_session(vec![input], emitter).with_extra_flags(matches.into());
compile::compile(Rc::new(session))
}
#[cfg(feature = "debug")]
Commands::Debug {
input,
inputs,
Expand Down
9 changes: 5 additions & 4 deletions midenc-session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ readme.workspace = true
edition.workspace = true

[features]
default = []
default = ["std"]
std = ["dep:termcolor", "dep:parking_lot", "dep:clap"]
serde = ["dep:serde", "dep:serde_repr", "midenc-hir-symbol/serde"]

[dependencies]
atty = "0.2"
clap.workspace = true
clap = { workspace = true, optional = true }
inventory.workspace = true
log.workspace = true
miden-assembly.workspace = true
miden-core.workspace = true
miden-stdlib.workspace = true
miden-diagnostics.workspace = true
midenc-hir-symbol.workspace = true
midenc-hir-macros.workspace = true
miden-base-sys = { version = "0.0.0", path = "../sdk/base-sys", features = [
"masl-lib",
] }
parking_lot = { workspace = true, optional = true }
termcolor = { version = "1.4.1", optional = true }
thiserror.workspace = true
serde = { workspace = true, optional = true }
serde_repr = { workspace = true, optional = true }
Loading

0 comments on commit c21bf07

Please sign in to comment.