OpenASIP  2.0
Functions
TestOsal.cc File Reference
#include <iostream>
#include "TestOsal.hh"
#include "Operation.hh"
#include "Conversion.hh"
#include "SimValue.hh"
#include "Application.hh"
#include "LineReader.hh"
#include "LineReaderFactory.hh"
#include "CmdHelp.hh"
#include "StringTools.hh"
#include "InterpreterContext.hh"
#include "OperationSimulator.hh"
#include "IdealSRAM.hh"
#include "BaseType.hh"
#include "TCEString.hh"
#include "tce_config.h"
#include "OperationBehavior.hh"
#include "OperationPool.hh"
Include dependency graph for TestOsal.cc:

Go to the source code of this file.

Functions

void executeCommand (OsalInterpreter &interpreter, string command)
 
int main (int argc, char *argv[])
 

Detailed Description

Implementation of test_osal.

Author
Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
Note
rating: red

Definition in file TestOsal.cc.

Function Documentation

◆ executeCommand()

void executeCommand ( OsalInterpreter interpreter,
string  command 
)

Executes given command with interpreter.

Parameters
interpreterInterpreter which executes the command.
commandThe command to be executed.
printTrue, if result is printed.

Definition at line 1039 of file TestOsal.cc.

1039  {
1040  bool succeeded = interpreter.interpret(command);
1041  if (interpreter.result() != "") {
1042  if (!succeeded) {
1043  cout << "Error: ";
1044  }
1045  cout << interpreter.result() << endl;
1046  }
1047 }

References SimpleScriptInterpreter::interpret(), and ScriptInterpreter::result().

Referenced by main().

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Main program.

Definition at line 942 of file TestOsal.cc.

942  {
943 
945  try {
946  options.parse(argv, argc);
947  } catch (ParserStopRequest) {
948  return EXIT_SUCCESS;
949  } catch (const IllegalCommandLine& i) {
950  cerr << i.errorMessage() << endl;
951  return EXIT_FAILURE;
952  }
953 
954  OsalInterpreter interpreter;
956  TesterContext context;
957  CmdTrigger* trigger = new CmdTrigger();
958  CmdHelp* help = new CmdHelp();
959  CmdReset* reset = new CmdReset();
960  CmdOutput* output = new CmdOutput();
961  CmdQuit* quit = new CmdQuit();
962  CmdRegister* reg = new CmdRegister();
963  CmdMem* mem = new CmdMem();
964  CmdAdvanceClock* clock = new CmdAdvanceClock();
965 
966  interpreter.initialize(argc, argv, &context, reader);
967  interpreter.addCustomCommand(trigger);
968  interpreter.addCustomCommand(help);
969  interpreter.addCustomCommand(reset);
970  interpreter.addCustomCommand(output);
971  interpreter.addCustomCommand(quit);
972  interpreter.addCustomCommand(reg);
973  interpreter.addCustomCommand(mem);
974  interpreter.addCustomCommand(clock);
975  reader->initialize(">> ");
976 
977  // memory is 64k bytes
978  // TODO: what endianess
979  IdealSRAM* memory = new IdealSRAM(0, 65535, 8, false);
980  context.operationContext().setMemory(memory);
981 
982  if (options.numberOfArguments() > 0) {
983  // batch mode
984 
985  string command = "trigger ";
986  for (int i = 1; i <= options.numberOfArguments(); i++) {
987  string token = options.argument(i);
988  if (token.substr(token.size() - 1) == ";") {
989  // an end of the command
990  command += token.substr(0, token.size() - 1);
991  executeCommand(interpreter, command);
992  command = "trigger ";
993  } else {
994  command += token + " ";
995  }
996  }
997  if (command != "") {
998  executeCommand(interpreter, command);
999  }
1000 
1001  } else {
1002  // interactive mode
1003  string command = "";
1004  InterpreterContext& interpCont = interpreter.context();
1005  TesterContext& testCont = *dynamic_cast<TesterContext*>(&interpCont);
1006  while (testCont.cont()) {
1007  try {
1008  command = reader->readLine();
1009  } catch (const EndOfFile&) {
1010  interpreter.interpret("quit\n");
1011  break;
1012  }
1013  command = StringTools::trim(command);
1014  if (command == "") {
1015  continue;
1016  }
1017  if (command.find("!") == string::npos) {
1018  command = "trigger " + command;
1019  } else {
1020  command = command.substr(1, command.length());
1021  }
1022  executeCommand(interpreter, command);
1023  }
1024  }
1025  delete reader;
1026  delete memory;
1027  interpreter.finalize();
1028  return EXIT_SUCCESS;
1029 }

