mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-12 13:30:51 +00:00
ARM IAS: support emitting constant values in target expressions
A 32-bit immediate value can be formed from a constant expression and loaded into a register. Add support to emit this into an object file. Because this value is a constant, a relocation must *not* be produced for it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199023 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ccdb9c9483
commit
8009754517
@ -26,6 +26,7 @@
|
|||||||
#include "llvm/MC/MCInstrInfo.h"
|
#include "llvm/MC/MCInstrInfo.h"
|
||||||
#include "llvm/MC/MCRegisterInfo.h"
|
#include "llvm/MC/MCRegisterInfo.h"
|
||||||
#include "llvm/MC/MCSubtargetInfo.h"
|
#include "llvm/MC/MCSubtargetInfo.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -912,6 +913,20 @@ ARMMCCodeEmitter::getHiLo16ImmOpValue(const MCInst &MI, unsigned OpIdx,
|
|||||||
const ARMMCExpr *ARM16Expr = cast<ARMMCExpr>(E);
|
const ARMMCExpr *ARM16Expr = cast<ARMMCExpr>(E);
|
||||||
E = ARM16Expr->getSubExpr();
|
E = ARM16Expr->getSubExpr();
|
||||||
|
|
||||||
|
if (const MCConstantExpr *MCE = dyn_cast<MCConstantExpr>(E)) {
|
||||||
|
const int64_t Value = MCE->getValue();
|
||||||
|
if (Value > UINT32_MAX)
|
||||||
|
report_fatal_error("constant value truncated (limited to 32-bit)");
|
||||||
|
|
||||||
|
switch (ARM16Expr->getKind()) {
|
||||||
|
case ARMMCExpr::VK_ARM_HI16:
|
||||||
|
return (int32_t(Value) & 0xffff0000) >> 16;
|
||||||
|
case ARMMCExpr::VK_ARM_LO16:
|
||||||
|
return (int32_t(Value) & 0x0000ffff);
|
||||||
|
default: llvm_unreachable("Unsupported ARMFixup");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (ARM16Expr->getKind()) {
|
switch (ARM16Expr->getKind()) {
|
||||||
default: llvm_unreachable("Unsupported ARMFixup");
|
default: llvm_unreachable("Unsupported ARMFixup");
|
||||||
case ARMMCExpr::VK_ARM_HI16:
|
case ARMMCExpr::VK_ARM_HI16:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
@ RUN: llvm-mc -triple armv7-eabi -filetype asm -o - %s | FileCheck %s
|
@ RUN: llvm-mc -triple armv7-eabi -filetype asm -o - %s | FileCheck %s
|
||||||
|
@ RUN: llvm-mc -triple armv7-eabi -filetype obj -o - %s | llvm-readobj -r \
|
||||||
|
@ RUN: | FileCheck -check-prefix CHECK-RELOCATIONS %s
|
||||||
|
|
||||||
.syntax unified
|
.syntax unified
|
||||||
|
|
||||||
@ -6,6 +8,9 @@
|
|||||||
function:
|
function:
|
||||||
bx lr
|
bx lr
|
||||||
|
|
||||||
|
.global external
|
||||||
|
.type external,%function
|
||||||
|
|
||||||
.set deadbeat, 0xdeadbea7
|
.set deadbeat, 0xdeadbea7
|
||||||
|
|
||||||
.type test,%function
|
.type test,%function
|
||||||
@ -28,6 +33,18 @@ test:
|
|||||||
movw r5, #:lower16:0xD1510D6E
|
movw r5, #:lower16:0xD1510D6E
|
||||||
movt r5, #:upper16:0xD1510D6E
|
movt r5, #:upper16:0xD1510D6E
|
||||||
|
|
||||||
|
movw r0, :lower16:external
|
||||||
|
movt r0, :upper16:external
|
||||||
|
|
||||||
|
movw r1, #:lower16:external
|
||||||
|
movt r1, #:upper16:external
|
||||||
|
|
||||||
|
movw r2, #:lower16:(16 + 16)
|
||||||
|
movt r2, #:upper16:(16 + 16)
|
||||||
|
|
||||||
|
movw r3, :lower16:(16 + 16)
|
||||||
|
movt r3, :upper16:(16 + 16)
|
||||||
|
|
||||||
@ CHECK-LABEL: test:
|
@ CHECK-LABEL: test:
|
||||||
@ CHECK: movw r0, :lower16:function
|
@ CHECK: movw r0, :lower16:function
|
||||||
@ CHECK: movt r0, :upper16:function
|
@ CHECK: movt r0, :upper16:function
|
||||||
@ -41,4 +58,23 @@ test:
|
|||||||
@ CHECK: movt r4, :upper16:(3511749998)
|
@ CHECK: movt r4, :upper16:(3511749998)
|
||||||
@ CHECK: movw r5, :lower16:(3511749998)
|
@ CHECK: movw r5, :lower16:(3511749998)
|
||||||
@ CHECK: movt r5, :upper16:(3511749998)
|
@ CHECK: movt r5, :upper16:(3511749998)
|
||||||
|
@ CHECK: movw r0, :lower16:external
|
||||||
|
@ CHECK: movt r0, :upper16:external
|
||||||
|
@ CHECK: movw r1, :lower16:external
|
||||||
|
@ CHECK: movt r1, :upper16:external
|
||||||
|
@ CHECK: movw r2, :lower16:(32)
|
||||||
|
@ CHECK: movt r2, :upper16:(32)
|
||||||
|
@ CHECK: movw r3, :lower16:(32)
|
||||||
|
@ CHECK: movt r3, :upper16:(32)
|
||||||
|
|
||||||
|
@ CHECK-RELOCATIONS: Relocations [
|
||||||
|
@ CHECK-RELOCATIONS: 0x4 R_ARM_MOVW_ABS_NC function 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x8 R_ARM_MOVT_ABS function 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0xC R_ARM_MOVW_ABS_NC function 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x10 R_ARM_MOVT_ABS function 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x34 R_ARM_MOVW_ABS_NC external 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x38 R_ARM_MOVT_ABS external 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x3C R_ARM_MOVW_ABS_NC external 0x0
|
||||||
|
@ CHECK-RELOCATIONS: 0x40 R_ARM_MOVT_ABS external 0x0
|
||||||
|
@ CHECK-RELOCATIONS: ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user