irgen of ast2

This commit is contained in:
Janis 2024-12-29 19:57:29 +01:00
parent f6b956deee
commit 43c828d96f
3 changed files with 156 additions and 3 deletions

4
Makefile Normal file
View file

@ -0,0 +1,4 @@
test:
cargo run --bin main -- -i tests/legal/call.sea asm > asm.S
clang asm.S -c && clang asm.o -o asm && ./asm; echo $$?

View file

@ -4502,10 +4502,15 @@ pub mod ast_gen {
}
}
pub mod ir_gen {
pub mod irgen {
use super::visitor::AstExt;
use super::*;
use crate::{symbol_table::syms2::Symbols, triples::*};
use crate::{
symbol_table::syms2::Symbols,
triples::{self, *},
};
use std::collections::HashMap;
struct IRGen {
ast: Ast,
@ -4514,5 +4519,143 @@ pub mod ir_gen {
ip: intern::InternPool,
}
impl IRGen {}
impl IRGen {
fn build(&mut self) {
let mut mapping = HashMap::<Index, u32>::new();
self.ast.visitor().visit(
|ast, scopes, i, tag, data| {
// pre
match tag {
Tag::Root => todo!(),
Tag::File => todo!(),
Tag::FunctionProto => todo!(),
Tag::FunctionDecl => todo!(),
Tag::ParameterList => todo!(),
Tag::Parameter => todo!(),
Tag::Block => todo!(),
Tag::BlockTrailingExpr => todo!(),
Tag::Constant => todo!(),
Tag::ExprStmt => todo!(),
Tag::ReturnStmt => todo!(),
Tag::ReturnExprStmt => todo!(),
Tag::VarDecl => todo!(),
Tag::MutVarDecl => todo!(),
Tag::VarDeclAssignment => todo!(),
Tag::MutVarDeclAssignment => todo!(),
Tag::GlobalDecl => todo!(),
Tag::StructDecl => todo!(),
Tag::FieldDecl => todo!(),
Tag::DeclRef => todo!(),
Tag::DeclRefUnresolved => todo!(),
Tag::InternedType => todo!(),
Tag::TypeDeclRef => todo!(),
Tag::TypeDeclRefUnresolved => todo!(),
Tag::PointerType => todo!(),
Tag::ArrayType => todo!(),
Tag::CallExpr => todo!(),
Tag::FieldAccess => todo!(),
Tag::ArgumentList => todo!(),
Tag::Argument => todo!(),
Tag::NamedArgument => todo!(),
Tag::ExplicitCast => todo!(),
Tag::Deref => todo!(),
Tag::AddressOf => todo!(),
Tag::Not => todo!(),
Tag::Negate => todo!(),
Tag::Or => todo!(),
Tag::And => todo!(),
Tag::BitOr => todo!(),
Tag::BitXOr => todo!(),
Tag::BitAnd => todo!(),
Tag::Eq => todo!(),
Tag::NEq => todo!(),
Tag::Lt => todo!(),
Tag::Gt => todo!(),
Tag::Le => todo!(),
Tag::Ge => todo!(),
Tag::Shl => todo!(),
Tag::Shr => todo!(),
Tag::Add => todo!(),
Tag::Sub => todo!(),
Tag::Mul => todo!(),
Tag::Div => todo!(),
Tag::Rem => todo!(),
Tag::Assign => todo!(),
Tag::SubscriptExpr => todo!(),
Tag::IfExpr => todo!(),
Tag::IfElseExpr => todo!(),
Tag::Error => todo!(),
Tag::Undefined => todo!(),
}
},
|ast, scopes, i, tag, data| {
// post
match tag {
Tag::Root => todo!(),
Tag::File => todo!(),
Tag::FunctionProto => todo!(),
Tag::FunctionDecl => {
todo!()
}
Tag::ParameterList => todo!(),
Tag::Parameter => todo!(),
Tag::Block => todo!(),
Tag::BlockTrailingExpr => todo!(),
Tag::Constant => todo!(),
Tag::ExprStmt => todo!(),
Tag::ReturnStmt => todo!(),
Tag::ReturnExprStmt => todo!(),
Tag::VarDecl => todo!(),
Tag::MutVarDecl => todo!(),
Tag::VarDeclAssignment => todo!(),
Tag::MutVarDeclAssignment => todo!(),
Tag::GlobalDecl => todo!(),
Tag::StructDecl => todo!(),
Tag::FieldDecl => todo!(),
Tag::DeclRef => todo!(),
Tag::DeclRefUnresolved => todo!(),
Tag::InternedType => todo!(),
Tag::TypeDeclRef => todo!(),
Tag::TypeDeclRefUnresolved => todo!(),
Tag::PointerType => todo!(),
Tag::ArrayType => todo!(),
Tag::CallExpr => todo!(),
Tag::FieldAccess => todo!(),
Tag::ArgumentList => todo!(),
Tag::Argument => todo!(),
Tag::NamedArgument => todo!(),
Tag::ExplicitCast => todo!(),
Tag::Deref => todo!(),
Tag::AddressOf => todo!(),
Tag::Not => todo!(),
Tag::Negate => todo!(),
Tag::Or => todo!(),
Tag::And => todo!(),
Tag::BitOr => todo!(),
Tag::BitXOr => todo!(),
Tag::BitAnd => todo!(),
Tag::Eq => todo!(),
Tag::NEq => todo!(),
Tag::Lt => todo!(),
Tag::Gt => todo!(),
Tag::Le => todo!(),
Tag::Ge => todo!(),
Tag::Shl => todo!(),
Tag::Shr => todo!(),
Tag::Add => todo!(),
Tag::Sub => todo!(),
Tag::Mul => todo!(),
Tag::Div => todo!(),
Tag::Rem => todo!(),
Tag::Assign => todo!(),
Tag::SubscriptExpr => todo!(),
Tag::IfExpr => todo!(),
Tag::IfElseExpr => todo!(),
Tag::Error => todo!(),
Tag::Undefined => todo!(),
}
},
);
}
}
}

View file

@ -0,0 +1,6 @@
fn main() -> u32 {
let a: u10 = 16u10;
let b: u80 = 299;
return a as u32 + b as u32;
}