@@ -90,70 +90,103 @@ void XtensaInstPrinter::printMemOperand(const MCInst *MI, int OpNum,
9090 printOperand (MI, OpNum + 1 , OS);
9191}
9292
93- void XtensaInstPrinter::printBranchTarget (const MCInst *MI, int OpNum ,
94- raw_ostream &OS ) {
93+ void XtensaInstPrinter::printBranchTarget (const MCInst *MI, uint64_t Address ,
94+ int OpNum, raw_ostream &O ) {
9595 const MCOperand &MC = MI->getOperand (OpNum);
9696 if (MI->getOperand (OpNum).isImm ()) {
9797 int64_t Val = MC.getImm () + 4 ;
98- OS << " . " ;
99- if (Val > 0 )
100- OS << ' +' ;
101- OS << Val;
98+ printPCRelImm (Address, Val, O);
10299 } else if (MC.isExpr ())
103- MC.getExpr ()->print (OS , &MAI);
100+ MC.getExpr ()->print (O , &MAI);
104101 else
105102 llvm_unreachable (" Invalid operand" );
106103}
107104
108- void XtensaInstPrinter::printJumpTarget (const MCInst *MI, int OpNum,
109- raw_ostream &OS) {
105+ void XtensaInstPrinter::printLoopTarget (const MCInst *MI, uint64_t Address,
106+ int OpNum, raw_ostream &O) {
107+ const MCOperand &MC = MI->getOperand (OpNum);
108+ if (MI->getOperand (OpNum).isImm ()) {
109+ int64_t Val = MC.getImm () + 4 ;
110+ printPCRelImm (Address, Val, O);
111+ } else if (MC.isExpr ())
112+ MC.getExpr ()->print (O, &MAI, true );
113+ else
114+ llvm_unreachable (" Invalid operand" );
115+ }
116+
117+ void XtensaInstPrinter::printJumpTarget (const MCInst *MI, uint64_t Address,
118+ int OpNum, raw_ostream &O) {
110119 const MCOperand &MC = MI->getOperand (OpNum);
111120 if (MC.isImm ()) {
112121 int64_t Val = MC.getImm () + 4 ;
113- OS << " . " ;
114- if (Val > 0 )
115- OS << ' +' ;
116- OS << Val;
122+ printPCRelImm (Address, Val, O);
117123 } else if (MC.isExpr ())
118- MC.getExpr ()->print (OS , &MAI);
124+ MC.getExpr ()->print (O , &MAI);
119125 else
120126 llvm_unreachable (" Invalid operand" );
121127 ;
122128}
123129
124- void XtensaInstPrinter::printCallOperand (const MCInst *MI, int OpNum ,
125- raw_ostream &OS ) {
130+ void XtensaInstPrinter::printCallOperand (const MCInst *MI, uint64_t Address ,
131+ int OpNum, raw_ostream &O ) {
126132 const MCOperand &MC = MI->getOperand (OpNum);
127133 if (MC.isImm ()) {
128134 int64_t Val = MC.getImm () + 4 ;
129- OS << " . " ;
130- if (Val > 0 )
131- OS << ' +' ;
132- OS << Val;
135+ if (PrintBranchImmAsAddress) {
136+ uint64_t Target = Address;
137+ Target &= ~0x3 ;
138+ Target += Val & (~0x3 );
139+ O << formatHex (Target);
140+ } else {
141+ O << " . " ;
142+ if (Val > 0 )
143+ O << ' +' ;
144+ O << Val;
145+ }
133146 } else if (MC.isExpr ())
134- MC.getExpr ()->print (OS , &MAI);
147+ MC.getExpr ()->print (O , &MAI);
135148 else
136149 llvm_unreachable (" Invalid operand" );
137150}
138151
139- void XtensaInstPrinter::printL32RTarget (const MCInst *MI, int OpNum ,
140- raw_ostream &O) {
152+ void XtensaInstPrinter::printL32RTarget (const MCInst *MI, uint64_t Address ,
153+ int OpNum, raw_ostream &O) {
141154 const MCOperand &MC = MI->getOperand (OpNum);
142155 if (MC.isImm ()) {
143156 int64_t Value = MI->getOperand (OpNum).getImm ();
144- int64_t InstrOff = Value & 0x3 ;
145- Value -= InstrOff;
146- assert ((Value >= -262144 && Value <= -4 ) &&
147- " Invalid argument, value must be in ranges [-262144,-4]" );
148- Value += ((InstrOff + 0x3 ) & 0x4 ) - InstrOff;
149- O << " . " ;
150- O << Value;
157+ if (PrintBranchImmAsAddress) {
158+ uint64_t Target = (Address + 0x3 ) & (~0x3 );
159+ Value &= ~0x3 ;
160+ Target += Value;
161+ O << formatHex (Target);
162+ } else {
163+ int64_t InstrOff = Value & 0x3 ;
164+ Value -= InstrOff;
165+ assert ((Value >= -262144 && Value <= -4 ) &&
166+ " Invalid argument, value must be in ranges [-262144,-4]" );
167+ Value += ((InstrOff + 0x3 ) & 0x4 ) - InstrOff;
168+ printPCRelImm (Address, Value, O);
169+ }
151170 } else if (MC.isExpr ())
152171 MC.getExpr ()->print (O, &MAI);
153172 else
154173 llvm_unreachable (" Invalid operand" );
155174}
156175
176+ void XtensaInstPrinter::printPCRelImm (uint64_t Address, int64_t Offset,
177+ raw_ostream &O) {
178+ if (PrintBranchImmAsAddress) {
179+ uint64_t Target = Address + Offset;
180+ Target &= 0xffffffff ;
181+ O << formatHex (Target);
182+ } else {
183+ O << " . " ;
184+ if (Offset > 0 )
185+ O << ' +' ;
186+ O << Offset;
187+ }
188+ }
189+
157190void XtensaInstPrinter::printImm8_AsmOperand (const MCInst *MI, int OpNum,
158191 raw_ostream &O) {
159192 if (MI->getOperand (OpNum).isImm ()) {
@@ -404,3 +437,14 @@ void XtensaInstPrinter::printB4constu_AsmOperand(const MCInst *MI, int OpNum,
404437 } else
405438 printOperand (MI, OpNum, O);
406439}
440+
441+ void XtensaInstPrinter::printImm7_22_AsmOperand (const MCInst *MI, int OpNum,
442+ raw_ostream &O) {
443+ if (MI->getOperand (OpNum).isImm ()) {
444+ int64_t Value = MI->getOperand (OpNum).getImm ();
445+ assert ((Value >= 7 && Value <= 22 ) &&
446+ " Invalid argument, value must be in range <7,22>" );
447+ O << Value;
448+ } else
449+ printOperand (MI, OpNum, O);
450+ }
0 commit comments