Skip to content

Commit

Permalink
Move report vars under lang_features folder (#175)
Browse files Browse the repository at this point in the history
* Move report vars under lang_features folder

* fmt
  • Loading branch information
ejrgilbert authored Nov 11, 2024
1 parent 462e14f commit 247ab78
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 123 deletions.
20 changes: 10 additions & 10 deletions src/common/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use crate::cli::LibraryLinkStrategyArg;
use crate::common::error::ErrorGen;
use crate::emitter::module_emitter::{MemoryTracker, ModuleEmitter};
use crate::emitter::report_var_metadata::ReportVarMetadata;
use crate::emitter::rewriting::visiting_emitter::VisitingEmitter;
use crate::emitter::InjectStrategy;
use crate::generator::rewriting::init_generator::InitGenerator;
Expand All @@ -15,6 +14,7 @@ use crate::lang_features::libraries::core::io::IOPackage;
use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter;
use crate::lang_features::libraries::core::maps::MapLibPackage;
use crate::lang_features::libraries::core::LibPackage;
use crate::lang_features::report_vars::ReportVars;
use crate::parser::types::{Whamm, WhammVisitor};
use crate::parser::whamm_parser::parse_script;
use crate::verifier::types::SymbolTable;
Expand Down Expand Up @@ -177,7 +177,7 @@ pub fn run(
);
let mut map_lib_adapter = map_package.adapter;
let mut io_adapter = io_package.adapter;
let mut report_var_metadata = ReportVarMetadata::new();
let mut report_vars = ReportVars::new();
let mut unshared_var_handler = UnsharedVarHandler::default();

// If there were any errors encountered, report and exit!
Expand All @@ -191,7 +191,7 @@ pub fn run(
&mut symbol_table,
&mut io_adapter,
&mut map_lib_adapter,
&mut report_var_metadata,
&mut report_vars,
&mut unshared_var_handler,
&mut err,
&config,
Expand All @@ -205,13 +205,13 @@ pub fn run(
&mut symbol_table,
&mut io_adapter,
&mut map_lib_adapter,
&mut report_var_metadata,
&mut report_vars,
&mut unshared_var_handler,
&mut err,
);
}
// for debugging
report_var_metadata.print_metadata();
report_vars.print_metadata();

if let Some(output_wasm_path) = output_wasm_path {
try_path(&output_wasm_path);
Expand Down Expand Up @@ -240,7 +240,7 @@ fn run_instr_wizard(
symbol_table: &mut SymbolTable,
io_adapter: &mut IOAdapter,
map_lib_adapter: &mut MapLibAdapter,
report_var_metadata: &mut ReportVarMetadata,
report_vars: &mut ReportVars,
unshared_var_handler: &mut UnsharedVarHandler,
err: &mut ErrorGen,
config: &Config,
Expand All @@ -263,7 +263,7 @@ fn run_instr_wizard(
symbol_table,
&mut mem_tracker,
map_lib_adapter,
report_var_metadata,
report_vars,
unshared_var_handler,
),
io_adapter,
Expand All @@ -283,7 +283,7 @@ fn run_instr_rewrite(
symbol_table: &mut SymbolTable,
io_adapter: &mut IOAdapter,
map_lib_adapter: &mut MapLibAdapter,
report_var_metadata: &mut ReportVarMetadata,
report_vars: &mut ReportVars,
unshared_var_handler: &mut UnsharedVarHandler,
err: &mut ErrorGen,
) {
Expand All @@ -298,7 +298,7 @@ fn run_instr_rewrite(
symbol_table,
&mut mem_tracker,
map_lib_adapter,
report_var_metadata,
report_vars,
unshared_var_handler,
),
context_name: "".to_string(),
Expand All @@ -321,7 +321,7 @@ fn run_instr_rewrite(
&mut mem_tracker,
map_lib_adapter,
io_adapter,
report_var_metadata,
report_vars,
unshared_var_handler,
),
simple_ast,
Expand Down
13 changes: 5 additions & 8 deletions src/emitter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
pub mod module_emitter;
pub mod report_var_metadata;
pub mod rewriting;
#[cfg(test)]
pub mod tests;
pub mod utils;

use crate::common::error::ErrorGen;
use crate::emitter::report_var_metadata::{Metadata, ReportVarMetadata};
use crate::emitter::rewriting::rules::Arg;
use crate::lang_features::libraries::core::io::io_adapter::IOAdapter;
use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter;
use crate::lang_features::report_vars::{Metadata, ReportVars};
use crate::parser::types::{Block, Expr, Statement};
use crate::verifier::types::{Record, SymbolTable};
use orca_wasm::ir::id::{FunctionID, GlobalID};
Expand Down Expand Up @@ -41,25 +40,23 @@ pub trait Emitter {
pub fn configure_flush_routines(
wasm: &mut Module,
table: &mut SymbolTable,
report_var_metadata: &mut ReportVarMetadata,
report_vars: &mut ReportVars,
map_lib_adapter: &mut MapLibAdapter,
io_adapter: &mut IOAdapter,
err_msg: &str,
err: &mut ErrorGen,
) {
if report_var_metadata.variable_metadata.is_empty()
&& report_var_metadata.map_metadata.is_empty()
{
if report_vars.variable_metadata.is_empty() && report_vars.map_metadata.is_empty() {
return;
}

//convert the metadata into strings, add those to the data section, then use those to populate the maps
let var_meta: HashMap<u32, String> = report_var_metadata
let var_meta: HashMap<u32, String> = report_vars
.variable_metadata
.iter()
.map(|(key, value)| (*key, value.to_csv()))
.collect();
let map_meta: HashMap<u32, String> = report_var_metadata
let map_meta: HashMap<u32, String> = report_vars
.map_metadata
.iter()
.map(|(key, value)| (*key, value.to_csv()))
Expand Down
20 changes: 10 additions & 10 deletions src/emitter/module_emitter.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::common::error::{ErrorGen, WhammError};
use crate::emitter::report_var_metadata::ReportVarMetadata;
use crate::emitter::rewriting::rules::Arg;
use crate::emitter::utils::{emit_body, emit_expr, emit_stmt, whamm_type_to_wasm_global};
use crate::emitter::{configure_flush_routines, Emitter, InjectStrategy};
use crate::lang_features::alloc_vars::rewriting::UnsharedVarHandler;
use crate::lang_features::libraries::core::io::io_adapter::IOAdapter;
use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter;
use crate::lang_features::report_vars::ReportVars;
use crate::parser::types::{Block, DataType, Definition, Expr, Fn, FnId, Statement, Value};
use crate::verifier::types::{Record, SymbolTable, VarAddr};
use log::debug;
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
pub table: &'c mut SymbolTable,
mem_tracker: &'d mut MemoryTracker,
pub map_lib_adapter: &'e mut MapLibAdapter,
pub report_var_metadata: &'f mut ReportVarMetadata,
pub report_vars: &'f mut ReportVars,
pub unshared_var_handler: &'g mut UnsharedVarHandler,
fn_providing_contexts: Vec<String>,
}
Expand All @@ -54,7 +54,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
table: &'c mut SymbolTable,
mem_tracker: &'d mut MemoryTracker,
map_lib_adapter: &'e mut MapLibAdapter,
report_var_metadata: &'f mut ReportVarMetadata,
report_vars: &'f mut ReportVars,
unshared_var_handler: &'g mut UnsharedVarHandler,
) -> Self {
Self {
Expand All @@ -63,7 +63,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
emitting_func: None,
mem_tracker,
map_lib_adapter,
report_var_metadata,
report_vars,
unshared_var_handler,
table,
fn_providing_contexts: vec!["whamm".to_string()],
Expand Down Expand Up @@ -496,7 +496,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
name,
ty.clone(),
&mut init_fn,
self.report_var_metadata,
self.report_vars,
false,
err,
)
Expand All @@ -513,7 +513,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
*addr = Some(VarAddr::Global { addr: *global_id });
//now save off the global variable metadata
if report_mode {
self.report_var_metadata
self.report_vars
.put_global_metadata(*global_id, name.clone(), err);
}
Some(self.emit_global_getter(&global_id, name, global_ty))
Expand Down Expand Up @@ -663,7 +663,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> ModuleEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
configure_flush_routines(
self.app_wasm,
self.table,
self.report_var_metadata,
self.report_vars,
self.map_lib_adapter,
io_adapter,
UNEXPECTED_ERR_MSG,
Expand All @@ -686,7 +686,7 @@ impl Emitter for ModuleEmitter<'_, '_, '_, '_, '_, '_, '_> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand All @@ -710,7 +710,7 @@ impl Emitter for ModuleEmitter<'_, '_, '_, '_, '_, '_, '_> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand All @@ -729,7 +729,7 @@ impl Emitter for ModuleEmitter<'_, '_, '_, '_, '_, '_, '_> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand Down
18 changes: 9 additions & 9 deletions src/emitter/rewriting/visiting_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use crate::emitter::rewriting::rules::{Arg, LocInfo, ProbeRule, Provider, WhammP
use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter;
use std::collections::HashMap;

use crate::emitter::report_var_metadata::ReportVarMetadata;
use crate::emitter::utils::{
block_type_to_wasm, emit_expr, emit_stmt, print_report_all, whamm_type_to_wasm_global,
};
use crate::emitter::{configure_flush_routines, Emitter, InjectStrategy};
use crate::generator::folding::ExprFolder;
use crate::lang_features::alloc_vars::rewriting::UnsharedVarHandler;
use crate::lang_features::libraries::core::io::io_adapter::IOAdapter;
use crate::lang_features::report_vars::ReportVars;
use crate::parser;
use crate::parser::rules::UNKNOWN_IMMS;
use crate::parser::types::{Block, DataType, Definition, Expr, RulePart, Statement, Value};
Expand All @@ -36,7 +36,7 @@ pub struct VisitingEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
pub mem_tracker: &'d mut MemoryTracker,
pub map_lib_adapter: &'e mut MapLibAdapter,
pub io_adapter: &'f mut IOAdapter,
pub(crate) report_var_metadata: &'g mut ReportVarMetadata,
pub(crate) report_vars: &'g mut ReportVars,
pub(crate) unshared_var_handler: &'g mut UnsharedVarHandler,
instr_created_args: Vec<(String, usize)>,
pub curr_num_unshared: i32,
Expand All @@ -52,7 +52,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> VisitingEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
mem_tracker: &'d mut MemoryTracker,
map_lib_adapter: &'e mut MapLibAdapter,
io_adapter: &'f mut IOAdapter,
report_var_metadata: &'g mut ReportVarMetadata,
report_vars: &'g mut ReportVars,
unshared_var_handler: &'g mut UnsharedVarHandler,
) -> Self {
let a = Self {
Expand All @@ -62,7 +62,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> VisitingEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
mem_tracker,
map_lib_adapter,
io_adapter,
report_var_metadata,
report_vars,
unshared_var_handler,
instr_created_args: vec![],
curr_num_unshared: 0,
Expand Down Expand Up @@ -389,7 +389,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> VisitingEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand Down Expand Up @@ -733,7 +733,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g> VisitingEmitter<'a, 'b, 'c, 'd, 'e, 'f, 'g> {
configure_flush_routines(
self.app_iter.module,
self.table,
self.report_var_metadata,
self.report_vars,
self.map_lib_adapter,
self.io_adapter,
UNEXPECTED_ERR_MSG,
Expand All @@ -757,7 +757,7 @@ impl Emitter for VisitingEmitter<'_, '_, '_, '_, '_, '_, '_> {
print_report_all(
&mut self.app_iter,
self.table,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
err,
);
Expand Down Expand Up @@ -802,7 +802,7 @@ impl Emitter for VisitingEmitter<'_, '_, '_, '_, '_, '_, '_> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand All @@ -817,7 +817,7 @@ impl Emitter for VisitingEmitter<'_, '_, '_, '_, '_, '_, '_> {
self.table,
self.mem_tracker,
self.map_lib_adapter,
self.report_var_metadata,
self.report_vars,
self.unshared_var_handler,
UNEXPECTED_ERR_MSG,
err,
Expand Down
Loading

0 comments on commit 247ab78

Please sign in to comment.