diff --git a/.gitignore b/.gitignore index e60401677..cd0489dd2 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,7 @@ /bnf/rust.tab.h /bnf/rust.output /bnf/test.bin + +/subprojects/* +!/subprojects/*.wrap +/build* diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..79ceeffeb --- /dev/null +++ b/meson.build @@ -0,0 +1,50 @@ +project( + 'mrustc', + 'cpp', + version: '0.8.0', + license: 'MIT', + default_options: [ + 'cpp_std=c++14', + 'werror=false', + 'warning_level=2', + ], +) + +python = import('python').find_installation('python3') +major_version = 0 +minor_version = 8 +patch_version = 0 + +compiler = meson.get_compiler('cpp').get_id() +if compiler == 'msvc' + add_project_arguments( + '-wd4267', + '-wd4244', + '-wd4099', + '-wd4996', + '-wd4146', + language: 'cpp', + ) +endif + +subdir('tools/common') +subdir('tools/minicargo') +subdir('tools/standalone_miri') +subdir('tools/testrunner') + +subdir('src') + +rustc_source_url = get_option('rustc_source_url') +rustc_source_hash = get_option('rustc_source_hash') +'''rustc_source = custom_target( + 'rustc_source', + input: 'download_rustc_source.py', + build_always_stale: true, + install: false, + command: [ + python, '@INPUT@', + '--output-directory', 'rustc_source', + '--source-url', rustc_source_url, + '--source-hash', rustc_source_hash, + ], +)''' diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 000000000..9a143809f --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,14 @@ +option( + 'rustc_source_url', + type: 'string', + value: 'https://github.com/rust-lang/rust/archive/1.19.0.tar.gz', + description: 'URL or local path of where rustc\'s source should be downloaded from.', +) + +option( + 'rustc_source_hash', + type: 'string', + value: 'SHA256=7e1ecb476118b79b5abed02bc7a724bb65413057e26f1d2b8538c572f7463be0', + description: + 'SHA256 of the file downloaded from MRUSTC_RUSTC_SOURCE_URL. You can leave this empty to skip verifying whether the downloaded archive is correct.', +) diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp index 0e1c8149d..c84e0c441 100644 --- a/src/ast/attrs.hpp +++ b/src/ast/attrs.hpp @@ -11,50 +11,7 @@ namespace AST { -// class Attribute; -::std::ostream& operator<<(::std::ostream& os, const Attribute& x); - -/// A list of attributes on an item (searchable by the attribute name) -class AttributeList -{ -public: - ::std::vector m_items; - - AttributeList() {} - AttributeList(::std::vector items): - m_items( mv$(items) ) - { - } - - // Move present - AttributeList(AttributeList&&) = default; - AttributeList& operator=(AttributeList&&) = default; - // No copy assign, but explicit copy - explicit AttributeList(const AttributeList&) = default; - AttributeList& operator=(const AttributeList&) = delete; - // Explicit clone - AttributeList clone() const; - - void push_back(Attribute i); - - const Attribute* get(const char *name) const; - Attribute* get(const char *name) { - return const_cast( const_cast(this)->get(name)); - } - bool has(const char *name) const { - return get(name) != 0; - } - - friend ::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) { - for(const auto& i : x.m_items) { - os << "#[" << i << "]"; - } - return os; - } -}; - - TAGGED_UNION(AttributeData, None, (None, struct {}), (String, struct { @@ -70,7 +27,6 @@ TAGGED_UNION(AttributeData, None, // - A parenthesised token tree // > In 1.19 this was actually just sub-attributes // - an associated (string) literal - class Attribute { Span m_span; @@ -151,6 +107,46 @@ class Attribute } }; + +/// A list of attributes on an item (searchable by the attribute name) +class AttributeList +{ +public: + ::std::vector m_items; + + AttributeList() {} + AttributeList(::std::vector items): + m_items( mv$(items) ) + { + } + + // Move present + AttributeList(AttributeList&&) = default; + AttributeList& operator=(AttributeList&&) = default; + // No copy assign, but explicit copy + explicit AttributeList(const AttributeList&) = default; + AttributeList& operator=(const AttributeList&) = delete; + // Explicit clone + AttributeList clone() const; + + void push_back(Attribute i); + + const Attribute* get(const char *name) const; + Attribute* get(const char *name) { + return const_cast( const_cast(this)->get(name)); + } + bool has(const char *name) const { + return get(name) != 0; + } + + friend ::std::ostream& operator<<(::std::ostream& os, const AttributeList& x) { + for(const auto& i : x.m_items) { + os << "#[" << i << "]"; + } + return os; + } +}; + } // namespace AST #endif diff --git a/src/include/version.hpp b/src/include/version.hpp index 2270a5925..a34509781 100644 --- a/src/include/version.hpp +++ b/src/include/version.hpp @@ -9,12 +9,13 @@ #include -extern unsigned int giVersion_Major; -extern unsigned int giVersion_Minor; -extern unsigned int giVersion_Patch; -extern const char* gsVersion_GitHash; -extern const char* gsVersion_GitShortHash; -extern const char* gsVersion_BuildTime; -extern bool gbVersion_GitDirty; +extern const unsigned int giVersion_Major; +extern const unsigned int giVersion_Minor; +extern const unsigned int giVersion_Patch; +extern const bool gbVersion_GitDirty; +extern const char gsVersion_GitHash[]; +extern const char gsVersion_GitShortHash[]; +extern const char gsVersion_GitBranch[]; +extern const char gsVersion_BuildTime[]; extern ::std::string Version_GetString(); diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000..28d247b55 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,161 @@ +zdep = dependency('zlib', fallback: ['zlib', 'zlib_dep']) + +mrustc_includes = include_directories( + 'include', + '.', + + 'parse', + + 'expand', + 'macro_rules', + + 'ast', + + 'resolve', + 'hir', + 'hir_conv', + 'hir_typeck', + 'hir_expand', + + 'mir', + + 'trans', +) + +version = custom_target( + 'version', + input: 'version.py', + output: 'version.cpp', + build_always_stale: true, + install: false, + command: [ + python, '@INPUT@', + '--output-file', '@OUTPUT@', + '--major-version', major_version.to_string(), + '--minor-version', minor_version.to_string(), + '--patch-version', patch_version.to_string(), + ], +) +version_cpp = version[0] + +mrustc_exe = executable( + 'mrustc', + 'debug.cpp', + 'main.cpp', + 'ident.cpp', + 'span.cpp', + 'rc_string.cpp', + version_cpp, + + 'parse/root.cpp', + 'parse/types.cpp', + 'parse/tokentree.cpp', + 'parse/pattern.cpp', + 'parse/paths.cpp', + 'parse/ttstream.cpp', + 'parse/token.cpp', + 'parse/ttstream.hpp', + 'parse/expr.cpp', + 'parse/lex.cpp', + 'parse/interpolated_fragment.cpp', + 'parse/parseerror.cpp', + 'parse/tokenstream.cpp', + + 'expand/crate_tags.cpp', + 'expand/concat.cpp', + 'expand/format_args.cpp', + 'expand/derive.cpp', + 'expand/std_prelude.cpp', + 'expand/env.cpp', + 'expand/cfg.cpp', + 'expand/macro_rules.cpp', + 'expand/test_harness.cpp', + 'expand/include.cpp', + 'expand/mod.cpp', + 'expand/asm.cpp', + 'expand/file_line.cpp', + 'expand/lang_item.cpp', + 'expand/test.cpp', + 'expand/proc_macro.cpp', + 'expand/stringify.cpp', + 'expand/rustc_diagnostics.cpp', + 'macro_rules/parse.cpp', + 'macro_rules/mod.cpp', + 'macro_rules/eval.cpp', + + 'ast/types.cpp', + 'ast/dump.cpp', + 'ast/crate.cpp', + 'ast/pattern.cpp', + 'ast/expr.cpp', + 'ast/path.cpp', + 'ast/ast.cpp', + + 'resolve/absolute.cpp', + 'resolve/use.cpp', + 'resolve/index.cpp', + 'hir/generic_params.cpp', + 'hir/type.cpp', + 'hir/crate_post_load.cpp', + 'hir/dump.cpp', + 'hir/hir.cpp', + 'hir/pattern.cpp', + 'hir/expr_ptr.cpp', + 'hir/crate_ptr.cpp', + 'hir/from_ast.cpp', + 'hir/serialise.cpp', + 'hir/expr.cpp', + 'hir/pattern.hpp', + 'hir/visitor.cpp', + 'hir/serialise_lowlevel.cpp', + 'hir/path.cpp', + 'hir/deserialise.cpp', + 'hir/from_ast_expr.cpp', + 'hir_conv/bind.cpp', + 'hir_conv/expand_type.cpp', + 'hir_conv/resolve_ufcs.cpp', + 'hir_conv/markings.cpp', + 'hir_conv/constant_evaluation.cpp', + 'hir_expand/erased_types.cpp', + 'hir_expand/closures.cpp', + 'hir_expand/annotate_value_usage.cpp', + 'hir_expand/vtable.cpp', + 'hir_expand/ufcs_everything.cpp', + 'hir_expand/reborrow.cpp', + 'hir_typeck/helpers.cpp', + 'hir_typeck/expr_visit.cpp', + 'hir_typeck/expr_check.cpp', + 'hir_typeck/expr_cs.cpp', + 'hir_typeck/impl_ref.cpp', + 'hir_typeck/static.cpp', + 'hir_typeck/outer.cpp', + 'hir_typeck/common.cpp', + + 'mir/check_full.cpp', + 'mir/helpers.cpp', + 'mir/optimise.cpp', + 'mir/mir.cpp', + 'mir/dump.cpp', + 'mir/visit_crate_mir.cpp', + 'mir/mir_builder.cpp', + 'mir/from_hir_match.cpp', + 'mir/cleanup.cpp', + 'mir/check.cpp', + 'mir/from_hir.cpp', + 'mir/mir_ptr.cpp', + + 'trans/enumerate.cpp', + 'trans/codegen.cpp', + 'trans/monomorphise.hpp', + 'trans/mangling.cpp', + 'trans/target.cpp', + 'trans/trans_list.cpp', + 'trans/codegen_mmir.cpp', + 'trans/monomorphise.cpp', + 'trans/allocator.cpp', + 'trans/codegen_c.cpp', + 'trans/codegen_c_structured.cpp', + + include_directories: mrustc_includes, + dependencies: [zdep, common], +) diff --git a/src/mir/from_hir.hpp b/src/mir/from_hir.hpp index 0dcbd65bc..182a4b5d0 100644 --- a/src/mir/from_hir.hpp +++ b/src/mir/from_hir.hpp @@ -82,6 +82,14 @@ struct SplitArm { //BasicBlockId source_block; ::std::map states; ::std::map arg_states; + + SplitArm(const SplitArm&) = delete; + SplitArm(SplitArm&&) = default; + + SplitArm& operator=(const SplitArm&) = delete; + SplitArm& operator=(SplitArm&&) = default; + + ~SplitArm() = default; }; struct SplitEnd { ::std::map states; diff --git a/src/version.cpp b/src/version.cpp deleted file mode 100644 index b40196ffe..000000000 --- a/src/version.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * MRustC - Rust Compiler - * - By John Hodge (Mutabah/thePowersGang) - * - * version.cpp - * - Compiler version number - */ -#include -#include - -#define VERSION_MAJOR 0 -#define VERSION_MINOR 8 -#define VERSION_PATCH 0 - -#ifdef _WIN32 -# define VERSION_GIT_ISDIRTY 1 -# define VERSION_GIT_FULLHASH "" -# define VERSION_GIT_SHORTHASH "" -# define VERSION_BUILDTIME "" -# define VERSION_GIT_BRANCH "" -#endif - -unsigned int giVersion_Major = VERSION_MAJOR; -unsigned int giVersion_Minor = VERSION_MINOR; -unsigned int giVersion_Patch = VERSION_PATCH; -bool gbVersion_GitDirty = VERSION_GIT_ISDIRTY; -const char* gsVersion_GitHash = VERSION_GIT_FULLHASH; -const char* gsVersion_GitShortHash = VERSION_GIT_SHORTHASH; -const char* gsVersion_BuildTime = VERSION_BUILDTIME; - - -::std::string Version_GetString() -{ - ::std::stringstream ss; - ss << "v" << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH << " " << VERSION_GIT_BRANCH << ":" << VERSION_GIT_SHORTHASH; - return ss.str(); -} diff --git a/src/version.py b/src/version.py new file mode 100644 index 000000000..204329b50 --- /dev/null +++ b/src/version.py @@ -0,0 +1,123 @@ +import argparse +from datetime import datetime +import string + +def get_arguments(): + parser = argparse.ArgumentParser( + description= 'Create a version.cpp file - this is run by meson on every build', + allow_abbrev=False, + ) + + parser.add_argument( + '--output-file', + action='store', + metavar='PATH', + required=True, + help='Where to put the generated version file', + ) + + parser.add_argument( + '--major-version', + action='store', + metavar='X', + required=True, + type=int, + help='Major version number', + ) + + parser.add_argument( + '--minor-version', + action='store', + metavar='Y', + required=True, + type=int, + help='Minor version number', + ) + + parser.add_argument( + '--patch-version', + action='store', + metavar='Z', + required=True, + type=int, + help='Patch version number', + ) + + return parser.parse_args() + +def git_info(): + from subprocess import run + is_dirty = 1 + fullhash = '' + shorthash = '' + branch = '' + + try: + is_dirty_output = run( + ['git', 'status', '--porcelain'], capture_output=True) + if not is_dirty_output.stdout: + is_dirty = 0 + + fullhash_output = run( + ['git', 'rev-parse', 'HEAD'], capture_output=True) + fullhash = fullhash_output.stdout.decode().strip() + + shorthash_output = run( + ['git', 'rev-parse', '--short', 'HEAD'], capture_output=True) + shorthash = shorthash_output.stdout.decode().strip() + + branch_output = run( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], capture_output=True) + branch = branch_output.stdout.decode().strip() + except: + pass + + return { + 'GIT_ISDIRTY': is_dirty, + 'GIT_FULLHASH': fullhash, + 'GIT_SHORTHASH': shorthash, + 'GIT_BRANCH': branch, + } + +def main(): + from os import getcwd + arguments = get_arguments() + print('---', getcwd()) + + buildtime = datetime.utcnow().isoformat() + + templated = TEMPLATE_FILE.safe_substitute( + git_info(), + MAJOR=arguments.major_version, + MINOR=arguments.minor_version, + PATCH=arguments.patch_version, + BUILDTIME=buildtime, + ) + + with open(arguments.output_file, 'w') as f: + f.write(templated) + +TEMPLATE_FILE = string.Template(''' +#include +#include + +const unsigned int giVersion_Major = $MAJOR; +const unsigned int giVersion_Minor = $MINOR; +const unsigned int giVersion_Patch = $PATCH; +const bool gbVersion_GitDirty = $GIT_ISDIRTY; +const char gsVersion_GitHash[] = "$GIT_FULLHASH"; +const char gsVersion_GitShortHash[] = "$GIT_SHORTHASH"; +const char gsVersion_GitBranch[] = "$GIT_BRANCH"; +const char gsVersion_BuildTime[] = "$BUILDTIME"; + + +::std::string Version_GetString() +{ + ::std::stringstream ss; + ss << 'v' << giVersion_Major << '.' << giVersion_Minor << '.' << giVersion_Patch << ' ' << gsVersion_GitBranch << ':' << gsVersion_GitShortHash; + return ss.str(); +} +''') + +if __name__ == '__main__': + main() diff --git a/subprojects/zlib.wrap b/subprojects/zlib.wrap new file mode 100644 index 000000000..97de00ef7 --- /dev/null +++ b/subprojects/zlib.wrap @@ -0,0 +1,10 @@ +[wrap-file] +directory = zlib-1.2.11 + +source_url = http://zlib.net/fossils/zlib-1.2.11.tar.gz +source_filename = zlib-1.2.11.tar.gz +source_hash = c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1 + +patch_url = https://wrapdb.mesonbuild.com/v1/projects/zlib/1.2.11/3/get_zip +patch_filename = zlib-1.2.11-3-wrap.zip +patch_hash = f07dc491ab3d05daf00632a0591e2ae61b470615b5b73bcf9b3f061fff65cff0 diff --git a/tools/common/meson.build b/tools/common/meson.build new file mode 100644 index 000000000..2eb7c3183 --- /dev/null +++ b/tools/common/meson.build @@ -0,0 +1,12 @@ +common_include_directories = include_directories('.') + +common = declare_dependency( + link_with: static_library( + 'common', + 'debug.cpp', + 'path.cpp', + 'toml.cpp', + include_directories: common_include_directories, + ), + include_directories: common_include_directories, +) diff --git a/tools/minicargo/meson.build b/tools/minicargo/meson.build new file mode 100644 index 000000000..e69de29bb diff --git a/tools/standalone_miri/meson.build b/tools/standalone_miri/meson.build new file mode 100644 index 000000000..e69de29bb diff --git a/tools/testrunner/meson.build b/tools/testrunner/meson.build new file mode 100644 index 000000000..e69de29bb