-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: support toggling the rendering of pseudoinstructions
Pseudo instructions like `addi x4,zero,2` are rendered as the more human- friendly `li x4,2`. However, the user can force the instructions to be rendered in their canonical format.
- Loading branch information
Showing
23 changed files
with
871 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#region License | ||
/* | ||
* Copyright (C) 1999-2024 John Källén. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; see the file COPYING. If not, write to | ||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | ||
*/ | ||
#endregion | ||
|
||
using NUnit.Framework; | ||
using Reko.Arch.RiscV; | ||
using Reko.Core; | ||
using Reko.Core.Machine; | ||
|
||
|
||
namespace Reko.UnitTests.Arch.RiscV | ||
{ | ||
[TestFixture] | ||
public class RiscVAssemblyRendererTests | ||
{ | ||
private readonly RegisterStorage zero = RegisterStorage.Reg32("zero", 0); | ||
private readonly RegisterStorage x1 = RegisterStorage.Reg32("x1", 1); | ||
private MachineInstructionRendererFlags flags; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
flags = MachineInstructionRendererFlags.None; | ||
} | ||
|
||
private void AssertCode(string sExpected, RiscVInstruction instr) | ||
{ | ||
var sr = new StringRenderer(); | ||
var options = new MachineInstructionRendererOptions( | ||
flags: flags | ||
); | ||
instr.Render(sr, options); | ||
var sActual = sr.ToString(); | ||
Assert.AreEqual(sExpected, sActual); | ||
} | ||
|
||
[Test] | ||
public void RiscVAr_addi_aliased_to_li() | ||
{ | ||
var instr = new RiscVInstruction | ||
{ | ||
Mnemonic = Mnemonic.addi, | ||
Operands = new MachineOperand[] { x1, zero, ImmediateOperand.Int32(-1)}, | ||
}; | ||
AssertCode("li\tx1,-0x1", instr); | ||
} | ||
|
||
[Test] | ||
public void RiscVAr_addi_not_aliased_to_li() | ||
{ | ||
var instr = new RiscVInstruction | ||
{ | ||
Mnemonic = Mnemonic.addi, | ||
Operands = new MachineOperand[] { x1, zero, ImmediateOperand.Int32(-1)}, | ||
}; | ||
flags |= MachineInstructionRendererFlags.RenderInstructionsCanonically; | ||
AssertCode("addi\tx1,zero,-0x1", instr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.