diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2021-01-13 21:25:20 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2021-01-13 21:25:20 +0800 |
commit | b3a39d99c1d6f45890dbac33a9d17c8dd464654e (patch) | |
tree | 8dd6eab91e751b6ead8d1066bff353f5a0a28810 | |
parent | bc94b7de4614100b63e17a50692a23feab1c139f (diff) | |
parent | 05b9f235566d7d361709c5bc44e7c36598515946 (diff) | |
download | gcc-b3a39d99c1d6f45890dbac33a9d17c8dd464654e.zip gcc-b3a39d99c1d6f45890dbac33a9d17c8dd464654e.tar.gz gcc-b3a39d99c1d6f45890dbac33a9d17c8dd464654e.tar.bz2 |
Merge branch 'master' of https://github.com/redbrain/gccrs
-rw-r--r-- | README.md | 40 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 18 |
2 files changed, 36 insertions, 22 deletions
@@ -1,22 +1,22 @@ - +   [](https://gcc-rust.zulipchat.com/) # GCC Rust  -This is a full alternative implementaion of the Rust language ontop of GCC which the goal +gccrs is a full alternative implementation of the Rust language ontop of GCC with the goal to become fully upstream with the GNU toolchain. The origin of this project was a community effort several years ago where Rust was still at version 0.9; the language was subject to so much change that it became difficult for a community effort to play catch up. -Now that the language is in a stable state, it is a good time to create alternative compilers. The developers of +Now that the language is stable, it is an excellent time to create alternative compilers. The developers of the project are keen “Rustaceans” with a desire to give back to the Rust community and to learn what GCC is capable of when it comes to a modern language. -## Development Enviroment +## Development Environment -Fetch dependancies for ubuntu: +Fetch dependencies for Ubuntu: ```bash $ apt install build-essential libgmp3-dev libmpfr-dev libmpc-dev flex bison autogen gcc-multilib dejagnu @@ -28,8 +28,8 @@ Clone the repository $ git clone git@github.com:Rust-GCC/gccrs.git ``` -Compilation script. It is important to remember that GNU toolchain projects are designed to be built outside of its source directory -this is why a build directory is created. +Compilation script. It is important to remember that GNU toolchain projects are designed to be built outside of their source directory +which is why a build directory is created. ```bash $ mkdir gccrs-build @@ -40,33 +40,33 @@ $ make Running the compiler itself without make install we can simply invoke the compiler proper: -``` +```bash $ gdb --args ./gcc/rust1 test.rs -frust-dump-parse -Warray-bounds -dumpbase test.rs -mtune=generic -march=x86-64 -O0 -version -fdump-tree-gimple -o test.s -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 ``` To invoking the compiler driver (gccrs) we need to: -``` +```bash $ make install ``` Then invoke the compiler as expected: -``` +```bash $ gccrs -g -O2 -c test.rs -o test.o $ gccrs -o test test.o ``` ## Testsuite -The test suite can be invoked via: +Invoke the test suite via: -``` +```bash $ make check-rust ``` -Test cases can be found within gcc/testsuite/rust.test please feel free to contribute your specific -test cases referencing any issues on github. +Test cases are located within [gcc/testsuite/rust.test](gcc/testsuite/rust.test) please feel free to contribute your specific +test cases referencing any issues on Github. ## Docker image @@ -74,13 +74,13 @@ There is a docker image hosted over on: https://hub.docker.com/repository/docker/philberty/gccrs -``` +```bash $ docker pull philberty/gccrs ``` Or you can build your own image: -``` +```bash $ docker build . -t gccrs-dev $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \ gccrs-dev:latest gccrs -g -O2 -c \ @@ -89,14 +89,14 @@ $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp \ ## Contributing -Please be aware this project is designed to be pushed upstream to GCC when we reach some milestones and this means we require -contribtions to have copyright assignment in place. Please see: https://gcc.gnu.org/contribute.html +Please be aware this project is designed to be pushed upstream to GCC when we reach some milestones, and this means we require +contributions to have copyright assignment in place. Please see https://gcc.gnu.org/contribute.html. -Not all contributions must be code, we would love to see new test cases or bugs and issues to be reported. Feel free to add any comments on open PRs +Not all contributions must be code; we would love to see new test cases or bugs and issues to be reported. Feel free to add any comments on open PRs ## Community -We can be found on all usual Rust channels such as Zulip but we also have our own channels: +We can be found on all usual Rust channels such as Zulip, but we also have our own channels: * GCC Rust Zulip: https://gcc-rust.zulipchat.com/ * Twitter: https://twitter.com/gcc_rust diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index e042ccb..c5fe9a2 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -138,10 +138,24 @@ public: // convert to the actual function type auto compiled_fn_type = TyTyCompile::compile (ctx->get_backend (), fnType); + unsigned int flags = 0; + bool is_main_fn = function.function_name.compare ("main") == 0; + + // if its the main fn or pub visibility mark its as DECL_PUBLIC + // please see https://github.com/Rust-GCC/gccrs/pull/137 + if (is_main_fn || function.has_visibility ()) + flags |= Backend::function_is_visible; + + std::string asm_name = function.function_name; + if (!is_main_fn) + { + // FIXME need name mangling + asm_name = "__" + function.function_name; + } + Bfunction *fndecl = ctx->get_backend ()->function (compiled_fn_type, function.function_name, - "" /* asm_name */, 0 /* flags */, - function.get_locus ()); + asm_name, flags, function.get_locus ()); ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl); // setup the params |