Compare commits

...

6 Commits

Author SHA1 Message Date
5d9b956883
Call codegen and write LLVM output to output file 2024-12-09 20:30:01 -05:00
892658de78
Create CodeGen module 2024-12-09 20:29:04 -05:00
898160d611
Add string-conversions package 2024-12-09 20:23:56 -05:00
2819b7fc57
Take in input/output file args 2024-12-09 20:19:31 -05:00
37cf2fe339
Add llvm-hs-pretty package
Fix prettyprinter version conflict
2024-12-09 20:09:13 -05:00
d558831984
Add output files to gitignore 2024-12-09 20:03:56 -05:00
7 changed files with 45 additions and 8 deletions

4
.gitignore vendored
View File

@ -21,3 +21,7 @@ cabal.project.local
cabal.project.local~ cabal.project.local~
.HTF/ .HTF/
.ghc.environment.* .ghc.environment.*
# Windows12 output files
*.ll
*.s

7
cabal.project Normal file
View File

@ -0,0 +1,7 @@
-- Needed to get a working version of llvm-hs-pretty
-- The one on hackage is broken with this version of GHC
source-repository-package
type: git
location: https://github.com/rumkeller/llvm-hs-pretty.git
packages: ./windows12.cabal

View File

@ -3,13 +3,27 @@
module Main where module Main where
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import Prettyprinter import qualified Data.Text.Lazy.IO as TL
import Data.Text.Lazy (toStrict, unpack)
import Data.String.Conversions (cs)
import Data.Text.Prettyprint.Doc (pretty)
import Text.Megaparsec (parse) import Text.Megaparsec (parse)
import Windows12.Parser (programP) import Windows12.Parser (programP)
import System.Environment (getArgs)
import LLVM.Pretty
import Windows12.Ast
import Windows12.CodeGen (codegen)
main :: IO () main :: IO ()
main = do main = do
test <- T.readFile "test/hello.w12" args <- getArgs
case parse programP "test/hello.w12" test of
Left err -> print err if length args /= 2
Right ast -> print (pretty ast) then putStrLn "Usage: windows12 <input file> <output file>"
else do
let [inputFile, outputFile] = args
test <- T.readFile inputFile
case parse programP inputFile test of
Left err -> print err
Right ast -> TL.writeFile outputFile (ppllvm (codegen (cs inputFile) ast))

View File

@ -2,4 +2,5 @@ module Windows12 where
import Windows12.Ast import Windows12.Ast
import Windows12.Lexer import Windows12.Lexer
import Windows12.Parser import Windows12.Parser
import Windows12.CodeGen

View File

@ -3,7 +3,7 @@
module Windows12.Ast where module Windows12.Ast where
import Data.Text (Text) import Data.Text (Text)
import Prettyprinter import Data.Text.Prettyprint.Doc
data BinOp data BinOp
= Add = Add

8
src/Windows12/CodeGen.hs Normal file
View File

@ -0,0 +1,8 @@
module Windows12.CodeGen where
import Data.Text (Text)
import Windows12.Ast
import LLVM.AST (Module)
codegen :: Text -> Program -> Module
codegen filename (Program structs enums funcs) = undefined

View File

@ -68,6 +68,7 @@ executable windows12
Windows12.Ast Windows12.Ast
Windows12.Lexer Windows12.Lexer
Windows12.Parser Windows12.Parser
Windows12.CodeGen
-- LANGUAGE extensions used by modules in this package. -- LANGUAGE extensions used by modules in this package.
-- other-extensions: -- other-extensions:
@ -76,10 +77,12 @@ executable windows12
build-depends: build-depends:
base >= 4.15.1 && < 4.16, base >= 4.15.1 && < 4.16,
llvm-hs-pure >= 9.0.0 && < 9.1, llvm-hs-pure >= 9.0.0 && < 9.1,
llvm-hs-pretty >= 0.9.0 && < 0.10,
megaparsec >= 9.6.1 && < 9.7, megaparsec >= 9.6.1 && < 9.7,
text >= 1.2.5 && < 1.3, text >= 1.2.5 && < 1.3,
parser-combinators >= 1.3.0 && < 1.4, parser-combinators >= 1.3.0 && < 1.4,
prettyprinter >= 1.7.1 && < 1.8, prettyprinter >= 1.5.1 && < 1.6,
string-conversions >= 0.4.0 && < 0.5
-- Directories containing source files. -- Directories containing source files.
hs-source-dirs: src hs-source-dirs: src