Compare commits
	
		
			No commits in common. "6cc1822ec6f51ec775744839ec6e53905e0c474c" and "379769bc59d6931f91533d68399413ca6ab86fe7" have entirely different histories.
		
	
	
		
			6cc1822ec6
			...
			379769bc59
		
	
		
|  | @ -402,73 +402,6 @@ impl Index { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| pub struct InternPoolWrapper(core::cell::UnsafeCell<InternPool>); | ||||
| 
 | ||||
| impl InternPoolWrapper { | ||||
|     pub fn as_mut(&self) -> &mut InternPool { | ||||
|         unsafe { &mut *self.0.get() } | ||||
|     } | ||||
|     pub fn as_ref(&self) -> &InternPool { | ||||
|         unsafe { &*self.0.get() } | ||||
|     } | ||||
| 
 | ||||
|     pub fn new() -> Self { | ||||
|         InternPool::new().into() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl From<InternPool> for InternPoolWrapper { | ||||
|     fn from(value: InternPool) -> Self { | ||||
|         Self(core::cell::UnsafeCell::new(value)) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl core::ops::Deref for InternPoolWrapper { | ||||
|     type Target = InternPool; | ||||
| 
 | ||||
|     fn deref(&self) -> &Self::Target { | ||||
|         unsafe { &*self.0.get() } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl core::ops::DerefMut for InternPoolWrapper { | ||||
|     fn deref_mut(&mut self) -> &mut Self::Target { | ||||
|         self.as_mut() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl AsRef<InternPool> for InternPoolWrapper { | ||||
|     fn as_ref(&self) -> &InternPool { | ||||
|         Self::as_ref(self) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl AsRef<InternPool> for InternPool { | ||||
|     fn as_ref(&self) -> &InternPool { | ||||
|         self | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| // impl AsMut<InternPool> for InternPoolWrapper {
 | ||||
| //     fn as_mut(&mut self) -> &mut InternPool {
 | ||||
| //         Self::as_mut(self)
 | ||||
| //     }
 | ||||
| // }
 | ||||
| 
 | ||||
| // impl AsMut<InternPool> for InternPool {
 | ||||
| //     fn as_mut(&mut self) -> &mut InternPool {
 | ||||
| //         self
 | ||||
| //     }
 | ||||
| // }
 | ||||
| 
 | ||||
| impl core::fmt::Debug for InternPoolWrapper { | ||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
|         f.debug_tuple("InternPoolWrapper") | ||||
|             .field(self.as_ref()) | ||||
|             .finish() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub struct InternPool { | ||||
|     tags: Vec<Tag>, | ||||
|     indices: Vec<u32>, | ||||
|  | @ -641,17 +574,6 @@ pub struct TypeInfo { | |||
|     pub signed: bool, | ||||
| } | ||||
| 
 | ||||
| impl TypeInfo { | ||||
|     /// byte size
 | ||||
|     pub fn size(&self) -> u32 { | ||||
|         self.bitsize.div_ceil(8) | ||||
|     } | ||||
|     /// byte align
 | ||||
|     pub fn align(&self) -> u32 { | ||||
|         self.bitalign.div_ceil(8) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl InternPool { | ||||
|     pub fn peer_type(&mut self, lhs: Index, rhs: Index) -> Option<Index> { | ||||
|         if lhs == rhs { | ||||
|  | @ -1375,13 +1297,6 @@ impl InternPool { | |||
|         }) | ||||
|     } | ||||
| 
 | ||||
|     pub fn try_get_pointee_type(&self, pointer: Index) -> Option<Index> { | ||||
|         match self.get_key(pointer) { | ||||
|             Key::PointerType { pointee, .. } | Key::ArrayType { pointee, .. } => Some(pointee), | ||||
|             _ => None, | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     pub fn get_pointer_type(&mut self, pointee: Index, flags: Option<PointerFlags>) -> Index { | ||||
|         let key = Key::PointerType { | ||||
|             pointee, | ||||
|  | @ -1389,7 +1304,6 @@ impl InternPool { | |||
|         }; | ||||
|         self.get_or_insert(key) | ||||
|     } | ||||
| 
 | ||||
|     pub fn try_get_pointer_type( | ||||
|         &self, | ||||
|         pointee: Index, | ||||
|  |  | |||
							
								
								
									
										1735
									
								
								src/ast2/mod.rs
									
									
									
									
									
								
							
							
						
						
									
										1735
									
								
								src/ast2/mod.rs
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -70,5 +70,3 @@ impl BitSize for &[u8] { | |||
|         bits as u32 | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub fn unit<T>(_: T) {} | ||||
|  |  | |||
|  | @ -35,13 +35,25 @@ impl SymbolPath { | |||
|         for node in self.0.iter().skip(1).rev() { | ||||
|             match tree.nodes.get_node(node.unwrap()) { | ||||
|                 Tag::VarDecl { name, .. } => { | ||||
|                     _ = write!(&mut buf, "V{}::", tree.get_ident_str(*name).unwrap()); | ||||
|                     _ = write!( | ||||
|                         &mut buf, | ||||
|                         "V{}::", | ||||
|                         tree.get_ident_str(*name).unwrap() | ||||
|                     ); | ||||
|                 } | ||||
|                 Tag::GlobalDecl { name, .. } => { | ||||
|                     _ = write!(&mut buf, "G{}::", tree.get_ident_str(*name).unwrap()); | ||||
|                     _ = write!( | ||||
|                         &mut buf, | ||||
|                         "G{}::", | ||||
|                         tree.get_ident_str(*name).unwrap() | ||||
|                     ); | ||||
|                 } | ||||
|                 Tag::FunctionProto { name, .. } => { | ||||
|                     _ = write!(&mut buf, "F{}::", tree.get_ident_str(*name).unwrap()); | ||||
|                     _ = write!( | ||||
|                         &mut buf, | ||||
|                         "F{}::", | ||||
|                         tree.get_ident_str(*name).unwrap() | ||||
|                     ); | ||||
|                 } | ||||
|                 _ => {} | ||||
|             } | ||||
|  | @ -130,7 +142,12 @@ impl Drop for InnerSymbolTable { | |||
| } | ||||
| 
 | ||||
| impl InnerSymbolTable { | ||||
|     fn insert_symbol(&mut self, name: &str, node: AstNode, kind: SymbolKind) -> &SymbolRecord { | ||||
|     fn insert_symbol( | ||||
|         &mut self, | ||||
|         name: &str, | ||||
|         node: AstNode, | ||||
|         kind: SymbolKind, | ||||
|     ) -> &SymbolRecord { | ||||
|         match kind { | ||||
|             SymbolKind::Var => { | ||||
|                 self.ordered_identifiers.push(SymbolRecord { | ||||
|  | @ -143,7 +160,11 @@ impl InnerSymbolTable { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     fn insert_orderless_symbol(&mut self, name: &str, node: AstNode) -> &SymbolRecord { | ||||
|     fn insert_orderless_symbol( | ||||
|         &mut self, | ||||
|         name: &str, | ||||
|         node: AstNode, | ||||
|     ) -> &SymbolRecord { | ||||
|         self.orderless_identifiers.insert( | ||||
|             name.to_owned(), | ||||
|             SymbolRecord { | ||||
|  | @ -154,7 +175,11 @@ impl InnerSymbolTable { | |||
|         self.orderless_identifiers.get(name).unwrap() | ||||
|     } | ||||
| 
 | ||||
|     fn find_symbol_or_insert_with<'a, F>(&'a mut self, name: &str, cb: F) -> &'a SymbolRecord | ||||
|     fn find_symbol_or_insert_with<'a, F>( | ||||
|         &'a mut self, | ||||
|         name: &str, | ||||
|         cb: F, | ||||
|     ) -> &'a SymbolRecord | ||||
|     where | ||||
|         F: FnOnce() -> (AstNode, SymbolKind), | ||||
|     { | ||||
|  | @ -177,7 +202,9 @@ impl InnerSymbolTable { | |||
|                     .find(|(_, v)| v.decl == decl) | ||||
|                     .map(|(_, v)| v) | ||||
|             }) | ||||
|             .or_else(|| self.parent_ref().and_then(|p| p.find_symbol_by_decl(decl))) | ||||
|             .or_else(|| { | ||||
|                 self.parent_ref().and_then(|p| p.find_symbol_by_decl(decl)) | ||||
|             }) | ||||
|     } | ||||
| 
 | ||||
|     fn find_any_symbol(&self, name: &str) -> Option<&SymbolRecord> { | ||||
|  | @ -192,7 +219,9 @@ impl InnerSymbolTable { | |||
|         self.ordered_identifiers | ||||
|             .iter() | ||||
|             .find(|r| r.name.as_str() == name) | ||||
|             .or_else(|| self.parent_ref().and_then(|p| p.find_ordered_symbol(name))) | ||||
|             .or_else(|| { | ||||
|                 self.parent_ref().and_then(|p| p.find_ordered_symbol(name)) | ||||
|             }) | ||||
|     } | ||||
| 
 | ||||
|     fn find_orderless_symbol(&self, name: &str) -> Option<&SymbolRecord> { | ||||
|  | @ -286,7 +315,12 @@ impl SymbolTableWrapper { | |||
| } | ||||
| 
 | ||||
| impl SymbolTableWrapper { | ||||
|     pub fn insert_symbol(&mut self, name: &str, node: AstNode, kind: SymbolKind) -> &SymbolRecord { | ||||
|     pub fn insert_symbol( | ||||
|         &mut self, | ||||
|         name: &str, | ||||
|         node: AstNode, | ||||
|         kind: SymbolKind, | ||||
|     ) -> &SymbolRecord { | ||||
|         self.current_mut().insert_symbol(name, node, kind) | ||||
|     } | ||||
| 
 | ||||
|  | @ -294,15 +328,27 @@ impl SymbolTableWrapper { | |||
|         self.root_mut().find_orderless_symbol(name) | ||||
|     } | ||||
| 
 | ||||
|     pub fn insert_root_symbol(&mut self, name: &str, node: AstNode) -> &SymbolRecord { | ||||
|     pub fn insert_root_symbol( | ||||
|         &mut self, | ||||
|         name: &str, | ||||
|         node: AstNode, | ||||
|     ) -> &SymbolRecord { | ||||
|         self.root_mut().insert_orderless_symbol(name, node) | ||||
|     } | ||||
| 
 | ||||
|     pub fn insert_orderless_symbol(&mut self, name: &str, node: AstNode) -> &SymbolRecord { | ||||
|     pub fn insert_orderless_symbol( | ||||
|         &mut self, | ||||
|         name: &str, | ||||
|         node: AstNode, | ||||
|     ) -> &SymbolRecord { | ||||
|         self.current_mut().insert_orderless_symbol(name, node) | ||||
|     } | ||||
| 
 | ||||
|     pub fn find_symbol_or_insert_with<'a, F>(&'a mut self, name: &str, cb: F) -> &'a SymbolRecord | ||||
|     pub fn find_symbol_or_insert_with<'a, F>( | ||||
|         &'a mut self, | ||||
|         name: &str, | ||||
|         cb: F, | ||||
|     ) -> &'a SymbolRecord | ||||
|     where | ||||
|         F: FnOnce() -> (AstNode, SymbolKind), | ||||
|     { | ||||
|  | @ -424,40 +470,6 @@ pub mod syms2 { | |||
|         }, | ||||
|     } | ||||
| 
 | ||||
|     impl Key { | ||||
|         pub fn kind(&self) -> Option<SymbolKind> { | ||||
|             match self { | ||||
|                 Key::Symbol { kind, .. } => Some(*kind), | ||||
|                 _ => None, | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #[repr(u32)] | ||||
|     pub enum DeclKind { | ||||
|         Local = 1, | ||||
|         Parameter, | ||||
|     } | ||||
| 
 | ||||
|     impl DeclKind { | ||||
|         pub fn from_u32(v: u32) -> Option<Self> { | ||||
|             match v { | ||||
|                 1 => Some(Self::Local), | ||||
|                 2 => Some(Self::Parameter), | ||||
|                 _ => None, | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     impl From<SymbolKind> for Option<DeclKind> { | ||||
|         fn from(value: SymbolKind) -> Self { | ||||
|             match value { | ||||
|                 SymbolKind::Parameter(_) => Some(DeclKind::Parameter), | ||||
|                 SymbolKind::Local(_) => Some(DeclKind::Local), | ||||
|                 _ => None, | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] | ||||
|     pub enum SymbolKind { | ||||
|         __First, | ||||
|  | @ -467,7 +479,6 @@ pub mod syms2 { | |||
|         __TypeScope, | ||||
|         Scope, | ||||
|         ParentScope, | ||||
|         Parameter(SourceLocation), | ||||
|         Local(SourceLocation), | ||||
|         __Last, | ||||
|     } | ||||
|  | @ -515,7 +526,9 @@ pub mod syms2 { | |||
|             } | ||||
|             let entries = self.inner.iter().map(|(key, val)| { | ||||
|                 let payload = match key { | ||||
|                     Key::ScopeByIndex { .. } => ExpandedPayload::Intern(val.as_intern()), | ||||
|                     Key::ScopeByIndex { .. } => { | ||||
|                         ExpandedPayload::Intern(val.as_intern()) | ||||
|                     } | ||||
|                     _ => ExpandedPayload::Ast(val.as_ast()), | ||||
|                 }; | ||||
| 
 | ||||
|  | @ -554,7 +567,7 @@ pub mod syms2 { | |||
|             scope: AstIndex, | ||||
|             name: InternIndex, | ||||
|             loc: SourceLocation, | ||||
|         ) -> Option<(Key, AstIndex)> { | ||||
|         ) -> Option<AstIndex> { | ||||
|             use SymbolKind::*; | ||||
|             let range = self.inner.range( | ||||
|                 Key::Symbol { | ||||
|  | @ -568,8 +581,8 @@ pub mod syms2 { | |||
|                 }, | ||||
|             ); | ||||
| 
 | ||||
|             if let Some((key, payload)) = range.rev().next() { | ||||
|                 Some((*key, payload.as_ast())) | ||||
|             if let Some((_, payload)) = range.rev().next() { | ||||
|                 Some(payload.as_ast()) | ||||
|             } else { | ||||
|                 if let Some(parent) = self.inner.get(&Key::Symbol { | ||||
|                     scope, | ||||
|  | @ -588,7 +601,7 @@ pub mod syms2 { | |||
|             scope: AstIndex, | ||||
|             name: InternIndex, | ||||
|             loc: SourceLocation, | ||||
|         ) -> Option<(Key, AstIndex)> { | ||||
|         ) -> Option<AstIndex> { | ||||
|             use SymbolKind::*; | ||||
|             let range = self.inner.range( | ||||
|                 Key::Symbol { | ||||
|  | @ -602,15 +615,15 @@ pub mod syms2 { | |||
|                 }, | ||||
|             ); | ||||
| 
 | ||||
|             if let Some((key, payload)) = range.rev().next() { | ||||
|                 Some((*key, payload.as_ast())) | ||||
|             if let Some((_, payload)) = range.rev().next() { | ||||
|                 Some(payload.as_ast()) | ||||
|             } else { | ||||
|                 if let Some(parent) = self.inner.get(&Key::Symbol { | ||||
|                     scope, | ||||
|                     name: InternIndex::invalid(), | ||||
|                     kind: ParentScope, | ||||
|                 }) { | ||||
|                     self.find_type_symbol(parent.as_ast(), name, loc) | ||||
|                     self.find_symbol(parent.as_ast(), name, loc) | ||||
|                 } else { | ||||
|                     None | ||||
|                 } | ||||
|  | @ -624,8 +637,10 @@ pub mod syms2 { | |||
|             kind: SymbolKind, | ||||
|             ast: AstIndex, | ||||
|         ) { | ||||
|             self.inner | ||||
|                 .insert(Key::Symbol { scope, name, kind }, Payload::new_ast(ast)); | ||||
|             self.inner.insert( | ||||
|                 Key::Symbol { scope, name, kind }, | ||||
|                 Payload::new_ast(ast), | ||||
|             ); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -159,13 +159,10 @@ pub enum Inst { | |||
|     Constant, | ||||
|     /// size, align
 | ||||
|     Alloca, | ||||
|     /// (pointee type)
 | ||||
|     /// src
 | ||||
|     Load(intern::Index), | ||||
|     /// (pointee type)
 | ||||
|     /// src, dst
 | ||||
|     Store(intern::Index), | ||||
|     /// (pointer type)
 | ||||
|     /// ptr, index,
 | ||||
|     GetElementPtr(intern::Index), | ||||
|     /// size, align
 | ||||
|  | @ -762,8 +759,8 @@ impl<'tree, 'ir> IRBuilder<'tree, 'ir> { | |||
| } | ||||
| 
 | ||||
| pub struct IR { | ||||
|     pub(crate) nodes: Vec<Inst>, | ||||
|     pub(crate) data: Vec<Option<Data>>, | ||||
|     nodes: Vec<Inst>, | ||||
|     data: Vec<Option<Data>>, | ||||
|     // intern_pool: &'a mut InternPool,
 | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue