diff --git a/fco2/GenerateC.hs b/fco2/GenerateC.hs index 6a11ff1..7048cab 100644 --- a/fco2/GenerateC.hs +++ b/fco2/GenerateC.hs @@ -966,8 +966,17 @@ introduceSpec (A.Specification _ n (A.Retypes _ am t v)) = do origT <- typeOfVariable v let (rhs, rhsSizes) = abbrevVariable A.Abbrev origT v genDecl am t n - tell [" = ("] + tell [" = "] + -- For non-array types that are VAL abbreviations (e.g. VAL INT64), + -- we need to dereference the pointer that abbrevVariable gives us. + let deref = case (am, t) of + (_, A.Array _ _) -> False + (A.ValAbbrev, _) -> True + _ -> True + when deref $ tell ["*"] + tell ["("] genDeclType am t + when deref $ tell [" *"] tell [") "] rhs tell [";\n"] diff --git a/fco2/TODO b/fco2/TODO index 9641022..aff8fe9 100644 --- a/fco2/TODO +++ b/fco2/TODO @@ -46,6 +46,10 @@ default behaviour that simplifies expressions inside another one. Output item expressions should be pulled up to variables. +We should generally try to reduce the number of unnecessary pullups we do: +- plain subscripts that result in a non-array shouldn't pull up (e.g. x[i][j]) +- expressions that are already a variable should just be turned into the variable + Before code generation, have a pass that resolves all the DATA TYPE .. IS directives to their real types. diff --git a/fco2/testcases/place.occ b/fco2/testcases/place.occ new file mode 100644 index 0000000..c853e16 --- /dev/null +++ b/fco2/testcases/place.occ @@ -0,0 +1,11 @@ +PROC P () + INT x: + PLACE x AT #123456: + CHAN OF INT c: + PLACE c AT #654321: + INT w: + PLACE w IN WORKSPACE: + INT v: + PLACE v IN VECSPACE: + SKIP +: diff --git a/fco2/testcases/val-retypes2.occ b/fco2/testcases/val-retypes2.occ new file mode 100644 index 0000000..17555db --- /dev/null +++ b/fco2/testcases/val-retypes2.occ @@ -0,0 +1,26 @@ +-- from cgtest10 +PROC check.REAL64 (VAL REAL64 a, b, VAL []BYTE s) + ASSERT (a = b) +: +PROC check.INT64 (VAL INT64 a, b, VAL []BYTE s) + ASSERT (a = b) +: +PROC P () + VAL xr IS 8.6157349597130242515E+1(REAL64) : + VAL yr IS 4.1066306682575781263E+1(REAL64) : + VAL xi IS #40558A12040B6DA5(INT64) : + VAL yi IS #4044887CBCC495A9(INT64) : + VAL REAL64 xir RETYPES xi : + VAL REAL64 yir RETYPES yi : + REAL64 x, y : + SEQ + x, y := xr, yr + check.REAL64(xr, xir, "B251a") + check.REAL64(yr, yir, "B251b") + check.REAL64(x, xir, "B251c") + check.REAL64(y, yir, "B251d") + VAL INT64 xx RETYPES x : + check.INT64(xx, xi, "B251e") + VAL INT64 yy RETYPES y : + check.INT64(yy, yi, "B251f") +: