Skip to content

Commit 10aec9f

Browse files
committed
Implemented and removed some TODOs
1 parent 614aaeb commit 10aec9f

File tree

10 files changed

+26
-54
lines changed

10 files changed

+26
-54
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ wabt = "0.10.0"
1919
ewasm_api = "0.11.0"
2020
libchisel = "0.6.0"
2121
parity-wasm = "0.41.0"
22-
pwasm-utils = "0.14.0"
23-
num-bigint = "0.3.0"
22+
pwasm-utils = "0.14.0"

src/ewasm/assignment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ impl<'a> LLVMAssignment<'a> {
1919
codegen: &mut Codegen<'_, 'ctx>,
2020
function_context: &mut FunctionContext<'ctx>,
2121
) -> Option<BasicValueEnum<'ctx>> {
22-
function_context.assigning = true;
22+
function_context.requires_pointer = true;
2323
let lhs = LLVMExpression {
2424
expression: self.lhs,
2525
}
2626
.generate(codegen, function_context)
2727
.unwrap();
28-
function_context.assigning = false;
28+
function_context.requires_pointer = false;
2929
let rhs = LLVMExpression {
3030
expression: self.rhs,
3131
}

src/ewasm/expressions.rs

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ impl<'a> LLVMIdentifier<'a> {
107107
line_info: Default::default(),
108108
}),
109109
}
110-
.generate(codegen, function_context)
111-
} else if self.identifier.token.as_str().eq(codegen.contract_name) {
112-
// TODO is this necessary? Might we just add the global to the function context instead?
110+
.generate(codegen, function_context)
111+
} else if !self.identifier.token.as_str().eq(codegen.contract_name) {
112+
let variable = function_context
113+
.get_declaration(self.identifier.token.as_str())
114+
.unwrap();
115+
116+
Some(*variable)
117+
} else {
113118
Some(
114119
codegen
115120
.module
@@ -118,12 +123,6 @@ impl<'a> LLVMIdentifier<'a> {
118123
.as_pointer_value()
119124
.as_basic_value_enum(),
120125
)
121-
} else {
122-
let variable = function_context
123-
.get_declaration(self.identifier.token.as_str())
124-
.unwrap();
125-
126-
Some(*variable)
127126
}
128127
}
129128
}
@@ -793,14 +792,13 @@ impl<'a> LLVMInoutExpression<'a> {
793792
function_context: &mut FunctionContext<'ctx>,
794793
) -> Option<BasicValueEnum<'ctx>> {
795794
// An assumption is that inout expressions are only used on structs
796-
function_context.assigning = true;
797-
dbg!(self.expression.clone());
795+
function_context.requires_pointer = true;
798796
let expr = LLVMExpression {
799797
expression: &self.expression.expression,
800798
}
801799
.generate(codegen, function_context)
802800
.unwrap();
803-
function_context.assigning = false;
801+
function_context.requires_pointer = false;
804802

805803
if expr.is_pointer_value()
806804
&& expr
@@ -823,22 +821,6 @@ impl<'a> LLVMInoutExpression<'a> {
823821

824822
Some(BasicValueEnum::PointerValue(ptr))
825823
}
826-
827-
/*if expr.is_pointer_value()
828-
&& expr
829-
.into_pointer_value()
830-
.get_name()
831-
.to_str()
832-
.expect("cannot convert cstr to str")
833-
.eq(codegen.contract_name)
834-
{
835-
return Some(expr);
836-
}
837-
838-
let ptr = codegen.builder.build_alloca(expr.get_type(), "tmp_ptr");
839-
codegen.builder.build_store(ptr, expr);
840-
841-
Some(BasicValueEnum::PointerValue(ptr))*/
842824
}
843825
}
844826

@@ -900,7 +882,7 @@ impl<'a> LLVMCastExpression<'a> {
900882
}
901883
.generate(codegen);
902884

