This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
/
compiler_options.hpp.in
756 lines (728 loc) · 23.3 KB
/
compiler_options.hpp.in
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
#pragma once
#include <eosio/utils.hpp>
#include <eosio/whereami/whereami.hpp>
#include <vector>
#include <string>
#include "llvm/Support/FileSystem.h"
#ifdef ONLY_LD
#define LD_CAT EosioLdToolCategory
#else
#define LD_CAT EosioCompilerToolCategory
#endif
#ifndef ONLY_LD
static llvm::cl::OptionCategory EosioCompilerToolCategory("compiler options");
#else
static llvm::cl::OptionCategory EosioLdToolCategory("ld options");
#endif
/// begin ld options
static cl::opt<bool> fquery_opt(
"fquery",
cl::desc("Produce binaries for wasmql"),
cl::cat(LD_CAT));
static cl::opt<bool> use_old_malloc_opt(
"use-freeing-malloc",
cl::desc("Set the malloc implementation to the old freeing malloc"),
cl::Hidden,
cl::cat(LD_CAT));
static cl::opt<std::string> eosio_imports_opt(
"eosio-imports",
cl::desc("Set the file for eosio.imports"),
cl::Hidden,
cl::cat(LD_CAT));
static cl::opt<std::string> pp_path_opt(
"eosio-pp-dir",
cl::desc("Set the directory for eosio.pp"),
cl::Hidden,
cl::cat(LD_CAT));
static cl::opt<bool> use_rt_opt(
"use-rt",
cl::desc("Use software compiler-rt"),
cl::Hidden,
cl::cat(LD_CAT));
static cl::opt<bool> fno_lto_opt(
"fno-lto",
cl::desc("Disable LTO"),
cl::cat(LD_CAT));
static cl::opt<bool> fno_cfl_aa_opt(
"fno-cfl-aa",
cl::desc("Disable CFL Alias Analysis"),
cl::cat(LD_CAT));
static cl::opt<bool> fno_stack_first_opt(
"fno-stack-first",
cl::desc("Don't set the stack first in memory"),
cl::cat(LD_CAT));
static cl::opt<bool> fno_post_pass_opt(
"fno-post-pass",
cl::desc("Don't run post processing pass"),
cl::cat(LD_CAT));
static cl::opt<std::string> lto_opt_opt(
"lto-opt",
cl::desc("LTO Optimization level (O0-O3)"),
cl::cat(LD_CAT));
static cl::list<std::string> L_opt(
"L",
cl::desc("Add directory to library search path"),
cl::cat(LD_CAT),
cl::Prefix,
cl::ZeroOrMore);
static cl::list<std::string> l_opt(
"l",
cl::desc("Root name of library to link"),
cl::cat(LD_CAT),
cl::Prefix,
cl::ZeroOrMore);
static cl::opt<std::string> o_opt(
"o",
cl::desc("Write output to <file>"),
cl::cat(LD_CAT));
static cl::list<std::string> input_filename_opt(
cl::Positional,
cl::desc("<input file> ..."),
cl::cat(LD_CAT),
cl::OneOrMore);
static cl::opt<bool> fasm_opt(
"fasm",
cl::desc("Assemble file for x86-64"),
cl::ZeroOrMore,
cl::cat(LD_CAT));
static cl::opt<bool> fnative_opt(
"fnative",
cl::desc("Compile and link for x86-64"),
cl::ZeroOrMore,
cl::cat(LD_CAT));
static cl::opt<bool> fuse_main_opt(
"fuse-main",
cl::desc("Use main as entry"),
cl::cat(LD_CAT));
static cl::opt<bool> allow_sse_opt(
"allow-sse",
cl::desc("Should not be used, except for build libc"),
cl::Hidden,
cl::cat(LD_CAT));
/// End of ld options
#ifndef ONLY_LD
/// begin c/c++ options/
static cl::opt<bool> llvm_ir_opt(
"emit-ir",
cl::desc("Emit llvm ir"),
cl::Hidden,
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> MF_opt(
"MF",
cl::desc("Write depfile output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> MT_opt(
"MT",
cl::desc("Specify name of main file output in depfile"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> MD_opt(
"MD",
cl::desc("Write depfile containing user and system headers"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> MMD_opt(
"MMD",
cl::desc("Write depfile containing user"),
cl::cat(EosioCompilerToolCategory));
static cl::list<std::string> resources(
"R",
cl::Prefix,
cl::desc("Add a resource path for inclusion"),
cl::ZeroOrMore,
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> abigen_opt(
"abigen",
cl::desc("Generate ABI"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> abigen_output_opt(
"abigen_output",
cl::desc("ABIGEN output"),
cl::cat(EosioCompilerToolCategory));
// ignore for now
static cl::opt<bool> g_opt(
"g",
cl::desc("debug build <ignored>"),
cl::Hidden,
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> x_opt(
"x",
cl::desc("<ignored>"),
cl::Hidden,
cl::Prefix,
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> pch_opt(
"fpch-preprocess",
cl::desc("<ignored>"),
cl::Hidden,
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> CC_opt(
"CC",
cl::desc("Include comments from within macros in preprocessed output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> C_opt(
"C",
cl::desc("Include comments in preprocessed output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> c_opt(
"c",
cl::desc("Only run preprocess, compile, and assemble steps"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> color_diag_opt(
"fcolor-diagnostics",
cl::desc("Use colors in diagnostics"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> dD_opt(
"dD",
cl::desc("Print macro definitions in -E mode in addition to normal output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> dI_opt(
"dI",
cl::desc("Print include directives in -E mode in addition to normal output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> dM_opt(
"dM",
cl::desc("Print macro definitions in -E mode instead to normal output"),
cl::cat(EosioCompilerToolCategory));
static cl::list<std::string> D_opt(
"D",
cl::desc("Define <macro> to <value> (or 1 if <value> omitted)"),
cl::ZeroOrMore,
cl::Prefix,
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> emit_ast_opt(
"emit-ast",
cl::desc("Emit Clang AST files for source inputs"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> emit_llvm_opt(
"emit-llvm",
cl::desc("Use the LLVM representation for assembler and object files"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> E_opt(
"E",
cl::desc("Only run the preprocessor"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> finline_functions_opt(
"finline-functions",
cl::desc("Inline suitable functions"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> finline_hint_functions_opt(
"finline-hint-functions",
cl::desc("Inline functions which are (explicitly or implicitly) marked inline"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fmerge_all_constants_opt(
"fmerge-all-constants",
cl::desc("Allow merging of constants"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fno_elide_constructors_opt(
"fno-elide-constructors",
cl::desc("Disable C++ copy constructor elision"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstack_protector_all_opt(
"fstack-protector-all",
cl::desc("Force the usage of stack protectors for all functions"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstack_protector_strong_opt(
"fstack-protector-strong",
cl::desc("Use a strong heuristic to apply stack protectors to functions"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstack_protector_opt(
"fstack-protector",
cl::desc("Enable stack protectors for functions potentially vulnerable to stack smashing"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstrict_enums_opt(
"fstrict-enums",
cl::desc("Enable optimizations based on the strict definition of an enum's value range"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstrict_return_opt(
"fstrict-return",
cl::desc("Always treat control flow paths that fall off the end of a non-void function as unreachable"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fstrict_vtable_pointers_opt(
"fstrict-vtable-pointers",
cl::desc("Enable optimizations based on the strict rules for overwriting polymorphic C++ objects"),
cl::cat(EosioCompilerToolCategory));
static cl::list<std::string> include_opt(
"include",
cl::desc("Include file before parsing"),
cl::cat(EosioCompilerToolCategory),
cl::ZeroOrMore);
static cl::list<std::string> I_opt(
"I",
cl::desc("Add directory to include search path"),
cl::cat(EosioCompilerToolCategory),
cl::Prefix,
cl::ZeroOrMore);
static cl::opt<std::string> O_opt(
"O",
cl::desc("Optimization level s, 0-3"),
cl::Prefix,
cl::ZeroOrMore,
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> sysroot_opt(
"sysroot",
cl::desc("Set the system root directory"),
cl::Prefix,
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> isysroot_opt(
"isysroot",
cl::desc("Set the system root directory (usually /)"),
cl::Hidden,
cl::Prefix,
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> isystem_opt(
"isystem",
cl::desc("Add directory to SYSTEM include search path"),
cl::Prefix,
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> S_opt(
"S",
cl::desc("Only run preprocess and compilation steps"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<std::string> U_opt(
"U",
cl::desc("Undefine macro <macro>"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> v_opt(
"v",
cl::desc("Show commands to run and use verbose output"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> w_opt(
"w",
cl::desc("Suppress all warnings"),
cl::cat(EosioCompilerToolCategory));
static cl::list<std::string> W_opt(
"W",
cl::desc("Enable the specified warning"),
cl::cat(EosioCompilerToolCategory),
cl::Prefix,
cl::ZeroOrMore);
static cl::opt<std::string> contract_name(
"contract",
cl::desc("Contract name"),
cl::cat(EosioCompilerToolCategory));
/// end c/c++ options
/// begin c++ options
#ifdef CPP_COMP
static cl::opt<std::string> std_opt(
"std",
cl::desc("Language standard to compile for"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> faligned_allocation_opt(
"faligned-allocation",
cl::desc("Enable C++17 aligned allocation functions"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> fcoroutine_ts_opt(
"fcoroutine-ts",
cl::desc("Enable support for the C++ Coroutines TS"),
cl::cat(EosioCompilerToolCategory));
#endif
/// end c++ options
#endif
struct Options {
std::string output_fn;
std::vector<std::string> inputs;
bool link;
bool abigen;
std::string eosio_pp_dir;
std::string abigen_output;
std::string abigen_contract;
std::vector<std::string> comp_options;
std::vector<std::string> ld_options;
std::vector<std::string> abigen_options;
std::vector<std::string> abigen_resources;
bool native;
};
static void GetCompDefaults(std::vector<std::string>& copts) {
const char* eosio_apply_suff = "${CMAKE_SHARED_LIBRARY_SUFFIX}";
std::string apply_lib;
if (!fnative_opt) {
copts.emplace_back("--target=wasm32");
copts.emplace_back("-ffreestanding");
} else {
#ifdef __APPLE__
copts.emplace_back("--target=x86_64-unknown-darwin-macho");
copts.emplace_back("-mmacosx-version-min=10.13");
copts.emplace_back("-fno-stack-protector");
copts.emplace_back("-m64");
#else
copts.emplace_back("--target=x86_64-unknown-linux-gnu");
copts.emplace_back("-m64");
#endif
if (!allow_sse_opt) {
copts.emplace_back("-mno-sse");
copts.emplace_back("-mno-sse2");
copts.emplace_back("-mno-mmx");
copts.emplace_back("-mno-3dnow");
}
if (!fasm_opt) {
copts.emplace_back("-DEOSIO_NATIVE");
copts.emplace_back("-DLP64");
}
}
if (!fasm_opt) {
copts.emplace_back("-fno-threadsafe-statics");
#ifdef CPP_COMP
copts.emplace_back("-fno-rtti");
copts.emplace_back("-fno-exceptions");
copts.emplace_back("-fmodules-ts");
#endif
copts.emplace_back("-DBOOST_DISABLE_ASSERTS");
copts.emplace_back("-DBOOST_EXCEPTION_DISABLE");
if (!fnative_opt) {
copts.emplace_back("-Xclang");
copts.emplace_back("-load");
copts.emplace_back("-Xclang");
if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/LLVMEosioApply"+eosio_apply_suff))
copts.emplace_back(eosio::cdt::whereami::where()+"/LLVMEosioApply"+eosio_apply_suff);
else if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/../lib/LLVMEosioApply"+eosio_apply_suff))
copts.emplace_back(eosio::cdt::whereami::where()+"/../lib/LLVMEosioApply"+eosio_apply_suff);
}
if (false && fnative_opt) {
copts.emplace_back("-Xclang");
copts.emplace_back("-load");
copts.emplace_back("-Xclang");
if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/LLVMEosioSoftfloat"+eosio_apply_suff))
copts.emplace_back(eosio::cdt::whereami::where()+"/LLVMEosioSoftfloat"+eosio_apply_suff);
else if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/../lib/LLVMEosioSoftfloat"+eosio_apply_suff))
copts.emplace_back(eosio::cdt::whereami::where()+"/../lib/LLVMEosioSoftfloat"+eosio_apply_suff);
}
if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/eosio_plugin"+eosio_apply_suff))
copts.emplace_back("-fplugin="+eosio::cdt::whereami::where()+"/eosio_plugin"+eosio_apply_suff);
else if (llvm::sys::fs::exists(eosio::cdt::whereami::where()+"/../lib/eosio_plugin"+eosio_apply_suff))
copts.emplace_back("-fplugin="+eosio::cdt::whereami::where()+"/../lib/eosio_plugin"+eosio_apply_suff);
}
}
#ifdef ONLY_LD
static void GetLdDefaults(std::vector<std::string>& ldopts) {
if (!fnative_opt) {
if (fuse_main_opt)
ldopts.emplace_back("-e main");
else {
if (fquery_opt) {
// fill in base entry point for query wasm
ldopts.emplace_back("-e apply");
} else
ldopts.emplace_back("-e apply");
}
ldopts.emplace_back("--gc-sections");
ldopts.emplace_back("--strip-all");
ldopts.emplace_back("-zstack-size="+std::string("${EOSIO_STACK_SIZE}"));
ldopts.emplace_back("--merge-data-segments");
} else {
#ifdef __APPLE__
ldopts.emplace_back("-arch x86_64 -macosx_version_min 10.13 -framework Foundation -framework System");
#endif
ldopts.emplace_back("-static");
}
}
#endif
static Options CreateOptions(bool add_defaults=true) {
std::string output_fn;
std::vector<std::string> inputs;
std::vector<std::string> agresources;
std::vector<std::string> copts;
std::vector<std::string> ldopts;
std::vector<std::string> agopts;
bool link = true;
std::string pp_dir;
std::string abigen_output;
std::string abigen_contract;
#ifdef ONLY_LD
bool abigen = false;
#else
bool abigen = abigen_opt;
abigen_output = abigen_output_opt;
#endif
if (add_defaults) {
GetCompDefaults(copts);
GetCompDefaults(agopts);
#ifdef ONLY_LD
GetLdDefaults(ldopts);
#endif
}
if (!pp_path_opt.empty())
pp_dir = pp_path_opt;
else
pp_dir = eosio::cdt::whereami::where();
if (!fno_cfl_aa_opt) {
copts.emplace_back("-mllvm");
copts.emplace_back("-use-cfl-aa-in-codegen=both");
agopts.emplace_back("-mllvm");
agopts.emplace_back("-use-cfl-aa-in-codegen=both");
#ifdef ONLY_LD
ldopts.emplace_back("-mllvm");
ldopts.emplace_back("-use-cfl-aa-in-codegen=both");
#else
ldopts.emplace_back("-fno-cfl-aa");
#endif
}
for ( auto input_filename : input_filename_opt ) {
#ifdef ONLY_LD
ldopts.push_back(input_filename);
#else
inputs.push_back(input_filename);
#endif
}
#ifdef ONLY_LD
ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib");
#ifndef __APPLE__
ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib64");
#endif
#endif
#ifndef ONLY_LD
if (!sysroot_opt.empty()) {
copts.emplace_back("--sysroot="+sysroot_opt);
copts.emplace_back("-I"+sysroot_opt+"/include/libcxx");
copts.emplace_back("-I"+sysroot_opt+"/include/libc");
agopts.emplace_back("--sysroot="+sysroot_opt);
agopts.emplace_back("-I"+sysroot_opt+"/include/libcxx");
agopts.emplace_back("-I"+sysroot_opt+"/include/libc");
ldopts.emplace_back("-L"+sysroot_opt+"/lib");
#ifndef __APPLE__
ldopts.emplace_back("-L"+sysroot_opt+"/lib64");
#endif
}
else {
copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx");
copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc");
copts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include");
copts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../");
agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libcxx");
agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include/libc");
agopts.emplace_back("-I"+eosio::cdt::whereami::where()+"/../include");
agopts.emplace_back("--sysroot="+eosio::cdt::whereami::where()+"/../");
ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib");
#ifndef __APPLE__
ldopts.emplace_back("-L"+eosio::cdt::whereami::where()+"/../lib64");
#endif
}
if (!isystem_opt.empty()) {
copts.emplace_back("-isystem="+isystem_opt);
}
if (CC_opt) {
copts.emplace_back("-CC");
}
if (C_opt) {
copts.emplace_back("-C");
}
copts.emplace_back("-c");
if (c_opt) {
link = false;
}
if (dD_opt) {
copts.emplace_back("-dD");
}
if (dI_opt) {
copts.emplace_back("-dI");
}
if (dM_opt) {
copts.emplace_back("-dM");
}
for ( auto define : D_opt ) {
copts.emplace_back("-D"+define);
}
if (emit_ast_opt) {
copts.emplace_back("-emit-ast");
}
if (emit_llvm_opt) {
copts.emplace_back("-emit-llvm");
}
if (E_opt) {
link = false;
copts.emplace_back("-E");
}
if(g_opt)
copts.emplace_back("-g");
if (color_diag_opt) {
copts.emplace_back("-fcolor-diagnostics");
}
if (!MF_opt.empty()) {
copts.emplace_back("-MF "+MF_opt);
}
if (MD_opt) {
copts.emplace_back("-MD");
}
if (MMD_opt) {
copts.emplace_back("-MMD");
}
if (!MT_opt.empty()) {
copts.emplace_back("-MT "+MT_opt);
}
if (finline_functions_opt) {
copts.emplace_back("-finline-functions");
}
if (finline_hint_functions_opt) {
copts.emplace_back("-finline-hint-functions");
}
if (fmerge_all_constants_opt) {
copts.emplace_back("-fmerge-all-constants");
}
if (fstack_protector_all_opt) {
copts.emplace_back("-fstack-protector-all");
}
if (fstack_protector_strong_opt) {
copts.emplace_back("-fstack-protector-strong");
}
if (fstack_protector_opt) {
copts.emplace_back("-fstack-protector");
}
if (fstrict_enums_opt) {
copts.emplace_back("-fstrict-enums");
}
if (fstrict_return_opt) {
copts.emplace_back("-fstrict-return");
}
for ( auto include : include_opt ) {
copts.emplace_back("-include="+include);
agopts.emplace_back("-include="+include);
}
for ( auto inc_dir : I_opt ) {
copts.emplace_back("-I"+inc_dir);
agopts.emplace_back("-I"+inc_dir);
}
if (O_opt.empty() && !g_opt) {
copts.emplace_back("-O3");
}
else if (!O_opt.empty() && !g_opt) {
copts.emplace_back("-O"+O_opt);
}
if (S_opt) {
copts.emplace_back("-S");
link = false;
}
if (llvm_ir_opt) {
copts.emplace_back("-S");
copts.emplace_back("-emit-llvm");
link = false;
}
if (v_opt) {
copts.emplace_back("-v");
}
if (w_opt) {
copts.emplace_back("-w");
}
for ( auto warn : W_opt ) {
copts.emplace_back("-W"+warn);
}
#endif
if (!fnative_opt) {
#ifdef ONLY_LD
if (!fno_stack_first_opt) {
ldopts.emplace_back("-stack-first");
}
if (fno_lto_opt) {
ldopts.emplace_back("--lto-O0");
if (!lto_opt_opt.empty())
std::cerr << "Warning : lto disabled but lto optimization level given\n";
}
else if (!lto_opt_opt.empty()) {
ldopts.emplace_back("--lto-"+lto_opt_opt);
}
else {
ldopts.emplace_back("--lto-O3");
}
#else
if (fno_stack_first_opt) {
ldopts.emplace_back("-fno-stack-first");
}
if (fno_lto_opt) {
ldopts.emplace_back("-fno-lto-opt");
}
else if (!lto_opt_opt.empty()) {
ldopts.emplace_back("-lto-opt="+lto_opt_opt);
}
#endif
}
for ( auto lib_dir : L_opt ) {
ldopts.emplace_back("-L"+lib_dir);
}
for ( auto library : l_opt ) {
ldopts.emplace_back("-l"+library);
}
if (o_opt.empty()) {
#ifndef ONLY_LD
ldopts.emplace_back("a.out");
#endif
ldopts.emplace_back("-o a.out");
output_fn = "a.out";
}
else {
ldopts.emplace_back("-o "+o_opt);
output_fn = o_opt;
}
if (!fnative_opt) {
#ifndef ONLY_LD
if (!eosio_imports_opt.empty()) {
ldopts.emplace_back("-eosio-imports="+eosio_imports_opt);
}
#else
if (!eosio_imports_opt.empty()) {
ldopts.emplace_back("--allow-undefined-file="+eosio_imports_opt);
}
else {
ldopts.emplace_back("--allow-undefined-file="+eosio::cdt::whereami::where()+"/../eosio.imports");
}
#endif
}
#ifndef ONLY_LD
#ifdef CPP_COMP
if (! std_opt.empty()) {
copts.emplace_back("--std="+std_opt);
agopts.emplace_back("--std="+std_opt);
} else {
copts.emplace_back("--std=c++17");
agopts.emplace_back("--std=c++17");
}
if (faligned_allocation_opt) {
copts.emplace_back("-faligned-allocation");
agopts.emplace_back("-faligned-allocation");
}
if (fcoroutine_ts_opt) {
copts.emplace_back("-fcoroutine-ts");
agopts.emplace_back("-fcoroutine-ts");
}
if (fno_elide_constructors_opt) {
copts.emplace_back("-fno-elide-constructors");
agopts.emplace_back("-fno-elide-constructors");
}
if (fstrict_vtable_pointers_opt) {
copts.emplace_back("-fstrict-vtable-pointers");
agopts.emplace_back("-fstrict-vtable-pointers");
}
#endif
if (!contract_name.empty())
abigen_contract = contract_name;
else {
std::string fn = llvm::sys::path::filename(output_fn);
abigen_contract = fn.substr(0, fn.rfind(".wasm"));
}
for ( auto resource : resources ) {
agresources.emplace_back(std::string("-R")+resource);
}
if (fnative_opt)
ldopts.emplace_back("-fnative");
if (fuse_main_opt)
ldopts.emplace_back("-fuse-main");
#else
if (fnative_opt)
ldopts.emplace_back("-lnative_c++ -lnative_c -lnative_eosio -lnative");
else {
ldopts.emplace_back("-lc++ -lc -leosio");
if (use_old_malloc_opt)
ldopts.emplace_back("-leosio_malloc");
else
ldopts.emplace_back("-leosio_dsm");
if (fquery_opt) {
ldopts.emplace_back("--export-table");
ldopts.emplace_back("--only-export \"*:table\"");
// fill in other exports for "entry points"
//ldopts.emplace_back("--export ");
//ldopts.emplace_back("--only-export \":function\"");
} else {
ldopts.emplace_back("--only-export \"apply:function\"");
}
}
if ((use_rt_opt && !fnative_opt) || fquery_opt)
ldopts.emplace_back("-lrt -lsf");
#endif
return {output_fn, inputs, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, fnative_opt};
}