pub struct X64Context {
pub code: Vec<u8>,
pub stack_offset: i32,
pub labels: HashMap<String, Label>,
pub relocations: Vec<RelocationInfo>,
pub function_calls: Vec<FunctionCall>,
pub string_constants: HashMap<String, usize>,
pub register_usage: HashMap<X64Register, bool>,
pub stack_size: u32,
}Expand description
X64 代码生成上下文
Fields§
§code: Vec<u8>生成的机器码
stack_offset: i32当前栈偏移(相对于 RBP)
labels: HashMap<String, Label>标签管理
relocations: Vec<RelocationInfo>重定位信息
function_calls: Vec<FunctionCall>函数调用信息
string_constants: HashMap<String, usize>字符串常量表
register_usage: HashMap<X64Register, bool>寄存器使用状态
stack_size: u32当前函数的栈空间大小
Implementations§
Source§impl X64Context
impl X64Context
Sourcepub fn emit_bytes(&mut self, bytes: &[u8])
pub fn emit_bytes(&mut self, bytes: &[u8])
添加机器码字节
Sourcepub fn current_position(&self) -> usize
pub fn current_position(&self) -> usize
获取当前代码位置
Sourcepub fn define_label(&mut self, name: &str)
pub fn define_label(&mut self, name: &str)
定义标签
Sourcepub fn reference_label(&mut self, name: &str) -> usize
pub fn reference_label(&mut self, name: &str) -> usize
引用标签(用于跳转指令)
Sourcepub fn allocate_stack(&mut self, size: u32) -> i32
pub fn allocate_stack(&mut self, size: u32) -> i32
分配栈空间
Sourcepub fn add_string_constant(&mut self, value: &str) -> usize
pub fn add_string_constant(&mut self, value: &str) -> usize
添加字符串常量
Sourcepub fn add_function_call(&mut self, name: &str, is_import: bool)
pub fn add_function_call(&mut self, name: &str, is_import: bool)
添加函数调用
Sourcepub fn add_relocation(&mut self, reloc_type: RelocationType, symbol: &str)
pub fn add_relocation(&mut self, reloc_type: RelocationType, symbol: &str)
添加重定位信息
Trait Implementations§
Source§impl Debug for X64Context
impl Debug for X64Context
Auto Trait Implementations§
impl Freeze for X64Context
impl RefUnwindSafe for X64Context
impl Send for X64Context
impl Sync for X64Context
impl Unpin for X64Context
impl UnwindSafe for X64Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more