token endianness

This commit is contained in:
caheckman 2020-10-20 11:23:59 -04:00
parent a4f5472e94
commit 6ed4ce628c
10 changed files with 42 additions and 15 deletions

View file

@ -119,6 +119,7 @@ tokens {
OP_SUBTABLE;
OP_TABLE;
OP_TOKEN;
OP_TOKEN_ENDIAN;
OP_TRUNCATION_SIZE;
OP_TYPE;
OP_UNIMPL;

View file

@ -183,10 +183,20 @@ tokendef
if (sym != null) {
redefinedError(sym, n, "token");
} else {
$tokendef::tokenSymbol = sc.defineToken(find(n), $n.value.getText(), $i.value.intValue());
$tokendef::tokenSymbol = sc.defineToken(find(n), $n.value.getText(), $i.value.intValue(), 0);
}
}
} fielddefs)
| ^(OP_TOKEN_ENDIAN n=specific_identifier["token definition"] i=integer s=endian {
if (n != null) {
SleighSymbol sym = sc.findSymbol($n.value.getText());
if (sym != null) {
redefinedError(sym, n, "token");
} else {
$tokendef::tokenSymbol = sc.defineToken(find(n), $n.value.getText(), $i.value.intValue(), $s.value ==0 ? -1 : 1);
}
}
} fielddefs)
;
fielddefs

View file

@ -60,6 +60,7 @@ aligndef
tokendef
: ^(OP_TOKEN n=identifier i=integer { out("define token " + $n.value + "(" + $i.value + ")"); } fielddefs)
| ^(OP_TOKEN_ENDIAN n=identifier i=integer s=endian { out("define token endian" + $n.value + "(" + $i.value + ")"); } fielddefs)
;
fielddefs

View file

@ -74,6 +74,7 @@ aligndef
tokendef
: lc=KEY_DEFINE KEY_TOKEN identifier LPAREN integer rp=RPAREN fielddefs[$rp] -> ^(OP_TOKEN[$lc, "define token"] identifier integer fielddefs)
| lc=KEY_DEFINE KEY_TOKEN identifier LPAREN integer RPAREN rp=KEY_ENDIAN ASSIGN endian fielddefs[$rp] -> ^(OP_TOKEN_ENDIAN[$lc, "define token"] identifier integer endian fielddefs)
;
fielddefs[Token lc]

View file

@ -889,9 +889,9 @@ public class SleighLanguage implements Language {
}
boolean isBigEndian = SpecXmlUtils.decodeBoolean(el.getAttribute("bigendian"));
// check the instruction endianess, not the program data endianess
if (isBigEndian ^ description.getInstructionEndian().isBigEndian()) {
if (isBigEndian ^ description.getEndian().isBigEndian()) {
throw new SleighException(
".ldefs says " + getLanguageID() + " is " + description.getInstructionEndian() +
".ldefs says " + getLanguageID() + " is " + description.getEndian() +
" but .sla says " + el.getAttribute("bigendian"));
}
uniqueBase = SpecXmlUtils.decodeLong(el.getAttribute("uniqbase"));

View file

@ -529,8 +529,8 @@ public class SleighCompile extends SleighBase {
static int findCollision(Map<Long, Integer> local2Operand, ArrayList<Long> locals,
int operand) {
Integer boxOperand = Integer.valueOf(operand);
for (int i = 0; i < locals.size(); ++i) {
Integer previous = local2Operand.putIfAbsent(locals.get(i), boxOperand);
for (Long local : locals) {
Integer previous = local2Operand.putIfAbsent(local, boxOperand);
if (previous != null) {
if (previous.intValue() != operand) {
return previous.intValue();
@ -842,7 +842,7 @@ public class SleighCompile extends SleighBase {
}
// Parser functions
public TokenSymbol defineToken(Location location, String name, long sz) {
public TokenSymbol defineToken(Location location, String name, long sz, int endian) {
entry("defineToken", location, name, sz);
int size = (int) sz;
if ((size & 7) != 0) {
@ -853,8 +853,15 @@ public class SleighCompile extends SleighBase {
else {
size = size / 8;
}
boolean isBig;
if (endian == 0) {
isBig = isBigEndian();
}
else {
isBig = (endian > 0);
}
ghidra.pcodeCPort.context.Token newtoken =
new ghidra.pcodeCPort.context.Token(name, size, isBigEndian(), tokentable.size());
new ghidra.pcodeCPort.context.Token(name, size, isBig, tokentable.size());
tokentable.push_back(newtoken);
TokenSymbol res = new TokenSymbol(location, newtoken);
addSymbol(res);