Make the decompiler plugin invoke the transpiler

This commit is contained in:
Dhruv Maroo
2023-04-22 07:04:44 +05:30
parent 8f916a6a8d
commit 59fef18c3a
9 changed files with 1511 additions and 1454 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -100,6 +100,8 @@ public interface CParserConstants {
int LETTER = 55;
/** RegularExpression Id. */
int DIGIT = 56;
/** RegularExpression Id. */
int SEPARATOR = 57;
/** Lexical state. */
int DEFAULT = 0;
@@ -165,6 +167,7 @@ public interface CParserConstants {
"<IDENTIFIER>",
"<LETTER>",
"<DIGIT>",
"<SEPARATOR>",
"\";\"",
"\",\"",
"\"=\"",

View File

@@ -1,7 +1,7 @@
package ghidrust.decompiler.parser.c.gen;
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 7.0 */
/* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
/**
* An implementation of interface CharStream, where the stream is assumed to
* contain only ASCII characters (without unicode processing).
@@ -10,35 +10,35 @@ package ghidrust.decompiler.parser.c.gen;
public class SimpleCharStream
{
/** Whether parser is static. */
public static final boolean staticFlag = true;
static int bufsize;
static int available;
static int tokenBegin;
public static final boolean staticFlag = false;
int bufsize;
int available;
int tokenBegin;
/** Position in buffer. */
static public int bufpos = -1;
static protected int bufline[];
static protected int bufcolumn[];
public int bufpos = -1;
protected int bufline[];
protected int bufcolumn[];
static protected int column = 0;
static protected int line = 1;
protected int column = 0;
protected int line = 1;
static protected boolean prevCharIsCR = false;
static protected boolean prevCharIsLF = false;
protected boolean prevCharIsCR = false;
protected boolean prevCharIsLF = false;
static protected java.io.Reader inputStream;
protected java.io.Reader inputStream;
static protected char[] buffer;
static protected int maxNextCharInd = 0;
static protected int inBuf = 0;
static protected int tabSize = 1;
static protected boolean trackLineColumn = true;
protected char[] buffer;
protected int maxNextCharInd = 0;
protected int inBuf = 0;
protected int tabSize = 1;
protected boolean trackLineColumn = true;
static public void setTabSize(int i) { tabSize = i; }
static public int getTabSize() { return tabSize; }
public void setTabSize(int i) { tabSize = i; }
public int getTabSize() { return tabSize; }
static protected void ExpandBuff(boolean wrapAround)
protected void ExpandBuff(boolean wrapAround)
{
char[] newbuffer = new char[bufsize + 2048];
int newbufline[] = new int[bufsize + 2048];
@@ -87,7 +87,7 @@ public class SimpleCharStream
tokenBegin = 0;
}
static protected void FillBuff() throws java.io.IOException
protected void FillBuff() throws java.io.IOException
{
if (maxNextCharInd == available)
{
@@ -132,7 +132,7 @@ public class SimpleCharStream
}
/** Start. */
static public char BeginToken() throws java.io.IOException
public char BeginToken() throws java.io.IOException
{
tokenBegin = -1;
char c = readChar();
@@ -141,7 +141,7 @@ public class SimpleCharStream
return c;
}
static protected void UpdateLineColumn(char c)
protected void UpdateLineColumn(char c)
{
column++;
@@ -182,7 +182,7 @@ public class SimpleCharStream
}
/** Read a character. */
static public char readChar() throws java.io.IOException
public char readChar() throws java.io.IOException
{
if (inBuf > 0)
{
@@ -209,7 +209,7 @@ public class SimpleCharStream
* @see #getEndColumn
*/
static public int getColumn() {
public int getColumn() {
return bufcolumn[bufpos];
}
@@ -219,32 +219,32 @@ public class SimpleCharStream
* @see #getEndLine
*/
static public int getLine() {
public int getLine() {
return bufline[bufpos];
}
/** Get token end column number. */
static public int getEndColumn() {
public int getEndColumn() {
return bufcolumn[bufpos];
}
/** Get token end line number. */
static public int getEndLine() {
public int getEndLine() {
return bufline[bufpos];
}
/** Get token beginning column number. */
static public int getBeginColumn() {
public int getBeginColumn() {
return bufcolumn[tokenBegin];
}
/** Get token beginning line number. */
static public int getBeginLine() {
public int getBeginLine() {
return bufline[tokenBegin];
}
/** Backup a number of characters. */
static public void backup(int amount) {
public void backup(int amount) {
inBuf += amount;
if ((bufpos -= amount) < 0)
@@ -255,10 +255,6 @@ public class SimpleCharStream
public SimpleCharStream(java.io.Reader dstream, int startline,
int startcolumn, int buffersize)
{
if (inputStream != null)
throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream.\n" +
" You must either use ReInit() or set the JavaCC option STATIC to false\n" +
" during the generation of this class.");
inputStream = dstream;
line = startline;
column = startcolumn - 1;
@@ -392,7 +388,7 @@ public class SimpleCharStream
ReInit(dstream, startline, startcolumn, 4096);
}
/** Get token literal value. */
static public String GetImage()
public String GetImage()
{
if (bufpos >= tokenBegin)
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
@@ -402,7 +398,7 @@ public class SimpleCharStream
}
/** Get the suffix. */
static public char[] GetSuffix(int len)
public char[] GetSuffix(int len)
{
char[] ret = new char[len];
@@ -419,7 +415,7 @@ public class SimpleCharStream
}
/** Reset buffer when finished. */
static public void Done()
public void Done()
{
buffer = null;
bufline = null;
@@ -429,7 +425,7 @@ public class SimpleCharStream
/**
* Method to adjust line and column numbers for the start of a token.
*/
static public void adjustBeginLineColumn(int newLine, int newCol)
public void adjustBeginLineColumn(int newLine, int newCol)
{
int start = tokenBegin;
int len;
@@ -472,7 +468,7 @@ public class SimpleCharStream
line = bufline[j];
column = bufcolumn[j];
}
static boolean getTrackLineColumn() { return trackLineColumn; }
static void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; }
boolean getTrackLineColumn() { return trackLineColumn; }
void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; }
}
/* JavaCC - OriginalChecksum=052d2c8783a7a693ccde91d90feb1d3b (do not edit this line) */
/* JavaCC - OriginalChecksum=320e3957affec8972ad656fb86b8d782 (do not edit this line) */

View File

@@ -12,6 +12,7 @@ From: https://github.com/javacc/javacc/blob/master/grammars/CParser.jj
options {
STATIC = false;
}
PARSER_BEGIN(CParser)
@@ -22,7 +23,7 @@ import java.nio.charset.StandardCharsets;
import ghidrust.decompiler.parser.c.CVisitor;
public class CParser/*@bgen(jjtree)*/implements CParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/
protected static JJTCParserState jjtree = new JJTCParserState();
protected JJTCParserState jjtree = new JJTCParserState();
/*@egen*/
private static CParser c_parser;
@@ -123,9 +124,10 @@ TOKEN : {
}
TOKEN : {
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
<IDENTIFIER: (<LETTER> | <SEPARATOR> <SEPARATOR>) (<LETTER> | <SEPARATOR> <SEPARATOR> | <DIGIT>)*>
| <#LETTER: ["$","A"-"Z","_","a"-"z"]>
| <#DIGIT: ["0"-"9"]>
| <#SEPARATOR: [":"]>
}

View File

@@ -11,6 +11,7 @@ From: https://github.com/javacc/javacc/blob/master/grammars/CParser.jj
options {
MULTI = true;
VISITOR = true;
STATIC = false;
}
PARSER_BEGIN(CParser)
@@ -119,9 +120,10 @@ TOKEN : {
}
TOKEN : {
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
<IDENTIFIER: (<LETTER> | <SEPARATOR> <SEPARATOR>) (<LETTER> | <SEPARATOR> <SEPARATOR> | <DIGIT>)*>
| <#LETTER: ["$","A"-"Z","_","a"-"z"]>
| <#DIGIT: ["0"-"9"]>
| <#SEPARATOR: [":"]>
}