elna/src/Main.hs

40 lines
1.5 KiB
Haskell
Raw Normal View History

module Main
( main
) where
2024-07-21 16:15:17 +02:00
2024-09-05 23:18:48 +02:00
import Language.Elna.CommandLine (CommandLine(..), commandLine, execParser)
import Language.Elna.Object.ElfCoder (elfObject)
2024-10-02 22:56:15 +02:00
import Language.Elna.Backend.Allocator (allocate)
import Language.Elna.Glue (glue)
import Language.Elna.Frontend.NameAnalysis (nameAnalysis)
import Language.Elna.Frontend.Parser (programP)
import Language.Elna.Frontend.TypeAnalysis (typeAnalysis)
import Language.Elna.RiscV.CodeGenerator (generateRiscV, riscVConfiguration)
import Language.Elna.RiscV.ElfWriter (riscv32Elf)
2024-09-05 23:18:48 +02:00
import Data.Maybe (fromMaybe)
import System.FilePath (replaceExtension, takeFileName)
2024-09-08 02:08:13 +02:00
import Text.Megaparsec (runParser, errorBundlePretty)
import qualified Data.Text.IO as Text
main :: IO ()
2024-09-05 23:18:48 +02:00
main = execParser commandLine >>= withCommandLine
where
withCommandLine CommandLine{..} =
2024-09-08 02:08:13 +02:00
let defaultOutput = flip fromMaybe output
$ replaceExtension (takeFileName input) "o"
in Text.readFile input
>>= withParsedInput defaultOutput
. runParser programP input
withParsedInput output (Right program) =
2024-09-20 13:32:24 +02:00
either print (withSymbolTable output program)
$ nameAnalysis program
2024-09-08 02:08:13 +02:00
withParsedInput _ (Left errorBundle) = putStrLn
$ errorBundlePretty errorBundle
2024-09-20 13:32:24 +02:00
withSymbolTable output program symbolTable =
let _ = typeAnalysis symbolTable program
2024-10-01 00:02:19 +02:00
instructions = generateRiscV
$ allocate riscVConfiguration
2024-10-02 22:56:15 +02:00
$ glue symbolTable program
2024-09-20 13:32:24 +02:00
in elfObject output
$ riscv32Elf instructions