Skip to content

Commit

Permalink
[master] switch from i1 to i8 for bool (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Apr 17, 2017
1 parent ecc5ea9 commit 5e7fd04
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 14 deletions.
20 changes: 20 additions & 0 deletions src/dale/BasicTypes/BasicTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ makeFunction(Context *ctx, llvm::Module *mod, std::string *once_tag,
(*(iter + 1))->value,
unused_twine)
);
if (ret_type->base_type == BaseType::Bool) {
ret_val = builder.CreateZExt(ret_val,
ctx->toLLVMType(ret_type,
NULL, false));
}
builder.CreateRet(ret_val);
}

Expand Down Expand Up @@ -199,6 +204,11 @@ makeFunction(Context *ctx, llvm::Module *mod, std::string *once_tag,
unused_twine,
false)
);
if (ret_type->base_type == BaseType::Bool) {
ret_val = builder.CreateZExt(ret_val,
ctx->toLLVMType(ret_type,
NULL, false));
}
builder.CreateRet(ret_val);
}

Expand Down Expand Up @@ -229,6 +239,11 @@ makeFunction(Context *ctx, llvm::Module *mod, std::string *once_tag,
false,
true)
);
if (ret_type->base_type == BaseType::Bool) {
ret_val = builder.CreateZExt(ret_val,
ctx->toLLVMType(ret_type,
NULL, false));
}
builder.CreateRet(ret_val);
}

Expand Down Expand Up @@ -259,6 +274,11 @@ makeFunction(Context *ctx, llvm::Module *mod, std::string *once_tag,
false,
true)
);
if (ret_type->base_type == BaseType::Bool) {
ret_val = builder.CreateZExt(ret_val,
ctx->toLLVMType(ret_type,
NULL, false));
}
builder.CreateRet(ret_val);
}

Expand Down
2 changes: 1 addition & 1 deletion src/dale/Context/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ Context::toLLVMTypeBase(Type *type,
case BaseType::UInt: lbt = nt->getNativeUIntType(); break;
case BaseType::Char: lbt = nt->getNativeCharType(); break;
case BaseType::Void: lbt = llvm::Type::getVoidTy(lc); break;
case BaseType::Bool: lbt = llvm::Type::getInt1Ty(lc); break;
case BaseType::Bool: lbt = nt->getNativeCharType(); break;
case BaseType::Float: lbt = llvm::Type::getFloatTy(lc); break;
case BaseType::Double: lbt = llvm::Type::getDoubleTy(lc); break;
case BaseType::LongDouble: lbt = nt->getNativeLongDoubleType(); break;
Expand Down
9 changes: 7 additions & 2 deletions src/dale/Form/Proc/If/If.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ FormProcIfParse(Units *units, Function *fn, llvm::BasicBlock *block,
"else", fn->llvm_function);

llvm::IRBuilder<> builder_cond(cond_pr.block);
builder_cond.CreateCondBr(cond_pr.getValue(ctx),
then_block, else_block);
builder_cond.CreateCondBr(
builder_cond.CreateTrunc(
cond_pr.getValue(ctx),
llvm::Type::getInt1Ty(llvm::getGlobalContext())
),
then_block, else_block
);

ParseResult destruct_pr;
res = Operation::Destruct(ctx, &cond_pr, &destruct_pr, &builder_cond);
Expand Down
7 changes: 5 additions & 2 deletions src/dale/Form/Proc/Null/Null.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ FormProcNullParse(Units *units, Function *fn, llvm::BasicBlock *block,
ctx->nt->getNativeIntType());

llvm::Value *null_res =
llvm::cast<llvm::Value>(
builder.CreateICmpEQ(int_res, ctx->nt->getLLVMZero())
builder.CreateZExt(
llvm::cast<llvm::Value>(
builder.CreateICmpEQ(int_res, ctx->nt->getLLVMZero())
),
llvm::Type::getInt8Ty(llvm::getGlobalContext())
);

ParseResult destruct_pr;
Expand Down
9 changes: 7 additions & 2 deletions src/dale/Form/Proc/PtrEquals/PtrEquals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ FormProcPtrEqualsParse(Units *units, Function *fn,

llvm::IRBuilder<> builder(ptr_pr2.block);
llvm::Value *cmp_res =
llvm::cast<llvm::Value>(builder.CreateICmpEQ(ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)));
builder.CreateZExt(
llvm::cast<llvm::Value>(builder.CreateICmpEQ(
ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)
)),
llvm::Type::getInt8Ty(llvm::getGlobalContext())
);

ptr_pr1.block = ptr_pr2.block;
ParseResult destruct_pr;
Expand Down
9 changes: 7 additions & 2 deletions src/dale/Form/Proc/PtrGreaterThan/PtrGreaterThan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ FormProcPtrGreaterThanParse(Units *units, Function *fn,

llvm::IRBuilder<> builder(ptr_pr2.block);
llvm::Value *cmp_res =
llvm::cast<llvm::Value>(builder.CreateICmpUGT(ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)));
builder.CreateZExt(
llvm::cast<llvm::Value>(builder.CreateICmpUGT(
ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)
)),
llvm::Type::getInt8Ty(llvm::getGlobalContext())
);

ptr_pr1.block = ptr_pr2.block;
ParseResult destruct_pr;
Expand Down
9 changes: 7 additions & 2 deletions src/dale/Form/Proc/PtrLessThan/PtrLessThan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ FormProcPtrLessThanParse(Units *units, Function *fn,

llvm::IRBuilder<> builder(ptr_pr2.block);
llvm::Value *cmp_res =
llvm::cast<llvm::Value>(builder.CreateICmpULT(ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)));
builder.CreateZExt(
llvm::cast<llvm::Value>(builder.CreateICmpULT(
ptr_pr1.getValue(ctx),
ptr_pr2.getValue(ctx)
)),
llvm::Type::getInt8Ty(llvm::getGlobalContext())
);

ptr_pr1.block = ptr_pr2.block;
ParseResult destruct_pr;
Expand Down
2 changes: 1 addition & 1 deletion src/dale/Form/Proc/Token/Token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ parseBoolLiteral(Context *ctx, llvm::BasicBlock *block, Node *node,
if (is_true || is_false) {
pr->set(block, ctx->tr->type_bool,
llvm::ConstantInt::get(
llvm::Type::getInt1Ty(llvm::getGlobalContext()),
llvm::Type::getInt8Ty(llvm::getGlobalContext()),
is_true
));
}
Expand Down
4 changes: 2 additions & 2 deletions src/dale/NativeTypes/NativeTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ NativeTypes::NativeTypes()
llvm::LLVMContext &lc = llvm::getGlobalContext();

llvm::Type *native_bool_type =
llvm::IntegerType::get(lc, 1);
native_char_type = llvm::IntegerType::get(lc, BITS(char));
native_char_type = llvm::IntegerType::get(lc, BITS(char));

native_int_type =
native_uint_type = llvm::IntegerType::get(lc, BITS(int));
native_intptr_type = llvm::IntegerType::get(lc, BITS(char *));
Expand Down

0 comments on commit 5e7fd04

Please sign in to comment.