private void EmitOpCodeRet() { LLVM.Type retTy = _method.Function.GetReturnType(); if (retTy.Equals(CLR.Void)) { Trace.Assert(_stack.Count == 0); _builder.CreateRetVoid(); } else { // TODO.FIXME must deref return Value Trace.Assert(_stack.Count >= 1); LLVM.Value ret = _stack.Pop(); _builder.CreateRet(ConvertToType(ret, retTy)); } }
private void EmitOpCodeCall(MethodReference method) { Trace.Assert(method != null); List <LLVM.Type> argsTy = new List <LLVM.Type>(); if (method.HasThis) { argsTy.Add(Cil2Llvm.GetType(method.DeclaringType).GetPointerTo()); } if (method.HasParameters) { foreach (ParameterDefinition p in method.Parameters) { argsTy.Add(Cil2Llvm.GetType(p.ParameterType)); } } Trace.Assert(_stack.Count >= argsTy.Count); LLVM.Value[] args = new LLVM.Value[argsTy.Count]; for (int i = argsTy.Count - 1; i >= 0; i--) { args[i] = ConvertToType(_stack.Pop(), argsTy[i]); } LLVM.Value ret = _builder.CreateCall(Cil2Llvm.GetMethod(method), args); LLVM.Type retTy = Cil2Llvm.GetType(method.ReturnType); if (!retTy.Equals(CLR.Void)) { _stack.Push(ret); } /* * // Cast to object type, call ctor and push on the stack * // * convertValue(newobj, PointerType::get(ClassTy, 0), bb); * callMethod(newobj, token, bb); * _Stack.push_back(newobj); */ }