Fix bug with string literals
This commit is contained in:
parent
e76540182f
commit
de881d73d2
@ -37,7 +37,7 @@ namespace AST {
|
||||
return std::shared_ptr<types::Type> {stack_type};
|
||||
}
|
||||
|
||||
codegen::StackValue StringLiteralExpression::codegen(codegen::Builder& builder, codegen::Scope&) {
|
||||
codegen::StackValue StringLiteralExpression::codegen(codegen::Builder& builder, codegen::Scope& scope) {
|
||||
auto stack_type = new types::ArrayType{
|
||||
std::make_unique<types::FundamentalType>(types::FundamentalTypeKind::Char),
|
||||
static_cast<uint32_t>(this->m_value.size()) + 1
|
||||
@ -46,10 +46,18 @@ namespace AST {
|
||||
auto str = llvm::StringRef{ this->m_value.c_str() };
|
||||
auto global_str = builder.builder->CreateGlobalString(str);
|
||||
|
||||
return codegen::StackValue{
|
||||
builder.builder->CreateLoad(stack_type->codegen(builder), global_str, "literal"),
|
||||
std::unique_ptr<types::Type>{stack_type},
|
||||
};
|
||||
if (scope.is_lvalue) {
|
||||
return codegen::StackValue{
|
||||
global_str,
|
||||
std::unique_ptr<types::Type>{stack_type},
|
||||
};
|
||||
}
|
||||
else {
|
||||
return codegen::StackValue{
|
||||
builder.builder->CreateLoad(stack_type->codegen(builder), global_str, "literal"),
|
||||
std::unique_ptr<types::Type>{stack_type},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<types::Type> ValueReferenceExpression::get_codegen_type(codegen::Scope& scope) {
|
||||
@ -159,7 +167,9 @@ namespace AST {
|
||||
|
||||
codegen::StackValue CastExpression::codegen(codegen::Builder& builder, codegen::Scope& scope) {
|
||||
auto expr_ty = this->m_expr->get_codegen_type(scope);
|
||||
if (expr_ty->m_kind == types::TypeKind::Pointer && this->m_ty->m_kind == types::TypeKind::Pointer) {
|
||||
if ((expr_ty->m_kind == types::TypeKind::Array
|
||||
|| expr_ty->m_kind == types::TypeKind::Pointer)
|
||||
&& this->m_ty->m_kind == types::TypeKind::Pointer) {
|
||||
std::cout << expr_ty->formatted() << std::endl;
|
||||
auto lvalued = scope.with_lvalue();
|
||||
auto expr = this->m_expr->codegen(builder, lvalued);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user