Skip to content

Commit ab7573c

Browse files
committed
chore: code cleanup
Remove extraneous headers Make consistent ordering of load, store etc. Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent 230d681 commit ab7573c

9 files changed

Lines changed: 85 additions & 105 deletions

File tree

include/cmcpp/context.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
#include "traits.hpp"
55

6-
#include <functional>
7-
#include <memory>
8-
#include <optional>
96
#include <future>
107
#if __has_include(<span>)
118
#include <span>

include/cmcpp/float.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "context.hpp"
55
#include "integer.hpp"
66

7-
#include <cmath>
8-
97
namespace cmcpp
108
{
119
namespace float_

include/cmcpp/func.hpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,38 @@ namespace cmcpp
4949
// return unpack_flags_from_int<T>(i);
5050
// }
5151

52-
enum class ContextType
53-
{
54-
Lift,
55-
Lower
56-
};
52+
// enum class ContextType
53+
// {
54+
// Lift,
55+
// Lower
56+
// };
5757

58-
template <Func T>
59-
inline core_func_t flatten(LiftLowerContext &cx, ContextType context)
60-
{
61-
std::vector<WasmValType> flat_params(ValTrait<T>::flat_params_types.begin(), ValTrait<T>::flat_params_types.end());
62-
std::vector<WasmValType> flat_results(ValTrait<T>::flat_result_types.begin(), ValTrait<T>::flat_result_types.end());
63-
// if (cx.opts.sync == true)
64-
{
65-
if (flat_params.size() > MAX_FLAT_PARAMS)
66-
{
67-
flat_params = {WasmValType::i32};
68-
}
69-
if (flat_results.size() > MAX_FLAT_RESULTS)
70-
{
71-
switch (context)
72-
{
73-
case ContextType::Lift:
74-
flat_results = {WasmValType::i32};
75-
break;
76-
case ContextType::Lower:
77-
flat_params.push_back(WasmValType::i32);
78-
flat_results = {};
79-
}
80-
}
81-
}
82-
return {flat_params, flat_results};
83-
}
58+
// template <Func T>
59+
// inline core_func_t flatten(LiftLowerContext &cx, ContextType context)
60+
// {
61+
// std::vector<WasmValType> flat_params(ValTrait<T>::flat_params_types.begin(), ValTrait<T>::flat_params_types.end());
62+
// std::vector<WasmValType> flat_results(ValTrait<T>::flat_result_types.begin(), ValTrait<T>::flat_result_types.end());
63+
// // if (cx.opts.sync == true)
64+
// {
65+
// if (flat_params.size() > MAX_FLAT_PARAMS)
66+
// {
67+
// flat_params = {WasmValType::i32};
68+
// }
69+
// if (flat_results.size() > MAX_FLAT_RESULTS)
70+
// {
71+
// switch (context)
72+
// {
73+
// case ContextType::Lift:
74+
// flat_results = {WasmValType::i32};
75+
// break;
76+
// case ContextType::Lower:
77+
// flat_params.push_back(WasmValType::i32);
78+
// flat_results = {};
79+
// }
80+
// }
81+
// }
82+
// return {flat_params, flat_results};
83+
// }
8484

8585
// template <Flags T>
8686
// inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)

include/cmcpp/integer.hpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#include "context.hpp"
55
#include "util.hpp"
66

7-
#include <cstring>
8-
#include <iostream>
9-
#include <cassert>
10-
117
namespace cmcpp
128
{
139
namespace integer
@@ -53,35 +49,43 @@ namespace cmcpp
5349
}
5450
}
5551

52+
// Boolean ------------------------------------------------------------------
5653
template <Boolean T>
5754
inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)
5855
{
5956
integer::store<T>(cx, v, ptr);
6057
}
58+
template <Boolean T>
59+
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
60+
{
61+
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
62+
return {static_cast<WasmValType>(v)};
63+
}
6164

62-
template <Char T>
63-
inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)
65+
template <Boolean T>
66+
inline T load(const LiftLowerContext &cx, uint32_t ptr)
6467
{
65-
integer::store<T>(cx, char_to_i32(cx, v), ptr);
68+
return convert_int_to_bool(integer::load<uint8_t>(cx, ptr));
6669
}
6770

