forked from facebookincubator/hsthrift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhsc.h
35 lines (31 loc) · 1.13 KB
/
hsc.h
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
// Copyright (c) Facebook, Inc. and its affiliates.
#pragma once
/*
* #{ mangled signature }
*
* Takes a C++ function signature and mangles it into the corresponding
* C++ linker symbol.
*
* #{ mangled int foo(const char*) }
*
* "3fooPKc"
*
* This lets you write C++ foreign imports more cleanly.
*
* foreign import ccall #{ mangled int foo(const char*) }
* foo :: CString -> IO CInt
*
* In order to use this plugin, you must link with '@/common/hs:hsc'.
*
*/
#define hsc_mangled_common(str, x...) \
do { \
hs_init(NULL, NULL); \
char symbol[] = #x; \
const char* const mangled = reinterpret_cast<const char*>( \
itaniumMangle(symbol, sizeof(symbol) - 1)); \
hsc_printf(str, mangled); \
free(const_cast<char*>(mangled)); \
} while (0)
#define hsc_mangled(x...) hsc_mangled_common("\"%s\"", x)
#define hsc_mangled_reference(x...) hsc_mangled_common("\"&%s\"", x)