From fd64a7e669e9cdc811f0c95a204505967826dbce Mon Sep 17 00:00:00 2001 From: Samuel Hammersberg Date: Tue, 24 Jan 2023 11:38:33 +0100 Subject: [PATCH] Added a function to load the Standard LLVM library at runtime. --- language.cabal | 2 ++ src/Compiler/StandardLLVMLibrary.hs | 10 +++++++--- src/Compiler/TH.hs | 10 ++++++++++ {test => src/Compiler}/standard_library.ll | 0 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/Compiler/TH.hs rename {test => src/Compiler}/standard_library.ll (100%) diff --git a/language.cabal b/language.cabal index caf05d9..7a9c2f8 100644 --- a/language.cabal +++ b/language.cabal @@ -32,6 +32,7 @@ executable language Grammar.Skel Compiler.Compiler Compiler.StandardLLVMLibrary + Compiler.TH Interpreter hs-source-dirs: src @@ -42,5 +43,6 @@ executable language , containers , either , array + , template-haskell default-language: GHC2021 diff --git a/src/Compiler/StandardLLVMLibrary.hs b/src/Compiler/StandardLLVMLibrary.hs index 4672f5c..1b8c2da 100644 --- a/src/Compiler/StandardLLVMLibrary.hs +++ b/src/Compiler/StandardLLVMLibrary.hs @@ -1,6 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} module Compiler.StandardLLVMLibrary where +import Control.Monad +import Language.Haskell.TH +import Compiler.TH + +-- $(genCurries 8) standardLLVMLibrary :: String -standardLLVMLibrary = " - -" \ No newline at end of file +standardLLVMLibrary = $(includeStr "src/Compiler/standard_library.ll") diff --git a/src/Compiler/TH.hs b/src/Compiler/TH.hs new file mode 100644 index 0000000..497cbc7 --- /dev/null +++ b/src/Compiler/TH.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} +module Compiler.TH where +import Control.Monad +import Language.Haskell.TH +import System.IO.Unsafe(unsafePerformIO) + +includeStr :: String -> Q Exp +includeStr file = do + let res = unsafePerformIO $ readFile file + [|res|] \ No newline at end of file diff --git a/test/standard_library.ll b/src/Compiler/standard_library.ll similarity index 100% rename from test/standard_library.ll rename to src/Compiler/standard_library.ll