-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dunor
committed
Aug 10, 2023
1 parent
6f7be13
commit 635b59c
Showing
18 changed files
with
293 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# t-lang bootstrap compiler | ||
# bootstrap compiler from GHC | ||
|
||
Please see ./src/Compiler/README.md for design of compiler pipeline. | ||
|
||
Documents are under construction. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{- | a helper module which provides many common codegen pattern with | ||
-- carefully designed environment. | ||
-- | ||
-} | ||
module Compiler.Backend.LLVM.Runtime | ||
( | ||
wrapMain | ||
) | ||
where | ||
|
||
import Compiler.Backend.LLVM.Definition | ||
import Compiler.Backend.LLVM.IR (ensureNamedBlock, ensureBlockEndWith) | ||
import qualified LLVM.AST as LLVM | ||
import qualified LLVM.AST.Type as LLVM | ||
import qualified LLVM.AST.Typed as LLVM | ||
import qualified LLVM.AST.Constant as LLVM | ||
import Data.String (IsString) | ||
|
||
-- | make a main function as execution environment for generated code. | ||
wrapMain :: (MonadLLVMBuilder m, IsString name) => ([(name, (LLVM.Type, LLVM.Operand))] -> m LLVM.Operand) -> m LLVM.Operand | ||
wrapMain make = globalFunction "main" [(LLVM.i32, Just "argc"), (LLVM.ptr, Just "argv")] LLVM.i32 \case | ||
[argc, argv] -> do | ||
ensureNamedBlock "main.start" -- create start block | ||
r <- make [("argc", (LLVM.i32, argc)), ("argv", (LLVM.ptr, argv))] | ||
-- create ending block | ||
LLVM.typeOf r >>= \case | ||
Right (LLVM.IntegerType 32) -> ensureBlockEndWith (LLVM.Do $ LLVM.Ret (Just r) []) | ||
_ -> ensureBlockEndWith . LLVM.Do $ LLVM.Ret (Just $ LLVM.ConstantOperand $ LLVM.Int 32 0) [] | ||
_ -> error "impossible when building wrapper for main function" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{- | name checking stage | ||
-- | ||
-- this module provides functionality of converting raw surface module into | ||
-- wellformed surface module, which can be used as inputs in the next compiler pipeline. | ||
-- | ||
-- generally speaking, we will check validity of names in source code and rename them to | ||
-- avoid name collision. | ||
-} | ||
module Compiler.NameChecking | ||
( | ||
NamePrefix (..) | ||
) | ||
where | ||
|
||
data NamePrefix | ||
-- | variable in type level | ||
= NameTypeVariable | ||
-- | variable in term level, consumed | ||
| NameTermVariable | ||
-- | variable in pattern, introduced | ||
| NameBindingVariable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.