Skip to content

Commit

Permalink
prefix capi functions with age_
Browse files Browse the repository at this point in the history
  • Loading branch information
raggledodo committed Dec 1, 2018
1 parent 8ad8572 commit 6f5720b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 3 additions & 1 deletion age/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ genrule(
"generated/opmap.cpp",
],
tools = ["//age:agen"],
cmd = "$(location //age:agen) --cfg $(location :test/mock.json) --out $(@D)/generated --strip_prefix=$$(dirname $(@D)) --gen_capi",
cmd = "$(location //age:agen) " +
"--cfg $(location :test/mock.json) --out $(@D)/generated " +
"--strip_prefix=$$(dirname $(@D)) --gen_capi",
)

cc_test(
Expand Down
6 changes: 3 additions & 3 deletions age/templates/capi_tmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
""")

header.api_decls = ("apis", lambda apis: '\n\n'.join([\
"extern int64_t {api} ({args});".format(\
api = api["name"], args = ', '.join([\
"extern int64_t age_{func} ({args});".format(\
func = api["name"], args = ', '.join([\
arg.replace(_origtype, _repltype)\
for arg in api["args"]])) for api in apis]))

Expand Down Expand Up @@ -71,7 +71,7 @@
#endif
""")

_cfunc_fmt = """int64_t {func} ({params})
_cfunc_fmt = """int64_t age_{func} ({params})
{{
{arg_decls}auto ptr = age::{func}({retargs});
int64_t id = (int64_t) ptr.get();
Expand Down
12 changes: 6 additions & 6 deletions age/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
extern void get_shape (int outshape[8], int64_t tens);
extern int64_t func1 ();
extern int64_t age_func1 ();
extern int64_t func2 (int64_t arg, Arg arg1);
extern int64_t age_func2 (int64_t arg, Arg arg1);
extern int64_t func3 (int64_t arg, Arg arg1, int64_t arg2);
extern int64_t age_func3 (int64_t arg, Arg arg1, int64_t arg2);
#endif // _GENERATED_CAPI_HPP
"""
Expand Down Expand Up @@ -161,15 +161,15 @@
std::copy(shape.begin(), shape.end(), outshape);
}
int64_t func1 ()
int64_t age_func1 ()
{
auto ptr = age::func1();
int64_t id = (int64_t) ptr.get();
tens.emplace(id, ptr);
return id;
}
int64_t func2 (int64_t arg, Arg arg1)
int64_t age_func2 (int64_t arg, Arg arg1)
{
ade::TensptrT arg_ptr = get_tens(arg);
auto ptr = age::func2(arg_ptr, arg1);
Expand All @@ -178,7 +178,7 @@
return id;
}
int64_t func3 (int64_t arg, Arg arg1, int64_t arg2)
int64_t age_func3 (int64_t arg, Arg arg1, int64_t arg2)
{
ade::TensptrT arg_ptr = get_tens(arg);
ade::TensptrT arg2_ptr = get_tens(arg2);
Expand Down
4 changes: 2 additions & 2 deletions age/test/test_capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TEST(AGE, CApi)
{
// everything should be exactly the same as Api
// except inputs and output types are different
int64_t carrot = goku(16);
int64_t carrot = age_goku(16);
MockTensor* kakarot = dynamic_cast<MockTensor*>(
static_cast<ade::iTensor*>(get_ptr(carrot)));
EXPECT_NE(nullptr, kakarot);
Expand All @@ -22,7 +22,7 @@ TEST(AGE, CApi)
EXPECT_EQ(16, shape.at(0));

int64_t var = malloc_tens(new MockTensor(1, ade::Shape({1, 1, 31})));
int64_t vegetable = vegeta(var, 2);
int64_t vegetable = age_vegeta(var, 2);
MockTensor* planet = dynamic_cast<MockTensor*>(
static_cast<ade::iTensor*>(get_ptr(vegetable)));
EXPECT_NE(nullptr, planet);
Expand Down

0 comments on commit 6f5720b

Please sign in to comment.