mirror of
https://github.com/RPCS3/llvm.git
synced 2026-01-31 01:25:19 +01:00
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304787 91177308-0d34-0410-b5e6-96231b3b80d8
190 lines
4.9 KiB
C++
190 lines
4.9 KiB
C++
//===-- AVRMCExpr.cpp - AVR specific MC expression classes ----------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "AVRMCExpr.h"
|
|
|
|
#include "llvm/MC/MCAsmLayout.h"
|
|
#include "llvm/MC/MCAssembler.h"
|
|
#include "llvm/MC/MCContext.h"
|
|
#include "llvm/MC/MCStreamer.h"
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
namespace llvm {
|
|
|
|
namespace {
|
|
|
|
const struct ModifierEntry {
|
|
const char * const Spelling;
|
|
AVRMCExpr::VariantKind VariantKind;
|
|
} ModifierNames[] = {
|
|
{"lo8", AVRMCExpr::VK_AVR_LO8}, {"hi8", AVRMCExpr::VK_AVR_HI8},
|
|
{"hh8", AVRMCExpr::VK_AVR_HH8}, // synonym with hlo8
|
|
{"hlo8", AVRMCExpr::VK_AVR_HH8}, {"hhi8", AVRMCExpr::VK_AVR_HHI8},
|
|
|
|
{"pm_lo8", AVRMCExpr::VK_AVR_PM_LO8}, {"pm_hi8", AVRMCExpr::VK_AVR_PM_HI8},
|
|
{"pm_hh8", AVRMCExpr::VK_AVR_PM_HH8},
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
const AVRMCExpr *AVRMCExpr::create(VariantKind Kind, const MCExpr *Expr,
|
|
bool Negated, MCContext &Ctx) {
|
|
return new (Ctx) AVRMCExpr(Kind, Expr, Negated);
|
|
}
|
|
|
|
void AVRMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
|
|
assert(Kind != VK_AVR_None);
|
|
|
|
if (isNegated())
|
|
OS << '-';
|
|
|
|
OS << getName() << '(';
|
|
getSubExpr()->print(OS, MAI);
|
|
OS << ')';
|
|
}
|
|
|
|
bool AVRMCExpr::evaluateAsConstant(int64_t &Result) const {
|
|
MCValue Value;
|
|
|
|
bool isRelocatable =
|
|
getSubExpr()->evaluateAsRelocatable(Value, nullptr, nullptr);
|
|
|
|
if (!isRelocatable)
|
|
return false;
|
|
|
|
if (Value.isAbsolute()) {
|
|
Result = evaluateAsInt64(Value.getConstant());
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool AVRMCExpr::evaluateAsRelocatableImpl(MCValue &Result,
|
|
const MCAsmLayout *Layout,
|
|
const MCFixup *Fixup) const {
|
|
MCValue Value;
|
|
bool isRelocatable = SubExpr->evaluateAsRelocatable(Value, Layout, Fixup);
|
|
|
|
if (!isRelocatable)
|
|
return false;
|
|
|
|
if (Value.isAbsolute()) {
|
|
Result = MCValue::get(evaluateAsInt64(Value.getConstant()));
|
|
} else {
|
|
if (!Layout) return false;
|
|
|
|
MCContext &Context = Layout->getAssembler().getContext();
|
|
const MCSymbolRefExpr *Sym = Value.getSymA();
|
|
MCSymbolRefExpr::VariantKind Modifier = Sym->getKind();
|
|
if (Modifier != MCSymbolRefExpr::VK_None)
|
|
return false;
|
|
|
|
Sym = MCSymbolRefExpr::create(&Sym->getSymbol(), Modifier, Context);
|
|
Result = MCValue::get(Sym, Value.getSymB(), Value.getConstant());
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
int64_t AVRMCExpr::evaluateAsInt64(int64_t Value) const {
|
|
if (Negated)
|
|
Value *= -1;
|
|
|
|
switch (Kind) {
|
|
case AVRMCExpr::VK_AVR_LO8:
|
|
break;
|
|
case AVRMCExpr::VK_AVR_HI8:
|
|
Value >>= 8;
|
|
break;
|
|
case AVRMCExpr::VK_AVR_HH8:
|
|
Value >>= 16;
|
|
break;
|
|
case AVRMCExpr::VK_AVR_HHI8:
|
|
Value >>= 24;
|
|
break;
|
|
case AVRMCExpr::VK_AVR_PM_LO8:
|
|
Value >>= 1;
|
|
break;
|
|
case AVRMCExpr::VK_AVR_PM_HI8:
|
|
Value >>= 9;
|
|
break;
|
|
case AVRMCExpr::VK_AVR_PM_HH8:
|
|
Value >>= 17;
|
|
break;
|
|
|
|
case AVRMCExpr::VK_AVR_None:
|
|
llvm_unreachable("Uninitialized expression.");
|
|
}
|
|
return static_cast<uint64_t>(Value) & 0xff;
|
|
}
|
|
|
|
AVR::Fixups AVRMCExpr::getFixupKind() const {
|
|
AVR::Fixups Kind = AVR::Fixups::LastTargetFixupKind;
|
|
|
|
switch (getKind()) {
|
|
case VK_AVR_LO8:
|
|
Kind = isNegated() ? AVR::fixup_lo8_ldi_neg : AVR::fixup_lo8_ldi;
|
|
break;
|
|
case VK_AVR_HI8:
|
|
Kind = isNegated() ? AVR::fixup_hi8_ldi_neg : AVR::fixup_hi8_ldi;
|
|
break;
|
|
case VK_AVR_HH8:
|
|
Kind = isNegated() ? AVR::fixup_hh8_ldi_neg : AVR::fixup_hh8_ldi;
|
|
break;
|
|
case VK_AVR_HHI8:
|
|
Kind = isNegated() ? AVR::fixup_ms8_ldi_neg : AVR::fixup_ms8_ldi;
|
|
break;
|
|
|
|
case VK_AVR_PM_LO8:
|
|
Kind = isNegated() ? AVR::fixup_lo8_ldi_pm_neg : AVR::fixup_lo8_ldi_pm;
|
|
break;
|
|
case VK_AVR_PM_HI8:
|
|
Kind = isNegated() ? AVR::fixup_hi8_ldi_pm_neg : AVR::fixup_hi8_ldi_pm;
|
|
break;
|
|
case VK_AVR_PM_HH8:
|
|
Kind = isNegated() ? AVR::fixup_hh8_ldi_pm_neg : AVR::fixup_hh8_ldi_pm;
|
|
break;
|
|
|
|
case VK_AVR_None:
|
|
llvm_unreachable("Uninitialized expression");
|
|
}
|
|
|
|
return Kind;
|
|
}
|
|
|
|
void AVRMCExpr::visitUsedExpr(MCStreamer &Streamer) const {
|
|
Streamer.visitUsedExpr(*getSubExpr());
|
|
}
|
|
|
|
const char *AVRMCExpr::getName() const {
|
|
const auto &Modifier = std::find_if(
|
|
std::begin(ModifierNames), std::end(ModifierNames),
|
|
[this](ModifierEntry const &Mod) { return Mod.VariantKind == Kind; });
|
|
|
|
if (Modifier != std::end(ModifierNames)) {
|
|
return Modifier->Spelling;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
AVRMCExpr::VariantKind AVRMCExpr::getKindByName(StringRef Name) {
|
|
const auto &Modifier = std::find_if(
|
|
std::begin(ModifierNames), std::end(ModifierNames),
|
|
[&Name](ModifierEntry const &Mod) { return Mod.Spelling == Name; });
|
|
|
|
if (Modifier != std::end(ModifierNames)) {
|
|
return Modifier->VariantKind;
|
|
}
|
|
return VK_AVR_None;
|
|
}
|
|
|
|
} // end of namespace llvm
|
|
|