Skip to content

Commit

Permalink
[FIX] i think i fixed #8 for windows but it isn't fixed for linux + […
Browse files Browse the repository at this point in the history
…FIX] fixing test
  • Loading branch information
Cr0a3 committed Aug 27, 2024
1 parent 854ed8a commit f27cfe7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/Obj/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl ObjectBuilder {
let secData = obj.add_section(vec![], ".data".as_bytes().to_vec(), SectionKind::Data);
let secConsts = obj.add_section(vec![], ".rodata".as_bytes().to_vec(), SectionKind::ReadOnlyData);

let mut syms: BTreeMap<String, (Option<SectionId>, Option</*offsest*/u64>, SymbolId)> = BTreeMap::new();
let mut syms: BTreeMap<String, (Option<SectionId>, Option</*offsest*/u64>, SymbolId, Decl)> = BTreeMap::new();

for (name, data) in &self.defines {
let name = name.to_owned();
Expand Down Expand Up @@ -247,21 +247,25 @@ impl ObjectBuilder {
Decl::Constant => obj.add_symbol_data(sym, secConsts, &data, align),
};

syms.insert(name.clone(), (None, Some(def_offset), sym));
syms.insert(name.clone(), (None, Some(def_offset), sym, *decl));
} else {
syms.insert(name.clone(), (None, None, sym));
syms.insert(name.clone(), (None, None, sym, *decl));
}
}

for link in &self.links {
let (_, off, _) = syms.get(&link.from).unwrap();
let (_, _, to_sym) = syms.get(&link.to).unwrap();
let (_, off, _, _) = syms.get(&link.from).unwrap();
let (_, _, to_sym, ty) = syms.get(&link.to).unwrap();

let mut addend = 0;
let mut offset = 0;

if self.triple.getCallConv() == Ok(CallConv::WindowsFastCall) {
addend = -1;
addend = match ty {
Decl::Function => 0,
Decl::Data => -1,
Decl::Constant => -1,
};
offset = -4;
} else if self.triple.getCallConv() == Ok(CallConv::SystemV) {
addend = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Target/target_descr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl BackendInfos {

for (var, store) in &self.varsStorage {
if let VarStorage::Register(var_reg) = store {
if var_reg == &reg {
if var_reg.sub64() == reg.sub64() {
out = Some(var);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/x64_instruction_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ pub fn test_ret() {
#[test]
pub fn test_optimization() {
let mut instrs = vec![
Instr::with0(Mnemonic::StartOptimization),
Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rax.boxed()), Operand::Reg(x64Reg::Rcx.boxed())),
Instr::with2(Mnemonic::Add, Operand::Reg(x64Reg::Rax.boxed()), Operand::Reg(x64Reg::Rdx.boxed())),
Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rcx.boxed()), Operand::Reg(x64Reg::Rax.boxed())),
];

let expected_optimized = vec![
Instr::with0(Mnemonic::StartOptimization),
Instr::with2(Mnemonic::Lea, Operand::Reg(x64Reg::Rax.boxed()), Operand::Mem(x64Reg::Rcx + x64Reg::Rdx)),
Instr::with2(Mnemonic::Mov, Operand::Reg(x64Reg::Rcx.boxed()), Operand::Reg(x64Reg::Rax.boxed())),
];
Expand Down

0 comments on commit f27cfe7

Please sign in to comment.