aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-07-08 12:43:20 +0100
committergingerBill <bill@gingerbill.org>2023-07-08 12:43:20 +0100
commitf0e77a309d2c1f93cabb2948ae3eefd31b7c1e31 (patch)
tree8cbdfc5f99c843668cce1d404dd3e54034efa932 /src
parent7ab531bd21d19338e2e6fb9ed12a9443cca95d7e (diff)
Hellope World! with Tilde
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp1
-rw-r--r--src/tilde/tb.libbin4004042 -> 4295510 bytes
-rw-r--r--src/tilde_backend.cpp39
3 files changed, 38 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c16cfa35f..adb955460 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2900,7 +2900,6 @@ int main(int arg_count, char const **arg_ptr) {
if (!tb_generate_code(checker)) {
return 1;
}
-
} else
#endif
{
diff --git a/src/tilde/tb.lib b/src/tilde/tb.lib
index bea6a58e3..ab5b02014 100644
--- a/src/tilde/tb.lib
+++ b/src/tilde/tb.lib
Binary files differ
diff --git a/src/tilde_backend.cpp b/src/tilde_backend.cpp
index 6f51784e8..87e1a1329 100644
--- a/src/tilde_backend.cpp
+++ b/src/tilde_backend.cpp
@@ -13,6 +13,43 @@
bool tb_generate_code(Checker *c) {
- gb_printf_err("TODO(bill): implement Tilde Backend\n");
+ TB_FeatureSet feature_set = {};
+ bool is_jit = false;
+ TB_Module *m = tb_module_create(TB_ARCH_X86_64, TB_SYSTEM_WINDOWS, &feature_set, is_jit);
+ defer (tb_module_destroy(m));
+ tb_module_set_tls_index(m, "_tls_index");
+
+
+ TB_Arena *arena = nullptr;
+
+ {
+ TB_PrototypeParam printf_ret = {TB_TYPE_I32};
+ TB_PrototypeParam printf_params = {TB_TYPE_PTR};
+ TB_FunctionPrototype *printf_proto = tb_prototype_create(m, TB_STDCALL, 1, &printf_params, 1, &printf_ret, true);
+ TB_External *printf_proc = tb_extern_create(m, "printf", TB_EXTERNAL_SO_LOCAL);
+
+ TB_PrototypeParam main_ret = {TB_TYPE_I32};
+ TB_FunctionPrototype *main_proto = tb_prototype_create(m, TB_STDCALL, 0, nullptr, 1, &main_ret, false);
+ TB_Function * p = tb_function_create(m, "main", TB_LINKAGE_PUBLIC, TB_COMDAT_NONE);
+ tb_function_set_prototype(p, main_proto, arena);
+
+
+ TB_Node *params[2] = {};
+ params[0] = tb_inst_cstring(p, "Hellope %s!\n");
+ params[1] = tb_inst_cstring(p, "World");
+ TB_MultiOutput output = tb_inst_call(p, printf_proto, tb_inst_get_symbol_address(p, cast(TB_Symbol *)printf_proc), gb_count_of(params), params);
+ gb_unused(output);
+
+ TB_Node *value = tb_inst_uint(p, TB_TYPE_I32, 0);
+ tb_inst_ret(p, 1, &value);
+
+ tb_module_compile_function(m, p, TB_ISEL_FAST);
+
+ TB_ExportBuffer export_buffer = tb_module_object_export(m, TB_DEBUGFMT_NONE);
+ defer (tb_export_buffer_free(export_buffer));
+
+ char const *path = "W:/Odin/tilde_main.obj";
+ GB_ASSERT(tb_export_buffer_to_file(export_buffer, path));
+ }
return false;
} \ No newline at end of file