mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-6158: Allows static methods to be marked @PcodeOp in UseropLibrary
This commit is contained in:
@@ -238,6 +238,11 @@ public abstract class AbstractJitCodeGeneratorTest extends AbstractJitTest {
|
||||
return 2 * a + b;
|
||||
}
|
||||
|
||||
@PcodeUserop(functional = true)
|
||||
public static long func_st_userop(long a, long b) {
|
||||
return 3 * a + b;
|
||||
}
|
||||
|
||||
@PcodeUserop(functional = true)
|
||||
public void func_mpUserop(@OpOutput int[] out, int[] a, int[] b) {
|
||||
gotFuncUseropCall = true;
|
||||
@@ -254,6 +259,20 @@ public abstract class AbstractJitCodeGeneratorTest extends AbstractJitTest {
|
||||
}
|
||||
}
|
||||
|
||||
@PcodeUserop(functional = true)
|
||||
public static void func_st_mpUserop(@OpOutput int[] out, int[] a, int[] b) {
|
||||
if (out == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
out[0] = b[0];
|
||||
out[1] = a[0];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
out[0] |= out[0] << 8;
|
||||
out[1] |= out[1] << 8;
|
||||
}
|
||||
}
|
||||
|
||||
@PcodeUserop(canInline = true)
|
||||
public void sleigh_userop(@OpExecutor PcodeExecutor<byte[]> executor,
|
||||
@OpLibrary PcodeUseropLibrary<byte[]> library,
|
||||
|
||||
@@ -497,6 +497,17 @@ public abstract class AbstractToyJitCodeGeneratorTest extends AbstractJitCodeGen
|
||||
assertEquals(0, tr.getLongRegVal("r0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallOtherFuncJavaDefStatic() throws Exception {
|
||||
Translation tr = translateSleigh(getLanguageID(), """
|
||||
r0 = func_st_userop(6:8, 2:8);
|
||||
""");
|
||||
assertFalse(tr.library().gotFuncUseropCall);
|
||||
tr.runFallthrough();
|
||||
assertFalse(tr.library().gotFuncUseropCall);
|
||||
assertEquals(20, tr.getLongRegVal("r0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallOtherFuncJavaDefMpInt() throws Exception {
|
||||
Translation tr = translateSleigh(getLanguageID(), """
|
||||
@@ -524,6 +535,20 @@ public abstract class AbstractToyJitCodeGeneratorTest extends AbstractJitCodeGen
|
||||
assertEquals(0, tr.getLongRegVal("r0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallOtherFuncJavaDefStaticMpInt() throws Exception {
|
||||
Translation tr = translateSleigh(getLanguageID(), """
|
||||
temp1:9 = zext(6:8);
|
||||
temp2:9 = zext(2:8);
|
||||
temp0:9 = func_st_mpUserop(temp1, temp2);
|
||||
r0 = temp0(0);
|
||||
""");
|
||||
assertFalse(tr.library().gotFuncUseropCall);
|
||||
tr.runFallthrough();
|
||||
assertFalse(tr.library().gotFuncUseropCall);
|
||||
assertEquals(0x0606060602020202L, tr.getLongRegVal("r0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the emulator doesn't throw until the userop is actually encountered at run time.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user