public override void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { string label = labelStack.NewLabel(); fourExpList.Add(FourExpFac.GenLabel(label)); statement.Translate(varTable, labelStack, fourExpList); string condition = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJne(condition, 0 + "", label)); }
public bool AddReachedLabel(Statement label) { List <DefiniteAssignmentBitSet> das; if (LabelStack == null) { LabelStack = new Dictionary <Statement, List <DefiniteAssignmentBitSet> > (); das = null; } else { LabelStack.TryGetValue(label, out das); } if (das == null) { das = new List <DefiniteAssignmentBitSet> (); das.Add(new DefiniteAssignmentBitSet(DefiniteAssignment)); LabelStack.Add(label, das); return(false); } foreach (var existing in das) { if (DefiniteAssignmentBitSet.AreEqual(existing, DefiniteAssignment)) { return(true); } } if (DefiniteAssignment == DefiniteAssignmentBitSet.Empty) { das.Add(DefiniteAssignment); } else { das.Add(new DefiniteAssignmentBitSet(DefiniteAssignment)); } return(false); }
public override void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { if (statement1 == null) { string label = labelStack.NewLabel(); string condition = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJe(condition, 0 + "", label)); statement1.Translate(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenLabel(label)); } else { string label1 = labelStack.NewLabel(); string label2 = labelStack.NewLabel(); string condition = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJe(condition, 0 + "", label1)); statement1.Translate(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJmp(label2)); fourExpList.Add(FourExpFac.GenLabel(label1)); statement2.Translate(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenLabel(label2)); } }
public override string GetValue(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { return(""); }
public override string GetValue(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { string returnValue = ""; string label, t1, t2, var; switch (this.op.Type) { case OperatorType.not: //非 label = labelStack.NewLabel(); var = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJe(var, 0 + "", label)); t1 = varTable.NewTemp(VariableType.BOOL); fourExpList.Add(FourExpFac.GenMov(1 + "", t1)); var = t1; fourExpList.Add(FourExpFac.GenLabel(label)); t2 = varTable.NewTemp(VariableType.BOOL); fourExpList.Add(FourExpFac.GenNot(t1, t2)); returnValue = t2; break; case OperatorType.selfaddhead: //自增前置 var = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenAdd(var, 1 + "", var)); returnValue = var; break; case OperatorType.selfsubhead: //自减前置 var = expression.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenSub(var, 1 + "", var)); returnValue = var; break; case OperatorType.selfaddtail: //自增后置 var = expression.GetValue(varTable, labelStack, fourExpList); t1 = varTable.NewTemp(var); fourExpList.Add(FourExpFac.GenAdd(var, 1 + "", var)); returnValue = t1; break; case OperatorType.selfsubtail: //自减后置 var = expression.GetValue(varTable, labelStack, fourExpList); t1 = varTable.NewTemp(var); fourExpList.Add(FourExpFac.GenSub(var, 1 + "", var)); returnValue = t1; break; case OperatorType.bitnot: //按位非 var = expression.GetValue(varTable, labelStack, fourExpList); t1 = varTable.NewTemp(var); fourExpList.Add(FourExpFac.GenNot(var, t1)); returnValue = t1; break; case OperatorType.neg: //取反 var = expression.GetValue(varTable, labelStack, fourExpList); t1 = varTable.NewTemp(var); fourExpList.Add(FourExpFac.GenNeg(var, t1)); returnValue = t1; break; } return(returnValue); }
public virtual void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { }
public override string GetValue(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { string returnValue = ""; //加、减、乘、除、按位与、按位或 if (this.op.Type == OperatorType.add || this.op.Type == OperatorType.sub || this.op.Type == OperatorType.mul || this.op.Type == OperatorType.div || this.op.Type == OperatorType.bitand || this.op.Type == OperatorType.bitor) { string arg1 = expression1.GetValue(varTable, labelStack, fourExpList); string arg2 = expression2.GetValue(varTable, labelStack, fourExpList); string t = varTable.NewTemp(arg1, arg2); switch (this.op.Type) { case OperatorType.add: //+ fourExpList.Add(FourExpFac.GenAdd(arg1, arg2, t)); break; case OperatorType.sub: //- fourExpList.Add(FourExpFac.GenSub(arg1, arg2, t)); break; case OperatorType.mul: //* fourExpList.Add(FourExpFac.GenMul(arg1, arg2, t)); break; case OperatorType.div: /// fourExpList.Add(FourExpFac.GenDiv(arg1, arg2, t)); break; case OperatorType.bitand: //按位与 fourExpList.Add(FourExpFac.GenAnd(arg1, arg2, t)); break; case OperatorType.bitor: //按位或 fourExpList.Add(FourExpFac.GenOr(arg1, arg2, t)); break; default: break; } returnValue = t; } //与、或 else if (this.op.Type == OperatorType.and || this.op.Type == OperatorType.or) { string label1 = labelStack.NewLabel(); string arg1 = expression1.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJe(arg1, 0 + "", label1)); string t1 = varTable.NewTemp(VariableType.BOOL); fourExpList.Add(FourExpFac.GenMov(1 + "", t1)); arg1 = t1; fourExpList.Add(FourExpFac.GenLabel(label1)); string label2 = labelStack.NewLabel(); string arg2 = expression2.GetValue(varTable, labelStack, fourExpList); fourExpList.Add(FourExpFac.GenJe(arg2, 0 + "", label2)); string t2 = varTable.NewTemp(VariableType.BOOL); fourExpList.Add(FourExpFac.GenMov(1 + "", t2)); arg2 = t2; fourExpList.Add(FourExpFac.GenLabel(label2)); string t3 = varTable.NewTemp(VariableType.BOOL); switch (this.op.Type) { case OperatorType.and: //与 fourExpList.Add(FourExpFac.GenAnd(arg1, arg2, t3)); break; case OperatorType.or: //或 fourExpList.Add(FourExpFac.GenOr(arg1, arg2, t3)); break; } returnValue = t3; } //左移、右移 else if (this.op.Type == OperatorType.leftmove || this.op.Type == OperatorType.rightmove) { string arg1 = expression1.GetValue(varTable, labelStack, fourExpList); string arg2 = expression2.GetValue(varTable, labelStack, fourExpList); string t = varTable.NewTemp(arg1); switch (this.op.Type) { case OperatorType.leftmove: //左移 fourExpList.Add(FourExpFac.GenLeftshift(arg1, arg2, t)); break; case OperatorType.rightmove: //右移 fourExpList.Add(FourExpFac.GenRightshift(arg1, arg2, t)); break; default: break; } returnValue = t; } //小于、小于等于、大于、大于等于、等于、不等于 else if (this.op.Type == OperatorType.less || this.op.Type == OperatorType.lessequal || this.op.Type == OperatorType.greater || this.op.Type == OperatorType.greatereuqal || this.op.Type == OperatorType.equal || this.op.Type == OperatorType.notequal) { string label1 = labelStack.NewLabel(); string label2 = labelStack.NewLabel(); string t = varTable.NewTemp(VariableType.BOOL); string arg1 = expression1.GetValue(varTable, labelStack, fourExpList); string arg2 = expression2.GetValue(varTable, labelStack, fourExpList); switch (this.op.Type) { case OperatorType.less: //< fourExpList.Add(FourExpFac.GenJl(arg1, arg2, label1)); break; case OperatorType.lessequal: //<= fourExpList.Add(FourExpFac.GenJle(arg1, arg2, label1)); break; case OperatorType.greater: //> fourExpList.Add(FourExpFac.GenJg(arg1, arg2, label1)); break; case OperatorType.greatereuqal: //>= fourExpList.Add(FourExpFac.GenJge(arg1, arg2, label1)); break; case OperatorType.equal: //== fourExpList.Add(FourExpFac.GenJe(arg1, arg2, label1)); break; case OperatorType.notequal: //!= fourExpList.Add(FourExpFac.GenJne(arg1, arg2, label1)); break; default: // break; } fourExpList.Add(FourExpFac.GenMov(0 + "", t)); fourExpList.Add(FourExpFac.GenJmp(label2)); fourExpList.Add(FourExpFac.GenLabel(label1)); fourExpList.Add(FourExpFac.GenMov(1 + "", t)); fourExpList.Add(FourExpFac.GenLabel(label2)); returnValue = t; } else { //错误处理 } return(returnValue); }
public virtual string GetValue(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { return(""); }
public override void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { }
public override void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { string value = expression.GetValue(varTable, labelStack, fourExpList); varTable.SetValue(this.identify, value); }
public override void Translate(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { int value = 0; varTable.Add(this.name, this.type, value); }
public override string GetValue(VarTable varTable, LabelStack labelStack, List <FourExp> fourExpList) { return(this.value.ToString()); }
public Router(string filePath) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); RouterName = doc.SelectSingleNode("/Router/RouterName").InnerText; IP = IPAddress.Parse(doc.SelectSingleNode("/Router/IP").InnerText); logicIP = IPAddress.Parse(doc.SelectSingleNode("/Router/logIP").InnerText); recPort = Convert.ToInt32(doc.SelectSingleNode("/Router/RecPort").InnerText); cloudPort = Convert.ToInt32(doc.SelectSingleNode("/Router/CloudPort").InnerText); Receiver = new Socket((new IPEndPoint(IP, recPort)).AddressFamily, SocketType.Stream, ProtocolType.Tcp); //FILL TABLES FROM XML XmlNodeList FIBMPLS = doc.DocumentElement.SelectNodes("/Router/FIB-MPLS/Element"); foreach (XmlNode FIBRec in FIBMPLS) { IPAddress destIP = IPAddress.Parse(FIBRec["destIP"].InnerText); Simulation.Label label = new Simulation.Label(Convert.ToInt16(FIBRec["label"].InnerText)); FIBTableMPLS.Add(new FIBRecordMPLS(destIP, label)); } XmlNodeList FIBIP = doc.DocumentElement.SelectNodes("/Router/FIB-IP/Element"); foreach (XmlNode FIBRec in FIBIP) { IPAddress destIP = IPAddress.Parse(FIBRec["destIP"].InnerText); IPAddress outInt = IPAddress.Parse(FIBRec["outInt"].InnerText); FIBTableIP.Add(new FIBRecordIP(destIP, outInt)); } XmlNodeList ILM = doc.DocumentElement.SelectNodes("/Router/ILM/Element"); foreach (XmlNode ILMRec in ILM) { IPAddress intFrom = IPAddress.Parse(ILMRec["intFrom"].InnerText); Simulation.Label incLabel = new Simulation.Label(Convert.ToInt16(ILMRec["incLabel"].InnerText)); /*Simulation.Label poppedLabel = new Simulation.Label(Convert.ToInt16(ILMRec["poppedLabel"].InnerText)); * LabelStack poppedLabelStack = new LabelStack(); * poppedLabelStack.labels.Push(poppedLabel);*/ string[] poppedLabelsTab = ILMRec["poppedLabel"].InnerText .Replace(" ", "") .Split(','); LabelStack poppedLabelStack = new LabelStack(poppedLabelsTab); int nextOperationID = Convert.ToInt32(ILMRec["nextOperationID"].InnerText); ILMTable.Add(new ILMRecord(intFrom, incLabel, poppedLabelStack, nextOperationID)); } XmlNodeList FTN = doc.DocumentElement.SelectNodes("/Router/FTN/Element"); foreach (XmlNode FTNRec in FTN) { Simulation.Label fec = new Simulation.Label(Convert.ToInt16(FTNRec["FEC"].InnerText)); int nextOperationID = Convert.ToInt32(FTNRec["nextOperationID"].InnerText); FTNTable.Add(new FTNRecord(fec, nextOperationID)); } XmlNodeList NHLFE = doc.DocumentElement.SelectNodes("/Router/NHLFE/Element"); foreach (XmlNode NHLFERec in NHLFE) { int nextOperationID = Convert.ToInt32(NHLFERec["nextOperationID"].InnerText); //Operation operation = (Operation)Convert.ToByte(NHLFERec["operation"].InnerText); // nie jestem pewien czy tu int (operation to enum w NHLFE) Operation operation = (Operation)Enum.Parse(typeof(Operation), NHLFERec["operation"].InnerText); Simulation.Label outLabel = new Simulation.Label(Convert.ToInt16(NHLFERec["outLabel"].InnerText)); IPAddress outInt = IPAddress.Parse(NHLFERec["outInt"].InnerText); int nextOperation = Convert.ToInt32(NHLFERec["nextOperation"].InnerText); NHLFETable.Add(new NHLFERecord(nextOperationID, operation, outLabel, outInt, nextOperation)); } //Run listening Thread t = new Thread(Listen); t.Start(); }