-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput_c.def
167 lines (145 loc) · 5.53 KB
/
output_c.def
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
include: output.def
include: macros_output/case.def
include: macros_output/for.def
include: macros_output/scope.def
include: macros_output/functions.def
include: macros_output/variables.def
include: macros_output/types.def
include: macros_c/parsing.def
include: macros_c/structure.def
include: macros_c/functions.def
include: macros_c/variables.def
include: macros_c/types.def
include: macros_c/dump.def
include: macros_c/list_functions.def
include: macros_c/cpp_hack.def
include: macros_c/hacks.def
include: macros_c/regex.def
subcode:: package_globals
$global %misc_vars
our $except;
page: output_c, output_main
type: pm
output_dir: lib/MyDef
ext: c
package: MyDef::output_c
subcode: init_page
$call check_default_data_size
$if $page->{"use_libmydef"}
$call load_autodecl, c/libmydef.inc
$if $page->{autodecl}
my @tlist=split /,\s*/, $page->{autodecl}
$foreach $f in @tlist
$call load_autodecl, $f
$call @autoload_hack
$call autolist_functions, static
$if $page->{autolist} eq "page"
$call autolist_page_functions
# -------------
subcode: check_default_data_size
my $macros=$MyDef::def->{macros}
$(for:v in use_double,has_bool,use_int64,use_prefix)
$if $macros->{$(v)} and !defined $page->{$(v)}
$page->{$(v)}=$macros->{$(v)}
$if $page->{"use_double"}
$type_name{f}="double";
$type_prefix{f}="double";
$else
$type_name{f}="float";
$type_prefix{f}="float";
$if $page->{"use_int64"}
$(for:i in i,j,k,l)
$type_name{$(i)}="int64_t";
$type_prefix{i}="int64_t";
$type_prefix{n}="int64_t";
$type_prefix{u}="uint64_t";
$else
$(for:i in i,j,k,l)
$type_name{$(i)}="int";
$type_prefix{i}="int";
$type_prefix{n}="int";
$type_prefix{u}="unsigned int";
subcode: parsecode
$(set:parse_condition=1)
$call parsecode_case_support, if, else if, c2_style
$call parsecode_common
subcode: dumpout
$call process_main_function
$call process_functions
$call process_extern_binary
$call process_link_objects
# ---- Header stuff --------------------------
my @t
$(for:frame_init,global_init,meta_init)
$if !$page->{has_stub_$1}
# always unless template frame already defines them
push @t, "DUMP_STUB $1"
$if @t
unshift @$out, @t
$(for:meta_exit,global_exit,frame_exit)
$if !$page->{has_stub_$1}
push @$out, "DUMP_STUB $1"
$call c_dump_init
# -------------------------------
subcode: process_main_function
my $mainfunc=$functions{"main"};
$if $mainfunc and !$mainfunc->{processed}
$global $has_main
$has_main=1
$mainfunc->{skip_declare}=1;
$mainfunc->{return_type}="int";
$mainfunc->{param_list}=["int argc", "char** argv"];
$if !$mainfunc->{return}
$mainfunc->{return}="return 0;"
subcode: process_functions
$call @check_func_hook
$foreach $func in @function_list
$if !$func->{processed}
process_function_std($func)
# ----
my $name=$func->{name}
$call @func_hook
$if !$has_main
$if $function_autolist{$name} eq "static"
$if $func->{return_type} !~/\bstatic\b/
$func->{declare}="static ".$func->{declare}
$elif $function_autolist{$name} eq "skip_declare"
$func->{skip_declare} = 1
$if $func->{decl_append}
$func->{declare} .=$func->{decl_append}
$call @process_function_cpp
# -- similar to -finstrument-functions but totaly customary
subcode: check_func_hook
my $func_hook
$if $MyDef::def->{codes}->{_FUNC_HOOK}
$func_hook = MyDef::compileutil::eval_sub("_FUNC_HOOK")
subcode: func_hook
$if $func_hook
eval $func_hook
subcode: process_link_objects
my @objlist
my @liblist
$foreach $i in @object_list
$if $i=~/^lib(.*)\.a/
push @liblist, "-Wl,-Bstatic -l$1"
$elif $i=~/^lib(.*)/
push @liblist, "-l$1"
$else
push @objlist, $i
my ($lib_list, $obj_list)
# NOTE: objlist after liblist, maybe this is undesired
$if @liblist
$lib_list=join(" ", @liblist)
$page->{lib_list}=$lib_list
$if @objlist
$obj_list=join(" ", @objlist)
$page->{lib_list}.=" ".$obj_list
#-----------------------------------------------
subcode: if_c2_style
$call push_single_block, "if ($cond) {", "}"
subcode: elif_c2_style
$call else_merge, }
$call push_single_block, "} else if ($cond) {", "}"
subcode: else_c2_style
$call else_merge, }
$call push_single_block, "} else {", "}"