Skip to content

Commit 9493353

Browse files
committed
Address most of Jame's review comments
1 parent fc3f575 commit 9493353

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

src/AST.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,6 @@ data ModuleImplementation = ModuleImplementation {
16001600
modKnownProcs:: Map Ident (Set ProcSpec), -- ^Procs visible to this module
16011601
modForeignObjects:: Set FilePath, -- ^Foreign object files used
16021602
modForeignLibs:: Set String -- ^Foreign libraries used
1603-
-- modLLVM :: Maybe LLVMAST.Module -- ^Module's LLVM representation
16041603
} deriving (Generic)
16051604

16061605
emptyImplementation :: ModuleImplementation
@@ -3432,17 +3431,17 @@ argIsVar ArgVar{} = True
34323431
argIsVar _ = False
34333432

34343433

3435-
-- | Test if a PrimArg is a compile-time constant.
3434+
-- | Test if a PrimArg is a compile-time constant. This can include a
3435+
-- compile-time constant pointer to mutable memory, so it doesn't mean
3436+
-- *recursively* constant.
34363437
argIsConst :: PrimArg -> Bool
34373438
argIsConst ArgVar{} = False
34383439
argIsConst ArgInt{} = True
34393440
argIsConst ArgFloat{} = True
34403441
argIsConst ArgString{} = True
34413442
argIsConst ArgChar{} = True
34423443
argIsConst (ArgClosure _ as _) = all argIsConst as
3443-
-- XXX Should we consider globals to be constants, since they are compile-time
3444-
-- constant pointers, even if what they point to might not be constant?
3445-
argIsConst ArgGlobal{} = False
3444+
argIsConst ArgGlobal{} = True
34463445
argIsConst ArgUnneeded{} = True
34473446
argIsConst ArgUndef{} = False
34483447

src/AliasAnalysis.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,11 @@ _maybeAliasPrimArgs args = do
344344
ArgGlobal global ty -> maybeAddressAlias arg ty $ AliasByGlobal global
345345
_ -> return Nothing
346346
maybeAddressAlias arg ty item = do
347-
isPhantom <- argIsPhantom arg
347+
-- isPhantom <- argIsPhantom arg
348348
rep <- lookupTypeRepresentation ty
349349
-- Only Pointer type will create alias
350-
if not isPhantom && rep == Just Pointer
350+
-- if not isPhantom && rep == Just Pointer
351+
if rep == Just Pointer
351352
then return $ Just item
352353
else return Nothing
353354

src/Emit.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import Config (objectExtension, bitcodeExtension,
2222
llvmToObjectCommand,
2323
removeLPVMSection)
2424
import Control.Monad ( (>=>), unless )
25-
import Control.Monad.Trans (liftIO)
25+
import Control.Monad.Trans (liftIO, lift)
2626
import Control.Monad.Trans.Except
2727
import Control.Monad.Trans.State
2828
import qualified Data.ByteString as BS
@@ -42,7 +42,7 @@ import System.IO (openFile, hClose, Handle,
4242
IOMode (WriteMode), hPutStrLn)
4343
import System.Process (proc, readCreateProcessWithExitCode)
4444
import System.FilePath ((-<.>))
45-
import System.Directory (getPermissions, writable, doesFileExist)
45+
import System.Directory (getPermissions, writable, doesFileExist, removeFile)
4646
import Util (createLocalCacheFile)
4747
import LLVM
4848
import Data.String
@@ -86,6 +86,7 @@ emitObjectFile m f = do
8686
liftIO $ createLocalCacheFile filename
8787
let (cmd,cmdLine) = llvmToObjectCommand llFilename filename userOptions
8888
runOSCmd cmd cmdLine
89+
lift $ removeFile llFilename
8990

9091

9192
-- | With the LLVM AST representation of a LPVM Module, create a
@@ -99,10 +100,11 @@ emitBitcodeFile m f = do
99100
userOptions <- gets options
100101
let (cmd,cmdLine) = llvmToBitcodeCommand llFilename filename userOptions
101102
runOSCmd cmd cmdLine
103+
lift $ removeFile llFilename
102104

103105

104-
-- | With the LLVM AST representation of a LPVM Module, create a target LLVM
105-
-- Assembly file. This function forms the basis for all LLVM code generation.
106+
-- | Create a target LLVM Assembly (.ll) file. This function forms the basis
107+
-- for all LLVM code generation.
106108
emitAssemblyFile :: ModSpec -> FilePath -> Compiler FilePath
107109
emitAssemblyFile m f = do
108110
let filename = f -<.> Config.assemblyExtension

src/LLVM.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ instance Show StaticConstSpec where
288288
show (ClosureSpec pspec args) = show pspec ++ showArguments args
289289

290290

291-
-- | If the specified PrimArg is a string constant, add it to the set. For Wybe
292-
-- strings, add both the Wybe string and the C string, since the Wybe string
293-
-- constant refers to the C string.
291+
-- | If the specified PrimArg is a string constant or closure with only constant
292+
-- arguments, add it to the set. For Wybe strings, add both the Wybe string and
293+
-- the C string, since the Wybe string constant refers to the C string.
294294
prescanArg :: PrimArg -> LLVM ()
295295
prescanArg (ArgString str WybeString _) = do
296296
recordConst $ WybeStringSpec str
@@ -755,9 +755,9 @@ writeWybeCall wybeProc args pos = do
755755
(ins,outs,oRefs,iRefs) <- partitionArgsWithRefs args
756756
unless (List.null iRefs)
757757
$ shouldnt $ "Wybe call " ++ show wybeProc ++ " with take-reference arg"
758-
prefix <- tailMarker False
758+
tailKind <- tailMarker False
759759
if List.null oRefs then
760-
writeActualCall wybeProc ins outs prefix
760+
writeActualCall wybeProc ins outs tailKind
761761
else
762762
deferCall wybeProc ins outs oRefs
763763

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def foo(x:T) use !io {
2-
?l = [x]
3-
!println(length(l))
4-
}
1+
# def foo(x:T) use !io {
2+
# ?l = [x]
3+
# !println(length(l))
4+
# }
55

6-
!foo(1)
7-
!foo(true)
8-
!foo(1.0)
9-
?x = 1.0; !foo(x)
6+
# !foo(1)
7+
# !foo(true)
8+
# !foo(1.0)
9+
# ?x = 1.0; !foo(x)
1010

1111
def {test} foo2(x:T0, ?y:T0) {
1212
?l = [x]
@@ -15,7 +15,8 @@ def {test} foo2(x:T0, ?y:T0) {
1515

1616
if {foo2(42, ?y) :: !println(y)}
1717
?i = 42; if {foo2(i, ?y) :: !println(y)}
18-
?f = 1.0; if {foo2(f, ?fx) :: !println(fx)}
18+
?f = 1.0; if {foo2(f, ?fx) :: !println(fx)
19+
| else :: !println "foo2 fails!"}
1920
if {foo2(1.0, ?x) :: !println(x)}
2021
if {foo2('a', ?z) :: !println(z)}
2122
if {foo2(false, ?b) :: !println(b)}

0 commit comments

Comments
 (0)