Skip to content

Commit

Permalink
Merge pull request #951 from kenjiuno/fix-bdx-opcode-renaming
Browse files Browse the repository at this point in the history
Opcode name changing chance
  • Loading branch information
shananas authored Dec 22, 2023
2 parents 3fe37b4 + c8f18e1 commit d7a7864
Show file tree
Hide file tree
Showing 17 changed files with 454 additions and 114 deletions.
4 changes: 2 additions & 2 deletions OpenKh.Command.Bdxio/Antlr4/BdxScript.g4
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ numberdata:
| '0x' hexnumber = (DEC | HEX)
| floatnumber = FLOATNUM;
hexbody: DEC | HEX;
id: ID | DEC | HEX;
id: DEC | HEX | ID;
include: '%include' FileName NL;
section: 'section' section_id NL;
section_id: '.text' | '.bss';
Expand All @@ -41,7 +41,7 @@ HEX: [0-9a-fA-F]+;
FLOATNUM:
[-+]? ([0-9]* '.' [0-9]+)
| ([0-9]+ [eE] [-+]? [0-9]+);
ID: [a-zA-Z_][a-zA-Z0-9_]*;
ID: [a-zA-Z_][a-zA-Z0-9_]* ('.' [a-zA-Z0-9_]+)*;
WS: [ \t] -> skip;
NL: '\r'? '\n' | '\r';
FileName: '"' ~["]* '"';
Expand Down
38 changes: 21 additions & 17 deletions OpenKh.Command.Bdxio/Antlr4/BdxScriptLexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static BdxScriptLexer() {
}
}
private static int[] _serializedATN = {
4,0,22,196,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
4,0,22,207,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,
6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,
7,14,2,15,7,15,2,16,7,16,2,17,7,17,2,18,7,18,2,19,7,19,2,20,7,20,2,21,
7,21,1,0,1,0,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,4,1,5,1,5,1,
Expand All @@ -109,22 +109,23 @@ static BdxScriptLexer() {
16,131,8,16,1,16,5,16,134,8,16,10,16,12,16,137,9,16,1,16,1,16,4,16,141,
8,16,11,16,12,16,142,1,16,4,16,146,8,16,11,16,12,16,147,1,16,1,16,3,16,
152,8,16,1,16,4,16,155,8,16,11,16,12,16,156,3,16,159,8,16,1,17,1,17,5,
17,163,8,17,10,17,12,17,166,9,17,1,18,1,18,1,18,1,18,1,19,3,19,173,8,19,
1,19,1,19,3,19,177,8,19,1,20,1,20,5,20,181,8,20,10,20,12,20,184,9,20,1,
20,1,20,1,21,1,21,5,21,190,8,21,10,21,12,21,193,9,21,1,21,1,21,0,0,22,
17,163,8,17,10,17,12,17,166,9,17,1,17,1,17,4,17,170,8,17,11,17,12,17,171,
5,17,174,8,17,10,17,12,17,177,9,17,1,18,1,18,1,18,1,18,1,19,3,19,184,8,
19,1,19,1,19,3,19,188,8,19,1,20,1,20,5,20,192,8,20,10,20,12,20,195,9,20,
1,20,1,20,1,21,1,21,5,21,201,8,21,10,21,12,21,204,9,21,1,21,1,21,0,0,22,
1,1,3,2,5,3,7,4,9,5,11,6,13,7,15,8,17,9,19,10,21,11,23,12,25,13,27,14,
29,15,31,16,33,17,35,18,37,19,39,20,41,21,43,22,1,0,10,1,0,39,39,2,0,43,
43,45,45,1,0,48,57,3,0,48,57,65,70,97,102,2,0,69,69,101,101,3,0,65,90,
95,95,97,122,4,0,48,57,65,90,95,95,97,122,2,0,9,9,32,32,1,0,34,34,2,0,
10,10,13,13,211,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,
10,10,13,13,224,0,1,1,0,0,0,0,3,1,0,0,0,0,5,1,0,0,0,0,7,1,0,0,0,0,9,1,
0,0,0,0,11,1,0,0,0,0,13,1,0,0,0,0,15,1,0,0,0,0,17,1,0,0,0,0,19,1,0,0,0,
0,21,1,0,0,0,0,23,1,0,0,0,0,25,1,0,0,0,0,27,1,0,0,0,0,29,1,0,0,0,0,31,
1,0,0,0,0,33,1,0,0,0,0,35,1,0,0,0,0,37,1,0,0,0,0,39,1,0,0,0,0,41,1,0,0,
0,0,43,1,0,0,0,1,45,1,0,0,0,3,47,1,0,0,0,5,51,1,0,0,0,7,54,1,0,0,0,9,56,
1,0,0,0,11,59,1,0,0,0,13,64,1,0,0,0,15,69,1,0,0,0,17,76,1,0,0,0,19,79,
1,0,0,0,21,88,1,0,0,0,23,96,1,0,0,0,25,102,1,0,0,0,27,107,1,0,0,0,29,117,
1,0,0,0,31,125,1,0,0,0,33,158,1,0,0,0,35,160,1,0,0,0,37,167,1,0,0,0,39,
176,1,0,0,0,41,178,1,0,0,0,43,187,1,0,0,0,45,46,5,58,0,0,46,2,1,0,0,0,
1,0,0,0,31,125,1,0,0,0,33,158,1,0,0,0,35,160,1,0,0,0,37,178,1,0,0,0,39,
187,1,0,0,0,41,189,1,0,0,0,43,198,1,0,0,0,45,46,5,58,0,0,46,2,1,0,0,0,
47,48,5,101,0,0,48,49,5,113,0,0,49,50,5,117,0,0,50,4,1,0,0,0,51,52,5,100,
0,0,52,53,5,119,0,0,53,6,1,0,0,0,54,55,5,44,0,0,55,8,1,0,0,0,56,57,5,100,
0,0,57,58,5,98,0,0,58,10,1,0,0,0,59,60,5,114,0,0,60,61,5,101,0,0,61,62,
Expand Down Expand Up @@ -154,16 +155,19 @@ static BdxScriptLexer() {
0,0,0,155,156,1,0,0,0,156,154,1,0,0,0,156,157,1,0,0,0,157,159,1,0,0,0,
158,130,1,0,0,0,158,145,1,0,0,0,159,34,1,0,0,0,160,164,7,5,0,0,161,163,
7,6,0,0,162,161,1,0,0,0,163,166,1,0,0,0,164,162,1,0,0,0,164,165,1,0,0,
0,165,36,1,0,0,0,166,164,1,0,0,0,167,168,7,7,0,0,168,169,1,0,0,0,169,170,
6,18,0,0,170,38,1,0,0,0,171,173,5,13,0,0,172,171,1,0,0,0,172,173,1,0,0,
0,173,174,1,0,0,0,174,177,5,10,0,0,175,177,5,13,0,0,176,172,1,0,0,0,176,
175,1,0,0,0,177,40,1,0,0,0,178,182,5,34,0,0,179,181,8,8,0,0,180,179,1,
0,0,0,181,184,1,0,0,0,182,180,1,0,0,0,182,183,1,0,0,0,183,185,1,0,0,0,
184,182,1,0,0,0,185,186,5,34,0,0,186,42,1,0,0,0,187,191,5,59,0,0,188,190,
8,9,0,0,189,188,1,0,0,0,190,193,1,0,0,0,191,189,1,0,0,0,191,192,1,0,0,
0,192,194,1,0,0,0,193,191,1,0,0,0,194,195,6,21,0,0,195,44,1,0,0,0,17,0,
111,117,122,127,130,135,142,147,151,156,158,164,172,176,182,191,1,6,0,
0
0,165,175,1,0,0,0,166,164,1,0,0,0,167,169,5,46,0,0,168,170,7,6,0,0,169,
168,1,0,0,0,170,171,1,0,0,0,171,169,1,0,0,0,171,172,1,0,0,0,172,174,1,
0,0,0,173,167,1,0,0,0,174,177,1,0,0,0,175,173,1,0,0,0,175,176,1,0,0,0,
176,36,1,0,0,0,177,175,1,0,0,0,178,179,7,7,0,0,179,180,1,0,0,0,180,181,
6,18,0,0,181,38,1,0,0,0,182,184,5,13,0,0,183,182,1,0,0,0,183,184,1,0,0,
0,184,185,1,0,0,0,185,188,5,10,0,0,186,188,5,13,0,0,187,183,1,0,0,0,187,
186,1,0,0,0,188,40,1,0,0,0,189,193,5,34,0,0,190,192,8,8,0,0,191,190,1,
0,0,0,192,195,1,0,0,0,193,191,1,0,0,0,193,194,1,0,0,0,194,196,1,0,0,0,
195,193,1,0,0,0,196,197,5,34,0,0,197,42,1,0,0,0,198,202,5,59,0,0,199,201,
8,9,0,0,200,199,1,0,0,0,201,204,1,0,0,0,202,200,1,0,0,0,202,203,1,0,0,
0,203,205,1,0,0,0,204,202,1,0,0,0,205,206,6,21,0,0,206,44,1,0,0,0,19,0,
111,117,122,127,130,135,142,147,151,156,158,164,171,175,183,187,193,202,
1,6,0,0
};

public static readonly ATN _ATN =
Expand Down
2 changes: 1 addition & 1 deletion OpenKh.Command.Bdxio/Antlr4/BdxScriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1025,9 +1025,9 @@ public HexbodyContext hexbody() {
}

public partial class IdContext : ParserRuleContext {
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(BdxScriptParser.ID, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode DEC() { return GetToken(BdxScriptParser.DEC, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode HEX() { return GetToken(BdxScriptParser.HEX, 0); }
[System.Diagnostics.DebuggerNonUserCode] public ITerminalNode ID() { return GetToken(BdxScriptParser.ID, 0); }
public IdContext(ParserRuleContext parent, int invokingState)
: base(parent, invokingState)
{
Expand Down
25 changes: 25 additions & 0 deletions OpenKh.Command.Bdxio/Antlr4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ java.exe -jar antlr-4.11.1-complete.jar BdxScript.g4 -Dlanguage=CSharp -no-liste
```

Only `BdxScriptLexer.cs` and `BdxScriptParser.cs` are needed. Others are not needed.

## How bdx text is parsed to tree

Use Visual Studio Code `mike-lischke.vscode-antlr4` plugin.

And write this at `OpenKh/OpenKh.Command.Bdxio/Antlr4/.vscode/launch.json`

```
{
"version": "1.0.0",
"configurations": [
{
"name": "Debug ANTLR4 grammar",
"type": "antlr-debug",
"request": "launch",
"input": "test.bdx",
"grammar": "BdxScript.g4",
"printParseTree": true,
"visualParseTree": true
},
]
}
```

Write something to `test.bdx` and press `F5` key.
8 changes: 5 additions & 3 deletions OpenKh.Command.Bdxio/Models/BdxInstructionDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ public record BdxInstructionDesc
public ushort Code { get; set; }
public ushort CodeMask { get; set; }

public string Name { get; set; }
public string Name { get; set; } = "";
public bool IsSyscall { get; set; }
public bool IsGosub { get; set; }
public bool IsJump { get; set; }
public bool IsJumpConditional { get; set; }
public bool NeverReturn { get; set; }
public bool IsGosubRet { get; set; }
public bool CodeRevealerLabeling { get; set; }
public int CodeSize { get; set; }
public Arg[] Args { get; set; }
public Arg[] Args { get; set; } = new Arg[0];
public string[] OldNames { get; set; } = new string[0];

public override string ToString() => Name;

public record Arg
{
public string Name { get; set; }
public string Name { get; set; } = "";
public ArgType Type { get; set; }

/// <summary>
Expand Down
Loading

0 comments on commit d7a7864

Please sign in to comment.