OpenASIP 2.2
Loading...
Searching...
No Matches
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
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 */
56
57/**
58 * Destructor.
59 *
60 * Does nothing.
61 */
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 */
74bool
75SymbolAddressCommand::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 */
110std::string
112 return "Returns the address of the given data symbol (global variable).";
113}
bool checkArgumentCount(int argumentCount, int minimum, int maximum)
ScriptInterpreter * interpreter() const
virtual void setError(bool state)
virtual void setResult(DataObject *result)
const TTAProgram::Program & program() const
virtual std::string helpText() const
virtual bool execute(const std::vector< DataObject > &arguments)
InstructionAddress location() const
virtual Address address() const
Definition Label.cc:84
const GlobalScope & globalScopeConst() const
Definition Program.cc:192
const DataLabel & dataLabel(const std::string &name) const
Definition Scope.cc:251