903-
// TODO: which opcode should we pick here?
885+
// TODO: which opcode should we pick here? We need tests for this
904886
Some(codegen.builder.build_cast(
905887
InstructionOpcode::Load,
906888
cast_from_val,

src/ewasm/function.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ impl<'a> LLVMFunction<'a> {
5454
}
5555
}
5656

57-
// TODO: add tags
58-
// TODO: add dictionary to tags?
5957
for statement in &self.function_declaration.body {
6058
if statement.eq(self.function_declaration.body.last().unwrap()) {
6159
function_context.is_last_statement = true;
@@ -98,7 +96,6 @@ pub fn generate_function_type(function_declaration: &FunctionDeclaration, codege
9896
.collect();
9997

10098
let func_type = if let Some(result_type) = function_declaration.get_result_type() {
101-
// TODO: should is_var_args be false?
10299
LLVMType {
103100
ast_type: &result_type,
104101
}

src/ewasm/function_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub struct FunctionContext<'a> {
66
this_func: FunctionValue<'a>,
77
parameters: HashMap<String, BasicValueEnum<'a>>,
88
locals: HashMap<String, BasicValueEnum<'a>>,
9-
pub assigning: bool,
9+
pub requires_pointer: bool,
1010
pub is_last_statement: bool,
1111
}
1212

@@ -16,7 +16,7 @@ impl<'a> FunctionContext<'a> {
1616
this_func: func,
1717
parameters: params,
1818
locals: HashMap::new(),
19-
assigning: false,
19+
requires_pointer: false,
2020
is_last_statement: false,
2121
}
2222
}

src/ewasm/preprocessor/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ impl Visitor for LLVMPreProcessor {
5353
) -> VResult {
5454
// If we are in the declaration that contains the initialiser, then that is where we will insert the
5555
// getters and setters since there are no caller protections or type state restrictions
56-
// TODO the above explanation is somewhat hacky
5756
if declaration
5857
.members
5958
.iter()
@@ -204,7 +203,6 @@ impl Visitor for LLVMPreProcessor {
204203
scope_ctx.parameters.push(self_param)
205204
}
206205
}
207-
// TODO: dynamic parameters?
208206

209207
Ok(())
210208
}
@@ -365,7 +363,6 @@ impl Visitor for LLVMPreProcessor {
365363

366364
expr.lhs_expression = Box::from(Expression::SelfExpression);
367365
expr.rhs_expression = Box::from(Expression::BinaryExpression(rhs));
368-
// TODO: check if this is the correct local variable to add
369366
scope_ctx.local_variables.push(VariableDeclaration {
370367
declaration_token: None,
371368
identifier: id,

src/ewasm/struct_access.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ impl<'a> LLVMStructAccess<'a> {
4040
function_context: &mut FunctionContext<'ctx>,
4141
) -> Option<BasicValueEnum<'ctx>> {
4242
if let [first, accesses @ ..] = self.flatten_expr(self.expr).as_slice() {
43-
// TODO account for the fact that we might have something like foo().bar() if foo returns a struct
4443
let the_struct = function_context.get_declaration(first.as_field()).unwrap();
4544
let the_struct = the_struct.into_pointer_value();
4645

@@ -52,7 +51,7 @@ impl<'a> LLVMStructAccess<'a> {
5251
}
5352
});
5453

55-
if function_context.assigning {
54+
if function_context.requires_pointer {
5655
access.map(|ptr| ptr.as_basic_value_enum())
5756
} else if let Some(ptr) = access {
5857
Some(codegen.builder.build_load(ptr, "loaded"))

src/ewasm/temporary_llvm_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,14 @@ pub fn structs(codegen: &Codegen) {
533533
assert_eq!(get_bxx2.call(), 0);
534534
// assert_eq!(get_bxx3.call(), 256); Power function not implemented
535535
set_bxx3.call(5);
536-
assert_eq!(get_bxx.call(), 5); // TODO does not pass
536+
assert_eq!(get_bxx.call(), 5);
537537

538538
// Cxx
539539
assert_eq!(get_cxx.call(), 0);
540540
set_cxx.call(10);
541-
assert_eq!(get_cxx.call(), 10); // TODO does not pass
541+
assert_eq!(get_cxx.call(), 10);
542542
set_cxx2.call(5);
543-
assert_eq!(get_cxx.call(), 5); // TODO does not pass
543+
assert_eq!(get_cxx.call(), 5);
544544

545545
// Bxy
546546
assert!(!get_bxy.call());
@@ -556,8 +556,8 @@ pub fn structs(codegen: &Codegen) {
556556
assert_eq!(get_size.call(), 0);
557557
assert_eq!(get.call(0), 0);
558558
append.call(5);
559-
assert_eq!(get_size.call(), 1); // TODO does not pass
560-
assert_eq!(get.call(0), 5); // TODO does not pass
559+
assert_eq!(get_size.call(), 1);
560+
assert_eq!(get.call(0), 5);
561561

562562
// D
563563
assert_eq!(get_d.call(), 5);

src/ewasm/types.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@ use super::inkwell::AddressSpace;
33
use crate::ast::{FixedSizedArrayType, InoutType, Type};
44
use crate::ewasm::Codegen;
55

6-
// I wonder whether we should return our own wrapper type, so we may add more information if we want?
76
pub struct LLVMType<'a> {
87
pub ast_type: &'a Type,
98
}
109

1110
impl<'a> LLVMType<'a> {
1211
pub fn generate<'ctx>(&self, codegen: &mut Codegen<'_, 'ctx>) -> BasicTypeEnum<'ctx> {
1312
let context = codegen.context;
14-
// TODO add address space parameter? (see documentation)
1513

1614
match self.ast_type {
1715
Type::InoutType(inout) => self.inout_to_llvm(inout, codegen),
@@ -23,11 +21,11 @@ impl<'a> LLVMType<'a> {
2321
self.extract_defined_type(definition.token.as_str(), codegen)
2422
}
2523
Type::Solidity(_) => unimplemented!(),
26-
Type::SelfType => unimplemented!(), // TODO implement
24+
Type::SelfType => unimplemented!(),
2725
Type::Bool => context.bool_type().as_basic_type_enum(),
2826
Type::Int => context.i64_type().as_basic_type_enum(),
2927
Type::String => unimplemented!(),
30-
Type::Address => context.custom_width_int_type(160).as_basic_type_enum(), // Needs to be a 160 bit number?
28+
Type::Address => context.custom_width_int_type(160).as_basic_type_enum(),
3129
Type::Error => unimplemented!(),
3230
Type::TypeState => context.i8_type().as_basic_type_enum(),
3331
}

src/ewasm_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ mod ewasm_tests {
1717
fn test_ewasm_validity() {
1818
// List the filenames we want to test separated by a space
1919
// TODO refactor this process not to rely on move test folder
20-
let file_names = "counter factorial shapes assert traffic_lights operators memory inits rockpaperscissors public_and_visible typestates_counter property_modification"
20+
let file_names = "counter factorial shapes assert traffic_lights operators memory inits rockpaperscissors public_and_visible typestates_counter property_modification structs"
2121
.split(' ')
22-
.zip("Counter Factorial Shapes Assert TrafficLights Operators Memory Inits RockPaperScissors MyContract Counter PropertyModification".split(' '))
22+
.zip("Counter Factorial Shapes Assert TrafficLights Operators Memory Inits RockPaperScissors MyContract Counter PropertyModification C".split(' '))
2323
.collect::<Vec<(&str, &str)>>();
2424

2525
for (flint_file_name, wasm_file_name) in file_names {

0 commit comments

Comments
 (0)