Rain: implemented the pass to record the types of integer literals
This commit is contained in:
parent
97cc82e235
commit
bad3f0818a
|
@ -40,7 +40,11 @@ rainPasses =
|
||||||
[ ("AST Validity check, Rain #1", excludeNonRainFeatures)
|
[ ("AST Validity check, Rain #1", excludeNonRainFeatures)
|
||||||
,("Resolve Int -> Int64",transformInt)
|
,("Resolve Int -> Int64",transformInt)
|
||||||
,("Uniquify variable declarations, record declared types and resolve variable names",uniquifyAndResolveVars) --depends on transformInt
|
,("Uniquify variable declarations, record declared types and resolve variable names",uniquifyAndResolveVars) --depends on transformInt
|
||||||
,("Record inferred name types in dictionary",recordInfNameTypes) --depends on uniquifyAndResolveVars
|
|
||||||
|
,("Fold all constant expressions",constantFoldPass) -- depends on transformInt and possibly depends on uniquifyAndResolveVars, not sure
|
||||||
|
,("Annotate integer literal types",annnotateIntLiteralTypes) --depends on transformInt and constantFoldPass
|
||||||
|
|
||||||
|
,("Record inferred name types in dictionary",recordInfNameTypes) --depends on uniquifyAndResolveVars and annnotateIntLiteralTypes
|
||||||
,("Find and tag the main function",findMain) --depends on uniquifyAndResolveVars
|
,("Find and tag the main function",findMain) --depends on uniquifyAndResolveVars
|
||||||
,("Check parameters in process calls",matchParamPass) --depends on uniquifyAndResolveVars and recordInfNameTypes
|
,("Check parameters in process calls",matchParamPass) --depends on uniquifyAndResolveVars and recordInfNameTypes
|
||||||
,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",transformEachRange)
|
,("Convert seqeach/pareach loops over ranges into simple replicated SEQ/PAR",transformEachRange)
|
||||||
|
|
|
@ -69,4 +69,25 @@ annnotateIntLiteralTypes :: Data t => t -> PassM t
|
||||||
annnotateIntLiteralTypes = everywhereASTM doExpression
|
annnotateIntLiteralTypes = everywhereASTM doExpression
|
||||||
where
|
where
|
||||||
doExpression :: A.Expression -> PassM A.Expression
|
doExpression :: A.Expression -> PassM A.Expression
|
||||||
doExpression = return
|
doExpression (A.Literal m t (A.IntLiteral m' s))
|
||||||
|
= do t' <-
|
||||||
|
if (t == A.Int64) then --it's a signed literal
|
||||||
|
(if (n >= 2^63 || n < (-(2^63)))
|
||||||
|
then dieP m $ "Signed integer literal too large to fit into 64 bits: " ++ s
|
||||||
|
else
|
||||||
|
if (n < (-(2^31)) || n >= 2^31)
|
||||||
|
then return A.Int64
|
||||||
|
else
|
||||||
|
if (n < (-(2^15)) || n >= 2^15)
|
||||||
|
then return A.Int32
|
||||||
|
else
|
||||||
|
if (n < (-(2^7)) || n >= 2^7)
|
||||||
|
then return A.Int16
|
||||||
|
else return A.Int8
|
||||||
|
)
|
||||||
|
else
|
||||||
|
dieP m $ "Unsigned literals currently unsupported"
|
||||||
|
return $ A.Literal m t' (A.IntLiteral m' s)
|
||||||
|
where
|
||||||
|
n = read s
|
||||||
|
doExpression e = return e
|
||||||
|
|
Loading…
Reference in New Issue
Block a user