public void Build(IVerifiableType inputType, IVerifiableType outputType, IVerifiableType contextType) { ImplementationInputType = inputType ?? throw new ArgumentNullException(nameof(inputType)); ImplementationOutputType = outputType ?? throw new ArgumentNullException(nameof(outputType)); ContextType = contextType ?? throw new ArgumentNullException(nameof(contextType)); MethodInputType = contextType ?? throw new ArgumentNullException(nameof(contextType)); var(outputMethod, outputMethodBuilder) = MethodType.Create(); outputMethodBuilder.Build(inputType, outputType); MethodOutputType = outputMethod; }
public ICodeBlock EmitMethod(IMethod Method, ICodeBlock Caller, Operator Op) { return(new DelegateBlock(this, Method, (CodeBlock)Caller, Op, MethodType.Create(Method))); }
/// <summary> /// Auto-implements this method. /// </summary> private IStatement AutoImplement() { var delegateAttribute = ParentType.GetAttribute( MethodType.DelegateAttributeType) as IntrinsicAttribute; string methodName = PreMangledName.Unmangle(Name).ToString(); var parameters = this.GetParameters(); if (delegateAttribute != null && delegateAttribute.Arguments[0].GetValue <string>() == methodName) { // Implement this method using a simple invocation expression. var args = new IExpression[parameters.Length]; for (int i = 0; i < args.Length; i++) { args[i] = new ArgumentVariable(parameters[i], i).CreateGetExpression(); } return(new ReturnStatement( new InvocationExpression( new ReinterpretCastExpression( new ThisVariable(DeclaringType).CreateGetExpression(), MethodType.Create(this)), args))); } else if (methodName == "LoadDelegateHasContextInternal" && IsStatic && ReturnType == PrimitiveTypes.Boolean && parameters.Length == 1) { return(new ReturnStatement( LLVMCodeGenerator.ToExpression( new UnaryBlock( codeGenerator, (CodeBlock) new ArgumentVariable(parameters[0], 0) .CreateGetExpression() .Emit(codeGenerator), PrimitiveTypes.Boolean, DelegateBlock.BuildLoadHasContext)))); } else if (methodName == "LoadDelegateFunctionPointerInternal" && IsStatic && ReturnType.GetIsPointer() && parameters.Length == 1) { return(new ReturnStatement( LLVMCodeGenerator.ToExpression( new UnaryBlock( codeGenerator, (CodeBlock) new ArgumentVariable(parameters[0], 0) .CreateGetExpression() .Emit(codeGenerator), ReturnType, DelegateBlock.BuildLoadFunctionPointer)))); } else if (methodName == "CompareExchange" && IsStatic && parameters.Length == 3) { return(new ReturnStatement( LLVMCodeGenerator.ToExpression( new CompareExchangeBlock( (CodeBlock) new ArgumentVariable(parameters[0], 0) .CreateGetExpression() .Emit(codeGenerator), (CodeBlock) new ArgumentVariable(parameters[1], 1) .CreateGetExpression() .Emit(codeGenerator), (CodeBlock) new ArgumentVariable(parameters[2], 2) .CreateGetExpression() .Emit(codeGenerator), codeGenerator)))); } else if (methodName.StartsWith("AtomicRMW") && IsStatic && parameters.Length == 2) { return(new ReturnStatement( LLVMCodeGenerator.ToExpression( new ReadModifyWriteBlock( (CodeBlock) new ArgumentVariable(parameters[0], 0) .CreateGetExpression() .Emit(codeGenerator), (CodeBlock) new ArgumentVariable(parameters[1], 1) .CreateGetExpression() .Emit(codeGenerator), ReadModifyWriteBlock.ParseOperator( methodName.Substring("AtomicRMW".Length)), codeGenerator)))); } else { throw new NotSupportedException( "Runtime doesn't know how to implement method '" + this.FullName.ToString() + "'."); } }
static IntrinsicValue() { // Signature: void* __cxa_allocate_exception(size_t thrown_size) throw() CxaAllocateExceptionSignature = new DescribedMethod( "__cxa_allocate_exception", null, PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer), true); CxaAllocateExceptionSignature.AddParameter( new DescribedParameter("thrown_size", PrimitiveTypes.UInt64)); CxaAllocateException = new IntrinsicValue( MethodType.Create(CxaAllocateExceptionSignature), DeclareCxaAllocateException); // Signature: void __cxa_throw(void* thrown_object, std::type_info* tinfo, void (*dest)(void*)) CxaThrowSignature = new DescribedMethod( "__cxa_throw", null, PrimitiveTypes.Void, true); CxaThrowSignature.AddParameter( new DescribedParameter( "thrown_object", PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer))); CxaThrowSignature.AddParameter( new DescribedParameter( "tinfo", PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer))); CxaThrowSignature.AddParameter( new DescribedParameter( "dest", PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer))); CxaThrow = new IntrinsicValue( MethodType.Create(CxaThrowSignature), DeclareCxaThrow); // Signature: void __cxa_rethrow() CxaRethrowSignature = new DescribedMethod( "__cxa_rethrow", null, PrimitiveTypes.Void, true); CxaRethrow = new IntrinsicValue( MethodType.Create(CxaRethrowSignature), DeclareCxaRethrow); // Signature: void* __cxa_begin_catch(void* exception_obj) CxaBeginCatchSignature = new DescribedMethod( "__cxa_begin_catch", null, PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer), true); CxaBeginCatchSignature.AddParameter( new DescribedParameter( "exception_obj", PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer))); CxaBeginCatch = new IntrinsicValue( MethodType.Create(CxaBeginCatchSignature), DeclareCxaBeginCatch); // Signature: void __cxa_end_catch() CxaEndCatchSignature = new DescribedMethod( "__cxa_end_catch", null, PrimitiveTypes.Void, true); CxaEndCatch = new IntrinsicValue( MethodType.Create(CxaEndCatchSignature), DeclareCxaEndCatch); // Signature: declare i32 @__gxx_personality_v0(...) GxxPersonalityV0 = new IntrinsicValue( PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer), DeclareGxxPersonalityV0); // Signature: @_ZTIPv = external constant i8* CxaVoidPointerRtti = new IntrinsicValue( PrimitiveTypes.Void.MakePointerType(PointerKind.TransientPointer), DeclareCxaVoidPointerRtti); }