-
Notifications
You must be signed in to change notification settings - Fork 34
/
hsc.h
41 lines (37 loc) · 1.3 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
36
37
38
39
40
41
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#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)