Skip to content

Commit

Permalink
Generate Builder.foo for all math ops on load
Browse files Browse the repository at this point in the history
  • Loading branch information
bacek committed Mar 8, 2011
1 parent 3b39ab4 commit 4f7f1ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions runtime/parrot/library/LLVM/Builder.pm
Expand Up @@ -193,6 +193,26 @@ class LLVM::Builder is LLVM::Opaque {
# LLVMBuildIsNotNull => "pppt",
# LLVMBuildPtrDiff => "ppppt",

INIT {
my $HOW := LLVM::Builder.HOW;
my $WHAT := LLVM::Builder.WHAT;

# Generate binary ops
for <Add NSWAdd FAdd Sub FSub Mul FMul UDiv SDiv ExactSDiv FDiv URem SRem FRem Shl LShr AShr And Or Xor> -> $name {
my $call := "Build" ~ $name;
my $subname := pir::downcase($name);
$HOW.add_method(
$subname,
method (LLVM::Value $left, LLVM::Value $right, :$name?) {
LLVM::Value.create(
LLVM::call($call, self, $left, $right, $name)
)
},
to => $WHAT
);
}
}

};

# vim: ft=perl6
8 changes: 8 additions & 0 deletions t/library/llvm.t
Expand Up @@ -42,6 +42,14 @@ ok( 1, "Call created with args");

my $answer := LLVM::Constant::integer(42);
ok( 1, "Constant created");

# Simple math
$answer := $builder.add(
LLVM::Constant::integer(40),
LLVM::Constant::integer(2)
);
ok( 1, "Simple add created");

$builder.ret($answer);
ok( 1, "return created");

Expand Down

0 comments on commit 4f7f1ed

Please sign in to comment.