| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- #pragma once
- namespace IR {
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::Use
- ///
- /// If this operand is not inUse, use it. Otherwise, make a copy.
- ///
- ///----------------------------------------------------------------------------
- inline Opnd *
- Opnd::Use(Func *func)
- {
- if (!m_inUse)
- {
- m_inUse = true;
- return this;
- }
- Opnd * newOpnd = this->Copy(func);
- newOpnd->m_inUse = true;
- return newOpnd;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::UnUse
- ///
- ///----------------------------------------------------------------------------
- inline void
- Opnd::UnUse()
- {
- AssertMsg(m_inUse, "Expected inUse to be set...");
- m_inUse = false;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsSymOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsSymOpnd() const
- {
- return GetKind() == OpndKindSym;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsSymOpnd
- ///
- /// Use this opnd as a SymOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline SymOpnd *
- Opnd::AsSymOpnd()
- {
- AssertMsg(this->IsSymOpnd(), "Bad call to AsSymOpnd()");
- return reinterpret_cast<SymOpnd *>(this);
- }
- inline PropertySymOpnd *
- Opnd::AsPropertySymOpnd()
- {
- AssertMsg(this->IsSymOpnd() && this->AsSymOpnd()->IsPropertySymOpnd(), "Bad call to AsPropertySymOpnd()");
- return reinterpret_cast<PropertySymOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsRegOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsRegOpnd() const
- {
- return GetKind() == OpndKindReg;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsRegOpnd
- ///
- /// Use this opnd as a RegOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline const RegOpnd *
- Opnd::AsRegOpnd() const
- {
- AssertMsg(this->IsRegOpnd(), "Bad call to AsRegOpnd()");
- return reinterpret_cast<const RegOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsRegOpnd
- ///
- /// Use this opnd as a RegOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline RegOpnd *
- Opnd::AsRegOpnd()
- {
- AssertMsg(this->IsRegOpnd(), "Bad call to AsRegOpnd()");
- return reinterpret_cast<RegOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsRegBVOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsRegBVOpnd() const
- {
- return GetKind() == OpndKindRegBV;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsRegBVOpnd
- ///
- /// Use this opnd as a RegBVOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline RegBVOpnd *
- Opnd::AsRegBVOpnd()
- {
- AssertMsg(this->IsRegBVOpnd(), "Bad call to AsRegOpnd()");
- return reinterpret_cast<RegBVOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsIntConstOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsIntConstOpnd() const
- {
- return GetKind() == OpndKindIntConst;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsIntConstOpnd
- ///
- /// Use this opnd as a IntConstOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline IntConstOpnd *
- Opnd::AsIntConstOpnd()
- {
- AssertMsg(this->IsIntConstOpnd(), "Bad call to AsIntConstOpnd()");
- return reinterpret_cast<IntConstOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsFloatConstOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsFloatConstOpnd() const
- {
- return GetKind() == OpndKindFloatConst;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsFloatConstOpnd
- ///
- /// Use this opnd as a FloatConstOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline FloatConstOpnd *
- Opnd::AsFloatConstOpnd()
- {
- AssertMsg(this->IsFloatConstOpnd(), "Bad call to AsFloatConstOpnd()");
- return reinterpret_cast<FloatConstOpnd *>(this);
- }
- inline bool
- Opnd::IsSimd128ConstOpnd() const
- {
- return GetKind() == OpndKindSimd128Const;
- }
- inline Simd128ConstOpnd *
- Opnd::AsSimd128ConstOpnd()
- {
- AssertMsg(this->IsSimd128ConstOpnd(), "Bad call to AsSimd128ConstOpnd()");
- return reinterpret_cast<Simd128ConstOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsHelperCallOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsHelperCallOpnd() const
- {
- return GetKind() == OpndKindHelperCall;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsHelperCallOpnd
- ///
- /// Use this opnd as a HelperCallOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline HelperCallOpnd *
- Opnd::AsHelperCallOpnd()
- {
- AssertMsg(this->IsHelperCallOpnd(), "Bad call to AsHelperCallOpnd()");
- return reinterpret_cast<HelperCallOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsAddrOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsAddrOpnd() const
- {
- return GetKind() == OpndKindAddr;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsAddrOpnd
- ///
- /// Use this opnd as a AddrOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline AddrOpnd *
- Opnd::AsAddrOpnd()
- {
- AssertMsg(this->IsAddrOpnd(), "Bad call to AsAddrOpnd()");
- return reinterpret_cast<AddrOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsIndirOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsIndirOpnd() const
- {
- return GetKind() == OpndKindIndir;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsIndirOpnd
- ///
- /// Use this opnd as a IndirOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline IndirOpnd *
- Opnd::AsIndirOpnd()
- {
- AssertMsg(this->IsIndirOpnd(), "Bad call to AsIndirOpnd()");
- return reinterpret_cast<IndirOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsMemRefOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsMemRefOpnd() const
- {
- return GetKind() == OpndKindMemRef;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::AsMemRefOpnd
- ///
- /// Use this opnd as a MemRefOpnd.
- ///
- ///----------------------------------------------------------------------------
- inline MemRefOpnd *
- Opnd::AsMemRefOpnd()
- {
- AssertMsg(this->IsMemRefOpnd(), "Bad call to AsMemRefOpnd()");
- return reinterpret_cast<MemRefOpnd *>(this);
- }
- inline bool
- Opnd::IsLabelOpnd() const
- {
- return GetKind() == OpndKindLabel;
- }
- inline LabelOpnd *
- Opnd::AsLabelOpnd()
- {
- AssertMsg(this->IsLabelOpnd(), "Bad call to AsLabelOpnd()");
- return reinterpret_cast<LabelOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsImmediateOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsImmediateOpnd() const
- {
- return this->IsIntConstOpnd() || this->IsAddrOpnd() || this->IsHelperCallOpnd();
- }
- inline bool Opnd::IsMemoryOpnd() const
- {
- switch(GetKind())
- {
- case OpndKindSym:
- case OpndKindIndir:
- case OpndKindMemRef:
- return true;
- }
- return false;
- }
- ///----------------------------------------------------------------------------
- ///
- /// Opnd::IsConstOpnd
- ///
- ///----------------------------------------------------------------------------
- inline bool
- Opnd::IsConstOpnd() const
- {
- bool result = this->IsImmediateOpnd() || this->IsFloatConstOpnd();
- result = result || this->IsSimd128ConstOpnd();
- return result;
- }
- ///----------------------------------------------------------------------------
- ///
- /// RegOpnd::AsArrayRegOpnd
- ///
- ///----------------------------------------------------------------------------
- inline ArrayRegOpnd *RegOpnd::AsArrayRegOpnd()
- {
- Assert(IsArrayRegOpnd());
- return static_cast<ArrayRegOpnd *>(this);
- }
- ///----------------------------------------------------------------------------
- ///
- /// RegOpnd::GetReg
- ///
- ///----------------------------------------------------------------------------
- inline RegNum
- RegOpnd::GetReg() const
- {
- return m_reg;
- }
- ///----------------------------------------------------------------------------
- ///
- /// RegOpnd::SetReg
- ///
- ///----------------------------------------------------------------------------
- inline void
- RegOpnd::SetReg(RegNum reg)
- {
- m_reg = reg;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::GetBaseOpnd
- ///
- ///----------------------------------------------------------------------------
- inline RegOpnd *
- IndirOpnd::GetBaseOpnd() const
- {
- return this->m_baseOpnd;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::GetIndexOpnd
- ///
- ///----------------------------------------------------------------------------
- inline RegOpnd *
- IndirOpnd::GetIndexOpnd()
- {
- return m_indexOpnd;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::GetOffset
- ///
- ///----------------------------------------------------------------------------
- inline int32
- IndirOpnd::GetOffset() const
- {
- return m_offset;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::SetOffset
- ///
- ///----------------------------------------------------------------------------
- inline void
- IndirOpnd::SetOffset(int32 offset, bool dontEncode /* = false */)
- {
- m_offset = offset;
- m_dontEncode = dontEncode;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::GetScale
- ///
- ///----------------------------------------------------------------------------
- inline byte
- IndirOpnd::GetScale() const
- {
- return m_scale;
- }
- ///----------------------------------------------------------------------------
- ///
- /// IndirOpnd::SetScale
- ///
- ///----------------------------------------------------------------------------
- inline void
- IndirOpnd::SetScale(byte scale)
- {
- m_scale = scale;
- }
- ///----------------------------------------------------------------------------
- ///
- /// MemRefOpnd::GetMemLoc
- ///
- ///----------------------------------------------------------------------------
- inline void *
- MemRefOpnd::GetMemLoc() const
- {
- return m_memLoc;
- }
- ///----------------------------------------------------------------------------
- ///
- /// MemRefOpnd::SetMemLoc
- ///
- ///----------------------------------------------------------------------------
- inline void
- MemRefOpnd::SetMemLoc(void * pMemLoc)
- {
- m_memLoc = pMemLoc;
- }
- inline LabelInstr *
- LabelOpnd::GetLabel() const
- {
- return m_label;
- }
- inline void
- LabelOpnd::SetLabel(LabelInstr * labelInstr)
- {
- m_label = labelInstr;
- }
- inline BVUnit32
- RegBVOpnd::GetValue() const
- {
- return m_value;
- }
- } // namespace IR
|