summaryrefslogtreecommitdiff
path: root/tools/standalone_miri/module_tree.hpp
blob: ca24b06ac127b8e4494b90ccd6eb7821b412ad96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
//
//
#pragma once
#include <string>
#include <vector>
#include <map>
#include <set>

#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 `::""::<A,B,C,...>`
    ::std::map<::HIR::GenericPath, ::std::unique_ptr<DataType>>  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
{
    ::HIR::GenericPath my_path;
    // TODO: Store the name of this type for logging?

    // TODO: Metadata type! (indicates an unsized wrapper)
    // TODO: Drop glue

    size_t  alignment;
    size_t  size;

    ::HIR::Path drop_glue;
    ::HIR::TypeRef  dst_meta;

    // Offset and datatype
    ::std::vector<::std::pair<size_t, ::HIR::TypeRef>> fields;
    // Values for variants
    struct VariantValue {
        size_t data_field;
        size_t base_field;
        ::std::vector<size_t>   field_path;

        //size_t tag_offset;  // Cached.
        ::std::string tag_data;
    };
    ::std::vector<VariantValue> variants;
};