Search in sources :

Example 1 with Amd64Interpret

use of suite.assembler.Amd64Interpret in project suite by stupidsing.

the class ElfTest method test.

private void test(String program, String input, int code) {
    Bytes bytes = Bytes.of(input.getBytes(Constants.charset));
    if (RunUtil.isUnix()) {
        // not Windows => run ELF
        Execute exec = elf.exec(bytes.toArray(), offset -> Funp_.main().compile(offset, program).t1);
        assertEquals(code, exec.code);
        assertEquals(input, exec.out);
    } else {
        // Windows => interpret assembly
        Pair<List<Instruction>, Bytes> pair = Funp_.main().compile(code, program);
        Amd64Interpret interpret = new Amd64Interpret();
        assertEquals(code, interpret.interpret(pair.t0, pair.t1, bytes));
        assertEquals(bytes, interpret.out.toBytes());
    }
}
Also used : Bytes(suite.primitive.Bytes) Amd64Interpret(suite.assembler.Amd64Interpret) List(java.util.List)

Example 2 with Amd64Interpret

use of suite.assembler.Amd64Interpret in project suite by stupidsing.

the class FunpTest method test.

private void test(int r, String p) {
    LogUtil.info(p);
    Pair<List<Instruction>, Bytes> pair = Funp_.main().compile(0, p);
    Bytes bytes = pair.t1;
    LogUtil.info("Hex" + bytes + "\n\n");
    assertEquals(r, new Amd64Interpret().interpret(pair.t0, Bytes.of(), Bytes.of()));
    assertTrue(bytes != null);
}
Also used : Bytes(suite.primitive.Bytes) Amd64Interpret(suite.assembler.Amd64Interpret) List(java.util.List)

Aggregations

List (java.util.List)2 Amd64Interpret (suite.assembler.Amd64Interpret)2 Bytes (suite.primitive.Bytes)2