Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

Commit

Permalink
Fix abi generation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
conr2d committed Sep 6, 2021
1 parent 0483923 commit 5a6ec90
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
2 changes: 1 addition & 1 deletion modules/EosioCDTMacros.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro(add_contract CONTRACT_NAME TARGET)
add_executable( ${TARGET} ${ARGN} )
get_target_property(BINOUTPUT ${TARGET} BINARY_DIR)
target_compile_definitions( ${TARGET} PUBLIC BLANC_CONTRACT=${CONTRACT_NAME} )
target_compile_definitions( ${TARGET} PUBLIC EOSIO_CONTRACT=${CONTRACT_NAME} )
endmacro()
macro (target_ricardian_directory TARGET DIR)
target_compile_options( ${TARGET} PUBLIC -R${DIR} )
Expand Down
3 changes: 3 additions & 0 deletions plugins/eosio/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ class eosio_codegen_visitor : public RecursiveASTVisitor<eosio_codegen_visitor>,
ss << "\n\n#include <eosio/datastream.hpp>\n";
ss << "#include <eosio/name.hpp>\n";
ss << "extern \"C\" {\n";
ss << " [[clang::import_name(\"action_data_size\")]]\n";
ss << " uint32_t action_data_size();\n";
ss << " [[clang::import_name(\"read_action_data\")]]\n";
ss << " uint32_t read_action_data(void*, uint32_t);\n";
const auto& return_ty = decl->getReturnType().getAsString();
if (return_ty != "void")
ss << " [[clang::import_name(\"set_action_return_value\")]]\n";
ss << " void set_action_return_value(void*, size_t);\n";
ss << " __attribute__((weak))\n";
ss << " void " << func_name << nm << "(unsigned long long r, unsigned long long c) {\n";
Expand Down
12 changes: 6 additions & 6 deletions tools/include/eosio/abigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,11 @@ namespace eosio { namespace cdt {
for (const auto& arg : tokenize(args[0])) {
if (arg.starts_with("contract=")) {
abigen::get().set_contract_name(arg.substr(arg.find("=")+1));
} else if (arg == "abi_version=") {
} else if (arg.starts_with("abi_version=")) {
auto str = arg.substr(arg.find("=")+1);
float tmp;
int abi_version_major = std::stoi(str);
int abi_version_minor = (int)(std::modf(std::stof(str), nullptr) * 10);
int abi_version_minor = (int)(std::modf(std::stof(str), &tmp) * 10);
abigen::get().set_abi_version(abi_version_major, abi_version_minor);
} else if (arg == "no_abigen") {
abigen::get().no_abigen = true;
Expand All @@ -887,10 +888,9 @@ namespace eosio { namespace cdt {
} else {
return false;
}

if (resource_dirs.size()) {
abigen::get().set_resource_dirs(resource_dirs);
}
}
if (resource_dirs.size()) {
abigen::get().set_resource_dirs(resource_dirs);
}
return true;
}
Expand Down
55 changes: 36 additions & 19 deletions tools/src/cc.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ std::vector<std::string> new_inputs;
std::string output;
std::vector<std::string> resource_dirs;
std::set<std::string> include_dirs;
bool link = true;

std::string contract_name;
std::string abi_version;
Expand Down Expand Up @@ -138,6 +139,10 @@ std::vector<std::string> override_compile_options(InputArgList& Args) {
output = fn.str().str();
}

if (Args.hasArgNoClaim(OPT_c, OPT_fsyntax_only, OPT_E)) {
link = false;
}

if (auto arg = Args.getLastArgNoClaim(OPT_contract)) {
contract_name = arg->getValue();
Args.eraseArg(OPT_contract);
Expand All @@ -146,33 +151,45 @@ std::vector<std::string> override_compile_options(InputArgList& Args) {
llvm::sys::path::replace_extension(fn, "");
contract_name = fn.str().str();
}
// XXX: workaround fix for ide
auto defs = Args.filtered(OPT_D);
for (const auto& arg : defs) {
std::string def(arg->getValue());
auto found = 0;
if (def.starts_with("BLANC_CONTRACT=")) {
contract_name = def.substr(def.find("=")+1);
found++;
} else if (def.starts_with("BLANC_PROFILE=")) {
_profile = to_profile(def.substr(def.find("=")+1));
found++;
}
if (found >= 2) {
break;
}
}

if (auto arg = Args.getLastArgNoClaim(OPT_abi_version)) {
abi_version = arg->getValue();
new_opts.emplace_back("-Wl,--abi_version="+abi_version);
if (link) {
new_opts.emplace_back("-Wl,--abi-version="+abi_version);
}
}
if (Args.hasArgNoClaim(OPT_no_abigen)) {
no_abigen = true;
new_opts.emplace_back("-Wl,--no-abigen");
if (link) {
new_opts.emplace_back("-Wl,--no-abigen");
}
}
if (Args.hasArgNoClaim(OPT_no_missing_ricardian_clause)) {
suppress_ricardian_warnings = true;
}
// XXX: workaround fix for ide
auto defs = Args.filtered(OPT_D);
for (const auto& arg : defs) {
std::string def(arg->getValue());
if (def.starts_with("BLANC_PROFILE=")) {
_profile = to_profile(def.substr(def.find("=")+1));
} else if (def.starts_with("EOSIO_CONTRACT=")) {
contract_name = def.substr(def.find("=")+1);
} else if (def.starts_with("EOSIO_ABI_VERSION=")) {
abi_version = def.substr(def.find("=")+1);
if (link) {
new_opts.emplace_back("-Wl,--abi-version="+abi_version);
}
} else if (def.starts_with("EOSIO_NO_ABIGEN")) {
no_abigen = true;
if (link) {
new_opts.emplace_back("-Wl,--no-abigen");
}
} else if (def.starts_with("EOSIO_NO_RICARDIAN")) {
suppress_ricardian_warnings = true;
}
}

auto resource_args = Args.filtered(OPT_R_Joined);
for (const auto& arg : resource_args) {
resource_dirs.emplace_back(arg->getValue());
Expand Down Expand Up @@ -340,7 +357,7 @@ int main(int argc, const char** argv) {
}
#endif

if (is_wasm_target && !Args.hasArgNoClaim(OPT_c, OPT_fsyntax_only, OPT_E)) {
if (is_wasm_target && link) {
args.insert(args.begin(), "-fuse-ld="+eosio::cdt::whereami::where()+"/"+LINKER_NAME);
args.emplace_back("-Wl,--profile="+std::to_string(_profile));
if (output.size()) {
Expand Down
3 changes: 2 additions & 1 deletion tools/src/ld.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ std::vector<std::string> override_link_options(InputArgList& Args) {
}
if (auto arg = Args.getLastArgNoClaim(OPT_abi_version)) {
std::string abi_version = arg->getValue();
float tmp;
abi_version_major = std::stoi(abi_version);
abi_version_minor = (int)(std::modf(std::stof(abi_version), nullptr) * 10);
abi_version_minor = (int)(std::modf(std::stof(abi_version), &tmp) * 10);
}
new_opts.emplace_back("-export=__heap_base");
new_opts.emplace_back("-export=__data_end");
Expand Down

0 comments on commit 5a6ec90

Please sign in to comment.