diff options
| author | Eugen Wissner <belka@caraus.de> | 2024-09-08 02:08:13 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2024-09-08 02:08:13 +0200 |
| commit | 1cbbef19afcf997315431e3aa45f824fe8a8a0e7 (patch) | |
| tree | 8813df9aab3185a9c2b778499ecb041a6c58cead /src/Main.hs | |
| parent | a625bbff505c912f8a19f62bcb92313a63c60ed4 (diff) | |
| download | elna-1cbbef19afcf997315431e3aa45f824fe8a8a0e7.tar.gz | |
Stub the implementation for all phases
Diffstat (limited to 'src/Main.hs')
| -rw-r--r-- | src/Main.hs | 91 |
1 files changed, 23 insertions, 68 deletions
diff --git a/src/Main.hs b/src/Main.hs index 4d5e406..872cad9 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -3,78 +3,33 @@ module Main ) where import Language.Elna.CommandLine (CommandLine(..), commandLine, execParser) -import Language.Elna.Object.Elf - ( Elf32_Ehdr(..) - , ElfMachine(..) - , ElfType(..) - , ElfVersion(..) - , ElfIdentification(..) - , ElfClass(..) - , ElfData(..) - , Elf32_Shdr(..) - , ElfSectionType(..) - , elfHeaderSize - , elfObject - ) -import qualified Data.ByteString as ByteString -import Data.Vector (Vector) -import qualified Data.Vector as Vector +import Language.Elna.PrinterWriter (riscv32Elf, riscv32Header) +import Language.Elna.Object.Elf (elfObject) +import Language.Elna.Parser (programP) +import Language.Elna.NameAnalysis (nameAnalysis) +import Language.Elna.TypeAnalysis (typeAnalysis) +import Language.Elna.Intermediate (intermediate) +import Language.Elna.CodeGenerator (generateCode) import Data.Maybe (fromMaybe) -import System.IO (Handle) import System.FilePath (replaceExtension, takeFileName) - -riscv32Elf :: Handle -> IO (Vector Elf32_Shdr) -riscv32Elf objectHandle = - let stringTable = "\0shstrtab\0" - written = Vector.fromList - [ Elf32_Shdr - { sh_type = SHT_NULL - , sh_size = 0 - , sh_offset = 0 - , sh_name = 0 - , sh_link = 0 - , sh_info = 0 - , sh_flags = 0 - , sh_entsize = 0 - , sh_addralign = 0 - , sh_addr = 0 - } - , Elf32_Shdr - { sh_type = SHT_STRTAB - , sh_size = fromIntegral $ ByteString.length stringTable - , sh_offset = fromIntegral elfHeaderSize - , sh_name = 1 - , sh_link = 0 - , sh_info = 0 - , sh_flags = 0 - , sh_entsize = 0 - , sh_addralign = 0 - , sh_addr = 0 - } - ] - in ByteString.hPut objectHandle stringTable >> pure written - -riscv32Header :: Elf32_Ehdr -riscv32Header = Elf32_Ehdr - { e_version = EV_CURRENT - , e_type = ET_REL - , e_shstrndx = 1 -- String table. SHN_UNDEF - , e_shoff = 0 - , e_shnum = 2 - , e_shentsize = 40 - , e_phoff = 0 - , e_phnum = 0 - , e_phentsize = 32 - , e_machine = EM_RISCV - , e_ident = ElfIdentification ELFCLASS32 ELFDATA2LSB - , e_flags = 0x4 -- EF_RISCV_FLOAT_ABI_DOUBLE - , e_entry = 0 - , e_ehsize = fromIntegral elfHeaderSize - } +import Text.Megaparsec (runParser, errorBundlePretty) +import qualified Data.Text.IO as Text main :: IO () main = execParser commandLine >>= withCommandLine where withCommandLine CommandLine{..} = - let defaultOutput = replaceExtension (takeFileName input) "o" - in elfObject (fromMaybe defaultOutput output) riscv32Header riscv32Elf + let defaultOutput = flip fromMaybe output + $ replaceExtension (takeFileName input) "o" + in Text.readFile input + >>= withParsedInput defaultOutput + . runParser programP input + withParsedInput output (Right program) = + let symbolTable = nameAnalysis program + _ = typeAnalysis symbolTable program + intermediate' = intermediate symbolTable program + in elfObject output riscv32Header + $ riscv32Elf + $ generateCode symbolTable intermediate' + withParsedInput _ (Left errorBundle) = putStrLn + $ errorBundlePretty errorBundle |
