Search in sources :

Example 6 with Operand

use of suite.assembler.Amd64.Operand in project suite by stupidsing.

the class Amd64Dump method dump.

public String dump(Instruction instruction) {
    Operand op0 = instruction.op0;
    Operand op1 = instruction.op1;
    Operand op2 = instruction.op2;
    return // 
    instruction.insn + // 
    (!(op0 instanceof OpNone) ? " " + dump(op0) : "") + // 
    (!(op1 instanceof OpNone) ? "," + dump(op1) : "") + (!(op2 instanceof OpNone) ? "," + dump(op2) : "");
}
Also used : Operand(suite.assembler.Amd64.Operand) OpNone(suite.assembler.Amd64.OpNone)

Example 7 with Operand

use of suite.assembler.Amd64.Operand in project suite by stupidsing.

the class Amd64Parse method parse.

public Instruction parse(Node node) {
    Tree tree = Tree.decompose(node, TermOp.TUPLE_);
    Insn insn = Enum.valueOf(Insn.class, ((Atom) tree.getLeft()).name);
    Node ops = tree.getRight();
    List<Operand> operands = scan(ops, ".0, .1").map(this::parseOperand).toList();
    return // 
    amd64.instruction(// 
    insn, // 
    0 < operands.size() ? operands.get(0) : amd64.none, // 
    1 < operands.size() ? operands.get(1) : amd64.none, 2 < operands.size() ? operands.get(2) : amd64.none);
}
Also used : Insn(suite.assembler.Amd64.Insn) Operand(suite.assembler.Amd64.Operand) Node(suite.node.Node) Tree(suite.node.Tree)

Example 8 with Operand

use of suite.assembler.Amd64.Operand in project suite by stupidsing.

the class Amd64Parse method parseOpMem.

private Operand parseOpMem(Node[] m, int size) {
    OpMem opMem = amd64.new OpMem();
    opMem.size = size;
    opMem.indexReg = -1;
    opMem.baseReg = -1;
    opMem.dispSize = 0;
    for (Node component : scan(m[0], ".0 + .1")) if ((m = Suite.pattern(".0 * .1").match(component)) != null)
        if (opMem.indexReg < 0) {
            opMem.indexReg = amd64.regByName.get(m[0]).reg;
            opMem.scale = ((Int) m[1]).number;
        } else
            Fail.t("bad operand");
    else if (component instanceof Int)
        if (opMem.dispSize == 0) {
            opMem.disp = ((Int) component).number;
            opMem.dispSize = 4;
        } else
            Fail.t("bad operand");
    else if (opMem.baseReg < 0)
        opMem.baseReg = amd64.regByName.get(component).reg;
    else
        Fail.t("bad operand");
    return opMem;
}
Also used : Node(suite.node.Node) OpMem(suite.assembler.Amd64.OpMem) Int(suite.node.Int)

Example 9 with Operand

use of suite.assembler.Amd64.Operand in project suite by stupidsing.

the class Amd64Parse method parseOperand.

public Operand parseOperand(Node node) {
    Operand operand;
    Node[] m;
    if ((operand = amd64.registerByName.get(node)) != null)
        return operand;
    else if ((m = Suite.pattern("BYTE `.0`").match(node)) != null)
        return parseOpMem(m, 1);
    else if ((m = Suite.pattern("WORD `.0`").match(node)) != null)
        return parseOpMem(m, 2);
    else if ((m = Suite.pattern("DWORD `.0`").match(node)) != null)
        return parseOpMem(m, 4);
    else if ((m = Suite.pattern("`.0`").match(node)) != null)
        return parseOpMem(m, 4);
    else if (node instanceof Int) {
        OpImm opImm = amd64.new OpImm();
        opImm.imm = ((Int) node).number;
        opImm.size = 4;
        return opImm;
    } else
        return Fail.t("bad operand");
}
Also used : OpImm(suite.assembler.Amd64.OpImm) Operand(suite.assembler.Amd64.Operand) Node(suite.node.Node) Int(suite.node.Int)

Aggregations

OpImm (suite.assembler.Amd64.OpImm)5 OpReg (suite.assembler.Amd64.OpReg)5 Operand (suite.assembler.Amd64.Operand)5 OpMem (suite.assembler.Amd64.OpMem)4 Node (suite.node.Node)3 Insn (suite.assembler.Amd64.Insn)2 Int (suite.node.Int)2 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Instruction (suite.assembler.Amd64.Instruction)1 OpNone (suite.assembler.Amd64.OpNone)1 Funp_ (suite.funp.Funp_)1 Tree (suite.node.Tree)1 LogUtil (suite.os.LogUtil)1 Bytes (suite.primitive.Bytes)1 BytesBuilder (suite.primitive.Bytes.BytesBuilder)1 IntSink (suite.primitive.IntPrimitives.IntSink)1 IntIntMap (suite.primitive.adt.map.IntIntMap)1 Fail (suite.util.Fail)1 Friends.min (suite.util.Friends.min)1