From 247ab78e3f01028c4d975349d43b330e7e7d31b7 Mon Sep 17 00:00:00 2001 From: evilg Date: Mon, 11 Nov 2024 15:18:31 -0500 Subject: [PATCH] Move report vars under lang_features folder (#175) * Move report vars under lang_features folder * fmt --- src/common/instr.rs | 20 ++-- src/emitter/mod.rs | 13 +-- src/emitter/module_emitter.rs | 20 ++-- src/emitter/rewriting/visiting_emitter.rs | 18 ++-- src/emitter/utils.rs | 96 +++++++++---------- src/generator/mod.rs | 4 +- src/generator/rewriting/init_generator.rs | 4 +- src/generator/rewriting/instr_generator.rs | 4 +- src/generator/wizard/mod.rs | 4 +- src/lang_features/alloc_vars/rewriting.rs | 13 +-- .../libraries/core/maps/map_adapter.rs | 26 ++--- src/lang_features/mod.rs | 1 + .../report_vars.rs} | 8 +- 13 files changed, 108 insertions(+), 123 deletions(-) rename src/{emitter/report_var_metadata.rs => lang_features/report_vars.rs} (98%) diff --git a/src/common/instr.rs b/src/common/instr.rs index 411c3e25..86097163 100644 --- a/src/common/instr.rs +++ b/src/common/instr.rs @@ -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; @@ -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; @@ -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! @@ -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, @@ -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); @@ -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, @@ -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, @@ -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, ) { @@ -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(), @@ -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, diff --git a/src/emitter/mod.rs b/src/emitter/mod.rs index 7b129c75..c0c7b947 100644 --- a/src/emitter/mod.rs +++ b/src/emitter/mod.rs @@ -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}; @@ -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 = report_var_metadata + let var_meta: HashMap = report_vars .variable_metadata .iter() .map(|(key, value)| (*key, value.to_csv())) .collect(); - let map_meta: HashMap = report_var_metadata + let map_meta: HashMap = report_vars .map_metadata .iter() .map(|(key, value)| (*key, value.to_csv())) diff --git a/src/emitter/module_emitter.rs b/src/emitter/module_emitter.rs index ebd700e3..a6b68296 100644 --- a/src/emitter/module_emitter.rs +++ b/src/emitter/module_emitter.rs @@ -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; @@ -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, } @@ -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 { @@ -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()], @@ -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, ) @@ -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)) @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/src/emitter/rewriting/visiting_emitter.rs b/src/emitter/rewriting/visiting_emitter.rs index 5a48271d..4a828cf0 100644 --- a/src/emitter/rewriting/visiting_emitter.rs +++ b/src/emitter/rewriting/visiting_emitter.rs @@ -5,7 +5,6 @@ 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, }; @@ -13,6 +12,7 @@ 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}; @@ -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, @@ -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 { @@ -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, @@ -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, @@ -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, @@ -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, ); @@ -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, @@ -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, diff --git a/src/emitter/utils.rs b/src/emitter/utils.rs index dedb1507..258bd0f5 100644 --- a/src/emitter/utils.rs +++ b/src/emitter/utils.rs @@ -1,11 +1,11 @@ #![allow(clippy::too_many_arguments)] use crate::common::error::ErrorGen; use crate::emitter::module_emitter::MemoryTracker; -use crate::emitter::report_var_metadata::ReportVarMetadata; use crate::emitter::InjectStrategy; use crate::generator::folding::ExprFolder; use crate::lang_features::alloc_vars::rewriting::UnsharedVarHandler; use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter; +use crate::lang_features::report_vars::ReportVars; use crate::parser::types::{ BinOp, Block, DataType, Definition, Expr, Location, Statement, UnOp, Value, }; @@ -35,7 +35,7 @@ pub fn emit_body<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -49,7 +49,7 @@ pub fn emit_body<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -65,7 +65,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -81,7 +81,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -93,7 +93,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -111,7 +111,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -126,7 +126,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -140,7 +140,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -152,7 +152,7 @@ pub fn emit_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -259,7 +259,7 @@ fn emit_unshared_decl_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, _mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -295,7 +295,7 @@ fn emit_unshared_decl_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( addr, injector, map_lib_adapter, - report_var_metadata, + report_vars, err_msg, err, ) @@ -332,7 +332,7 @@ fn emit_assign_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -359,7 +359,7 @@ fn emit_assign_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( } if *is_report_var { //you changed a report variable: need to turn dirty bool to true and then print somewhere - report_var_metadata.flush_soon = true; + report_vars.flush_soon = true; } } @@ -370,7 +370,7 @@ fn emit_assign_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -383,7 +383,7 @@ fn emit_assign_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( var_id, injector, table, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -410,7 +410,7 @@ fn emit_set_map_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -425,7 +425,7 @@ fn emit_set_map_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( let Some((map_id, key_ty, val_ty)) = get_map_info(table, name, err) else { return false; }; - report_var_metadata.mutating_map(map_id); + report_vars.mutating_map(map_id); injector.u32_const(map_id); emit_expr( @@ -435,7 +435,7 @@ fn emit_set_map_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -447,7 +447,7 @@ fn emit_set_map_stmt<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -515,7 +515,7 @@ fn emit_set<'a, T: Opcode<'a>>( var_id: &mut Expr, injector: &mut T, table: &mut SymbolTable, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, _unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -529,11 +529,11 @@ fn emit_set<'a, T: Opcode<'a>>( // this will be different based on if this is a global or local var match addr { Some(VarAddr::Global { addr }) => { - report_var_metadata.mutating_var(*addr); + report_vars.mutating_var(*addr); injector.global_set(GlobalID(*addr)); } Some(VarAddr::Local { addr }) => { - report_var_metadata.mutating_var(*addr); + report_vars.mutating_var(*addr); injector.local_set(LocalID(*addr)); } Some(VarAddr::MapId { .. }) => { @@ -568,7 +568,7 @@ fn emit_if_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -583,7 +583,7 @@ fn emit_if_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -598,7 +598,7 @@ fn emit_if_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -617,7 +617,7 @@ fn emit_if_else_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -632,7 +632,7 @@ fn emit_if_else_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -649,7 +649,7 @@ fn emit_if_else_preamble<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -668,7 +668,7 @@ fn emit_if<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -683,7 +683,7 @@ fn emit_if<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -703,7 +703,7 @@ fn emit_if_else<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -719,7 +719,7 @@ fn emit_if_else<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -738,7 +738,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -754,7 +754,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -770,7 +770,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -782,7 +782,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -834,7 +834,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -858,7 +858,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -945,7 +945,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -957,7 +957,7 @@ pub(crate) fn emit_expr<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -1040,7 +1040,7 @@ fn emit_value<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -1105,7 +1105,7 @@ fn emit_value<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -1144,7 +1144,7 @@ fn emit_map_get<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table: &mut SymbolTable, mem_tracker: &MemoryTracker, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, unshared_var_handler: &mut UnsharedVarHandler, err_msg: &str, err: &mut ErrorGen, @@ -1162,7 +1162,7 @@ fn emit_map_get<'a, T: Opcode<'a> + MacroOpcode<'a> + AddLocal>( table, mem_tracker, map_lib_adapter, - report_var_metadata, + report_vars, unshared_var_handler, err_msg, err, @@ -1234,11 +1234,11 @@ fn get_map_info( pub fn print_report_all<'a, T: Opcode<'a> + AddLocal>( injector: &mut T, table: &mut SymbolTable, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, _unshared_var_handler: &mut UnsharedVarHandler, err: &mut ErrorGen, ) { - if !report_var_metadata.flush_soon { + if !report_vars.flush_soon { return; } let Some(Record::Fn { @@ -1258,5 +1258,5 @@ pub fn print_report_all<'a, T: Opcode<'a> + AddLocal>( return; }; injector.call(FunctionID(*fid)); - report_var_metadata.performed_flush(); + report_vars.performed_flush(); } diff --git a/src/generator/mod.rs b/src/generator/mod.rs index 44eba5e2..74b0be6a 100644 --- a/src/generator/mod.rs +++ b/src/generator/mod.rs @@ -1,4 +1,4 @@ -use crate::emitter::report_var_metadata::LocationData; +use crate::lang_features::report_vars::LocationData; use crate::parser::rules::{Event, Package, Probe, Provider}; use crate::parser::types::{ BinOp, Block, DataType, Definition, Expr, Fn, Global, ProvidedFunction, Script, Statement, @@ -60,7 +60,7 @@ pub trait GeneratingVisitor: WhammVisitorMut { // do not inject globals into Wasm that are used/defined by the compiler if global.is_from_user() { if global.report { - //emit global and add the metadata to the report_var_metadata + //emit global and add the metadata to the report_vars if let Some(fid) = self.emit_report_global(name.clone(), global.ty.clone(), &global.value) { diff --git a/src/generator/rewriting/init_generator.rs b/src/generator/rewriting/init_generator.rs index 2ea3d876..be7c51d6 100644 --- a/src/generator/rewriting/init_generator.rs +++ b/src/generator/rewriting/init_generator.rs @@ -4,8 +4,8 @@ use crate::common::error::ErrorGen; use crate::emitter::module_emitter::ModuleEmitter; -use crate::emitter::report_var_metadata::LocationData; use crate::generator::GeneratingVisitor; +use crate::lang_features::report_vars::LocationData; use crate::parser::types::{DataType, Fn, Value, Whamm, WhammVisitorMut}; use orca_wasm::ir::id::FunctionID; @@ -75,7 +75,7 @@ impl GeneratingVisitor for InitGenerator<'_, '_, '_, '_, '_, '_, '_, '_, '_> { } fn set_curr_loc(&mut self, loc: LocationData) { - self.emitter.report_var_metadata.curr_location = loc; + self.emitter.report_vars.curr_location = loc; } fn enter_named_scope(&mut self, name: &str) { diff --git a/src/generator/rewriting/instr_generator.rs b/src/generator/rewriting/instr_generator.rs index 34a22966..4553feaa 100644 --- a/src/generator/rewriting/instr_generator.rs +++ b/src/generator/rewriting/instr_generator.rs @@ -1,10 +1,10 @@ use crate::common::error::ErrorGen; -use crate::emitter::report_var_metadata::{BytecodeLoc, LocationData}; use crate::emitter::rewriting::rules::{provider_factory, Arg, LocInfo, ProbeRule, WhammProvider}; use crate::emitter::rewriting::visiting_emitter::VisitingEmitter; use crate::emitter::Emitter; use crate::generator::folding::ExprFolder; use crate::generator::rewriting::simple_ast::{SimpleAST, SimpleProbe}; +use crate::lang_features::report_vars::{BytecodeLoc, LocationData}; use crate::parser::rules::core::WhammModeKind; use crate::parser::types::{Block, Expr, Value}; use orca_wasm::iterator::iterator_trait::Iterator; @@ -196,7 +196,7 @@ impl<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h> InstrGenerator<'a, 'b, 'c, 'd, 'e, 'f, 'g, } => BytecodeLoc::new(*func_idx, instr_idx as u32), }; //set the current location in bytecode and load some new globals for potential report vars - self.emitter.report_var_metadata.curr_location = LocationData::Local { + self.emitter.report_vars.curr_location = LocationData::Local { script_id: curr_script_id, bytecode_loc: loc, probe_id: curr_probe_id, diff --git a/src/generator/wizard/mod.rs b/src/generator/wizard/mod.rs index d8481268..32370e09 100644 --- a/src/generator/wizard/mod.rs +++ b/src/generator/wizard/mod.rs @@ -4,11 +4,11 @@ pub mod metadata_collector; use crate::common::error::ErrorGen; use crate::common::instr::Config; use crate::emitter::module_emitter::ModuleEmitter; -use crate::emitter::report_var_metadata::{BytecodeLoc, LocationData}; use crate::emitter::utils::{whamm_type_to_wasm_global, whamm_type_to_wasm_type}; use crate::generator::wizard::ast::{WizardProbe, WizardScript}; use crate::generator::GeneratingVisitor; use crate::lang_features::libraries::core::io::io_adapter::IOAdapter; +use crate::lang_features::report_vars::{BytecodeLoc, LocationData}; use crate::parser::types::{Block, DataType, Definition, FnId, Statement, Value, WhammVisitorMut}; use crate::verifier::types::{Record, VarAddr}; use log::trace; @@ -272,7 +272,7 @@ impl GeneratingVisitor for WizardGenerator<'_, '_, '_, '_, '_, '_, '_, '_, '_, ' } fn set_curr_loc(&mut self, loc: LocationData) { - self.emitter.report_var_metadata.curr_location = loc; + self.emitter.report_vars.curr_location = loc; } fn enter_named_scope(&mut self, name: &str) { diff --git a/src/lang_features/alloc_vars/rewriting.rs b/src/lang_features/alloc_vars/rewriting.rs index a5b3aba8..b0afa0d0 100644 --- a/src/lang_features/alloc_vars/rewriting.rs +++ b/src/lang_features/alloc_vars/rewriting.rs @@ -1,8 +1,8 @@ #![allow(clippy::too_many_arguments)] use crate::common::error::ErrorGen; -use crate::emitter::report_var_metadata::ReportVarMetadata; use crate::emitter::utils::whamm_type_to_wasm_type; use crate::lang_features::libraries::core::maps::map_adapter::MapLibAdapter; +use crate::lang_features::report_vars::ReportVars; use crate::parser::types::DataType; use crate::verifier::types::VarAddr; use orca_wasm::module_builder::AddLocal; @@ -39,7 +39,7 @@ impl UnsharedVarHandler { addr: &mut Option, injector: &mut T, map_lib_adapter: &mut MapLibAdapter, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, err_msg: &str, err: &mut ErrorGen, ) -> bool { @@ -49,7 +49,7 @@ impl UnsharedVarHandler { var_name.to_string(), ty.clone(), injector, - report_var_metadata, + report_vars, true, err, ) @@ -64,12 +64,7 @@ impl UnsharedVarHandler { let wasm_ty = whamm_type_to_wasm_type(ty); if let Some(id) = self.use_available_gid(err_msg, err) { if is_report { - report_var_metadata.put_local_metadata( - id, - var_name.to_string(), - wasm_ty, - err, - ); + report_vars.put_local_metadata(id, var_name.to_string(), wasm_ty, err); } *addr = Some(VarAddr::Global { addr: id }); diff --git a/src/lang_features/libraries/core/maps/map_adapter.rs b/src/lang_features/libraries/core/maps/map_adapter.rs index 20c9bcb4..1af31f8d 100644 --- a/src/lang_features/libraries/core/maps/map_adapter.rs +++ b/src/lang_features/libraries/core/maps/map_adapter.rs @@ -1,6 +1,6 @@ use crate::common::error::ErrorGen; -use crate::emitter::report_var_metadata::{LocationData, Metadata, ReportVarMetadata}; use crate::lang_features::libraries::core::LibAdapter; +use crate::lang_features::report_vars::{LocationData, Metadata, ReportVars}; use crate::parser::types::DataType; use orca_wasm::ir::id::{FunctionID, GlobalID}; use orca_wasm::ir::types::BlockType as OrcaBlockType; @@ -104,13 +104,13 @@ impl MapLibAdapter { name: String, ty: DataType, func: &mut T, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, is_local: bool, err: &mut ErrorGen, ) -> u32 { let map_id = self.map_create(ty, func, err); //create the metadata for the map - self.create_map_metadata(map_id, name.clone(), report_var_metadata, is_local, err); + self.create_map_metadata(map_id, name.clone(), report_vars, is_local, err); map_id } @@ -164,25 +164,19 @@ impl MapLibAdapter { &mut self, map_id: u32, name: String, - report_var_metadata: &mut ReportVarMetadata, + report_vars: &mut ReportVars, is_local: bool, err: &mut ErrorGen, ) { if is_local { - if !matches!( - report_var_metadata.curr_location, - LocationData::Local { .. } - ) { + if !matches!(report_vars.curr_location, LocationData::Local { .. }) { err.unexpected_error( true, Some(format!("Can only emit local maps when in a local function scope in the target application...but we're in the global scope! See map: {}", name)), None, ); } - } else if !matches!( - report_var_metadata.curr_location, - LocationData::Global { .. } - ) { + } else if !matches!(report_vars.curr_location, LocationData::Global { .. }) { err.unexpected_error( true, Some(format!("Can only emit global maps when in the global scope of the target application...but we're in a local function scope! See map: {}", name)), @@ -190,11 +184,9 @@ impl MapLibAdapter { ); }; - let metadata = Metadata::new(name.clone(), &report_var_metadata.curr_location); - report_var_metadata - .map_metadata - .insert(map_id, metadata.clone()); - if !report_var_metadata.all_metadata.insert(metadata) { + let metadata = Metadata::new(name.clone(), &report_vars.curr_location); + report_vars.map_metadata.insert(map_id, metadata.clone()); + if !report_vars.all_metadata.insert(metadata) { err.unexpected_error( true, Some(format!("Duplicate metadata for map with name: {}", name)), diff --git a/src/lang_features/mod.rs b/src/lang_features/mod.rs index f01b60e7..721c974c 100644 --- a/src/lang_features/mod.rs +++ b/src/lang_features/mod.rs @@ -1,2 +1,3 @@ pub mod alloc_vars; pub mod libraries; +pub mod report_vars; diff --git a/src/emitter/report_var_metadata.rs b/src/lang_features/report_vars.rs similarity index 98% rename from src/emitter/report_var_metadata.rs rename to src/lang_features/report_vars.rs index 06996bbb..5fafcc8a 100644 --- a/src/emitter/report_var_metadata.rs +++ b/src/lang_features/report_vars.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use crate::common::error::ErrorGen; -pub struct ReportVarMetadata { +pub struct ReportVars { //MapID -> Metadata pub map_metadata: HashMap, //GID -> Metadata @@ -12,15 +12,15 @@ pub struct ReportVarMetadata { pub curr_location: LocationData, pub flush_soon: bool, } -impl Default for ReportVarMetadata { +impl Default for ReportVars { fn default() -> Self { Self::new() } } -impl ReportVarMetadata { +impl ReportVars { pub fn new() -> Self { - ReportVarMetadata { + ReportVars { map_metadata: HashMap::new(), variable_metadata: HashMap::new(), all_metadata: HashSet::new(),