[project @ 2000-01-24 17:24:23 by sewardj]
[ghc-hetmet.git] / ghc / compiler / nativeGen / MachMisc.lhs
index 16fa5fd..d72de13 100644 (file)
@@ -18,9 +18,10 @@ module MachMisc (
 
        underscorePrefix,
        fmtAsmLbl,
-       cvtLitLit,
        exactLog2,
 
+        stixFor_stdout, stixFor_stderr, stixFor_stdin,
+
        Instr(..),  IF_ARCH_i386(Operand(..) COMMA,)
        Cond(..),
        Size(..)
@@ -36,7 +37,7 @@ module MachMisc (
     ) where
 
 #include "HsVersions.h"
---#include "config.h"
+-- #include "config.h"
 
 import AbsCSyn         ( MagicId(..) ) 
 import AbsCUtils       ( magicIdPrimRep )
@@ -52,6 +53,7 @@ import Stix           ( StixTree(..), StixReg(..), CodeSegment )
 import Panic           ( panic )
 import Char            ( isDigit )
 import GlaExts         ( word2Int#, int2Word#, shiftRL#, and#, (/=#) )
+import Outputable      ( text )
 \end{code}
 
 \begin{code}
@@ -78,6 +80,30 @@ fmtAsmLbl s
      )
 
 ---------------------------
+stixFor_stdout, stixFor_stderr, stixFor_stdin :: StixTree
+#if i386_TARGET_ARCH
+-- Linux glibc 2 / libc6
+stixFor_stdout  = StInd PtrRep (StLitLbl (text "stdout"))
+stixFor_stderr  = StInd PtrRep (StLitLbl (text "stderr"))
+stixFor_stdin   = StInd PtrRep (StLitLbl (text "stdin"))
+#endif
+
+#if alpha_TARGET_ARCH
+stixFor_stdout = error "stixFor_stdout: not implemented for Alpha"
+stixFor_stderr = error "stixFor_stderr: not implemented for Alpha"
+stixFor_stdin  = error "stixFor_stdin: not implemented for Alpha"
+#endif
+
+#if sparc_TARGET_ARCH
+stixFor_stdout = error "stixFor_stdout: not implemented for Sparc"
+stixFor_stderr = error "stixFor_stderr: not implemented for Sparc"
+stixFor_stdin  = error "stixFor_stdin: not implemented for Sparc"
+#endif
+
+#if 0
+Here's some old stuff from which it shouldn't be too hard to
+implement the above for Alpha/Sparc.
+
 cvtLitLit :: String -> String
 
 --
@@ -85,36 +111,20 @@ cvtLitLit :: String -> String
 -- _iob offsets.
 --
 cvtLitLit "stdin"  = IF_ARCH_alpha("_iob+0" {-probably OK...-}
-                   ,IF_ARCH_i386("_IO_stdin_"
+                   ,IF_ARCH_i386("stdin"
                    ,IF_ARCH_sparc("__iob+0x0"{-probably OK...-}
                    ,)))
 
 cvtLitLit "stdout" = IF_ARCH_alpha("_iob+"++show (``FILE_SIZE''::Int)
-                   ,IF_ARCH_i386("_IO_stdout_"
+                   ,IF_ARCH_i386("stdout"
                    ,IF_ARCH_sparc("__iob+"++show (``FILE_SIZE''::Int)
                    ,)))
 cvtLitLit "stderr" = IF_ARCH_alpha("_iob+"++show (2*(``FILE_SIZE''::Int))
-                   ,IF_ARCH_i386("_IO_stderr_"
+                   ,IF_ARCH_i386("stderr"
                    ,IF_ARCH_sparc("__iob+"++show (2*(``FILE_SIZE''::Int))
                    ,)))
-{-
-cvtLitLit "stdout" = IF_ARCH_alpha("_iob+56"{-dodgy *at best*...-}
-                   ,IF_ARCH_i386("_IO_stdout_"
-                   ,IF_ARCH_sparc("__iob+0x10"{-dodgy *at best*...-}
-                   ,)))
-cvtLitLit "stderr" = IF_ARCH_alpha("_iob+112"{-dodgy *at best*...-}
-                   ,IF_ARCH_i386("_IO_stderr_"
-                   ,IF_ARCH_sparc("__iob+0x20"{-dodgy *at best*...-}
-                   ,)))
--}
-cvtLitLit s
-  | isHex s   = s
-  | otherwise = error ("Native code generator can't handle ``" ++ s ++ "''")
-  where
-    isHex ('0':'x':xs) = all isHexDigit xs
-    isHex _ = False
-    -- Now, where have I seen this before?
-    isHexDigit c = isDigit c || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'
+#endif
+
 \end{code}
 
 % ----------------------------------------------------------------
@@ -465,49 +475,34 @@ data RI
 
 -- Float Arithmetic. -- ToDo for 386
 
--- Note that we cheat by treating F{ABS,MOV,NEG} of doubles as single instructions
+-- Note that we cheat by treating G{ABS,MOV,NEG} of doubles as single instructions
 -- right up until we spit them out.
 
-             | SAHF          -- stores ah into flags
-             | FABS
-             | FADD          Size Operand -- src
-             | FADDP
-             | FIADD         Size MachRegsAddr -- src
-             | FCHS
-             | FCOM          Size Operand -- src
-             | FCOS
-             | FDIV          Size Operand -- src
-             | FDIVP
-             | FIDIV         Size MachRegsAddr -- src
-             | FDIVR         Size Operand -- src
-             | FDIVRP
-             | FIDIVR        Size MachRegsAddr -- src
-             | FICOM         Size MachRegsAddr -- src
-             | FILD          Size MachRegsAddr Reg -- src, dst
-             | FIST          Size MachRegsAddr -- dst
-             | FLD           Size Operand -- src
-             | FLD1
-             | FLDZ
-             | FMUL          Size Operand -- src
-             | FMULP
-             | FIMUL         Size MachRegsAddr -- src
-             | FRNDINT
-             | FSIN
-             | FSQRT
-             | FST           Size Operand -- dst
-             | FSTP          Size Operand -- dst
-             | FSUB          Size Operand -- src
-             | FSUBP
-             | FISUB         Size MachRegsAddr -- src
-             | FSUBR         Size Operand -- src
-             | FSUBRP
-             | FISUBR        Size MachRegsAddr -- src
-             | FTST
-             | FCOMP         Size Operand -- src
-             | FUCOMPP
-             | FXCH
-             | FNSTSW
-             | FNOP
+              -- all the 3-operand fake fp insns are src1 src2 dst
+              -- and furthermore are constrained to be fp regs only.
+             | GMOV          Reg Reg -- src(fpreg), dst(fpreg)
+              | GLD           Size MachRegsAddr Reg -- src, dst(fpreg)
+              | GST           Size Reg MachRegsAddr -- src(fpreg), dst
+
+             | GFTOD         Reg Reg -- src(fpreg), dst(fpreg)
+              | GFTOI         Reg Reg -- src(fpreg), dst(intreg)
+
+             | GDTOF         Reg Reg -- src(fpreg), dst(fpreg)
+              | GDTOI         Reg Reg -- src(fpreg), dst(intreg)
+
+              | GITOF         Reg Reg -- src(intreg), dst(fpreg)
+              | GITOD         Reg Reg -- src(intreg), dst(fpreg)
+
+             | GADD          Size Reg Reg Reg -- src1, src2, dst
+             | GDIV          Size Reg Reg Reg -- src1, src2, dst
+             | GSUB          Size Reg Reg Reg -- src1, src2, dst
+             | GMUL          Size Reg Reg Reg -- src1, src2, dst
+
+             | GCMP          Size Reg Reg -- src1, src2
+
+             | GABS          Size Reg Reg -- src, dst
+             | GNEG          Size Reg Reg -- src, dst
+             | GSQRT         Size Reg Reg -- src, dst
 
 -- Comparison
 
@@ -519,6 +514,8 @@ data RI
 
              | PUSH          Size Operand
              | POP           Size Operand
+             | PUSHA
+             | POPA
 
 -- Jumping around.