From 41f24fe983e9c10b8e900c97e6f61e44c5d572d8 Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Fri, 19 May 2000 09:29:08 +0000
Subject: [PATCH] [project @ 2000-05-19 09:29:08 by simonmar] Fix type casts w/
 CIndex assignments.  Should eliminate some warnings in via-C compilations.

---
 ghc/compiler/absCSyn/PprAbsC.lhs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/ghc/compiler/absCSyn/PprAbsC.lhs b/ghc/compiler/absCSyn/PprAbsC.lhs
index c90b9b4443c2..57135be9d1d3 100644
--- a/ghc/compiler/absCSyn/PprAbsC.lhs
+++ b/ghc/compiler/absCSyn/PprAbsC.lhs
@@ -1108,6 +1108,29 @@ pprAmode amode
   = ppr_amode amode
 \end{code}
 
+When we have an indirection through a CIndex, we have to be careful to
+get the type casts right.  
+
+this amode:
+
+	CVal (CIndex kind1 base offset) kind2
+
+means (in C speak): 
+	
+	*(kind2 *)((kind1 *)base + offset)
+
+That is, the indexing is done in units of kind1, but the resulting
+amode has kind2.
+
+\begin{code}
+ppr_amode (CVal reg_rel@(CIndex _ _ _) kind)
+  = case (pprRegRelative False{-no sign wanted-} reg_rel) of
+	(pp_reg, Nothing)     -> panic "ppr_amode: CIndex"
+	(pp_reg, Just offset) -> 
+	   hcat [ char '*', parens (pprPrimKind kind <> char '*'),
+		  parens (pp_reg <> char '+' <> offset) ]
+\end{code}
+
 Now the rest of the cases for ``workhorse'' @ppr_amode@:
 
 \begin{code}
-- 
GitLab