//===- UnaryOp.cpp --------------------------------------------------------===// // // The MCLinker Project // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include #include #include #include #include #include #include using namespace mcld; //===----------------------------------------------------------------------===// // UnaryOp //===----------------------------------------------------------------------===// template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); res->setValue(+ m_pOperand->value()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); res->setValue(- m_pOperand->value()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); res->setValue(! m_pOperand->value()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); res->setValue(~ m_pOperand->value()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); const LDSection* sect = NULL; switch (m_pOperand->type()) { case Operand::SECTION: sect = pModule.getSection(llvm::cast(m_pOperand)->name()); break; case Operand::SECTION_DESC: sect = llvm::cast(m_pOperand)->outputDesc()->getSection(); break; default: assert(0); break; } assert(sect != NULL); res->setValue(sect->addr()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); const LDSection* sect = NULL; switch (m_pOperand->type()) { case Operand::SECTION: sect = pModule.getSection(llvm::cast(m_pOperand)->name()); break; case Operand::SECTION_DESC: sect = llvm::cast(m_pOperand)->outputDesc()->getSection(); break; default: assert(0); break; } assert(sect != NULL); res->setValue(sect->align()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); res->setValue(m_pOperand->value()); return res; } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { // TODO assert(0); return result(); } template<> IntOperand* UnaryOp::eval(const Module& pModule, const TargetLDBackend& pBackend) { IntOperand* res = result(); const LDSection* sect = NULL; switch (m_pOperand->type()) { case Operand::SECTION: sect = pModule.getSection(llvm::cast(m_pOperand)->name()); break; case Operand::SECTION_DESC: sect = llvm::cast(m_pOperand)->outputDesc()->getSection(); break; default: assert(0); break; } assert(sect != NULL); res->setValue(sect->size()); return res; }