|
35 | 35 | //! to the list specified by the target, rather than replace.
|
36 | 36 |
|
37 | 37 | use crate::abi::call::Conv;
|
38 |
| -use crate::abi::{ |
39 |
| - AbiAndPrefAlign, AddressSpace, Align, Endian, Integer, Size, TargetDataLayout, |
40 |
| - TargetDataLayoutErrors, |
41 |
| -}; |
| 38 | +use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors}; |
42 | 39 | use crate::json::{Json, ToJson};
|
43 | 40 | use crate::spec::abi::{lookup as lookup_abi, Abi};
|
44 | 41 | use crate::spec::crt_objects::{CrtObjects, LinkSelfContainedDefault};
|
@@ -1322,92 +1319,7 @@ pub struct Target {
|
1322 | 1319 |
|
1323 | 1320 | impl Target {
|
1324 | 1321 | pub fn parse_data_layout<'a>(&'a self) -> Result<TargetDataLayout, TargetDataLayoutErrors<'a>> {
|
1325 |
| - // Parse an address space index from a string. |
1326 |
| - let parse_address_space = |s: &'a str, cause: &'a str| { |
1327 |
| - s.parse::<u32>().map(AddressSpace).map_err(|err| { |
1328 |
| - TargetDataLayoutErrors::InvalidAddressSpace { addr_space: s, cause, err } |
1329 |
| - }) |
1330 |
| - }; |
1331 |
| - |
1332 |
| - // Parse a bit count from a string. |
1333 |
| - let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| { |
1334 |
| - s.parse::<u64>().map_err(|err| TargetDataLayoutErrors::InvalidBits { |
1335 |
| - kind, |
1336 |
| - bit: s, |
1337 |
| - cause, |
1338 |
| - err, |
1339 |
| - }) |
1340 |
| - }; |
1341 |
| - |
1342 |
| - // Parse a size string. |
1343 |
| - let size = |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits); |
1344 |
| - |
1345 |
| - // Parse an alignment string. |
1346 |
| - let align = |s: &[&'a str], cause: &'a str| { |
1347 |
| - if s.is_empty() { |
1348 |
| - return Err(TargetDataLayoutErrors::MissingAlignment { cause }); |
1349 |
| - } |
1350 |
| - let align_from_bits = |bits| { |
1351 |
| - Align::from_bits(bits) |
1352 |
| - .map_err(|err| TargetDataLayoutErrors::InvalidAlignment { cause, err }) |
1353 |
| - }; |
1354 |
| - let abi = parse_bits(s[0], "alignment", cause)?; |
1355 |
| - let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?; |
1356 |
| - Ok(AbiAndPrefAlign { abi: align_from_bits(abi)?, pref: align_from_bits(pref)? }) |
1357 |
| - }; |
1358 |
| - |
1359 |
| - let mut dl = TargetDataLayout::default(); |
1360 |
| - let mut i128_align_src = 64; |
1361 |
| - for spec in self.data_layout.split('-') { |
1362 |
| - let spec_parts = spec.split(':').collect::<Vec<_>>(); |
1363 |
| - |
1364 |
| - match &*spec_parts { |
1365 |
| - ["e"] => dl.endian = Endian::Little, |
1366 |
| - ["E"] => dl.endian = Endian::Big, |
1367 |
| - [p] if p.starts_with('P') => { |
1368 |
| - dl.instruction_address_space = parse_address_space(&p[1..], "P")? |
1369 |
| - } |
1370 |
| - ["a", ref a @ ..] => dl.aggregate_align = align(a, "a")?, |
1371 |
| - ["f32", ref a @ ..] => dl.f32_align = align(a, "f32")?, |
1372 |
| - ["f64", ref a @ ..] => dl.f64_align = align(a, "f64")?, |
1373 |
| - [p @ "p", s, ref a @ ..] | [p @ "p0", s, ref a @ ..] => { |
1374 |
| - dl.pointer_size = size(s, p)?; |
1375 |
| - dl.pointer_align = align(a, p)?; |
1376 |
| - } |
1377 |
| - [s, ref a @ ..] if s.starts_with('i') => { |
1378 |
| - let Ok(bits) = s[1..].parse::<u64>() else { |
1379 |
| - size(&s[1..], "i")?; // For the user error. |
1380 |
| - continue; |
1381 |
| - }; |
1382 |
| - let a = align(a, s)?; |
1383 |
| - match bits { |
1384 |
| - 1 => dl.i1_align = a, |
1385 |
| - 8 => dl.i8_align = a, |
1386 |
| - 16 => dl.i16_align = a, |
1387 |
| - 32 => dl.i32_align = a, |
1388 |
| - 64 => dl.i64_align = a, |
1389 |
| - _ => {} |
1390 |
| - } |
1391 |
| - if bits >= i128_align_src && bits <= 128 { |
1392 |
| - // Default alignment for i128 is decided by taking the alignment of |
1393 |
| - // largest-sized i{64..=128}. |
1394 |
| - i128_align_src = bits; |
1395 |
| - dl.i128_align = a; |
1396 |
| - } |
1397 |
| - } |
1398 |
| - [s, ref a @ ..] if s.starts_with('v') => { |
1399 |
| - let v_size = size(&s[1..], "v")?; |
1400 |
| - let a = align(a, s)?; |
1401 |
| - if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) { |
1402 |
| - v.1 = a; |
1403 |
| - continue; |
1404 |
| - } |
1405 |
| - // No existing entry, add a new one. |
1406 |
| - dl.vector_align.push((v_size, a)); |
1407 |
| - } |
1408 |
| - _ => {} // Ignore everything else. |
1409 |
| - } |
1410 |
| - } |
| 1322 | + let mut dl = TargetDataLayout::parse_from_llvm_datalayout_string(&self.data_layout)?; |
1411 | 1323 |
|
1412 | 1324 | // Perform consistency checks against the Target information.
|
1413 | 1325 | if dl.endian != self.endian {
|
|
0 commit comments