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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include "builtins/builtins.h"
using namespace empathy;
using namespace empathy::builtins;
namespace empathy::builtins
{
void SetupRuntimeBasicTypes( Env& e )
{
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_half ) ), ANYTERM( _ ), GetValueType< RTHalf >() );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_float ) ), ANYTERM( _ ), GetValueType< RTFloat >() );
e.storeValue( AppendToVectorTerm( RootIdentity(), TSID( rt_double ) ), ANYTERM( _ ), GetValueType< RTDouble >() );
RegisterBuiltinFunc< Value ( uint64_t ) >( e, "RTInteger"_sid,
[]( uint64_t numBits )
{
return ToValue( RTInteger( numBits ) );
} );
}
}
namespace empathy::ir
{
//// Half
const Term& Bridge< RTHalf >::Type()
{
static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_half ) ) );
return type;
}
const Value& Bridge< RTHalf >::TypeVal()
{
static auto type = Value( TypeType(), TSID( rt_half ) );
return type;
}
//// Float
const Term& Bridge< RTFloat >::Type()
{
static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_float ) ) );
return type;
}
const Value& Bridge< RTFloat >::TypeVal()
{
static auto type = Value( TypeType(), TSID( rt_float ) );
return type;
}
//// Double
const Term& Bridge< RTDouble >::Type()
{
static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_double ) ) );
return type;
}
const Value& Bridge< RTDouble >::TypeVal()
{
static auto type = Value( TypeType(), TSID( rt_double ) );
return type;
}
//// Integer
const Term& Bridge< RTInteger >::Type()
{
static auto type = ValueToIRExpr( Value( TypeType(), TSID( rt_integer ) ) );
return type;
}
Value Bridge< RTInteger >::ToValue( const RTInteger& i )
{
return Value( Type(), TERM( i.m_numBits ) );
}
optional< RTInteger > Bridge< RTInteger >::FromValue( const Value& v )
{
auto typeVal = ValueFromIRExpr( v.type() );
auto result = Decompose( typeVal->val(),
Vec(
Lit( "decl"_sid ),
Val< uint64_t >()
)
);
if( !result )
return nullopt;
|
|
|
|
|
|
<
|
>
>
|
|
|
|
<
|
|
>
>
|
|
|
<
|
|
>
>
|
<
<
<
<
<
<
|
<
|
|
|
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include "builtins/builtins.h"
using namespace empathy;
using namespace empathy::builtins;
namespace empathy::builtins
{
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< Value ( uint64_t ) >( e, "RTInteger"_sid,
[]( uint64_t numBits )
{
return ToValue( RTInteger( numBits ) );
} );
}
}
namespace empathy::ir
{
//// Half
Value Bridge< RTHalf >::ToValue( const RTHalf& i )
{
return Value( Type(), TSID( rt_half ) );
}
optional< RTHalf > Bridge< RTHalf >::FromValue( const Value& v )
{
if( !v.isType() || v.val() != TSID( rt_half ) )
return nullopt;
return {};
}
//// Float
Value Bridge< RTFloat >::ToValue( const RTFloat& i )
{
return Value( Type(), TSID( rt_float ) );
}
optional< RTFloat > Bridge< RTFloat >::FromValue( const Value& v )
{
if( !v.isType() || v.val() != TSID( rt_float ) )
return nullopt;
return {};
}
//// Double
Value Bridge< RTDouble >::ToValue( const RTDouble& i )
{
return Value( Type(), TSID( rt_double ) );
}
optional< RTDouble > Bridge< RTDouble >::FromValue( const Value& v )
{
if( !v.isType() || v.val() != TSID( rt_double ) )
return nullopt;
return {};
}
//// Integer
Value Bridge< RTInteger >::ToValue( const RTInteger& i )
{
return Value( Type(), TVEC( TSID( rt_integer ), TERM( i.m_numBits ) ) );
}
optional< RTInteger > Bridge< RTInteger >::FromValue( const Value& v )
{
auto result = Decompose( v.val(),
Vec(
Lit( "rt_integer"_sid ),
Val< uint64_t >()
)
);
if( !result )
return nullopt;
|