68-
template <Integer T>
69-
inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)
71+
template <Boolean T>
72+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
7073
{
71-
integer::store<T>(cx, v, ptr);
74+
return convert_int_to_bool(vi.next<int32_t>());
7275
}
7376

74-
template <SignedInteger T>
75-
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
77+
// Char ------------------------------------------------------------------
78+
template <Char T>
79+
inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)
7680
{
77-
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
78-
return integer::lower_flat_signed(v, ValTrait<WasmValType>::size * 8);
81+
integer::store<T>(cx, char_to_i32(cx, v), ptr);
7982
}
8083

81-
template <Boolean T>
82-
inline T load(const LiftLowerContext &cx, uint32_t ptr)
84+
template <Char T>
85+
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
8386
{
84-
return convert_int_to_bool(integer::load<uint8_t>(cx, ptr));
87+
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
88+
return {static_cast<WasmValType>(char_to_i32(cx, v))};
8589
}
8690

8791
template <Char T>
@@ -90,24 +94,24 @@ namespace cmcpp
9094
return convert_i32_to_char(cx, integer::load<uint32_t>(cx, ptr));
9195
}
9296

93-
template <Integer T>
94-
inline T load(const LiftLowerContext &cx, uint32_t ptr)
97+
template <Char T>
98+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
9599
{
96-
return integer::load<T>(cx, ptr);
100+
return convert_i32_to_char(cx, vi.next<int32_t>());
97101
}
98102

99-
template <Boolean T>
100-
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
103+
// Integer ------------------------------------------------------------------
104+
template <Integer T>
105+
inline void store(LiftLowerContext &cx, const T &v, uint32_t ptr)
101106
{
102-
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
103-
return {static_cast<WasmValType>(v)};
107+
integer::store<T>(cx, v, ptr);
104108
}
105109

106-
template <Char T>
110+
template <SignedInteger T>
107111
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
108112
{
109113
using WasmValType = WasmValTypeTrait<ValTrait<T>::flat_types[0]>::type;
110-
return {static_cast<WasmValType>(char_to_i32(cx, v))};
114+
return integer::lower_flat_signed(v, ValTrait<WasmValType>::size * 8);
111115
}
112116

113117
template <UnsignedInteger T>
@@ -118,16 +122,10 @@ namespace cmcpp
118122
return {fv};
119123
}
120124

121-
template <Boolean T>
122-
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
123-
{
124-
return convert_int_to_bool(vi.next<int32_t>());
125-
}
126-
127-
template <Char T>
128-
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
125+
template <Integer T>
126+
inline T load(const LiftLowerContext &cx, uint32_t ptr)
129127
{
130-
return convert_i32_to_char(cx, vi.next<int32_t>());
128+
return integer::load<T>(cx, ptr);
131129
}
132130

133131
template <UnsignedInteger T>

include/cmcpp/list.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#include "load.hpp"
77
#include "util.hpp"
88

9-
#include <tuple>
10-
#include <limits>
11-
#include <cassert>
12-
139
namespace cmcpp
1410
{
1511
namespace list
@@ -48,7 +44,7 @@ namespace cmcpp
4844
}
4945

