Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Commit 056890e

Browse files
authored
Merge pull request #426 from EOSIO/quick_fixes
Quick fixes
2 parents 6517123 + fcaa3bd commit 056890e

File tree

4 files changed

+88
-63
lines changed

4 files changed

+88
-63
lines changed

eosio_llvm

tools/cc/eosio-cpp.cpp.in

+8-10
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,15 @@ void generate(const std::vector<std::string>& base_options, std::string input, s
156156
finder.addMatcher(class_tmp_matcher, &eosio_record_matcher);
157157

158158
int tool_run = -1;
159-
if (abigen) {
160-
tool_run = ctool.run(newFrontendActionFactory(&finder).get());
161-
if (tool_run != 0) {
162-
throw std::runtime_error("abigen error");
163-
}
164-
std::string abi_s;
165-
if (get_abigen_ref().is_empty())
166-
return;
167-
get_abigen_ref().to_json().dump(abi_s);
168-
codegen::get().set_abi(abi_s);
159+
tool_run = ctool.run(newFrontendActionFactory(&finder).get());
160+
if (tool_run != 0) {
161+
throw std::runtime_error("abigen error");
169162
}
163+
std::string abi_s;
164+
if (get_abigen_ref().is_empty())
165+
return;
166+
get_abigen_ref().to_json().dump(abi_s);
167+
codegen::get().set_abi(abi_s);
170168
tool_run = ctool.run(newFrontendActionFactory<eosio_codegen_frontend_action>().get());
171169
if (tool_run != 0) {
172170
throw std::runtime_error("codegen error");

tools/include/compiler_options.hpp.in

+66-37
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55
#include <string>
66
#include "llvm/Support/FileSystem.h"
7+
#include "llvm/Support/Path.h"
78

89
#ifdef ONLY_LD
910
#define LD_CAT EosioLdToolCategory
@@ -400,24 +401,52 @@ static void GetCompDefaults(std::vector<std::string>& copts) {
400401
#ifdef ONLY_LD
401402
static void GetLdDefaults(std::vector<std::string>& ldopts) {
402403
if (!fnative_opt) {
403-
if (fuse_main_opt)
404-
ldopts.emplace_back("-e main");
405-
else {
406-
if (fquery_opt) {
407-
// fill in base entry point for query wasm
408-
ldopts.emplace_back("-e apply");
409-
} else
410-
ldopts.emplace_back("-e apply");
411-
}
412404
ldopts.emplace_back("--gc-sections");
413405
ldopts.emplace_back("--strip-all");
414406
ldopts.emplace_back("-zstack-size="+std::string("${EOSIO_STACK_SIZE}"));
415407
ldopts.emplace_back("--merge-data-segments");
408+
if (fquery_opt) {
409+
ldopts.emplace_back("--export-table");
410+
ldopts.emplace_back("-other-model");
411+
ldopts.emplace_back("--only-export \"*:table\"");
412+
ldopts.emplace_back("--only-export \"*:memory\"");
413+
if (fuse_main_opt)
414+
ldopts.emplace_back("-e main");
415+
else
416+
ldopts.emplace_back("-e initialize ");
417+
ldopts.emplace_back("-export startup ");
418+
ldopts.emplace_back("-export create_request ");
419+
ldopts.emplace_back("-export decode_response ");
420+
ldopts.emplace_back("-export describe_request ");
421+
ldopts.emplace_back("-export describe_response ");
422+
ldopts.emplace_back("--only-export \"initialize:function\"");
423+
ldopts.emplace_back("--only-export \"startup:function\"");
424+
ldopts.emplace_back("--only-export \"create_request:function\"");
425+
ldopts.emplace_back("--only-export \"decode_response:function\"");
426+
ldopts.emplace_back("--only-export \"describe_request:function\"");
427+
ldopts.emplace_back("--only-export \"describe_response:function\"");
428+
} else {
429+
if (fuse_main_opt)
430+
ldopts.emplace_back("-e main");
431+
else
432+
ldopts.emplace_back("-e apply");
433+
ldopts.emplace_back("--only-export \"apply:function\"");
434+
}
435+
ldopts.emplace_back("-lc++ -lc -leosio");
436+
if (use_old_malloc_opt)
437+
ldopts.emplace_back("-leosio_malloc");
438+
else
439+
ldopts.emplace_back("-leosio_dsm");
440+
441+
if (use_rt_opt || fquery_opt)
442+
ldopts.emplace_back("-lrt -lsf");
443+
416444
} else {
417445
#ifdef __APPLE__
418446
ldopts.emplace_back("-arch x86_64 -macosx_version_min 10.13 -framework Foundation -framework System");
419447
#endif
420448
ldopts.emplace_back("-static");
449+
ldopts.emplace_back("-lnative_c++ -lnative_c -lnative_eosio -lnative");
421450
}
422451
}
423452
#endif
@@ -448,6 +477,11 @@ static Options CreateOptions(bool add_defaults=true) {
448477
GetLdDefaults(ldopts);
449478
#endif
450479
}
480+
481+
#ifndef ONLY_LD
482+
if (fquery_opt)
483+
ldopts.emplace_back("-fquery");
484+
#endif
451485

452486
if (!pp_path_opt.empty())
453487
pp_dir = pp_path_opt;
@@ -677,10 +711,27 @@ static Options CreateOptions(bool add_defaults=true) {
677711
}
678712
if (o_opt.empty()) {
679713
#ifndef ONLY_LD
680-
ldopts.emplace_back("a.out");
714+
if (inputs.size() == 1) {
715+
llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]);
716+
llvm::SmallString<256> fn2 = fn;
717+
llvm::sys::path::replace_extension(fn, ".wasm");
718+
output_fn = fn.str();
719+
llvm::SmallString<256> res;
720+
llvm::sys::path::system_temp_directory(true, res);
721+
ldopts.emplace_back(std::string(std::string(res.str())+"/"+std::string(fn2.str())+".o"));
722+
} else {
723+
ldopts.emplace_back("a.out");
724+
}
681725
#endif
682-
ldopts.emplace_back("-o a.out");
683-
output_fn = "a.out";
726+
if (inputs.size() == 1) {
727+
llvm::SmallString<256> fn = llvm::sys::path::filename(inputs[0]);
728+
llvm::sys::path::replace_extension(fn, ".wasm");
729+
ldopts.emplace_back("-o "+output_fn);
730+
output_fn = fn.str();
731+
} else {
732+
ldopts.emplace_back("-o a.out");
733+
output_fn = "a.out";
734+
}
684735
}
685736
else {
686737
ldopts.emplace_back("-o "+o_opt);
@@ -733,8 +784,9 @@ static Options CreateOptions(bool add_defaults=true) {
733784
if (!contract_name.empty())
734785
abigen_contract = contract_name;
735786
else {
736-
std::string fn = llvm::sys::path::filename(output_fn);
737-
abigen_contract = fn.substr(0, fn.rfind(".wasm"));
787+
llvm::SmallString<256> fn = llvm::sys::path::filename(output_fn);
788+
llvm::sys::path::replace_extension(fn, "");
789+
abigen_contract = fn.str();
738790
}
739791

740792
for ( auto resource : resources ) {
@@ -744,29 +796,6 @@ static Options CreateOptions(bool add_defaults=true) {
744796
ldopts.emplace_back("-fnative");
745797
if (fuse_main_opt)
746798
ldopts.emplace_back("-fuse-main");
747-
#else
748-
if (fnative_opt)
749-
ldopts.emplace_back("-lnative_c++ -lnative_c -lnative_eosio -lnative");
750-
else {
751-
ldopts.emplace_back("-lc++ -lc -leosio");
752-
if (use_old_malloc_opt)
753-
ldopts.emplace_back("-leosio_malloc");
754-
else
755-
ldopts.emplace_back("-leosio_dsm");
756-
757-
if (fquery_opt) {
758-
ldopts.emplace_back("--export-table");
759-
ldopts.emplace_back("--only-export \"*:table\"");
760-
// fill in other exports for "entry points"
761-
//ldopts.emplace_back("--export ");
762-
//ldopts.emplace_back("--only-export \":function\"");
763-
} else {
764-
ldopts.emplace_back("--only-export \"apply:function\"");
765-
}
766-
767-
}
768-
if ((use_rt_opt && !fnative_opt) || fquery_opt)
769-
ldopts.emplace_back("-lrt -lsf");
770799
#endif
771800
return {output_fn, inputs, link, abigen, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, fnative_opt};
772801
}

tools/include/eosio/codegen.hpp

+13-15
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,19 @@ namespace eosio { namespace cdt {
412412
visitor->get_rewriter().ReplaceText(inc.range,
413413
std::string("\"")+inc.file_name+"\"\n");
414414
}
415-
if (!cg.abi.empty()) {
416-
// generate apply stub with abi
417-
std::stringstream ss;
418-
ss << "extern \"C\" {\n";
419-
ss << "void eosio_assert_code(uint32_t, uint64_t);";
420-
ss << "\t__attribute__((weak, eosio_wasm_entry, eosio_wasm_abi(";
421-
std::string abi = cg.abi;
422-
ss << "\"" << _quoted(abi) << "\"";
423-
ss << ")))\n";
424-
ss << "\tvoid __insert_eosio_abi(unsigned long long r, unsigned long long c, unsigned long long a){";
425-
ss << "eosio_assert_code(false, 1);";
426-
ss << "}\n";
427-
ss << "}";
428-
visitor->get_rewriter().InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(fid), ss.str());
429-
}
415+
// generate apply stub with abi
416+
std::stringstream ss;
417+
ss << "extern \"C\" {\n";
418+
ss << "void eosio_assert_code(uint32_t, uint64_t);";
419+
ss << "\t__attribute__((weak, eosio_wasm_entry, eosio_wasm_abi(";
420+
std::string abi = cg.abi;
421+
ss << "\"" << _quoted(abi) << "\"";
422+
ss << ")))\n";
423+
ss << "\tvoid __insert_eosio_abi(unsigned long long r, unsigned long long c, unsigned long long a){";
424+
ss << "eosio_assert_code(false, 1);";
425+
ss << "}\n";
426+
ss << "}";
427+
visitor->get_rewriter().InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(fid), ss.str());
430428
auto& RewriteBuf = visitor->get_rewriter().getEditBuffer(fid);
431429
out << std::string(RewriteBuf.begin(), RewriteBuf.end());
432430
cg.tmp_files.emplace(main_file, fn.str());

0 commit comments

Comments
 (0)