merge util.rs into dbg.rs

This commit is contained in:
Fabian 2025-07-03 16:59:47 +07:00
parent 0cc8f0221e
commit 13d4dd0ca9
4 changed files with 45 additions and 50 deletions

View file

@ -28,6 +28,7 @@ use crate::cpu::misc_instr::{
};
use crate::cpu::modrm::{resolve_modrm16, resolve_modrm32};
use crate::cpu::pic;
use crate::dbg::dbg_trace;
use crate::gen;
use crate::jit;
use crate::jit::is_near_end_of_page;
@ -39,7 +40,6 @@ use crate::profiler;
use crate::profiler::stat;
use crate::softfloat;
use crate::state_flags::CachedStateFlags;
use crate::util::dbg_trace;
use std::collections::HashSet;
use std::ptr;

View file

@ -1,3 +1,43 @@
#[allow(dead_code)]
pub const DEBUG: bool = cfg!(debug_assertions);
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn log_from_wasm(ptr: *const u8, len: usize);
pub fn console_log_from_wasm(ptr: *const u8, len: usize);
pub fn dbg_trace_from_wasm();
}
#[cfg(target_arch = "wasm32")]
pub fn log_to_js_console<T: std::string::ToString>(s: T) {
let s = s.to_string();
let len = s.len();
unsafe {
log_from_wasm(s.as_bytes().as_ptr(), len);
}
}
#[cfg(target_arch = "wasm32")]
pub fn console_log_to_js_console<T: std::string::ToString>(s: T) {
let s = s.to_string();
let len = s.len();
unsafe {
console_log_from_wasm(s.as_bytes().as_ptr(), len);
}
}
#[cfg(target_arch = "wasm32")]
pub fn dbg_trace() {
if DEBUG {
unsafe {
dbg_trace_from_wasm();
}
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn dbg_trace() {}
#[allow(unused_macros)]
macro_rules! dbg_log {
($fmt:expr) => {
@ -30,14 +70,12 @@ macro_rules! dbg_assert {
macro_rules! console_log {
($fmt:expr) => {
{
use crate::util::{ console_log_to_js_console };
console_log_to_js_console($fmt);
crate::dbg::console_log_to_js_console($fmt);
}
};
($fmt:expr, $($arg:tt)*) => {
{
use crate::util::{ console_log_to_js_console };
console_log_to_js_console(format!($fmt, $($arg)*));
crate::dbg::console_log_to_js_console(format!($fmt, $($arg)*));
}
};
}
@ -47,13 +85,13 @@ macro_rules! console_log {
macro_rules! dbg_log {
($fmt:expr) => {
{
use crate::util::{ DEBUG, log_to_js_console };
use crate::dbg::{ DEBUG, log_to_js_console };
if DEBUG { log_to_js_console($fmt); }
}
};
($fmt:expr, $($arg:tt)*) => {
{
use crate::util::{ DEBUG, log_to_js_console };
use crate::dbg::{ DEBUG, log_to_js_console };
if DEBUG { log_to_js_console(format!($fmt, $($arg)*)); }
}
};

View file

@ -27,6 +27,5 @@ mod prefix;
mod regs;
mod softfloat;
mod state_flags;
mod util;
mod wasmgen;
mod zstd;

View file

@ -1,42 +0,0 @@
#[allow(dead_code)]
pub const DEBUG: bool = cfg!(debug_assertions);
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn log_from_wasm(ptr: *const u8, len: usize);
pub fn console_log_from_wasm(ptr: *const u8, len: usize);
pub fn dbg_trace_from_wasm();
}
#[cfg(target_arch = "wasm32")]
use std::string::ToString;
#[cfg(target_arch = "wasm32")]
pub fn log_to_js_console<T: ToString>(s: T) {
let s = s.to_string();
let len = s.len();
unsafe {
log_from_wasm(s.as_bytes().as_ptr(), len);
}
}
#[cfg(target_arch = "wasm32")]
pub fn console_log_to_js_console<T: ToString>(s: T) {
let s = s.to_string();
let len = s.len();
unsafe {
console_log_from_wasm(s.as_bytes().as_ptr(), len);
}
}
#[cfg(target_arch = "wasm32")]
pub fn dbg_trace() {
if DEBUG {
unsafe {
dbg_trace_from_wasm();
}
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn dbg_trace() { }