Cthulhu  0.2.10
Cthulhu compiler collection
main.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-3.0-only
2 
3 #include "oberon/driver.h"
4 
5 #include "oberon/sema/sema.h"
6 
8 
9 #include "driver/driver.h"
10 
11 #include "interop/compile.h"
12 
13 #include "std/vector.h"
14 
15 #include "base/util.h"
16 #include "core/macros.h"
17 
18 #include "obr_bison.h" // IWYU pragma: keep
19 #include "obr_flex.h" // IWYU pragma: keep
20 
21 CT_CALLBACKS(kCallbacks, obr);
22 
23 static void obr_postparse(language_runtime_t *runtime, scan_t *scan, void *tree)
24 {
25  CT_UNUSED(scan);
26 
27  vector_t *modules = tree;
28 
29  size_t len = vector_len(modules);
30  for (size_t i = 0; i < len; i++)
31  {
32  obr_t *mod = vector_get(modules, i);
33 
34  size_t decl_count = vector_len(mod->decls);
35  size_t sizes[eObrTagTotal] = {
36  [eObrTagValues] = decl_count,
37  [eObrTagTypes] = decl_count,
38  [eObrTagProcs] = decl_count,
39  [eObrTagModules] = 32,
40  };
41 
42  lang_add_unit(runtime, text_view_from(mod->name), mod->node, mod, sizes, eObrTagTotal);
43  }
44 }
45 
46 static void obr_destroy(language_runtime_t *handle) { CT_UNUSED(handle); }
47 
48 #define NEW_EVENT(id, ...) const diagnostic_t kEvent_##id = __VA_ARGS__;
49 #include "oberon/oberon.inc"
50 
51 static const diagnostic_t *const kDiagnosticTable[] = {
52 #define NEW_EVENT(id, ...) &kEvent_##id,
53 #include "oberon/oberon.inc"
54 };
55 
56 static const char *const kLangNames[] = CT_LANG_EXTS("m", "mod", "obr", "oberon");
57 
58 static const size_t kDeclSizes[eObrTagTotal] = {
59  [eObrTagValues] = 32,
60  [eObrTagTypes] = 32,
61  [eObrTagProcs] = 32,
62  [eObrTagModules] = 32,
63 };
64 
65 static const char *const kDeclNames[eObrTagTotal] = {
66 #define DECL_TAG(id, val, name) [id] = (name),
67 #include "oberon/oberon.inc"
68 };
69 
70 CT_DRIVER_API const language_t kOberonModule = {
71  .info = {
72  .id = "lang/oberon2",
73  .name = "Oberon-2",
74  .version = {
75  .license = "LGPLv3",
76  .desc = "Oberon-2 language frontend",
77  .author = "Elliot Haisley",
78  .version = CT_NEW_VERSION(1, 0, 0)
79  },
80 
81  .diagnostics = {
82  .diagnostics = kDiagnosticTable,
83  .count = sizeof(kDiagnosticTable) / sizeof(const diagnostic_t *)
84  },
85  },
86 
87  .builtin = {
88  .name = CT_TEXT_VIEW("obr\0lang"),
89  .decls = kDeclSizes,
90  .names = kDeclNames,
91  .length = eObrTagTotal,
92  },
93 
94  .exts = kLangNames,
95 
96  .ast_size = sizeof(obr_t),
97 
98  .fn_create = obr_create,
99  .fn_destroy = obr_destroy,
100 
101  .fn_postparse = obr_postparse,
102 
103  .scanner = &kCallbacks,
104 
105  .fn_passes = {
106  [ePassForwardDecls] = obr_forward_decls,
107  [ePassImportModules] = obr_process_imports
108  }
109 };
110 
#define CT_TEXT_VIEW(str)
create a text view from a string literal
Definition: text.h:39
CT_PUREFN CT_BASE_API text_view_t text_view_from(const char *text)
create a new non-owning text array this is a shortcut for
Definition: util.c:191
CT_BROKER_API void lang_add_unit(language_runtime_t *runtime, unit_id_t id, const node_t *node, void *ast, const size_t *sizes, size_t count)
all runtime apis
Definition: broker.c:462
#define CT_LANG_EXTS(...)
Definition: broker.h:49
#define CT_NEW_VERSION(major, minor, patch)
creates a new ctu_version_t from major, minor and patch
Definition: version_def.h:20
#define CT_LANG_EXPORT(mod)
declares the entry point for a language driver module
#define CT_UNUSED(x)
mark a variable as unused
Definition: macros.h:46
CT_NODISCARD CT_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from a vector
Definition: vector.c:134
CT_NODISCARD CT_PUREFN CT_STD_API size_t vector_len(const vector_t *vector)
get the length of a vector
Definition: vector.c:152
CT_CALLBACKS(kCallbacks, ctu)
void obr_create(language_runtime_t *runtime, tree_t *root)
Definition: sema.c:123
void obr_forward_decls(language_runtime_t *runtime, compile_unit_t *unit)
Definition: driver.c:20
void obr_process_imports(language_runtime_t *runtime, compile_unit_t *unit)
Definition: driver.c:80
CT_DRIVER_API const language_t kOberonModule
Definition: main.c:70
@ eObrTagTotal
Definition: sema.h:13
a diagnostic
Definition: diagnostic.h:27
a language driver support capabilities
Definition: broker.h:143
module_info_t info
common information about the language
Definition: broker.h:145
const char * id
unique id for the module
Definition: broker.h:101
Definition: ast.h:93
char * name
Definition: ast.h:184
vector_t * decls
Definition: ast.h:191
const node_t * node
Definition: ast.h:95
a source file scanner
Definition: scan.h:24
a generic vector of pointers
Definition: vector.c:16