Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tiger
nolimips
Commits
2b10fad1
Commit
2b10fad1
authored
Jul 12, 2003
by
Benoit Perrot
Browse files
Factorize Section code.
parent
64de91bc
Changes
4
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
2b10fad1
2003-07-12 Benot Perrot <benoit@lrde.epita.fr>
* src/inst/section.hh,
* src/inst/data_section.hh, src/inst/text_section.hh:
Factorize Section code.
2003-07-11 Benot Perrot <benoit@lrde.epita.fr>
* config/{depcomp, install-sh, missing, mkinstalldirs}:
...
...
src/inst/data_section.hh
View file @
2b10fad1
...
...
@@ -21,14 +21,10 @@
// FIXME: lack of compatibility
# include <stdint.h>
# include <string.h>
# include <list>
# include <map>
# include <iostream>
# include "misc/contract.hh"
# include "inst/label.hh"
# include "inst/section.hh"
# include "inst/inst.hh"
// FIXME: should not be a #define !
...
...
@@ -37,7 +33,8 @@
namespace
inst
{
class
DataSection
class
DataSection
:
public
Section
{
typedef
std
::
list
<
const
Label
*>
label_list_t
;
typedef
std
::
map
<
Label
,
int
>
label_to_offset_t
;
...
...
@@ -46,7 +43,7 @@ namespace inst
DataSection
()
:
_size
(
0
)
{
memset
(
_
bytes
,
0
,
INST_DATA_DATASIZE
);
std
::
memset
(
bytes
,
0
,
INST_DATA_DATASIZE
);
}
public:
...
...
@@ -58,21 +55,7 @@ namespace inst
public:
void
add_label
(
Label
&
label
)
{
_offsets
[
label
]
=
_size
;
_labels
[
_size
].
push_back
(
&
label
);
}
bool
has_label
(
const
Label
&
label
)
const
{
label_to_offset_t
::
const_iterator
it
=
_offsets
.
find
(
label
);
return
it
!=
_offsets
.
end
();
}
int
get_offset
(
const
Label
&
label
)
const
{
label_to_offset_t
::
const_iterator
it
=
_offsets
.
find
(
label
);
assertion
(
it
!=
_offsets
.
end
());
return
(
*
it
).
second
;
Section
::
add_label
(
label
,
_size
);
}
public:
...
...
@@ -87,7 +70,7 @@ namespace inst
{
// FIXME: check b in byte range
precondition
(
_size
<
INST_DATA_DATASIZE
);
_
bytes
[
_size
]
=
b
;
bytes
[
_size
]
=
b
;
++
_size
;
}
...
...
@@ -105,43 +88,17 @@ namespace inst
add_byte
(
0
);
}
public:
void
store_byte
(
int
offset
,
int
b
)
{
precondition
((
0
<=
offset
&&
offset
<
_size
));
_bytes
[
offset
]
=
(
uint8_t
)(
b
);
}
void
store_word
(
int
offset
,
int
w
)
{
precondition
((
0
<=
offset
)
&&
((
offset
+
3
)
<
_size
));
unsigned
pow
=
256
*
256
*
256
;
for
(
unsigned
i
=
0
;
i
<
4
;
++
i
,
++
offset
,
pow
/=
256
)
_bytes
[
offset
]
=
w
/
pow
;
}
public:
int
load_byte
(
int
offset
)
const
{
precondition
((
0
<=
offset
&&
offset
<
_size
));
return
(
int8_t
)
_bytes
[
offset
];
}
int
load_word
(
int
offset
)
const
{
int
w
=
0
;
for
(
unsigned
i
=
0
;
i
<
4
;
++
i
,
++
offset
)
{
precondition
((
0
<=
offset
&&
offset
<
_size
));
w
=
(
w
*
256
)
+
_bytes
[
offset
];
}
return
w
;
return
(
int8_t
)
bytes
[
offset
];
}
public:
void
print
(
std
::
ostream
&
ostr
)
const
virtual
void
print
(
std
::
ostream
&
ostr
)
const
{
if
(
_size
==
0
)
return
;
...
...
@@ -152,14 +109,14 @@ namespace inst
while
(
i
<
_size
)
{
std
::
map
<
int
,
label_list_t
>::
const_iterator
it
=
_
labels
.
find
(
i
);
if
(
it
!=
_
labels
.
end
())
labels
.
find
(
i
);
if
(
it
!=
labels
.
end
())
for
(
label_list_t
::
const_iterator
l
=
(
*
it
).
second
.
begin
();
l
!=
(
*
it
).
second
.
end
();
++
l
)
ostr
<<
*
(
*
l
)
<<
':'
<<
std
::
endl
;
ostr
<<
"
\t
.byte
\t
0x"
<<
std
::
hex
<<
static_cast
<
unsigned
>
(
_
bytes
[
i
++
])
<<
std
::
hex
<<
static_cast
<
unsigned
>
(
bytes
[
i
++
])
<<
std
::
endl
;
}
ostr
<<
std
::
dec
;
...
...
@@ -167,19 +124,9 @@ namespace inst
protected:
int
_size
;
uint8_t
_bytes
[
INST_DATA_DATASIZE
];
std
::
map
<
int
,
label_list_t
>
_labels
;
label_to_offset_t
_offsets
;
uint8_t
bytes
[
INST_DATA_DATASIZE
];
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
DataSection
&
s
)
{
s
.
print
(
ostr
);
return
ostr
;
}
}
// namespace inst
#endif // !INST_DATA_SECTION_HH
src/inst/section.hh
0 → 100644
View file @
2b10fad1
//
// This file is part of Mipsy, a tiny MIPS simulator
// Copyright (C) 2003 Benoit Perrot <benoit@lrde.epita.fr>
//
// Mipsy 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.
//
// Mipsy 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 INST_SECTION_HH
# define INST_SECTION_HH
# include <list>
# include <map>
# include "misc/contract.hh"
# include "inst/label.hh"
namespace
inst
{
class
Section
{
protected:
typedef
std
::
list
<
const
Label
*>
label_list_t
;
typedef
std
::
map
<
const
Label
,
int
>
label_offset_t
;
public:
Section
()
{
}
virtual
~
Section
()
{
}
protected:
void
add_label
(
Label
&
label
,
int
offset
)
{
// FIXME: check that this label has not already been added.
offsets
[
label
]
=
offset
;
labels
[
offset
].
push_back
(
&
label
);
}
public:
bool
has_label
(
const
Label
&
label
)
const
{
label_offset_t
::
const_iterator
it
=
offsets
.
find
(
label
);
return
it
!=
offsets
.
end
();
}
int
get_offset
(
const
Label
&
label
)
const
{
label_offset_t
::
const_iterator
it
=
offsets
.
find
(
label
);
assertion
(
it
!=
offsets
.
end
());
return
(
*
it
).
second
;
}
public:
virtual
void
print
(
std
::
ostream
&
ostr
)
const
=
0
;
protected:
// FIXME: Might be static, to avoid multi-definition of labels.
std
::
map
<
int
,
label_list_t
>
labels
;
label_offset_t
offsets
;
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
Section
&
s
)
{
s
.
print
(
ostr
);
return
ostr
;
}
}
// namespace inst
#endif // !INST_SECTION_HH
src/inst/text_section.hh
View file @
2b10fad1
...
...
@@ -20,106 +20,80 @@
# define INST_TEXT_SECTION_HH
# include <vector>
# include <list>
# include <map>
# include <iostream>
# include "misc/contract.hh"
# include "inst/
label
.hh"
# include "inst/
section
.hh"
# include "inst/inst.hh"
namespace
inst
{
class
TextSection
class
TextSection
:
public
Section
{
typedef
std
::
list
<
const
Label
*>
label_list_t
;
typedef
std
::
map
<
const
Label
,
int
>
label_to_offset_t
;
public:
TextSection
()
{
}
public:
void
add_inst
(
inst
::
Inst
&
i
nst
)
int
size
()
co
nst
{
_insts
.
push_back
(
&
inst
);
return
insts
.
size
(
);
}
public:
void
add_label
(
Label
&
label
)
{
// FIXME: check that this label has not already been added.
_offsets
[
label
]
=
_insts
.
size
()
*
4
;
_labels
.
resize
(
_insts
.
size
()
+
1
);
_labels
[
_insts
.
size
()].
push_back
(
&
label
);
}
bool
has_label
(
const
Label
&
label
)
const
{
label_to_offset_t
::
const_iterator
it
=
_offsets
.
find
(
label
);
return
it
!=
_offsets
.
end
();
}
int
get_offset
(
const
Label
&
label
)
const
{
label_to_offset_t
::
const_iterator
it
=
_offsets
.
find
(
label
);
assertion
(
it
!=
_offsets
.
end
());
return
(
*
it
).
second
;
Section
::
add_label
(
label
,
insts
.
size
()
*
4
);
}
public:
int
size
()
co
nst
void
add_inst
(
inst
::
Inst
&
i
nst
)
{
return
_insts
.
size
(
);
insts
.
push_back
(
&
inst
);
}
public:
const
inst
::
Inst
&
operator
[](
int
offset
)
const
{
precondition
(
0
<=
offset
&&
(
unsigned
)
offset
<
_
insts
.
size
());
precondition
(
0
<=
offset
&&
(
unsigned
)
offset
<
insts
.
size
());
assertion
(
_
insts
[
offset
]);
return
*
(
_
insts
[
offset
]);
assertion
(
insts
[
offset
]);
return
*
(
insts
[
offset
]);
}
inst
::
Inst
&
operator
[](
int
offset
)
{
precondition
(
0
<=
offset
&&
(
unsigned
)
offset
<
_
insts
.
size
());
precondition
(
0
<=
offset
&&
(
unsigned
)
offset
<
insts
.
size
());
assertion
(
_
insts
[
offset
]);
return
*
(
_
insts
[
offset
]);
assertion
(
insts
[
offset
]);
return
*
(
insts
[
offset
]);
}
public:
void
print
(
std
::
ostream
&
ostr
)
const
virtual
void
print
(
std
::
ostream
&
ostr
)
const
{
ostr
<<
"
\t
.text"
<<
std
::
endl
;
for
(
unsigned
i
=
0
;
i
<
_
insts
.
size
();
++
i
)
for
(
unsigned
i
=
0
;
i
<
insts
.
size
();
++
i
)
{
if
(
i
<
_labels
.
size
())
for
(
label_list_t
::
const_iterator
it
=
_labels
[
i
].
begin
();
it
!=
_labels
[
i
].
end
();
++
it
)
ostr
<<
*
(
*
it
)
<<
":"
<<
std
::
endl
;
ostr
<<
'\t'
<<
*
(
_insts
[
i
])
<<
std
::
endl
;
std
::
map
<
int
,
label_list_t
>::
const_iterator
it
=
labels
.
find
(
i
);
if
(
it
!=
labels
.
end
())
for
(
label_list_t
::
const_iterator
l
=
(
*
it
).
second
.
begin
();
l
!=
(
*
it
).
second
.
end
();
++
l
)
ostr
<<
*
(
*
l
)
<<
':'
<<
std
::
endl
;
ostr
<<
'\t'
<<
*
(
insts
[
i
])
<<
std
::
endl
;
}
}
protected:
std
::
vector
<
inst
::
Inst
*>
_insts
;
std
::
vector
<
label_list_t
>
_labels
;
label_to_offset_t
_offsets
;
std
::
vector
<
inst
::
Inst
*>
insts
;
};
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
ostr
,
const
TextSection
&
s
)
{
s
.
print
(
ostr
);
return
ostr
;
}
}
// namespace inst
#endif // !INST_TEXT_SECTION_HH
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment