Skip to content

Commit

Permalink
RISC-V: implement ++ operators for TR::RealRegister::RegNum
Browse files Browse the repository at this point in the history
This allows one using for-loop over registers without having to cast
to int and back.

Signed-off-by: Jan Vrany <jan.vrany@fit.cvut.cz>
  • Loading branch information
janvrany committed Apr 7, 2021
1 parent bfa41af commit dd45ea2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/riscv/codegen/RealRegister.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2019 IBM Corp. and others
* Copyright (c) 2019, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -57,4 +57,17 @@ inline TR::RealRegister *toRealRegister(TR::Register *r)
return static_cast<TR::RealRegister *>(r);
}


inline TR::RealRegister::RegNum& operator++(TR::RealRegister::RegNum& rn)
{
rn = static_cast<TR::RealRegister::RegNum>(static_cast<int>(rn + 1));
return rn;
}

inline TR::RealRegister::RegNum operator++(TR::RealRegister::RegNum& in, int)
{
TR::RealRegister::RegNum out = in;
++in;
return out;
}
#endif

0 comments on commit dd45ea2

Please sign in to comment.