From a24c5353a58d486178c8d67989cc4a1acde3b144 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Thu, 3 Jul 2025 16:56:32 +0200 Subject: [PATCH] Add compilation method for IR-IF --- .../backend/code-generator.lisp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp index 4186b64..c06059e 100644 --- a/wip-duuqnd/user-side-compiler/backend/code-generator.lisp +++ b/wip-duuqnd/user-side-compiler/backend/code-generator.lisp @@ -191,6 +191,21 @@ :byte-length 3)) (setf *last-instruction* '(:jump))) +(defmethod compile-ir ((inst ir-if)) + (let ((next-iblock (next (iblock inst))) + (then-iblock (first (destinations inst))) + (else-iblock (second (destinations inst)))) + ;; With how the midstage is built, the true case's block comes immediately + ;; after the IF, and therefore we should branch on false. This assert + ;; ensures that this assumption become false without us noticing. + ;; We implicitly fall through to THEN-BLOCK in the event of no branch. + (assert (eql next-iblock then-iblock)) + (emit-load-bool (input inst)) + (emit-asm-instruction :opcode #xD0 + :operand else-iblock + :byte-length 2) + (setf *last-instruction* '(:conditional)))) + (defmethod compile-ir ((inst ir-test-equal)) (emit-load-data (first (inputs inst))) (if (eql (strategy (allocation-details (second (inputs inst))))