OpenASIP  2.0
SymbolAddressCommand.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file SymbolAddressCommand.cc
26  *
27  * Implementation of SymbolAddressCommand class
28  *
29  * @author Pekka Jääskeläinen 2008 (pjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "SymbolAddressCommand.hh"
34 #include "SimulatorFrontend.hh"
35 #include "MemorySystem.hh"
36 #include "SimulatorToolbox.hh"
37 #include "Memory.hh"
38 #include "StringTools.hh"
39 #include "Address.hh"
40 #include "NullAddressSpace.hh"
41 #include "SimValue.hh"
42 #include "GlobalScope.hh"
43 #include "DataLabel.hh"
44 #include "Program.hh"
45 
46 #include <iostream>
47 
48 /**
49  * Constructor.
50  *
51  * Sets the name of the command to the base class.
52  */
54  SimControlLanguageCommand("symbol_address") {
55 }
56 
57 /**
58  * Destructor.
59  *
60  * Does nothing.
61  */
63 }
64 
65 /**
66  * Executes the "symbol_address" command.
67  *
68  * Prints the address of a data symbol.
69  *
70  * @param arguments The symbol to print.
71  * @return True in case simulation is initialized and arguments are ok.
72  * @exception NumberFormatException Is never thrown by this command.
73  */
74 bool
75 SymbolAddressCommand::execute(const std::vector<DataObject>& arguments) {
76  const int argumentCount = arguments.size() - 1;
77  if (!checkArgumentCount(argumentCount, 1, 1)) {
78  return false;
79  }
80 
81  if (!checkProgramLoaded()) {
82  return false;
83  }
84 
85  const TTAProgram::GlobalScope& globalScope =
87  try {
88  TTAProgram::Address address =
89  globalScope.dataLabel(arguments.at(1).stringValue()).address();
90  interpreter()->setResult(static_cast<int>(address.location()));
91  interpreter()->setError(false);
92  return true;
93  } catch (const KeyNotFound&) {
94  // couldn't evaluate the label
96  "Symbol not found. Try adding '_' prefix to the symbol, "
97  "e.g. '_foo'.");
98  interpreter()->setError(true);
99  return false;
100  }
101 }
102 
103 /**
104  * Returns the help text for this command.
105  *
106  * Help text is searched from SimulatorTextGenerator.
107  *
108  * @return The help text.
109  */
110 std::string
112  return "Returns the address of the given data symbol (global variable).";
113 }
CustomCommand::checkArgumentCount
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
Definition: CustomCommand.cc:82
SymbolAddressCommand::helpText
virtual std::string helpText() const
Definition: SymbolAddressCommand.cc:111
SimulatorFrontend::program
const TTAProgram::Program & program() const
Definition: SimulatorFrontend.cc:276
TTAProgram::Address
Definition: Address.hh:51
Memory.hh
SimControlLanguageCommand::checkProgramLoaded
bool checkProgramLoaded()
Definition: SimControlLanguageCommand.cc:180
MemorySystem.hh
DataLabel.hh
GlobalScope.hh
TTAProgram::Program::globalScopeConst
const GlobalScope & globalScopeConst() const
Definition: Program.cc:192
StringTools.hh
SymbolAddressCommand::SymbolAddressCommand
SymbolAddressCommand()
Definition: SymbolAddressCommand.cc:53
SimulatorToolbox.hh
SymbolAddressCommand.hh
NullAddressSpace.hh
TTAProgram::GlobalScope
Definition: GlobalScope.hh:47
TTAProgram::Address::location
InstructionAddress location() const
SimulatorFrontend.hh
TTAProgram::Label::address
virtual Address address() const
Definition: Label.cc:84
CustomCommand::interpreter
ScriptInterpreter * interpreter() const
ScriptInterpreter::setResult
virtual void setResult(DataObject *result)
Definition: ScriptInterpreter.cc:128
SymbolAddressCommand::execute
virtual bool execute(const std::vector< DataObject > &arguments)
Definition: SymbolAddressCommand.cc:75
SymbolAddressCommand::~SymbolAddressCommand
virtual ~SymbolAddressCommand()
Definition: SymbolAddressCommand.cc:62
Program.hh
Address.hh
SimValue.hh
TTAProgram::Scope::dataLabel
const DataLabel & dataLabel(const std::string &name) const
Definition: Scope.cc:251
ScriptInterpreter::setError
virtual void setError(bool state)
Definition: ScriptInterpreter.cc:205
KeyNotFound
Definition: Exception.hh:285
SimControlLanguageCommand
Definition: SimControlLanguageCommand.hh:63
SimControlLanguageCommand::simulatorFrontend
SimulatorFrontend & simulatorFrontend()
Definition: SimControlLanguageCommand.cc:214