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