References ScriptInterpreter::addCustomCommand(), CmdLineParser::argument(), TesterContext::cont(), SimpleScriptInterpreter::context(), Exception::errorMessage(), executeCommand(), ScriptInterpreter::finalize(), SimpleScriptInterpreter::initialize(), LineReader::initialize(), SimpleScriptInterpreter::interpret(), LineReaderFactory::lineReader(), CmdLineParser::numberOfArguments(), TesterContext::operationContext(), options, CmdLineOptions::parse(), LineReader::readLine(), OperationContext::setMemory(), and StringTools::trim().

Here is the call graph for this function:
ScriptInterpreter::finalize
virtual void finalize()
Definition: ScriptInterpreter.cc:329
OperationContext::setMemory
void setMemory(Memory *memory)
Definition: OperationContext.cc:238
LineReaderFactory::lineReader
static LineReader * lineReader()
Definition: LineReaderFactory.cc:54
ParserStopRequest
Definition: Exception.hh:491
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
CmdLineParser::numberOfArguments
virtual int numberOfArguments() const
SimpleScriptInterpreter::context
virtual InterpreterContext & context() const
Definition: SimpleScriptInterpreter.cc:185
SimpleScriptInterpreter::initialize
virtual void initialize(int argc, char *argv[], InterpreterContext *context, LineReader *reader)
Definition: SimpleScriptInterpreter.cc:64
CmdMem
Definition: TestOsal.hh:168
CmdTrigger
Definition: TestOsal.hh:58
IllegalCommandLine
Definition: Exception.hh:438
LineReader::readLine
virtual std::string readLine(std::string prompt="")=0
TesterContext::cont
bool cont() const
Definition: TestOsal.cc:441
TesterContext
Definition: TestOsal.hh:212
TesterContext::operationContext
OperationContext & operationContext()
Definition: TestOsal.cc:453
CmdQuit
Definition: TestOsal.hh:94
InterpreterContext
Definition: InterpreterContext.hh:40
CmdReset
Definition: TestOsal.hh:77
executeCommand
void executeCommand(OsalInterpreter &interpreter, string command)
Definition: TestOsal.cc:1039
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
CmdLineOptions::parse
void parse(char *argv[], int argc)
Definition: CmdLineOptions.cc:107
OsalInterpreter
Definition: TestOsal.hh:249
options
static MachInfoCmdLineOptions options
Definition: MachInfo.cc:46
StringTools::trim
static std::string trim(const std::string &source)
Definition: StringTools.cc:55
CmdHelp
Definition: CmdHelp.hh:50
CmdRegister
Definition: TestOsal.hh:145
LineReader
Definition: LineReader.hh:52
LineReader::initialize
virtual void initialize(std::string defPrompt="", FILE *in=stdin, FILE *out=stdout, FILE *err=stderr)=0
SimpleScriptInterpreter::interpret
virtual bool interpret(const std::string &commandLine)
Definition: SimpleScriptInterpreter.cc:118
IdealSRAM
Definition: IdealSRAM.hh:55
CmdOutput
Definition: TestOsal.hh:114
CmdAdvanceClock
Definition: TestOsal.hh:195
EndOfFile
Definition: Exception.hh:189
CmdLineParser::argument
virtual std::string argument(int index) const
ScriptInterpreter::addCustomCommand
virtual void addCustomCommand(CustomCommand *command)
Definition: ScriptInterpreter.cc:78
OsalCmdLineOptions
Definition: TestOsal.hh:270