1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "builtins/builtins.h"
using namespace goose;
using namespace goose::builtins;
namespace goose::builtins
{
void SetupRuntimeArrayType( Env& e )
{
RegisterBuiltinFunc< Eager< Value > ( Value, uint32_t ) >( e, "array"_sid,
[]( const Value& containedType, uint32_t count )
{
if( !GetLLVMType( containedType ) )
{
DiagnosticsManager::GetInstance().emitErrorMessage( containedType.locationId(), "runtime arrays can only contain runtime types." );
return PoisonValue();
}
return ToValue( ArrayType( ValueToEIR( containedType ), count ) );
} );
}
llvm::Type* GetLLVMType( const ArrayType& a )
{
return llvm::ArrayType::get( GetLLVMType( *EIRToValue( a.m_containedType ) ), a.m_count );
}
}
namespace goose::eir
{
Value Bridge< ArrayType >::ToValue( const ArrayType& a )
{
return Value( Type(), MkStdRTType( TSID( rt_type ),
GetLLVMType( a ), TSID( array ),
TERM( a.m_count ), a.m_containedType ) );
}
optional< ArrayType > Bridge< ArrayType >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "array"_sid ),
Val< uint64_t >(),
SubTerm()
)
);
if( !result )
return nullopt;
auto&& [predicates, llvmType, count, containedType] = *result;
return ArrayType( containedType, count );
}
}
|
|
|
>
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#include "builtins/builtins.h"
using namespace goose;
using namespace goose::builtins;
namespace goose::builtins
{
void SetupRuntimeArrayType( Env& e )
{
RegisterBuiltinFunc< Eager< Value > ( Value, uint32_t ) >( e, "array"_sid,
[]( const Value& containedType, uint32_t count )
{
if( !GetCodegenType( containedType ) )
{
DiagnosticsManager::GetInstance().emitErrorMessage( containedType.locationId(), "runtime arrays can only contain runtime types." );
return PoisonValue();
}
return ToValue( ArrayType( ValueToEIR( containedType ), count ) );
} );
}
const codegen::Type* GetCodegenType( const ArrayType& a )
{
return codegen::Type::Get( llvm::ArrayType::get(
*GetCodegenType( *EIRToValue( a.m_containedType ) ), a.m_count ) );
}
}
namespace goose::eir
{
Value Bridge< ArrayType >::ToValue( const ArrayType& a )
{
return Value( Type(), MkStdRTType( TSID( rt_type ),
GetCodegenType( a ), TSID( array ),
TERM( a.m_count ), a.m_containedType ) );
}
optional< ArrayType > Bridge< ArrayType >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
SubTerm(),
Val< void* >(),
Lit( "array"_sid ),
Val< uint64_t >(),
SubTerm()
)
);
if( !result )
return nullopt;
auto&& [predicates, cgType, count, containedType] = *result;
return ArrayType( containedType, count );
}
}
|