Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 380 lines (301 sloc) 10.382 kB
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
1 require 'tmpdir'
2
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
3 task :vm => 'vm/vm'
4
5 ############################################################
6 # Files, Flags, & Constants
7
dbe8229 Fix stack GC invariant
Evan Phoenix authored
8 if ENV['LLVM_DEBUG']
9 LLVM_STYLE = "Debug"
10 else
11 LLVM_STYLE = "Release"
12 end
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
13
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
14 ENV.delete 'CDPATH' # confuses llvm_config
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
15 LLVM_CONFIG = "vm/external_libs/llvm/#{LLVM_STYLE}/bin/llvm-config"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
16 tests = FileList["vm/test/test_*.hpp"]
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
17
18 # vm/test/test_instructions.hpp may not have been generated yet
19 tests << 'vm/test/test_instructions.hpp'
20 tests.uniq!
21
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
22 srcs = FileList["vm/*.{cpp,c}"] + FileList["vm/builtin/*.{cpp,c}"]
23 hdrs = FileList["vm/*.{hpp,h}"] + FileList["vm/builtin/*.{hpp,h}"]
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
24 objs = srcs.map { |f| f.sub(/c(pp)?$/, 'o') }
25 dep_file = "vm/.depends.mf"
26 vm_objs = %w[ vm/drivers/cli.o ]
27 vm_srcs = %w[ vm/drivers/cli.cpp ]
28 EX_INC = %w[ libtommath onig libffi/include
29 libltdl libev llvm/include
30 ].map { |f| "vm/external_libs/#{f}" }
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
31
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
32 INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
33 vm/gen/iseq_instruction_names.hpp
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
34 vm/gen/iseq_instruction_size.gen
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
35 vm/test/test_instructions.hpp ]
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
36 TYPE_GEN = %w[ vm/gen/includes.hpp
37 vm/gen/simple_field.rb
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
38 vm/gen/typechecks.gen.cpp
39 vm/gen/primitives_declare.hpp
40 vm/gen/primitives_glue.gen.cpp ]
41
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
42 field_extract_headers = %w[
0509b76 Add objects.hpp into list so Integer is processed.
Evan Phoenix authored
43 vm/objects.hpp
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
44 vm/builtin/object.hpp
b881222 Steamroller session getting the kernel running.
Evan Phoenix authored
45 vm/builtin/integer.hpp
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
46 vm/builtin/array.hpp
47 vm/builtin/bignum.hpp
48 vm/builtin/block_environment.hpp
49 vm/builtin/bytearray.hpp
50 vm/builtin/channel.hpp
51 vm/builtin/class.hpp
52 vm/builtin/executable.hpp
464bdfd @brixen Added CompactLookupTable.
brixen authored
53 vm/builtin/compactlookuptable.hpp
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
54 vm/builtin/compiledmethod.hpp
55 vm/builtin/contexts.hpp
56 vm/builtin/dir.hpp
57 vm/builtin/exception.hpp
58 vm/builtin/fixnum.hpp
59 vm/builtin/float.hpp
60 vm/builtin/hash.hpp
61 vm/builtin/immediates.hpp
62 vm/builtin/io.hpp
63 vm/builtin/iseq.hpp
64 vm/builtin/list.hpp
65 vm/builtin/lookuptable.hpp
66 vm/builtin/memorypointer.hpp
67 vm/builtin/methodtable.hpp
68 vm/builtin/nativefunction.hpp
69 vm/builtin/regexp.hpp
70 vm/builtin/selector.hpp
71 vm/builtin/sendsite.hpp
72 vm/builtin/staticscope.hpp
73 vm/builtin/string.hpp
74 vm/builtin/symbol.hpp
75 vm/builtin/task.hpp
76 vm/builtin/thread.hpp
77 vm/builtin/tuple.hpp
78 ]
79
d19313c Compile the kernel, and load it in
Evan Phoenix authored
80 BC = "vm/instructions.bc"
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
81 LLVM_A = "vm/external_libs/llvm/#{LLVM_STYLE}/lib/libLLVMSystem.a"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
82 EXTERNALS = %W[ #{LLVM_A}
83 vm/external_libs/libtommath/libtommath.a
84 vm/external_libs/onig/.libs/libonig.a
85 vm/external_libs/libffi/.libs/libffi.a
86 vm/external_libs/libltdl/.libs/libltdl.a
87 vm/external_libs/libev/.libs/libev.a ]
88 OPTIONS = {
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
89 LLVM_A => "--enable-targets=host-only"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
90 }
91
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
92 if LLVM_STYLE == "Release"
93 OPTIONS[LLVM_A] << " --enable-optimized"
94 end
95
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
96 INCLUDES = (EX_INC + %w[vm/test/cxxtest vm .]).map { |f| "-I#{f}" }
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
97 FLAGS = %w(-Wall -Werror -ggdb -gdwarf-2)
d19313c Compile the kernel, and load it in
Evan Phoenix authored
98 CC = ENV['CC'] || "gcc"
99
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
100
101 FLAGS << "-O2" if ENV['FAST']
102
103
3197850 Fix using strlcpy and strlcat, respect CC
Evan Phoenix authored
104 def compile(obj, src)
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
105 unless defined? $llvm_c then
106 $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
107 $llvm_c.delete_if { |e| e.index("-O") == 0 }
108 end
109
110 flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
111
d19313c Compile the kernel, and load it in
Evan Phoenix authored
112 if ENV['TERSE']
113 puts "CC #{src}"
114 sh "#{CC} #{flags} -c -o #{obj} #{src} 2>&1", :verbose => false
115 else
116 sh "#{CC} #{flags} -c -o #{obj} #{src} 2>&1"
117 end
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
118 end
119
d19313c Compile the kernel, and load it in
Evan Phoenix authored
120 def link t
121 $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
122
123 ld = ENV['LD'] || 'g++'
124 o = t.prerequisites.find_all { |f| f =~ /o$/ }.join(' ')
125 l = ex_libs.join(' ')
126
127 if ENV['TERSE']
128 puts "LD #{t.name}"
129 sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}", :verbose => false
130 else
131 sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}"
132 end
133 end
134
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
135 def tmpname(suffix = "cpp")
136 @which ||= 0
137
138 path = File.join(Dir.tmpdir, "rake.#{$$}.#{@which += 1}.#{suffix}")
139
140 yield path
141
142 ensure
143 FileUtils.rm_rf path
144 end
145
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
146 def rubypp_task(target, prerequisite, *extra)
147 file target => [prerequisite, 'vm/rubypp.rb'] + extra do
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
148 path = tmpname do |path|
149 ruby 'vm/rubypp.rb', prerequisite, path
07fb519 @drbrain Fix rubypp_task because I am an idiot.
drbrain authored
150 yield path
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
151 end
152 end
153 end
d19313c Compile the kernel, and load it in
Evan Phoenix authored
154
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
155 ############################################################
156 # Other Tasks
157
158 rule '.o' do |t|
159 obj = t.name
160 src = t.prerequisites.find { |f| f =~ /#{File.basename obj, '.o'}\.c(pp)?$/}
161
162 compile obj, src
163 end
164
165 def files targets, dependencies = nil, &block
166 targets.each do |target|
167 if dependencies then
168 file target => dependencies, &block
169 else
170 file target, &block
171 end
172 end
173 end
174
175 directory "vm/gen"
176 file "vm/type_info.o" => "vm/gen/typechecks.gen.cpp"
177 file "vm/primitives.hpp" => "vm/gen/primitives_declare.hpp"
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
178 files Dir["vm/builtin/*.hpp"], INSN_GEN
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
179 files vm_objs, vm_srcs
180
181 objs.zip(srcs).each do |obj, src|
182 file obj => src
183 end
184
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
185 objs += ["vm/instructions.o"] # NOTE: BC isn't added due to llvm-g++ requirement
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
186
187 files EXTERNALS do |t|
188 path = File.join(*split_all(t.name)[0..2])
189 configure_path = File.join(path, 'configure')
190
191 if File.exist? configure_path then
192 sh "cd #{path}; ./configure #{OPTIONS[t.name]} && make"
193 else
194 sh "cd #{path}; make"
195 end
196 end
197
d19313c Compile the kernel, and load it in
Evan Phoenix authored
198 file "vm/primitives.o" => "vm/field_extract.rb"
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
199 file 'vm/instructions_gen.rb' => 'kernel/core/iseq.rb'
6dab41d minor tweak, I doubt it fixes anything
Ryan Davis authored
200 file 'vm/instructions.rb' => "vm/gen"
201 file 'vm/instructions.rb' => "vm/instructions_gen.rb"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
202
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
203 files INSN_GEN, %w[vm/instructions.rb] do
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
204 ruby 'vm/instructions.rb', :verbose => $verbose
205 end
206
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
207 file 'vm/field_extract.rb' => 'vm/gen'
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
208
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
209 files TYPE_GEN, field_extract_headers + %w[vm/field_extract.rb] do
f29d1d4 Fix field_extract and some prims, remove Task->ip.
Evan Phoenix authored
210 puts "GEN field_extract"
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
211 field_extract field_extract_headers
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
212 end
213
214 file 'vm/vm' => EXTERNALS + objs + vm_objs do |t|
215 link t
216 end
217
218 file 'vm/gen/primitives_glue.gen.cpp' => hdrs
219
8684bc6 @drbrain tests depend on objs
drbrain authored
220 file 'vm/test/runner.cpp' => tests + objs do
b598bc7 @dgtized fixed test runner order to always be sorted to ensure dependencies wo…
dgtized authored
221 tests = tests.sort + [{ :verbose => true }]
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
222 sh("vm/test/cxxtest/cxxtestgen.pl", "--error-printer", "--have-eh",
223 "--abort-on-fail", "-o", "vm/test/runner.cpp", *tests)
224 end
225
226 file 'vm/test/runner.o' => 'vm/test/runner.cpp' # no rule .o => .cpp
227
228 file 'vm/test/runner' => EXTERNALS + objs + %w[vm/test/runner.o] do |t|
229 link t
230 end
231
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
232 # A simple JIT tester driver
233
234 file 'vm/drivers/compile.o' => 'vm/drivers/compile.cpp'
235
236 file 'vm/compile' => EXTERNALS + objs + %w[vm/drivers/compile.o] do |t|
237 link t
238 end
239
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
240 rubypp_task 'vm/instructions.o', 'vm/llvm/instructions.cpp', *hdrs do |path|
d19313c Compile the kernel, and load it in
Evan Phoenix authored
241 compile 'vm/instructions.o', path
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
242 end
243
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
244 rubypp_task 'vm/instructions.bc', 'vm/llvm/instructions.cpp', *hdrs do |path|
d19313c Compile the kernel, and load it in
Evan Phoenix authored
245 sh "llvm-g++ -emit-llvm -Ivm -Ivm/external_libs/libffi/include -c -o vm/instructions.bc #{path}"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
246 end
247
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
248 namespace :vm do
249 desc 'Run all VM tests'
250 task :test => 'vm/test/runner' do
bebd2d1 Add coverage task back in as vm:coverage
Evan Phoenix authored
251 ENV['VERBOSE'] = '1' if $verbose
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
252 sh 'vm/test/runner', :verbose => $verbose
253 end
254
bebd2d1 Add coverage task back in as vm:coverage
Evan Phoenix authored
255 task :coverage do
256 Dir.mkdir "vm/test/coverage" unless File.directory? "vm/test/coverage"
257 unless defined? $llvm_c then
258 $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
259 $llvm_c.delete_if { |e| e.index("-O") == 0 }
260 end
261
262 $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
263
264 flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
265
266 puts "CC/LD vm/test/coverage/runner"
267 begin
268 path = tmpname do |path|
269 ruby 'vm/rubypp.rb', "vm/llvm/instructions.cpp", path
270 sh "g++ -fprofile-arcs -ftest-coverage #{flags} -o vm/test/coverage/runner vm/test/runner.cpp vm/*.cpp vm/builtin/*.cpp vm/*.c #{path} #{$link_opts} #{(ex_libs + EXTERNALS).join(' ')}"
271 end
272
273 puts "RUN vm/test/coverage/runner"
274 sh "vm/test/coverage/runner"
275 if $verbose
276 sh "vm/test/lcov/bin/lcov --directory . --capture --output-file vm/test/coverage/app.info"
277 else
278 sh "vm/test/lcov/bin/lcov --directory . --capture --output-file vm/test/coverage/app.info > /dev/null 2>&1"
279 end
280
281 puts "GEN vm/test/coverage/index.html"
282 if $verbose
283 sh "cd vm/test/coverage; ../lcov/bin/genhtml app.info"
284 else
285 sh "cd vm/test/coverage; ../lcov/bin/genhtml app.info > /dev/null 2>&1"
286 end
287 ensure
288 sh "rm -f *.gcno *.gcda"
289 end
290 end
291
292
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
293 desc "Clean up vm build files"
294 task :clean do
295 files = [
d19313c Compile the kernel, and load it in
Evan Phoenix authored
296 objs, dep_file, TYPE_GEN, INSN_GEN,
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
297 'vm/gen',
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
298 'vm/test/runner',
299 'vm/test/runner.cpp',
300 'vm/test/test_instructions.cpp',
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
301 'vm/vm'
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
302 ].flatten
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
303
304 files.each do |filename|
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
305 rm_rf filename, :verbose => $verbose
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
306 end
307 end
308
309 desc "Clean up, including all external libs"
310 task :distclean => :clean do
311 EXTERNALS.each do |lib|
312 path = File.join(*lib.split(File::SEPARATOR)[0..2])
313 system "cd #{path}; make clean"
314 end
315 end
316
317 desc "Show which primitives are missing"
318 task :missing_primitives do
3420ff2 @wilson Look in the correct directory for 'missing_primitives'
wilson authored
319 cpp_primitives = `grep 'Ruby.primitive' vm/builtin/*.hpp | awk '{ print $4 }'`
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
320
321 cpp_primitives = cpp_primitives.gsub(':', '').split("\n").sort.uniq
322
323 shotgun_primitives = File.read('vm/shotgun_primitives.txt')
324 shotgun_primitives = shotgun_primitives.split("\n").sort.uniq
325
326 missing = shotgun_primitives - cpp_primitives
327
328 puts missing.join("\n")
329 end
330 end
331
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
332 ############################################################$
333 # Importers & Methods:
334
335 require 'rake/loaders/makefile'
336
d19313c Compile the kernel, and load it in
Evan Phoenix authored
337 generated = (TYPE_GEN + INSN_GEN).select { |f| f =~ /pp$/ }
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
338
339 file dep_file => srcs + hdrs + vm_srcs + generated do |t|
340 includes = INCLUDES.join ' '
341
342 flags = FLAGS.join ' '
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
343 flags << " -D__STDC_LIMIT_MACROS"
344
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
345 cmd = "makedepend -f- #{includes} -- #{flags} -- #{t.prerequisites}"
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
346 cmd << ' 2>/dev/null' unless $verbose
1ff280a Added top 10 node coloring, include filtering, and minimum edge filte…
Ryan Davis authored
347 warn "makedepend ..."
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
348
349 dep = `#{cmd}`
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
350 dep.gsub!(%r% /usr/include\S+%, '') # speeds up rake a lot
351 dep.gsub!(%r%^\S+:[^ ]%, '')
352
353 File.open t.name, 'w' do |f|
354 f.puts dep
355 end
356 end
357
358 import dep_file
359
360 def ex_libs # needs to be method to delay running of llvm_config
361 unless defined? $ex_libs then
362 $ex_libs = EXTERNALS + [ "-ldl" ]
363 $ex_libs << "-lrt" if RUBY_PLATFORM =~ /linux/
364
365 llvm_libfiles = `#{LLVM_CONFIG} --libfiles all`.split(/\s+/)
366 llvm_libfiles = llvm_libfiles.select { |f| File.file? f }
367
368 pwd = File.join Dir.pwd, '' # add /
369 llvm_libfiles = llvm_libfiles.map { |f| f.sub pwd, '' }
370 $ex_libs += llvm_libfiles
371 end
372 $ex_libs
373 end
374
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
375 def field_extract(headers)
376 headers += [{ :verbose => $verbose}]
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
377
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
378 ruby('vm/field_extract.rb', *headers)
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake …
drbrain authored
379 end
Something went wrong with that request. Please try again.