Revision: 3126 http://trac.macosforge.org/projects/ruby/changeset/3126 Author: lsansonetti@apple.com Date: 2009-12-16 18:37:03 -0800 (Wed, 16 Dec 2009) Log Message: ----------- support LLVM's ToT, do not emit buggy subprogram dwarf entries, make sure basename and dirname fields of dwarf compile unit entries are good Modified Paths: -------------- MacRuby/trunk/compiler.cpp MacRuby/trunk/vm.cpp Modified: MacRuby/trunk/compiler.cpp =================================================================== --- MacRuby/trunk/compiler.cpp 2009-12-16 22:40:49 UTC (rev 3125) +++ MacRuby/trunk/compiler.cpp 2009-12-17 02:37:03 UTC (rev 3126) @@ -3115,11 +3115,16 @@ bb = BasicBlock::Create(context, "MainBlock", f); DISubprogram old_debug_subprogram = debug_subprogram; +#if 0 + // This is not the right way to emit subprogram DWARF entries, + // llc emits some assembly that doesn't compile because some + // symbols are duplicated. debug_subprogram = debug_info->CreateSubprogram( debug_compile_unit, f->getName(), f->getName(), f->getName(), debug_compile_unit, nd_line(node), DIType(), f->hasInternalLinkage(), true); debug_info->InsertSubprogramStart(debug_subprogram, bb); +#endif std::map<ID, Value *> old_lvars = lvars; lvars.clear(); @@ -5311,6 +5316,8 @@ return NULL; } +#include <libgen.h> + void RoxorCompiler::set_fname(const char *_fname) { @@ -5318,8 +5325,29 @@ fname = _fname; if (fname != NULL) { + // Compute complete path. + char path[PATH_MAX]; + if (*_fname == '/') { + strncpy(path, _fname, sizeof path); + } + else { + char cwd[PATH_MAX]; + getcwd(cwd, sizeof cwd); + snprintf(path, sizeof path, "%s/%s", cwd, _fname); + } + + // Split the path into 2 parts: the directory and the base. + char *dir = dirname(path); + char *base = basename(path); + + // LLVM (llc) really doesn't like when you pass empty strings for + // these values and might later throw a cryptic C++ exception that + // will take hours to investigate. How fun. + assert(strlen(dir) > 0); + assert(strlen(base) > 0); + debug_compile_unit = debug_info->CreateCompileUnit(DW_LANG_Ruby, - fname, "", RUBY_DESCRIPTION, false, false, ""); + base, dir, RUBY_DESCRIPTION, false, false, ""); } } } Modified: MacRuby/trunk/vm.cpp =================================================================== --- MacRuby/trunk/vm.cpp 2009-12-16 22:40:49 UTC (rev 3125) +++ MacRuby/trunk/vm.cpp 2009-12-17 02:37:03 UTC (rev 3126) @@ -242,8 +242,13 @@ for (std::vector<EmittedFunctionDetails::LineStart>::const_iterator iter = Details.LineStarts.begin(); iter != Details.LineStarts.end(); ++iter) { DebugLocTuple dlt = Details.MF->getDebugLocTuple(iter->Loc); if (file.size() == 0) { +#if LLVM_TOT + DICompileUnit unit(dlt.Scope); + file.append(unit.getFilename()); +#else DICompileUnit unit(dlt.CompileUnit); unit.getFilename(file); +#endif assert(file.size() != 0); } @@ -3797,7 +3802,6 @@ RoxorCompiler::shared->set_fname(RSTRING_PTR(rb_progname)); Function *f = RoxorCompiler::shared->compile_main_function(node); f->setName(RSTRING_PTR(ruby_aot_init_func)); - GET_CORE()->optimize(f); // Force a module verification. if (verifyModule(*RoxorCompiler::module, PrintMessageAction)) { @@ -3805,6 +3809,9 @@ exit(1); } + // Optimize the IR. + GET_CORE()->optimize(f); + // Dump the bitcode. std::string err; const char *output = RSTRING_PTR(ruby_aot_compile);