aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <[email protected]>2014-03-16 21:28:43 +0900
committerMITSUNARI Shigeo <[email protected]>2014-03-16 21:28:43 +0900
commit8c3225865c16038034f49e95b20c5b746255c3ad (patch)
tree6fd005a7744cd312e1f170ee989164be9e31c665
parent16416c4c7851d9e69cdd49ed79fed0a8019f9962 (diff)
downloadxbyak-8c3225865c16038034f49e95b20c5b746255c3ad.tar.gz
xbyak-8c3225865c16038034f49e95b20c5b746255c3ad.zip
remove state of Label
-rw-r--r--xbyak/xbyak.h52
1 files changed, 19 insertions, 33 deletions
diff --git a/xbyak/xbyak.h b/xbyak/xbyak.h
index 0f4fb28..515b627 100644
--- a/xbyak/xbyak.h
+++ b/xbyak/xbyak.h
@@ -887,13 +887,10 @@ struct JmpLabel {
};
class Label {
- static const int setByL = 1;
- static const int setByJ = 2;
mutable int id;
- mutable int state;
friend class LabelManager;
public:
- Label() : id(0), state(0) {}
+ Label() : id(0) {}
int getId() const { return id; }
// backward compatibility
@@ -939,7 +936,7 @@ class LabelManager {
@f --> @@.<num + 1>
.*** -> .***.<num>
*/
- std::string convertLabel(std::string label) const
+ std::string getId(std::string label) const
{
if (label == "@f" || label == "@F") {
label = std::string("@@") + Label::toStr(anonymousCount_ + 1);
@@ -950,6 +947,11 @@ class LabelManager {
}
return label;
}
+ int getId(const Label& label) const
+ {
+ if (label.id == 0) label.id = labelId_++;
+ return label.id;
+ }
template<class DefList, class UndefList, class T>
void define_inner(DefList& defList, UndefList& undefList, const T& labelId, size_t addrOffset)
{
@@ -983,6 +985,14 @@ class LabelManager {
undefList.erase(itr);
}
}
+ template<class DefList, class T>
+ bool getOffset_inner(const DefList& defList, size_t *offset, const T& label) const
+ {
+ typename DefList::const_iterator i = defList.find(getId(label));
+ if (i == defList.end()) return false;
+ *offset = i->second;
+ return true;
+ }
public:
LabelManager()
: base_(0)
@@ -1027,49 +1037,25 @@ public:
}
void define2(const Label& label)
{
- if (label.state & Label::setByL) throw Error(ERR_LABEL_IS_SET_BY_L);
- if (label.id == 0) {
- label.id = labelId_++;
- label.state |= Label::setByL;
- }
- define_inner(definedList2_, undefinedList2_, label.id, base_->getSize());
+ define_inner(definedList2_, undefinedList2_, getId(label), base_->getSize());
}
void assign(Label& dst, const Label& src)
{
- if (dst.state == 0) {
- dst = src;
- return;
- }
- if (dst.state & Label::setByL) throw Error(ERR_LABEL_IS_SET_BY_L);
DefinedList2::const_iterator i = definedList2_.find(src.id);
if (i == definedList2_.end()) throw Error(ERR_LABEL_ISNOT_SET_BY_L);
- dst.state |= Label::setByL;
define_inner(definedList2_, undefinedList2_, dst.id, i->second);
}
bool getOffset(size_t *offset, const std::string& label) const
{
- const std::string newLabel = convertLabel(label);
- DefinedList::const_iterator itr = definedList_.find(newLabel);
- if (itr == definedList_.end()) return false;
- *offset = itr->second;
- return true;
+ return getOffset_inner(definedList_, offset, label);
}
bool getOffset(size_t *offset, const Label& label) const
{
- if (label.id == 0) {
- label.id = labelId_++;
- label.state |= Label::setByJ;
- return false;
- }
- DefinedList2::const_iterator itr = definedList2_.find(label.id);
- if (itr == definedList2_.end()) return false;
- *offset = itr->second;
- return true;
+ return getOffset_inner(definedList2_, offset, label);
}
void addUndefinedLabel(const std::string& label, const JmpLabel& jmp)
{
- std::string newLabel = convertLabel(label);
- undefinedList_.insert(UndefinedList::value_type(newLabel, jmp));
+ undefinedList_.insert(UndefinedList::value_type(getId(label), jmp));
}
void addUndefinedLabel(const Label& label, const JmpLabel& jmp)
{