Permalink
Browse files

Add Some Features.

    1) support 32bit architecture
    2) support package system
    3) support use/use base
    4) support global variable
    5) add some test codes
  • Loading branch information...
1 parent 34ec3f2 commit 52b2c68d961ada05c4d3478195689f78f5104cbf @goccy committed Aug 29, 2013
Showing with 265,175 additions and 2,499 deletions.
  1. +9 −0 Makefile.PL
  2. +4 −1 example/array.pl
  3. +32 −0 example/assign.pl
  4. +4 −0 example/hash_ref.pl
  5. +0 −1 example/loop.pl
  6. +1 −0 example/operator.pl
  7. +51 −0 example/package.pl
  8. +34 −34 example/sub.pl
  9. +20 −499 gen/runtime_api.c
  10. +21 −258 gen/runtime_api.h
  11. +5,958 −1,454 gen/runtime_api.lli
  12. +81 −0 gen/runtime_api_32.c
  13. +62 −0 gen/runtime_api_32.h
  14. +1,322 −0 gen/runtime_api_common.c
  15. +93 −0 gen/runtime_api_common_body.h
  16. +206 −0 gen/runtime_api_common_footer.h
  17. +24 −0 gen/runtime_api_common_header.h
  18. +56 −4 include/codegen.hpp
  19. +2 −0 include/parser.hpp
  20. +11 −1 lib/Compiler/CodeGenerator/LLVM.pm
  21. +68 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api.h
  22. +9,858 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api.ll
  23. +62 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api_32.h
  24. +8,583 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api_32.ll
  25. +93 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api_common_body.h
  26. +206 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api_common_footer.h
  27. +24 −0 lib/Compiler/CodeGenerator/LLVM/runtime_api_common_header.h
  28. +25 −2 src/Compiler-CodeGenerator-LLVM.xs
  29. +792 −212 src/compiler/code_generator/llvm/generator.cpp
  30. +2 −0 src/hv_to_ast.cpp
  31. +0 −32 t/Compiler-CodeGenerator-LLVM.t
  32. +307 −0 t/aobench.t
  33. +43 −0 t/array.t
  34. +52 −0 t/array_ref.t
  35. +32 −0 t/assign.t
  36. +51 −0 t/auto_vivification.t
  37. +30 −0 t/code_ref.t
  38. +10 −0 t/compile.t
  39. +42 −0 t/condition.t
  40. +71 −0 t/dump.t
  41. +26 −0 t/expand_string.t
  42. +26 −0 t/fib.t
  43. +35 −0 t/hash.t
  44. +41 −0 t/hash_ref.t
  45. +83 −0 t/inc/Test/Compiler.pm
  46. +25 −0 t/io.t
  47. +26,860 −0 t/ir/aobench.ll
  48. +11,324 −0 t/ir/array_ref.ll
  49. +10,720 −0 t/ir/assign.ll
  50. +10,967 −0 t/ir/auto_vivification.ll
  51. +10,682 −0 t/ir/code_ref.ll
  52. +11,059 −0 t/ir/condition.ll
  53. +10,890 −0 t/ir/dump.ll
  54. +10,588 −0 t/ir/expand_string.ll
  55. +10,681 −0 t/ir/fib.ll
  56. +10,749 −0 t/ir/hash.ll
  57. +11,169 −0 t/ir/hash_ref.ll
  58. +10,605 −0 t/ir/io.ll
  59. +11,011 −0 t/ir/loop.ll
  60. +10,799 −0 t/ir/multi_assign.ll
  61. +11,444 −0 t/ir/operator.ll
  62. +10,592 −0 t/ir/package.ll
  63. +10,663 −0 t/ir/scalar_ref.ll
  64. +13,125 −0 t/ir/sub.ll
  65. +11,037 −0 t/ir/use.ll
  66. +11,099 −0 t/ir/use_base.ll
  67. +22 −0 t/lib/Person.pm
  68. +65 −0 t/loop.t
  69. +36 −0 t/multi_assign.t
  70. +69 −0 t/operator.t
  71. +49 −0 t/package.pl
  72. +28 −0 t/scalar_ref.t
  73. +169 −0 t/sub.t
  74. +31 −0 t/use.t
  75. +62 −0 t/use_base.t
  76. +2 −1 type_test.c
