This commit is contained in:
nora 2023-05-24 20:24:19 +02:00
parent f321d0e9e1
commit ee0b311261
12 changed files with 265 additions and 36 deletions

View file

@ -12,7 +12,7 @@ use crate::{
};
#[derive(Debug)]
pub(crate) struct LoweringCx<'cx> {
pub struct LoweringCx<'cx> {
tys: RefCell<FxHashSet<&'cx TyKind<'cx>>>,
layouts: RefCell<FxHashSet<&'cx Layout>>,
string_literals: RefCell<FxHashMap<&'cx [u8], DefId>>,
@ -23,7 +23,7 @@ pub(crate) struct LoweringCx<'cx> {
}
impl<'cx> LoweringCx<'cx> {
pub(crate) fn new(arena: &'cx bumpalo::Bump) -> Self {
pub fn new(arena: &'cx bumpalo::Bump) -> Self {
LoweringCx {
tys: RefCell::default(),
layouts: RefCell::default(),

View file

@ -2,17 +2,18 @@
#![warn(rust_2018_idioms)]
mod ctxt;
mod ir;
pub mod ir;
mod lower;
mod ty;
pub mod ty;
pub use ctxt::LoweringCx;
pub use lower::lower_translation_unit;
use parser::Span;
#[derive(Debug)]
pub struct Error {
msg: String,
span: Span,
span: Option<Span>,
notes: Vec<Note>,
}
@ -26,7 +27,15 @@ impl Error {
pub fn new(msg: impl Into<String>, span: Span) -> Self {
Self {
msg: msg.into(),
span,
span: Some(span),
notes: Vec::new(),
}
}
pub fn new_without_span(msg: impl Into<String>) -> Self {
Self {
msg: msg.into(),
span: None,
notes: Vec::new(),
}
}

View file

@ -21,11 +21,9 @@ use crate::{
type Result<T, E = Error> = std::result::Result<T, E>;
pub fn lower_translation_unit<'cx>(
arena: &'cx bumpalo::Bump,
lcx: &mut LoweringCx<'cx>,
ast: &ast::TranslationUnit,
) -> Result<Ir<'cx>, Error> {
let mut lcx = LoweringCx::new(arena);
let mut ir = Ir {
funcs: FxHashMap::default(),
};