Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5::X64::Assembler - add labels
  • Loading branch information
fglock committed Mar 24, 2013
1 parent ab5f52f commit 0be697d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src5/lib/Perlito5/X64/Assembler.pm
@@ -1,13 +1,34 @@
use strict;
use warnings;


package Perlito5::X64::Label;

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

sub pos {
return $_[0]->{pos}
}

sub bind {
$_[0]->{pos} = $_[1];
}


package Perlito5::X64::Register;

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

sub code {
return $_[0]->{code}
}

sub is {
return $_[0]->{code} == $_[1]->{code};
}
Expand Down Expand Up @@ -172,9 +193,20 @@ sub is_uint16 {
return 0 <= $_[0] && $_[0] < 65536;
}

sub label {
return Perlito5::X64::Label->new();
}

#--- instructions

# bind the current address to a label
sub _bind {
my ($label) = @_;
die "bind: expecting a label"
if ref($label) ne 'Perlito5::X64::Label';
$label->bind( scalar(@buffer) );
}

sub _movl {
my ( $dst, $src ) = @_;
if ( is_register($dst) && is_register($src) ) {
Expand Down Expand Up @@ -368,6 +400,13 @@ The Perlito5 x64 backend
_ret();
say to_hex(); # C3
asm_reset();
my $here = label;
_xchg( rax, rcx );
_bind($here);
say "# xchg " . to_hex();
say "# label pos=", $here->pos();
=head1 References
- V8 Javascript Compiler
Expand Down
3 changes: 3 additions & 0 deletions t5-x64/01_sanity.t
Expand Up @@ -56,7 +56,10 @@ say "1..4";
say "# shld " . to_hex();

asm_reset();
my $here = label;
_xchg( rax, rcx );
_bind($here);
say "# xchg " . to_hex();
say "# label pos=", $here->pos();
}

0 comments on commit 0be697d

Please sign in to comment.