Skip to content

Commit de17a9b

Browse files
i fixed the params to fir (#41)
1 parent a5d9fb6 commit de17a9b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

bootstrap/repr/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include <stdio.h>
21
#include <stdint.h>
2+
#include <stdio.h>
33

44
extern uint64_t add(uint64_t, uint64_t);
55

66
int main() {
7-
printf("Hello");
8-
printf("Hello %lu", add(2, 7));
9-
puts("Hello");
7+
uint64_t val = add(2, 7);
8+
printf("Hello %lu\n", val);
9+
return val;
1010
}

bootstrap/repr/makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ all: .ty/main.o .ty/integrationc.o .ty/integration.o .ty/repr-37b621cda8f778ea.r
22
cd .ty && objdump -D integrationc.o > integrationc.o.txt
33
cd .ty && objdump -D integration.o > integrationty.o.txt
44
cd .ty && objdump -D repr-37b621cda8f778ea.repr.c0ded12167d2f276-cgu.0.rcgu.o > integrationrs.o.txt
5+
cc -o .ty/mainty .ty/integration.o .ty/main.o
56
touch .ty/all
67

78
.ty/main.o: main.c

fir/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,29 @@ impl Fir {
4444
types: &Vec<TypeTree>,
4545
oir: &mut Oir,
4646
) -> Function {
47-
let sig = Signature::new(CallConv::Cold);
47+
let sig = Signature::new(CallConv::Fast);
4848
let name = UserFuncName::user(namespace, index);
4949
// todo:: types need to be worked out, params and returns defined
5050
let mut func = Function::with_name_signature(name, sig);
5151
let mut builder = FunctionBuilder::new(&mut func, ctx);
5252
let root_block = builder.create_block();
53-
// todo:: this is the issue with function arguments not working simple repr add case
54-
func_def.args.iter().for_each(|x| {
53+
let mut result_sets = vec![];
54+
for x in func_def.args.iter() {
5555
let z = self
5656
.recurse(*x, &mut builder, dtbl, scopes, types, oir)
5757
.unwrap();
5858
builder.func.signature.params.push(AbiParam::new(I64));
59-
//let res = builder.block_params(root_block)[z.as_u32() as usize];
60-
});
61-
builder.func.signature.returns.push(AbiParam::new(I64));
59+
result_sets.push(z);
60+
}
6261
builder.append_block_params_for_function_params(root_block);
6362
builder.switch_to_block(root_block);
63+
64+
for (i, x) in result_sets.iter().enumerate() {
65+
let res = builder.block_params(root_block)[i];
66+
builder.def_var(*x, res);
67+
}
68+
builder.func.signature.returns.push(AbiParam::new(I64));
69+
6470
let _result = self.recurse(func_def.block, &mut builder, dtbl, scopes, types, oir);
6571
builder.seal_block(root_block);
6672
builder.finalize();
@@ -76,6 +82,7 @@ impl Fir {
7682
oir: &mut Oir,
7783
) -> ResultFir<Variable> {
7884
let result = self.add_var();
85+
builder.declare_var(result, I64);
7986
self.sym.table.insert(op.ident.clone(), result.as_u32());
8087
Ok(result)
8188
}

0 commit comments

Comments
 (0)