Fix non-ascii function parameters in LLVM IR

This commit is contained in:
Ginger Bill
2017-04-15 23:14:14 +01:00
parent 23a0a6de4b
commit 169310a9f6
3 changed files with 4 additions and 132 deletions
+1 -1
View File
@@ -5371,7 +5371,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
case Token_transmute: {
if (o->mode == Addressing_Constant) {
gbString expr_str = expr_to_string(o->expr);
error_node(o->expr, "Cannot transmute constant expression: `%s`", expr_str);
error_node(o->expr, "Cannot transmute a constant expression: `%s`", expr_str);
gb_string_free(expr_str);
o->mode = Addressing_Invalid;
o->expr = node;
+1 -1
View File
@@ -432,7 +432,7 @@ typedef i32 b32; // NOTE(bill): Prefer this!!!
// NOTE(bill): Get true and false
#if !defined(__cplusplus)
#if (defined(_MSC_VER) && _MSC_VER <= 1800) || (!defined(_MSC_VER) && !defined(__STDC_VERSION__))
#if (defined(_MSC_VER) && _MSC_VER < 1800) || (!defined(_MSC_VER) && !defined(__STDC_VERSION__))
#ifndef true
#define true (0 == 0)
#endif
+2 -130
View File
@@ -1385,135 +1385,6 @@ void ir_print_instr(irFileBuffer *f, irModule *m, irValue *value) {
void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
// #ifndef GB_SYSTEM_WINDOWS
#if 0
bool is_main_proc = proc->parent == NULL && str_eq(proc->name, str_lit("main"));
AstFile fake_file;
gb_arena_init_from_allocator(&fake_file.arena, heap_allocator(), gb_size_of(AstNode) * 4);
bool uses_args = false;
if(is_main_proc)
for(int i=0;i<proc->module->min_dep_map.entries.count;i++) {
Entity *value = proc->module->min_dep_map.entries.e[i].value;
if(value == NULL) continue;
if(str_eq(str_lit("args"), value->token.string)) {
uses_args = true;
break;
}
}
// TODO(zangent): THIS IS AN UGLY HACK
// I _SERIOUSLY_ need to change this system, because this is just disgraceful.
if(uses_args) {
ir_fprintf(f, "%s", "; Hack to give Linux/OSX launch arguments\n"
"define i32 @main(i32 %argc, i8** %argv) {\n"
"decls-0:\n"
" %0 = alloca i32, align 4\n"
" %1 = alloca i8**, align 8\n"
" %2 = alloca i32, align 4\n"
" %3 = alloca i8*, align 8\n"
" %4 = alloca %..string, align 8\n"
" store i32 zeroinitializer, i32* %0\n"
" store i32 %argc, i32* %0\n"
" store i8** zeroinitializer, i8*** %1\n"
" store i8** %argv, i8*** %1\n"
" call void @.__$startup_runtime()\n"
" ; reserve\n"
" ; SelectorExpr\n"
" %5 = load i32, i32* %0, align 4\n"
" %6 = sext i32 %5 to i64\n"
" %7 = bitcast {%..string*, i64, i64,%Allocator}* @.args to %..rawptr\n"
" %8 = call i1 @.__dynamic_array_reserve(%..rawptr %7, i64 16, i64 8, i64 %6)\n"
" ; AssignStmt\n"
" ; SelectorExpr\n"
" ; SelectorExpr\n"
" %9 = getelementptr inbounds {%..string*, i64, i64,%Allocator}, {%..string*, i64, i64,%Allocator}* @.args, i64 0, i32 1\n"
" %10 = load i32, i32* %0, align 4\n"
" ; cast - cast\n"
" %11 = sext i32 %10 to i64\n"
" store i64 %11, i64* %9\n"
" ; i\n"
" store i32 zeroinitializer, i32* %2\n"
" store i32 0, i32* %2\n"
" ; ForStmt\n"
" br label %for.loop-1\n"
"\n"
"for.loop-1:\n"
" %12 = load i32, i32* %2, align 4\n"
" %13 = load i32, i32* %0, align 4\n"
" %14 = icmp slt i32 %12, %13\n"
" br i1 %14, label %for.body-2, label %for.done-6\n"
"\n"
"for.body-2:\n"
" ; cstr\n"
" store i8* zeroinitializer, i8** %3\n"
" %15 = load i8**, i8*** %1, align 8\n"
" %16 = load i32, i32* %2, align 4\n"
" %17 = sext i32 %16 to i64\n"
" %18 = getelementptr inbounds i8*, i8** %15, i64 %17\n"
" %19 = getelementptr inbounds i8*, i8** %18, i64 0\n"
" %20 = load i8*, i8** %19, align 8\n"
" store i8* %20, i8** %3\n"
" ; str\n"
" store %..string zeroinitializer, %..string* %4\n"
" ; AssignStmt\n"
" ; SelectorExpr\n"
" %21 = getelementptr inbounds %..string, %..string* %4, i64 0, i32 0\n"
" %22 = load i8*, i8** %3, align 8\n"
" store i8* %22, i8** %21\n"
" ; ForStmt\n"
" br label %for.loop-3\n"
"\n"
"for.loop-3:\n"
" %23 = load i8*, i8** %3, align 8\n"
" ; SelectorExpr\n"
" %24 = getelementptr inbounds %..string, %..string* %4, i64 0, i32 1\n"
" %25 = load i64, i64* %24, align 8\n"
" %26 = getelementptr inbounds i8, i8* %23, i64 %25\n"
" %27 = getelementptr inbounds i8, i8* %26, i64 0\n"
" %28 = load i8, i8* %27, align 1\n"
" %29 = icmp ne i8 %28, 0\n"
" br i1 %29, label %for.body-4, label %for.done-5\n"
"\n"
"for.body-4:\n"
" ; SelectorExpr\n"
" %30 = getelementptr inbounds %..string, %..string* %4, i64 0, i32 1\n"
" %31 = load i64, i64* %30, align 8\n"
" %32 = add i64 %31, 1\n"
" store i64 %32, i64* %30\n"
" br label %for.loop-3\n"
"\n"
"for.done-5:\n"
" ; AssignStmt\n"
" ; IndexExpr\n"
" ; SelectorExpr\n"
" %33 = load {%..string*, i64, i64,%Allocator}, {%..string*, i64, i64,%Allocator}* @.args, align 8\n"
" %34 = extractvalue {%..string*, i64, i64,%Allocator} %33, 0\n"
" %35 = extractvalue {%..string*, i64, i64,%Allocator} %33, 1\n"
" %36 = load i32, i32* %2, align 4\n"
" %37 = sext i32 %36 to i64\n"
" %38 = getelementptr inbounds %..string, %..string* %34, i64 %37\n"
" %39 = load %..string, %..string* %4, align 8\n"
" store %..string %39, %..string* %38\n"
" ; AssignStmt\n"
" %40 = load i32, i32* %2, align 4\n"
" %41 = add i32 %40, 1\n"
" store i32 %41, i32* %2\n"
" br label %for.loop-1\n"
"\n"
"for.done-6:\n"
" call void @.nix_argpatch_main()\n"
" ret i32 0\n"
"}\n"
);
}
#endif
if (proc->body == NULL) {
ir_fprintf(f, "declare ");
// if (proc->tags & ProcTag_dll_import) {
@@ -1566,7 +1437,8 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
if (proc->body != NULL) {
if (!str_eq(e->token.string, str_lit("")) &&
!str_eq(e->token.string, str_lit("_"))) {
ir_fprintf(f, " %%%.*s", LIT(e->token.string));
ir_fprintf(f, " ");
ir_print_encoded_local(f, e->token.string);
} else {
ir_fprintf(f, " %%_.param_%td", i);
}