From 62a7c61cdc7927df6eef3e96937e88a0c4701b3b Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Fri, 25 Oct 2024 15:29:17 +0200 Subject: [PATCH] properly selecting li instructions for integer sizes --- lang/src/son.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lang/src/son.rs b/lang/src/son.rs index 3570056..c15e103 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -1430,9 +1430,12 @@ impl ItemCtx { self.emit(instrs::jmp(0)); } } - Kind::CInt { value } => { - self.emit(instrs::li64(atr(allocs[0]), value as _)); - } + Kind::CInt { value } => self.emit(match tys.size_of(node.ty) { + 1 => instrs::li8(atr(allocs[0]), value as _), + 2 => instrs::li16(atr(allocs[0]), value as _), + 4 => instrs::li32(atr(allocs[0]), value as _), + _ => instrs::li64(atr(allocs[0]), value as _), + }), Kind::Extend => { let base = fuc.nodes[node.inputs[1]].ty; let dest = node.ty;