Commit dddbcfb9 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

2005-04-02 Benoît Perrot <benoit@lrde.epita.fr>

	Introduce `lockable' facility.

	* src/misc/lockable.hh: New file.
	* src/misc/Makefile.am: Distribute it.
	* src/inst/text_label.hh, src/inst/exp.hh, src/inst/label.hh,
	* src/inst/int_exp.hh, src/inst/int_exp.cc:
	Use lockable.
	* dev/inst-solver-gen.py: Update accordingly.
parent 956e2a0e
2005-04-02 Benoît Perrot <benoit@lrde.epita.fr>
Introduce `lockable' facility.
* src/misc/lockable.hh: New file.
* src/misc/Makefile.am: Distribute it.
* src/inst/text_label.hh, src/inst/exp.hh, src/inst/label.hh,
* src/inst/int_exp.hh, src/inst/int_exp.cc:
Use lockable.
* dev/inst-solver-gen.py: Update accordingly.
2005-04-02 Benoît Perrot <benoit@lrde.epita.fr>
Split `exp' files.
......
......@@ -150,10 +150,10 @@ print """#include \"inst/program_solver.hh\"
namespace inst
{
void
ProgramSolver::visit(IntExp &i)
ProgramSolver::visit(IntExp &)
{
i.set_immediate(i.get_integer());
}
void
......
......@@ -21,6 +21,8 @@
# include <iostream>
# include "misc/contract.hh"
# include "misc/lockable.hh"
# include "misc/counted_ptr.hh"
# include "inst/exp-visitor.hh"
......@@ -28,13 +30,13 @@
namespace inst
{
class Exp
class Exp:
public misc::lockable
{
protected:
Exp():
immediate_(-2097) // Caracteristic initial value
{
}
immediate_(0)
{}
public:
virtual ~Exp();
......@@ -47,16 +49,22 @@ namespace inst
public:
operator int () const
{
return immediate_;
return get_immediate();
}
int get_immediate()
int get_immediate() const
{
precondition(locked());
return immediate_;
}
void set_immediate(int i)
void set_immediate(int i)
{
precondition(!locked());
lock();
immediate_ = i;
}
protected:
int immediate_;
};
......
......@@ -37,10 +37,4 @@ namespace inst
v.visit(*this);
}
void
IntExp::print(std::ostream& ostr) const
{
ostr << integer_;
}
} // namespace inst
......@@ -28,27 +28,15 @@ namespace inst
public Exp
{
public:
IntExp(int integer):
integer_(integer)
IntExp(int integer)
{
set_immediate(integer);
}
virtual ~IntExp();
public:
virtual void accept(ConstExpVisitor& v) const;
virtual void accept(ExpVisitor& v);
public:
int get_integer() const
{
return integer_;
}
public:
virtual void print(std::ostream& ostr) const;
protected:
int integer_;
};
} // namespace inst
......
......@@ -23,12 +23,15 @@
# include <string>
# include <iostream>
# include "misc/contract.hh"
# include "misc/lockable.hh"
# include "misc/unique_string.hh"
namespace inst
{
class Label
class Label:
public misc::lockable
{
public:
struct deref_ptr_less:
......@@ -47,7 +50,9 @@ namespace inst
public:
Label(const std::string &s, int offset):
ustr_(misc::unique_string::create(s)), offset_(offset)
{}
{
lock();
}
public:
const std::string &get_name() const
......@@ -56,6 +61,8 @@ namespace inst
}
int get_offset() const
{
precondition(locked());
return offset_;
}
......
......@@ -37,6 +37,9 @@ namespace inst
public:
void set_offset(int offset)
{
precondition(!locked());
lock();
offset_ = offset;
}
......
......@@ -3,6 +3,7 @@ noinst_LIBRARIES = libmisc.a
libmisc_a_CPPFLAGS = -I $(top_srcdir)/src -I $(top_builddir)/src
libmisc_a_SOURCES = \
contract.hh \
lockable.hh \
deref.hh \
escape.hh \
has.hh \
......
//
// lockable.hh: lock interface for contract verification.
// Copyright (C) 2005 Benoit Perrot <benoit@lrde.epita.fr>
//
// Nolimips is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nolimips is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#ifndef MISC_LOCKABLE_HH
# define MISC_LOCKABLE_HH
namespace misc
{
class lockable
{
public:
lockable()
#ifndef NDEBUG
: locked_(false)
#endif // !NDEBUG
{}
public:
void lock() const
{
#ifndef NDEBUG
locked_ = true;
#endif // !NDEBUG
}
void unlock() const
{
#ifndef NDEBUG
locked_ = false;
#endif // !NDEBUG
}
#ifndef NDEBUG
bool locked() const
{
return locked_;
}
#endif // !NDEBUG
#ifndef NDEBUG
private:
mutable bool locked_;
#endif // !NDEBUG
};
} // namespace misc
#endif // !MISC_LOCKABLE_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment