aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/Builtins.h
blob: 34e36a963e3a70277260be8b2b05ebf543ef8337 (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

#pragma once
#include <string>

namespace cps::detail {

// Single source of truth for the built-in functions: name, arity and return
// type. emitExpr checks arity against this table before dispatching, and
// getExprTypeInfo reads the return type from it.
struct BuiltinInfo {
    const char *Name;
    unsigned Arity;
    const char *ReturnTypeName;
};

inline constexpr BuiltinInfo Builtins[] = {
    {"LENGTH",     1, "INTEGER"},
    {"MID",        3, "STRING"},
    {"RIGHT",      2, "STRING"},
    {"LEFT",       2, "STRING"},
    {"LCASE",      1, "STRING"},
    {"UCASE",      1, "STRING"},
    {"ASC",        1, "INTEGER"},
    {"CHR",        1, "STRING"},
    {"IS_NUM",     1, "BOOLEAN"},
    {"NUM_TO_STR", 1, "STRING"},
    {"STR_TO_NUM", 1, "REAL"},
    {"EOF",        1, "BOOLEAN"},
};

inline const BuiltinInfo *findBuiltin(const std::string &Name) {
    for (const auto &B : Builtins) {
        if (Name == B.Name) return &B;
    }
    return nullptr;
}

} // namespace cps::detail