Ejemplo n.º 1
0
Ir::Intf::Function* IrFunctionRepository::GetMemCopyFunction()
{
    if (!memCopyFunction)
    {
        Ir::Intf::Type* i8Ptr = Cm::IrIntf::Pointer(Ir::Intf::GetFactory()->GetI8(), 1);
        Own(i8Ptr);
        memCopyFunction.reset(Cm::IrIntf::CreateMemCopyFunction(i8Ptr));
    }
    return memCopyFunction.get();
}
Ejemplo n.º 2
0
Ir::Intf::Object* IrFunctionRepository::GetFunctionId(Cm::Sym::FunctionSymbol* function, Cm::Sym::TypeSymbol* functionPtrPtrType)
{
    FunctionIdMapIt i = functionIdMap.find(function);
    if (i != functionIdMap.end())
    {
        return i->second;
    }
    std::string functionIdName = Cm::Sym::MangleName(function->Ns()->FullName(), function->GroupName(), function->TypeArguments(), function->Parameters());
    Ir::Intf::Object* functionId = Cm::IrIntf::CreateGlobal(functionIdName, functionPtrPtrType->GetIrType());
    functionIdMap[function] = functionId;
    Own(functionId);
    return functionId;
}
Ejemplo n.º 3
0
Ir::Intf::Type* IrFunctionRepository::CreateIrPointerToDelegateType(Cm::Sym::DelegateTypeSymbol* delegateType)
{
    Cm::Sym::TypeSymbol* returnType = delegateType->GetReturnType();
    Ir::Intf::Type* irReturnType = returnType->GetIrType()->Clone();
    std::vector<Ir::Intf::Type*> irParameterTypes;
    for (Cm::Sym::ParameterSymbol* parameter : delegateType->Parameters())
    {
        Cm::Sym::TypeSymbol* parameterType = parameter->GetType();
        Ir::Intf::Type* irParameterType = parameterType->GetIrType()->Clone();
        irParameterTypes.push_back(irParameterType);
    }
    if (!delegateType->IsNothrow())
    {
        Ir::Intf::Type* exceptionCodeParamType = Cm::IrIntf::Pointer(Ir::Intf::GetFactory()->GetI32(), 1);
        irParameterTypes.push_back(exceptionCodeParamType);
    }
    Ir::Intf::Type* irFunctionType = Cm::IrIntf::CreateFunctionType(irReturnType, irParameterTypes);
    Own(irFunctionType);
    Ir::Intf::Type* delegatePointerType = Cm::IrIntf::Pointer(irFunctionType, 2);
    Own(delegatePointerType);
    return delegatePointerType;
}
Ejemplo n.º 4
0
Ir::Intf::Function* IrFunctionRepository::CreateIrFunction(Cm::Sym::FunctionSymbol* function)
{
    IrFunctionMapIt i = irFunctionMap.find(function);
    if (i != irFunctionMap.end())
    {
        Ir::Intf::Function* irFun = i->second;
        return irFun;
    }
    std::string functionName;
    std::string functionGroupName;
    Ir::Intf::Type* irReturnType = nullptr;
    std::vector<Ir::Intf::Parameter*> irParameters;
    std::vector<Ir::Intf::Type*> irParameterTypes;
    if (function->IsStaticConstructor())
    {
        functionName = "__sc_" + function->Class()->GetMangleId();
        irReturnType = Cm::IrIntf::Void();
        if (function->CanThrow())
        {
            Ir::Intf::Type* exceptionCodeParamType = Cm::IrIntf::Pointer(Ir::Intf::GetFactory()->GetI32(), 1);
            Own(exceptionCodeParamType);
            exceptionCodeParam = Cm::IrIntf::CreateParameter(Cm::IrIntf::GetExceptionCodeParamName(), exceptionCodeParamType);
            Own(exceptionCodeParam);
            irParameters.push_back(exceptionCodeParam);
            irParameterTypes.push_back(exceptionCodeParamType->Clone());
        }
        Own(irReturnType);
    }
    else
    {
        bool returnsClassOrInterfaceObjectByValue = function->ReturnsClassOrInterfaceObjectByValue();
        if (!returnsClassOrInterfaceObjectByValue)
        {
            Cm::Sym::TypeSymbol* returnType = function->GetReturnType();
            if (returnType)
            {
                irReturnType = returnType->GetIrType();
            }
        }
        if (!irReturnType)
        {
            irReturnType = Cm::IrIntf::Void();
            Own(irReturnType);
        }
        for (Cm::Sym::ParameterSymbol* parameter : function->Parameters())
        {
            Ir::Intf::Parameter* irParameter = CreateIrParameter(parameter);
            Own(irParameter);
            irParameters.push_back(irParameter);
            irParameterTypes.push_back(irParameter->GetType()->Clone());
        }
        if (returnsClassOrInterfaceObjectByValue)
        {
            if (!function->GetReturnType()->IrTypeMade())
            {
                function->GetReturnType()->MakeIrType();
            }
            Ir::Intf::Type* classOrInterfaceObjectResultParamType = Cm::IrIntf::Pointer(function->GetReturnType()->GetIrType(), 1);
            Own(classOrInterfaceObjectResultParamType);
            Ir::Intf::Parameter* irClassOrInterfaceObjectParameter = Cm::IrIntf::CreateParameter(Cm::IrIntf::GetClassObjectResultParamName(), classOrInterfaceObjectResultParamType);
            Own(irClassOrInterfaceObjectParameter);
            irParameters.push_back(irClassOrInterfaceObjectParameter);
            irParameterTypes.push_back(classOrInterfaceObjectResultParamType->Clone());
            function->SetClassOrInterfaceObjectResultIrParam(irClassOrInterfaceObjectParameter);
        }
        if (function->CanThrow())
        {
            Ir::Intf::Type* exceptionCodeParamType = Cm::IrIntf::Pointer(Ir::Intf::GetFactory()->GetI32(), 1);
            Own(exceptionCodeParamType);
            exceptionCodeParam = Cm::IrIntf::CreateParameter(Cm::IrIntf::GetExceptionCodeParamName(), exceptionCodeParamType);
            Own(exceptionCodeParam);
            irParameters.push_back(exceptionCodeParam);
            irParameterTypes.push_back(exceptionCodeParamType->Clone());
        }
        functionGroupName = function->GroupName();
        if (!Cm::Sym::GetGlobalFlag(Cm::Sym::GlobalFlags::unit_test))
        {
            if (functionGroupName.empty())
            {
                functionGroupName = "main";
            }
            else if (functionGroupName == "main")
            {
                functionGroupName = "user" + Cm::IrIntf::GetPrivateSeparator() + "main";
            }
        }
        functionName = functionGroupName;
    }
    if (!function->IsCDecl() && !function->IsStaticConstructor())
    {
        if (function->IsConversionFunction())
        {
            functionName = Cm::Sym::MangleName(function->Ns()->FullName(), "cv_" + Cm::Sym::MakeAssemblyName(function->GetReturnType()->FullName()), function->TypeArguments(), function->Parameters());
        }
        else if (function->IsStatic())
        {
            functionName = Cm::Sym::MangleName(function->Class()->FullName(), functionGroupName, function->TypeArguments(), function->Parameters());
        }
        else
        {
            functionName = Cm::Sym::MangleName(function->Ns()->FullName(), functionGroupName, function->TypeArguments(), function->Parameters());
        }
    }
    Ir::Intf::Function* irFunction = Cm::IrIntf::CreateFunction(functionName, irReturnType, irParameters);
    ownedIrFunctions.push_back(std::unique_ptr<Ir::Intf::Function>(irFunction));
    Ir::Intf::Type* irFunPtrType = Cm::IrIntf::Pointer(Cm::IrIntf::CreateFunctionType(irReturnType->Clone(), irParameterTypes), 1);
    ownedIrTypes.push_back(std::unique_ptr<Ir::Intf::Type>(irFunPtrType));
    irFunPtrType->SetOwned();
    irFunPtrMap[function] = irFunPtrType;
    irFunctionMap[function] = irFunction;
    return irFunction;
}
Ejemplo n.º 5
0
 static Own New(size_t index) { return Own(new T(index)); }