From 9f037095653425bf80a50f27532c0f2928dbeebe Mon Sep 17 00:00:00 2001 From: Oriol Linan Date: Tue, 7 Jan 2025 21:53:21 +0100 Subject: [PATCH 1/2] fix: spacing issue with parse `If` --- lib/Ast/Parser/Expr.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Ast/Parser/Expr.hs b/lib/Ast/Parser/Expr.hs index 4dfa83f..971ea68 100644 --- a/lib/Ast/Parser/Expr.hs +++ b/lib/Ast/Parser/Expr.hs @@ -88,7 +88,7 @@ parseCall = do parseIf :: PU.Parser AT.Expr parseIf = do - cond <- PU.symbol "if" *> parseExpr + cond <- PU.symbol "if" *> PU.lexeme parseExpr then' <- parseBlock else' <- M.optional $ PU.symbol "else" *> parseBlock srcLoc <- parseSrcLoc From 71900723a5ea046f335ed986c424f5d5b68b98b5 Mon Sep 17 00:00:00 2001 From: Javier R Date: Wed, 8 Jan 2025 12:25:21 +0100 Subject: [PATCH 2/2] fix: `br` overriding `ret` instruction and `phi` nodes --- lib/Codegen/Codegen.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Codegen/Codegen.hs b/lib/Codegen/Codegen.hs index cd6cab4..92c3a7e 100644 --- a/lib/Codegen/Codegen.hs +++ b/lib/Codegen/Codegen.hs @@ -310,17 +310,25 @@ generateIf (AT.If _ cond then_ else_) = mdo thenBlock <- IRM.block `IRM.named` U.stringToByteString "if.then" thenValue <- generateExpr then_ - I.br mergeBB + + case TD.typeOf thenValue of + T.VoidType -> I.br mergeBB + _ -> pure () elseBlock <- IRM.block `IRM.named` U.stringToByteString "if.else" elseValue <- case else_ of Just e -> generateExpr e Nothing -> pure $ AST.ConstantOperand $ C.Undef T.void - I.br mergeBB + + case TD.typeOf elseValue of + T.VoidType -> I.br mergeBB + _ -> pure () mergeBB <- IRM.block `IRM.named` U.stringToByteString "if.merge" - I.phi [(thenValue, thenBlock), (elseValue, elseBlock)] + case TD.typeOf elseValue of + T.VoidType -> I.phi [(thenValue, elseBlock)] + _ -> I.phi [(thenValue, thenBlock), (elseValue, elseBlock)] generateIf expr = E.throwError $ CodegenError (U.getLoc expr) $ UnsupportedDefinition expr