string comparisons

This commit is contained in:
gingerBill
2016-08-15 13:46:01 +01:00
parent 0f48a7d299
commit 3ed75b22a3
14 changed files with 1176 additions and 195 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ void ssa_gen_code(ssaGen *s) {
gb_for_array(i, info->entities.entries) {
auto *entry = &info->entities.entries[i];
Entity *e = cast(Entity *)cast(uintptr)entry->key;
Entity *e = cast(Entity *)cast(uintptr)entry->key.key;
DeclInfo *decl = entry->value;
String name = e->token.string;
+37 -10
View File
@@ -400,7 +400,32 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
ssa_fprintf(f, "%%%d = ", value->id);
if (gb_is_between(bo->op.kind, Token__ComparisonBegin+1, Token__ComparisonEnd-1)) {
if (is_type_float(elem_type)) {
if (is_type_string(elem_type)) {
ssa_fprintf(f, "call ");
ssa_print_type(f, m->sizes, t_bool);
char *runtime_proc = "";
switch (bo->op.kind) {
case Token_CmpEq: runtime_proc = "__string_eq"; break;
case Token_NotEq: runtime_proc = "__string_ne"; break;
case Token_Lt: runtime_proc = "__string_lt"; break;
case Token_Gt: runtime_proc = "__string_gt"; break;
case Token_LtEq: runtime_proc = "__string_le"; break;
case Token_GtEq: runtime_proc = "__string_gt"; break;
}
ssa_fprintf(f, " @%s(", runtime_proc);
ssa_print_type(f, m->sizes, type);
ssa_fprintf(f, " ");
ssa_print_value(f, m, bo->left, type);
ssa_fprintf(f, ", ");
ssa_print_type(f, m->sizes, type);
ssa_fprintf(f, " ");
ssa_print_value(f, m, bo->right, type);
ssa_fprintf(f, ")\n");
return;
} else if (is_type_float(elem_type)) {
ssa_fprintf(f, "fcmp ");
switch (bo->op.kind) {
case Token_CmpEq: ssa_fprintf(f, "oeq"); break;
@@ -434,14 +459,15 @@ void ssa_print_instr(gbFile *f, ssaModule *m, ssaValue *value) {
ssa_fprintf(f, "f");
switch (bo->op.kind) {
case Token_Add: ssa_fprintf(f, "add"); break;
case Token_Sub: ssa_fprintf(f, "sub"); break;
case Token_And: ssa_fprintf(f, "and"); break;
case Token_Or: ssa_fprintf(f, "or"); break;
case Token_Xor: ssa_fprintf(f, "xor"); break;
case Token_Shl: ssa_fprintf(f, "shl"); break;
case Token_Add: ssa_fprintf(f, "add"); break;
case Token_Sub: ssa_fprintf(f, "sub"); break;
case Token_And: ssa_fprintf(f, "and"); break;
case Token_Or: ssa_fprintf(f, "or"); break;
case Token_Xor: ssa_fprintf(f, "xor"); break;
case Token_Shl: ssa_fprintf(f, "shl"); break;
case Token_Shr: ssa_fprintf(f, "lshr"); break;
case Token_Mul: ssa_fprintf(f, "mul"); break;
case Token_Mul: ssa_fprintf(f, "mul"); break;
case Token_Not: ssa_fprintf(f, "xor"); break;
case Token_AndNot: GB_PANIC("Token_AndNot Should never be called");
@@ -655,15 +681,16 @@ void ssa_print_llvm_ir(gbFile *f, ssaModule *m) {
ssa_print_encoded_local(f, make_string(".string"));
ssa_fprintf(f, " = type {i8*, ");
ssa_print_type(f, m->sizes, t_int);
ssa_fprintf(f, "} ; Basic_string\n\n");
ssa_fprintf(f, "} ; Basic_string\n");
ssa_print_encoded_local(f, make_string(".rawptr"));
ssa_fprintf(f, " = type i8* ; Basic_rawptr\n\n");
ssa_fprintf(f, "declare void @llvm.memmove.p0i8.p0i8.");
ssa_print_type(f, m->sizes, t_int);
ssa_fprintf(f, "(i8*, i8*, ");
ssa_print_type(f, m->sizes, t_int);
ssa_fprintf(f, ", i32, i1)\n\n");
ssa_fprintf(f, ", i32, i1) argmemonly nounwind \n\n");
gb_for_array(i, m->nested_type_names) {
ssaValue *v = m->nested_type_names[i];
+3 -6
View File
@@ -670,7 +670,7 @@ ssaValue *ssa_make_value_block(ssaProcedure *proc, AstNode *node, Scope *scope,
b32 ssa_is_blank_ident(AstNode *node) {
if (node->kind == AstNode_Ident) {
ast_node(i, Ident, node);
return are_strings_equal(i->token.string, make_string("_"));
return is_blank_ident(i->token.string);
}
return false;
}
@@ -1390,6 +1390,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
ssaValue *right = ssa_build_expr(proc, ue->expr);
return ssa_emit_arith(proc, ue->op, left, right, tv->type);
} break;
case Token_Not: // Boolean not
case Token_Xor: { // Bitwise not
// NOTE(bill): "not" `x` == `x` "xor" `-1`
ExactValue neg_one = make_exact_value_integer(-1);
@@ -1397,10 +1398,6 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
ssaValue *right = ssa_make_value_constant(proc->module->allocator, tv->type, neg_one);
return ssa_emit_arith(proc, ue->op, left, right, tv->type);
} break;
case Token_Not: // Boolean not
GB_PANIC("Token_Not");
return NULL;
}
case_end;
@@ -2057,7 +2054,7 @@ void ssa_build_stmt(ssaProcedure *proc, AstNode *node) {
String name = make_string(name_text, name_len-1);
Entity **found = map_get(&proc->module->info->definitions, hash_pointer(pd->name));
GB_ASSERT(found != NULL);
GB_ASSERT_MSG(found != NULL, "Unable to find: %.*s", LIT(pd->name->Ident.token.string));
Entity *e = *found;
ssaValue *value = ssa_make_value_procedure(proc->module->allocator,
proc->module, e->type, pd->type, pd->body, name);