Search in sources :

Example 86 with Node

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);
}
Also used : Insn(suite.assembler.Amd64.Insn) Operand(suite.assembler.Amd64.Operand) Node(suite.node.Node) Tree(suite.node.Tree)

Example 87 with Node

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;
}
Also used : Node(suite.node.Node) OpMem(suite.assembler.Amd64.OpMem) Int(suite.node.Int)

Example 88 with Node

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");
}
Also used : OpImm(suite.assembler.Amd64.OpImm) Operand(suite.assembler.Amd64.Operand) Node(suite.node.Node) Int(suite.node.Int)

Example 89 with Node

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");
}
Also used : CompileGeneralizerImpl(suite.lp.compile.impl.CompileGeneralizerImpl) Node(suite.node.Node) Data(suite.node.Data) Atom(suite.node.Atom)

Example 90 with Node

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;
}
Also used : Node(suite.node.Node)

Aggregations

Node (suite.node.Node)139 Tree (suite.node.Tree)50 Reference (suite.node.Reference)41 Atom (suite.node.Atom)37 Int (suite.node.Int)33 ArrayList (java.util.ArrayList)32 Pair (suite.adt.pair.Pair)25 List (java.util.List)24 TermOp (suite.node.io.TermOp)21 Read (suite.streamlet.Read)21 Test (org.junit.Test)20 Map (java.util.Map)19 Suite (suite.Suite)18 Generalizer (suite.lp.doer.Generalizer)18 Fail (suite.util.Fail)18 Fun (suite.util.FunUtil.Fun)18 Str (suite.node.Str)17 Trail (suite.lp.Trail)16 RuleSet (suite.lp.kb.RuleSet)16 Tuple (suite.node.Tuple)16