const char *tools::SplitDebugName(const ArgList &Args, const InputInfo &Input) { Arg *FinalOutput = Args.getLastArg(options::OPT_o); if (FinalOutput && Args.hasArg(options::OPT_c)) { SmallString<128> T(FinalOutput->getValue()); llvm::sys::path::replace_extension(T, "dwo"); return Args.MakeArgString(T); } else { // Use the compilation dir. SmallString<128> T( Args.getLastArgValue(options::OPT_fdebug_compilation_dir)); SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput())); llvm::sys::path::replace_extension(F, "dwo"); T += F; return Args.MakeArgString(F); } }
void Driver::PrintOptions(const ArgList &Args) const { unsigned i = 0; for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it, ++i) { Arg *A = *it; llvm::errs() << "Option " << i << " - " << "Name: \"" << A->getOption().getName() << "\", " << "Values: {"; for (unsigned j = 0; j < A->getNumValues(); ++j) { if (j) llvm::errs() << ", "; llvm::errs() << '"' << A->getValue(Args, j) << '"'; } llvm::errs() << "}\n"; } }
Arg *MultiArgOption::accept(const ArgList &Args, unsigned &Index) const { // Matches iff this is an exact match. // FIXME: Avoid strlen. if (strlen(getName()) != strlen(Args.getArgString(Index))) return 0; Index += 1 + NumArgs; if (Index > Args.getNumInputArgStrings()) return 0; Arg *A = new Arg(getUnaliasedOption(), Index - 1 - NumArgs, Args.getArgString(Index - NumArgs)); for (unsigned i = 1; i != NumArgs; ++i) A->getValues().push_back(Args.getArgString(Index - NumArgs + i)); return A; }
void send_sample(int ctrix) { boost::shared_ptr<std::string> sp(new std::string(counterNames_[ctrix])); (*sp) += " "; (*sp) += boost::lexical_cast<std::string>(counter_value(ctrix)); (*sp) += "\r\n"; async_write(socket_, buffer(sp->c_str(), sp->size()), boost::bind(&send_done, sp, placeholders::error, placeholders::bytes_transferred)); ++ctrix; if (ctrix == (int)counterNames_.size()) { ctrix = 0; } ++totalCount_; // make sure there's no race in ctrl-C sigset_t sset; sigemptyset(&sset); sigaddset(&sset, SIGINT); sigaddset(&sset, SIGHUP); sigprocmask(SIG_BLOCK, &sset, NULL); if (0 < num.get() - totalCount_ && running_) { start_timer(ctrix); } sigemptyset(&sset); sigaddset(&sset, SIGINT); sigaddset(&sset, SIGHUP); sigprocmask(SIG_UNBLOCK, &sset, NULL); }
void calculate_counters() { std::vector<int> numbers; for (int i = 1000; i < 33768; ++i) { numbers.push_back(i); } // the shuffle is the same for all seeds, even if the number // of counters used is different for each for (int i = 0; i < 32768; ++i) { std::swap(numbers[i], numbers[rand() & 0x7fff]); } numbers.resize(counters.get()); for (size_t i = 0; i < numbers.size(); ++i) { std::string s; int val = numbers[i]; do { int dig = val % 10; if (s.size()) { s += "."; } s += counterStems[dig]; val = val / 10; } while (val > 0); counterNames_.push_back(s); } }
TEST(Arg, isReadOk)//Test avec 3 arguments correct lecture fichier { argvRead[1] = "--file"; argvRead[2] = "input.csv"; ReadArgTest.readArg(3,argvRead,&state, &newdata); EXPECT_EQ(READ, state); }
TEST(Arg, isErrorPhoneOnlyOk)//Test avec 2 arguments mais mauvais syntaxe { argvErrorPhoneOnly[1] = "--phone"; ErrorPhoneOnly.readArg(2, argvErrorPhoneOnly, &state, &newdata); EXPECT_EQ(ERROR, state); // When done redirect cout to its old self std::cout.rdbuf(sbuf); }
Arg *ArgList::getLastArg(OptSpecifier Id0, OptSpecifier Id1, OptSpecifier Id2, OptSpecifier Id3, OptSpecifier Id4) const { Arg *Res = nullptr; for (const_iterator it = begin(), ie = end(); it != ie; ++it) { if ((*it)->getOption().matches(Id0) || (*it)->getOption().matches(Id1) || (*it)->getOption().matches(Id2) || (*it)->getOption().matches(Id3) || (*it)->getOption().matches(Id4)) { Res = *it; Res->claim(); } } return Res; }
void aarch64::getAArch64TargetFeatures(const Driver &D, const ArgList &Args, std::vector<StringRef> &Features) { Arg *A; bool success = true; // Enable NEON by default. Features.push_back("+neon"); if ((A = Args.getLastArg(options::OPT_march_EQ))) success = getAArch64ArchFeaturesFromMarch(D, A->getValue(), Args, Features); else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features); else if (Args.hasArg(options::OPT_arch)) success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args, A), Args, Features); if (success && (A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ))) success = getAArch64MicroArchFeaturesFromMtune(D, A->getValue(), Args, Features); else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ))) success = getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features); else if (success && Args.hasArg(options::OPT_arch)) success = getAArch64MicroArchFeaturesFromMcpu( D, getAArch64TargetCPU(Args, A), Args, Features); if (!success) D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); if (Args.getLastArg(options::OPT_mgeneral_regs_only)) { Features.push_back("-fp-armv8"); Features.push_back("-crypto"); Features.push_back("-neon"); } // En/disable crc if (Arg *A = Args.getLastArg(options::OPT_mcrc, options::OPT_mnocrc)) { if (A->getOption().matches(options::OPT_mcrc)) Features.push_back("+crc"); else Features.push_back("-crc"); } if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) if (A->getOption().matches(options::OPT_mno_unaligned_access)) Features.push_back("+strict-align"); if (Args.hasArg(options::OPT_ffixed_x18)) Features.push_back("+reserve-x18"); if (Args.hasArg(options::OPT_ffixed_x20)) Features.push_back("+reserve-x20"); if (Args.hasArg(options::OPT_mno_neg_immediates)) Features.push_back("+no-neg-immediates"); }
/** Send a create composite task to a target worker * @param wi a worker information that will execute this CreateComposite task * @param name a name of Composite array that will be created * @param name arg argument that contains information about splits that will build a composite array * @param id an ID of this task (Generally 0) * @param uid a real ID of this task * @return NULL */ static void dispatch_createcomposite(WorkerInfo *wi, const string &name, const Arg &carg, const std::vector<Arg>* task_args, ::uint64_t id, ::uint64_t uid, ::uint64_t parentid) { CreateCompositeRequest req; req.set_name(name); for (int j = 0; j < carg.arrays_size(); j++) { NewArg arg; arg.set_varname(carg.name()); arg.set_arrayname(carg.arrays(j).name()); req.add_cargs()->CopyFrom(arg); //req.add_arraynames(carg.arrays(j).name()); req.add_offsets()->CopyFrom(carg.offsets(j)); } req.mutable_dims()->CopyFrom(carg.dim()); if(task_args !=NULL && DATASTORE == RINSTANCE) { for (int i = 0; i < task_args->size(); i++) { if ((*task_args)[i].arrays_size() == 1 || (*task_args)[i].is_list()) { NewArg arg; arg.set_varname((*task_args)[i].name()); if((*task_args)[i].is_list()){ for(int j = 0; j < (*task_args)[i].arrays_size(); j ++){ arg.add_list_arraynames((*task_args)[i].arrays(j).name()); } arg.set_arrayname("list_type..."); }else{ arg.set_arrayname((*task_args)[i].arrays(0).name()); } req.add_task_args()->CopyFrom(arg); } } } req.set_id(id); req.set_uid(uid); req.set_parenttaskid(parentid); wi->CreateComposite(req); LOG_INFO("CREATECOMPOSITE Create TaskID %6d - Sent to Worker %s", static_cast<int>(uid), wi->hostname().c_str()); }
static DebugInfoKind mustEmitDebugInfo(const ArgList &Args) { Arg *A = Args.getLastArg(options::OPT_O_Group); if (Args.hasFlag(options::OPT_cuda_noopt_device_debug, options::OPT_no_cuda_noopt_device_debug, !A || A->getOption().matches(options::OPT_O0))) { if (const Arg *A = Args.getLastArg(options::OPT_g_Group)) { const Option &Opt = A->getOption(); if (Opt.matches(options::OPT_gN_Group)) { if (Opt.matches(options::OPT_g0) || Opt.matches(options::OPT_ggdb0)) return NoDebug; if (Opt.matches(options::OPT_gline_tables_only) || Opt.matches(options::OPT_ggdb1)) return LineTableOnly; } return FullDebug; } } return NoDebug; }
bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args, ArgStringList &CmdArgs) const { // Check if -ffast-math or -funsafe-math is enabled. Arg *A = Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations); if (!A || A->getOption().getID() == options::OPT_fno_fast_math || A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) return false; // If crtfastmath.o exists add it to the arguments. std::string Path = GetFilePath("crtfastmath.o"); if (Path == "crtfastmath.o") // Not found. return false; CmdArgs.push_back(Args.MakeArgString(Path)); return true; }
virtual void run (Arg arg) { string pipeID = isnil (arg)? "Black Hole" : arg[1]; string streamID = 2>arg.size()? "teststream" : arg[2] ; createExplicit (pipeID,streamID); create_or_ref (pipeID); create_using_default (); dependProcPatt (pipeID); }
virtual void run (Arg arg) { int range = 0 < arg.size()? lexical_cast<int> (arg[0]) : 12; int scale = 1 < arg.size()? lexical_cast<int> (arg[1]) : 4; checkWrap (range, scale); checkWrap (range, -scale); checkWrap<long> (range, scale); checkWrap<long> (range, -scale); }
InputArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); InputArgList *Args = new InputArgList(ArgBegin, ArgEnd); // FIXME: Handle '@' args (or at least error on them). unsigned Index = 0, End = ArgEnd - ArgBegin; while (Index < End) { // gcc's handling of empty arguments doesn't make // sense, but this is not a common use case. :) // // We just ignore them here (note that other things may // still take them as arguments). if (Args->getArgString(Index)[0] == '\0') { ++Index; continue; } unsigned Prev = Index; Arg *A = getOpts().ParseOneArg(*Args, Index); assert(Index > Prev && "Parser failed to consume argument."); // Check for missing argument error. if (!A) { assert(Index >= End && "Unexpected parser error."); Diag(clang::diag::err_drv_missing_argument) << Args->getArgString(Prev) << (Index - Prev - 1); break; } if (A->getOption().isUnsupported()) { Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args); continue; } Args->append(A); } return Args; }
bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args, ArgStringList &CmdArgs) const { // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed // (to keep the linker options consistent with gcc and clang itself). if (!isOptimizationLevelFast(Args)) { // Check if -ffast-math or -funsafe-math. Arg *A = Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math, options::OPT_funsafe_math_optimizations, options::OPT_fno_unsafe_math_optimizations); if (!A || A->getOption().getID() == options::OPT_fno_fast_math || A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) return false; } // If crtfastmath.o exists add it to the arguments. std::string Path = GetFilePath("crtfastmath.o"); if (Path == "crtfastmath.o") // Not found. return false; CmdArgs.push_back(Args.MakeArgString(Path)); return true; }
virtual void run (Arg arg) { if (0 < arg.size()) NUM_ELMS = lexical_cast<uint> (arg[1]); verify_simpleIters(); verify_transformIter(); verify_MapWrappers<TreeMap>(); verify_MapWrappers<HashMap>(); verify_MultimapIters<TreeMultimap>(); verify_MultimapIters<HashMultimap>(); }
bool PatchpointSpecial::isValid(Inst& inst) { PatchpointValue* patchpoint = inst.origin->as<PatchpointValue>(); unsigned argIndex = 1; if (inst.origin->type() != Void) { if (argIndex >= inst.args.size()) return false; if (!isArgValidForValue(inst.args[argIndex], patchpoint)) return false; if (!isArgValidForRep(code(), inst.args[argIndex], patchpoint->resultConstraint)) return false; argIndex++; } if (!isValidImpl(0, argIndex, inst)) return false; argIndex += patchpoint->numChildren(); if (argIndex + patchpoint->numGPScratchRegisters + patchpoint->numFPScratchRegisters != inst.args.size()) return false; for (unsigned i = patchpoint->numGPScratchRegisters; i--;) { Arg arg = inst.args[argIndex++]; if (!arg.isGPTmp()) return false; } for (unsigned i = patchpoint->numFPScratchRegisters; i--;) { Arg arg = inst.args[argIndex++]; if (!arg.isFPTmp()) return false; } return true; }
InputArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); unsigned MissingArgIndex, MissingArgCount; InputArgList *Args = getOpts().ParseArgs(ArgBegin, ArgEnd, MissingArgIndex, MissingArgCount); // Check for missing argument error. if (MissingArgCount) Diag(clang::diag::err_drv_missing_argument) << Args->getArgString(MissingArgIndex) << MissingArgCount; // Check for unsupported options. for (ArgList::const_iterator it = Args->begin(), ie = Args->end(); it != ie; ++it) { Arg *A = *it; if (A->getOption().isUnsupported()) { Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(*Args); continue; } } return Args; }
sge::d3d9::state::ffp::sampler::state const make_one_arg( Arg const _arg ) { return sge::d3d9::state::ffp::sampler::state( sge::d3d9::state::convert::sampler_arg_type< OpType, Arg >::get(), sge::d3d9::state::convert::sampler_arg( _arg.get() ) ); }
TEST(Arg, isWriteOk)//Test avec 13 arguments correct ecriture fichier { argvWrite[1] = "--name"; argvWrite[2] = "toto"; argvWrite[3] = "--phone"; argvWrite[4] = "1234"; argvWrite[5] = "--expense"; argvWrite[6] = "200"; argvWrite[7] = "--group"; argvWrite[8] = "Righi"; argvWrite[9] = "--type"; argvWrite[10] = "Donor"; argvWrite[11] = "--file"; argvWrite[12] = "input.csv"; WriteArgTest.readArg(13, argvWrite, &state, &newdata); EXPECT_EQ("toto,1234,200,Righi,Donor\n", newdata); EXPECT_EQ(WRITE, state); }
ValueRep StackmapSpecial::repForArg(Code& code, const Arg& arg) { switch (arg.kind()) { case Arg::Tmp: return ValueRep::reg(arg.reg()); break; case Arg::Imm: case Arg::Imm64: return ValueRep::constant(arg.value()); break; case Arg::Addr: if (arg.base() == Tmp(GPRInfo::callFrameRegister)) return ValueRep::stack(arg.offset()); ASSERT(arg.base() == Tmp(MacroAssembler::stackPointerRegister)); return ValueRep::stack(arg.offset() - code.frameSize()); default: ASSERT_NOT_REACHED(); return ValueRep(); } }
unsigned HexagonToolChain::getOptimizationLevel( const llvm::opt::ArgList &DriverArgs) const { // Copied in large part from lib/Frontend/CompilerInvocation.cpp. Arg *A = DriverArgs.getLastArg(options::OPT_O_Group); if (!A) return 0; if (A->getOption().matches(options::OPT_O0)) return 0; if (A->getOption().matches(options::OPT_Ofast) || A->getOption().matches(options::OPT_O4)) return 3; assert(A->getNumValues() != 0); StringRef S(A->getValue()); if (S == "s" || S == "z" || S.empty()) return 2; if (S == "g") return 1; unsigned OptLevel; if (S.getAsInteger(10, OptLevel)) return 0; return OptLevel; }
void Driver::BuildJobs(Compilation &C) const { llvm::PrettyStackTraceString CrashInfo("Building compilation jobs"); bool SaveTemps = C.getArgs().hasArg(options::OPT_save_temps); bool UsePipes = C.getArgs().hasArg(options::OPT_pipe); // FIXME: Pipes are forcibly disabled until we support executing // them. if (!CCCPrintBindings) UsePipes = false; // -save-temps inhibits pipes. if (SaveTemps && UsePipes) { Diag(clang::diag::warn_drv_pipe_ignored_with_save_temps); UsePipes = true; } Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o); // It is an error to provide a -o option if we are making multiple // output files. if (FinalOutput) { unsigned NumOutputs = 0; for (ActionList::const_iterator it = C.getActions().begin(), ie = C.getActions().end(); it != ie; ++it) if ((*it)->getType() != types::TY_Nothing) ++NumOutputs; if (NumOutputs > 1) { Diag(clang::diag::err_drv_output_argument_with_multiple_files); FinalOutput = 0; } } for (ActionList::const_iterator it = C.getActions().begin(), ie = C.getActions().end(); it != ie; ++it) { Action *A = *it; // If we are linking an image for multiple archs then the linker // wants -arch_multiple and -final_output <final image // name>. Unfortunately, this doesn't fit in cleanly because we // have to pass this information down. // // FIXME: This is a hack; find a cleaner way to integrate this // into the process. const char *LinkingOutput = 0; if (isa<LipoJobAction>(A)) { if (FinalOutput) LinkingOutput = FinalOutput->getValue(C.getArgs()); else LinkingOutput = DefaultImageName.c_str(); } InputInfo II; BuildJobsForAction(C, A, &C.getDefaultToolChain(), /*CanAcceptPipe*/ true, /*AtTopLevel*/ true, /*LinkingOutput*/ LinkingOutput, II); } // If the user passed -Qunused-arguments or there were errors, don't // warn about any unused arguments. if (Diags.getNumErrors() || C.getArgs().hasArg(options::OPT_Qunused_arguments)) return; // Claim -### here. (void) C.getArgs().hasArg(options::OPT__HASH_HASH_HASH); for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end(); it != ie; ++it) { Arg *A = *it; // FIXME: It would be nice to be able to send the argument to the // Diagnostic, so that extra values, position, and so on could be // printed. if (!A->isClaimed()) { if (A->getOption().hasNoArgumentUnused()) continue; // Suppress the warning automatically if this is just a flag, // and it is an instance of an argument we already claimed. const Option &Opt = A->getOption(); if (isa<FlagOption>(Opt)) { bool DuplicateClaimed = false; // FIXME: Use iterator. for (ArgList::const_iterator it = C.getArgs().begin(), ie = C.getArgs().end(); it != ie; ++it) { if ((*it)->isClaimed() && (*it)->getOption().matches(Opt.getId())) { DuplicateClaimed = true; break; } } if (DuplicateClaimed) continue; } Diag(clang::diag::warn_drv_unused_argument) << A->getAsString(C.getArgs()); } } }
void Driver::BuildActions(const ArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building compilation actions"); // Start by constructing the list of inputs and their types. // Track the current user specified (-x) input. We also explicitly // track the argument used to set the type; we only want to claim // the type when we actually use it, so we warn about unused -x // arguments. types::ID InputType = types::TY_Nothing; Arg *InputTypeArg = 0; llvm::SmallVector<std::pair<types::ID, const Arg*>, 16> Inputs; for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { Arg *A = *it; if (isa<InputOption>(A->getOption())) { const char *Value = A->getValue(Args); types::ID Ty = types::TY_INVALID; // Infer the input type if necessary. if (InputType == types::TY_Nothing) { // If there was an explicit arg for this, claim it. if (InputTypeArg) InputTypeArg->claim(); // stdin must be handled specially. if (memcmp(Value, "-", 2) == 0) { // If running with -E, treat as a C input (this changes the // builtin macros, for example). This may be overridden by // -ObjC below. // // Otherwise emit an error but still use a valid type to // avoid spurious errors (e.g., no inputs). if (!Args.hasArg(options::OPT_E, false)) Diag(clang::diag::err_drv_unknown_stdin_type); Ty = types::TY_C; } else { // Otherwise lookup by extension, and fallback to ObjectType // if not found. We use a host hook here because Darwin at // least has its own idea of what .s is. if (const char *Ext = strrchr(Value, '.')) Ty = Host->lookupTypeForExtension(Ext + 1); if (Ty == types::TY_INVALID) Ty = types::TY_Object; } // -ObjC and -ObjC++ override the default language, but only for "source // files". We just treat everything that isn't a linker input as a // source file. // // FIXME: Clean this up if we move the phase sequence into the type. if (Ty != types::TY_Object) { if (Args.hasArg(options::OPT_ObjC)) Ty = types::TY_ObjC; else if (Args.hasArg(options::OPT_ObjCXX)) Ty = types::TY_ObjCXX; } } else { assert(InputTypeArg && "InputType set w/o InputTypeArg"); InputTypeArg->claim(); Ty = InputType; } // Check that the file exists. It isn't clear this is worth // doing, since the tool presumably does this anyway, and this // just adds an extra stat to the equation, but this is gcc // compatible. if (memcmp(Value, "-", 2) != 0 && !llvm::sys::Path(Value).exists()) Diag(clang::diag::err_drv_no_such_file) << A->getValue(Args); else Inputs.push_back(std::make_pair(Ty, A)); } else if (A->getOption().isLinkerInput()) { // Just treat as object type, we could make a special type for // this if necessary. Inputs.push_back(std::make_pair(types::TY_Object, A)); } else if (A->getOption().getId() == options::OPT_x) { InputTypeArg = A; InputType = types::lookupTypeForTypeSpecifier(A->getValue(Args)); // Follow gcc behavior and treat as linker input for invalid -x // options. Its not clear why we shouldn't just revert to // unknown; but this isn't very important, we might as well be // bug comatible. if (!InputType) { Diag(clang::diag::err_drv_unknown_language) << A->getValue(Args); InputType = types::TY_Object; } } } if (!SuppressMissingInputWarning && Inputs.empty()) { Diag(clang::diag::err_drv_no_input_files); return; } // Determine which compilation mode we are in. We look for options // which affect the phase, starting with the earliest phases, and // record which option we used to determine the final phase. Arg *FinalPhaseArg = 0; phases::ID FinalPhase; // -{E,M,MM} only run the preprocessor. if ((FinalPhaseArg = Args.getLastArg(options::OPT_E)) || (FinalPhaseArg = Args.getLastArg(options::OPT_M)) || (FinalPhaseArg = Args.getLastArg(options::OPT_MM))) { FinalPhase = phases::Preprocess; // -{fsyntax-only,-analyze,emit-llvm,S} only run up to the compiler. } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_fsyntax_only)) || (FinalPhaseArg = Args.getLastArg(options::OPT__analyze, options::OPT__analyze_auto)) || (FinalPhaseArg = Args.getLastArg(options::OPT_S))) { FinalPhase = phases::Compile; // -c only runs up to the assembler. } else if ((FinalPhaseArg = Args.getLastArg(options::OPT_c))) { FinalPhase = phases::Assemble; // Otherwise do everything. } else FinalPhase = phases::Link; // Reject -Z* at the top level, these options should never have been // exposed by gcc. if (Arg *A = Args.getLastArg(options::OPT_Z_Joined)) Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args); // Construct the actions to perform. ActionList LinkerInputs; for (unsigned i = 0, e = Inputs.size(); i != e; ++i) { types::ID InputType = Inputs[i].first; const Arg *InputArg = Inputs[i].second; unsigned NumSteps = types::getNumCompilationPhases(InputType); assert(NumSteps && "Invalid number of steps!"); // If the first step comes after the final phase we are doing as // part of this compilation, warn the user about it. phases::ID InitialPhase = types::getCompilationPhase(InputType, 0); if (InitialPhase > FinalPhase) { // Claim here to avoid the more general unused warning. InputArg->claim(); Diag(clang::diag::warn_drv_input_file_unused) << InputArg->getAsString(Args) << getPhaseName(InitialPhase) << FinalPhaseArg->getOption().getName(); continue; } // Build the pipeline for this file. Action *Current = new InputAction(*InputArg, InputType); for (unsigned i = 0; i != NumSteps; ++i) { phases::ID Phase = types::getCompilationPhase(InputType, i); // We are done if this step is past what the user requested. if (Phase > FinalPhase) break; // Queue linker inputs. if (Phase == phases::Link) { assert(i + 1 == NumSteps && "linking must be final compilation step."); LinkerInputs.push_back(Current); Current = 0; break; } // Some types skip the assembler phase (e.g., llvm-bc), but we // can't encode this in the steps because the intermediate type // depends on arguments. Just special case here. if (Phase == phases::Assemble && Current->getType() != types::TY_PP_Asm) continue; // Otherwise construct the appropriate action. Current = ConstructPhaseAction(Args, Phase, Current); if (Current->getType() == types::TY_Nothing) break; } // If we ended with something, add to the output list. if (Current) Actions.push_back(Current); } // Add a link action if necessary. if (!LinkerInputs.empty()) Actions.push_back(new LinkJobAction(LinkerInputs, types::TY_Image)); }
void Driver::BuildUniversalActions(const ArgList &Args, ActionList &Actions) const { llvm::PrettyStackTraceString CrashInfo("Building actions for universal build"); // Collect the list of architectures. Duplicates are allowed, but // should only be handled once (in the order seen). llvm::StringSet<> ArchNames; llvm::SmallVector<const char *, 4> Archs; for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); it != ie; ++it) { Arg *A = *it; if (A->getOption().getId() == options::OPT_arch) { const char *Name = A->getValue(Args); // FIXME: We need to handle canonicalization of the specified // arch? A->claim(); if (ArchNames.insert(Name)) Archs.push_back(Name); } } // When there is no explicit arch for this platform, make sure we // still bind the architecture (to the default) so that -Xarch_ is // handled correctly. if (!Archs.size()) Archs.push_back(0); // FIXME: We killed off some others but these aren't yet detected in // a functional manner. If we added information to jobs about which // "auxiliary" files they wrote then we could detect the conflict // these cause downstream. if (Archs.size() > 1) { // No recovery needed, the point of this is just to prevent // overwriting the same files. if (const Arg *A = Args.getLastArg(options::OPT_save_temps)) Diag(clang::diag::err_drv_invalid_opt_with_multiple_archs) << A->getAsString(Args); } ActionList SingleActions; BuildActions(Args, SingleActions); // Add in arch binding and lipo (if necessary) for every top level // action. for (unsigned i = 0, e = SingleActions.size(); i != e; ++i) { Action *Act = SingleActions[i]; // Make sure we can lipo this kind of output. If not (and it is an // actual output) then we disallow, since we can't create an // output file with the right name without overwriting it. We // could remove this oddity by just changing the output names to // include the arch, which would also fix // -save-temps. Compatibility wins for now. if (Archs.size() > 1 && !types::canLipoType(Act->getType())) Diag(clang::diag::err_drv_invalid_output_with_multiple_archs) << types::getTypeName(Act->getType()); ActionList Inputs; for (unsigned i = 0, e = Archs.size(); i != e; ++i) Inputs.push_back(new BindArchAction(Act, Archs[i])); // Lipo if necessary, We do it this way because we need to set the // arch flag so that -Xarch_ gets overwritten. if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing) Actions.append(Inputs.begin(), Inputs.end()); else Actions.push_back(new LipoJobAction(Inputs, Act->getType())); } }
//////////////////////////////////////////////////////////////////////////////// ///Parse function declaration after ifc_fn bool MethodIG::parse( iglexer& lex, const charstr& host, const charstr& ns, dynarray<Arg>& irefargs ) { bstatic = lex.match_optional("static"); //rettype fncname '(' ... if(!ret.parse(lex, false)) throw lex.exc(); bhasifctargets = !ret.ifctarget.is_empty(); if(!bstatic && ret.biref) ret.add_unique(irefargs); biref=bptr=false; if(bstatic) { charstr tmp; if(ret.bptr && ret.type == ((tmp=host)<<'*')) { (ret.type="iref<")<<ns<<host<<'>'; } else if(ret.type == ((tmp="iref<")<<host<<'>')) { biref = true; (ret.type="iref<")<<ns<<host<<'>'; } else if(ret.type == ((tmp="iref<")<<ns<<host<<'>')) biref = true; //else if(ret.type == ((tmp="ref<")<<ns<<host<<'>')) // ; //else if(ret.type == ((tmp=ns)<<host<<'*')) // bptr = true; else { lex.set_err() << "invalid return type for static interface creator method\n" " should be iref<" << host << ">"; throw lex.exc(); } storage = ret.type; } lex.match(lex.IDENT, name, "expected method name"); boperator = name == "operator"; if(boperator) { lex.match('('); lex.match(')'); name << "()"; } binternal = binternal || name.first_char() == '_'; lex.match('('); ninargs = noutargs = 0; if(!lex.matches(')')) { do { if( !args.add()->parse(lex, true) ) throw lex.exc(); Arg* arg = args.last(); if(arg->binarg) { ++ninargs; if(!arg->defval) ++ninargs_nondef; } if(arg->boutarg) ++noutargs; arg->tokenpar = arg->binarg && (arg->basetype=="token" || arg->basetype=="coid::token" || arg->basetype=="charstr" || arg->basetype=="coid::charstr"); if(!bstatic && arg->biref && arg->boutarg) arg->add_unique(irefargs); if(arg->ifctarget) bhasifctargets = true; } while(lex.matches(',')); lex.match(')'); } bconst = lex.matches("const"); //optional default event impl bool evbody = lex.matches(lex.IFC_EVBODY); if(evbody) { default_event_body = lex.match_block(lex.ROUND, true); if(default_event_body.first_char() == '"') { default_event_body.del(0, 1); if(default_event_body.last_char() == '"') default_event_body.resize(-1); } if(default_event_body.first_char() != '{') { default_event_body.ins(0, '{'); default_event_body << '}'; } } //else // default_event_body = "{ throw coid::exception(\"handler not implemented\"); }"; bmandatory = !evbody && (ret.type != "void" || noutargs > 0); //declaration parsed successfully return lex.no_err(); }
Arg *Option::accept(const ArgList &Args, unsigned &Index, unsigned ArgSize) const { const Option &UnaliasedOption = getUnaliasedOption(); StringRef Spelling; // If the option was an alias, get the spelling from the unaliased one. if (getID() == UnaliasedOption.getID()) { Spelling = StringRef(Args.getArgString(Index), ArgSize); } else { Spelling = Args.MakeArgString(Twine(UnaliasedOption.getPrefix()) + Twine(UnaliasedOption.getName())); } switch (getKind()) { case FlagClass: { if (ArgSize != strlen(Args.getArgString(Index))) return nullptr; Arg *A = new Arg(UnaliasedOption, Spelling, Index++); if (getAliasArgs()) { const char *Val = getAliasArgs(); while (*Val != '\0') { A->getValues().push_back(Val); // Move past the '\0' to the next argument. Val += strlen(Val) + 1; } } return A; } case JoinedClass: { const char *Value = Args.getArgString(Index) + ArgSize; return new Arg(UnaliasedOption, Spelling, Index++, Value); } case CommaJoinedClass: { // Always matches. const char *Str = Args.getArgString(Index) + ArgSize; Arg *A = new Arg(UnaliasedOption, Spelling, Index++); // Parse out the comma separated values. const char *Prev = Str; for (;; ++Str) { char c = *Str; if (!c || c == ',') { if (Prev != Str) { char *Value = new char[Str - Prev + 1]; memcpy(Value, Prev, Str - Prev); Value[Str - Prev] = '\0'; A->getValues().push_back(Value); } if (!c) break; Prev = Str + 1; } } A->setOwnsValues(true); return A; } case SeparateClass: // Matches iff this is an exact match. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) return nullptr; Index += 2; if (Index > Args.getNumInputArgStrings()) return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 1)); case MultiArgClass: { // Matches iff this is an exact match. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) return nullptr; Index += 1 + getNumArgs(); if (Index > Args.getNumInputArgStrings()) return nullptr; Arg *A = new Arg(UnaliasedOption, Spelling, Index - 1 - getNumArgs(), Args.getArgString(Index - getNumArgs())); for (unsigned i = 1; i != getNumArgs(); ++i) A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i)); return A; } case JoinedOrSeparateClass: { // If this is not an exact match, it is a joined arg. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) { const char *Value = Args.getArgString(Index) + ArgSize; return new Arg(*this, Spelling, Index++, Value); } // Otherwise it must be separate. Index += 2; if (Index > Args.getNumInputArgStrings()) return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 1)); } case JoinedAndSeparateClass: // Always matches. Index += 2; if (Index > Args.getNumInputArgStrings()) return nullptr; return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 2) + ArgSize, Args.getArgString(Index - 1)); case RemainingArgsClass: { // Matches iff this is an exact match. // FIXME: Avoid strlen. if (ArgSize != strlen(Args.getArgString(Index))) return nullptr; Arg *A = new Arg(UnaliasedOption, Spelling, Index++); while (Index < Args.getNumInputArgStrings()) A->getValues().push_back(Args.getArgString(Index++)); return A; } default: llvm_unreachable("Invalid option kind!"); } }
Arg *Option::accept(const ArgList &Args, unsigned &Index) const { switch (getKind()) { case FlagClass: if (getName().size() != strlen(Args.getArgString(Index))) return 0; return new Arg(getUnaliasedOption(), Index++); case JoinedClass: { const char *Value = Args.getArgString(Index) + getName().size(); return new Arg(getUnaliasedOption(), Index++, Value); } case CommaJoinedClass: { // Always matches. const char *Str = Args.getArgString(Index) + getName().size(); Arg *A = new Arg(getUnaliasedOption(), Index++); // Parse out the comma separated values. const char *Prev = Str; for (;; ++Str) { char c = *Str; if (!c || c == ',') { if (Prev != Str) { char *Value = new char[Str - Prev + 1]; memcpy(Value, Prev, Str - Prev); Value[Str - Prev] = '\0'; A->getValues().push_back(Value); } if (!c) break; Prev = Str + 1; } } A->setOwnsValues(true); return A; } case SeparateClass: // Matches iff this is an exact match. // FIXME: Avoid strlen. if (getName().size() != strlen(Args.getArgString(Index))) return 0; Index += 2; if (Index > Args.getNumInputArgStrings()) return 0; return new Arg(getUnaliasedOption(), Index - 2, Args.getArgString(Index - 1)); case MultiArgClass: { // Matches iff this is an exact match. // FIXME: Avoid strlen. if (getName().size() != strlen(Args.getArgString(Index))) return 0; Index += 1 + getNumArgs(); if (Index > Args.getNumInputArgStrings()) return 0; Arg *A = new Arg(getUnaliasedOption(), Index - 1 - getNumArgs(), Args.getArgString(Index - getNumArgs())); for (unsigned i = 1; i != getNumArgs(); ++i) A->getValues().push_back(Args.getArgString(Index - getNumArgs() + i)); return A; } case JoinedOrSeparateClass: { // If this is not an exact match, it is a joined arg. // FIXME: Avoid strlen. if (getName().size() != strlen(Args.getArgString(Index))) { const char *Value = Args.getArgString(Index) + getName().size(); return new Arg(this, Index++, Value); } // Otherwise it must be separate. Index += 2; if (Index > Args.getNumInputArgStrings()) return 0; return new Arg(getUnaliasedOption(), Index - 2, Args.getArgString(Index - 1)); } case JoinedAndSeparateClass: // Always matches. Index += 2; if (Index > Args.getNumInputArgStrings()) return 0; return new Arg(getUnaliasedOption(), Index - 2, Args.getArgString(Index-2)+getName().size(), Args.getArgString(Index-1)); default: llvm_unreachable("Invalid option kind!"); } }
void operator()(Arg &arg) const { arg.on_exec_error(e_); }