mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-30 16:17:05 +00:00 
			
		
		
		
	implement the rest of correct x86-64 encoder support for
rip-relative addresses, and add a testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96040 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -15,6 +15,7 @@ | |||||||
| #include "X86.h" | #include "X86.h" | ||||||
| #include "X86InstrInfo.h" | #include "X86InstrInfo.h" | ||||||
| #include "llvm/MC/MCCodeEmitter.h" | #include "llvm/MC/MCCodeEmitter.h" | ||||||
|  | #include "llvm/MC/MCExpr.h" | ||||||
| #include "llvm/MC/MCInst.h" | #include "llvm/MC/MCInst.h" | ||||||
| #include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||||
| using namespace llvm; | using namespace llvm; | ||||||
| @@ -36,10 +37,11 @@ class X86MCCodeEmitter : public MCCodeEmitter { | |||||||
|   void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT |   void operator=(const X86MCCodeEmitter &); // DO NOT IMPLEMENT | ||||||
|   const TargetMachine &TM; |   const TargetMachine &TM; | ||||||
|   const TargetInstrInfo &TII; |   const TargetInstrInfo &TII; | ||||||
|  |   MCContext &Ctx; | ||||||
|   bool Is64BitMode; |   bool Is64BitMode; | ||||||
| public: | public: | ||||||
|   X86MCCodeEmitter(TargetMachine &tm, bool is64Bit)  |   X86MCCodeEmitter(TargetMachine &tm, MCContext &ctx, bool is64Bit)  | ||||||
|     : TM(tm), TII(*TM.getInstrInfo()) { |     : TM(tm), TII(*TM.getInstrInfo()), Ctx(ctx) { | ||||||
|     Is64BitMode = is64Bit; |     Is64BitMode = is64Bit; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -122,13 +124,13 @@ public: | |||||||
| MCCodeEmitter *llvm::createX86_32MCCodeEmitter(const Target &, | MCCodeEmitter *llvm::createX86_32MCCodeEmitter(const Target &, | ||||||
|                                                TargetMachine &TM, |                                                TargetMachine &TM, | ||||||
|                                                MCContext &Ctx) { |                                                MCContext &Ctx) { | ||||||
|   return new X86MCCodeEmitter(TM, false); |   return new X86MCCodeEmitter(TM, Ctx, false); | ||||||
| } | } | ||||||
|  |  | ||||||
| MCCodeEmitter *llvm::createX86_64MCCodeEmitter(const Target &, | MCCodeEmitter *llvm::createX86_64MCCodeEmitter(const Target &, | ||||||
|                                                TargetMachine &TM, |                                                TargetMachine &TM, | ||||||
|                                                MCContext &Ctx) { |                                                MCContext &Ctx) { | ||||||
|   return new X86MCCodeEmitter(TM, true); |   return new X86MCCodeEmitter(TM, Ctx, true); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -167,7 +169,9 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind, | |||||||
|  |  | ||||||
|   // If we have an immoffset, add it to the expression. |   // If we have an immoffset, add it to the expression. | ||||||
|   const MCExpr *Expr = DispOp.getExpr(); |   const MCExpr *Expr = DispOp.getExpr(); | ||||||
|   // FIXME: NO CONTEXT. |   if (ImmOffset) | ||||||
|  |     Expr = MCBinaryExpr::CreateAdd(Expr,MCConstantExpr::Create(ImmOffset, Ctx), | ||||||
|  |                                    Ctx); | ||||||
|    |    | ||||||
|   // Emit a symbolic constant as a fixup and 4 zeros. |   // Emit a symbolic constant as a fixup and 4 zeros. | ||||||
|   Fixups.push_back(MCFixup::Create(CurByte, Expr, FixupKind)); |   Fixups.push_back(MCFixup::Create(CurByte, Expr, FixupKind)); | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								test/MC/AsmParser/X86/x86_64-new-encoder.s
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								test/MC/AsmParser/X86/x86_64-new-encoder.s
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | // RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding --enable-new-x86-encoder %s | FileCheck %s | ||||||
|  |  | ||||||
|  | movl	foo(%rip), %eax | ||||||
|  | // CHECK: movl	foo(%rip), %eax | ||||||
|  | // CHECK: encoding: [0x8b,0x05,A,A,A,A] | ||||||
|  | // CHECK: fixup A - offset: 2, value: foo, kind: reloc_riprel_4byte | ||||||
|  |  | ||||||
|  | movb	$12, foo(%rip) | ||||||
|  | // CHECK: movb	$12, foo(%rip) | ||||||
|  | // CHECK: encoding: [0xc6,0x05,A,A,A,A,B] | ||||||
|  | // CHECK:    fixup A - offset: 2, value: foo-1, kind: reloc_riprel_4byte | ||||||
|  | // CHECK:    fixup B - offset: 6, value: 12, kind: FK_Data_1 | ||||||
|  |  | ||||||
|  | movw	$12, foo(%rip) | ||||||
|  | // CHECK: movw	$12, foo(%rip) | ||||||
|  | // CHECK: encoding: [0x66,0xc7,0x05,A,A,A,A,B,B] | ||||||
|  | // CHECK:    fixup A - offset: 3, value: foo-2, kind: reloc_riprel_4byte | ||||||
|  | // CHECK:    fixup B - offset: 7, value: 12, kind: FK_Data_2 | ||||||
|  |  | ||||||
|  | movl	$12, foo(%rip) | ||||||
|  | // CHECK: movl	$12, foo(%rip) | ||||||
|  | // CHECK: encoding: [0xc7,0x05,A,A,A,A,B,B,B,B] | ||||||
|  | // CHECK:    fixup A - offset: 2, value: foo-4, kind: reloc_riprel_4byte | ||||||
|  | // CHECK:    fixup B - offset: 6, value: 12, kind: FK_Data_4 | ||||||
|  |  | ||||||
|  | movq	$12, foo(%rip) | ||||||
|  | // CHECK:  movq	$12, foo(%rip) | ||||||
|  | // CHECK: encoding: [0x48,0xc7,0x05,A,A,A,A,B,B,B,B] | ||||||
|  | // CHECK:    fixup A - offset: 3, value: foo-4, kind: reloc_riprel_4byte | ||||||
|  | // CHECK:    fixup B - offset: 7, value: 12, kind: FK_Data_4 | ||||||
		Reference in New Issue
	
	Block a user