debug: remove #ifdef's and use dumb logger
authorBernhard Urban <lewurm@gmail.com>
Sat, 25 Aug 2012 19:06:03 +0000 (21:06 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sat, 25 Aug 2012 19:06:03 +0000 (21:06 +0200)
advantage:
- Haskell code, i.e. tools like hlint or ghc-mod don't have problems with
  processing the source files with CPP
- no (ugly?) old school CPP stuff

disadvantage:
- it's not really a printf thingy (maybe we'll be able to use it soon)

18 files changed:
.gitignore
HACKING
Makefile
Mate.hs
Mate/BasicBlocks.hs
Mate/ClassPool.hs
Mate/Debug.hs
Mate/GarbageAlloc.hs
Mate/MethodPool.hs
Mate/NativeMachine.hs
Mate/NativeSizes.hs
Mate/RegisterAllocation.hs
Mate/Strings.hs
Mate/Utilities.hs
Mate/X86CodeGen.hs
Mate/X86TrapHandling.hs
debug.h [deleted file]
ffi/trap.c

index d48b83db78856e970908ac4a43490596346c91fa..b382dfe4d7393b40e0754be88e82a331607c92f3 100644 (file)
@@ -5,6 +5,7 @@ mate
 mate.static
 mate.dbg
 mate.prof
+mate.log
 tags
 *.swp
 *_stub.c
diff --git a/HACKING b/HACKING
index c70e19460291d17828bed41b7f06b43fe007c0f7..c1d34d95e94e7ea5d3ab81206d590de5166f5fe0 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -6,14 +6,10 @@ for testing a release build against OpenJDK output, use
 $ make tests/Fib.test
 
 
-for testing with a debug build, use
-$ DBGFLAGS='-DDBG_JIT -DDBG_BB' make tests/Fib.dbg
+for testing with a debug build, use edit Mate/Debug.hs and set
+`mateDEBUG = True' and build again. Output is in `mate.log'
 
-`make clean' is needed if you change $DBGFLAGS.
-for all available flags, see `debug.h'.
-
-
-for debugging with gdb, modify Mate/MethodPool.hs and make a debug build with at
-least -DDBG_JIT enabled, then use
+for debugging with gdb, modify Mate/MethodPool.hs and enable Debugging in
+Mate/Debug.hs, then use
 $ make tests/Fib.gdb
 and follow the instructions in the source file.
index 837c67cc6160606dcb2bc7c10c621647987ee2ff..1b02428d44ffdf65a9537c2aa5eb552d27fe92f9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -68,24 +68,11 @@ mate.static: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILE
        @mkdir -p $(B_STATIC)
        $(GHCCALL) $(B_STATIC) -static
 
-%.dbg: %.class mate.dbg
-       ./mate.dbg $(basename $<)
-
-%.gdb: %.class mate.dbg
-       gdb -x .gdbcmds -q --args mate.dbg $(basename $<) +RTS -V0 --install-signal-handlers=no
-
-ifeq (${DBGFLAGS},)
-DEBUGFLAGS = -DDBG_JIT -DDBG_MP
-else
-DEBUGFLAGS = ${DBGFLAGS}
-endif
-mate.dbg: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES)
-       @mkdir -p $(B_DEBUG)/{ffi,Mate,}
-       gcc -Wall $(DEBUGFLAGS) -O0 -c ffi/trap.c -o $(B_DEBUG)/ffi/trap.o
-       ghc --make $(DEBUGFLAGS) $(GHC_OPT) Mate.hs $(B_DEBUG)/ffi/trap.o -o $@ $(GHC_LD) -outputdir $(B_DEBUG)
+%.gdb: %.class mate
+       gdb -x .gdbcmds -q --args mate $(basename $<) +RTS -V0 --install-signal-handlers=no
 
 clean:
