/* * gets aditionals parameters of an option if any. * <0 error. else the position in the table of the command */ static int do_short_opt( struct global *data ) { int c; int n; assert( data ); c = *(data->pt++); if( !*data->pt ) /* we finish this arg. go to the next */ { data->pt = NULL; data->i++; } n = findShortOption( data->table,c); if( n < 0 ) { n = RET_UNKNOW; report(data->flags,_("unknow option '%c'"),c); } else if( has_one_arg( data->table[n] ) ) { if( data->pt ) /* inlined argument */ { data->arg = data->pt; data->pt = NULL; data->i++; } else if ( !current_arg(data) || force_end(current_arg(data)) || ( !is_number(current_arg(data)) && is_option(current_arg(data)) ) ) { n = RET_ENOUGH; report(data->flags,_("not enough parameters for `%c'"), c); } else { data->arg = current_arg(data); data->i++; } } return n; }
void gdbWatchCB(Widget w, XtPointer client_data, XtPointer call_data) { (void) call_data; // Use it string arg = current_arg(); #if 0 // We may have different kinds of watchpoints! if (have_watchpoint_at_arg()) { // Don't place multiple watchpoints on one expression gdbUnwatchCB(w, client_data, call_data); } #endif if (arg != "" && !arg.matches(rxwhite)) gdb_command(gdb->watch_command(arg, WatchMode((int)(long)client_data)), w); }
/* * handle the long options. * returs <0 on error. * TODO: stinks */ static int do_long_option ( struct global *data ) { char *q,*arg ; int n; assert( data ); arg = current_arg(data)+2; data->i++; if( (q=strchr( arg , '=' )) ) /* separate --argument=something */ { q++; *(q-1)=0; if(!*q) q=NULL; } n = findLongOption ( data->table , arg); if( n<0 ) { n = RET_UNKNOW; report(data->flags,_("unknow long option `%s'"),arg); } else if( has_one_arg( data->table[n] ) ) { if( q ) /* inline option */ data->arg = q; else if( !current_arg(data) || force_end( current_arg(data) ) || ( !is_number(current_arg(data)) && is_option(current_arg(data)) ) ) { n = RET_ENOUGH; report(data->flags,_("not enough parameters for `%s'"), arg); } else { data->arg = current_arg(data); data->i++; } } else if( data->table[n].flags!=0) assert( 0 ); return n; }
void gdbLookupCB(Widget, XtPointer, XtPointer) { source_view->lookup(current_arg(true)); }
bool have_watchpoint_at_ref_arg() { return source_view->watchpoint_at(deref(current_arg())) != 0; }
bool have_enabled_watchpoint_at_arg() { BreakPoint *bp = source_view->watchpoint_at(current_arg()); return bp != 0 && bp->enabled(); }
void gdbSetPCCB(Widget w, XtPointer, XtPointer) { source_view->move_pc(current_arg(true), w); }
void gdbEditWatchpointPropertiesCB(Widget, XtPointer, XtPointer) { BreakPoint *bp = source_view->watchpoint_at(current_arg(true)); if (bp != 0) source_view->edit_breakpoint_properties(bp->number()); }
void gdbToggleBreakCB(Widget w, XtPointer, XtPointer) { source_view->set_bp(current_arg(true), !have_breakpoint_at_arg(), false, "", w); }
void gdbContUntilCB(Widget w, XtPointer, XtPointer) { source_view->temp_n_cont(current_arg(true), w); }
void gdbClearAtCB(Widget w, XtPointer, XtPointer) { source_view->clear_bp(current_arg(true), w); }
void gdbTempBreakAtCB(Widget w, XtPointer, XtPointer) { source_view->create_temp_bp(current_arg(true), w); }
bool have_enabled_breakpoint_at_arg() { BreakPoint *bp = source_view->breakpoint_at(current_arg(true)); return bp != 0 && bp->enabled(); }
bool have_breakpoint_at_arg() { return source_view->breakpoint_at(current_arg(true)) != 0; }
int clang_main(int argc, char ** argv, SgSourceFile& sageFile) { // 0 - Analyse Cmd Line std::vector<std::string> inc_dirs_list; std::vector<std::string> define_list; std::vector<std::string> inc_list; std::string input_file; for (int i = 0; i < argc; i++) { std::string current_arg(argv[i]); if (current_arg.find("-I") == 0) { if (current_arg.length() > 2) { inc_dirs_list.push_back(current_arg.substr(2)); } else { i++; if (i < argc) inc_dirs_list.push_back(current_arg); else break; } } else if (current_arg.find("-D") == 0) { if (current_arg.length() > 2) { define_list.push_back(current_arg.substr(2)); } else { i++; if (i < argc) define_list.push_back(current_arg); else break; } } else if (current_arg.find("-c") == 0) {} else if (current_arg.find("-o") == 0) { if (current_arg.length() == 2) { i++; if (i >= argc) break; } } else { // TODO -include #if DEBUG_ARGS std::cerr << "argv[" << i << "] = " << current_arg << " is neither define or include dir. Use it as input file." << std::endl; #endif input_file = current_arg; } } ClangToSageTranslator::Language language = ClangToSageTranslator::unknown; size_t last_period = input_file.find_last_of("."); std::string extention(input_file.substr(last_period + 1)); if (extention == "c") { language = ClangToSageTranslator::C; } else if (extention == "C" || extention == "cxx" || extention == "cpp" || extention == "cc") { language = ClangToSageTranslator::CPLUSPLUS; } else if (extention == "objc") { language = ClangToSageTranslator::OBJC; } else if (extention == "cu") { language = ClangToSageTranslator::CUDA; } else if (extention == "ocl" || extention == "cl") { language = ClangToSageTranslator::OPENCL; } ROSE_ASSERT(language != ClangToSageTranslator::unknown); const char * cxx_config_include_dirs_array [] = CXX_INCLUDE_STRING; const char * c_config_include_dirs_array [] = C_INCLUDE_STRING; std::vector<std::string> cxx_config_include_dirs ( cxx_config_include_dirs_array, cxx_config_include_dirs_array + sizeof(cxx_config_include_dirs_array) / sizeof(const char*) ); std::vector<std::string> c_config_include_dirs ( c_config_include_dirs_array, c_config_include_dirs_array + sizeof(c_config_include_dirs_array) / sizeof(const char*) ); std::string rose_include_path; bool in_install_tree = roseInstallPrefix(rose_include_path); if (in_install_tree) { rose_include_path += "/include-staging/"; } else { rose_include_path = std::string(ROSE_AUTOMAKE_TOP_BUILDDIR) + "/include-staging/"; } std::vector<std::string>::iterator it; for (it = c_config_include_dirs.begin(); it != c_config_include_dirs.end(); it++) if (it->length() > 0 && (*it)[0] != '/') *it = rose_include_path + *it; for (it = cxx_config_include_dirs.begin(); it != cxx_config_include_dirs.end(); it++) if (it->length() > 0 && (*it)[0] != '/') *it = rose_include_path + *it; inc_dirs_list.push_back(rose_include_path + "clang/"); // FIXME add ROSE path to gcc headers... switch (language) { case ClangToSageTranslator::C: inc_dirs_list.insert(inc_dirs_list.begin(), c_config_include_dirs.begin(), c_config_include_dirs.end()); inc_list.push_back("clang-builtin-c.h"); break; case ClangToSageTranslator::CPLUSPLUS: inc_dirs_list.insert(inc_dirs_list.begin(), cxx_config_include_dirs.begin(), cxx_config_include_dirs.end()); inc_list.push_back("clang-builtin-cpp.hpp"); break; case ClangToSageTranslator::CUDA: inc_dirs_list.insert(inc_dirs_list.begin(), cxx_config_include_dirs.begin(), cxx_config_include_dirs.end()); inc_list.push_back("clang-builtin-cuda.hpp"); break; case ClangToSageTranslator::OPENCL: // inc_dirs_list.insert(inc_dirs_list.begin(), c_config_include_dirs.begin(), c_config_include_dirs.end()); // FIXME get the path right inc_list.push_back("clang-builtin-opencl.h"); break; case ClangToSageTranslator::OBJC: default: ROSE_ASSERT(false); } // FIXME should be handle by Clang ? define_list.push_back("__I__=_Complex_I"); unsigned cnt = define_list.size() + inc_dirs_list.size() + inc_list.size(); char ** args = new char*[cnt]; std::vector<std::string>::iterator it_str; unsigned i = 0; for (it_str = define_list.begin(); it_str != define_list.end(); it_str++) { args[i] = new char[it_str->size() + 3]; args[i][0] = '-'; args[i][1] = 'D'; strcpy(&(args[i][2]), it_str->c_str()); #if DEBUG_ARGS std::cerr << "args[" << i << "] = " << args[i] << std::endl; #endif i++; } for (it_str = inc_dirs_list.begin(); it_str != inc_dirs_list.end(); it_str++) { args[i] = new char[it_str->size() + 3]; args[i][0] = '-'; args[i][1] = 'I'; strcpy(&(args[i][2]), it_str->c_str()); #if DEBUG_ARGS std::cerr << "args[" << i << "] = " << args[i] << std::endl; #endif i++; } for (it_str = inc_list.begin(); it_str != inc_list.end(); it_str++) { args[i] = new char[it_str->size() + 9]; args[i][0] = '-'; args[i][1] = 'i'; args[i][2] = 'n'; args[i][3] = 'c'; args[i][4] = 'l'; args[i][5] = 'u'; args[i][6] = 'd'; args[i][7] = 'e'; strcpy(&(args[i][8]), it_str->c_str()); #if DEBUG_ARGS std::cerr << "args[" << i << "] = " << args[i] << std::endl; #endif i++; } // 2 - Create a compiler instance clang::CompilerInstance * compiler_instance = new clang::CompilerInstance(); clang::TextDiagnosticPrinter * diag_printer = new clang::TextDiagnosticPrinter(llvm::errs(), clang::DiagnosticOptions()); compiler_instance->createDiagnostics(argc, argv, diag_printer, true, false); clang::CompilerInvocation * invocation = new clang::CompilerInvocation(); clang::CompilerInvocation::CreateFromArgs(*invocation, args, &(args[cnt]), compiler_instance->getDiagnostics()); compiler_instance->setInvocation(invocation); clang::LangOptions & lang_opts = compiler_instance->getLangOpts(); switch (language) { case ClangToSageTranslator::C: // compiler_instance->getInvocation().setLangDefaults(lang_opts, clang::IK_C, ); break; case ClangToSageTranslator::CPLUSPLUS: lang_opts.CPlusPlus = 1; // compiler_instance->getInvocation().setLangDefaults(lang_opts, clang::IK_CXX, ); break; case ClangToSageTranslator::CUDA: lang_opts.CUDA = 1; // lang_opts.CPlusPlus = 1; // compiler_instance->getInvocation().setLangDefaults(lang_opts, clang::IK_CUDA, clang::LangStandard::lang_cuda); break; case ClangToSageTranslator::OPENCL: lang_opts.OpenCL = 1; // compiler_instance->getInvocation().setLangDefaults(lang_opts, clang::IK_OpenCL, clang::LangStandard::lang_opencl); break; case ClangToSageTranslator::OBJC: ROSE_ASSERT(!"Objective-C is not supported by ROSE Compiler."); // compiler_instance->getInvocation().setLangDefaults(lang_opts, clang::IK_, ); default: ROSE_ASSERT(false); } clang::TargetOptions target_options; target_options.Triple = llvm::sys::getHostTriple(); clang::TargetInfo * target_info = clang::TargetInfo::CreateTargetInfo(compiler_instance->getDiagnostics(), target_options); compiler_instance->setTarget(target_info); compiler_instance->createFileManager(); compiler_instance->createSourceManager(compiler_instance->getFileManager()); const clang::FileEntry * input_file_entry = compiler_instance->getFileManager().getFile(input_file); compiler_instance->getSourceManager().createMainFileID(input_file_entry); if (!compiler_instance->hasPreprocessor()) compiler_instance->createPreprocessor(); if (!compiler_instance->hasASTContext()) compiler_instance->createASTContext(); ClangToSageTranslator translator(compiler_instance, language); compiler_instance->setASTConsumer(&translator); if (!compiler_instance->hasSema()) compiler_instance->createSema(clang::TU_Complete, NULL); ROSE_ASSERT (compiler_instance->hasDiagnostics()); ROSE_ASSERT (compiler_instance->hasTarget()); ROSE_ASSERT (compiler_instance->hasFileManager()); ROSE_ASSERT (compiler_instance->hasSourceManager()); ROSE_ASSERT (compiler_instance->hasPreprocessor()); ROSE_ASSERT (compiler_instance->hasASTContext()); ROSE_ASSERT (compiler_instance->hasSema()); // 3 - Translate compiler_instance->getDiagnosticClient().BeginSourceFile(compiler_instance->getLangOpts(), &(compiler_instance->getPreprocessor())); clang::ParseAST(compiler_instance->getPreprocessor(), &translator, compiler_instance->getASTContext()); compiler_instance->getDiagnosticClient().EndSourceFile(); SgGlobal * global_scope = translator.getGlobalScope(); // 4 - Attach to the file if (sageFile.get_globalScope() != NULL) SageInterface::deleteAST(sageFile.get_globalScope()); sageFile.set_globalScope(global_scope); global_scope->set_parent(&sageFile); std::string file_name(input_file); Sg_File_Info * start_fi = new Sg_File_Info(file_name, 0, 0); Sg_File_Info * end_fi = new Sg_File_Info(file_name, 0, 0); global_scope->set_startOfConstruct(start_fi); global_scope->set_endOfConstruct(end_fi); // 5 - Finish the AST (fixup phase) finishSageAST(translator); return 1; }