Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data milestone 2 #33

Merged
merged 20 commits into from
Dec 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
scir is coming along nicely.
coffeebe4code committed Dec 22, 2024
commit c60dc41187446ccb6ad480345d4cf4911849cc72
9 changes: 4 additions & 5 deletions fir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ use cranelift_codegen::verifier::verify_function;
use cranelift_frontend::*;
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use perror::*;
use std::rc::Rc;
use symtable::SymTable;
use types::*;

// Function Intermediate Representation
pub struct Fir {
variables: u32,
sym: SymTable,
@@ -29,16 +29,15 @@ impl Fir {
}
pub fn run(
&mut self,
func_def: Rc<Box<TypeTree>>,
func_def: &FunctionInitialize,
ctx: &mut FunctionBuilderContext,
namespace: u32,
index: u32,
) -> Function {
let mut sig = Signature::new(CallConv::SystemV);
let name = UserFuncName::user(namespace, index);
let func_init = func_def.into_func_init();
// todo:: types need to be worked out, params and returns defined
func_init
func_def
.args
.iter()
.for_each(|_x| sig.params.push(AbiParam::new(I64)));
@@ -48,7 +47,7 @@ impl Fir {
let root_block = builder.create_block();
builder.append_block_params_for_function_params(root_block);
builder.switch_to_block(root_block);
let _result = self.recurse(&func_init.block, &mut builder);
let _result = self.recurse(&func_def.block, &mut builder);
builder.seal_block(root_block);
builder.finalize();
func
3 changes: 2 additions & 1 deletion oir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ use cranelift_object::{ObjectBuilder, ObjectModule};
use types::Initialization;
use types::TypeTree;

// Object intermediate representation
pub struct Oir {
pub obj_mod: ObjectModule,
pub data: DataDescription,
@@ -34,7 +35,7 @@ impl Oir {
}

pub fn const_init(&mut self, init: &Initialization) -> DataId {
println!("const init {}", init.right.whatami());
println!("const init {:?}", init);
self.recurse(init.right.as_ref());
let id = self
.obj_mod
2 changes: 2 additions & 0 deletions scir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,3 +10,5 @@ fir = { path="../fir" }
scopetable = { path="../scopetable" }
typetable = { path="../typetable" }
symtable = { path="../symtable" }
cranelift-frontend = "0"
cranelift-codegen = "0"
41 changes: 41 additions & 0 deletions scir/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,64 @@
use std::rc::Rc;

use cranelift_codegen::ir::Function;
use cranelift_frontend::FunctionBuilderContext;
use fir::Fir;
use oir::Oir;
use scopetable::ScopeTable;
use symtable::SymTable;
use types::{FunctionInitialize, TypeTree};
use typetable::TypeTable;

pub struct Scir {
pub oir: Oir,
pub fir: Fir,
pub scopes: Vec<ScopeTable>,
pub type_tables: Vec<TypeTable>,
pub namespace: u32,
pub index: u32,
pub fbc: FunctionBuilderContext,
}

// Source Compiled Intermediate Representation
// Context of a Source file, these are the scopes, name, and type tables containing the type tree
// output from the linter.
// name = the name of the source file.
// scopes = the scopes output from linter.
// type_tables = the type table output from the linter
impl Scir {
pub fn new(name: &str, scopes: Vec<ScopeTable>, type_tables: Vec<TypeTable>) -> Scir {
Scir {
oir: Oir::new(name),
fir: Fir::new(0, SymTable::new()),
scopes,
type_tables,
namespace: 0,
index: 0,
fbc: FunctionBuilderContext::new(),
}
}
// top_res is the output top decls of the linter
pub fn loopf(&mut self, top_res: Vec<Rc<Box<TypeTree>>>) -> () {
for item in &top_res {
match item.as_ref().as_ref() {
TypeTree::ConstInit(ci) => {
self.oir.const_init(&ci);
}
TypeTree::FuncInit(fi) => {
let _fn = self.make_fir(fi);
self.oir.add_fn(&fi.name, _fn);
}
_ => panic!("developer error, unhandled loopfval, {:?}", item.clone()),
}
}
}
fn make_fir(&mut self, fi: &FunctionInitialize) -> Function {
self.fir.refresh();
let _fn = self.fir.run(fi, &mut self.fbc, self.namespace, self.index);
self.index += 1;
return _fn;
}
pub fn flush_self(self) -> Vec<u8> {
return self.oir.flush_self();
}
}