bool ToolInvocation::run() { std::vector<const char*> Argv; for (const std::string &Str : CommandLine) Argv.push_back(Str.c_str()); const char *const BinaryName = Argv[0]; IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); TextDiagnosticPrinter DiagnosticPrinter( llvm::errs(), &*DiagOpts); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); const std::unique_ptr<clang::driver::Driver> Driver( newDriver(&Diagnostics, BinaryName)); // Since the input might only be virtual, don't check whether it exists. Driver->setCheckInputsExist(false); const std::unique_ptr<clang::driver::Compilation> Compilation( Driver->BuildCompilation(llvm::makeArrayRef(Argv))); const llvm::opt::ArgStringList *const CC1Args = getCC1Arguments( &Diagnostics, Compilation.get()); if (CC1Args == NULL) { return false; } std::unique_ptr<clang::CompilerInvocation> Invocation( newInvocation(&Diagnostics, *CC1Args)); for (const auto &It : MappedFileContents) { // Inject the code as the given file name into the preprocessor options. auto *Input = llvm::MemoryBuffer::getMemBuffer(It.getValue()); Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(), Input); } return runInvocation(BinaryName, Compilation.get(), Invocation.release()); }
bool ToolInvocation::run() { std::vector<const char*> Argv; for (int I = 0, E = CommandLine.size(); I != E; ++I) Argv.push_back(CommandLine[I].c_str()); const char *const BinaryName = Argv[0]; DiagnosticOptions DefaultDiagnosticOptions; TextDiagnosticPrinter DiagnosticPrinter( llvm::errs(), DefaultDiagnosticOptions); DiagnosticsEngine Diagnostics(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>( new DiagnosticIDs()), &DiagnosticPrinter, false); const llvm::OwningPtr<clang::driver::Driver> Driver( newDriver(&Diagnostics, BinaryName)); // Since the input might only be virtual, don't check whether it exists. Driver->setCheckInputsExist(false); const llvm::OwningPtr<clang::driver::Compilation> Compilation( Driver->BuildCompilation(llvm::makeArrayRef(Argv))); const clang::driver::ArgStringList *const CC1Args = getCC1Arguments( &Diagnostics, Compilation.get()); if (CC1Args == NULL) { return false; } llvm::OwningPtr<clang::CompilerInvocation> Invocation( newInvocation(&Diagnostics, *CC1Args)); return runInvocation(BinaryName, Compilation.get(), Invocation.take(), *CC1Args, ToolAction.take()); }
bool ToolInvocation::run() { std::vector<const char*> Argv; for (const std::string &Str : CommandLine) Argv.push_back(Str.c_str()); const char *const BinaryName = Argv[0]; IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); TextDiagnosticPrinter DiagnosticPrinter( llvm::errs(), &*DiagOpts); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, DiagConsumer ? DiagConsumer : &DiagnosticPrinter, false); const std::unique_ptr<clang::driver::Driver> Driver( newDriver(&Diagnostics, BinaryName, Files->getVirtualFileSystem())); // Since the input might only be virtual, don't check whether it exists. Driver->setCheckInputsExist(false); const std::unique_ptr<clang::driver::Compilation> Compilation( Driver->BuildCompilation(llvm::makeArrayRef(Argv))); // Just print the cc1 options if -### was present. if (Compilation->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) { Compilation->getJobs().Print(llvm::errs(), "\n", true); return true; } // We expect to get back a command job. If there is no job // everything was handled by the driver. const driver::JobList &Jobs = Compilation->getJobs(); if (Jobs.size() == 0) return true; const llvm::opt::ArgStringList *const CC1Args = getCC1Arguments( &Diagnostics, Compilation.get()); if (!CC1Args) { return false; } std::unique_ptr<clang::CompilerInvocation> Invocation( newInvocation(&Diagnostics, *CC1Args)); if(Diagnostics.hasUncompilableErrorOccurred()) return false; // FIXME: remove this when all users have migrated! for (const auto &It : MappedFileContents) { // Inject the code as the given file name into the preprocessor options. std::unique_ptr<llvm::MemoryBuffer> Input = llvm::MemoryBuffer::getMemBuffer(It.getValue()); Invocation->getPreprocessorOpts().addRemappedFile(It.getKey(), Input.release()); } return runInvocation(BinaryName, Compilation.get(), Invocation.release(), PCHContainerOps); }
void AdafruitServoController::Init(vector<uint8_t> driversAddresses_, uint8_t pwmFreq_, uint16_t pulseMin_, uint16_t pulseMax_) { this->addresses = driversAddresses_; this->pwmFreq = pwmFreq_; this->pulseMax = pulseMax_; this->pulseMin = pulseMin_; for (const auto& addr : this->addresses) { try { unique_ptr<AdafruitServoDriver> newDriver ( new AdafruitServoDriver(addr)); newDriver->setPWMFreq(this->pwmFreq); this->drivers.push_back( std::move(newDriver) ); } catch (std::runtime_error& e) { throw e; } } const uint8_t servosCount = (this->addresses.size() * SERVOS_PER_DRIVER) - 1; // -1 is for zero-indexing this->servos.reserve(servosCount); for (uint8_t i = 0; i < servosCount; i++) { std::pair<uint8_t, uint8_t> driverAndServoId = getDriverAndServoId(i); Servo servo (driverAndServoId.first, driverAndServoId.second, 0, 0, 0); // FIXME SUPER CRAZY HACK // set all servos initially at 90* servo.currentPulse = this->angleToPulse(90); servo.desiredPulse = servo.currentPulse; // don't trigger another servo job in servo thread this->drivers[servo.driverId]->setPWM(servo.servoId, 0, servo.currentPulse); this->servos.push_back(servo); } this->run = true; this->servosThread = std::thread([this] { this->handleServos(); }); // sched_param sch_params; // sch_params.sched_priority = sched_get_priority_max(SCHED_FIFO); // pthread_setschedparam(this->servosThread.native_handle(), SCHED_FIFO, // &sch_params); }