2025-09-08 03:27:52 +09:00
|
|
|
#[test]
|
|
|
|
|
fn llvm_bitops_compile_and_exec() {
|
2025-11-17 11:28:18 +09:00
|
|
|
use crate::backend::VM;
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
use crate::mir::{
|
|
|
|
|
BinaryOp, BasicBlockId, ConstValue, FunctionSignature, MirFunction,
|
|
|
|
|
MirInstruction, MirModule, MirType,
|
|
|
|
|
};
|
2025-09-08 03:27:52 +09:00
|
|
|
|
|
|
|
|
// Build MIR: compute sum of bitwise/shift ops -> 48
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let sig = FunctionSignature {
|
|
|
|
|
name: "Main.main".into(),
|
|
|
|
|
params: vec![],
|
|
|
|
|
return_type: MirType::Integer,
|
|
|
|
|
effects: Default::default(),
|
|
|
|
|
};
|
2025-09-08 03:27:52 +09:00
|
|
|
let mut f = MirFunction::new(sig, BasicBlockId::new(0));
|
|
|
|
|
let bb = f.entry_block;
|
|
|
|
|
// Constants
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let c5 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c5,
|
|
|
|
|
value: ConstValue::Integer(5),
|
|
|
|
|
});
|
|
|
|
|
let c3 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c3,
|
|
|
|
|
value: ConstValue::Integer(3),
|
|
|
|
|
});
|
|
|
|
|
let c2 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c2,
|
|
|
|
|
value: ConstValue::Integer(2),
|
|
|
|
|
});
|
|
|
|
|
let c1 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c1,
|
|
|
|
|
value: ConstValue::Integer(1),
|
|
|
|
|
});
|
|
|
|
|
let c32 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c32,
|
|
|
|
|
value: ConstValue::Integer(32),
|
|
|
|
|
});
|
|
|
|
|
let c5_sh = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c5_sh,
|
|
|
|
|
value: ConstValue::Integer(5),
|
|
|
|
|
});
|
|
|
|
|
let c3_sh = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Const {
|
|
|
|
|
dst: c3_sh,
|
|
|
|
|
value: ConstValue::Integer(3),
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
|
|
|
|
|
// a = 5 & 3 -> 1
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let a = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: a,
|
|
|
|
|
op: BinaryOp::BitAnd,
|
|
|
|
|
lhs: c5,
|
|
|
|
|
rhs: c3,
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
// b = 5 | 2 -> 7
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let b = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: b,
|
|
|
|
|
op: BinaryOp::BitOr,
|
|
|
|
|
lhs: c5,
|
|
|
|
|
rhs: c2,
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
// c = 5 ^ 1 -> 4
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let c = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: c,
|
|
|
|
|
op: BinaryOp::BitXor,
|
|
|
|
|
lhs: c5,
|
|
|
|
|
rhs: c1,
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
// d = 1 << 5 -> 32
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let d = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: d,
|
|
|
|
|
op: BinaryOp::Shl,
|
|
|
|
|
lhs: c1,
|
|
|
|
|
rhs: c5_sh,
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
// e = 32 >> 3 -> 4
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let e = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: e,
|
|
|
|
|
op: BinaryOp::Shr,
|
|
|
|
|
lhs: c32,
|
|
|
|
|
rhs: c3_sh,
|
|
|
|
|
});
|
2025-09-08 03:27:52 +09:00
|
|
|
|
|
|
|
|
// sum = a + b + c + d + e
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let t1 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: t1,
|
|
|
|
|
op: BinaryOp::Add,
|
|
|
|
|
lhs: a,
|
|
|
|
|
rhs: b,
|
|
|
|
|
});
|
|
|
|
|
let t2 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: t2,
|
|
|
|
|
op: BinaryOp::Add,
|
|
|
|
|
lhs: t1,
|
|
|
|
|
rhs: c,
|
|
|
|
|
});
|
|
|
|
|
let t3 = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: t3,
|
|
|
|
|
op: BinaryOp::Add,
|
|
|
|
|
lhs: t2,
|
|
|
|
|
rhs: d,
|
|
|
|
|
});
|
|
|
|
|
let sum = f.next_value_id();
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::BinOp {
|
|
|
|
|
dst: sum,
|
|
|
|
|
op: BinaryOp::Add,
|
|
|
|
|
lhs: t3,
|
|
|
|
|
rhs: e,
|
|
|
|
|
});
|
|
|
|
|
f.get_block_mut(bb)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.add_instruction(MirInstruction::Return { value: Some(sum) });
|
2025-09-08 03:27:52 +09:00
|
|
|
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let mut m = MirModule::new("bitops".into());
|
|
|
|
|
m.add_function(f);
|
2025-09-08 03:27:52 +09:00
|
|
|
|
|
|
|
|
// VM executes to 48
|
|
|
|
|
let mut vm = VM::new();
|
|
|
|
|
let out = vm.execute_module(&m).expect("vm exec");
|
|
|
|
|
assert_eq!(out.to_string_box().value, "48");
|
|
|
|
|
|
|
|
|
|
// LLVM: ensure lowering/emit succeeds; compile_and_execute should also return 48 (via MIR interpreter fallback)
|
2025-09-14 00:44:28 +09:00
|
|
|
#[cfg(feature = "llvm-inkwell-legacy")]
|
2025-09-08 03:27:52 +09:00
|
|
|
{
|
|
|
|
|
use crate::backend::llvm;
|
refactor(tests): Reorganize test files into module directories
- Split join_ir_vm_bridge_dispatch.rs into module directory
- Reorganize test files into categorical directories:
- exec_parity/, flow/, if_no_phi/, joinir/, macro_tests/
- mir/, parser/, sugar/, vm/, vtable/
- Fix compilation errors after refactoring:
- BinaryOperator::LessThan → Less, Mod → Modulo
- Add VM re-export in backend::vm module
- Fix BinaryOp import to use public API
- Add callee: None for MirInstruction::Call
- Fix VMValue type mismatch with proper downcast
- Resolve borrow checker issues in vtable tests
- Mark 2 tests using internal APIs as #[ignore]
JoinIR tests: 50 passed, 0 failed, 20 ignored
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 18:28:20 +09:00
|
|
|
let tmp = format!(
|
|
|
|
|
"{}/target/aot_objects/test_bitops",
|
|
|
|
|
env!("CARGO_MANIFEST_DIR")
|
|
|
|
|
);
|
2025-09-08 03:27:52 +09:00
|
|
|
llvm::compile_to_object(&m, &format!("{}.o", tmp)).expect("llvm emit");
|
|
|
|
|
let out2 = llvm::compile_and_execute(&m, &tmp).expect("llvm compile&exec");
|
|
|
|
|
assert_eq!(out2.to_string_box().value, "48");
|
|
|
|
|
}
|
|
|
|
|
}
|