From b239094a513db4be28d34023ad10345c099d4855 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 22 Mar 2019 16:28:00 -0400 Subject: [PATCH 1/4] add back some options to cpp and fix lld --- eosio_llvm | 2 +- tools/include/compiler_options.hpp.in | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/eosio_llvm b/eosio_llvm index 9a9ff09d43..a41b8e7653 160000 --- a/eosio_llvm +++ b/eosio_llvm @@ -1 +1 @@ -Subproject commit 9a9ff09d4302331d3289fdf58a64213506b4aefb +Subproject commit a41b8e7653258a4f1a5911ef28c95672efce051e diff --git a/tools/include/compiler_options.hpp.in b/tools/include/compiler_options.hpp.in index a3e15d9143..c26558f8a6 100644 --- a/tools/include/compiler_options.hpp.in +++ b/tools/include/compiler_options.hpp.in @@ -356,6 +356,8 @@ static void GetCompDefaults(std::vector& copts) { if (!fnative_opt) { copts.emplace_back("--target=wasm32"); copts.emplace_back("-ffreestanding"); + copts.emplace_back("-nostdlib"); + copts.emplace_back("-fno-builtin"); } else { copts.emplace_back("-Wunused-command-line-argument"); #ifdef __APPLE__ @@ -377,8 +379,8 @@ static void GetCompDefaults(std::vector& copts) { 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("-fno-rtti"); copts.emplace_back("-fmodules-ts"); #endif copts.emplace_back("-DBOOST_DISABLE_ASSERTS"); From b29bca5988a0a8c64cc2e1f0c88d5f685f8a9181 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 22 Mar 2019 17:46:14 -0400 Subject: [PATCH 2/4] small fixes for predefined apply --- tools/include/eosio/codegen.hpp | 123 +++++++++++++++++++------------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/tools/include/eosio/codegen.hpp b/tools/include/eosio/codegen.hpp index 2ffefe8925..5a3c80a7a3 100644 --- a/tools/include/eosio/codegen.hpp +++ b/tools/include/eosio/codegen.hpp @@ -149,8 +149,12 @@ namespace eosio { namespace cdt { StringRef main_name; Rewriter rewriter; CompilerInstance* ci; + bool apply_was_found = false; public: + std::vector action_decls; + std::vector notify_decls; + explicit eosio_codegen_visitor(CompilerInstance *CI) : generation_utils([&](){throw cg.codegen_ex;}), ci(CI) { cg.ast_context = &(CI->getASTContext()); @@ -221,56 +225,58 @@ namespace eosio { namespace cdt { template void create_dispatch(const std::string& attr, const std::string& func_name, F&& get_str, CXXMethodDecl* decl) { constexpr static uint32_t max_stack_size = 512; - std::stringstream ss; - codegen& cg = codegen::get(); - std::string nm = decl->getNameAsString()+"_"+decl->getParent()->getNameAsString(); - if (cg.is_eosio_contract(decl, cg.contract_name)) { - if (has_eosiolib) { - ss << "\n\n#include \n"; - ss << "#include \n"; - } else { - ss << "\n\n#include \n"; - ss << "#include \n"; - } - ss << "extern \"C\" {\n"; - ss << "uint32_t action_data_size();\n"; - ss << "uint32_t read_action_data(void*, uint32_t);\n"; - ss << "__attribute__((weak, " << attr << "(\""; - ss << get_str(decl); - ss << ":"; - ss << func_name << nm; - ss << "\"))) void " << func_name << nm << "(unsigned long long r, unsigned long long c) {\n"; - ss << "size_t as = ::action_data_size();\n"; - ss << "void* buff = nullptr;\n"; - ss << "if (as > 0) {\n"; - ss << "buff = as >= " << max_stack_size << " ? malloc(as) : alloca(as);\n"; - ss << "::read_action_data(buff, as);\n"; - ss << "}\n"; - ss << "eosio::datastream ds{(char*)buff, as};\n"; - int i=0; - for (auto param : decl->parameters()) { - clang::LangOptions lang_opts; - lang_opts.CPlusPlus = true; - clang::PrintingPolicy policy(lang_opts); - auto qt = param->getOriginalType().getNonReferenceType(); - qt.removeLocalConst(); - qt.removeLocalVolatile(); - qt.removeLocalRestrict(); - std::string tn = clang::TypeName::getFullyQualifiedName(qt, *(cg.ast_context), policy); - tn = tn == "_Bool" ? "bool" : tn; // TODO look out for more of these oddities - ss << tn << " arg" << i << "; ds >> arg" << i << ";\n"; - i++; - } - ss << decl->getParent()->getQualifiedNameAsString() << "{eosio::name{r},eosio::name{c},ds}." << decl->getNameAsString() << "("; - for (int i=0; i < decl->parameters().size(); i++) { - ss << "arg" << i; - if (i < decl->parameters().size()-1) - ss << ", "; - } - ss << ");"; - ss << "}}\n"; + if (!apply_was_found) { + std::stringstream ss; + codegen& cg = codegen::get(); + std::string nm = decl->getNameAsString()+"_"+decl->getParent()->getNameAsString(); + if (cg.is_eosio_contract(decl, cg.contract_name)) { + if (has_eosiolib) { + ss << "\n\n#include \n"; + ss << "#include \n"; + } else { + ss << "\n\n#include \n"; + ss << "#include \n"; + } + ss << "extern \"C\" {\n"; + ss << "uint32_t action_data_size();\n"; + ss << "uint32_t read_action_data(void*, uint32_t);\n"; + ss << "__attribute__((weak, " << attr << "(\""; + ss << get_str(decl); + ss << ":"; + ss << func_name << nm; + ss << "\"))) void " << func_name << nm << "(unsigned long long r, unsigned long long c) {\n"; + ss << "size_t as = ::action_data_size();\n"; + ss << "void* buff = nullptr;\n"; + ss << "if (as > 0) {\n"; + ss << "buff = as >= " << max_stack_size << " ? malloc(as) : alloca(as);\n"; + ss << "::read_action_data(buff, as);\n"; + ss << "}\n"; + ss << "eosio::datastream ds{(char*)buff, as};\n"; + int i=0; + for (auto param : decl->parameters()) { + clang::LangOptions lang_opts; + lang_opts.CPlusPlus = true; + clang::PrintingPolicy policy(lang_opts); + auto qt = param->getOriginalType().getNonReferenceType(); + qt.removeLocalConst(); + qt.removeLocalVolatile(); + qt.removeLocalRestrict(); + std::string tn = clang::TypeName::getFullyQualifiedName(qt, *(cg.ast_context), policy); + tn = tn == "_Bool" ? "bool" : tn; // TODO look out for more of these oddities + ss << tn << " arg" << i << "; ds >> arg" << i << ";\n"; + i++; + } + ss << decl->getParent()->getQualifiedNameAsString() << "{eosio::name{r},eosio::name{c},ds}." << decl->getNameAsString() << "("; + for (int i=0; i < decl->parameters().size(); i++) { + ss << "arg" << i; + if (i < decl->parameters().size()-1) + ss << ", "; + } + ss << ");"; + ss << "}}\n"; - rewriter.InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(main_fid), ss.str()); + rewriter.InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(main_fid), ss.str()); + } } } @@ -300,7 +306,7 @@ namespace eosio { namespace cdt { } if (cg.actions.count(decl->getNameAsString()) == 0) { if (cg.actions.count(name) == 0) - create_action_dispatch(decl); + action_decls.push_back(decl); else emitError(*ci, decl->getLocation(), "action already defined elsewhere"); } @@ -333,7 +339,7 @@ namespace eosio { namespace cdt { if (cg.notify_handlers.count(decl->getNameAsString()) == 0) { if (cg.notify_handlers.count(name) == 0) - create_notify_dispatch(decl); + notify_decls.push_back(decl); else emitError(*ci, decl->getLocation(), "notification handler already defined elsewhere"); } @@ -351,6 +357,15 @@ namespace eosio { namespace cdt { //cg.cxx_methods.emplace(name, decl); return true; } + + virtual bool VisitDecl(clang::Decl* decl) { + if (auto* fd = dyn_cast(decl)) { + if (fd->getNameInfo().getAsString() == "apply") + apply_was_found = true; + } + return true; + } + /* virtual bool VisitRecordDecl(RecordDecl* decl) { static std::set _action_set; //used for validations @@ -401,6 +416,12 @@ namespace eosio { namespace cdt { visitor->set_main_fid(fid); visitor->set_main_name(main_fe->getName()); visitor->TraverseDecl(Context.getTranslationUnitDecl()); + for (auto ad : visitor->action_decls) + visitor->create_action_dispatch(ad); + + for (auto nd : visitor->notify_decls) + visitor->create_notify_dispatch(nd); + int fd; llvm::SmallString<128> fn; try { From 16d0cfc1ea6a8dbda67bde3c97549961cb1c8cf4 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 22 Mar 2019 18:02:43 -0400 Subject: [PATCH 3/4] revert --- tools/include/eosio/codegen.hpp | 104 ++++++++++++++++---------------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/tools/include/eosio/codegen.hpp b/tools/include/eosio/codegen.hpp index 5a3c80a7a3..28388eecd0 100644 --- a/tools/include/eosio/codegen.hpp +++ b/tools/include/eosio/codegen.hpp @@ -225,58 +225,56 @@ namespace eosio { namespace cdt { template void create_dispatch(const std::string& attr, const std::string& func_name, F&& get_str, CXXMethodDecl* decl) { constexpr static uint32_t max_stack_size = 512; - if (!apply_was_found) { - std::stringstream ss; - codegen& cg = codegen::get(); - std::string nm = decl->getNameAsString()+"_"+decl->getParent()->getNameAsString(); - if (cg.is_eosio_contract(decl, cg.contract_name)) { - if (has_eosiolib) { - ss << "\n\n#include \n"; - ss << "#include \n"; - } else { - ss << "\n\n#include \n"; - ss << "#include \n"; - } - ss << "extern \"C\" {\n"; - ss << "uint32_t action_data_size();\n"; - ss << "uint32_t read_action_data(void*, uint32_t);\n"; - ss << "__attribute__((weak, " << attr << "(\""; - ss << get_str(decl); - ss << ":"; - ss << func_name << nm; - ss << "\"))) void " << func_name << nm << "(unsigned long long r, unsigned long long c) {\n"; - ss << "size_t as = ::action_data_size();\n"; - ss << "void* buff = nullptr;\n"; - ss << "if (as > 0) {\n"; - ss << "buff = as >= " << max_stack_size << " ? malloc(as) : alloca(as);\n"; - ss << "::read_action_data(buff, as);\n"; - ss << "}\n"; - ss << "eosio::datastream ds{(char*)buff, as};\n"; - int i=0; - for (auto param : decl->parameters()) { - clang::LangOptions lang_opts; - lang_opts.CPlusPlus = true; - clang::PrintingPolicy policy(lang_opts); - auto qt = param->getOriginalType().getNonReferenceType(); - qt.removeLocalConst(); - qt.removeLocalVolatile(); - qt.removeLocalRestrict(); - std::string tn = clang::TypeName::getFullyQualifiedName(qt, *(cg.ast_context), policy); - tn = tn == "_Bool" ? "bool" : tn; // TODO look out for more of these oddities - ss << tn << " arg" << i << "; ds >> arg" << i << ";\n"; - i++; - } - ss << decl->getParent()->getQualifiedNameAsString() << "{eosio::name{r},eosio::name{c},ds}." << decl->getNameAsString() << "("; - for (int i=0; i < decl->parameters().size(); i++) { - ss << "arg" << i; - if (i < decl->parameters().size()-1) - ss << ", "; - } - ss << ");"; - ss << "}}\n"; - - rewriter.InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(main_fid), ss.str()); + std::stringstream ss; + codegen& cg = codegen::get(); + std::string nm = decl->getNameAsString()+"_"+decl->getParent()->getNameAsString(); + if (cg.is_eosio_contract(decl, cg.contract_name)) { + if (has_eosiolib) { + ss << "\n\n#include \n"; + ss << "#include \n"; + } else { + ss << "\n\n#include \n"; + ss << "#include \n"; + } + ss << "extern \"C\" {\n"; + ss << "uint32_t action_data_size();\n"; + ss << "uint32_t read_action_data(void*, uint32_t);\n"; + ss << "__attribute__((weak, " << attr << "(\""; + ss << get_str(decl); + ss << ":"; + ss << func_name << nm; + ss << "\"))) void " << func_name << nm << "(unsigned long long r, unsigned long long c) {\n"; + ss << "size_t as = ::action_data_size();\n"; + ss << "void* buff = nullptr;\n"; + ss << "if (as > 0) {\n"; + ss << "buff = as >= " << max_stack_size << " ? malloc(as) : alloca(as);\n"; + ss << "::read_action_data(buff, as);\n"; + ss << "}\n"; + ss << "eosio::datastream ds{(char*)buff, as};\n"; + int i=0; + for (auto param : decl->parameters()) { + clang::LangOptions lang_opts; + lang_opts.CPlusPlus = true; + clang::PrintingPolicy policy(lang_opts); + auto qt = param->getOriginalType().getNonReferenceType(); + qt.removeLocalConst(); + qt.removeLocalVolatile(); + qt.removeLocalRestrict(); + std::string tn = clang::TypeName::getFullyQualifiedName(qt, *(cg.ast_context), policy); + tn = tn == "_Bool" ? "bool" : tn; // TODO look out for more of these oddities + ss << tn << " arg" << i << "; ds >> arg" << i << ";\n"; + i++; } + ss << decl->getParent()->getQualifiedNameAsString() << "{eosio::name{r},eosio::name{c},ds}." << decl->getNameAsString() << "("; + for (int i=0; i < decl->parameters().size(); i++) { + ss << "arg" << i; + if (i < decl->parameters().size()-1) + ss << ", "; + } + ss << ");"; + ss << "}}\n"; + + rewriter.InsertTextAfter(ci->getSourceManager().getLocForEndOfFile(main_fid), ss.str()); } } @@ -306,7 +304,7 @@ namespace eosio { namespace cdt { } if (cg.actions.count(decl->getNameAsString()) == 0) { if (cg.actions.count(name) == 0) - action_decls.push_back(decl); + create_action_dispatch(decl); else emitError(*ci, decl->getLocation(), "action already defined elsewhere"); } @@ -339,7 +337,7 @@ namespace eosio { namespace cdt { if (cg.notify_handlers.count(decl->getNameAsString()) == 0) { if (cg.notify_handlers.count(name) == 0) - notify_decls.push_back(decl); + create_notify_dispatch(decl); else emitError(*ci, decl->getLocation(), "notification handler already defined elsewhere"); } From 9018616bcc1ef18f50e9c16734110aaaa148b751 Mon Sep 17 00:00:00 2001 From: Bucky Kittinger Date: Fri, 22 Mar 2019 18:09:49 -0400 Subject: [PATCH 4/4] Bump version --- CMakeLists.txt | 2 +- README.md | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85d1a62613..5346831d17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ endif() set(VERSION_MAJOR 1) set(VERSION_MINOR 6) -set(VERSION_PATCH 0) +set(VERSION_PATCH 1) #set(VERSION_SUFFIX rc2) if (VERSION_SUFFIX) diff --git a/README.md b/README.md index cd83ee8e78..c0cd29d277 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # EOSIO.CDT (Contract Development Toolkit) -## Version : 1.6.0 +## Version : 1.6.1 EOSIO.CDT is a toolchain for WebAssembly (WASM) and set of tools to facilitate contract writing for the EOSIO platform. In addition to being a general purpose WebAssembly toolchain, [EOSIO](https://github.com/eosio/eos) specific optimizations are available to support building EOSIO smart contracts. This new toolchain is built around [Clang 7](https://github.com/eosio/llvm), which means that EOSIO.CDT has the most currently available optimizations and analyses from LLVM, but as the WASM target is still considered experimental, some optimizations are not available or incomplete. @@ -22,8 +22,8 @@ $ brew remove eosio.cdt ``` #### Debian Package Install ```sh -$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.0/eosio.cdt_1.6.0-1_amd64.deb -$ sudo apt install ./eosio.cdt_1.6.0-1_amd64.deb +$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.1/eosio.cdt_1.6.1-1_amd64.deb +$ sudo apt install ./eosio.cdt_1.6.1-1_amd64.deb ``` #### Debian Package Uninstall ```sh @@ -32,8 +32,8 @@ $ sudo apt remove eosio.cdt #### Fedora RPM Package Install ```sh -$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.0/eosio.cdt-1.6.0-1.fedora-x86_64.rpm -$ sudo yum install ./eosio.cdt-1.6.0-1.fedora-x86_64.rpm +$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.1/eosio.cdt-1.6.1-1.fedora-x86_64.rpm +$ sudo yum install ./eosio.cdt-1.6.1-1.fedora-x86_64.rpm ``` #### Fedora RPM Package Uninstall @@ -43,8 +43,8 @@ $ sudo yum remove eosio.cdt #### Centos RPM Package Install ```sh -$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.0/eosio.cdt-1.6.0-1.centos-x86_64.rpm -$ sudo yum install ./eosio.cdt-1.6.0-1.centos-x86_64.rpm +$ wget https://github.com/eosio/eosio.cdt/releases/download/v1.6.1/eosio.cdt-1.6.1-1.centos-x86_64.rpm +$ sudo yum install ./eosio.cdt-1.6.1-1.centos-x86_64.rpm ``` #### Centos RPM Package Uninstall