9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
{
void SetupRuntimeBasicTypes( Env& e )
{
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_half ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTHalf() ) ) );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_float ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTFloat() ) ) );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTDouble() ) ) );
RegisterBuiltinFunc< Eager< Value > ( uint64_t ) >( e, "RTInteger"_sid,
[]( uint64_t numBits )
{
return ToValue( RTInteger( numBits ) );
} );
}
}
namespace empathy::ir
{
//// Half
Value Bridge< RTHalf >::ToValue( const RTHalf& i )
|
|
>
>
>
>
>
>
|
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
|
{
void SetupRuntimeBasicTypes( Env& e )
{
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_half ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTHalf() ) ) );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_float ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTFloat() ) ) );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), ValueToIRExpr( ToValue( RTDouble() ) ) );
RegisterBuiltinFunc< Eager< Value > ( uint64_t ) >( e, "RTUInt"_sid,
[]( uint64_t numBits )
{
return ToValue( RTInteger( numBits ) );
} );
RegisterBuiltinFunc< Eager< Value > ( uint64_t ) >( e, "RTSInt"_sid,
[]( uint64_t numBits )
{
return ToValue( RTInteger( numBits, true ) );
} );
}
}
namespace empathy::ir
{
//// Half
Value Bridge< RTHalf >::ToValue( const RTHalf& i )
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
}
//// Integer
Value Bridge< RTInteger >::ToValue( const RTInteger& i )
{
return Value( Type(), TVEC( TSID( rt_type ),
TERM( llvm::IntegerType::get( GetLLVMContext(), i.m_numBits ) ),
TSID( rt_integer ), TERM( i.m_numBits ) ) );
}
optional< RTInteger > Bridge< RTInteger >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
Val< void* >(),
Lit( "rt_integer"_sid ),
Val< uint64_t >()
)
);
if( !result )
return nullopt;
auto&& [llvmType, numBits] = *result;
return RTInteger( numBits );
}
}
|
|
>
|
|
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
}
//// Integer
Value Bridge< RTInteger >::ToValue( const RTInteger& i )
{
return Value( Type(), TVEC( TSID( rt_type ),
TERM( llvm::IntegerType::get( GetLLVMContext(), i.m_numBits ) ),
TSID( rt_integer ), TERM( i.m_numBits ), i.m_signed ? TERM( 1ULL ) : TERM( 0ULL ) ) );
}
optional< RTInteger > Bridge< RTInteger >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_type"_sid ),
Val< void* >(),
Lit( "rt_integer"_sid ),
Val< uint64_t >(),
Val< uint64_t >()
)
);
if( !result )
return nullopt;
auto&& [llvmType, numBits, signd] = *result;
return RTInteger( numBits, !!signd );
}
}
|