public static bool AreEqual(Instruction x, Instruction y) { if (x.GetType() != y.GetType()) return false; switch (MethodName(x.GetType().ToString())) { case "Debug": return (((Debug)x).Info == ((Debug)y).Info); case "MakeGlobal": return (((MakeGlobal)x).Method == ((MakeGlobal)y).Method); case "SectionCode": return true; case "Add": return (AreEqual(((Add)x).Target, ((Add)y).Target) && AreEqual(((Add)x).Value, ((Add)y).Value)); case "And": return (AreEqual(((And)x).Val1, ((And)y).Val1) && AreEqual(((And)x).Val2, ((And)y).Val2)); case "Call": return (((Call)x).Name == ((Call)y).Name); case "Comment": return (((Comment)x).Name == ((Comment)y).Name); case "Compare": return (AreEqual(((Compare)x).Val1, ((Compare)y).Val1) && AreEqual(((Compare)x).Val2, ((Compare)y).Val2)); case "Jump": return (((Jump)x).Name == ((Jump)y).Name); case "JumpE": return (((JumpE)x).Name == ((JumpE)y).Name); case "JumpG": return (((JumpG)x).Name == ((JumpG)y).Name); case "JumpGE": return (((JumpGE)x).Name == ((JumpGE)y).Name); case "JumpL": return (((JumpL)x).Name == ((JumpL)y).Name); case "JumpLE": return (((Jump)x).Name == ((JumpLE)y).Name); case "JumpNE": return (((JumpNE)x).Name == ((JumpNE)y).Name); case "Label": return (((Label)x).Method == ((Label)y).Method); case "Lea": return (AreEqual(((Lea)x).From, ((Lea)y).From) && AreEqual(((Lea)x).To, ((Lea)y).To)); case "Leave": return true; case "Move": return (AreEqual(((Move)x).From, ((Move)y).From) && AreEqual(((Move)x).To, ((Move)y).To)); case "Nope": return true; case "Or": return (AreEqual(((Or)x).Val1, ((Or)y).Val1) && AreEqual(((Or)x).Val2, ((Or)y).Val2)); case "Pop": return (AreEqual(((Pop)x).Target, ((Pop)y).Target)); case "Push": return (AreEqual(((Push)x).Target, ((Push)y).Target)); case "Ret": return true; case "Shl": return (AreEqual(((Shl)x).Target, ((Shl)y).Target) && AreEqual(((Shl)x).Value, ((Shl)y).Value)); case "Shr": return (AreEqual(((Shr)x).Target, ((Shr)y).Target) && AreEqual(((Shr)x).Value, ((Shr)y).Value)); case "Sub": return (AreEqual(((Sub)x).Target, ((Sub)y).Target) && AreEqual(((Sub)x).Value, ((Sub)y).Value)); case "Xchg": return (AreEqual(((Xchg)x).Val1, ((Xchg)y).Val1) && AreEqual(((Xchg)x).Val2, ((Xchg)y).Val2)); case "Xor": return (AreEqual(((Xor)x).Val1, ((Xor)y).Val1) && AreEqual(((Xor)x).Val2, ((Xor)y).Val2)); default: return false; } }
/*private void SearchConstants(ASTNode ast) { foreach (ASTNode node in ast.GetChildren()) { switch (node.GetType()) { //case Global.ASTType.STRING: // w("define_constant_string:" + teller.ToString() + ":" + node.GetName()); // node.SetAssemblyLocation(teller); // teller++; break; } SearchConstants(node); } } private void SearchUnitialised(ASTNode ast) { } private void SearchInitialised(ASTNode ast) { bool waitForAssignment = false; foreach (ASTNode node in ast.GetChildren()) { if (waitForAssignment) { if (node.GetType() == Global.ASTType.ASSIGNMENT) { Symbol symbol = node.GetScope().lookup(node.GetExpression1().accept(this)); switch (symbol.GetType()) { } } waitForAssignment = false; } switch (node.GetType()) { case Global.ASTType.VAR_DECLARATION: if (node.GetScope().GetReference() == null) { waitForAssignment = true; } break; } if (!waitForAssignment) SearchInitialised(node); } } private void ExecuteFunctionCall(ASTNode node) { string name = node.GetName(); List<ASTNode> args = node.GetChildren(); Table scope = node.GetScope(); while (scope != null) { Symbol reference = scope.lookup(name); if (reference != null) //The identifier exists in the current scope { if (reference.GetType() == Global.DataType.BUILTIN_FUNC) //The function is builtin { switch (reference.GetName()) { case "print": ExecutePrint(node); break; } } } scope = scope.GetReference(); } } private void ExecutePrint(ASTNode node) { if (node.GetChildren()[0].GetType() == Global.ASTType.STRING) w("call:print,constant," + node.GetChildren()[0].AssemblyLocation); }*/ private void Add(Instruction item) { postfixList.Add(item); }