From 2db208c05e7f18e167ce9877fafd62c8c5901854 Mon Sep 17 00:00:00 2001 From: Artem Pelenitsyn Date: Thu, 20 Jun 2024 19:32:39 +0000 Subject: [PATCH] generate the main expression if not in the library mode --- gibbon-compiler/src/Gibbon/Common.hs | 9 +++++++++ gibbon-compiler/src/Gibbon/Compiler.hs | 9 --------- gibbon-compiler/src/Gibbon/Passes/Codegen.hs | 8 +++++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gibbon-compiler/src/Gibbon/Common.hs b/gibbon-compiler/src/Gibbon/Common.hs index c5cc1ed1..8ee342af 100644 --- a/gibbon-compiler/src/Gibbon/Common.hs +++ b/gibbon-compiler/src/Gibbon/Common.hs @@ -22,6 +22,7 @@ module Gibbon.Common -- * Gibbon configuration , Config(..), Input(..), Mode(..), Backend(..), defaultConfig , RunConfig(..), getRunConfig, defaultRunConfig, getGibbonConfig + , isBench, isLibrary -- * Misc helpers , SSModality(..), (#), (!!!), fragileZip, fragileZip', sdoc, ndoc, abbrv @@ -255,6 +256,14 @@ data Mode = ToParse -- ^ Parse and then stop | Library Var -- ^ Compile as a library, with its main entry point given. deriving (Show, Read, Eq, Ord) +isBench :: Mode -> Bool +isBench (Bench _) = True +isBench _ = False + +isLibrary :: Mode -> Bool +isLibrary (Library _) = True +isLibrary _ = False + -- | Compilation backend used data Backend = C | LLVM deriving (Show,Read,Eq,Ord) diff --git a/gibbon-compiler/src/Gibbon/Compiler.hs b/gibbon-compiler/src/Gibbon/Compiler.hs index 28c0fa53..3ad5c2e5 100644 --- a/gibbon-compiler/src/Gibbon/Compiler.hs +++ b/gibbon-compiler/src/Gibbon/Compiler.hs @@ -542,15 +542,6 @@ compilationCmd C config = (cc config) ++" -std=gnu11 " simpleWriteBarrier = gopt Opt_SimpleWriteBarrier dflags lazyPromote = gopt Opt_NoEagerPromote dflags --- | -isBench :: Mode -> Bool -isBench (Bench _) = True -isBench _ = False - -isLibrary :: Mode -> Bool -isLibrary (Library _) = True -isLibrary _ = False - -- | The debug level at which we start to call the interpreter on the program during compilation. interpDbgLevel :: Int interpDbgLevel = 5 diff --git a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs index c7fb538b..757213f2 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Codegen.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Codegen.hs @@ -189,7 +189,7 @@ sortFns (Prog _ _ funs mtal) = foldl go S.empty allTails -- | Compile a program to C code that has the side effect of the -- "gibbon_main" expression in that program. codegenProg :: Config -> Prog -> IO String -codegenProg cfg prg@(Prog info_tbl sym_tbl funs mtal) = +codegenProg cfg@Config{mode} prg@(Prog info_tbl sym_tbl funs mtal) = return (hashIncludes ++ pretty 80 (stack (map ppr defs))) where init_fun_env = foldr (\fn acc -> M.insert (funName fn) (map snd (funArgs fn), funRetTy fn) acc) M.empty funs @@ -200,9 +200,11 @@ codegenProg cfg prg@(Prog info_tbl sym_tbl funs mtal) = (prots,funs') <- (unzip . concat) <$> mapM codegenFun funs main_expr' <- main_expr let struct_tys = uniqueDicts $ S.toList $ harvestStructTys prg - return ((L.nub $ makeStructs struct_tys) ++ prots ++ + return ((L.nub $ makeStructs struct_tys) ++ + prots ++ [gibTypesEnum, initInfoTable info_tbl, initSymTable sym_tbl] ++ - funs' -- ++ [main_expr'] + funs' ++ + if isLibrary mode then [] else [main_expr'] ) main_expr :: PassM C.Definition