Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Feb 1, 2025
2 parents 4e5fc24 + 9886b73 commit b808668
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CXXFLAGS += -Wno-pessimizing-move
CXXFLAGS += -Wno-misleading-indentation
#CXXFLAGS += -Wno-unused-private-field
#CXXFLAGS += -Wno-unknown-warning-option
#CXXFLAGS += -Wno-unqualified-std-cast-call

CXXFLAGS += -Werror=return-type
CXXFLAGS += -Werror=switch
Expand Down Expand Up @@ -186,7 +187,7 @@ $(OBJDIR)%.o: src/%.cpp
$(OBJDIR)version.o: $(OBJDIR)%.o: src/%.cpp $(filter-out $(OBJDIR)version.o,$(OBJ)) Makefile
@+mkdir -p $(dir $@)
@echo [CXX] -o $@
$V$(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep -D VERSION_GIT_FULLHASH=\"$(shell git show --pretty=%H -s --no-show-signature)\" -D VERSION_GIT_BRANCH="\"$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)\"" -D VERSION_GIT_SHORTHASH=\"$(shell git show -s --pretty=%h --no-show-signature)\" -D VERSION_BUILDTIME="\"$(shell date -uR)\"" -D VERSION_GIT_ISDIRTY=$(shell git diff-index --quiet HEAD; echo $$?)
$V$(CXX) -o $@ -c $< $(CXXFLAGS) $(CPPFLAGS) -MMD -MP -MF $@.dep -D VERSION_GIT_FULLHASH=\"$(shell git show --pretty=%H -s --no-show-signature)\" -D VERSION_GIT_BRANCH="\"$(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)\"" -D VERSION_GIT_SHORTHASH=\"$(shell git show -s --pretty=%h --no-show-signature)\" -D VERSION_BUILDTIME="\"$(shell env LC_TIME=C date -u +"%a, %e %b %Y %T +0000")\"" -D VERSION_GIT_ISDIRTY=$(shell git diff-index --quiet HEAD; echo $$?)

src/main.cpp: $(PCHS:%=src/%.gch)

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Dependencies
------------
- C++14-compatible compiler (tested with gcc 5.4 and gcc 6, and MSVC 2015)
- C11 compatible C compiler (for output, see above)
- `make` (for the mrustc makefiles)
- `patch` (For doing minor edits to the rustc source)
- `libz-dev` (used to reduce size of bytecode files, linux only - windows uses vcpkg to download it)
- `GNU make` (for the mrustc makefiles)
- `patch` (for doing minor edits to the rustc source)
- `libz-dev` (used for reducing the size of bytecode files, linux only - windows uses vcpkg to download it)
- `curl` (for downloading the rust source, linux only)
- `cmake` (at least 3.4.3, required for building llvm in rustc)
- `pkg-config` (required for find crate build deps, i.e libssl)
- `pkg-config` (required for finding crate build deps, i.e libssl)
- `python3` (required for building llvm in rustc)

Linux GNU and macOS
Expand All @@ -56,8 +56,9 @@ Similar to Linux, but you might need to
- specify the rustc default target explicitly
- specify the compiler
- use `gmake` to run GNU make
- use `CC=gcc` or `CC=egcc` if `cc` is `clang`

e.g. `gmake CC=cc RUSTC_TARGET=x86_64-unknown-freebsd -f minicargo.mk`
e.g. `gmake CC=gcc RUSTC_TARGET=x86_64-unknown-freebsd -f minicargo.mk`

Windows
--------
Expand Down
4 changes: 2 additions & 2 deletions TestRustcBootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rm -rf ${WORKDIR}build
#
echo "=== Building rustc bootstrap mrustc stage0"
mkdir -p ${WORKDIR}mrustc/
tar -xf rustc-${RUSTC_VERSION_NEXT}-src.tar.gz -C ${WORKDIR}mrustc/
tar -xzf rustc-${RUSTC_VERSION_NEXT}-src.tar.gz -C ${WORKDIR}mrustc/
cat - > ${WORKDIR}mrustc/rustc-${RUSTC_VERSION_NEXT}-src/config.toml <<EOF
[build]
cargo = "${PREFIX}bin/cargo"
Expand Down Expand Up @@ -81,7 +81,7 @@ mv ${WORKDIR}output ${WORKDIR}mrustc-output
#
echo "=== Building rustc bootstrap downloaded stage0"
mkdir -p ${WORKDIR}official/
tar -xf rustc-${RUSTC_VERSION_NEXT}-src.tar.gz -C ${WORKDIR}official/
tar -xzf rustc-${RUSTC_VERSION_NEXT}-src.tar.gz -C ${WORKDIR}official/
cat - > ${WORKDIR}official/rustc-${RUSTC_VERSION_NEXT}-src/config.toml <<EOF
[build]
full-bootstrap = true
Expand Down
2 changes: 1 addition & 1 deletion minicargo.mk
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ $(RUSTC_SRC_TARBALL):
@rm -f $@
@curl -sS https://static.rust-lang.org/dist/$@ -o $@
rustc-$(RUSTC_VERSION)-src/extracted: $(RUSTC_SRC_TARBALL)
tar -xf $(RUSTC_SRC_TARBALL)
tar -xzf $(RUSTC_SRC_TARBALL)
touch $@
$(RUSTC_SRC_DL): rustc-$(RUSTC_VERSION)-src/extracted rustc-$(RUSTC_VERSION)-src.patch
cd $(RUSTCSRC) && patch -p0 < ../rustc-$(RUSTC_VERSION)-src.patch;
Expand Down
9 changes: 9 additions & 0 deletions src/expand/asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,21 @@ namespace {
ERROR(sp, E0000, "Unknown register for x86/x86-64 - `" << str << "`");
}

AsmCommon::RegisterClass get_reg_class_riscv(const Span &sp, const RcString& str)
{
if(str == "reg" ) return AsmCommon::RegisterClass::riscv_reg;
if(str == "freg" ) return AsmCommon::RegisterClass::riscv_freg;
ERROR(sp, E0000, "Unknown register for riscv64 - `" << str << "`");
}

AsmCommon::RegisterClass get_reg_class(const Span& sp, const RcString& str)
{
if(Target_GetCurSpec().m_arch.m_name == "x86_64")
return get_reg_class_x8664(sp, str);
if(Target_GetCurSpec().m_arch.m_name == "x86")
return get_reg_class_x8664(sp, str);
if (Target_GetCurSpec().m_arch.m_name == "riscv64")
return get_reg_class_riscv(sp, str);
ERROR(sp, E0000, "Unknown architecture for asm!");
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/hir/asm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace AsmCommon {
//nvptx_reg32,
//nvptx_reg64,

//riscv_reg,
//riscv_freg,
riscv_reg,
riscv_freg,

//hexagon_reg,

Expand Down Expand Up @@ -106,6 +106,8 @@ namespace AsmCommon {
case RegisterClass::x86_ymm: return "ymm_reg";
case RegisterClass::x86_zmm: return "zmm_reg";
case RegisterClass::x86_kreg: return "kreg";
case RegisterClass::riscv_reg: return "reg";
case RegisterClass::riscv_freg: return "freg";
}
throw "";
}
Expand Down
1 change: 1 addition & 0 deletions src/parse/expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ bool Parse_IsTokValue(eTokenType tok_type)
case TOK_RWORD_FALSE:
case TOK_RWORD_SELF:
case TOK_RWORD_SUPER:
case TOK_RWORD_CRATE:
case TOK_RWORD_BOX:
case TOK_RWORD_IN:
case TOK_PAREN_OPEN:
Expand Down
8 changes: 8 additions & 0 deletions src/trans/codegen_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5441,13 +5441,17 @@ namespace {
// https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html
switch(c)
{
// x86
case AsmCommon::RegisterClass::x86_reg: m_of << "r"; break;
case AsmCommon::RegisterClass::x86_reg_abcd: m_of << "Q"; break;
case AsmCommon::RegisterClass::x86_reg_byte: m_of << "q"; break;
case AsmCommon::RegisterClass::x86_xmm: m_of << "x"; break;
case AsmCommon::RegisterClass::x86_ymm: m_of << "x"; break;
case AsmCommon::RegisterClass::x86_zmm: m_of << "v"; break;
case AsmCommon::RegisterClass::x86_kreg: m_of << "Yk"; break;
// riscv
case AsmCommon::RegisterClass::riscv_reg: m_of << "r"; break;
case AsmCommon::RegisterClass::riscv_freg: m_of << "f"; break;
}
TU_ARMA(Explicit, name) {
m_of << "r";
Expand Down Expand Up @@ -5478,13 +5482,17 @@ namespace {
TU_ARMA(Class, c)
switch(c)
{
// x86
case AsmCommon::RegisterClass::x86_reg: m_of << "r"; break;
case AsmCommon::RegisterClass::x86_reg_abcd: m_of << "Q"; break;
case AsmCommon::RegisterClass::x86_reg_byte: m_of << "q"; break;
case AsmCommon::RegisterClass::x86_xmm: m_of << "x"; break;
case AsmCommon::RegisterClass::x86_ymm: m_of << "x"; break;
case AsmCommon::RegisterClass::x86_zmm: m_of << "v"; break;
case AsmCommon::RegisterClass::x86_kreg: m_of << "Yk"; break;
// riscv
case AsmCommon::RegisterClass::riscv_reg: m_of << "r"; break;
case AsmCommon::RegisterClass::riscv_freg: m_of << "f"; break;
}
TU_ARMA(Explicit, name) {
auto it = ::std::find(outputs.begin(), outputs.end(), &r);
Expand Down
23 changes: 23 additions & 0 deletions src/trans/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ namespace
{
rv.m_arch = ARCH_M68K;
}
else if( key_val.value.as_string() == ARCH_POWERPC32.m_name )
{
rv.m_arch = ARCH_POWERPC32;
}
else if( key_val.value.as_string() == ARCH_POWERPC64.m_name )
{
rv.m_arch = ARCH_POWERPC64;
}
else if( key_val.value.as_string() == ARCH_POWERPC64LE.m_name )
{
rv.m_arch = ARCH_POWERPC64LE;
}
else if( key_val.value.as_string() == ARCH_RISCV64.m_name )
{
rv.m_arch = ARCH_RISCV64;
}
else
{
// Error.
Expand Down Expand Up @@ -481,6 +497,13 @@ namespace
ARCH_RISCV64
};
}
else if(target_name == "riscv64-unknown-linux-musl")
{
return TargetSpec {
"unix", "linux", "musl", {CodegenMode::Gnu11, false, "riscv64-unknown-linux-musl", BACKEND_C_OPTS_GNU},
ARCH_RISCV64
};
}
else if(target_name == "i586-pc-windows-gnu")
{
return TargetSpec {
Expand Down
2 changes: 1 addition & 1 deletion tools/minicargo/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ RunnableJob Job_BuildTarget::start()
}
else {
args.push_back("--target"); args.push_back(parent.m_opts.target_name);
args.push_back("-C"); args.push_back(format("emit-build-command=",outfile,".sh"));
//args.push_back("-C"); args.push_back(format("emit-build-command=",outfile,".sh"));
}
}

Expand Down
7 changes: 7 additions & 0 deletions tools/minicargo/manifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include <functional>
#include <path.h>

#ifdef __OpenBSD__
// major() and minor() are defined as macros in <sys/types.h> on OpenBSD
// see: https://man.openbsd.org/major.3
# undef major
# undef minor
#endif

class WorkspaceManifest;
class PackageManifest;
class Repository;
Expand Down
1 change: 1 addition & 0 deletions tools/standalone_miri/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ ::std::string Lexer::parse_string()
throw "";
ch = m_if.get();
} while(ch != '}');
assert(ch == '}');

if( v < 0x80 ) {
val.push_back(static_cast<char>(v));
Expand Down
72 changes: 71 additions & 1 deletion tools/standalone_miri/mir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,82 @@ namespace std {
}
#endif

namespace {
unsigned num_ch(const std::string& s) {
uint8_t bits[128/8] = {0};
for(char c : s) {
if( 0 <= c && c < 128 ) {
bits[c / 8] |= (1 << (c % 8));
}
}
unsigned rv = 0;
for(uint8_t v : bits) {
for(int i = 0; i < 8; i ++) {
if(v & (1 << i)) {
rv += 1;
}
}
}
return rv;
}

const char* tyname(const HIR::CoreType& t) {
switch(t.raw_type)
{
case RawType::I8 : return "i8";
case RawType::I16 : return "i16";
case RawType::I32 : return "i32";
case RawType::I64 : return "i64";
case RawType::I128: return "i128";
case RawType::U8 : return "u8";
case RawType::U16 : return "u16";
case RawType::U32 : return "u32";
case RawType::U64 : return "u64";
case RawType::U128: return "u128";

case RawType::ISize: return "isize";
case RawType::USize: return "usize";

case RawType::F32 : return "f32";
case RawType::F64 : return "f64";

case RawType::Bool: return "bool";
case RawType::Char: return "char";
case RawType::Unit: return "?()";
case RawType::Str : return "?str";

case RawType::Unreachable: return "!";
case RawType::Function: return "?fn";
case RawType::Composite: return "?stuct";
case RawType::TraitObject: return "?dyn";
}
return "?";
}
}

namespace MIR {
::std::ostream& operator<<(::std::ostream& os, const Constant& v) {
TU_MATCHA( (v), (e),
(Int,
os << (e.v < 0 ? "-" : "+");
os << (e.v < 0 ? -e.v : e.v);
os << " " << tyname(e.t);
),
(Uint,
os << e.v;
std::ostringstream ss_dec, ss_hex;
ss_dec << e.v;
ss_hex << std::hex << e.v;
if( num_ch(ss_dec.str()) < num_ch(ss_hex.str()) ) {
os << e.v;
}
else {
os << std::hex << "0x" << e.v << std::dec;
}
os << " " << tyname(e.t);
),
(Float,
os << e.v;
os << " " << tyname(e.t);
),
(Bool,
os << (e.v ? "true" : "false");
Expand Down Expand Up @@ -73,6 +137,9 @@ namespace MIR {
(Generic,
os << e;
),
(Function,
os << "addr{fn} " << *e.p;
),
(ItemAddr,
os << "addr " << *e;
)
Expand Down Expand Up @@ -441,6 +508,9 @@ namespace MIR {
(Const,
return ::ord(*ae.p, *be.p);
),
(Function,
return ::ord(*ae.p, *be.p);
),
(Generic,
//return ::ord(ae.binding, be.binding);
return OrdEqual;
Expand Down
Loading

0 comments on commit b808668

Please sign in to comment.