static methods: add inheritance capability
[mate.git] / Mate.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module Main where
3
4 import System.Environment
5 import Data.Char
6 import Data.List
7 import qualified Data.ByteString.Lazy as B
8
9 import Text.Printf
10
11 import JVM.ClassFile
12 import JVM.Dump
13
14 import Mate.BasicBlocks
15 import Mate.X86CodeGen
16 import Mate.MethodPool
17 import Mate.Types
18 import Mate.ClassPool
19
20 main ::  IO ()
21 main = do
22   args <- getArgs
23   register_signal
24   initMethodPool
25   case args of
26     [clspath] -> do
27       let bclspath = B.pack $ map (fromIntegral . ord) clspath
28       cls <- getClassFile bclspath
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 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               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>"