Fixed the constant folding to use a type for Int based on the compilation target rather than just assuming Int32

However, it is possible that there will still be a problem if the C and C++ compiler have different int sizes, because the constant folding has to know the type at compile time, and thus we have to arbitrarily choose to use the C version.  In future, we could perhaps swap all Ints for the appropriate substiution (e.g. Int64) at run-time, based on the flags and prior knowledge about C/C++ int sizes
This commit is contained in:
Neil Brown 2009-01-23 15:50:06 +00:00
parent 2a8ee9a420
commit 9145c993ea
3 changed files with 32 additions and 1 deletions

View File

@ -33,6 +33,7 @@ import qualified AST as A
import CompState hiding (CSM) -- everything here is read-only
import Errors
import Metadata
import TypeSizes
type EvalM = ErrorT ErrorReport (StateT CompState Identity)
@ -48,7 +49,7 @@ data OccValue =
| OccUInt64 Word64
| OccInt8 Int8
| OccInt16 Int16
| OccInt Int32
| OccInt CIntReplacement
| OccInt32 Int32
| OccInt64 Int64
| OccArray [OccValue]

View File

@ -1,8 +1,17 @@
-- | This module is auto-generated by autoconf from TypeSizes.hs.in
module TypeSizes where
import Data.Int
import qualified AST as A
cBoolSize, cxxBoolSize, cIntSize, cxxIntSize :: Int
cBoolSize = @C_BOOL_SIZE@
cxxBoolSize = @CXX_BOOL_SIZE@
cIntSize = @C_INT_SIZE@
cxxIntSize = @CXX_INT_SIZE@
type CIntReplacement = @C_INT_EQUIV@
type CXXIntReplacement = @CXX_INT_EQUIV@
cIntReplacement, cXXIntReplacement :: A.Type
cIntReplacement = A.@C_INT_EQUIV@
cXXIntReplacement = A.@CXX_INT_EQUIV@

View File

@ -193,6 +193,27 @@ AC_CHECK_SIZEOF(int)
AC_COMPUTE_INT(C_INT_SIZE,SIZEOF_INT)
AC_SUBST(C_INT_SIZE)
if test "x$C_INT_SIZE" = "x2"; then
C_INT_EQUIV=Int16
fi
if test "x$C_INT_SIZE" = "x4"; then
C_INT_EQUIV=Int32
fi
if test "x$C_INT_SIZE" = "x8"; then
C_INT_EQUIV=Int64
fi
if test "x$CXX_INT_SIZE" = "x2"; then
CXX_INT_EQUIV=Int16
fi
if test "x$CXX_INT_SIZE" = "x4"; then
CXX_INT_EQUIV=Int32
fi
if test "x$CXX_INT_SIZE" = "x8"; then
CXX_INT_EQUIV=Int64
fi
AC_SUBST(C_INT_EQUIV)
AC_SUBST(CXX_INT_EQUIV)
CFLAGS="$CFLAGS $no_strict_overflow $no_tree_vrp"
# The reason for -fno-strict-overflow and -fno-tree-vrp above is that with the way I have implemented
# range checking, on GCC 4.3.2 (and probably other versions), GCC has