Remove module-level code generation tests (#5870)

* Remove module-level code generation tests

* Add cold block tests for each backend

* Better cold block tests
This commit is contained in:
Trevor Elliott
2023-02-23 17:19:26 -08:00
committed by GitHub
parent f91640ffab
commit c5d9d5b10f
8 changed files with 309 additions and 662 deletions

View File

@@ -214,64 +214,3 @@ pub fn isa_builder(triple: Triple) -> IsaBuilder {
},
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::cursor::{Cursor, FuncCursor};
use crate::dominator_tree::DominatorTree;
use crate::flowgraph::ControlFlowGraph;
use crate::ir::types::*;
use crate::ir::{AbiParam, Function, InstBuilder, Signature, UserFuncName};
use crate::isa::CallConv;
use crate::settings;
use crate::settings::Configurable;
use core::str::FromStr;
use target_lexicon::Triple;
#[test]
fn test_compile_function() {
let name = UserFuncName::testcase("test0");
let mut sig = Signature::new(CallConv::SystemV);
sig.params.push(AbiParam::new(I32));
sig.returns.push(AbiParam::new(I32));
let mut func = Function::with_name_signature(name, sig);
let bb0 = func.dfg.make_block();
let arg0 = func.dfg.append_block_param(bb0, I32);
let mut pos = FuncCursor::new(&mut func);
pos.insert_block(bb0);
let v0 = pos.ins().iconst(I32, 0x1234);
let v1 = pos.ins().iadd(arg0, v0);
pos.ins().return_(&[v1]);
let mut shared_flags_builder = settings::builder();
shared_flags_builder.set("opt_level", "none").unwrap();
let shared_flags = settings::Flags::new(shared_flags_builder);
let isa_flags = riscv_settings::Flags::new(&shared_flags, riscv_settings::builder());
let backend = Riscv64Backend::new_with_flags(
Triple::from_str("riscv64").unwrap(),
shared_flags,
isa_flags,
);
let cfg = ControlFlowGraph::with_function(&func);
let domtree = DominatorTree::with_function(&func, &cfg);
let buffer = backend.compile_function(&mut func, &domtree, true).unwrap();
let code = buffer.buffer.data();
// To update this comment, write the golden bytes to a file, and run the following command
// on it to update:
// > riscv64-linux-gnu-objdump -b binary -D <file> -m riscv
//
// 0: 000015b7 lui a1,0x1
// 4: 23458593 addi a1,a1,564 # 0x1234
// 8: 00b5053b .4byte 0xb5053b
// c: 00008067 ret
let golden = vec![
183, 21, 0, 0, 147, 133, 69, 35, 59, 5, 181, 0, 103, 128, 0, 0,
];
assert_eq!(code, &golden[..]);
}
}