forked from jspahrsummers/luac-llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.hs
27 lines (21 loc) · 957 Bytes
/
generator.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Generator where
import qualified Parser
import System.IO
-- Writes an LLVM assembly statement
statement :: Handle -> String -> IO ()
statement fd line = do
hPutStrLn fd ("\t" ++ line)
-- Writes an LLVM assembly label
label :: Handle -> String -> IO ()
label fd name = do
hPutStrLn fd (name ++ ":")
-- Writes an LLVM number literal
expression :: Handle -> Parser.Expression -> IO ()
expression fd (Parser.NumberLiteral num) = do
statement fd ("call %lua_pushnumber_fp @lua_pushnumber (%lua_State* %state, %lua_Number " ++ (show num) ++ ")")
expression fd (Parser.NotExpression expr) = do
expression fd expr
statement fd ("%value = call %lua_toboolean_fp @lua_toboolean (%lua_State* %state, i32 -1)")
statement fd ("call %pop_fp @pop (%lua_State* %state, i32 1)")
statement fd ("%negatedValue = xor i32 %value, 1")
statement fd ("call %lua_pushboolean_fp @lua_pushboolean (%lua_State* %state, i32 %negatedValue)")