public static void LoadIfPointer(ref LLVMValueRef pValue, Emitting.EmittingContext pContext) { if (IsPointer(pValue)) { pValue = LLVM.BuildLoad(pContext.Builder, pValue, ""); } }
public void Emit(Emitting.EmittingContext pContext) { EmitReferencedNodes(pContext); pContext.Cache = Cache; pContext.Locals.AddScope(); //Emit our function that the runtime will call. //This will just call the method marked with "@run" //The reason we do this is so we have a static method name we can call var main = pContext.EmitMethodHeader("_main", LLVMTypeRef.Int32Type(), new LLVMTypeRef[] { }); var mainB = main.AppendBasicBlock(""); LLVMValueRef _main = Module.Emit(pContext); LLVM.PositionBuilderAtEnd(pContext.Builder, mainB); LLVM.BuildCall(pContext.Builder, _main, new LLVMValueRef[] { }, ""); LLVM.BuildRet(pContext.Builder, pContext.GetInt(0)); pContext.ValidateMethod(main); pContext.Locals.RemoveScope(); }
private void EmitReferencedNodes(Emitting.EmittingContext pContext) { var mrv = new ModuleReferenceVisitor(Cache, pContext); mrv.Visit(Module); //Emit types. Need to do it in order of dependencies so all types resolve foreach (var i in mrv.TypeNodes.OrderBy((pS) => ((TypeDefinitionSyntax)pS.Node).EmitOrder)) { pContext.Cache = i.Unit; i.Node.Emit(pContext); } //Emit type methods headers foreach (var m in mrv.MethodNodes) { pContext.Cache = m.Unit; ((MethodSyntax)m.Node).EmitHeader(pContext); } foreach (var s in mrv.TypeNodes) { pContext.Cache = s.Unit; ((TypeDefinitionSyntax)s.Node).EmitMethodHeaders(pContext); } //Emit type methods foreach (var m in mrv.MethodNodes) { pContext.Cache = m.Unit; ((MethodSyntax)m.Node).Emit(pContext); } foreach (var s in mrv.TypeNodes) { pContext.Cache = s.Unit; ((TypeDefinitionSyntax)s.Node).EmitMethods(pContext); } }