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

Add-M flag to eosio-cc and eosio-cpp #763

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tools/cc/eosio-cc.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ int main(int argc, const char **argv) {
std::string tmp_file = std::string(res.c_str())+"/"+input+"-tmp.c";
std::string output;

auto src = SmallString<64>(input);
llvm::sys::path::remove_filename(src);
std::string source_path = src.str().empty() ? "." : src.str();
new_opts.insert(new_opts.begin(), "-I" + source_path);
if (!opts.no_outputs) {
auto src = SmallString<64>(input);
llvm::sys::path::remove_filename(src);
std::string source_path = src.str().empty() ? "." : src.str();
new_opts.insert(new_opts.begin(), "-I" + source_path);
}

output = tmp_file+".o";

Expand All @@ -58,8 +60,11 @@ int main(int argc, const char **argv) {
output = opts.output_fn.empty() ? "a.out" : opts.output_fn;
}

new_opts.insert(new_opts.begin(), "-o"+output);
outputs.push_back(output);
if (!opts.no_outputs) {
new_opts.insert(new_opts.begin(), "-o"+output);
outputs.push_back(output);
}

if (!eosio::cdt::environment::exec_subprogram("clang-7", new_opts)) {
llvm::sys::fs::remove(tmp_file);
return -1;
Expand Down
17 changes: 11 additions & 6 deletions tools/cc/eosio-cpp.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,13 @@ int main(int argc, const char **argv) {
tool_opts.end());
generate(tool_opts, input, opts.abigen_contract, opts.abigen_resources, opts.abigen);

auto src = SmallString<64>(input);
llvm::sys::path::remove_filename(src);
std::string source_path = src.str().empty() ? "." : src.str();
new_opts.insert(new_opts.begin(), "-I" + source_path);
if (!opts.no_outputs) {
auto src = SmallString<64>(input);
llvm::sys::path::remove_filename(src);
std::string source_path = src.str().empty() ? "." : src.str();
new_opts.insert(new_opts.begin(), "-I" + source_path);
}


if (llvm::sys::fs::exists(tmp_file)) {
input = tmp_file;
Expand All @@ -205,8 +208,10 @@ int main(int argc, const char **argv) {
output = opts.output_fn.empty() ? "a.out" : opts.output_fn;
}

new_opts.insert(new_opts.begin(), {"-o", output});
outputs.push_back(output);
if (!opts.no_outputs) {
new_opts.insert(new_opts.begin(), {"-o", output});
outputs.push_back(output);
}
}
new_opts.insert(new_opts.begin(), input);

Expand Down
14 changes: 12 additions & 2 deletions tools/include/compiler_options.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ static cl::opt<bool> MMD_opt(
"MMD",
cl::desc("Write depfile containing user"),
cl::cat(EosioCompilerToolCategory));
static cl::opt<bool> M_opt(
"M",
cl::desc("Like -MD, but also implies -E and writes to stdout by default"),
cl::cat(EosioCompilerToolCategory));
static cl::list<std::string> resources(
"R",
cl::Prefix,
Expand Down Expand Up @@ -355,6 +359,7 @@ struct Options {
bool link;
bool abigen;
bool pp_only;
bool no_outputs;
std::string eosio_pp_dir;
std::string abigen_output;
std::string abigen_contract;
Expand Down Expand Up @@ -508,6 +513,7 @@ static Options CreateOptions(bool add_defaults=true) {
std::vector<std::string> agopts;
bool link = true;
bool debug = false;
bool no_outputs = false;
std::string pp_dir;
std::string abigen_output;
std::string abigen_contract;
Expand Down Expand Up @@ -633,6 +639,10 @@ static Options CreateOptions(bool add_defaults=true) {
if (!MT_opt.empty()) {
copts.emplace_back("-MT "+MT_opt);
}
if (M_opt) {
copts.emplace_back("-M ");
no_outputs = true;
}
if (finline_functions_opt) {
copts.emplace_back("-finline-functions");
}
Expand Down Expand Up @@ -862,8 +872,8 @@ static Options CreateOptions(bool add_defaults=true) {
#endif

#ifndef ONLY_LD
return {output_fn, inputs, link, abigen, pp_only, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt};
return {output_fn, inputs, link, abigen, pp_only, no_outputs, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt};
#else
return {output_fn, {}, link, abigen, pp_only, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt};
return {output_fn, {}, link, abigen, pp_only, no_outputs, pp_dir, abigen_output, abigen_contract, copts, ldopts, agopts, agresources, debug, fnative_opt};
#endif
}