Skip to content

Commit

Permalink
Merge branch '103-parse-expr' of github.com:EpitechPromo2027/B-FUN-50…
Browse files Browse the repository at this point in the history
…0-BAR-5-2-glados-oriol.linan into 103-parse-expr
  • Loading branch information
oriollinan committed Jan 9, 2025
2 parents b920e87 + 939c009 commit 6a59e6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Ast/Parser/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ parseCall = do
parseIf :: PU.Parser AT.Expr
parseIf = do
srcLoc <- PU.parseSrcLoc
cond <- PU.symbol "if" *> parseExpr
cond <- PU.symbol "if" *> PU.lexeme parseExpr
then' <- parseBlock
else' <- M.optional $ PU.symbol "else" *> parseBlock
return $ AT.If {AT.ifLoc = srcLoc, AT.ifCond = cond, AT.ifThen = then', AT.ifElse = else'}
Expand Down
14 changes: 11 additions & 3 deletions lib/Codegen/Codegen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6a59e6b

Please # to comment.