Skip to content

Commit

Permalink
Add Module type introspection.
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek authored and Reini Urban committed Oct 2, 2012
1 parent 5d6703f commit 6bfba36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 8 additions & 5 deletions runtime/parrot/library/LLVM/Module.pm
Expand Up @@ -45,18 +45,21 @@ class LLVM::Module is LLVM::Opaque {

#/** See Module::addTypeName. */
# LLVMAddTypeName => "Iptp",
method add_type_name(Str $name, $type) {
LLVM::call("AddTypeName", self, $name, $type);
method add_type(Str $name, LLVM::Type $type) {
# Reverse response.
!LLVM::call("AddTypeName", self, $name, $type);
}

# LLVMDeleteTypeName => "vpt",
method delete_type_name(Str $name) {
method delete_type(Str $name) {
LLVM::call("DeleteTypeName", self, $name);
}

# LLVMGetTypeByName => "ppt",
method get_type_name(Str $name) {
LLVM::call("GetTypeByName", self, $name);
method get_type(Str $name) {
LLVM::Type.create(
LLVM::call("GetTypeByName", self, $name)
)
}

# BitReader
Expand Down
21 changes: 21 additions & 0 deletions t/library/llvm/05-module.t
Expand Up @@ -25,6 +25,27 @@ ok( $ff.next() ~~ $lf, "first.next == last" );
ok( $lf.prev() ~~ $ff, "last.prev == first" );


# Types
my $type_name := "struct.FOO";
my $added := $module.add_type($type_name, LLVM::Type::struct());
ok( $added, "Type added" );

$added := $module.add_type($type_name, LLVM::Type::struct());
nok( $added, "Duplicated type not added" );

my $type := $module.get_type($type_name);
ok( $type, "Type found" );
ok( $type ~~ LLVM::Type, ".. with proper type");


$module.delete_type($type_name);
ok( 1, "Type deleted" );

$type := $module.get_type($type_name);
ok( !$type, "Deleted type not found" );



done_testing();

# vim: ft=perl6
Expand Down

0 comments on commit 6bfba36

Please sign in to comment.