authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-13 01:58:36-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-13 01:58:36-05:00
log8bb5f54b292efacc03ff8d7cc6f59ae36c24305d
tree85a854a12cba15e3674e2218d9c5efbf137a87c6
parenta6d2bdf6050642762cc7bc193bca34690f712d49

IR: implement character literal


1 files changed, 16 insertions(+), 54 deletions(-)

src/ir.cpp+16-54
......@@ -497,6 +497,14 @@ static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, Ast
497497 return &const_instruction->base;
498498}
499499
500static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {
501 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
502 const_instruction->base.type_entry = irb->codegen->builtin_types.entry_num_lit_int;
503 const_instruction->base.static_value.special = ConstValSpecialStatic;
504 bignum_init_unsigned(&const_instruction->base.static_value.data.x_bignum, value);
505 return &const_instruction->base;
506}
507
500508static IrInstruction *ir_build_const_bignum(IrBuilder *irb, Scope *scope, AstNode *source_node, BigNum *bignum) {
501509 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
502510 const_instruction->base.type_entry = (bignum->kind == BigNumKindInt) ?
......@@ -1991,6 +1999,12 @@ static IrInstruction *ir_gen_num_lit(IrBuilder *irb, Scope *scope, AstNode *node
19911999 return ir_build_const_bignum(irb, scope, node, node->data.number_literal.bignum);
19922000}
19932001
2002static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) {
2003 assert(node->type == NodeTypeCharLiteral);
2004
2005 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);
2006}
2007
19942008static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) {
19952009 assert(node->type == NodeTypeNullLiteral);
19962010
......@@ -3453,6 +3467,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
34533467 return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval);
34543468 case NodeTypeNumberLiteral:
34553469 return ir_lval_wrap(irb, scope, ir_gen_num_lit(irb, scope, node), lval);
3470 case NodeTypeCharLiteral:
3471 return ir_lval_wrap(irb, scope, ir_gen_char_lit(irb, scope, node), lval);
34563472 case NodeTypeSymbol:
34573473 return ir_gen_symbol(irb, scope, node, lval);
34583474 case NodeTypeFnCallExpr:
......@@ -3510,7 +3526,6 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
35103526 case NodeTypeSliceExpr:
35113527 return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval);
35123528 case NodeTypeUnwrapErrorExpr:
3513 case NodeTypeCharLiteral:
35143529 case NodeTypeZeroesLiteral:
35153530 case NodeTypeVarLiteral:
35163531 case NodeTypeFnProto:
......@@ -8893,47 +8908,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
88938908// }
88948909// zig_unreachable();
88958910//}
8896//static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
8897// AstNode *node, LValPurpose purpose)
8898//{
8899// TypeTableEntry *array_type = analyze_expression(g, import, context, nullptr,
8900// node->data.array_access_expr.array_ref_expr);
8901//
8902// TypeTableEntry *return_type;
8903//
8904// if (array_type->id == TypeTableEntryIdInvalid) {
8905// return_type = g->builtin_types.entry_invalid;
8906// } else if (array_type->id == TypeTableEntryIdArray) {
8907// if (array_type->data.array.len == 0) {
8908// add_node_error(g, node, buf_sprintf("out of bounds array access"));
8909// }
8910// return_type = array_type->data.array.child_type;
8911// } else if (array_type->id == TypeTableEntryIdPointer) {
8912// if (array_type->data.pointer.is_const && purpose == LValPurposeAssign) {
8913// add_node_error(g, node, buf_sprintf("cannot assign to constant"));
8914// return g->builtin_types.entry_invalid;
8915// }
8916// return_type = array_type->data.pointer.child_type;
8917// } else if (array_type->id == TypeTableEntryIdStruct &&
8918// array_type->data.structure.is_slice)
8919// {
8920// TypeTableEntry *pointer_type = array_type->data.structure.fields[0].type_entry;
8921// if (pointer_type->data.pointer.is_const && purpose == LValPurposeAssign) {
8922// add_node_error(g, node, buf_sprintf("cannot assign to constant"));
8923// return g->builtin_types.entry_invalid;
8924// }
8925// return_type = pointer_type->data.pointer.child_type;
8926// } else {
8927// add_node_error(g, node,
8928// buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
8929// return_type = g->builtin_types.entry_invalid;
8930// }
8931//
8932// analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.array_access_expr.subscript);
8933//
8934// return return_type;
8935//}
8936//
89378911//static TypeTableEntry *analyze_unwrap_error_expr(CodeGen *g, ImportTableEntry *import,
89388912// BlockContext *parent_context, TypeTableEntry *expected_type, AstNode *node)
89398913//{
......@@ -9120,18 +9094,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
91209094// }
91219095//}
91229096//
9123//static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) {
9124// assert(node->type == NodeTypeArrayAccessExpr);
9125//
9126// AstNode *array_expr_node = node->data.array_access_expr.array_ref_expr;
9127// TypeTableEntry *array_type = get_expr_type(array_expr_node);
9128//
9129// LLVMValueRef array_ptr = gen_array_base_ptr(g, array_expr_node);
9130//
9131// LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript);
9132// return gen_array_elem_ptr(g, node, array_ptr, array_type, subscript_value);
9133//}
9134//
91359097//static LLVMValueRef gen_unwrap_err_expr(CodeGen *g, AstNode *node) {
91369098// assert(node->type == NodeTypeUnwrapErrorExpr);
91379099//