1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#![cfg_attr(coverage_nightly, coverage(off))]
//! WebAssembly Analysis Support for PMAT
//!
//! This module provides WASM-specific analysis capabilities using wasmparser
//! for bytecode analysis and complexity metrics extraction from WASM modules.
//!
//! ## Module Structure
//! - `wasm_analysis.rs`: WasmModuleAnalyzer and WasmStackAnalyzer implementations
//! - `wasm_validation.rs`: WasmValidator implementation
//! - `wasm_tests.rs`: Unit tests and property-based tests
#[cfg(feature = "wasm-ast")]
use crate::services::context::AstItem;
use std::path::{Path, PathBuf};
use wasmparser::{Parser, Payload};
/// WASM module analyzer that extracts WASM-specific information
pub struct WasmModuleAnalyzer {
items: Vec<AstItem>,
_file_path: PathBuf,
module_name: String,
function_count: usize,
_import_count: usize,
_export_count: usize,
}
/// WASM stack depth analyzer for complexity calculation (complexity ≤10)
pub struct WasmStackAnalyzer {
max_stack_depth: u32,
current_depth: u32,
branch_count: u32,
}
impl Default for WasmStackAnalyzer {
fn default() -> Self {
Self::new()
}
}
/// WASM validation and quality checks (complexity ≤10)
pub struct WasmValidator {
validation_errors: Vec<String>,
security_warnings: Vec<String>,
}
impl Default for WasmValidator {
fn default() -> Self {
Self::new()
}
}
// --- Submodule includes ---
include!("wasm_analysis.rs");
include!("wasm_validation.rs");
include!("wasm_tests.rs");