summaryrefslogtreecommitdiff
path: root/c/libdietc.h
blob: e63af8d61039437a7edd99bd94a7413d513801da (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

static char *strchrnul(char *s, char c) {
    while (*s && *s != c) s++;
    return s;
}

enum TYPE {
    TYPE_BASIC,
    TYPE_POINTER,
    TYPE_ARRAY,
    TYPE_STRUCT,
    TYPE_UNION,
    TYPE_FUNCTION,
};

struct type {
    char *typedef_line;
    enum TYPE kind;
    unsigned long id;

    // basic type
    char *basic;

    // pointer & array types
    struct type *base;
    unsigned long length;

    // struct & union types
    struct type *members;
    struct type *next_member;
    char *field_name;

    // function types
    struct type *return_type;
    struct type *params;
    struct type *next_param;
    unsigned long is_variadic;
};

struct instruction {
    char *line;
    struct instruction *next;
};

struct function {
    char *start_line;
    struct type *type;
    struct instruction *instructions;
    struct function *next;
};

struct object {
    char *name;
    struct type *type;
};

struct program {
    char *original;

    // all lines before the function definitions
    char *preamble;

    // id -> type table
    struct type **id2type;
    unsigned long n_types;

    // hash map of objects
    struct object **objects;
    unsigned long cap_objects;
    unsigned long n_objects;

    struct function *functions;
};

struct identifiers {
    char *token;
    struct identifier *next;
};

char *libdietc_tokdup(char *tok);
struct program libdietc_parse(char *filename);
void libdietc_print(struct program program);
char *libdietc_nth_token(char *string, int n);
struct type *libdietc_object_type(struct program program, char *name);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback