// // // #pragma once #include #include #include #include #include "../../src/mir/mir.hpp" #include "hir_sim.hpp" struct Value; struct Function { ::HIR::Path my_path; ::std::vector<::HIR::TypeRef> args; ::HIR::TypeRef ret_ty; // If `link_name` is non-empty, then the function is an external struct { ::std::string link_name; ::std::string link_abi; } external; ::MIR::Function m_mir; }; /// Container for loaded code and structures class ModuleTree { friend struct Parser; ::std::set<::std::string> loaded_files; ::std::map<::HIR::Path, Function> functions; ::std::map<::HIR::Path, Value> statics; // TODO: statics // Hack: Tuples are stored as `::""::` ::std::map<::HIR::GenericPath, ::std::unique_ptr> data_types; public: ModuleTree(); void load_file(const ::std::string& path); ::HIR::SimplePath find_lang_item(const char* name) const; const Function& get_function(const ::HIR::Path& p) const; const Function* get_function_opt(const ::HIR::Path& p) const; Value& get_static(const ::HIR::Path& p); Value* get_static_opt(const ::HIR::Path& p); const DataType& get_composite(const ::HIR::GenericPath& p) const { return *data_types.at(p); } }; // struct/union/enum struct DataType { // TODO: Metadata type! (indicates an unsized wrapper) // TODO: Drop glue size_t alignment; size_t size; // Offset and datatype ::std::vector<::std::pair> fields; // Values for variants struct VariantValue { size_t data_field; size_t base_field; ::std::vector field_path; //size_t tag_offset; // Cached. ::std::string tag_data; }; ::std::vector variants; };