Skip to content

Commit a08823c

Browse files
committed
feedback
1 parent f30cbbc commit a08823c

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/codegen/generators/statement_generator.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (c) 2020 Ghaith Hachem and Mathias Rieder
22
use super::{
3-
expression_generator::{to_i1, ExpressionCodeGenerator},
3+
expression_generator::{to_i1, ExpressionCodeGenerator, ExpressionValue},
44
llvm::Llvm,
55
};
66
use crate::{
@@ -11,7 +11,7 @@ use crate::{
1111
},
1212
index::{ImplementationIndexEntry, Index},
1313
resolver::{AnnotationMap, AstAnnotations, StatementAnnotation},
14-
typesystem::{get_bigger_type, DataTypeInformation},
14+
typesystem::{get_bigger_type, DataTypeInformation, DINT_TYPE},
1515
};
1616
use inkwell::{
1717
basic_block::BasicBlock,
@@ -332,8 +332,8 @@ impl<'a, 'b> StatementCodeGenerator<'a, 'b> {
332332

333333
let end_ty = self.annotations.get_type_or_void(end, self.index);
334334
let counter_ty = self.annotations.get_type_or_void(counter, self.index);
335-
let ty = get_bigger_type(self.index.get_type_or_panic("DINT"), counter_ty, self.index);
336-
let ll_ty = self.llvm_index.find_associated_type(ty.get_name()).unwrap();
335+
let cast_target_ty = get_bigger_type(self.index.get_type_or_panic(DINT_TYPE), counter_ty, self.index);
336+
let cast_target_llty = self.llvm_index.find_associated_type(cast_target_ty.get_name()).unwrap();
337337

338338
let step_ty = by_step.as_ref().map(|it| {
339339
self.register_debug_location(it);
@@ -342,10 +342,10 @@ impl<'a, 'b> StatementCodeGenerator<'a, 'b> {
342342

343343
let eval_step = || {
344344
step_ty.map_or_else(
345-
|| self.llvm.create_const_numeric(&ll_ty, "1", SourceLocation::undefined()),
345+
|| self.llvm.create_const_numeric(&cast_target_llty, "1", SourceLocation::undefined()),
346346
|step_ty| {
347347
let step = exp_gen.generate_expression(by_step.as_ref().unwrap())?;
348-
Ok(cast_if_needed!(exp_gen, ty, step_ty, step, None))
348+
Ok(cast_if_needed!(exp_gen, cast_target_ty, step_ty, step, None))
349349
},
350350
)
351351
};
@@ -366,7 +366,9 @@ impl<'a, 'b> StatementCodeGenerator<'a, 'b> {
366366
let is_incrementing = builder.build_int_compare(
367367
inkwell::IntPredicate::SGT,
368368
eval_step()?.into_int_value(),
369-
self.llvm.create_const_numeric(&ll_ty, "0", SourceLocation::undefined())?.into_int_value(),
369+
self.llvm
370+
.create_const_numeric(&cast_target_llty, "0", SourceLocation::undefined())?
371+
.into_int_value(),
370372
"is_incrementing",
371373
);
372374
builder.build_conditional_branch(is_incrementing, predicate_incrementing, predicate_decrementing);
@@ -380,14 +382,14 @@ impl<'a, 'b> StatementCodeGenerator<'a, 'b> {
380382

381383
let end = exp_gen.generate_expression_value(end).unwrap();
382384
let end_value = match end {
383-
super::expression_generator::ExpressionValue::LValue(ptr) => builder.build_load(ptr, ""),
384-
super::expression_generator::ExpressionValue::RValue(val) => val,
385+
ExpressionValue::LValue(ptr) => builder.build_load(ptr, ""),
386+
ExpressionValue::RValue(val) => val,
385387
};
386388
let counter_value = builder.build_load(counter, "");
387389
let cmp = builder.build_int_compare(
388390
predicate,
389-
cast_if_needed!(exp_gen, ty, counter_ty, counter_value, None).into_int_value(),
390-
cast_if_needed!(exp_gen, ty, end_ty, end_value, None).into_int_value(),
391+
cast_if_needed!(exp_gen, cast_target_ty, counter_ty, counter_value, None).into_int_value(),
392+
cast_if_needed!(exp_gen, cast_target_ty, end_ty, end_value, None).into_int_value(),
391393
"condition",
392394
);
393395
builder.build_conditional_branch(cmp, loop_body, afterloop);
@@ -412,10 +414,13 @@ impl<'a, 'b> StatementCodeGenerator<'a, 'b> {
412414
let counter_value = builder.build_load(counter, "");
413415
let inc = inkwell::values::BasicValue::as_basic_value_enum(&builder.build_int_add(
414416
eval_step()?.into_int_value(),
415-
cast_if_needed!(exp_gen, ty, counter_ty, counter_value, None).into_int_value(),
417+
cast_if_needed!(exp_gen, cast_target_ty, counter_ty, counter_value, None).into_int_value(),
416418
"next",
417419
));
418-
builder.build_store(counter, cast_if_needed!(exp_gen, counter_ty, ty, inc, None).into_int_value());
420+
builder.build_store(
421+
counter,
422+
cast_if_needed!(exp_gen, counter_ty, cast_target_ty, inc, None).into_int_value(),
423+
);
419424

420425
// check condition
421426
builder.build_conditional_branch(is_incrementing, predicate_incrementing, predicate_decrementing);

0 commit comments

Comments
 (0)