[macruby-changes] [2647] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 25 18:59:38 PDT 2009


Revision: 2647
          http://trac.macosforge.org/projects/ruby/changeset/2647
Author:   lsansonetti at apple.com
Date:     2009-09-25 18:59:38 -0700 (Fri, 25 Sep 2009)
Log Message:
-----------
AOT objects function names are now provided by rubyc

Modified Paths:
--------------
    MacRuby/trunk/bin/rubyc
    MacRuby/trunk/include/ruby/ruby.h
    MacRuby/trunk/ruby.c
    MacRuby/trunk/vm.cpp

Modified: MacRuby/trunk/bin/rubyc
===================================================================
--- MacRuby/trunk/bin/rubyc	2009-09-26 01:58:57 UTC (rev 2646)
+++ MacRuby/trunk/bin/rubyc	2009-09-26 01:59:38 UTC (rev 2647)
@@ -95,9 +95,12 @@
     base = File.basename(path, '.rb') 
     output ||= File.join(File.dirname(path), base + '.o')
 
+    # Generate init function (must be unique).
+    init_func = "MREP_#{File.read(path).hash}"
+
     # Compile the file into LLVM bitcode.
     bc = gen_tmpfile(base, 'bc')
-    execute("#{@macruby} --emit-llvm \"#{bc}\" \"#{path}\"")
+    execute("#{@macruby} --emit-llvm \"#{bc}\" #{init_func} \"#{path}\"")
 
     # Compile the bitcode as assembly.
     asm = gen_tmpfile(base, 's')
@@ -106,27 +109,22 @@
     # Finally compile the assembly.
     execute("#{@gcc} -c -arch x86_64 #{asm} -o #{output}")
 
-    output
+    [output, init_func]
   end
 
   def compile_bundle(file, output)
     base = File.basename(file, '.rb')
     obj = gen_tmpfile(base, 'o')
-    compile_object(file, obj)
+    obj, init_func = compile_object(file, obj)
 
     output ||= File.join(File.dirname(file), base + '.rbo')
 
-    real_init_func = guess_init_function_name(obj)
-    unless real_init_func
-      die "can't guess the init function of Ruby object file `#{obj}'"
-    end
-
     main_txt = <<EOS
 extern "C" {
-  void *#{real_init_func}(void *, void *);
+  void *#{init_func}(void *, void *);
   void *rb_vm_top_self(void);
   __attribute__((constructor)) static void __init__(void) {
-    #{real_init_func}(rb_vm_top_self(), 0);
+    #{init_func}(rb_vm_top_self(), 0);
   }
 }
 EOS
@@ -137,15 +135,11 @@
     execute("#{@gcxx} #{main} -dynamic -bundle -undefined suppress -flat_namespace -arch x86_64 #{link} #{obj} -o #{output}")
   end
 
-  def compile_executable(objs, output)
+  def compile_executable(objs_data, output)
     output ||= 'a.out'
-
-    # Guess which objects were originally MacRuby source files and memorize their init function.
+    objs = []
     init_funcs = []
-    objs.each do |file|
-      n = guess_init_function_name(file)
-      init_funcs << n if n
-    end
+    objs_data.each { |obj, init_func| objs << obj; init_funcs << init_func }
 
     # Generate main file.
     main_txt = <<EOS
@@ -201,11 +195,6 @@
     execute(line)
   end
 
-  def guess_init_function_name(file)
-    ary = execute("#{@nm} -g #{file}").scan(/^\d+\sT\s(_MREP_.*)$/)
-    ary.empty? ? nil : ary[0][0][1..-1] # drop _ prefix
-  end
-
   def execute(line)
     $stderr.puts line if @verbose
     ret = `#{line}`

Modified: MacRuby/trunk/include/ruby/ruby.h
===================================================================
--- MacRuby/trunk/include/ruby/ruby.h	2009-09-26 01:58:57 UTC (rev 2646)
+++ MacRuby/trunk/include/ruby/ruby.h	2009-09-26 01:59:38 UTC (rev 2647)
@@ -1004,7 +1004,8 @@
 
 VALUE rb_equal(VALUE,VALUE);
 
-RUBY_EXTERN VALUE ruby_verbose, ruby_debug, ruby_aot_compile;
+RUBY_EXTERN VALUE ruby_verbose, ruby_debug;
+RUBY_EXTERN VALUE ruby_aot_compile, ruby_aot_init_func;
 
 PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
 PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);

Modified: MacRuby/trunk/ruby.c
===================================================================
--- MacRuby/trunk/ruby.c	2009-09-26 01:58:57 UTC (rev 2646)
+++ MacRuby/trunk/ruby.c	2009-09-26 01:59:38 UTC (rev 2647)
@@ -45,6 +45,7 @@
 VALUE ruby_debug = Qfalse;
 VALUE ruby_verbose = Qfalse;
 VALUE ruby_aot_compile = Qfalse;
+VALUE ruby_aot_init_func = Qfalse;
 VALUE rb_parser_get_yydebug(VALUE);
 VALUE rb_parser_set_yydebug(VALUE, VALUE);
 
@@ -757,13 +758,16 @@
 		// This option is not documented and only used by macrubyc.
 		// Users should use macrubyc and never call this option
 		// directly.
-		if (argc < 2) {
+		if (argc < 3) {
 		    rb_raise(rb_eRuntimeError,
-			    "expected argument (output file) for --emit-llvm");
+			    "expected 2 arguments (output file and init function) for --emit-llvm");
 		}
 		ruby_aot_compile = rb_str_new2(argv[1]);
-		rb_objc_retain((void *)ruby_aot_compile);
+		ruby_aot_init_func = rb_str_new2(argv[2]);
+		GC_RETAIN(ruby_aot_compile);
+		GC_RETAIN(ruby_aot_init_func);
 		argc--; argv++;
+		argc--; argv++;
 	    }
 	    else {
 		rb_raise(rb_eRuntimeError,

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-09-26 01:58:57 UTC (rev 2646)
+++ MacRuby/trunk/vm.cpp	2009-09-26 01:59:38 UTC (rev 2647)
@@ -4809,26 +4809,16 @@
     return val;
 }
 
-// in st.c
-extern "C" int rb_hash_string(const char *str);
-
 extern "C"
 void
 rb_vm_aot_compile(NODE *node)
 {
     assert(ruby_aot_compile);
+    assert(ruby_aot_init_func);
 
-    const char *output = RSTRING_PTR(ruby_aot_compile);
-
-    // Generate the name of the init function.
-    char init_function_name[PATH_MAX];
-    const int hash = rb_hash_string(output);
-    snprintf(init_function_name, sizeof init_function_name,
-	    "MREP_%d", hash >= 0 ? hash : -hash);
-
     // Compile the program as IR.
     Function *f = RoxorCompiler::shared->compile_main_function(node);
-    f->setName(init_function_name);
+    f->setName(RSTRING_PTR(ruby_aot_init_func));
     GET_CORE()->optimize(f);
 
     // Force a module verification.
@@ -4839,6 +4829,7 @@
 
     // Dump the bitcode.
     std::string err;
+    const char *output = RSTRING_PTR(ruby_aot_compile);
     raw_fd_ostream out(output, err, raw_fd_ostream::F_Binary);
     if (!err.empty()) {
 	fprintf(stderr, "error when opening the output bitcode file: %s\n",
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090925/7b9eb013/attachment-0001.html>


More information about the macruby-changes mailing list