-       rm -rf $(BUILD) mate mate.static mate.dbg ffi/native.o \
+       rm -rf $(BUILD) mate mate.static ffi/native.o \
                tests/*.class Mate/*_stub.* \
                jmate/lang/*.class jmate/io/*.class java/io/*.class \
                java/lang/{Integer,Character,String,System}.class \
@@ -101,13 +88,7 @@ tags: mate.static
        ghc -I. -fforce-recomp -fobject-code $(PACKAGES) Mate.hs -outputdir $(B_STATIC) -e :ctags $(GHC_CPP)
 
 hlint:
-       @# hlint isn't able to evaluate CPP comments correctly *sigh*
-       @cp debug.h debug_tmp.h
-       @# so we remove them "by hand", for hlint
-       @gcc -E -x c -fpreprocessed -dD -E debug_tmp.h | grep -v 'debug_tmp.h' > debug.h
-       @# ignore error code from hlint
-       -hlint Mate.hs Mate/
-       @mv debug_tmp.h debug.h
+       hlint Mate.hs Mate/
 
 scratch: mate $(wildcard jmate/lang/*.java) scratch/GCTest.java
        javac $(wildcard jmate/lang/*.java)
diff --git a/Mate.hs b/Mate.hs
index 96edb9633155c58b5850e689e489134eb5eb9030..a191048495b26244a1ceab9bcd226d6e0289fb1a 100644 (file)
--- a/Mate.hs
+++ b/Mate.hs
@@ -1,6 +1,4 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
-#include "debug.h"
 module Main where
 
 import System.Environment
@@ -10,9 +8,6 @@ import Data.List.Split
 import qualified Data.ByteString.Lazy as B
 import Control.Monad
 
-#ifdef DEBUG
-import Text.Printf
-#endif
 import JVM.ClassFile
 import Java.JAR
 
@@ -21,6 +16,7 @@ import Mate.MethodPool
 import Mate.Types
 import Mate.ClassPool
 import Mate.NativeMachine
+import Mate.Debug
 
 import Mate.GC.Boehm
 
@@ -65,6 +61,7 @@ parseArgs _ _ = parseArgs ["-"] False
 executeMain :: B.ByteString -> Class Direct -> IO ()
 executeMain bclspath cls = do 
   initGC --required on some platforms. [todo bernhard: maybe this should be moved somewhere else - maybe at a global place where vm initialization takes place
+
   let methods = classMethods cls; methods :: [Method Direct]
   case find (\x -> methodName x == "main") methods of
     Just m -> do
@@ -72,8 +69,6 @@ executeMain bclspath cls = do
       rawmethod <- parseMethod cls "main" $ methodSignature m
       entry <- compileBB rawmethod mi
       addMethodRef entry mi [bclspath]
-#ifdef DEBUG
-      printf "executing `main' now:\n"
-#endif
+      printfInfo "executing `main' now:\n"
       executeFuncPtr entry
     Nothing -> error "main not found"
index 955f4f51191d1eae16ebef98636f75d4a4a58a22..04a2c3bc899119a8f43abb2de3f19c5059073b97 100644 (file)
@@ -1,15 +1,11 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
-#include "debug.h"
 module Mate.BasicBlocks(
   BlockID,
   BasicBlock,
   BBEnd,
   MapBB,
   Method,
-#ifdef DBG_BB
   printMapBB,
-#endif
   parseMethod,
   testCFG -- added by hs to perform benches from outside
   )where
@@ -29,49 +25,40 @@ import Mate.Types
 import Mate.Debug
 import Mate.Utilities
 
-#ifdef DEBUG
-import Text.Printf
-#endif
-
 -- for immediate representation to determine BBs
 type Offset = (Int, Maybe BBEnd) -- (offset in bytecode, offset to jump target)
 type OffIns = (Offset, Instruction)
 
 
-#ifdef DBG_BB
 printMapBB :: MapBB -> IO ()
 printMapBB hmap = do
-  putStr "BlockIDs: "
+  printfBb "BlockIDs: "
   let keys = M.keys hmap
-  mapM_ (putStr . (flip (++)) ", " . show) keys
-  putStrLn "\n\nBasicBlocks:"
+  mapM_ (printfBb. (flip (++)) ", " . show) keys
+  printfBb "\n\nBasicBlocks:"
   printMapBB' keys hmap
     where
       printMapBB' :: [BlockID] -> MapBB -> IO ()
       printMapBB' [] _ = return ()
       printMapBB' (i:is) hmap' = case M.lookup i hmap' of
         Just bb -> do
-          putStrLn $ "Block " ++ (show i)
-          mapM_ putStrLn (map ((++) "\t" . show) $ code bb)
-          case successor bb of
-            Return -> putStrLn ""
-            FallThrough t1 -> putStrLn $ "Sucessor: " ++ (show t1) ++ "\n"
-            OneTarget t1 -> putStrLn $ "Sucessor: " ++ (show t1) ++ "\n"
-            TwoTarget t1 t2 -> putStrLn $ "Sucessor: " ++ (show t1) ++ ", " ++ (show t2) ++ "\n"
+          printfBb $ "Block " ++ (show i)
+          mapM_ printfBb (map ((++) "\t" . show) $ code bb)
+          printfBb $ case successor bb of
+            Return -> ""
+            FallThrough t1 -> "Sucessor: " ++ (show t1) ++ "\n"
+            OneTarget t1 -> "Sucessor: " ++ (show t1) ++ "\n"
+            TwoTarget t1 t2 -> "Sucessor: " ++ (show t1) ++ ", " ++ (show t2) ++ "\n"
           printMapBB' is hmap
         Nothing -> error $ "BlockID " ++ show i ++ " not found."
-#endif
 
-#if 0
-#ifdef DBG_BB
+{-
 testInstance :: String -> B.ByteString -> MethodSignature -> IO ()
 testInstance cf method sig = do
   cls <- parseClassFile cf
   hmap <- parseMethod cls method sig
   printMapBB hmap
-#endif
 
-#ifdef DBG_BB
 test_main :: IO ()
 test_main = do
   test_01
@@ -84,8 +71,7 @@ test_01 = testInstance "./tests/Fib.class" "fib"
 test_02 = testInstance "./tests/While.class" "f"
 test_03 = testInstance "./tests/While.class" "g"
 test_04 = testInstance "./tests/Fac.class" "fac"
-#endif
-#endif
+-}
 
 
 parseMethod :: Class Direct -> B.ByteString -> MethodSignature -> IO RawMethod
@@ -107,19 +93,17 @@ parseMethod cls methodname sig = do
   let argscount = methodGetArgsCount nametype + (if isStatic then 0 else 1)
 
   let msig = methodSignature method
-  printfBb "BB: analysing \"%s\"\n" $ toString (methodname `B.append` ": " `B.append` encode msig)
-#ifdef DBG_BB
+  printfBb $ printf "BB: analysing \"%s\"\n" $ toString (methodname `B.append` ": " `B.append` encode msig)
   printMapBB mapbb
-#endif
   -- small example how to get information about
   -- exceptions of a method
   -- TODO: remove ;-)
   let (Just m) = lookupMethodSig methodname sig cls
   case attrByName m "Code" of
     Nothing ->
-      printfBb "exception: no handler for this method\n"
+      printfBb $ printf "exception: no handler for this method\n"
     Just exceptionstream ->
-      printfBb "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream)
+      printfBb $ printf "exception: \"%s\"\n" (show $ codeExceptions $ decodeMethod exceptionstream)
   return $ RawMethod mapbb locals stacks argscount codelen
 
 
index dde77e778599327620a8ee423ed3795ab6d7b611..849f1a1f1d06be03e22216ffb63a1d79efa02b8d 100644 (file)
@@ -1,6 +1,4 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
-#include "debug.h"
 module Mate.ClassPool (
   getClassInfo,
   classLoaded,
@@ -24,12 +22,7 @@ import qualified Data.ByteString.Lazy as B
 import Data.String.Utils
 import Control.Monad
 
-#ifdef DEBUG
-import Text.Printf
-#endif
-#ifdef DBG_CLASS
-import JVM.Dump
-#endif
+-- import JVM.Dump
 
 import Foreign.Ptr
 import Foreign.C.Types
@@ -126,9 +119,8 @@ readClass path = do
     Just cm -> return cm
     Nothing -> do
       cfile <- readClassFile $ toString path
-#ifdef DBG_CLASS
-      dumpClass cfile
-#endif
+      -- TODO(bernhard): hDumpClass
+      -- dumpClass cfile
       -- load all interfaces, which are implemented by this class
       sequence_ [ loadInterface i | i <- interfaces cfile ]
       superclass <- if path /= "java/lang/Object"
@@ -149,15 +141,23 @@ readClass path = do
       let wn_iftable = fromIntegral $ ptrToIntPtr iftable :: NativeWord
       -- store interface-table at offset 0 in method-table
       pokeElemOff (intPtrToPtr $ fromIntegral mbase) 0 wn_iftable
-#ifdef DBG_CLASS
-      let strpath = toString path
-      hexDumpMap ("staticmap @ " ++ strpath) staticmap
-      hexDumpMap ("fieldmap @ " ++ strpath) fieldmap
-      hexDumpMap ("methodmap @ " ++ strpath) methodmap
-      hexDumpMap ("interfacemap @ " ++ strpath) immap
-#endif
-      printfCp "mbase:   0x%08x\n" mbase
-      printfCp "iftable: 0x%08x\n" wn_iftable
+      let hexDumpMap :: Integral v => String -> M.Map B.ByteString v -> IO ()
+          hexDumpMap header mmap = do
+            let printValue :: B.ByteString -> IO ()
+                printValue key = printfCp $ printf "\t%-70s: 0x%08x\n" (toString key) val
+                  where val = fromIntegral (mmap M.! key) :: NativeWord
+            printfCp $ printf "%s\n" header
+            mapM_ printValue (M.keys mmap)
+      if mateDEBUG
+        then do
+          let strpath = toString path
+          hexDumpMap ("staticmap @ " ++ strpath) staticmap
+          hexDumpMap ("fieldmap @ " ++ strpath) fieldmap
+          hexDumpMap ("methodmap @ " ++ strpath) methodmap
+          hexDumpMap ("interfacemap @ " ++ strpath) immap
+          printfCp $ printf "mbase:   0x%08x\n" mbase
+          printfCp $ printf "iftable: 0x%08x\n" wn_iftable
+        else return ()
       virtual_map <- getVirtualMap
       setVirtualMap $ M.insert mbase path virtual_map
 
@@ -174,7 +174,7 @@ loadInterface path = do
   case M.lookup path imap of
     Just _ -> return ()
     Nothing -> do
-      printfCp "interface: loading \"%s\"\n" $ toString path
+      printfCp $ printf "interface: loading \"%s\"\n" $ toString path
       cfile <- readClassFile $ toString path
       -- load "superinterfaces" first
       sequence_ [ loadInterface i | i <- interfaces cfile ]
@@ -267,9 +267,9 @@ loadAndInitClass path = do
       let mi = MethodInfo "<clinit>" path (methodSignature m)
       entry <- compileBB rawmethod mi
       addMethodRef entry mi [path]
-      printfCp "executing static initializer from %s now\n" (toString path)
+      printfCp $ printf "executing static initializer from %s now\n" (toString path)
       executeFuncPtr entry
-      printfCp "static initializer from %s done\n" (toString path)
+      printfCp $ printf "static initializer from %s done\n" (toString path)
     Nothing -> return ()
 
   class_map' <- getClassMap
@@ -286,13 +286,13 @@ readClassFile path' = readIORef classPaths >>= rcf
     rcf [] = error $ "readClassFile: Class \"" ++ show path ++ "\" not found."
     rcf (Directory pre:xs) = do
       let cf = pre ++ path ++ ".class"
-      printfCp "rcf: searching @ %s for %s\n" (show pre) (show path)
+      printfCp $ printf "rcf: searching @ %s for %s\n" (show pre) (show path)
       b <- doesFileExist cf
       if b
         then parseClassFile cf
         else rcf xs
     rcf (JAR p:xs) = do
-      printfCp "rcf: searching %s in JAR\n" (show path)
+      printfCp $ printf "rcf: searching %s in JAR\n" (show path)
       entry <- getEntry p path
       case entry of
         Just (LoadedJAR _ cls) -> return cls
index dc8954eb84cb4eb184842209aa46a3c654d5deec..7acd3cd34abc3270d15f57a5f7aa7a06b731db1a 100644 (file)
@@ -1,48 +1,45 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
-#include "debug.h"
 
-module Mate.Debug where
-
-{- we cannot use `PrintfType' from Text.Printf, as it isn't exported.
- - so we implement a `VarArgsFake' here.
- - http://www.haskell.org/haskellwiki/Varargs -}
-class VarArgsFake t where
-  varFake :: [String] -> t
-
-instance VarArgsFake (IO a) where
-  varFake _ = return undefined
-
-instance (Show a, VarArgsFake r) => VarArgsFake (a -> r) where
-  varFake _ _ = varFake []
-
--- note: with -O2 GHC is able to completely optimize away such a `printfFake' call
-printfFake :: String -> (VarArgsFake t) => t
-printfFake _ = varFake []
-
-
--- see counterpart at `debug.h'
-#ifndef DBG_JIT
-printfJit :: String -> (VarArgsFake t) => t
-printfJit = printfFake
-#endif
-
-#ifndef DBG_BB
-printfBb :: String -> (VarArgsFake t) => t
-printfBb = printfFake
-#endif
-
-#ifndef DBG_MP
-printfMp :: String -> (VarArgsFake t) => t
-printfMp = printfFake
-#endif
-
-#ifndef DBG_CP
-printfCp :: String -> (VarArgsFake t) => t
-printfCp = printfFake
-#endif
-
-#ifndef DBG_STR
-printfStr :: String -> (VarArgsFake t) => t
-printfStr = printfFake
-#endif
+module Mate.Debug
+  ( printfJit
+  , printfBb
+  , printfMp
+  , printfCp
+  , printfStr
+  , printfInfo
+  , mateDEBUG
+  , printf -- TODO: delete me
+  ) where
+
+import Text.Printf
+import System.IO
+import System.IO.Unsafe
+
+
+{-# NOINLINE logHandle #-}
+-- TODO(bernhard): use MVar if threaded
+logHandle :: Handle
+logHandle = unsafePerformIO $ openFile "mate.log" WriteMode
+
+{-# INLINE mateDEBUG #-}
+mateDEBUG :: Bool
+mateDEBUG = False
+
+{-# INLINE printString #-}
+printString :: String -> String -> IO ()
+printString prefix str = if mateDEBUG
+  then hPutStr logHandle . (++) prefix $ str
+  else return ()
+
+
+printfJit, printfBb, printfMp, printfCp, printfStr, printfInfo  :: String -> IO ()
+{-
+-- TODO(bernhard):
+-- http://stackoverflow.com/questions/12123082/function-composition-with-text-printf-printf
+-}
+printfJit  = printString "Jit: "
+printfBb   = printString "Bb: "
+printfMp   = printString "Mp: "
+printfCp   = printString "Cp: "
+printfStr  = printString "Str: "
+printfInfo = printString "Info: "
index aa2ed3f12c5377ae8943b6bcdaf4f54c4911818b..617e571ba6d1407d7ad99200e4724478b94a6a6d 100644 (file)
@@ -1,6 +1,4 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
-{-# LANGUAGE CPP #-}
-#include "debug.h"
 module Mate.GarbageAlloc(
     mallocClassData,
     mallocStringGC,
@@ -16,9 +14,6 @@ import Foreign.C
 
 import Mate.GC.Boehm
 
-#ifdef DBG_STR
-import Text.Printf
-#endif
 import Mate.Debug
 
 -- unified place for allocating Memory
@@ -26,32 +21,32 @@ import Mate.Debug
 
 mallocClassData :: Int -> IO (Ptr a)
 mallocClassData size = do
-  printfStr "mallocClassData: %d\n" size
+  printfStr $ printf "mallocClassData: %d\n" size
   mem <- mallocBytes size
   addRootGC mem (plusPtr mem size)
   return mem
 
 mallocStringGC :: Int -> IO (Ptr a)
 mallocStringGC size = do
-  printfStr "mallocString: %d\n" size
+  printfStr $ printf "mallocString: %d\n" size
   mallocBytesGC size
 
 foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
 mallocObjectGC :: Int -> IO CPtrdiff
 mallocObjectGC size = do
   ptr <- mallocBytesGC size
-  printfStr "mallocObject: %d\n" size
+  printfStr $ printf "mallocObject: %d\n" size
   return $ fromIntegral $ ptrToIntPtr ptr
 
 mallocObjectUnmanaged :: Int -> IO CPtrdiff
 mallocObjectUnmanaged size = do
   ptr <- mallocBytes size
-  printfStr "mallocObjectUnmanged: %d\n" size
+  printfStr $ printf "mallocObjectUnmanged: %d\n" size
   return $ fromIntegral $ ptrToIntPtr ptr
 
 mallocStringUnmanaged :: Int -> IO (Ptr a)
 mallocStringUnmanaged size = do
-  printfStr "mallocStringUnamaged: %d\n" size
+  printfStr $ printf "mallocStringUnamaged: %d\n" size
   mallocBytes size
 
 
index 79b63e3ca2d9ec768221830cd14d0b926eaf6b48..223f50909fc6d04f62167be770392f7d21e00aa2 100644 (file)
@@ -1,7 +1,5 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE ForeignFunctionInterface #-}
-#include "debug.h"
 module Mate.MethodPool where
 
 import Data.Binary
@@ -18,13 +16,7 @@ import Foreign.C.String
 import JVM.ClassFile
 
 import Harpy
-#ifdef DBG_JIT
 import Harpy.X86Disassembler
-#endif
-
-#ifdef DEBUG
-import Text.Printf
-#endif
 
 import Mate.BasicBlocks
 import Mate.Types
@@ -67,7 +59,7 @@ getMethodEntry signal_from methodtable = do
   entryaddr <- case M.lookup mi' mmap of
     Nothing -> do
       cls <- getClassFile cm
-      printfMp "getMethodEntry(from 0x%08x): no method \"%s\" found. compile it\n" w32_from (show mi')
+      printfMp $ printf "getMethodEntry(from 0x%08x): no method \"%s\" found. compile it\n" w32_from (show mi')
       mm <- lookupMethodRecursive method sig [] cls
       case mm of
         Just (mm', clsnames, cls') -> do
@@ -91,7 +83,7 @@ getMethodEntry signal_from methodtable = do
                       parenth = replace "(" "_" $ replace ")" "_" $ toString $ encode sig
                       sym2 = replace ";" "_" $ replace "/" "_" parenth
                       symbol = sym1 ++ "__" ++ smethod ++ "__" ++ sym2
-                  printfMp "native-call: symbol: %s\n" symbol
+                  printfMp $ printf "native-call: symbol: %s\n" symbol
                   nf <- loadNativeFunction symbol
                   setMethodMap $ M.insert mi' nf mmap
                   return nf
@@ -165,12 +157,12 @@ compileBB rawmethod methodinfo = do
   let ((entry, _, _, new_tmap), _) = right
   setTrapMap $ tmap `M.union` new_tmap -- prefers elements in tmap
 
-  printfJit "generated code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo)
-  printfJit "\tstacksize: 0x%04x, locals: 0x%04x\n" (rawStackSize rawmethod) (rawLocals rawmethod)
-#ifdef DBG_JIT
-  mapM_ (printfJit "%s\n" . showAtt) (snd right)
-#endif
-  printfJit "\n\n"
+  printfJit $ printf "generated code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo)
+  printfJit $ printf "\tstacksize: 0x%04x, locals: 0x%04x\n" (rawStackSize rawmethod) (rawLocals rawmethod)
+  if mateDEBUG
+    then mapM_ (printfJit . printf "%s\n" . showAtt) (snd right)
+    else return ()
+  printfJit $ printf "\n\n"
   -- UNCOMMENT NEXT LINES FOR GDB FUN
   -- if (toString $ methName methodinfo) == "thejavamethodIwant2debug"
   --   then putStrLn "press CTRL+C now for setting a breakpoint. then `c' and ENTER for continue" >> getLine
index 14747410d3d8dcc28f55b3a8627a47eff25089b1..2587d939bb4342b8b3dbbcb354d4e0f96da6ca98 100644 (file)
@@ -11,7 +11,10 @@ module Mate.NativeMachine(
 import Mate.X86CodeGen
 import Mate.X86TrapHandling
 import Mate.NativeSizes
-
 #else
-#error "no other arch supported yet :/"
+
+-- HACK, for ghc-mod ...
+import Mate.X86CodeGen
+import Mate.X86TrapHandling
+import Mate.NativeSizes
 #endif
index 0ba612842eb7233522a5d8321f002ecd4fa5dd52..5e8795b46f158967db8d2e8ee72bdadbee7da25c 100644 (file)
@@ -8,5 +8,10 @@ ptrSize, longSize :: NativeWord
 ptrSize = 4
 longSize = 8
 
+type NativeWord = Word32
+#else
+-- HACK, for ghc-mod ...
+ptrSize = undefined
+longSize = undefined
 type NativeWord = Word32
 #endif
index 249840a43af1386ba664a738e797d9995f3eea3e..8c4e040371868adc20c6324408226e872b26a0fe 100644 (file)
@@ -1,9 +1,5 @@
-{-# LANGUAGE CPP #-}
 module Mate.RegisterAllocation where
 
-
-#include "debug.h"
-
 import Data.List
 import Data.Maybe
 
index 2f7504ac2aa4a24daf2db17fb1081273b49004a9..bb2bc8907f71139a9cfd2c712c70e93a7a03dd3a 100644 (file)
@@ -1,6 +1,4 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
-#include "debug.h"
 module Mate.Strings (
   getUniqueStringAddr
   ) where
@@ -9,9 +7,6 @@ import Data.Word
 import qualified Data.Map as M
 import qualified Data.ByteString.Lazy as B
 import qualified Data.ByteString.Internal as BI
-#ifdef DEBUG
-import Text.Printf
-#endif
 
 import JVM.ClassFile
 
@@ -56,7 +51,7 @@ allocateJavaString str = do
    -}
   -- build object layout
   fsize <- getObjectSize "java/lang/String"
-  printfStr "string: fsize: %d (should be 4 * 5)\n" fsize
+  printfStr $ printf "string: fsize: %d (should be 4 * 5)\n" fsize
   tblptr <- mallocObjectUnmanaged $ fromIntegral fsize
   let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr CPtrdiff
   mtbl <- getMethodTable "java/lang/String"
@@ -69,7 +64,7 @@ allocateJavaString str = do
   BI.memset newstr 0 (fromIntegral $ strlen + 5)
   arr <- newArray ((map fromIntegral $ B.unpack str) :: [Word8])
   copyBytes (plusPtr newstr 4) arr strlen
-  printfStr "new str ptr: (%s)@%d\n" (toString str) strlen
+  printfStr $ printf "new str ptr: (%s)@%d\n" (toString str) strlen
 
   let newstr_length = castPtr newstr :: Ptr CPtrdiff
   poke newstr_length $ fromIntegral strlen
index 8f234e5394ab5faba2ddc58cae9c019bc3845172..43e264ce76877fa0b5d3c4fc5f9c10da7803ec35 100644 (file)
@@ -1,4 +1,3 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
 module Mate.Utilities where
 
@@ -14,10 +13,6 @@ import JVM.ClassFile
 import Mate.Types
 import Mate.NativeSizes
 
-#ifdef DEBUG
-import Text.Printf
-#endif
-
 buildMethodID :: Class Direct -> Word16 -> MethodInfo
 buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt)
   where
@@ -76,15 +71,3 @@ methodIsStatic = S.member ACC_STATIC . methodAccessFlags
 lookupMethodSig :: B.ByteString -> MethodSignature -> Class Direct -> Maybe (Method Direct)
 lookupMethodSig name sig cls =
   find (\x -> methodName x == name && methodSignature x == sig) $ classMethods cls
-
-hexDumpMap :: Integral v => String -> M.Map B.ByteString v -> IO ()
-#ifdef DEBUG
-hexDumpMap header mmap = do
-  let printValue :: B.ByteString -> IO ()
-      printValue key = printf "\t%-70s: 0x%08x\n" (toString key) val
-        where val = fromIntegral (mmap M.! key) :: NativeWord
-  printf "%s\n" header
-  mapM_ printValue (M.keys mmap)
-#else
-hexDumpMap _ _ = return ()
-#endif
index 2f0f6e44edfb75b90e295eda3597a223304457a9..1a045794f32e33cbc33a144b4f66688a83bb2c95 100644 (file)
@@ -1,7 +1,5 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE ForeignFunctionInterface #-}
-#include "debug.h"
 module Mate.X86CodeGen where
 
 import Prelude hiding (and, div)
@@ -30,9 +28,6 @@ import Mate.Types
 import Mate.Utilities
 import Mate.ClassPool
 import Mate.Strings
-#ifdef DEBUG
-import Text.Printf
-#endif
 
 
 foreign import ccall "&mallocObjectGC"
index 1a571a39dd2f6eabee17131e99aa16bb231cc8e7..520e177d8da3fc396555ab1c8d7ad350d7d02a18 100644 (file)
@@ -1,7 +1,5 @@
-{-# LANGUAGE CPP #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE ForeignFunctionInterface #-}
-#include "debug.h"
 module Mate.X86TrapHandling (
   mateHandler,
   register_signal
@@ -22,9 +20,6 @@ import {-# SOURCE #-} Mate.MethodPool
 import Mate.ClassPool
 import Mate.X86CodeGen
 
-#ifdef DBG_JIT
-import Text.Printf
-#endif
 import Mate.Debug
 import Harpy.X86Disassembler
 
@@ -57,7 +52,7 @@ patchWithHarpy patcher reip = do
   let entry = Just (intPtrToPtr (fromIntegral reip), fixme)
   let cgconfig = defaultCodeGenConfig { customCodeBuffer = entry }
   (_, Right right) <- runCodeGenWithConfig (withDisasm $ patcher reip) () () cgconfig
-  mapM_ (printfJit "patched: %s\n" . showAtt) $ snd right
+  mapM_ (printfJit . printf "patched: %s\n" . showAtt) $ snd right
   return reip
 
 withDisasm :: CodeGen e s CPtrdiff -> CodeGen e s (CPtrdiff, [Instruction])
diff --git a/debug.h b/debug.h
deleted file mode 100644 (file)
index 4277648..0000000
--- a/debug.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/* DBG_JIT .... see generated code and CodeGen information
- * DBG_BB ..... BasicBlock information
- * DBG_MP ..... MethodPool.hs
- * DBG_CP ..... ClassPool.hs
- * DBG_STR .... Strings.hs
- * // no printf* defined
- * DBG_TRAP ... show information @ trap.c
- * DBG_CLASS .. dump classfile
- */
-
-/* ooops defines */
-#ifdef BG_ALL
-#define DBG_ALL
-#endif
-
-#ifdef BG_JIT
-#define DBG_JIT
-#endif
-
-#ifdef BG_BB
-#define DBG_BB
-#endif
-
-#ifdef BG_MP
-#define DBG_MP
-#endif
-
-#ifdef BG_CP
-#define DBG_CP
-#endif
-
-#ifdef BG_STR
-#define DBG_STR
-#endif
-
-#ifdef BG_TRAP
-#define DBG_TRAP
-#endif
-
-#ifdef BG_CLASS
-#define DBG_CLASS
-#endif
-
-/* if one constant from above is defined, we want to import
- * libraries like Text.Printf
- * needed for gettting proper `-Wall' output on a release build */
-
-#if defined(DBG_ALL) || defined(DBG_JIT) || defined(DBG_BB) || defined(DBG_MP) || defined(DBG_CP) || defined(DBG_STR)
-#define DEBUG
-#endif
-
-#if defined(DBG_ALL)
-#define DBG_JIT
-#define DBG_BB
-#define DBG_MP
-#define DBG_CP
-#define DBG_STR
-#define DBG_TRAP
-#if 0
-#define DBG_CLASS
-#endif
-#endif
-
-/* it would be awesome if we could just write
- * > printfFake = printf
- * here, but the type can't be infered, since `PrintfType'
- * isn't visible (at least this is my explanation :/).
- * if I'm wrong, move this to `Mate/Debug.hs'
- */
-#ifdef DBG_JIT
-#define printfJit printf
-#endif
-
-#ifdef DBG_BB
-#define printfBb printf
-#endif
-
-#ifdef DBG_MP
-#define printfMp printf
-#endif
-
-#ifdef DBG_CP
-#define printfCp printf
-#endif
-
-#ifdef DBG_STR
-#define printfStr printf
-#endif
index 4e526f23275d8967c9d05ed03899a7c29181aee1..c550658d5f5920d0cdc8a35f3520054ccf24163f 100644 (file)
@@ -2,8 +2,6 @@
 #include <stdlib.h>
 #include <stddef.h>
 
-#include "../debug.h"
-
 /* TODO(bernhard): use {u,}int* types */
 
 #define __USE_GNU