Declare a data object in this module.
(
&mut self,
name: &str,
linkage: Linkage,
writable: bool,
tls: bool,
)
| 775 | |
| 776 | /// Declare a data object in this module. |
| 777 | pub fn declare_data( |
| 778 | &mut self, |
| 779 | name: &str, |
| 780 | linkage: Linkage, |
| 781 | writable: bool, |
| 782 | tls: bool, |
| 783 | ) -> ModuleResult<(DataId, Linkage)> { |
| 784 | // TODO: Can we avoid allocating names so often? |
| 785 | use super::hash_map::Entry::*; |
| 786 | match self.names.entry(name.to_owned()) { |
| 787 | Occupied(entry) => match *entry.get() { |
| 788 | FuncOrDataId::Data(id) => { |
| 789 | let existing = &mut self.data_objects[id]; |
| 790 | existing.merge(linkage, writable, tls); |
| 791 | Ok((id, existing.linkage)) |
| 792 | } |
| 793 | |
| 794 | FuncOrDataId::Func(..) => { |
| 795 | Err(ModuleError::IncompatibleDeclaration(name.to_owned())) |
| 796 | } |
| 797 | }, |
| 798 | Vacant(entry) => { |
| 799 | let id = self.data_objects.push(DataDeclaration { |
| 800 | name: Some(name.to_owned()), |
| 801 | linkage, |
| 802 | writable, |
| 803 | tls, |
| 804 | }); |
| 805 | entry.insert(FuncOrDataId::Data(id)); |
| 806 | Ok((id, self.data_objects[id].linkage)) |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /// Declare an anonymous data object in this module. |
| 812 | pub fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> { |