5046
template <typename T>
51-
WasmValVector lower_flat_list(LiftLowerContext &cx, const list_t<T> &v)
47+
WasmValVector lower_flat(LiftLowerContext &cx, const list_t<T> &v)
5248
{
5349
auto [ptr, length] = store_into_range(cx, v);
5450
return {static_cast<int32_t>(ptr), static_cast<int32_t>(length)};
@@ -93,7 +89,7 @@ namespace cmcpp
9389
template <List T>
9490
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
9591
{
96-
return list::lower_flat_list(cx, v);
92+
return list::lower_flat(cx, v);
9793
}
9894

9995
template <List T>

include/cmcpp/string.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef CMCPP_STRING_HPP
22
#define CMCPP_STRING_HPP
33

4-
#include <cmcpp/context.hpp>
5-
#include <cmcpp/integer.hpp>
6-
#include <cmcpp/util.hpp>
4+
#include "context.hpp"
5+
#include "integer.hpp"
6+
#include "util.hpp"
77

88
namespace cmcpp
99
{

include/cmcpp/traits.hpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#ifndef CMCPP_TRAITS_HPP
22
#define CMCPP_TRAITS_HPP
33

4-
#include <cstdint>
5-
#include <vector>
6-
#include <map>
7-
#include <string_view>
4+
#include <cassert>
5+
#include <cstring>
6+
#include <cmath>
87
#include <bitset>
98
#include <optional>
109
#include <variant>
11-
#include <memory>
12-
#include <stdexcept>
13-
#include <array>
14-
#include <cassert>
1510
#include <limits>
16-
#include <cstring>
17-
#include <cmath>
1811

1912
#include "boost/pfr.hpp"
2013

include/cmcpp/tuple.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
#include "context.hpp"
55
#include "integer.hpp"
66
#include "store.hpp"
7+
#include "lower.hpp"
78
#include "load.hpp"
9+
#include "lift.hpp"
810
#include "util.hpp"
911

10-
#include <tuple>
11-
#include <limits>
12-
#include <cassert>
13-
1412
namespace cmcpp
1513
{
1614
namespace tuple
@@ -32,12 +30,12 @@ namespace cmcpp
3230
}
3331

3432
template <Tuple T>
35-
WasmValVector lower_flat_tuple(LiftLowerContext &cx, const T &v)
33+
WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
3634
{
3735
WasmValVector retVal = {};
3836
auto process_field = [&](auto &&field)
3937
{
40-
auto flat = lower_flat(cx, field);
38+
auto flat = cmcpp::lower_flat(cx, field);
4139
retVal.insert(retVal.end(), flat.begin(), flat.end());
4240
};
4341

@@ -53,7 +51,7 @@ namespace cmcpp
5351
auto process_field = [&](auto &&field)
5452
{
5553
ptr = align_to(ptr, ValTrait<std::remove_reference_t<decltype(field)>>::alignment);
56-
field = load<std::remove_reference_t<decltype(field)>>(cx, ptr);
54+
field = cmcpp::load<std::remove_reference_t<decltype(field)>>(cx, ptr);
5755
ptr += ValTrait<std::remove_reference_t<decltype(field)>>::size;
5856
};
5957

@@ -63,12 +61,12 @@ namespace cmcpp
6361
}
6462

6563
template <Tuple T>
66-
inline T lift_flat_tuple(const LiftLowerContext &cx, const CoreValueIter &vi)
64+
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
6765
{
6866
T result;
6967
auto process_field = [&](auto &&field)
7068
{
71-
field = lift_flat<std::remove_reference_t<decltype(field)>>(cx, vi);
69+
field = cmcpp::lift_flat<std::remove_reference_t<decltype(field)>>(cx, vi);
7270
};
7371

7472
std::apply([&](auto &&...fields)
@@ -86,13 +84,13 @@ namespace cmcpp
8684
template <Tuple T>
8785
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
8886
{
89-
return tuple::lower_flat_tuple(cx, v);
87+
return tuple::lower_flat(cx, v);
9088
}
9189

9290
template <Record T>
9391
inline WasmValVector lower_flat(LiftLowerContext &cx, const T &v)
9492
{
95-
return tuple::lower_flat_tuple(cx, boost::pfr::structure_to_tuple((typename ValTrait<T>::inner_type)v));
93+
return tuple::lower_flat(cx, boost::pfr::structure_to_tuple((typename ValTrait<T>::inner_type)v));
9694
}
9795

9896
template <Tuple T>
@@ -104,14 +102,14 @@ namespace cmcpp
104102
template <Tuple T>
105103
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
106104
{
107-
return tuple::lift_flat_tuple<T>(cx, vi);
105+
return tuple::lift_flat<T>(cx, vi);
108106
}
109107

110108
template <Record T>
111109
inline T lift_flat(const LiftLowerContext &cx, const CoreValueIter &vi)
112110
{
113111
using TupleType = decltype(boost::pfr::structure_to_tuple(std::declval<typename ValTrait<T>::inner_type>()));
114-
TupleType x = tuple::lift_flat_tuple<TupleType>(cx, vi);
112+
TupleType x = tuple::lift_flat<TupleType>(cx, vi);
115113
return to_struct<T>(x);
116114
}
117115

samples/wamr/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include <iostream>
2-
31
#include "wasm_export.h"
42
#include "cmcpp.hpp"
53

4+
#include <iostream>
5+
66
using namespace cmcpp;
77

88
char *read_wasm_binary_to_buffer(const char *filename, uint32_t *size)

0 commit comments

Comments
 (0)