Skip to content

Commit

Permalink
i fixed the params to fir (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeebe4code authored Jan 9, 2025
1 parent a5d9fb6 commit de17a9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions bootstrap/repr/main.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>

extern uint64_t add(uint64_t, uint64_t);

int main() {
printf("Hello");
printf("Hello %lu", add(2, 7));
puts("Hello");
uint64_t val = add(2, 7);
printf("Hello %lu\n", val);
return val;
}
1 change: 1 addition & 0 deletions bootstrap/repr/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ all: .ty/main.o .ty/integrationc.o .ty/integration.o .ty/repr-37b621cda8f778ea.r
cd .ty && objdump -D integrationc.o > integrationc.o.txt
cd .ty && objdump -D integration.o > integrationty.o.txt
cd .ty && objdump -D repr-37b621cda8f778ea.repr.c0ded12167d2f276-cgu.0.rcgu.o > integrationrs.o.txt
cc -o .ty/mainty .ty/integration.o .ty/main.o
touch .ty/all

.ty/main.o: main.c
Expand Down
19 changes: 13 additions & 6 deletions fir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,29 @@ impl Fir {
types: &Vec<TypeTree>,
oir: &mut Oir,
) -> Function {
let sig = Signature::new(CallConv::Cold);
let sig = Signature::new(CallConv::Fast);
let name = UserFuncName::user(namespace, index);
// todo:: types need to be worked out, params and returns defined
let mut func = Function::with_name_signature(name, sig);
let mut builder = FunctionBuilder::new(&mut func, ctx);
let root_block = builder.create_block();
// todo:: this is the issue with function arguments not working simple repr add case
func_def.args.iter().for_each(|x| {
let mut result_sets = vec![];
for x in func_def.args.iter() {
let z = self
.recurse(*x, &mut builder, dtbl, scopes, types, oir)
.unwrap();
builder.func.signature.params.push(AbiParam::new(I64));
//let res = builder.block_params(root_block)[z.as_u32() as usize];
});
builder.func.signature.returns.push(AbiParam::new(I64));
result_sets.push(z);
}
builder.append_block_params_for_function_params(root_block);
builder.switch_to_block(root_block);

for (i, x) in result_sets.iter().enumerate() {
let res = builder.block_params(root_block)[i];
builder.def_var(*x, res);
}
builder.func.signature.returns.push(AbiParam::new(I64));

let _result = self.recurse(func_def.block, &mut builder, dtbl, scopes, types, oir);
builder.seal_block(root_block);
builder.finalize();
Expand All @@ -76,6 +82,7 @@ impl Fir {
oir: &mut Oir,
) -> ResultFir<Variable> {
let result = self.add_var();
builder.declare_var(result, I64);
self.sym.table.insert(op.ident.clone(), result.as_u32());
Ok(result)
}
Expand Down

0 comments on commit de17a9b

Please sign in to comment.