use crate::SourcePosition;
use watto::Pod;
const SOURCEMAPCACHE_MAGIC_BYTES: [u8; 4] = *b"SMCA";
pub const SOURCEMAPCACHE_MAGIC: u32 = u32::from_le_bytes(SOURCEMAPCACHE_MAGIC_BYTES);
pub const SOURCEMAPCACHE_MAGIC_FLIPPED: u32 = SOURCEMAPCACHE_MAGIC.swap_bytes();
pub const SOURCEMAPCACHE_VERSION: u32 = 2;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct Header {
pub magic: u32,
pub version: u32,
pub num_mappings: u32,
pub num_files: u32,
pub num_line_offsets: u32,
pub string_bytes: u32,
pub _reserved: [u8; 8],
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(C)]
pub struct MinifiedSourcePosition {
pub line: u32,
pub column: u32,
}
impl From<SourcePosition> for MinifiedSourcePosition {
fn from(sp: SourcePosition) -> Self {
Self {
line: sp.line,
column: sp.column,
}
}
}
pub const NO_FILE_SENTINEL: u32 = u32::MAX;
pub const NO_NAME_SENTINEL: u32 = u32::MAX;
pub const GLOBAL_SCOPE_SENTINEL: u32 = u32::MAX;
pub const ANONYMOUS_SCOPE_SENTINEL: u32 = u32::MAX - 1;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct OriginalSourceLocation {
pub file_idx: u32,
pub line: u32,
pub column: u32,
pub name_idx: u32,
pub scope_idx: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(C)]
pub struct File {
pub name_offset: u32,
pub source_offset: u32,
pub line_offsets_start: u32,
pub line_offsets_end: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(C)]
pub struct LineOffset(pub u32);
unsafe impl Pod for Header {}
unsafe impl Pod for OriginalSourceLocation {}
unsafe impl Pod for MinifiedSourcePosition {}
unsafe impl Pod for File {}
unsafe impl Pod for LineOffset {}
#[cfg(test)]
mod tests {
use std::mem;
use super::*;
#[test]
fn test_sizeof() {
assert_eq!(mem::size_of::<Header>(), 32);
assert_eq!(mem::align_of::<Header>(), 4);
assert_eq!(mem::size_of::<MinifiedSourcePosition>(), 8);
assert_eq!(mem::align_of::<MinifiedSourcePosition>(), 4);
assert_eq!(mem::size_of::<OriginalSourceLocation>(), 20);
assert_eq!(mem::align_of::<OriginalSourceLocation>(), 4);
}
}