Skip to content

Commit

Permalink
Add Type::function for create FunctionType
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Mar 21, 2011
1 parent 9a5cbee commit 240d755
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
21 changes: 18 additions & 3 deletions runtime/parrot/library/LLVM/Type.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,27 @@ class LLVM::Type is LLVM::Value {
sub fp128() { LLVM::Type.create(LLVM::call("FP128Type")) }
sub ppcfp128() { LLVM::Type.create(LLVM::call("PPCFP128Type")) }

sub function(LLVM::Type $return, *@args, :$va_args?) {
LLVM::Type.create(
LLVM::call("FunctionType",
$return, # return
LLVM::to_array(@args), # parameters
+@args, # number of parameters
+$va_args, # is var args
)
)
}

sub struct(*@parts, :$packed?) {
LLVM::Type.create(LLVM::call("StructType", LLVM::to_array(@parts), +@parts, $packed));
LLVM::Type.create(
LLVM::call("StructType", LLVM::to_array(@parts), +@parts, $packed)
);
}

sub pointer($type, :$address_space?) {
LLVM::Type.create(LLVM::call("PointerType", $type, $address_space));
sub pointer(LLVM::Type $type, :$address_space?) {
LLVM::Type.create(
LLVM::call("PointerType", $type, $address_space)
);
}

sub void() { LLVM::Type.create(LLVM::call("VoidType", )) };
Expand Down
17 changes: 17 additions & 0 deletions t/library/llvm/02-type.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ my $ptr := LLVM::Type::pointer(LLVM::Type::int8());
ok( $ptr, "i8* created");
ok( $type ~~ LLVM::Type, ".. with proper class");

# FunctionType
# void foo()
$type := LLVM::Type::function(LLVM::Type::void());
ok( $type ~~ LLVM::Type, "void (*)()");

# int foo(...)
$type := LLVM::Type::function(LLVM::Type::int8(), :va_args<1>);
ok( $type ~~ LLVM::Type, "int (*)(...)");

# int foo(int, i8*, ...)
$type := LLVM::Type::function(
LLVM::Type::int8(),
LLVM::Type::int8(), LLVM::Type::cstring(),
:va_args<1>
);
ok( $type ~~ LLVM::Type, "int (*)(int, char*, ...)");

# TODO Add tests for floats

# Refine
Expand Down

0 comments on commit 240d755

Please sign in to comment.