示例#1
0
        public string ConvertArrayCreationNode(ArrayCreationNode acn, Dictionary <string, int> dict)
        {
            Func <string, string, string> f = (x, y) => x + "\t ; " + y;

            string code = converter.ConvertToCode(converter.Convert(acn.size, dict)
                                                  + "\t \t ; length of array",
                                                  f("mov ecx, [heapIndex]", "ecx = current position in heap"),
                                                  "shl eax, 2" + "\t \t ; length = length * 4",
                                                  "add ecx, eax" + "\t \t ; ecx = position + length * 4 ",
                                                  f("mov eax, [heapIndex]", "eax = heapIndex"),
                                                  f("mov [heapIndex], ecx", "heapIndex = ecx"));

            return(code);
        }
示例#2
0
        public string Comparator(BinaryOperationNode bnode, Dictionary <string, int> variableIndex)
        {
            string instructions = converter.ConvertToCode(StandardBinaryOperation(bnode, variableIndex));

            string zeroFlag = converter.ConvertToCode("cmp eax, ecx", "lahf", "shr eax, 14", "and eax, 1");
            string signFlag = converter.ConvertToCode("cmp eax, ecx", "lahf", "shr eax, 15", "and eax, 1");
            string comb     = zeroFlag + converter.ConvertToCode("mov edx, eax", "lahf", "shr eax, 14", "and eax, 1");

            string op     = "";
            string negate = converter.ConvertToCode("not eax", "and eax, 1");

            switch (bnode.operation)
            {
            case "==": op = zeroFlag; break;

            case "<": op = signFlag; break;

            case "<=": op = comb; break;

            case "!=": op = zeroFlag + negate;  break;

            case ">=": op = signFlag + negate;  break;

            case ">": op = comb + negate; break;

            default: throw new Exception("Comparator " + bnode.operation + " is not being converted.");
            }

            return(instructions + op);
        }