From 9d4220315e16a76a0656aca0f59def70544de4df Mon Sep 17 00:00:00 2001 From: philogy Date: Tue, 5 Nov 2024 23:25:09 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20broken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/analysis/src/lib.rs | 13 +++++++++++-- crates/cli/src/main.rs | 5 +++-- crates/compilation/src/lib.rs | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/analysis/src/lib.rs b/crates/analysis/src/lib.rs index dba3c53..4c250cf 100644 --- a/crates/analysis/src/lib.rs +++ b/crates/analysis/src/lib.rs @@ -220,12 +220,14 @@ impl<'a, 'src, 'ast: 'src, E: FnMut(AnalysisError<'ast, 'src>)> MacroAnalysis<'a } } Invoke::BuiltinCodeSize(code_ref) | Invoke::BuiltinCodeOffset(code_ref) => { + let mut no_error = true; if !global_exists!(self.global_defs, code_ref.ident(), Definition::Macro(_)) { self.emit(AnalysisError::DefinitionNotFound { scope: self.m, def_type: "macro", not_found: code_ref, - }) + }); + no_error = false; } if self .global_defs @@ -240,7 +242,14 @@ impl<'a, 'src, 'ast: 'src, E: FnMut(AnalysisError<'ast, 'src>)> MacroAnalysis<'a self.emit(AnalysisError::NotYetSupported { intent: "code introspection for macros with arguments".to_owned(), span: ((), code_ref.1), - }) + }); + no_error = false; + } + let mut inner_errors = Vec::new(); + if no_error { + analyze_entry_point(self.global_defs, code_ref.ident(), |err| { + inner_errors.push(err) + }); } } Invoke::BuiltinFuncSig(func_or_error_ref) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 9a39c54..7a50750 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -120,9 +120,10 @@ fn main() -> Result<(), Box> { } let mut mtracker = MarkTracker::default(); - let config = CompileGlobals::new(cli.evm_version.allows_push0(), unique_defs); + let mut config = CompileGlobals::new(cli.evm_version.allows_push0(), unique_defs); - let asm = match generate_for_entrypoint(&config, entry_point_macro.unwrap(), &mut mtracker) { + let asm = match generate_for_entrypoint(&mut config, entry_point_macro.unwrap(), &mut mtracker) + { Ok(asm) => asm, Err(reason) => { eprintln!("{}: {}", "Error".fg(Color::Red), reason); diff --git a/crates/compilation/src/lib.rs b/crates/compilation/src/lib.rs index c8a8813..22e7321 100644 --- a/crates/compilation/src/lib.rs +++ b/crates/compilation/src/lib.rs @@ -5,7 +5,7 @@ use huff_ast::*; use std::collections::BTreeMap; pub fn generate_for_entrypoint<'src>( - globals: &CompileGlobals<'src, '_>, + globals: &mut CompileGlobals<'src, '_>, entry_point: &Macro<'src>, mark_tracker: &mut MarkTracker, ) -> Result, String> { @@ -45,7 +45,7 @@ pub fn generate_default_constructor(runtime: Vec) -> Box<[Asm]> { } fn generate_for_macro<'src: 'cmp, 'cmp>( - globals: &CompileGlobals<'src, '_>, + globals: &mut CompileGlobals<'src, '_>, current: &Macro<'src>, arg_values: Box<[Asm]>, mark_tracker: &mut MarkTracker, @@ -87,7 +87,7 @@ fn generate_for_macro<'src: 'cmp, 'cmp>( }; generate_for_macro( globals, - target, + &target, args.0 .iter() .map(|arg| instruction_to_asm(globals, ¤t_args, label_stack, arg)) @@ -102,7 +102,7 @@ fn generate_for_macro<'src: 'cmp, 'cmp>( invoke )), }, - MacroStatement::Instruction(i) => { + MacroStatement::Instruction(ref i) => { asm.push(instruction_to_asm(globals, ¤t_args, label_stack, i)); Ok(()) } @@ -139,11 +139,19 @@ pub fn u256_to_asm(value: U256, allow_push0: bool) -> Asm { }) } +#[derive(Debug, Clone)] +pub struct IncludedMacro { + start_id: usize, + end_id: usize, + code: Vec, +} + #[derive(Debug, Clone)] pub struct CompileGlobals<'src, 'ast> { pub allow_push0: bool, pub defs: BTreeMap<&'src str, &'ast Definition<'src>>, pub constants: BTreeMap<&'src str, U256>, + pub referenced_macros: BTreeMap<&'src str, IncludedMacro>, } impl<'src, 'ast> CompileGlobals<'src, 'ast> { @@ -153,6 +161,7 @@ impl<'src, 'ast> CompileGlobals<'src, 'ast> { allow_push0, defs, constants, + referenced_macros: BTreeMap::new(), } } }