debug: get rid of #ifdef guards
[mate.git] / Mate.hs
1 {-# LANGUAGE CPP #-}
2 {-# LANGUAGE OverloadedStrings #-}
3 #include "debug.h"
4 module Main where
5
6 import System.Environment
7 import Data.Char
8 import Data.List
9 import qualified Data.ByteString.Lazy as B
10
11 #ifdef DEBUG
12 import Text.Printf
13 #endif
14 import JVM.ClassFile
15
16 import Mate.BasicBlocks
17 import Mate.X86CodeGen
18 import Mate.MethodPool
19 import Mate.Types
20 import Mate.ClassPool
21
22 main ::  IO ()
23 main = do
24   args <- getArgs
25   register_signal
26   initMethodPool
27   case args of
28     [clspath] -> do
29       let bclspath = B.pack $ map (fromIntegral . ord) clspath
30       cls <- getClassFile bclspath
31       hmap <- parseMethod cls "main"
32       case hmap of
33         Just hmap' -> do
34           let methods = classMethods cls; methods :: [Method Resolved]
35           let method = find (\x -> (methodName x) == "main") methods
36           case method of
37             Just m -> do
38               let mi = (MethodInfo "main" bclspath (methodSignature m))
39               entry <- compileBB hmap' mi
40               addMethodRef entry mi [bclspath]
41 #ifdef DEBUG
42               printf "executing `main' now:\n"
43 #endif
44               executeFuncPtr entry
45             Nothing -> error "main not found"
46         Nothing -> error "main not found"
47     _ -> error "Usage: mate <class-file>"