private void ILDivMod(QuadTuple qt, string op) { ProcSegment.Add(" xor edx,edx"); var tplt1 = " mov eax,{0}"; if (qt.RValueA.ValueType == "addr") { ProcSegment.Add(string.Format(tplt1, "dword ptr " + qt.RValueA.ID)); } else { ProcSegment.Add(string.Format(tplt1, qt.RValueA.ID)); } var tplt2 = " mov ebx,{0}"; if (qt.RValueB.ValueType == "addr") { ProcSegment.Add(string.Format(tplt2, "dword ptr " + qt.RValueB.ID)); } else { ProcSegment.Add(string.Format(tplt2, qt.RValueB.ID)); } ProcSegment.Add(" idiv ebx"); var tplt3 = " mov {0},{1}"; var target = qt.LValue.ID; if (!LSymbols.ContainsKey(target) && !GSymbols.ContainsKey(target)) { ProcSegment.Insert(0, string.Format(" local {0}:dword", target)); LSymbols[target] = "int"; } ProcSegment.Add(string.Format(tplt3, target, op)); }
//calc & store the addr of the element private void ILArrayAccess(QuadTuple qt) { var tplt1 = " mov eax,{0}"; ProcSegment.Add(string.Format(tplt1, qt.RValueB.ID)); if (qt.LValue.ValueType == "int" || qt.LValue.ValueType == "addr") { ProcSegment.Add(string.Format(" imul eax,eax,{0}", 4)); } var arrName = qt.RValueA.ID; ProcSegment.Add(string.Format(" lea ebx,{0}", arrName)); ProcSegment.Add(" mov eax,[eax][ebx]"); var tplt2 = " mov {0},eax"; var target = qt.LValue.ID; if (!LSymbols.ContainsKey(target) && !GSymbols.ContainsKey(target)) { if (qt.LValue.ValueType == "int" || qt.LValue.ValueType == "addr") { LSymbols[target] = "int"; ProcSegment.Insert(0, string.Format(" local {0}:dword", target)); } } ProcSegment.Add(string.Format(tplt2, target)); }
private void ILSimpleBinary(QuadTuple qt, string op) { var tplt1 = " mov eax,{0}"; if (qt.RValueA.ValueType == "addr") { ProcSegment.Add(string.Format(tplt1, "dword ptr " + qt.RValueA.ID)); } else { ProcSegment.Add(string.Format(tplt1, qt.RValueA.ID)); } var tplt2 = " {0} eax,{1}"; if (qt.RValueB.ValueType == "addr") { ProcSegment.Add(string.Format(tplt2, op, "dword ptr " + qt.RValueB.ID)); } else { ProcSegment.Add(string.Format(tplt2, op, qt.RValueB.ID)); } var tplt3 = " mov {0},eax"; var target = qt.LValue.ID; if (!LSymbols.ContainsKey(target) && !GSymbols.ContainsKey(target)) { ProcSegment.Insert(0, string.Format(" local {0}:dword", target)); LSymbols[target] = "int"; } ProcSegment.Add(string.Format(tplt3, target)); }
private void ILCall(QuadTuple qt) { var tplt = " invoke {0}"; if (qt.RValueA.ID == "scanf" || qt.RValueA.ID == "printf") { ProcSegment.Add(string.Format(tplt, "crt_" + qt.RValueA.ID)); } else { ProcSegment.Add(string.Format(tplt, qt.RValueA.ID)); } if (PushQueue is not null) { foreach (var i in PushQueue) { ProcSegment[ProcSegment.Count - 1] += i; } PushQueue = null; } if (qt.LValue is not null) { var ret = qt.LValue.ID; if (!LSymbols.ContainsKey(ret) && !GSymbols.ContainsKey(ret)) { ProcSegment.Insert(0, string.Format(" local {0}:dword", ret)); LSymbols[ret] = "int"; } var tplt4 = " mov {0},eax"; ProcSegment.Add(string.Format(tplt4, ret)); } }
private void ILAssign(QuadTuple qt) { var tplt1 = " mov eax,{0}"; if (qt.RValueA.ValueType == "addr") { ProcSegment.Add(string.Format(tplt1, "dword ptr " + qt.RValueA.ID)); } else { ProcSegment.Add(string.Format(tplt1, qt.RValueA.ID)); } var target = qt.LValue.ID; if (!LSymbols.ContainsKey(target) && !GSymbols.ContainsKey(target)) { ProcSegment.Insert(0, string.Format(" local {0}:dword", target)); LSymbols[target] = "int"; } if (qt.LValue.ValueType == "addr") { var tplt3 = " mov ebx,{0}"; ProcSegment.Add(string.Format(tplt3, qt.LValue.ID)); ProcSegment.Add(" mov [ebx],eax"); } else { var tplt2 = " mov {0},eax"; ProcSegment.Add(string.Format(tplt2, target)); } }
private void ILLoadAddress(QuadTuple qt) { var tplt1 = " lea eax,{0}"; ProcSegment.Add(string.Format(tplt1, qt.RValueA.ID)); if (qt.RValueB is not null) { var tplt3 = " mov ebx,{0}"; ProcSegment.Add(string.Format(tplt3, qt.RValueB.ID)); ProcSegment.Add(" imul ebx,ebx,4"); ProcSegment.Add(" add eax,ebx"); } var tplt2 = " mov {0},eax"; var target = qt.LValue.ID; if (!LSymbols.ContainsKey(target) && !GSymbols.ContainsKey(target)) { LSymbols[target] = "addr"; ProcSegment.Insert(0, string.Format(" local {0}:dword", target)); } ProcSegment.Add(string.Format(tplt2, target)); }