Permalink
Browse files

Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …

…tasks.
  • Loading branch information...
1 parent 6506bea commit 569fccd2e67bdf4220add2d93fb1978e76653804 @drbrain drbrain committed Jul 30, 2008
Showing with 298 additions and 281 deletions.
  1. +17 −31 Rakefile
  2. +239 −0 rakelib/vm.rake
  3. +0 −216 vm/Rakefile
  4. +4 −4 vm/field_extract.rb
  5. +5 −5 vm/instructions.rb
  6. +29 −21 vm/instructions_gen.rb
  7. +1 −1 vm/llvm/instructions.cpp
  8. +1 −1 vm/test/test_ar.hpp
  9. +1 −1 vm/test/test_compiled_file.hpp
  10. +1 −1 vm/vm.cpp
View
@@ -12,12 +12,12 @@ $compiler = nil
# require 'rakelib/const_generator'
# require 'rakelib/types_generator'
-task :default => :build
+task :default => %w[build vm:test]
# BUILD TASKS
desc "Build everything that needs to be built"
-task :build => 'build:vm'
+task :build => 'build:all'
# task :stable_compiler do
# if ENV['USE_CURRENT'] or ENV['SYSTEM']
@@ -79,21 +79,15 @@ task :build => 'build:vm'
namespace :build do
-# task :all => %w[
-# build:shotgun
+ task :all => %w[
+ vm
+ ]
# build:platform
# build:rbc
# compiler
# lib/etc.rb
# lib/rbconfig.rb
# extensions
-# ]
-
- task :vm => "vm/vm"
-
- file "vm/vm" do
- sh "cd vm; rake"
- end
# task :simple => "build:rbc" do
# sh "cd vm; rake"
@@ -128,7 +122,7 @@ namespace :build do
# file "shotgun/rubinius.bin" => c_source do
# sh make('vm')
# end
-
+
# file "shotgun/rubinius.local.bin" => c_source do
# sh make('vm')
# end
@@ -229,13 +223,13 @@ end
# desc "Recompile all ruby system files"
# task :rebuild => %w[clean build:all]
-# desc "Alias for clean:all"
-# task :clean => "clean:all"
+desc 'Remove rubinius build files'
+task :clean => %w[vm:clean clean:crap]
-# desc "Alias for clean:distclean"
-# task :distclean => "clean:distclean"
+desc 'Remove rubinius build files and external library build files'
+task :distclean => %w[vm:distclean]
-# namespace :clean do
+namespace :clean do
# desc "Clean everything but third-party libs"
# task :all => %w[clean:rbc clean:extensions clean:shotgun clean:generated clean:crap]
@@ -262,26 +256,18 @@ end
# end
# end
-# desc "Cleans up VM building site"
-# task :shotgun do
-# sh make('clean')
-# end
-
# desc "Cleans up generated files"
# task :generated do
# rm_f Dir["shotgun/lib/grammar.c"], :verbose => $verbose
# end
-# desc "Cleans up VM and external libs"
-# task :external do
-# sh "cd shotgun; #{make('distclean')}"
-# end
+ desc "Cleans up editor files and other misc crap"
+ task :crap do
+ files = (Dir["*~"] + Dir["**/*~"]).uniq
-# desc "Cleans up editor files and other misc crap"
-# task :crap do
-# rm_f Dir["*~"] + Dir["**/*~"], :verbose => $verbose
-# end
-# end
+ rm_f files, :verbose => $verbose unless files.empty?
+ end
+end
# # SPEC TASKS
# desc "Run all 'known good' specs (task alias for spec:ci)"
View
@@ -0,0 +1,239 @@
+task :vm => 'vm/vm'
+
+############################################################
+# Files, Flags, & Constants
+
+ENV.delete 'CDPATH' # confuses llvm_config
+LLVM_CONFIG = "vm/external_libs/llvm/Release/bin/llvm-config"
+tests = FileList["vm/test/test_*.hpp"]
+srcs = FileList["vm/*.{cpp,c}"]
+hdrs = FileList["vm/*.{hpp,h}"]
+objs = srcs.map { |f| f.sub(/c(pp)?$/, 'o') }
+dep_file = "vm/.depends.mf"
+vm_objs = %w[ vm/drivers/cli.o ]
+vm_srcs = %w[ vm/drivers/cli.cpp ]
+EX_INC = %w[ libtommath onig libffi/include
+ libltdl libev llvm/include
+ ].map { |f| "vm/external_libs/#{f}" }
+INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
+ vm/gen/iseq_instruction_names.hpp
+ vm/test/test_instructions.hpp ]
+TYPE_GEN = %w[ vm/gen/simple_field.rb
+ vm/gen/typechecks.gen.cpp
+ vm/gen/primitives_declare.hpp
+ vm/gen/primitives_glue.gen.cpp ]
+
+LLVM_A = "vm/external_libs/llvm/Release/lib/libLLVMSystem.a"
+EXTERNALS = %W[ #{LLVM_A}
+ vm/external_libs/libtommath/libtommath.a
+ vm/external_libs/onig/.libs/libonig.a
+ vm/external_libs/libffi/.libs/libffi.a
+ vm/external_libs/libltdl/.libs/libltdl.a
+ vm/external_libs/libev/.libs/libev.a ]
+OPTIONS = {
+ LLVM_A => "--enable-targets=host-only --enable-optimized"
+ }
+
+INCLUDES = (EX_INC + %w[vm/test/cxxtest vm .]).map { |f| "-I#{f}" }
+FLAGS = %w(-Wall -ggdb -gdwarf-2)
+
+FLAGS << "-O2" if ENV['FAST']
+
+def compile(obj, src)
+ cc = "gcc" # File.basename(src) == "c" ? "gcc" : "g++"
+
+ unless defined? $llvm_c then
+ $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
+ $llvm_c.delete_if { |e| e.index("-O") == 0 }
+ end
+
+ flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
+
+ sh "#{cc} #{flags} -c -o #{obj} #{src} 2>&1"
+end
+
+############################################################
+# Other Tasks
+
+rule '.o' do |t|
+ obj = t.name
+ src = t.prerequisites.find { |f| f =~ /#{File.basename obj, '.o'}\.c(pp)?$/}
+
+ compile obj, src
+end
+
+def files targets, dependencies = nil, &block
+ targets.each do |target|
+ if dependencies then
+ file target => dependencies, &block
+ else
+ file target, &block
+ end
+ end
+end
+
+directory "vm/gen"
+file "vm/type_info.o" => "vm/gen/typechecks.gen.cpp"
+file "vm/primitives.hpp" => "vm/gen/primitives_declare.hpp"
+files Dir["vm/builtin_*.hpp"], INSN_GEN
+files objs, EXTERNALS
+files vm_objs, vm_srcs
+
+objs.zip(srcs).each do |obj, src|
+ file obj => src
+end
+
+objs += ["vm/instructions.o"]
+
+files EXTERNALS do |t|
+ path = File.join(*split_all(t.name)[0..2])
+ configure_path = File.join(path, 'configure')
+
+ if File.exist? configure_path then
+ sh "cd #{path}; ./configure #{OPTIONS[t.name]} && make"
+ else
+ sh "cd #{path}; make"
+ end
+end
+
+file 'vm/instructions.rb' => 'vm/instructions_gen.rb'
+
+files INSN_GEN, %w[vm/gen vm/instructions.rb] do
+ ruby 'vm/instructions.rb', :verbose => $verbose
+end
+
+files TYPE_GEN, %w[vm/gen vm/instructions.rb vm/field_extract.rb] do
+ field_extract
+end
+
+file 'vm/vm' => EXTERNALS + objs + vm_objs do |t|
+ link t
+end
+
+file 'vm/gen/primitives_glue.gen.cpp' => hdrs
+
+file 'vm/test/runner.cpp' => tests do
+ tests += [{ :verbose => true }]
+ sh("vm/test/cxxtest/cxxtestgen.pl", "--error-printer", "--have-eh",
+ "--abort-on-fail", "-o", "vm/test/runner.cpp", *tests)
+end
+
+file 'vm/test/runner.o' => 'vm/test/runner.cpp' # no rule .o => .cpp
+
+file 'vm/test/runner' => EXTERNALS + objs + %w[vm/test/runner.o] do |t|
+ link t
+end
+
+file "vm/instructions.o" => %w[vm/llvm/instructions.cpp vm/instructions.rb] do
+ ruby "vm/rubypp.rb vm/llvm/instructions.cpp vm/llvm/.instructions.cpp"
+ compile "vm/instructions.o", "vm/llvm/.instructions.cpp"
+ rm_f "vm/llvm/.instructions.cpp", :verbose => $verbose
+end
+
+file "vm/instructions.bc" => "vm/llvm/instructions.cpp" do
+ ruby "vm/rubypp.rb vm/llvm/instructions.cpp vm/llvm/.instructions.cpp"
+ sh "llvm-g++ -emit-llvm -Ivm -Ivm/external_libs/libffi/include -c -o vm/instructions.bc vm/llvm/.instructions.cpp", :verbose => true
+ rm_f "llvm/.instructions.cpp", :verbose => $verbose
+end
+
+############################################################$
+# Importers & Methods:
+
+require 'rake/loaders/makefile'
+
+file dep_file => srcs + hdrs + vm_srcs do |t|
+ flags = (INCLUDES + FLAGS).join(' ')
+ flags << " -D__STDC_LIMIT_MACROS"
+
+ dep = nil
+ Dir.chdir 'vm' do
+ dep = `makedepend -f- -- #{flags} -- #{t.prerequisites} 2>/dev/null`
+ end
+ dep.gsub!(%r% /usr/include\S+%, '') # speeds up rake a lot
+ dep.gsub!(%r%^\S+:[^ ]%, '')
+
+ File.open t.name, 'w' do |f|
+ f.puts dep
+ end
+end
+
+import dep_file
+
+def ex_libs # needs to be method to delay running of llvm_config
+ unless defined? $ex_libs then
+ $ex_libs = EXTERNALS + [ "-ldl" ]
+ $ex_libs << "-lrt" if RUBY_PLATFORM =~ /linux/
+
+ llvm_libfiles = `#{LLVM_CONFIG} --libfiles all`.split(/\s+/)
+ llvm_libfiles = llvm_libfiles.select { |f| File.file? f }
+
+ pwd = File.join Dir.pwd, '' # add /
+ llvm_libfiles = llvm_libfiles.map { |f| f.sub pwd, '' }
+ $ex_libs += llvm_libfiles
+ end
+ $ex_libs
+end
+
+def field_extract
+ order = %w[vm/builtin_object.hpp vm/objects.hpp]
+ order += File.read("vm/objects.hpp").scan(/vm\/builtin_[^"]+/)
+ order << { :verbose => $verbose}
+ ruby('vm/field_extract.rb', *order)
+end
+
+def link t
+ $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
+
+ ld = ENV['LD'] || 'g++'
+ o = t.prerequisites.find_all { |f| f =~ /o$/ }.join(' ')
+ l = ex_libs.join(' ')
+
+ sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}"
+end
+
+namespace :vm do
+ desc 'Run all VM tests'
+ task :test => 'vm/test/runner' do
+ ENV['VERBOSE'] = '1' if $verbose
+ sh 'vm/test/runner', :verbose => $verbose
+ end
+
+ desc "Clean up vm build files"
+ task :clean do
+ # TODO evan? "*.gcda *.gcno *.gcov *.dSYM ../*.o coverage"
+ files = [
+ objs, dep_file,
+ 'vm/test/runner', 'vm/test/runner.cpp',
+ 'vm/gen',
+ 'vm/vm'
+ ]
+
+ files.each do |filename|
+ rm_f filename, :verbose => $verbose
+ end
+ end
+
+ desc "Clean up, including all external libs"
+ task :distclean => :clean do
+ EXTERNALS.each do |lib|
+ path = File.join(*lib.split(File::SEPARATOR)[0..2])
+ system "cd #{path}; make clean"
+ end
+ end
+
+ desc "Show which primitives are missing"
+ task :missing_primitives do
+ cpp_primitives = `grep 'Ruby.primitive' vm/*.hpp | awk '{ print $4 }'`
+
+ cpp_primitives = cpp_primitives.gsub(':', '').split("\n").sort.uniq
+
+ shotgun_primitives = File.read('vm/shotgun_primitives.txt')
+ shotgun_primitives = shotgun_primitives.split("\n").sort.uniq
+
+ missing = shotgun_primitives - cpp_primitives
+
+ puts missing.join("\n")
+ end
+
+end
+
Oops, something went wrong.

0 comments on commit 569fccd

Please sign in to comment.