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

@ -1987,7 +1987,7 @@ bool SleighCompile::undefinePreprocValue(const string &nm)
// Functions needed by the parser
TokenSymbol *SleighCompile::defineToken(string *name,uintb *sz)
TokenSymbol *SleighCompile::defineToken(string *name,uintb *sz,int4 endian)
{
uint4 size = *sz;
@ -1998,7 +1998,12 @@ TokenSymbol *SleighCompile::defineToken(string *name,uintb *sz)
}
else
size = size/8;
Token *newtoken = new Token(*name,size,isBigEndian(),tokentable.size());
bool isBig;
if (endian ==0)
isBig = isBigEndian();
else
isBig = (endian > 0);
Token *newtoken = new Token(*name,size,isBig,tokentable.size());
tokentable.push_back(newtoken);
delete name;
TokenSymbol *res = new TokenSymbol(newtoken);

View file

@ -261,7 +261,7 @@ public:
bool undefinePreprocValue(const string &nm);
// Parser functions
TokenSymbol *defineToken(string *name,uintb *sz);
TokenSymbol *defineToken(string *name,uintb *sz,int4 endian);
void addTokenField(TokenSymbol *sym,FieldQuality *qual);
bool addContextField(VarnodeSymbol *sym,FieldQuality *qual);
void newSpace(SpaceQuality *qual);

View file

@ -181,7 +181,9 @@ aligndef: DEFINE_KEY ALIGN_KEY '=' INTEGER ';' { slgh->setAlignment(*$4); delete
;
tokendef: tokenprop ';' {}
;
tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' { $$ = slgh->defineToken($3,$5); }
tokenprop: DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' { $$ = slgh->defineToken($3,$5,0); }
| DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' LITTLE_KEY { $$ = slgh->defineToken($3,$5,-1); }
| DEFINE_KEY TOKEN_KEY STRING '(' INTEGER ')' ENDIAN_KEY '=' BIG_KEY { $$ = slgh->defineToken($3,$5,1); }
| tokenprop fielddef { $$ = $1; slgh->addTokenField($1,$2); }
| DEFINE_KEY TOKEN_KEY anysymbol { string errmsg=$3->getName()+": redefined as a token"; yyerror(errmsg.c_str()); YYERROR; }
;

View file

@ -494,7 +494,7 @@ int4 scan_number(char *numtext,YYSTYPE *lval,bool signednum)
[(),\-] { yylval.ch = yytext[0]; return yytext[0]; }
\: { BEGIN(print); slgh->calcContextLayout(); yylval.ch = yytext[0]; return yytext[0]; }
\{ { BEGIN(sem); yylval.ch = yytext[0]; return yytext[0]; }
#.*$
#.*
[\r\ \t\v]+
\n { slgh->nextLine(); }
macro { BEGIN(macroblock); return MACRO_KEY; }
@ -540,7 +540,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<defblock>values { return VALUES_KEY; }
<defblock>variables { return VARIABLES_KEY; }
<defblock>pcodeop { return PCODEOP_KEY; }
<defblock>#.*$
<defblock>#.*
<defblock>[a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); }
<defblock>[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,false); }
<defblock>0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,false); }
@ -582,7 +582,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<pattern>\| { yylval.ch = yytext[0]; return (actionon==0) ? yytext[0] : OP_OR; }
<pattern>\^ { return OP_XOR; }
<pattern>[=(),:;+\-*/~<>] { yylval.ch = yytext[0]; return yytext[0]; }
<pattern>#.*$
<pattern>#.*
<pattern>[a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); }
<pattern>[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,true); }
<pattern>0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,true); }
@ -648,7 +648,7 @@ with { BEGIN(pattern); withsection = 1; slgh->calcContextLayout(); return WITH
<sem>build { return BUILD_KEY; }
<sem>local { return LOCAL_KEY; }
<sem>[=(),:\[\];!&|^+\-*/%~<>] { yylval.ch = yytext[0]; return yytext[0]; }
<sem>#.*$
<sem>#.*
<sem>[a-zA-Z_.][a-zA-Z0-9_.]* { return find_symbol(); }
<sem>[0-9]|[1-9][0-9]+ { return scan_number(yytext,&yylval,false); }
<sem>0x[0-9a-fA-F]+ { return scan_number(yytext,&yylval,false); }

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);