View
@@ -15,6 +15,15 @@ makemaker_args->{CC} = 'g++';
makemaker_args->{LD} = 'g++';
my @ignore_warnings_options = qw(missing-field-initializers unused-variable);
makemaker_args->{CCFLAGS} .= join('', map { ' -Wno-' . $_ } @ignore_warnings_options);
+chomp(my $bin_dir = `llvm-config --bindir`);
+my $clang = "$bin_dir/clang";
+die "could not find clang" unless ($clang);
+
+my $llvm_lib_dir = 'lib/Compiler/CodeGenerator/LLVM';
+`$clang -emit-llvm -S -o $llvm_lib_dir/runtime_api.ll gen/runtime_api.c`;
+`$clang -emit-llvm -arch i386 -S -o $llvm_lib_dir/runtime_api_32.ll gen/runtime_api_32.c`;
+`cp gen/*.h $llvm_lib_dir`;
+
if (DEBUG) {
makemaker_args->{OPTIMIZE} = '-O0';
chomp(my $llvm_cflags = `llvm-config --cxxflags`);
View
@@ -29,6 +29,9 @@
say $a[0];
$a[0] = 3;
say @a;
-
+my $b = 0;
+say $a[$b];
+$a[$b + 1] = 2;
+say @a;
#my @c = map { $_ * 2; } @a;
#say @c;
View
@@ -0,0 +1,32 @@
+use strict;
+use warnings;
+use Compiler::Lexer;
+use Compiler::Parser;
+use Compiler::Parser::AST::Renderer;
+use Compiler::CodeGenerator::LLVM;
+
+my $code = do { local $/; <DATA> };
+my $tokens = Compiler::Lexer->new('')->tokenize($code);
+my $parser = Compiler::Parser->new();
+my $ast = $parser->parse($tokens);
+Compiler::Parser::AST::Renderer->new->render($ast);
+my $generator = Compiler::CodeGenerator::LLVM->new();
+my $llvm_ir = $generator->generate($ast);
+open my $fh, '>', 'assign.ll';
+print $fh $llvm_ir;
+close $fh;
+
+$generator = Compiler::CodeGenerator::LLVM->new();
+$generator->debug_run($ast);
+
+__DATA__
+my $a = 10;
+
+$a += 2;
+say $a;
+$a -= 2;
+say $a;
+$a *= 2;
+say $a;
+$a /= 2;
+say $a;
View
@@ -19,7 +19,11 @@
$generator->debug_run($ast);
__DATA__
+<<<<<<< HEAD
my $a = { a => 1, b => { d => 2 }, c => 2 };
+=======
+my $a = { a => 1, b => { d => 8 }, c => 2 };
+>>>>>>> origin/dev
say $a;
say %$a;
View
@@ -31,7 +31,6 @@
my @a = (1, 2, 3, 4);
say @a;
-say "=============";
foreach my $itr (@a) {
say $itr;
View
@@ -20,6 +20,7 @@
$generator->debug_run($ast);
__DATA__
+say undef;
say 1;
say 2;
say 1 + 2 == 3;
View
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+use Compiler::Lexer;
+use Compiler::Parser;
+use Compiler::Parser::AST::Renderer;
+use Compiler::CodeGenerator::LLVM;
+
+my $code = do { local $/; <DATA> };
+my $tokens = Compiler::Lexer->new('')->tokenize($code);
+my $parser = Compiler::Parser->new();
+my $ast = $parser->parse($tokens);
+Compiler::Parser::AST::Renderer->new->render($ast);
+my $generator = Compiler::CodeGenerator::LLVM->new();
+my $llvm_ir = $generator->generate($ast);
+open my $fh, '>', 'package.ll';
+print $fh $llvm_ir;
+close $fh;
+print "generated\n";
+$generator = Compiler::CodeGenerator::LLVM->new();
+$generator->debug_run($ast);
+
+__DATA__
+
+package Person;
+
+sub new {
+ my ($class, $name, $age) = @_;
+ my $self = {
+ age => $age,
+ name => $name
+ };
+ return bless($self, $class);
+}
+
+sub get_name {
+ my $self = shift;
+ $self->{name};
+}
+
+sub get_age {
+ my $self = shift;
+ $self->{age};
+}
+
+package main;
+
+my $person = Person->new("goccy", 26);
+
+say $person;
+say $person->get_name();
+say $person->get_age;
View
@@ -26,48 +26,48 @@ sub f {
my $a = $_[0];
my $b = $_[1];
my $c = $a + $b;
- say $a;
- say $b;
+ say "$a : ", $a;
+ say "$b : ", $b;
# Object op Object
- say $a + $b;
- say $a - $b;
- say $a * $b;
- say $a / $b;
- say $a < $b;
- say $a > $b;
- say $a == $b;
- say $a != $b;
+ say "$a + $b : ", $a + $b;
+ say "$a - $b : ", $a - $b;
+ say "$a * $b : ", $a * $b;
+ say "$a / $b : ", $a / $b;
+ say "$a < $b : ", $a < $b;
+ say "$a > $b : ", $a > $b;
+ say "$a == $b : ", $a == $b;
+ say "$a != $b : ", $a != $b;
# Object op Int
- say $a + 2;
- say $b - 1;
- say $b * 2;
- say $b / 1;
- say $a < 1;
- say $a > 1;
- say $a == 1;
- say $a != 1;
+ say "$a + 2 : ", $a + 2;
+ say "$b - 1 : ", $b - 1;
+ say "$b * 2 : ", $b * 2;
+ say "$b / 1 : ", $b / 1;
+ say "$a < 1 : ", $a < 1;
+ say "$a > 1 : ", $a > 1;
+ say "$a == 1 : ", $a == 1;
+ say "$a != 1 : ", $a != 1;
# Int op Object
- say 2 + $b;
- say 1 - $b;
- say 2 * $b;
- say 1 / $b;
- say 1 < $a;
- say 1 > $a;
- say 1 == $a;
- say 1 != $a;
+ say "2 + $b : ", 2 + $b;
+ say "1 - $b : ", 1 - $b;
+ say "2 * $b : ", 2 * $b;
+ say "1 / $b : ", 1 / $b;
+ say "0 < $a : ", 0 < $a;
+ say "1 > $a : ", 1 > $a;
+ say "1 == $a : ", 1 == $a;
+ say "1 != $a : ", 1 != $a;
# Object op Double
- say $a < 1.2;
- say $a > 1.2;
- say $a + 2.1;
- say $b - 1.2;
- say $b * 1.2;
- say $b / 1.2;
- say $a == 1.2;
- say $a != 1.2;
+ say "$a < 1.2 : ", $a < 1.2;
+ say "$a > 1.2 : ", $a > 1.2;
+ say "$a + 2.1 : ", $a + 2.1;
+ say "$b - 1.2 : ", $b - 1.2;
+ say "$b * 1.2 : ", $b * 1.2;
+ say "$b / 1.2 : ", $b / 1.2;
+ say "$a == 1.2 : ", $a == 1.2;
+ say "$a != 1.2 : ", $a != 1.2;
# Double op Object
say 2.1 + $b;
Oops, something went wrong.

0 comments on commit 52b2c68

Please sign in to comment.