forked from oneapi-src/level-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibapi.cpp.mako
More file actions
92 lines (81 loc) · 2.27 KB
/
libapi.cpp.mako
File metadata and controls
92 lines (81 loc) · 2.27 KB
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
88
89
90
91
92
<%!
import re
from templates import helper as th
def define_dbg(obj, tags):
if re.match("class", obj['type']):
return True
if 'class' not in obj or obj['class'] in tags:
return re.match("enum", obj['type']) or re.match("struct|union", obj['type'])
return False
%><%
n=namespace
N=n.upper()
x=tags['$x']
X=x.upper()
%>/*
*
* Copyright (C) 2019-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file ${name}.cpp
*
* @brief C++ static library for ${n}
*
*/
#include "${x}_lib.h"
extern "C" {
%for s in specs:
## FUNCTION ###################################################################
%for obj in th.filter_items(s['objects'], 'type', 'function'):
///////////////////////////////////////////////////////////////////////////////
%if 'condition' in obj:
#if ${th.subt(n, tags, obj['condition'])}
%endif
%for line in th.make_desc_lines(n, tags, obj):
/// ${line}
%endfor
%for line in th.make_details_lines(n, tags, obj):
/// ${line}
%endfor
///
%for line in th.make_returns_lines(n, tags, obj, meta=meta):
/// ${line}
%endfor
${x}_result_t ${X}_APICALL
${th.make_func_name(n, tags, obj)}(
%for line in th.make_param_lines(n, tags, obj):
${line}
%endfor
)
{
%if re.match("Init", obj['name']):
static ${x}_result_t result = ${X}_RESULT_SUCCESS;
std::call_once(${x}_lib::context->initOnce, [flags]() {
%if re.match("zes", n):
result = ${x}_lib::context->Init(flags, true);
%else:
result = ${x}_lib::context->Init(flags, false);
%endif
});
if( ${X}_RESULT_SUCCESS != result )
return result;
%endif
if(ze_lib::context->inTeardown) {
return ${X}_RESULT_ERROR_UNINITIALIZED;
}
auto ${th.make_pfn_name(n, tags, obj)} = ${x}_lib::context->${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)};
if( nullptr == ${th.make_pfn_name(n, tags, obj)} ) {
if(!ze_lib::context->isInitialized)
return ${X}_RESULT_ERROR_UNINITIALIZED;
else
return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
return ${th.make_pfn_name(n, tags, obj)}( ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
}
%if 'condition' in obj:
#endif // ${th.subt(n, tags, obj['condition'])}
%endif
%endfor
%endfor
} // extern "C"