The check to see if an item was already on the heap was randomly hitting.
[jitcs.git] / include / jitcs_fnctypeinfo.h
blob074cca6783d996c28c52e3ff28657f11a53696ac
1 //===-- jitcs_fnctypeinfo.h - -----------------------------------*- C++ -*-===//
2 //
3 //===----------------------------------------------------------------------===//
5 #ifndef _JITCS_FNCTYPEINFO_H_
6 #define _JITCS_FNCTYPEINFO_H_
8 #include "jitcs_base.h"
10 namespace jitcs {
12 enum FTSubType {
13 FTS_CDecl,
14 FTS_FastCall,
15 FTS_StdCall,
17 enum FTTypeId {
18 FTT_Void,
19 FTT_Int,
20 FTT_PtrInt,
21 FTT_Ptr,
23 template <typename T> struct GetFTSubType {};
24 template <typename R, typename ...Args>
25 struct GetFTSubType<R (__cdecl *)(Args...)> {
26 static const FTSubType Value = FTS_CDecl;
27 typedef R (*FType)(Args...);
29 template <typename R, typename ...Args>
30 struct GetFTSubType<R (__fastcall *)(Args...)> {
31 static const FTSubType Value = FTS_FastCall;
32 typedef R (*FType)(Args...);
34 template <typename R, typename ...Args>
35 struct GetFTSubType<R (__stdcall *)(Args...)> {
36 static const FTSubType Value = FTS_StdCall;
37 typedef R (*FType)(Args...);
40 template <typename T>
41 struct GetFTTypeId {
42 static const bool OK = false;
43 static const FTTypeId Value = FTT_Void;
45 template <>
46 struct GetFTTypeId<void> {
47 static const bool OK = true;
48 static const FTTypeId Value = FTT_Void;
50 template <>
51 struct GetFTTypeId<i32> {
52 static const bool OK = true;
53 static const FTTypeId Value = FTT_Int;
55 template <>
56 struct GetFTTypeId<u32> {
57 static const bool OK = true;
58 static const FTTypeId Value = FTT_Int;
60 template <>
61 struct GetFTTypeId<i64> {
62 static const bool OK = sizeof(i64) <= sizeof(void*);
63 static const FTTypeId Value = sizeof(i64) == sizeof(void*) ? FTT_PtrInt : FTT_Int;
65 template <>
66 struct GetFTTypeId<u64> {
67 static const bool OK = sizeof(i64) <= sizeof(void*);
68 static const FTTypeId Value = sizeof(u64) == sizeof(void*) ? FTT_PtrInt : FTT_Int;
70 template <typename T>
71 struct GetFTTypeId<T*> {
72 static const bool OK = true;
73 static const FTTypeId Value = FTT_Ptr;
75 template <typename T>
76 struct GetFTTypeId<T const*> {
77 static const bool OK = true;
78 static const FTTypeId Value = FTT_Ptr;
80 template <typename T>
81 struct GetFTTypeId<T&> {
82 static const bool OK = true;
83 static const FTTypeId Value = FTT_Ptr;
85 template <typename T>
86 struct GetFTTypeId<T const&> {
87 static const bool OK = true;
88 static const FTTypeId Value = FTT_Ptr;
92 template <typename T> struct _GetFTResultId {};
93 template <typename R, typename ...Args>
94 struct _GetFTResultId<R (*)(Args...)> {
95 static const bool OK = GetFTTypeId<R>::OK;
96 static const FTTypeId Value = GetFTTypeId<R>::Value;
98 template <typename T> struct GetFTResultId : _GetFTResultId<typename GetFTSubType<T>::FType> {};
99 template <typename T> struct _GetFTParamCount {};
100 template <typename R>
101 struct _GetFTParamCount<R (*)()> {
102 static const uint Value = 0;
104 template <typename R, typename Arg, typename ...Args>
105 struct _GetFTParamCount<R (*)(Arg, Args...)> {
106 static const uint Value = _GetFTParamCount<R (*)(Args...)>::Value + 1;
108 template <typename T> struct GetFTParamCount : _GetFTParamCount<typename GetFTSubType<T>::FType> {};
109 template <typename T, uint N> struct _GetFTParamId {};
110 template <typename R, typename Arg, typename ...Args>
111 struct _GetFTParamId<R (*)(Arg, Args...), 0> {
112 static const bool OK = GetFTTypeId<Arg>::OK;
113 static const FTTypeId Value = GetFTTypeId<Arg>::Value;
115 template <typename R, uint N>
116 struct _GetFTParamId<R (*)(), N> {
117 static const bool OK = false;
118 static const FTTypeId Value = FTT_Void;
120 template <uint N, typename R, typename Arg, typename ...Args>
121 struct _GetFTParamId<R (*)(Arg, Args...), N> {
122 static const bool OK = _GetFTParamId<R (*)(Args...), N - 1>::OK;
123 static const FTTypeId Value = _GetFTParamId<R (*)(Args...), N - 1>::Value;
125 template <typename T, uint N> struct GetFTParamId : _GetFTParamId<typename GetFTSubType<T>::FType, N> {};
126 } // end of namespace jitcs
128 #endif
129 // _JITCS_FNCTYPEINFO_H_