Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5::X64::Assembler - add t5-x64/01_sanity.t
  • Loading branch information
fglock committed Mar 24, 2013
1 parent 0ff7ea2 commit d7f0089
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src5/lib/Perlito5/X64/Assembler.pm
@@ -1,17 +1,38 @@
use strict;
use warnings;

package Perlito6::X64::Assembler;
package Perlito5::X64::Assembler;

my @buffer;
my @hex_char = qw( 0 1 2 3 4 5 6 7 8 9 A B C D E F );

sub new {
my $class = shift;
@buffer = ();
bless {@_}, $class;
}

sub to_hex {
my $self = $_[0];
my $text = $_[1];
return '';
return join(' ',
map( $hex_char[int($_ / 16)] . $hex_char[$_ % 16], @buffer ) );
}

sub emit {
push @buffer, $_[0];
}

#---

sub ret {
my ( $self, $imm16 ) = @_;
if ( $imm16 == 0 ) {
emit(0xC3);
}
else {
emit(0xC2);
emit( $imm16 & 0xFF );
emit( ( $imm16 >> 8 ) & 0xFF );
}
}

1;
Expand All @@ -30,6 +51,12 @@ The Perlito5 x64 backend
my $asm = Perlito6::X64::Assembler->new();
say $asm->to_hex();
=head1 References
- V8 Javascript Compiler
src/x64/assembler-x64.cc
=cut


19 changes: 19 additions & 0 deletions t5-x64/01_sanity.t
@@ -0,0 +1,19 @@
use strict;
use warnings;
use Perlito5::X64::Assembler;
use Perlito5::Test;

say "1..1";

my $asm = Perlito5::X64::Assembler->new();

{
package Perlito5::X64::Assembler;

ret();
my $out = to_hex();

print "not " if $out ne 'C3';
say "ok # $out";
}

0 comments on commit d7f0089

Please sign in to comment.