diff --git a/runtime/parrot/library/LLVM/Builder.pm b/runtime/parrot/library/LLVM/Builder.pm index a9f7ed767c..73c242472f 100644 --- a/runtime/parrot/library/LLVM/Builder.pm +++ b/runtime/parrot/library/LLVM/Builder.pm @@ -36,8 +36,25 @@ class LLVM::Builder is LLVM::Opaque { } # LLVMClearInsertionPosition => "vp", + method clear_insert_position() { + LLVM::BasicBlock.create( + LLVM::call("ClearInsertPosition", self) + ); + } + # LLVMInsertIntoBuilder => "vpp", + method insert_into_builder(LLVM::Value $val) { + LLVM::BasicBlock.create( + LLVM::call("InsertIntoBuilder", self, $val) + ); + } + # LLVMInsertIntoBuilderWithName => "vppt", + method insert_into_builder_with_name(LLVM::Value $val, Str $name?) { + LLVM::BasicBlock.create( + LLVM::call("InsertIntoBuilderWithName", self, $val, $name) + ); + } # # Terminators # LLVMBuildRetVoid => "pp", @@ -53,7 +70,15 @@ class LLVM::Builder is LLVM::Opaque { LLVM::call("BuildRet", self, $value) ); } + # LLVMBuildAggregateRet => "ppp3", + method aggregate_ret(LLVM::Value *@vals) { + my $vals_llvm := LLVM::to_array(@vals); + LLVM::Value.create( + LLVM::call("BuildAggregateRet", self, $vals_llvm, +@vals) + ); + } + # LLVMBuildBr => "ppp", method br(LLVM::BasicBlock $to) { LLVM::Value.create( @@ -65,25 +90,77 @@ class LLVM::Builder is LLVM::Opaque { method cond_br(LLVM::Value $if, LLVM::BasicBlock $then, LLVM::BasicBlock $else) { LLVM::Value::create( LLVM::call("BuildCondBr", self, $if, $then, $else) - ) + ); } # LLVMBuildSwitch => "ppppi", + method switch(LLVM::Value $v, LLVM::BasicBlock $else, Int $num_cases) { + LLVM::Value::create( + LLVM::call("BuildSwitch", self, $v, $else, $num_cases) + ); + } + # LLVMBuildInvoke => "ppppippt", + method invoke(LLVM::Function $func, *@args, LLVM::BasicBlock $then, LLVM::BasicBlock $catch, Str :$name?) { + my $args_llvm := LLVM::to_array(@args); + LLVM::Value.create( + LLVM::call("BuildInvoke", self, $func, $args_llvm, +@args, $then, $catch, $name) + ); + } + # LLVMBuildUnwind => "pp", + method unwind(){ + LLVM::Value::create( + LLVM::call("BuildUnwind", self) + ); + } + # LLVMBuildUnreachable => "pp", + method unreachable(){ + LLVM::Value::create( + LLVM::call("BuildUnreachable", self) + ); + } # # Add a case to the switch instruction */ # LLVMAddCase => "vppp", + method add_case(LLVM::Value $switch, LLVM::Value $val, LLVM::BasicBlock $dest) { + LLVM::Value::create( + LLVM::call("BuildAddCase", $switch, $val, $dest) + ) + } # # Arithmetic is generated in INIT block. # LLVMBuildNeg => "pppt", + method neg(LLVM::Value $v, Str $name?) { + LLVM::Value.create( + LLVM::call("BuildNeg", self, $v, $name) + ); + } + # LLVMBuildNot => "pppt", + method not(LLVM::Value $v, Str $name?) { + LLVM::Value.create( + LLVM::call("BuildNot", self, $v, $name) + ); + } # # Memory # LLVMBuildMalloc => "pppt", + method malloc(LLVM::Type $type, Str $name?) { + LLVM::Value.create( + LLVM::call("BuildMalloc", self, $type, $name) + ); + } + # LLVMBuildArrayMalloc => "ppppt", + method array_malloc(LLVM::Type $type, LLVM::Value $n, Str $name?) { + LLVM::Value.create( + LLVM::call("BuildArrayMalloc", self, $type, $n, $name) + ); + } + # LLVMBuildAlloca => "pppt", method alloca(LLVM::Type $type, Str $name?) { LLVM::Value.create( @@ -91,7 +168,18 @@ class LLVM::Builder is LLVM::Opaque { ); } # LLVMBuildArrayAlloca => "ppppt", + method array_alloca(LLVM::Type $type, LLVM::Value $n, Str $name?) { + LLVM::Value.create( + LLVM::call("BuildArrayAlloca", self, $type, $n, $name) + ); + } # LLVMBuildFree => "ppp", + method free(LLVM::Value $ptr) { + LLVM::Value.create( + LLVM::call("BuildFree", self, $ptr) + ); + } + # LLVMBuildLoad => "pppt", method load(LLVM::Value $ptr, Str $name?) { LLVM::Value.create( @@ -160,8 +248,13 @@ class LLVM::Builder is LLVM::Opaque { # # Miscellaneous instructions # LLVMBuildPhi => "pppt", -# LLVMBuildCall => "pppppt", + method phi(LLVM::Type $type, Str $name?){ + LLVM::Value.create( + LLVM::call("BuildFhi", self, $type, $name) + ) + } +# LLVMBuildCall => "pppppt", method call(LLVM::Function $func, *@args, Str :$name?) { LLVM::call("BuildCall", self, @@ -172,16 +265,73 @@ class LLVM::Builder is LLVM::Opaque { ); } # LLVMBuildSelect => "pppppt", + method select(LLVM::Value $if, LLVM::BasicBlock $then, LLVM::BasicBlock $else, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildSelect", self, $if, $then, $else, $name) + ); + } + # LLVMBuildVAArg => "ppppt", + method va_arg(LLVM::Value $list, LLVM::Type $type, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildVAARG", self, $list, $type, $name) + ); + } + # LLVMBuildExtractElement => "ppppt", + method extract_element(LLVM::Value $vector, LLVM::Value $index, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildExtractElement", self, $vector, $index, $name) + ); + } + # LLVMBuildInsertElement => "pppppt", + method insert_element(LLVM::Value $vector, LLVM::Value $val, LLVM::Value $index, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildInsertElement", self, $vector, $val, $index, $name) + ); + } + # LLVMBuildShuffleVector => "pppppt", + method shuffle_vector(LLVM::Value $v1, LLVM::Value $v2, LLVM::Value $mask, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildShuffleVector", self, $v1, $v2, $mask, $name) + ); + } + # LLVMBuildExtractValue => "ppp3t", + method extract_value(LLVM::Value $aggr, Int $index, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildExtractValue", self, $aggr, $index, $name) + ); + } + # LLVMBuildInsertValue => "pppp3t", + method insert_value(LLVM::Value $aggr, LLVM::Value $val, Int $index, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildInsertValue", self, $aggr, $val, $index, $name) + ); + } # LLVMBuildIsNull => "pppt", + method is_null(LLVM::Value $val, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildIsNull", self, $val, $name) + ); + } + # LLVMBuildIsNotNull => "pppt", + method is_not_null(LLVM::Value $val, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildIsNotNull", self, $val, $name) + ); + } # LLVMBuildPtrDiff => "ppppt", + method ptr_diff(LLVM::Value $ptr1, LLVM::Value $ptr2, Str $name?) { + LLVM::Value::create( + LLVM::call("BuildPtrDiff", self, $ptr1, $ptr2, $name) + ); + } INIT { my $HOW := LLVM::Builder.HOW;