use of suite.node.Node 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.node.Node 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.node.Node 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");
}
use of suite.node.Node in project suite by stupidsing.
the class CommandDispatcher method elaborate.
private void elaborate(Node node0, Sink<Node> sink) {
int[] count = { 0 };
NodeEnv<Atom> ne = new CompileGeneralizerImpl().g(node0).source();
Node node1 = ne.node;
Node elab = new Data<Source<Boolean>>(() -> {
String dump = ne.dumpVariables();
if (!dump.isEmpty())
opt.prompt().println(dump);
count[0]++;
return Boolean.FALSE;
});
sink.sink(Tree.of(TermOp.AND___, node1, elab));
if (count[0] == 1)
opt.prompt().println(count[0] + " solution\n");
else
opt.prompt().println(count[0] + " solutions\n");
}
use of suite.node.Node in project suite by stupidsing.
the class CommandDispatcher method dispatchType.
public boolean dispatchType(List<String> inputs) throws IOException {
Node node = parseNode(inputs);
System.out.println(Formatter.dump(Suite.evaluateFunType(opt.fcc(node))));
return true;
}
Aggregations