1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

Simplify .org processing and make it a bit more powerful.

We now always create the fragment, which lets us handle things like .org after
a .align.

llvm-svn: 252101
This commit is contained in:
Rafael Espindola 2015-11-04 23:50:29 +00:00
parent 3c4afd7651
commit b32d97ac38
4 changed files with 15 additions and 21 deletions

View File

@ -533,12 +533,19 @@ uint64_t MCAssembler::computeFragmentSize(const MCAsmLayout &Layout,
case MCFragment::FT_Org: {
const MCOrgFragment &OF = cast<MCOrgFragment>(F);
int64_t TargetLocation;
if (!OF.getOffset().evaluateAsAbsolute(TargetLocation, Layout))
MCValue Value;
if (!OF.getOffset().evaluateAsValue(Value, Layout))
report_fatal_error("expected assembly-time absolute expression");
// FIXME: We need a way to communicate this error.
uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
int64_t TargetLocation = Value.getConstant();
if (const MCSymbolRefExpr *A = Value.getSymA()) {
uint64_t Val;
if (!Layout.getSymbolOffset(A->getSymbol(), Val))
report_fatal_error("expected absolute expression");
TargetLocation += Val;
}
int64_t Size = TargetLocation - FragmentOffset;
if (Size < 0 || Size >= 0x40000000)
report_fatal_error("invalid .org offset '" + Twine(TargetLocation) +

View File

@ -393,23 +393,7 @@ void MCObjectStreamer::EmitCodeAlignment(unsigned ByteAlignment,
bool MCObjectStreamer::EmitValueToOffset(const MCExpr *Offset,
unsigned char Value) {
int64_t Res;
if (Offset->evaluateAsAbsolute(Res, getAssembler())) {
insert(new MCOrgFragment(*Offset, Value));
return false;
}
MCSymbol *CurrentPos = getContext().createTempSymbol();
EmitLabel(CurrentPos);
MCSymbolRefExpr::VariantKind Variant = MCSymbolRefExpr::VK_None;
const MCExpr *Ref =
MCSymbolRefExpr::create(CurrentPos, Variant, getContext());
const MCExpr *Delta =
MCBinaryExpr::create(MCBinaryExpr::Sub, Offset, Ref, getContext());
if (!Delta->evaluateAsAbsolute(Res, getAssembler()))
return true;
EmitFill(Res, Value);
insert(new MCOrgFragment(*Offset, Value));
return false;
}

View File

@ -4,6 +4,6 @@
.extern foo
# CHECK: error: expected absolute expression
# CHECK: : expected absolute expression
. = foo + 10
.byte 1

View File

@ -11,6 +11,9 @@ two:
three:
.quad 0xdddddddddddddddd
.align 4
. = three + 9
// CHECK: Section {
// CHECK: Name: .text
// CHECK-NEXT: Type:
@ -18,5 +21,5 @@ three:
// CHECK: SectionData (
// CHECK-NEXT: 0000: FFFFFFFF FFFFFFFF 00000000 00000000
// CHECK-NEXT: 0010: 00000000 00000000 EEEEEEEE EEEEEEEE
// CHECK-NEXT: 0020: DDDDDDDD DDDDDDDD
// CHECK-NEXT: 0020: DDDDDDDD DDDDDDDD 00 |
// CHECK-NEXT: )