forked from withlin/advanced-go-programming-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch2-6-call-c-sum-v2.plantuml
63 lines (48 loc) · 1.02 KB
/
ch2-6-call-c-sum-v2.plantuml
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
' Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved.
' Use of this source code is governed by a Apache
' license that can be found in the LICENSE file.
@startuml
title c call go func
|_testmain.c|
:int main() {
extern int sum(int a, int b)
sum(1, 2)
return 0
};
-[#green,dashed]->
fork
|#AntiqueWhite|_cgo_export.c|
:int sum(int p0, int p1) {
struct { int p0, p1, r0; } a
_cgo_ctxt = _cgo_wait_runtime_init_done()
crosscall2(_cgoexp_xxx_sum, &a, 16, _cgo_ctxt)
_cgo_release_context(_cgo_ctxt)
return a.r0
};
|runtime/cgo/*.asm|
:TEXT crosscall2(SB),NOSPLIT,$0;
fork
|#AntiqueWhite|_cgo_types.go|
:func _cgoexp_xxx_sum(a unsafe.Pointer, n int32, ctxt uintptr) {
fn := _cgoexpwrap_xxx_sum
_cgo_runtime_cgocallback(
_cgoexpwrap_xxx_sum,
...
)
};
|#AntiqueWhite|_cgo_types.go|
:func _cgoexpwrap_xxx_sum(p0, p1) r0 {
return sum(p0, p1)
};
|main.go|
://export sum
func sum(a, b C.int) C.int {
return a + b
};
endfork
|runtime/cgo/*.asm|
:TEXT crosscall2(SB),NOSPLIT,$0;
endfork
|_testmain.c|
stop
@enduml