public GetValByAdress(IOperation adress, ValueType retType) { operationString = "get"; a = adress; try { variable = ASTTree.variables[(int)((adress as ASTvalue).getValue)]; operationString = variable.name; returnType = variable.returnTypes(); from = variable; return; } catch (Exception e) { variable = null; try { adder = (a as BinarySummatic).FindNonVariable(out from); } catch (Exception E) { // case if you have only *d, but not d[0], so there is no summ action in there from = adress; adder = new ASTvalue(new ValueType(VT.Cint), (object)0); } returnType = retType.TypeOfPointedByThis(); }; }
public override string ToLLVM(int depth) { string res = var.ToLLVM(); if (var.adress.typ != VAT.Global) { LLVM.AddToCode(String.Format("{0}{1} = alloca {2}\n", MISC.tabsLLVM(depth), res, var.returnTypes().ToLLVM())); } return(res); // %X = alloca i32 ; we have a pointer for %X, we like writing int*X = new int(); or some shit like it // now we can store i32 100, i32* %X }
public override string ToLLVM(int depth) { ASTvariable vari = null; if (a as GetValByAdress != null) { vari = ((a as GetValByAdress).from as ASTvariable); } if (a as Define != null) { vari = (a as Define).var; } if (vari != null && vari.everUsed > 0 && vari.adress.typ != VAT.Global)// && !vari.wasLoaded) { LLVM.varisReload.Add(vari); vari.reloadedTimes++; LLVM.CommandOrderQueueCode += String.Format("{0}{1} = load {2}, {3} {4}\n", MISC.tabsLLVM(depth), vari.ToLLVM(), vari.returnTypes().ToLLVM(), vari.returnTypes().TypeOfPointerToThis().ToLLVM(), MISC.RemoveCall(vari.ToLLVM())); vari.reloadedTimes--; } if (a as GetValByAdress != null) { // variable? from ASTvariable vari2 = ((a as GetValByAdress).from as ASTvariable); // NOT случай, когда переменная просто проходная- не глобальная, не параметр, и обращение идет прямо на неё if (!(vari2 != null /* && !vari.everPointed*/ && vari2.adress.typ != VAT.Parameter)) { (a as GetValByAdress).LLVM_isLeftOperand = true; string number = b.ToLLVM(depth), add_last = a.ToLLVM(depth); LLVM.AddToCode(b.returnTypes().ToLLVM() + " " + number + "," + add_last); return(""); } } if (!(vari != null && vari.adress.typ == VAT.Global)) { return(String.Format("{0}store {3} {4}, {1} {2}", MISC.tabsLLVM(depth), a.returnTypes().TypeOfPointerToThis().ToLLVM(), MISC.RemoveCall(a.ToLLVM(depth)), b.returnTypes().ToLLVM(), b.ToLLVM(depth))); } return(""); }