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) : "");
}
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);
}
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;
}
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");
}
Aggregations