My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl -w
use strict;
use Parse::Eyapp;
use Infix;
use I2PIR;

sub TERMINAL::info { $_[0]{attr} }

sub build_dec {
our %s;
my $dec = "";
if (%s) {
my @vars = sort keys %s;
my $last = pop @vars;
$dec .= "$_, " for @vars;
$dec .= $last;
}
return $dec;
}

sub peephole_optimization {
$_[0] =~ s{(\$N\d+)\s*=\s*(.*\n)\s* ([a-zA-Z_]\w*)\s*=\s*\1}{$3 = $2}gx;
}

sub output_code {
my ($trans, $dec) = @_;

# Indent
$$trans =~ s/^/\t/gm;

# Output the code
print << "TRANSLATION";
.sub 'main' :main
\t.local num $$dec
$$trans
.end
TRANSLATION
}

################# main ######################
my $filename = shift;
my $parser = Infix->new();
$parser->slurp_file($filename);

my $t = $parser->YYParse() || exit(1);

# Machine independent optimizations
$t->s(our @algebra);

# Address Assignment
our $reg_assign;
$reg_assign->s($t);

# Translate to PARROT
$t->bud(our @translation);
# variable declarations
my $dec = build_dec();

peephole_optimization($t->{tr});

output_code(\$t->{tr}, \$dec);

Change log

r380 by casiano.rodriguez.leon on Dec 26, 2009   Diff
mm
Go to: 
Project members, sign in to write a code review

Older revisions

r379 by casiano.rodriguez.leon on Dec 26, 2009   Diff
updating parrot example
r3 by casiano.rodriguez.leon on Jan 7, 2009   Diff
I started in the wrong dir. moving
files to trunk
r2 by casiano.rodriguez.leon on Jan 7, 2009   Diff
Parse-Eyapp at google code
All revisions of this file

File info

Size: 1035 bytes, 61 lines

File properties

svn:executable
Powered by Google Project Hosting