[llvm-commits] CVS: llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sat May 31 17:09:24 PDT 2003
Changes in directory llvm/lib/Reoptimizer/BinInterface:
sparcdis.cpp updated: 1.10 -> 1.11
---
Log message:
First version of working bininterface API/implementation
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp
diff -u llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp:1.10 llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp:1.11
--- llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp:1.10 Tue Apr 15 16:54:37 2003
+++ llvm/lib/Reoptimizer/BinInterface/sparcdis.cpp Sat May 31 17:08:16 2003
@@ -1,7 +1,7 @@
-//*****************************************************************************
+//===--------llvm/Reoptimizer/BinInterface/sparcdis.cpp-----------*- C++ -*--=//
// SPARC Instruction Disassembler
//
-// Disassembler API Header
+// Disassembler API
//
// * Initial implementation
// * Added support for MOVcc (somehow I missed it?!)
@@ -11,19 +11,16 @@
// labels instead of registers. And we wish to
// ommit RD from the view when we are not explicitly
// reading from it)
-//
+//
// Todo:
// * On the instructions that don't read from RD
// do not print the label field (we get l-1 when we print)
-//
-// 2002 Cameron Buschardt
-//*****************************************************************************
+//===----------------------------------------------------------------------===//
+#include "llvm/Reoptimizer/BinInterface/bitmath.h" // binary math routines
+#include "llvm/Reoptimizer/BinInterface/sparc9.h" // SPARC9 opcode definitions
#include <stdio.h>
#include <stdlib.h>
-
-#include "llvm/Reoptimizer/BinInterface/sparc9.h" // SPARC 9 definitions
-#include "llvm/Reoptimizer/BinInterface/bitmath.h"
#include <assert.h>
void sparc_printop_rs1(unsigned instr, int labelrs1)
@@ -31,7 +28,7 @@
if (labelrs1)
printf("l%d", labelrs1);
else
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RS1)]);
+ printf("%s", reg_names[RD_FLD(instr, INSTR_RS1)]);
}
void sparc_printop_rs2(unsigned instr, int labelrs2)
@@ -39,7 +36,7 @@
if (labelrs2)
printf("l%d", labelrs2);
else
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RS2)]);
+ printf("%s", reg_names[RD_FLD(instr, INSTR_RS2)]);
}
void sparc_printop_rrd(unsigned instr, int labelrrd)
@@ -47,7 +44,7 @@
if (labelrrd)
printf("l%d", labelrrd);
else
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
+ printf("%s", reg_names[RD_FLD(instr, INSTR_RD)]);
}
void sparc_printbr(unsigned instr, bool labels, int labelrs1, int labelrs2, int labelrd, int labelccf)
@@ -58,10 +55,10 @@
else if (RD_FLD(instr, INSTR_OP2)==OP2_SETHI)
{
if (RD_FLD(instr, INSTR_RD) == 0)
- printf("nop");
+ printf("NOP");
else
{
- printf("sethi %%hi(%08X), ", RD_FLD(instr, INSTR_IMM22) << 10);
+ printf("SETHI %%hi(%08X), ", RD_FLD(instr, INSTR_IMM22) << 10);
sparc_printop_rrd(instr, labelrd);
}
}
@@ -69,6 +66,10 @@
{
printf("b%s disp:%08X",icond_names[RD_FLD(instr, INSTR_COND_H)], SIGN_EXTEND(RD_FLD(instr,INSTR_DISP22),22));
}
+ else if (RD_FLD(instr, INSTR_OP2)==OP2_BPICC)
+ {
+ printf("b%s",icond_names[RD_FLD(instr, INSTR_COND_H)]);
+ }
else if (RD_FLD(instr, INSTR_OP2)==OP2_BPR)
{
//A, RCOND_H, D16HI, P, RS1, D16LO
@@ -95,31 +96,30 @@
}
}
-void sparc_printalu(char * basename , unsigned instr, bool labels,
+void sparc_printalu(const char * basename , unsigned instr, bool labels,
int labelrs1, int labelrs2, int labelrd, int labelccf)
{
// OP=OP_2 : RD, OP3, RS1: {I=0 -> RS2 I=1->SIMM13}
if (RD_FLD(instr, INSTR_I)==0)
{
printf("%s ", basename);
+ if (!labels)
+ printf("%s, ", reg_names[RD_FLD(instr, INSTR_RD)]);
sparc_printop_rs1(instr, labelrs1);
printf(" ,");
sparc_printop_rs2(instr, labelrs2);
- printf(" ,");
- if (!labels)
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
}
else
{
printf("%s ", basename);
- sparc_printop_rs1(instr, labelrs1);
- printf(" , %d, ", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
if (!labels)
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
+ printf("%s, ", reg_names[RD_FLD(instr, INSTR_RD)]);
+ sparc_printop_rs1(instr, labelrs1);
+ printf(" , %d", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
}
}
-void sparc_printshf(char * basename, unsigned instr, bool labels,
+void sparc_printshf(const char * basename, unsigned instr, bool labels,
int labelrs1, int labelrs2, int labelrd, int labelccf)
{
//OP=OP_2: RD, OP_3 RS1: {I=0 -> X & RS2 ,I=1 ->
@@ -127,19 +127,21 @@
if (RD_FLD(instr, INSTR_I)==0)
{
- printf("%s%d ", (RD_FLD(instr, INSTR_X)==0 ? 32 : 64));
+ printf("%s%d ", basename, (RD_FLD(instr, INSTR_X)==0 ? 32 : 64));
+ if (!labels)
+ printf("%s, ", reg_names[RD_FLD(instr, INSTR_RD)]);
sparc_printop_rs1(instr, labelrs1);
printf(", ");
sparc_printop_rs2(instr, labelrs2);
- printf(", ");
-
- if (!labels)
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
}
else
{
- printf("%s%s ", basename, (RD_FLD(instr, INSTR_X)==0 ? "" : "x"));
+
+ printf("%s%d ", basename, (RD_FLD(instr, INSTR_X)==0 ? 32 : 64));
+ if (!labels)
+ printf("%s, ", reg_names[RD_FLD(instr, INSTR_RD)]);
+
sparc_printop_rs1(instr, labelrs1);
@@ -147,7 +149,7 @@
? RD_FLD(instr, INSTR_SHCNT32)
: RD_FLD(instr, INSTR_SHCNT64)));
if (!labels)
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
+ printf("%s", reg_names[RD_FLD(instr, INSTR_RD)]);
}
}
@@ -253,154 +255,153 @@
printf("mov%s(%s) ", icond_names[RD_FLD(instr, INSTR_COND_L)],
cc_names[(RD_FLD(instr, INSTR_CC2) << 2) | (RD_FLD(instr, INSTR_MOV_CC1) << 1) | RD_FLD(instr, INSTR_MOV_CC0)]);
+ if (!labels)
+ printf("%s, ", reg_names[RD_FLD(instr, INSTR_RD)]);
+
if (RD_FLD(instr, INSTR_I)==0) // RS2
sparc_printop_rs2(instr, labelrs2);
else
printf("%d", SIGN_EXTEND(RD_FLD(instr, INSTR_SIMM11), 11));
- printf(", ");
-
- if (!labels)
- printf("%%%s", reg_names[RD_FLD(instr, INSTR_RD)]);
return;
}
case OP3_ADD:
- sparc_printalu("add", instr, labels,
+ sparc_printalu("ADD", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ADDcc:
- sparc_printalu("addcc", instr, labels,
+ sparc_printalu("ADDcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ADDC:
- sparc_printalu("addc", instr, labels,
+ sparc_printalu("ADDC", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ADDCcc:
- sparc_printalu("addccc", instr, labels,
+ sparc_printalu("ADDCcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_AND:
- sparc_printalu("and", instr, labels,
+ sparc_printalu("AND", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ANDcc:
- sparc_printalu("andcc", instr, labels,
+ sparc_printalu("ANDcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_OR:
- sparc_printalu("or", instr, labels,
+ sparc_printalu("OR", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ORcc:
- sparc_printalu("orcc", instr, labels,
+ sparc_printalu("ORcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_XOR:
- sparc_printalu("xor", instr, labels,
+ sparc_printalu("XOR", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_XORcc:
- sparc_printalu("xorcc", instr, labels,
+ sparc_printalu("XORcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SUB:
- sparc_printalu("sub", instr, labels,
+ sparc_printalu("SUB", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SUBcc:
- sparc_printalu("subcc", instr, labels,
+ sparc_printalu("SUBcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ANDN:
- sparc_printalu("andn", instr, labels,
+ sparc_printalu("ANDN", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ANDNcc:
- sparc_printalu("andncc", instr, labels,
+ sparc_printalu("ANDNcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ORN:
- sparc_printalu("orn", instr, labels,
+ sparc_printalu("ORN", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_ORNcc:
- sparc_printalu("orncc", instr, labels,
+ sparc_printalu("ORNcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_XNOR:
- sparc_printalu("xnor", instr, labels,
+ sparc_printalu("XNOR", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_XNORcc:
- sparc_printalu("xnorcc", instr, labels,
+ sparc_printalu("XNORcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SUBC:
- sparc_printalu("subc", instr, labels,
+ sparc_printalu("SUBC", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SUBCcc:
- sparc_printalu("subccc", instr, labels,
+ sparc_printalu("SUBCcc", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_MULX:
- sparc_printalu("mulx", instr, labels,
+ sparc_printalu("MULX", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SDIVX:
- sparc_printalu("sdivx", instr, labels,
+ sparc_printalu("SDIVX", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_UDIVX:
- sparc_printalu("udivx", instr, labels,
+ sparc_printalu("UDIVX", instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SLL:
- sparc_printshf("sll",instr, labels,
+ sparc_printshf("SLL",instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SRL:
- sparc_printshf("srl",instr, labels,
+ sparc_printshf("SRL",instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_SRA:
- sparc_printshf("sra",instr, labels,
+ sparc_printshf("SRA",instr, labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_DONERETRY:
{
if (RD_FLD(instr, INSTR_FCN)==FCN_DONE)
- printf("done");
+ printf("DONE");
else if (RD_FLD(instr, INSTR_FCN)==FCN_RETRY)
- printf("retry");
+ printf("RETRY");
return;
}
@@ -408,9 +409,9 @@
{
unsigned fop_n =RD_FLD(instr, INSTR_OPF) &~ OPF_MASK_ON;
if (fop_n==OPF_FCMPn)
- printf("fcmp");
+ printf("FCMP");
else if (fop_n==OPF_FCMPEn)
- printf("fcmpe");
+ printf("FCMPE");
return;
}
@@ -445,7 +446,7 @@
return;
case OP3_POPC:
- printf("popc ????");
+ printf("POPC ????");
return;
case OP3_RETURN:
@@ -509,55 +510,54 @@
assert(0);
}
-void sparc_printload(char * basename, unsigned instr, bool labels,
+void sparc_printload(const char * basename, unsigned instr, bool labels,
int labelrs1, int labelrs2, int labelrd , int labelccf)
{
if (RD_FLD(instr, INSTR_I)==0)
{
- printf("%s [", basename);
-
- sparc_printop_rs1(instr, labelrs1);
- printf(" + ");
- sparc_printop_rs2(instr, labelrs2);
- printf("], ");
-
+ printf("%s ", basename);
if (!labels)
+ {
sparc_printop_rrd(instr, labelrd);
+ printf(", ");
+ }
+ sparc_printop_rs1(instr, labelrs1);
+ printf("+");
+ sparc_printop_rs2(instr, labelrs2);
}
else
{
- printf("%s [", basename);
-
- sparc_printop_rs1(instr, labelrs1);
- printf(" + %d", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
- printf("], ");
-
+ printf("%s ", basename);
if (!labels)
+ {
sparc_printop_rrd(instr, labelrd);
+ printf(", ");
+ }
+ sparc_printop_rs1(instr, labelrs1);
+ printf("+%d", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
}
}
-void sparc_printstore(char * basename, unsigned instr, bool labels,
+void sparc_printstore(const char * basename, unsigned instr, bool labels,
int labelrs1, int labelrs2, int labelrd , int labelccf)
{
if (RD_FLD(instr, INSTR_I)==0)
{
printf("%s ", basename);
sparc_printop_rrd(instr, labelrd);
- printf(", [");
+ printf(", ");
sparc_printop_rs1(instr, labelrs1);
- printf(" + ");
+ printf("+");
sparc_printop_rs2(instr, labelrs2);
- printf("]");
+
}
else
{
printf("%s ", basename);
sparc_printop_rrd(instr, labelrd);
- printf(", [");
+ printf(", ");
sparc_printop_rs1(instr, labelrs1);
- printf(" + %d", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
- printf("]");
+ printf("+%d", SIGN_EXTEND13(RD_FLD(instr, INSTR_SIMM13)));
}
}
void sparc_print3(unsigned instr, bool labels, int labelrs1, int labelrs2,
@@ -574,62 +574,62 @@
{
//OP=OP_3 RD, Rs1 {I=0->RS2, I=1->SIMM13}
case OP3_LDSTUB:
- sparc_printload("ldstub", instr,labels,
+ sparc_printload("LDSTUB", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STB:
- sparc_printstore("stb", instr,labels,
+ sparc_printstore("STB", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STH:
- sparc_printstore("sth", instr,labels,
+ sparc_printstore("STH", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STW:
- sparc_printstore("stw", instr,labels,
+ sparc_printstore("STW", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STX:
- sparc_printstore("stx", instr,labels,
+ sparc_printstore("STX", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDSB:
- sparc_printload("ldsb", instr,labels,
+ sparc_printload("LDSB", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDSH:
- sparc_printload("ldsh", instr,labels,
+ sparc_printload("LDSH", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDSW:
- sparc_printload("ldsw", instr,labels,
+ sparc_printload("LDSW", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDUB:
- sparc_printload("ldub", instr,labels,
+ sparc_printload("LDUB", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDUH:
- sparc_printload("lduh", instr,labels,
+ sparc_printload("LDUH", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDUW:
- sparc_printload("lduw", instr,labels,
+ sparc_printload("LDUW", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_LDX:
- sparc_printload("ldx", instr,labels,
+ sparc_printload("LDX", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
@@ -637,14 +637,14 @@
if (RD_FLD(instr, INSTR_I)==0)
{
if (!labels)
- printf("casa [r%d] %%%d, r%d, r%d",
+ printf("CASA [r%d] %%%d, r%d, r%d",
RD_FLD(instr, INSTR_RS1),
RD_FLD(instr, INSTR_IMMASI),
RD_FLD(instr, INSTR_RS2),
RD_FLD(instr, INSTR_RD));
else
- printf("casa [l%d] %%%d, l%d, l%d",
+ printf("CASA [l%d] %%%d, l%d, l%d",
labelrs1,
RD_FLD(instr, INSTR_IMMASI),
labelrs2,
@@ -653,42 +653,42 @@
else
{
if (!labels)
- printf("casa [r%d] , r%d, r%d",
+ printf("CASA [r%d] , r%d, r%d",
RD_FLD(instr, INSTR_RS1),
RD_FLD(instr, INSTR_RS2),
RD_FLD(instr, INSTR_RD));
else
- printf("casa [l%d] , l%d, l%d", labelrs1, labelrs2, labelrd);
+ printf("CASA [l%d] , l%d, l%d", labelrs1, labelrs2, labelrd);
}
- sparc_printalu("casa", instr,labels,
+ sparc_printalu("CASA", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_CASXA:
- sparc_printalu("casxa", instr,labels,
+ sparc_printalu("CASXA", instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STFA:
- sparc_printalu("stfa",instr,labels,
+ sparc_printalu("STFA",instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STDFA:
- sparc_printalu("stdfa",instr,labels,
+ sparc_printalu("STDFA",instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_STQFA:
- sparc_printalu("stqfa",instr,labels,
+ sparc_printalu("STQFA",instr,labels,
labelrs1, labelrs2, labelrd, labelccf);
return;
case OP3_PREFETCH:
- printf("prefetch ??? ");
+ printf("PREFETCH ??? ");
return;
case OP3_PREFETCHA:
- printf("prefetcha ??? ");
+ printf("PREFETCHA ??? ");
return;
}
@@ -696,6 +696,8 @@
assert(0);
}
+
+
void sparc_print_pseudo(unsigned instr, int labelrs1, int labelrs2, int labelrd, int labelccf)
{
if (RD_FLD(instr,INSTR_OP)==OP_CALL)
@@ -711,7 +713,7 @@
void sparc_print(unsigned instr)
{
if (RD_FLD(instr,INSTR_OP)==OP_CALL)
- printf("call disp:+%08X", instr & 0x3FFFFFFF);
+ printf("CALL disp:+%08X", instr & 0x3FFFFFFF);
else if (RD_FLD(instr,INSTR_OP)==OP_BRANCH)
sparc_printbr(instr,false,0, 0, 0, 0);
else if (RD_FLD(instr,INSTR_OP)==OP_2)
@@ -719,3 +721,6 @@
else if (RD_FLD(instr,INSTR_OP)==OP_3)
sparc_print3(instr,false,0, 0, 0, 0 );
}
+
+
+
More information about the llvm-commits
mailing list