Skip to content

Commit

Permalink
Put under feature-gate
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Nov 10, 2022
1 parent 130d3eb commit 6e945a1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion boa_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository.workspace = true
rust-version.workspace = true

[dependencies]
boa_engine = { workspace = true, features = ["deser", "console"] }
boa_engine = { workspace = true, features = ["deser", "console", "flowgraph"] }
boa_ast = { workspace = true, features = ["serde"]}
boa_interner.workspace = true
boa_parser.workspace = true
Expand Down
22 changes: 16 additions & 6 deletions boa_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@

use boa_ast::StatementList;
use boa_engine::{
vm::{
graph::{Direction, Graph},
},
vm::graph::{Direction, Graph},
Context, JsResult,
};
use clap::{Parser, ValueEnum, ValueHint};
Expand Down Expand Up @@ -201,7 +199,11 @@ where
Ok(())
}

fn generate_flowgraph(context: &mut Context, src: &[u8], flowgraph: FlowgraphFormat) -> JsResult<String> {
fn generate_flowgraph(
context: &mut Context,
src: &[u8],
flowgraph: FlowgraphFormat,
) -> JsResult<String> {
let ast = context.parse(src)?;
let code = context.compile(&ast)?;

Expand Down Expand Up @@ -230,7 +232,11 @@ pub fn main() -> Result<(), io::Error> {
eprintln!("{e}");
}
} else if let Some(flowgraph) = args.flowgraph {
match generate_flowgraph(&mut context, &buffer, flowgraph.unwrap_or(FlowgraphFormat::Graphviz)) {
match generate_flowgraph(
&mut context,
&buffer,
flowgraph.unwrap_or(FlowgraphFormat::Graphviz),
) {
Ok(v) => println!("{}", v),
Err(v) => eprintln!("Uncaught {v}"),
}
Expand Down Expand Up @@ -281,7 +287,11 @@ pub fn main() -> Result<(), io::Error> {
eprintln!("{e}");
}
} else if let Some(flowgraph) = args.flowgraph {
match generate_flowgraph(&mut context, line.trim_end().as_bytes(), flowgraph.unwrap_or(FlowgraphFormat::Graphviz)) {
match generate_flowgraph(
&mut context,
line.trim_end().as_bytes(),
flowgraph.unwrap_or(FlowgraphFormat::Graphviz),
) {
Ok(v) => println!("{}", v),
Err(v) => eprintln!("Uncaught {v}"),
}
Expand Down
2 changes: 2 additions & 0 deletions boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ intl = [

fuzz = ["boa_ast/fuzz", "boa_interner/fuzz"]

flowgraph = []

# Enable Boa's WHATWG console object implementation.
console = []

Expand Down
1 change: 1 addition & 0 deletions boa_engine/src/vm/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ impl CodeBlock {
| Opcode::NewSpread
| Opcode::SuperCallSpread
| Opcode::ForAwaitOfLoopIterate
| Opcode::SetPrototype
| Opcode::Nop => {
graph.add_node(previous_pc, NodeShape::None, opcode_str.into(), Color::None);
graph.add_edge(previous_pc, pc, None, Color::None, EdgeStyle::Line);
Expand Down
4 changes: 3 additions & 1 deletion boa_engine/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ use std::{convert::TryInto, mem::size_of, time::Instant};

mod call_frame;
mod code_block;
pub mod graph;
mod opcode;

#[cfg(feature = "flowgraph")]
pub mod graph;

pub use {call_frame::CallFrame, code_block::CodeBlock, opcode::Opcode};

pub(crate) use {
Expand Down

0 comments on commit 6e945a1

Please sign in to comment.