Skip to content

Commit

Permalink
Merge commit '2f334bb12e3ba947714771408b9d49d398abb5df' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
tschwinge committed Mar 24, 2024
2 parents 8c40edc + 2f334bb commit f3f2065
Show file tree
Hide file tree
Showing 39 changed files with 2,778 additions and 1,122 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jobs:
build-essential \
gcc-multilib \
g++-multilib \
dejagnu
dejagnu;
# install Rust directly using rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.72.0;
- name: Configure
run: |
Expand All @@ -52,6 +54,8 @@ jobs:
shell: bash
run: |
cd gccrs-build; \
# Add cargo to our path quickly
. "$HOME/.cargo/env";
make -Otarget -j $(nproc) 2>&1 | tee log
- name: Check for new warnings
Expand Down Expand Up @@ -114,7 +118,9 @@ jobs:
build-essential \
gcc-multilib \
g++-multilib \
dejagnu
dejagnu;
# install Rust directly using rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.72.0;
- name: Configure
run: |
Expand All @@ -129,6 +135,8 @@ jobs:
shell: bash
run: |
cd gccrs-build; \
# Add cargo to our path quickly
. "$HOME/.cargo/env";
make -Otarget -j $(nproc) 2>&1 | tee log
- name: Check for new warnings
Expand Down Expand Up @@ -178,6 +186,7 @@ jobs:
run: |
apt-get update;
apt-get install -y \
curl \
automake \
autoconf \
libtool \
Expand All @@ -192,8 +201,9 @@ jobs:
g++-4.8 \
gcc-4.8-multilib \
g++-4.8-multilib \
dejagnu \
cargo
dejagnu;
# install Rust directly using rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.72.0;
- name: Configure
run: |
Expand All @@ -209,6 +219,8 @@ jobs:
- name: Build
shell: bash
run: |
# Add cargo to our path quickly
. "$HOME/.cargo/env";
make -C gccrs-build -j $(nproc)
- name: Run Tests
Expand Down Expand Up @@ -248,7 +260,9 @@ jobs:

- name: Install Deps
run: |
brew install dejagnu mpfr libmpc gmp
brew install dejagnu mpfr libmpc gmp;
# install Rust directly using rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain=1.72.0;
- name: Configure
run: |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $ make
Running the compiler itself without make install we can simply invoke the compiler proper:

```bash
$ ./gcc/crab1 test.rs -frust-debug -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 -frust-incomplete-and-experimental-compiler-do-not-use
$ ./gcc/crab1 test.rs -frust-debug -frust-dump-ast-pretty -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 -frust-incomplete-and-experimental-compiler-do-not-use
```

To invoke the compiler driver (gccrs) we need to:
Expand Down
13 changes: 12 additions & 1 deletion gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ GRS_OBJS = \
rust/rust-proc-macro-invoc-lexer.o \
rust/rust-macro-substitute-ctx.o \
rust/rust-macro-builtins.o \
rust/rust-macro-builtins-helpers.o \
rust/rust-macro-builtins-asm.o \
rust/rust-macro-builtins-trait.o \
rust/rust-macro-builtins-utility.o \
rust/rust-macro-builtins-log-debug.o \
rust/rust-macro-builtins-test-bench.o \
rust/rust-macro-builtins-format-args.o \
rust/rust-macro-builtins-location.o \
rust/rust-macro-builtins-include.o \
rust/rust-fmt.o \
rust/rust-hir.o \
rust/rust-hir-map.o \
Expand Down Expand Up @@ -147,6 +156,7 @@ GRS_OBJS = \
rust/rust-tyty-util.o \
rust/rust-tyty-call.o \
rust/rust-tyty-subst.o \
rust/rust-tyty-variance-analysis.o \
rust/rust-typecheck-context.o \
rust/rust-tyty-bounds.o \
rust/rust-hir-trait-resolve.o \
Expand Down Expand Up @@ -205,6 +215,7 @@ GRS_OBJS = \
rust/rust-unicode.o \
rust/rust-punycode.o \
rust/rust-lang-item.o \
rust/rust-expand-format-args.o \
$(END)
# removed object files from here

Expand Down Expand Up @@ -406,7 +417,7 @@ rust/%.o: rust/lex/%.cc
$(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
$(POSTCOMPILE)

%.toml:
%.toml:
echo $@

rust/libformat_parser.a: $(srcdir)/../libgrust/libformat_parser/Cargo.toml $(wildcard $(srcdir)/../libgrust/libformat_parser/src/*.rs)
Expand Down
66 changes: 44 additions & 22 deletions gcc/rust/ast/rust-ast-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,73 @@
// <http://www.gnu.org/licenses/>.

#include "rust-ast-builder.h"
#include "rust-ast-full-decls.h"
#include "rust-ast-full.h"
#include "rust-expr.h"
#include "rust-token.h"
#include "rust-make-unique.h"

namespace Rust {
namespace AST {

std::unique_ptr<Expr>
AstBuilder::call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args)
Builder::literal_string (std::string &&content) const
{
return std::unique_ptr<Expr> (
new AST::LiteralExpr (std::move (content), Literal::LitType::STRING,
PrimitiveCoreType::CORETYPE_STR, {}, loc));
}

std::unique_ptr<Expr>
Builder::call (std::unique_ptr<Expr> &&path,
std::vector<std::unique_ptr<Expr>> &&args) const
{
return std::unique_ptr<Expr> (
new CallExpr (std::move (path), std::move (args), {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::identifier (std::string name)
Builder::array (std::vector<std::unique_ptr<Expr>> &&members) const
{
auto elts = Rust::make_unique<ArrayElemsValues> (std::move (members), loc);

return std::unique_ptr<Expr> (new ArrayExpr (std::move (elts), {}, {}, loc));
}

std::unique_ptr<Expr>
Builder::identifier (std::string name) const
{
return std::unique_ptr<Expr> (new IdentifierExpr (name, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::tuple_idx (std::string receiver, int idx)
Builder::tuple_idx (std::string receiver, int idx) const
{
return std::unique_ptr<Expr> (
new TupleIndexExpr (identifier (receiver), idx, {}, loc));
}

FunctionQualifiers
AstBuilder::fn_qualifiers ()
Builder::fn_qualifiers () const
{
return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
}

PathExprSegment
AstBuilder::path_segment (std::string seg)
Builder::path_segment (std::string seg) const
{
return PathExprSegment (PathIdentSegment (seg, loc), loc);
}

std::unique_ptr<TypePathSegment>
AstBuilder::type_path_segment (std::string seg)
Builder::type_path_segment (std::string seg) const
{
return std::unique_ptr<TypePathSegment> (
new TypePathSegment (seg, false, loc));
}

std::unique_ptr<Type>
AstBuilder::single_type_path (std::string type)
Builder::single_type_path (std::string type) const
{
auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
segments.emplace_back (type_path_segment (type));
Expand All @@ -72,7 +92,7 @@ AstBuilder::single_type_path (std::string type)
}

PathInExpression
AstBuilder::path_in_expression (std::vector<std::string> &&segments)
Builder::path_in_expression (std::vector<std::string> &&segments) const
{
auto path_segments = std::vector<PathExprSegment> ();
for (auto &seg : segments)
Expand All @@ -82,69 +102,71 @@ AstBuilder::path_in_expression (std::vector<std::string> &&segments)
}

std::unique_ptr<Expr>
AstBuilder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr)
Builder::block (std::vector<std::unique_ptr<Stmt>> &&stmts,
std::unique_ptr<Expr> &&tail_expr) const
{
return std::unique_ptr<Expr> (new BlockExpr (std::move (stmts),
std::move (tail_expr), {}, {},
LoopLabel::error (), loc, loc));
}

std::unique_ptr<Stmt>
AstBuilder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
std::unique_ptr<Expr> init)
Builder::let (std::unique_ptr<Pattern> pattern, std::unique_ptr<Type> type,
std::unique_ptr<Expr> init) const
{
return std::unique_ptr<Stmt> (new LetStmt (std::move (pattern),
std::move (init), std::move (type),
{}, loc));
}

std::unique_ptr<Expr>
AstBuilder::ref (std::unique_ptr<Expr> &&of, bool mut)
Builder::ref (std::unique_ptr<Expr> &&of, bool mut) const
{
return std::unique_ptr<Expr> (
new BorrowExpr (std::move (of), mut, /* is double */ false, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::deref (std::unique_ptr<Expr> &&of)
Builder::deref (std::unique_ptr<Expr> &&of) const
{
return std::unique_ptr<Expr> (new DereferenceExpr (std::move (of), {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::struct_expr_struct (std::string struct_name)
Builder::struct_expr_struct (std::string struct_name) const
{
return std::unique_ptr<Expr> (
new StructExprStruct (path_in_expression ({struct_name}), {}, {}, loc));
}

std::unique_ptr<Expr>
AstBuilder::struct_expr (std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields)
Builder::struct_expr (
std::string struct_name,
std::vector<std::unique_ptr<StructExprField>> &&fields) const
{
return std::unique_ptr<Expr> (
new StructExprStructFields (path_in_expression ({struct_name}),
std::move (fields), loc));
}

std::unique_ptr<StructExprField>
AstBuilder::struct_expr_field (std::string field_name,
std::unique_ptr<Expr> &&value)
Builder::struct_expr_field (std::string field_name,
std::unique_ptr<Expr> &&value) const
{
return std::unique_ptr<StructExprField> (
new StructExprFieldIdentifierValue (field_name, std::move (value), loc));
}

std::unique_ptr<Expr>
AstBuilder::field_access (std::unique_ptr<Expr> &&instance, std::string field)
Builder::field_access (std::unique_ptr<Expr> &&instance,
std::string field) const
{
return std::unique_ptr<Expr> (
new FieldAccessExpr (std::move (instance), field, {}, loc));
}

std::unique_ptr<Pattern>
AstBuilder::wildcard ()
Builder::wildcard () const
{
return std::unique_ptr<Pattern> (new WildcardPattern (loc));
}
Expand Down
Loading

0 comments on commit f3f2065

Please sign in to comment.