Added a Malloc instruction.
This commit is contained in:
parent
230a205965
commit
c77139dfa8
3 changed files with 27 additions and 19 deletions
|
|
@ -114,8 +114,7 @@ data LLVMIr
|
|||
| Declare LLVMType Ident Params
|
||||
| SetVariable Ident LLVMIr
|
||||
| Variable Ident
|
||||
| -- extractvalue <aggregate type> <val>, <idx>{, <idx>}*
|
||||
ExtractValue LLVMType LLVMValue Integer
|
||||
| ExtractValue LLVMType LLVMValue Integer
|
||||
| GetElementPtr LLVMType LLVMType LLVMValue LLVMType LLVMValue LLVMType LLVMValue
|
||||
| GetElementPtrInbounds LLVMType LLVMType LLVMValue LLVMType LLVMValue LLVMType LLVMValue
|
||||
| Add LLVMType LLVMValue LLVMValue
|
||||
|
|
@ -134,6 +133,7 @@ data LLVMIr
|
|||
| Bitcast LLVMType LLVMValue LLVMType
|
||||
| Ret LLVMType LLVMValue
|
||||
| Comment String
|
||||
| Malloca Integer
|
||||
| UnsafeRaw String -- This should generally be avoided, and proper
|
||||
-- instructions should be used in its place
|
||||
deriving (Show, Eq, Ord)
|
||||
|
|
@ -223,6 +223,9 @@ llvmIrToString = go 0
|
|||
, ")\n"
|
||||
]
|
||||
(Alloca t) -> unwords ["alloca", toIr t, "\n"]
|
||||
(Malloca t) ->
|
||||
concat
|
||||
[ "call ptr @malloc(i32 ", show t, ")"]
|
||||
(Store t1 val t2 (Ident id2)) ->
|
||||
concat
|
||||
[ "store ", toIr t1, " ", toIr val
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
main : _Int ;
|
||||
main = double 3 ;
|
||||
|
||||
double : _Int -> _Int ;
|
||||
double x = x + x ;
|
||||
|
||||
|
|
@ -1,2 +1,13 @@
|
|||
main = const 1 2 ;
|
||||
id x = x;
|
||||
|
||||
const x y = x ;
|
||||
|
||||
data Maybe () where {
|
||||
Just : Int -> Maybe ()
|
||||
Nothing : Maybe ()
|
||||
};
|
||||
|
||||
main = case (Just 5) of {
|
||||
Just a => 10 ;
|
||||
Nothing => 0 ;
|
||||
}; --const (id 0) (id 'a') ;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue