OpenASIP 2.2
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Static Private Attributes | List of all members
Application Class Reference

#include <Application.hh>

Collaboration diagram for Application:
Collaboration graph

Classes

class  UnixSignalHandler
 

Static Public Member Functions

static void initialize (int argc, char *argv[])
 
static void initialize ()
 
static void finalize ()
 
static void writeToErrorLog (const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)
 
static void exitProgram (const int status=EXIT_SUCCESS)
 
static void abortProgram () __attribute__((noreturn))
 
static void unexpectedExceptionHandler ()
 
static bool shellCommandsExists (const std::string &commands)
 
static int runShellCommandSilently (const std::string &command)
 
static int runShellCommandAndGetOutput (const std::string &command, std::vector< std::string > &outputLines, std::size_t maxOutputLines=DEFAULT_MAX_OUTPUT_LINES, bool includeStdErr=false)
 
static std::ostream & logStream ()
 
static std::ostream & warningStream ()
 
static std::ostream & errorStream ()
 
static int verboseLevel ()
 
static bool increasedVerbose ()
 
static bool spamVerbose ()
 
static void setVerboseLevel (const int level=VERBOSE_LEVEL_DEFAULT)
 
static void setCmdLineOptions (CmdLineOptions *options_)
 
static CmdLineOptionscmdLineOptions ()
 
static int argc ()
 
static char ** argv ()
 
static bool isInstalled ()
 
static std::string installationDir ()
 
static void setSignalHandler (int signalNum, UnixSignalHandler &handler)
 
static UnixSignalHandlergetSignalHandler (int signalNum)
 
static void restoreSignalHandler (int signalNum)
 
static std::string TCEVersionString ()
 

Static Public Attributes

static const int VERBOSE_LEVEL_DEFAULT = 0
 Default verbose level - do not print anything unnecessary.
 
static const int VERBOSE_LEVEL_INCREASED = 1
 Increased verbose level - print information about modules etc.
 
static const int VERBOSE_LEVEL_SPAM = 2
 More Increased verbose level - spam about ddg heights of loops.
 
static const bool LOOP_OPT_DEFAULT = false
 Use Loop Optimizations.
 

Static Private Member Functions

static void signalRedirector (int data, siginfo_t *info, void *context)
 

Static Private Attributes

static bool initialized_ = false
 True when initialize() is called. Ensures that initialization is done only once.
 
static std::ostream * logStream_ = NULL
 The stream for debug logging.
 
static std::ostream * errorStream_ = NULL
 The stream for user error notifications.
 
static std::ostream * warningStream_ = NULL
 The stream for user error notifications.
 
static std::map< int, UnixSignalHandler * > signalHandlers_
 Signal handlers in a map associated by their signal numbers.
 
static int verboseLevel_ = Application::VERBOSE_LEVEL_DEFAULT
 Verbose level directs how much output will be printed to console.
 
static CmdLineOptionscmdLineOptions_ = NULL
 Holds command line options passed to program.
 
static int argc_
 The original argc and argv given to the main program, if applicable.
 
static char ** argv_
 
static std::string installationRoot_ = ""
 Path to the TCE installation root.
 

Detailed Description

Definition at line 144 of file Application.hh.

Member Function Documentation

◆ abortProgram()

void Application::abortProgram ( )
static

Exit the program in an abnormal situation.

Definition at line 266 of file Application.cc.

266 {
267 abort();
268}

Referenced by UniversalMachine::addAddressSpace(), UniversalMachine::addBridge(), UniversalMachine::addBus(), UniversalMachine::addFunctionUnit(), UniversalMachine::addImmediateUnit(), UniversalMachine::addInstructionTemplate(), UniversalFunctionUnit::addPipelineElement(), UniversalMachine::addRegisterFile(), UniversalMachine::addSocket(), UniversalFunctionUnit::addSupportedOperation(), TTAMachine::Socket::attachBus(), SmartHWOperation::bindPort(), ADFSerializer::busToMachine(), ADFSerializer::busToMDF(), TTAMachine::Socket::connection(), UniversalMachine::construct(), TTAProgram::TPEFProgramFactory::createTerminal(), UniversalMachine::deleteAddressSpace(), ADFSerializer::immediateUnitToMachine(), ADFSerializer::immediateUnitToMDF(), initialize(), SmartHWOperation::loadState(), UnboundedRegisterFile::loadState(), UniversalFunctionUnit::loadState(), UniversalFUPort::loadState(), UniversalMachine::loadState(), ADFSerializer::machinePipeline(), ADFSerializer::machineSRPort(), ADFSerializer::registerFileToMachine(), ADFSerializer::registerFileToMDF(), UniversalMachine::removeBus(), UniversalMachine::removeFunctionUnit(), UniversalMachine::removeRegisterFile(), UniversalMachine::removeSocket(), UniversalMachine::setGlobalControl(), ADFSerializer::setIUExtensionMode(), UnboundedRegisterFile::setMaxReads(), UnboundedRegisterFile::setMaxWrites(), SmartHWOperation::setName(), UnboundedRegisterFile::setName(), UniversalFUPort::setName(), UnboundedRegisterFile::setNumberOfRegisters(), UniversalFUPort::setOpcodeSetting(), UniversalFUPort::setTriggering(), UnboundedRegisterFile::setType(), UnboundedRegisterFile::setWidth(), UniversalFUPort::setWidth(), SmartHWOperation::unbindPort(), TTAMachine::Port::unconnectedSocket(), unexpectedExceptionHandler(), and UniversalMachine::unsetGlobalControl().

◆ argc()

static int Application::argc ( )
inlinestatic

Definition at line 192 of file Application.hh.

192{ return argc_; }
static int argc_
The original argc and argv given to the main program, if applicable.

References argc_.

Referenced by initialize(), and SimulatorCLI::SimulatorCLI().

◆ argv()

static char ** Application::argv ( )
inlinestatic

Definition at line 193 of file Application.hh.

193{ return argv_; }
static char ** argv_

References argv_.

Referenced by initialize(), and SimulatorCLI::SimulatorCLI().

◆ cmdLineOptions()

CmdLineOptions * Application::cmdLineOptions ( )
static

Definition at line 397 of file Application.cc.

397 {
398 return cmdLineOptions_;
399}
static CmdLineOptions * cmdLineOptions_
Holds command line options passed to program.

References cmdLineOptions_.

Referenced by llvm::TCEPassConfig::addPreISel(), BasicBlockScheduler::BasicBlockScheduler(), BBSchedulerController::BBSchedulerController(), BF2Scheduler::BF2Scheduler(), BF2Scheduler::BF2Scheduler(), BFEarlyBypasser::BFEarlyBypasser(), BFLateBypasses::BFLateBypasses(), BFShareOperands::BFShareOperands(), BFShareOperandsLate::BFShareOperandsLate(), BUBasicBlockScheduler::BUBasicBlockScheduler(), llvm::LLVMTCEIRBuilder::compileOptimized(), llvm::TCETargetMachine::createMachine(), CycleLookBackSoftwareBypasser::CycleLookBackSoftwareBypasser(), DataDependenceGraphBuilder::DataDependenceGraphBuilder(), DataDependenceGraphBuilder::DataDependenceGraphBuilder(), llvm::TCERegisterInfo::eliminateFrameIndex(), llvm::TCERegisterInfo::getReservedRegs(), BBSchedulerController::handleBasicBlock(), SimpleIfConverter::handleControlFlowGraph(), PreOptimizer::handleProcedure(), BBSchedulerController::handleProcedure(), llvm::LLVMTCEBuilder::initMembers(), llvm::TCETTIImpl::isHardwareLoopProfitable(), LLVMBackend::LLVMBackend(), DataDependenceGraphBuilder::memoryCategory(), DesignSpaceExplorer::schedule(), SimpleBrokerDirector::SimpleBrokerDirector(), SimpleIfConverter::SimpleIfConverter(), SimulatorCLI::SimulatorCLI(), llvm::TCETargetLowering::TCETargetLowering(), and llvm::LLVMTCEIRBuilder::~LLVMTCEIRBuilder().

◆ errorStream()

std::ostream & Application::errorStream ( )
static

Stream where error messages that should be printed immediately to the user should be written.

Errors are fatal which means the action performed could not be finished.

Usage example: errorStream() << "Compilation error: "...

Returns
A reference to the error stream.

Definition at line 171 of file Application.cc.

171 {
172 initialize();
173 return *errorStream_;
174}
static std::ostream * errorStream_
The stream for user error notifications.
static void initialize()

References errorStream_, and initialize().

Referenced by BlocksConnectIC::explore(), VLIWConnectIC::explore(), main(), ConstantTransformer::runOnMachineFunction(), and writeCustomOpMacros().

Here is the call graph for this function:

◆ exitProgram()

void Application::exitProgram ( const int  status = EXIT_SUCCESS)
static

Exits the program in a normal situation.

This method must be used when the program terminates due to nominal conditions without returning from main().

Parameters
statusProgram's status of exit.

Definition at line 258 of file Application.cc.

258 {
259 exit(status);
260}

Referenced by ComponentAdder::addRegisterFiles().

◆ finalize()

void Application::finalize ( )
static

Cleans up the state data used by the application services.

This method is called automatically when program is terminated.

Definition at line 199 of file Application.cc.

199 {
200
201 if (!initialized_) {
202 return;
203 }
204
205 if (logStream_ != &cerr && logStream_ != &cout && logStream_ != NULL) {
206 logStream_->flush();
207 delete logStream_;
208 logStream_ = NULL;
209 }
210 delete cmdLineOptions_;
211 cmdLineOptions_ = NULL;
212 initialized_ = false;
213}
static std::ostream * logStream_
The stream for debug logging.
static bool initialized_
True when initialize() is called. Ensures that initialization is done only once.

References cmdLineOptions_, initialized_, and logStream_.

Referenced by initialize().

◆ getSignalHandler()

Application::UnixSignalHandler * Application::getSignalHandler ( int  signalNum)
static

Returns a pointer to the signal's current handler

In platforms which do not support signals this method always returns NULL.

Returns
a pointer to the signal's current handler
Exceptions
InstanceNotFoundif the signal has not been set a custom handler

Definition at line 445 of file Application.cc.

445 {
446 std::map<int, UnixSignalHandler*>::iterator it =
447 signalHandlers_.find(signalNum);
448 if (it != signalHandlers_.end()) {
449 return it->second;
450 } else {
451 throw InstanceNotFound(__FILE__, __LINE__, __FUNCTION__);
452 }
453}
static std::map< int, UnixSignalHandler * > signalHandlers_
Signal handlers in a map associated by their signal numbers.

References signalHandlers_.

Referenced by signalRedirector().

◆ increasedVerbose()

static bool Application::increasedVerbose ( )
inlinestatic

Definition at line 179 of file Application.hh.

179 {
181 }
static const int VERBOSE_LEVEL_DEFAULT
Default verbose level - do not print anything unnecessary.
static int verboseLevel()

References VERBOSE_LEVEL_DEFAULT, and verboseLevel().

Referenced by DesignSpaceExplorer::evaluate(), and ProGe::ProGeUI::generateIDF().

Here is the call graph for this function:

◆ initialize() [1/2]

void Application::initialize ( )
static

Initializes the state data needed by the application services.

Definition at line 99 of file Application.cc.

99 {
100
101 // ensure that initialization is done only once per application
102 if (initialized_) {
103 return;
104 }
105
106 // if this is a developer version, we can output debug messages to
107 // cerr, in 'distributed version', we'll output the debug messages to
108 // a file
110 logStream_ = &cerr;
111 } else {
112 ofstream* fileLog = new ofstream;
113 fileLog->open(Environment::errorLogFilePath().c_str(), ios::app);
114 if (!fileLog->is_open()) {
115 logStream_ = &cerr;
116 } else {
117 logStream_ = fileLog;
118 }
119 }
120
122
123 errorStream_ = &cerr;
124 warningStream_ = &cerr;
125
126 // set the unexpected exception callback
128
129 // register finalization function to be called when exit() is called
130 // so Application is finalized automatically on program exit
131 if (atexit(Application::finalize) != 0) {
132 writeToErrorLog(__FILE__, __LINE__, __FUNCTION__,
133 "Application initialization failed.");
134 abortProgram();
135 }
136
137 initialized_ = true;
138}
static std::string installationDir()
static void finalize()
static void unexpectedExceptionHandler()
static std::string installationRoot_
Path to the TCE installation root.
static void abortProgram() __attribute__((noreturn))
static void writeToErrorLog(const std::string fileName, const int lineNumber, const std::string functionName, const std::string message, const int neededVerbosity=0)
static std::ostream * warningStream_
The stream for user error notifications.
static std::string errorLogFilePath()
static bool developerMode()

References abortProgram(), Environment::developerMode(), Environment::errorLogFilePath(), errorStream_, finalize(), initialized_, installationDir(), installationRoot_, logStream_, unexpectedExceptionHandler(), warningStream_, and writeToErrorLog().

Referenced by errorStream(), Script::execute(), initialize(), logStream(), main(), OSEd::OnInit(), Proxim::OnInit(), HDBEditor::OnInit(), ProDe::OnInit(), warningStream(), and writeToErrorLog().

Here is the call graph for this function:

◆ initialize() [2/2]

void Application::initialize ( int  argc,
char *  argv[] 
)
static

Definition at line 141 of file Application.cc.

141 {
143 argc_ = argc;
144 argv_ = argv;
145}
static char ** argv()
static int argc()

References argc(), argc_, argv(), argv_, and initialize().

Here is the call graph for this function:

◆ installationDir()

string Application::installationDir ( )
static

Returns the path to TCE installation root

Installation root can be one created by 'make install' or .deb package unpacked to homedir for example. Environment variable TCE_INSTALL_DIR should be set in the second case pointing to that dir where .deb was installed or tce installation manually copied/moved to.

Returns
Path to TCE installation root

Definition at line 537 of file Application.cc.

537 {
538
539 if (installationRoot_ != "") {
540 return installationRoot_;
541 }
542
543 string userRoot = Environment::environmentVariable("TCE_INSTALL_DIR");
544
545 // .deb check: check if envvar TCE_INSTALL_DIR is set
546 // and that dir exists ("icons" dir in our case)
547 if (userRoot != "" && FileSystem::fileExists(
548 userRoot + "/share/openasip/data/icons")) {
549 return userRoot;
550 }
551 return string(TCE_INSTALLATION_ROOT);
552}
static std::string environmentVariable(const std::string &variable)
static bool fileExists(const std::string fileName)

References Environment::environmentVariable(), FileSystem::fileExists(), and installationRoot_.

Referenced by OperationBuilder::buildObject(), Environment::codeCompressorPaths(), Environment::confPath(), LLVMBackend::createPlugin(), Environment::defaultSchedulerConf(), Environment::estimatorPluginPaths(), Environment::explorerPluginPaths(), Environment::hdbPaths(), Environment::icDecoderPluginPaths(), Environment::implementationTesterTemplatePaths(), Environment::includeDirPaths(), initialize(), Environment::initialize(), Environment::longHDBPath(), Environment::minimalADF(), Environment::oldGccSchedulerConf(), Environment::osalPaths(), Environment::pdfManual(), Environment::schedulerPluginPaths(), Environment::shortHDBPath(), Environment::tceCompiler(), and Environment::vhdlPaths().

Here is the call graph for this function:

◆ isInstalled()

bool Application::isInstalled ( )
static

Returns true if the application is running from an install path.

Since there is no reliable way to detect this from the binary name or such since TCE can be used as a library, we just assume we are using an installed TCE in case the developer mode is not set.

Definition at line 522 of file Application.cc.

522 {
524}

References Environment::developerMode().

Referenced by OperationBuilder::buildObject(), and main().

Here is the call graph for this function:

◆ logStream()

std::ostream & Application::logStream ( )
static

Allows writing to the log stream with stream operators.

Usage example: logStream() << "Debug output" << i << endl;

Returns
A reference to the log stream.

Definition at line 155 of file Application.cc.

155 {
156 initialize();
157 return *logStream_;
158}

References initialize(), and logStream_.

Referenced by llvm::LLVMTCEBuilder::addCandidateLSUAnnotations(), RegisterCopyAdder::addConnectionRegisterCopies(), LoopPrologAndEpilogBuilder::addEpilogFromRM(), ControlFlowGraph::addExit(), ProgramDependenceGraph::addLeafEdges(), RegisterCopyAdder::addMinimumRegisterCopies(), llvm::LLVMTCEBuilder::addPointerAnnotations(), LoopPrologAndEpilogBuilder::addPrologFromRM(), RegisterCopyAdder::addRegisterCopies(), RegisterCopyAdder::addRegisterCopiesToRRMove(), llvm::LLVMTCEBuilder::addressSpaceById(), MultiLatencyOperationExecutor::advanceClock(), ResourceConstraintAnalyzer::analyze(), PRegionAliasAnalyzer::analyze(), ControlDependenceGraph::analyzeCDG(), TDGen::analyzeMachineRegisters(), ResourceConstraintAnalyzer::analyzeMoveNode(), ResourceConstraintAnalyzer::analyzeRegisterAntideps(), TDGen::analyzeRegisters(), SimpleResourceManager::assign(), MachineInstrDDG::assignPhysReg(), DataDependenceGraphBuilder::build(), LoopPrologAndEpilogBuilder::build(), MoveNodeGroupBuilder::build(), ControlFlowGraph::buildMBBFromBB(), OperationBuilder::buildObject(), llvm::LLVMTCEIRBuilder::buildTCECFG(), SimpleResourceManager::canAssign(), SimpleBrokerDirector::canAssign(), SimpleIfConverter::canConvert(), DataDependenceGraphBuilder::checkAndCreateMemDep(), ProgramDependenceGraph::compareSiblings(), LLVMBackend::compile(), CompiledSimCompiler::compileDirectory(), CompiledSimCompiler::compileFile(), ConflictDetectionCodeGenerator::ConflictDetectionCodeGenerator(), BasicBlockPass::copyRMToBB(), ControlFlowGraph::createControlFlowEdge(), TTAProgram::ProgramWriter::createDataSections(), InstructionDictionary::createDictionary(), ProgramDependenceGraph::createJump(), llvm::LLVMTCEIRBuilder::createMBBReference(), LLVMBackend::createPlugin(), DataDependenceGraphBuilder::createRegisterDeps(), llvm::createTCESchedulerPass(), TTAProgram::TPEFProgramFactory::createTerminal(), DataDependenceGraphBuilder::DataDependenceGraphBuilder(), BasicBlockPass::ddgSnapshot(), llvm::LLVMTCEBuilder::deleteDeadProcedures(), ProgramDependenceGraph::disassemble(), MoveNodeGroup::earliestCycle(), SimpleResourceManager::earliestCycle(), SimpleResourceManager::earliestCycle(), llvm::LLVMTCEBuilder::emitInstruction(), llvm::LLVMTCEBuilder::emitMove(), llvm::LLVMTCEBuilder::emitWriteSP(), StrictMatchRFEstimator::estimateArea(), InterpolatingRFEstimator::estimateArea(), StrictMatchFUEstimator::estimateArea(), InterpolatingFUEstimator::estimateArea(), InterpolatingRFEstimator::estimateEnergy(), StrictMatchRFEstimator::estimateEnergy(), InterpolatingFUEstimator::estimateEnergy(), StrictMatchFUEstimator::estimateEnergy(), StrictMatchRFEstimator::estimateMaximumComputationDelay(), InterpolatingRFEstimator::estimateMaximumComputationDelay(), StrictMatchFUEstimator::estimateMaximumComputationDelay(), InterpolatingFUEstimator::estimateMaximumComputationDelay(), StrictMatchFUEstimator::estimatePortReadDelay(), InterpolatingFUEstimator::estimatePortReadDelay(), StrictMatchRFEstimator::estimatePortReadDelay(), InterpolatingRFEstimator::estimatePortReadDelay(), StrictMatchFUEstimator::estimatePortWriteDelay(), InterpolatingFUEstimator::estimatePortWriteDelay(), StrictMatchRFEstimator::estimatePortWriteDelay(), InterpolatingRFEstimator::estimatePortWriteDelay(), DesignSpaceExplorer::evaluate(), BasicBlockPass::executeDDGPass(), BBSchedulerController::executeDDGPass(), ProgramPass::executeProcedurePass(), CodeSectionCreator::finalize(), CostEstimator::Estimator::findAllICPaths(), CompiledSimCodeGenerator::findBasicBlocks(), ProgramImageGenerator::generateProgramImage(), BBSchedulerController::handleBasicBlock(), CallsToJumps::handleControlFlowGraph(), SimpleIfConverter::handleControlFlowGraph(), BF2Scheduler::handleLoopDDG(), BasicBlockScheduler::handleLoopDDG(), BUBasicBlockScheduler::handleLoopDDG(), llvm::LLVMTCEBuilder::handleMemoryCategoryInfo(), BBSchedulerController::handleProcedure(), BasicBlockScheduler::handleRemovedResultMoves(), CostEstimator::Estimator::icArea(), llvm::LLVMTCEBuilder::initDataSections(), StopPoint::isConditionOK(), SimpleResourceManager::largestCycle(), SimpleResourceManager::latestCycle(), SimpleResourceManager::latestCycle(), llvm::LLVMTCERISCVIntrinsicsLowering::LLVMTCERISCVIntrinsicsLowering(), llvm::LLVMTCEScheduler::LLVMTCEScheduler(), CostEstimator::Estimator::longestPath(), MachineInstrDDG::MachineInstrDDG(), main(), ResourceConstraintAnalyzer::memoryBoundScheduleResourceUsage(), CompiledSimulation::msg(), VirtRegIndependenceGraph::newFalseDepsFromAssign(), BlockImplementationFileDialog::onOK(), MoveSlotDictionary::printDetails(), ControlDependenceNode::printRelations(), ProgramDependenceNode::printRelations(), ControlDependenceGraph::processRegion(), ProgramDependenceGraph::processRegion(), ADFCombiner::readParameters(), ProgramDependenceGraph::removeGuardedJump(), CompiledSimController::reset(), BUBasicBlockScheduler::scheduleInputOperandTempMoves(), BasicBlockScheduler::scheduleOperation(), BUBasicBlockScheduler::scheduleOperation(), DataDependenceGraphBuilder::searchRegisterDeaths(), ProgramDependenceGraph::serializePDG(), SimpleIfConverter::SimpleIfConverter(), SimpleResourceManager::smallestCycle(), MultiLatencyOperationExecutor::startOperation(), SimpleIfConverter::successors(), llvm::TCETargetLowering::TCETargetLowering(), CostEstimator::Estimator::totalAreaOfFunctionUnits(), CostEstimator::Estimator::totalAreaOfRegisterFiles(), SimpleResourceManager::unassign(), TTAProgram::InstructionReferenceManager::validate(), TDGen::verbose(), VirtRegIndependenceGraph::VirtRegIndependenceGraph(), TDGen::writeInstrInfo(), llvm::LLVMTCEBuilder::writeMachineFunction(), llvm::LLVMTCEIRBuilder::writeMachineFunction(), TDGen::writeOperationDef(), and FiniteStateAutomaton::~FiniteStateAutomaton().

Here is the call graph for this function:

◆ restoreSignalHandler()

void Application::restoreSignalHandler ( int  signalNum)
static

Restores to the signal its original handler

Note in platforms which do not support signals (e.g. Windows), this function does nothing.

Parameters
signalNumsignal number

Definition at line 471 of file Application.cc.

471 {
472 signal(signalNum, SIG_DFL);
473 signalHandlers_.erase(signalNum);
474}

References signalHandlers_.

Referenced by main().

◆ runShellCommandAndGetOutput()

int Application::runShellCommandAndGetOutput ( const std::string &  command,
std::vector< std::string > &  outputLines,
std::size_t  maxOutputLines = DEFAULT_MAX_OUTPUT_LINES,
bool  includeStdErr = false 
)
static

Runs a shell command and captures its output (stdout) in the given vector.

Assumes that the executed program does not block and wait for input.

Parameters
commandCommand to execute.
outputLinesVector to which put the output lines.
maxOutputLinesMaximum lines to capture.
Returns
The return value of the program. -1 if some weird error occured.

Definition at line 338 of file Application.cc.

342 {
343
344 char line[MAX_OUTPUT_LINE_LENGTH];
345
346 // flush all streams to avoid: "...the output from a
347 // command opened for writing may become intermingled with that of
348 // the original process." (man popen)
349 fflush(NULL);
350
351 string shellCommand = command;
352 if (includeStdErr) {
353 shellCommand += " 2>1";
354 }
355 FILE* pipe = popen(shellCommand.c_str(), "r");
356
357 while (fgets(line, MAX_OUTPUT_LINE_LENGTH, pipe) == line) {
358
359 if (outputLines.size() < maxOutputLines) {
360 outputLines.push_back(string(line));
361 }
362 }
363
364 int exitStatus = pclose(pipe);
365
366 // see man wait4 for info about macros WIFEXITED and WEXITSTATUS
367 if (WIFEXITED(exitStatus)) {
368 return WEXITSTATUS(exitStatus);
369 }
370
371 return -1;
372}
#define WIFEXITED(stat_val)
#define WEXITSTATUS(stat_val)
const int MAX_OUTPUT_LINE_LENGTH
maximum length of an output line saved from popen() output in runShellCommandAndGetOutput()

References MAX_OUTPUT_LINE_LENGTH, WEXITSTATUS, and WIFEXITED.

Referenced by OperationBuilder::buildObject(), CompileTools::compileAsC(), GhdlSimulator::compileDesign(), ModelsimSimulator::compileOneFile(), ModelsimSimulator::createWorkDir(), GhdlSimulator::importFile(), DesignSpaceExplorer::schedule(), GhdlSimulator::simulate(), and ModelsimSimulator::simulate().

◆ runShellCommandSilently()

int Application::runShellCommandSilently ( const std::string &  command)
static

Runs a shell command and redirects all output to /dev/null

Parameters
commandCommand to execute.
Returns
The return value of the program. -1 if some weird error occurred.

Definition at line 301 of file Application.cc.

302 {
303
304 char line[MAX_OUTPUT_LINE_LENGTH];
305 // flush all streams to avoid: "...the output from a
306 // command opened for writing may become intermingled with that of
307 // the original process." (man popen)
308 fflush(NULL);
309
310 std::string fullCommand = command + " 2>&1 ";
311 FILE* pipe = popen(fullCommand.c_str(), "r");
312
313 while (fgets(line, MAX_OUTPUT_LINE_LENGTH, pipe) == line) {
314 // Drain stdout and stderr data.
315 }
316
317 int exitStatus = pclose(pipe);
318
319 // see man wait4 for info about macros WIFEXITED and WEXITSTATUS
320 if (WIFEXITED(exitStatus)) {
321 return WEXITSTATUS(exitStatus);
322 }
323
324 return -1;
325}

References MAX_OUTPUT_LINE_LENGTH, WEXITSTATUS, and WIFEXITED.

Referenced by CompileTools::compileAsLLVM(), and shellCommandsExists().

◆ setCmdLineOptions()

void Application::setCmdLineOptions ( CmdLineOptions options)
static

Set the command line options instance for the application.

The object becomes owned by Application class. It should be fully built (parsed) before passed to Application.

Definition at line 381 of file Application.cc.

381 {
382
383 // delete the possible old instance first
384 delete cmdLineOptions_;
386
389 }
390
393 }
394}
static MachInfoCmdLineOptions options
Definition MachInfo.cc:46
static const int VERBOSE_LEVEL_INCREASED
Increased verbose level - print information about modules etc.
static const int VERBOSE_LEVEL_SPAM
More Increased verbose level - spam about ddg heights of loops.
static void setVerboseLevel(const int level=VERBOSE_LEVEL_DEFAULT)
virtual bool isVerboseSwitchDefined() const
virtual bool isVerboseSpamSwitchDefined() const

References cmdLineOptions_, CmdLineOptions::isVerboseSpamSwitchDefined(), CmdLineOptions::isVerboseSwitchDefined(), options, setVerboseLevel(), VERBOSE_LEVEL_INCREASED, and VERBOSE_LEVEL_SPAM.

Referenced by llvm::LLVMTCEScheduler::LLVMTCEScheduler(), and main().

Here is the call graph for this function:

◆ setSignalHandler()

void Application::setSignalHandler ( int  signalNum,
UnixSignalHandler handler 
)
static

Sets a new signal handler for the given signal

Note in platforms which do not support signals (e.g. Windows), this function does nothing.

Parameters
signalNumsignal number
handlerThe handler to be set

Definition at line 417 of file Application.cc.

417 {
418 signalHandlers_[signalNum] = &handler;
419
420 struct sigaction action;
421 action.sa_flags = SA_SIGINFO;
422 action.sa_sigaction = signalRedirector;
423 // valgrind complains if this is uninitialized
424 sigemptyset(&action.sa_mask);
425 sigaction(signalNum, &action, NULL);
426}
static void signalRedirector(int data, siginfo_t *info, void *context)

References signalHandlers_, and signalRedirector().

Referenced by main().

Here is the call graph for this function:

◆ setVerboseLevel()

static void Application::setVerboseLevel ( const int  level = VERBOSE_LEVEL_DEFAULT)
inlinestatic

Definition at line 186 of file Application.hh.

186 {
187 verboseLevel_ = level;
188 }
static int verboseLevel_
Verbose level directs how much output will be printed to console.

References verboseLevel_.

Referenced by GenerateProcessor::generateProcessor(), main(), and setCmdLineOptions().

◆ shellCommandsExists()

bool Application::shellCommandsExists ( const std::string &  commands)
static

Returns true if all commands separated by space are found.

Otherwise return false;

Definition at line 290 of file Application.cc.

290 {
291 return runShellCommandSilently(std::string("type ") + commands) == 0;
292}
static int runShellCommandSilently(const std::string &command)

References runShellCommandSilently().

Here is the call graph for this function:

◆ signalRedirector()

void Application::signalRedirector ( int  data,
siginfo_t *  info,
void *  context 
)
staticprivate

Redirects the signal received to the current signal handler

Note in platforms which do not support signals (e.g. Windows), this function does nothing.

Parameters
dataData from the signal.
infosignal information struct
contextsignal context

Definition at line 494 of file Application.cc.

494 {
495 UnixSignalHandler* handler = getSignalHandler(info->si_signo);
496 assert(handler != NULL);
497 handler->execute(data, info);
498}
#define assert(condition)
static UnixSignalHandler * getSignalHandler(int signalNum)

References assert, Application::UnixSignalHandler::execute(), and getSignalHandler().

Referenced by setSignalHandler().

Here is the call graph for this function:

◆ spamVerbose()

static bool Application::spamVerbose ( )
inlinestatic

Definition at line 182 of file Application.hh.

182 {
184 }

References VERBOSE_LEVEL_INCREASED, and verboseLevel().

Referenced by ProGe::ProcessorGenerator::generateProcessor(), and InlineAsmParser::substituteAsmString().

Here is the call graph for this function:

◆ TCEVersionString()

std::string Application::TCEVersionString ( )
static

◆ unexpectedExceptionHandler()

void Application::unexpectedExceptionHandler ( )
static

Default callback for unexpected exceptions.

Definition at line 274 of file Application.cc.

274 {
276 << std::endl
277 << "Program aborted because of leaked unexpected exception. "
278 << std::endl << std::endl <<
279 "Information of the last thrown TCE exception: " << std::endl
280 << Exception::lastExceptionInfo() << std::endl;
281 abortProgram();
282}
static std::string lastExceptionInfo()
Returns information of the last thrown exception.
Definition Exception.cc:108

References abortProgram(), Exception::lastExceptionInfo(), and logStream_.

Referenced by initialize().

Here is the call graph for this function:

◆ verboseLevel()

static int Application::verboseLevel ( )
inlinestatic

Definition at line 176 of file Application.hh.

176 {
177 return verboseLevel_;
178 }

References verboseLevel_.

Referenced by llvm::LLVMTCEBuilder::addCandidateLSUAnnotations(), LoopPrologAndEpilogBuilder::addEpilogFromRM(), ControlFlowGraph::addExit(), LoopPrologAndEpilogBuilder::addPrologFromRM(), LoopPrologAndEpilogBuilder::addPrologIntoCfg(), LoopAnalyzer::analyze(), ControlDependenceGraph::analyzeCDG(), TDGen::analyzeMachineRegisters(), ResourceConstraintAnalyzer::analyzeRegisterAntideps(), TDGen::analyzeRegisters(), LoopPrologAndEpilogBuilder::build(), OperationBuilder::buildObject(), FrequencySweepExplorer::callPlugin(), LLVMBackend::compile(), MoveSlotDictionary::compress(), BasicBlockPass::copyRMToBB(), ControlFlowGraph::createControlFlowEdge(), InstructionDictionary::createDictionary(), LLVMBackend::createPlugin(), DataDependenceGraphBuilder::createRegisterDeps(), DataDependenceGraphBuilder::DataDependenceGraphBuilder(), llvm::LLVMTCEBuilder::deleteDeadProcedures(), BasicBlockPass::executeDDGPass(), BBSchedulerController::executeDDGPass(), ProgramPass::executeProcedurePass(), GrowMachine::explore(), FrequencySweepExplorer::explore(), LoopAnalyzer::findInitAndUpdate(), ProgramImageGenerator::generateProgramImage(), BBSchedulerController::handleBasicBlock(), SimpleIfConverter::handleControlFlowGraph(), BF2Scheduler::handleLoopDDG(), BF2Scheduler::handleLoopDDG(), BBSchedulerController::handleProcedure(), CostEstimator::Estimator::icArea(), increasedVerbose(), llvm::LLVMTCEBuilder::initDataSections(), llvm::TCETargetLowering::LowerBuildVector(), llvm::TCETargetLowering::LowerConstant(), llvm::TCETargetLowering::LowerGLOBALADDRESS(), main(), BasicBlockScheduler::printStats(), ControlDependenceGraph::processRegion(), ProgramDependenceGraph::processRegion(), MachineConnectivityCheck::raConnected(), ProgramDependenceGraph::removeGuardedJump(), ConstantTransformer::runOnMachineFunction(), DesignSpaceExplorer::schedule(), BF2ScheduleFront::scheduleFrontFromMove(), DataDependenceGraphBuilder::searchRegisterDeaths(), ProgramDependenceGraph::serializePDG(), SimpleIfConverter::SimpleIfConverter(), spamVerbose(), llvm::TCETargetLowering::TCETargetLowering(), MachineConnectivityCheck::tempRegisterFiles(), CostEstimator::Estimator::totalAreaOfFunctionUnits(), CostEstimator::Estimator::totalAreaOfRegisterFiles(), TDGen::verbose(), TDGen::writeInstrInfo(), llvm::LLVMTCEBuilder::writeMachineFunction(), llvm::LLVMTCEIRBuilder::writeMachineFunction(), and TDGen::writeOperationDef().

◆ warningStream()

std::ostream & Application::warningStream ( )
static

Stream where warning messages that should be printed immediately to the user should be written.

Warnings are non-fatal notifications to the user. The action performed might still be able to be finished.

Usage example: warningStream() << "warning: uninitialized thing "...

Returns
A reference to the warning stream.

Definition at line 188 of file Application.cc.

188 {
189 initialize();
190 return *warningStream_;
191}

References initialize(), and warningStream_.

Referenced by MachineStateBuilder::addPortToFU(), CostEstimator::Estimator::totalAreaOfFunctionUnits(), and CostEstimator::Estimator::totalAreaOfRegisterFiles().

Here is the call graph for this function:

◆ writeToErrorLog()

void Application::writeToErrorLog ( const std::string  fileName,
const int  lineNumber,
const std::string  functionName,
const std::string  message,
const int  neededVerbosity = 0 
)
static

Records a message into the error log.

Parameters
fileNameSource file of the code where the error occurred.
lineNumberSource line where the error occurred.
functionNameFunction where the error occurred.
messageThe error message.

Definition at line 224 of file Application.cc.

229 {
230
231 if (neededVerbosity > verboseLevel_) {
232 return;
233 }
234
235 if (!initialized_) {
236 initialize();
237 }
238
239 *logStream_ << fileName << ":" << lineNumber << ": ";
240
241 if (functionName != UNKNOWN_FUNCTION) {
242 *logStream_ << "In function \'" << functionName << "\': ";
243 }
244
245 *logStream_ << message << endl;
246}
#define UNKNOWN_FUNCTION

References initialize(), initialized_, logStream_, UNKNOWN_FUNCTION, and verboseLevel_.

Referenced by UniversalMachine::addAddressSpace(), UniversalMachine::addBridge(), UniversalMachine::addBus(), UniversalMachine::addFunctionUnit(), UniversalMachine::addImmediateUnit(), UniversalMachine::addInstructionTemplate(), UniversalFunctionUnit::addPipelineElement(), UniversalMachine::addRegisterFile(), UniversalMachine::addSocket(), UniversalFunctionUnit::addSupportedOperation(), TTAMachine::Socket::attachBus(), SmartHWOperation::bindPort(), ADFSerializer::busToMachine(), ADFSerializer::busToMDF(), TTAMachine::Socket::connection(), UniversalMachine::construct(), FileSystem::currentWorkingDir(), UniversalMachine::deleteAddressSpace(), ADFSerializer::immediateUnitToMachine(), ADFSerializer::immediateUnitToMDF(), initialize(), SmartHWOperation::loadState(), UnboundedRegisterFile::loadState(), UniversalFunctionUnit::loadState(), UniversalFUPort::loadState(), UniversalMachine::loadState(), ADFSerializer::machinePipeline(), ADFSerializer::machineSRPort(), ADFSerializer::registerFileToMachine(), ADFSerializer::registerFileToMDF(), UniversalMachine::removeBus(), UniversalMachine::removeFunctionUnit(), UniversalMachine::removeRegisterFile(), UniversalMachine::removeSocket(), ComponentImplementationSelector::selectFUs(), ComponentImplementationSelector::selectIUs(), ComponentImplementationSelector::selectRFs(), UniversalMachine::setGlobalControl(), ADFSerializer::setIUExtensionMode(), UnboundedRegisterFile::setMaxReads(), UnboundedRegisterFile::setMaxWrites(), SmartHWOperation::setName(), UnboundedRegisterFile::setName(), UniversalFUPort::setName(), UnboundedRegisterFile::setNumberOfRegisters(), UniversalFUPort::setOpcodeSetting(), UniversalFUPort::setTriggering(), UnboundedRegisterFile::setType(), UnboundedRegisterFile::setWidth(), UniversalFUPort::setWidth(), SmartHWOperation::unbindPort(), TTAMachine::Port::unconnectedSocket(), UniversalMachine::unsetGlobalControl(), ExecutionTrace::~ExecutionTrace(), ScriptInterpreter::~ScriptInterpreter(), and SQLiteQueryResult::~SQLiteQueryResult().

Here is the call graph for this function:

Member Data Documentation

◆ argc_

int Application::argc_
staticprivate

The original argc and argv given to the main program, if applicable.

Definition at line 257 of file Application.hh.

Referenced by argc(), and initialize().

◆ argv_

char ** Application::argv_
staticprivate

Definition at line 258 of file Application.hh.

Referenced by argv(), and initialize().

◆ cmdLineOptions_

CmdLineOptions * Application::cmdLineOptions_ = NULL
staticprivate

Holds command line options passed to program.

Definition at line 254 of file Application.hh.

Referenced by cmdLineOptions(), finalize(), and setCmdLineOptions().

◆ errorStream_

std::ostream * Application::errorStream_ = NULL
staticprivate

The stream for user error notifications.

Definition at line 242 of file Application.hh.

Referenced by errorStream(), and initialize().

◆ initialized_

bool Application::initialized_ = false
staticprivate

True when initialize() is called. Ensures that initialization is done only once.

Definition at line 236 of file Application.hh.

Referenced by finalize(), initialize(), and writeToErrorLog().

◆ installationRoot_

string Application::installationRoot_ = ""
staticprivate

Path to the TCE installation root.

Definition at line 261 of file Application.hh.

Referenced by initialize(), and installationDir().

◆ logStream_

std::ostream * Application::logStream_ = NULL
staticprivate

The stream for debug logging.

Definition at line 239 of file Application.hh.

Referenced by finalize(), initialize(), logStream(), unexpectedExceptionHandler(), and writeToErrorLog().

◆ LOOP_OPT_DEFAULT

const bool Application::LOOP_OPT_DEFAULT = false
static

Use Loop Optimizations.

Definition at line 229 of file Application.hh.

◆ signalHandlers_

std::map< int, Application::UnixSignalHandler * > Application::signalHandlers_
staticprivate

Signal handlers in a map associated by their signal numbers.

Definition at line 248 of file Application.hh.

Referenced by getSignalHandler(), restoreSignalHandler(), and setSignalHandler().

◆ VERBOSE_LEVEL_DEFAULT

const int Application::VERBOSE_LEVEL_DEFAULT = 0
static

◆ VERBOSE_LEVEL_INCREASED

const int Application::VERBOSE_LEVEL_INCREASED = 1
static

Increased verbose level - print information about modules etc.

Definition at line 224 of file Application.hh.

Referenced by GenerateProcessor::generateProcessor(), main(), setCmdLineOptions(), and spamVerbose().

◆ VERBOSE_LEVEL_SPAM

const int Application::VERBOSE_LEVEL_SPAM = 2
static

More Increased verbose level - spam about ddg heights of loops.

Definition at line 226 of file Application.hh.

Referenced by GenerateProcessor::generateProcessor(), and setCmdLineOptions().

◆ verboseLevel_

int Application::verboseLevel_ = Application::VERBOSE_LEVEL_DEFAULT
staticprivate

Verbose level directs how much output will be printed to console.

Definition at line 251 of file Application.hh.

Referenced by setVerboseLevel(), verboseLevel(), and writeToErrorLog().

◆ warningStream_

std::ostream * Application::warningStream_ = NULL
staticprivate

The stream for user error notifications.

Definition at line 245 of file Application.hh.

Referenced by initialize(), and warningStream().


The documentation for this class was generated from the following files: