Permalink
Browse files

Ensure that test_instructions.hpp is included in runner.cpp generation.

Fix generation of various bits from field_extract.rb

Improve readability of field_extract output.
  • Loading branch information...
1 parent 656a4b0 commit ecc013df34a85fafe0ca1d4d832acb57b3f7b4a3 @drbrain drbrain committed Aug 6, 2008
Showing with 117 additions and 72 deletions.
  1. +48 −11 rakelib/vm.rake
  2. +67 −52 vm/field_extract.rb
  3. +1 −5 vm/primitives.cpp
  4. +1 −4 vm/type_info.cpp
View
@@ -8,6 +8,11 @@ task :vm => 'vm/vm'
ENV.delete 'CDPATH' # confuses llvm_config
LLVM_CONFIG = "vm/external_libs/llvm/Release/bin/llvm-config"
tests = FileList["vm/test/test_*.hpp"]
+
+# vm/test/test_instructions.hpp may not have been generated yet
+tests << 'vm/test/test_instructions.hpp'
+tests.uniq!
+
srcs = FileList["vm/*.{cpp,c}"] + FileList["vm/builtin/*.{cpp,c}"]
hdrs = FileList["vm/*.{hpp,h}"] + FileList["vm/builtin/*.{hpp,h}"]
objs = srcs.map { |f| f.sub(/c(pp)?$/, 'o') }
@@ -22,11 +27,47 @@ INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
vm/gen/iseq_instruction_names.hpp
vm/gen/iseq_instruction_size.gen
vm/test/test_instructions.hpp ]
-TYPE_GEN = %w[ vm/gen/simple_field.rb
+TYPE_GEN = %w[ vm/gen/includes.hpp
+ vm/gen/simple_field.rb
vm/gen/typechecks.gen.cpp
vm/gen/primitives_declare.hpp
vm/gen/primitives_glue.gen.cpp ]
+field_extract_headers = %w[
+ vm/builtin/object.hpp
+ vm/builtin/array.hpp
+ vm/builtin/bignum.hpp
+ vm/builtin/block_environment.hpp
+ vm/builtin/bytearray.hpp
+ vm/builtin/channel.hpp
+ vm/builtin/class.hpp
+ vm/builtin/executable.hpp
+ vm/builtin/compiledmethod.hpp
+ vm/builtin/contexts.hpp
+ vm/builtin/dir.hpp
+ vm/builtin/exception.hpp
+ vm/builtin/fixnum.hpp
+ vm/builtin/float.hpp
+ vm/builtin/hash.hpp
+ vm/builtin/immediates.hpp
+ vm/builtin/io.hpp
+ vm/builtin/iseq.hpp
+ vm/builtin/list.hpp
+ vm/builtin/lookuptable.hpp
+ vm/builtin/memorypointer.hpp
+ vm/builtin/methodtable.hpp
+ vm/builtin/nativefunction.hpp
+ vm/builtin/regexp.hpp
+ vm/builtin/selector.hpp
+ vm/builtin/sendsite.hpp
+ vm/builtin/staticscope.hpp
+ vm/builtin/string.hpp
+ vm/builtin/symbol.hpp
+ vm/builtin/task.hpp
+ vm/builtin/thread.hpp
+ vm/builtin/tuple.hpp
+]
+
BC = "vm/instructions.bc"
LLVM_A = "vm/external_libs/llvm/Release/lib/libLLVMSystem.a"
EXTERNALS = %W[ #{LLVM_A}
@@ -150,10 +191,10 @@ files INSN_GEN, %w[vm/instructions.rb] do
ruby 'vm/instructions.rb', :verbose => $verbose
end
-file 'vm/field_extract.rb' => %w[vm/gen vm/builtin/object.hpp vm/objects.hpp]
+file 'vm/field_extract.rb' => 'vm/gen'
-files TYPE_GEN, %w[vm/field_extract.rb] do
- field_extract
+files TYPE_GEN, field_extract_headers + %w[vm/field_extract.rb] do
+ field_extract field_extract_headers
end
file 'vm/vm' => EXTERNALS + objs + vm_objs do |t|
@@ -271,12 +312,8 @@ def ex_libs # needs to be method to delay running of llvm_config
$ex_libs
end
-def field_extract
- order = %w[vm/builtin/object.hpp vm/objects.hpp]
- objects = File.read("vm/objects.hpp").scan(/builtin\/[^"]+/)
-
- order += objects.map { |f| File.join 'vm', f }
- order << { :verbose => $verbose}
+def field_extract(headers)
+ headers += [{ :verbose => $verbose}]
- ruby('vm/field_extract.rb', *order)
+ ruby('vm/field_extract.rb', *headers)
end
View
@@ -203,58 +203,66 @@ def generate_sets
def generate_typechecks
out = generate_sets()
- return if out.strip.empty?
+ return '' if out.strip.empty?
- str = "void #{@name}::Info::set_field(STATE, OBJECT _t, size_t index, OBJECT val) {\n"
- str << " #{@name}* target = as<#{@name}>(_t);\n"
- str << " switch(index) {\n"
+ <<-EOF
+void #{@name}::Info::set_field(STATE, OBJECT _t, size_t index, OBJECT val) {
+ #{@name}* target = as<#{@name}>(_t);
- str << out
+ switch(index) {
+#{out} }
+}
- str << " }\n}\n"
- str << "OBJECT #{@name}::Info::get_field(STATE, OBJECT _t, size_t index) {\n"
- str << " #{@name}* target = as<#{@name}>(_t);\n"
- str << " switch(index) {\n"
+OBJECT #{@name}::Info::get_field(STATE, OBJECT _t, size_t index) {
+ #{@name}* target = as<#{@name}>(_t);
- str << generate_gets()
+ switch(index) {
+#{generate_gets} }
- str << " }\n"
- str << " throw std::runtime_error(\"Unable to access field\");\n"
- str << "}\n"
+ throw std::runtime_error(\"Unable to access field\");
+}
+
+ EOF
end
def generate_marks(cpp)
- if cpp.super
- str = generate_marks(cpp.super)
- else
- str = ""
- end
+ str = ''
+
+ str << generate_marks(cpp.super) if cpp.super
cpp.fields.each do |name, type, idx|
- str << " {\n"
- str << " if(target->#{name}->reference_p()) {\n"
- str << " OBJECT res = mark.call(target->#{name});\n"
- str << " if(res) {\n"
- str << " target->#{name} = as<#{type}>(res);\n"
- str << " mark.just_set(target, res);\n"
- str << " }\n"
- str << " }\n"
- str << " }\n"
+ str << <<-EOF
+ {
+ if(target->#{name}->reference_p()) {
+ OBJECT res = mark.call(target->#{name});
+ if(res) {
+ target->#{name} = as<#{type}>(res);
+ mark.just_set(target, res);
+ }
+ }
+ }
+
+ EOF
end
return str
end
def generate_mark
- out = generate_sets()
- return if out.strip.empty?
+ marks = generate_marks(self).rstrip
- str = "void #{@name}::Info::mark(OBJECT _t, ObjectMark& mark) {\n"
- str << " #{@name}* target = as<#{@name}>(_t);\n"
+ str = ''
- str << generate_marks(self)
- str << "}\n"
- return str
+ str << <<-EOF unless marks.empty?
+void #{@name}::Info::mark(OBJECT _t, ObjectMark& mark) {
+ #{@name}* target = as<#{@name}>(_t);
+
+#{marks}
+}
+
+ EOF
+
+ str
end
end
@@ -333,18 +341,10 @@ def parse_stream(f)
break if /\};/.match(l)
break if /^\s*class/.match(l)
- if m = %r!^\s*([\w\d_]+)\*?\s+\*?([\w\d_]+)\s*;\s*//\s*slot(.*)!.match(l)
+ if m = %r!^\s*(\w+)\*?\s+\*?(\w+)\s*;\s*//\s*slot(.*)!.match(l)
type = m[1]
name = m[2]
- if name[0] == ?*
- name = name[1..-1]
- end
-
- if type[-1] == ?*
- type = type[0..-2]
- end
-
if mapped = @type_map[type]
type = mapped
else
@@ -356,7 +356,8 @@ def parse_stream(f)
else
flag = nil
end
- cpp.add_field idx, name, mapped, flag
+
+ cpp.add_field idx, name, type, flag
idx += 1
end
@@ -365,7 +366,7 @@ def parse_stream(f)
prim = m[2]
prototype = f.gets
- m = %r!\s*(static\s+)?([\w_\*]+)\s+([\w_]+)\((.*)\)!.match(prototype)
+ m = %r!\s*(static\s+)?([\w\*]+)\s+([\w]+)\((.*)\)!.match(prototype)
args = m[4].split(/\s*,\s*/)
if args.shift != "STATE"
raise "Invalid primitive #{prim}, STATE is not first argument"
@@ -392,8 +393,25 @@ def parse_stream(f)
parser = CPPParser.new
+includes = ARGV.map do |include|
+ "#include \"#{include.sub(/^vm\//, '')}\""
+end.join "\n"
+
parser.parse_stream ARGF
+File.open 'vm/gen/includes.hpp', 'w' do |f|
+ f << <<-EOF
+#ifndef GEN_INCLUDES_HPP
+#define GEN_INCLUDES_HPP
+
+// DO NOT INCLUDE THIS IN SOMETHING THAT DOES NOT INCLUDE A GENERATED FILE
+
+#{includes}
+
+#endif
+ EOF
+end
+
File.open("vm/gen/simple_field.rb", "w") do |f|
f.puts "# DO NOT EDIT!! Autogenerate by field_extract.rb"
parser.class_order.each do |name|
@@ -452,17 +470,14 @@ def parse_stream(f)
f.puts " ti->type_name = std::string(\"#{n}\");"
f.puts " state->add_type_info(ti);"
f.puts " }"
+ f.puts
end
f.puts "}"
+ f.puts
parser.classes.each do |n, cpp|
- if tc = cpp.generate_typechecks
- f.puts tc
- end
-
- if mc = cpp.generate_mark
- f.puts mc
- end
+ f.puts cpp.generate_typechecks
+ f.puts cpp.generate_mark
end
end
View
@@ -1,10 +1,6 @@
-
#include "primitives.hpp"
#include "event.hpp"
-
-#include "builtin/fixnum.hpp"
-#include "builtin/string.hpp"
-#include "builtin/symbol.hpp"
+#include "gen/includes.hpp"
namespace rubinius {
bool Primitives::unknown_primitive(STATE, VMExecutable* exec, Task* task, Message& msg) {
View
@@ -1,10 +1,7 @@
#include "type_info.hpp"
-#include "builtin/list.hpp"
-#include "builtin/string.hpp"
-#include "builtin/float.hpp"
#include "objectmemory.hpp"
-#include "builtin/fixnum.hpp"
+#include "gen/includes.hpp"
namespace rubinius {

0 comments on commit ecc013d

Please sign in to comment.