Summary Files Commits Branches @commit @diff @stats
path: root / Year 2 / Implementation of Programming Languages / Transpiler / src / LLVMVisitor / Register.cpp
blob: 329e1ba4befba6d155778f2d7aaa9a87ba6bd721 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "Register.h"

Register::Register(std::string prepend) : prepend(prepend), counter(1) {}

Register& Register::operator++() {
	++counter;
	return *this;
}

Register Register::operator++(int) {
	Register old = *this;
	++(*this);
	return old;
}

std::string Register::operator*() const {
	return prepend + std::to_string(counter);
}

void Register::reset() {
	counter = 0;
}

std::string Register::headless() {
	return std::to_string(counter);
}

std::ostream& operator<<(std::ostream& ostr, const Register& reg) {
	return ostr << *reg;
}