classpool: do classloading at central point. omit '.class' when calling `mate'
[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 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       dumpClass cls
32       hmap <- parseMethod cls "main"
33       printMapBB hmap
34       case hmap of
35         Just hmap' -> do
36           let methods = classMethods cls; methods :: [Method Resolved]
37           let method = find (\x -> (methodName x) == "main") methods
38           case method of
39             Just m -> do
40               entry <- compileBB hmap' (MethodInfo "main" bclspath (methodSignature m))
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>"