Update to rustfmt-preview (#348)
* Update to rustfmt-preview. * Run "cargo fmt --all" with rustfmt 0.4.1. rustfmt 0.4.1 is the latest release of rustfmt-preview available on the stable channel. * Fix a long line that rustfmt 0.4.1 can't handle. * Remove unneeded commas left behind by rustfmt.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
use DataContext;
|
||||
use Linkage;
|
||||
use ModuleNamespace;
|
||||
use ModuleError;
|
||||
use ModuleNamespace;
|
||||
use cretonne_codegen::Context;
|
||||
use cretonne_codegen::isa::TargetIsa;
|
||||
use cretonne_codegen::{binemit, ir};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Defines `DataContext`.
|
||||
|
||||
use cretonne_codegen::binemit::{Addend, CodeOffset};
|
||||
use cretonne_codegen::entity::PrimaryMap;
|
||||
use cretonne_codegen::binemit::{CodeOffset, Addend};
|
||||
use cretonne_codegen::ir;
|
||||
|
||||
/// This specifies how data is to be initialized.
|
||||
@@ -145,8 +145,8 @@ impl DataContext {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {DataContext, Writability, Init};
|
||||
use cretonne_codegen::ir;
|
||||
use {DataContext, Init, Writability};
|
||||
|
||||
#[test]
|
||||
fn basic_data_context() {
|
||||
@@ -202,7 +202,9 @@ mod tests {
|
||||
assert_eq!(description.writable, Writability::Readonly);
|
||||
assert_eq!(
|
||||
description.init,
|
||||
Init::Bytes { contents: contents_clone.into_boxed_slice() }
|
||||
Init::Bytes {
|
||||
contents: contents_clone.into_boxed_slice()
|
||||
}
|
||||
);
|
||||
assert_eq!(description.function_decls.len(), 0);
|
||||
assert_eq!(description.data_decls.len(), 0);
|
||||
|
||||
@@ -3,18 +3,10 @@
|
||||
#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
|
||||
#![warn(unused_import_braces, unstable_features)]
|
||||
#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
|
||||
#![cfg_attr(feature = "cargo-clippy", allow(new_without_default, new_without_default_derive))]
|
||||
#![cfg_attr(feature = "cargo-clippy",
|
||||
allow(new_without_default, new_without_default_derive))]
|
||||
#![cfg_attr(feature="cargo-clippy", warn(
|
||||
float_arithmetic,
|
||||
mut_mut,
|
||||
nonminimal_bool,
|
||||
option_map_unwrap_or,
|
||||
option_map_unwrap_or_else,
|
||||
print_stdout,
|
||||
unicode_not_nfc,
|
||||
use_self,
|
||||
))]
|
||||
warn(float_arithmetic, mut_mut, nonminimal_bool, option_map_unwrap_or,
|
||||
option_map_unwrap_or_else, print_stdout, unicode_not_nfc, use_self))]
|
||||
|
||||
#[macro_use]
|
||||
extern crate cretonne_codegen;
|
||||
@@ -28,5 +20,5 @@ mod data_context;
|
||||
mod module;
|
||||
|
||||
pub use backend::Backend;
|
||||
pub use data_context::{DataContext, Writability, DataDescription, Init};
|
||||
pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleNamespace, ModuleError};
|
||||
pub use data_context::{DataContext, DataDescription, Init, Writability};
|
||||
pub use module::{DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleError, ModuleNamespace};
|
||||
|
||||
@@ -42,7 +42,6 @@ impl From<DataId> for ir::ExternalName {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Linkage refers to where an entity is defined and who can see it.
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub enum Linkage {
|
||||
@@ -60,19 +59,15 @@ impl Linkage {
|
||||
fn merge(a: Self, b: Self) -> Self {
|
||||
match a {
|
||||
Linkage::Export => Linkage::Export,
|
||||
Linkage::Preemptible => {
|
||||
match b {
|
||||
Linkage::Export => Linkage::Export,
|
||||
_ => Linkage::Preemptible,
|
||||
}
|
||||
}
|
||||
Linkage::Local => {
|
||||
match b {
|
||||
Linkage::Export => Linkage::Export,
|
||||
Linkage::Preemptible => Linkage::Preemptible,
|
||||
_ => Linkage::Local,
|
||||
}
|
||||
}
|
||||
Linkage::Preemptible => match b {
|
||||
Linkage::Export => Linkage::Export,
|
||||
_ => Linkage::Preemptible,
|
||||
},
|
||||
Linkage::Local => match b {
|
||||
Linkage::Export => Linkage::Export,
|
||||
Linkage::Preemptible => Linkage::Preemptible,
|
||||
_ => Linkage::Local,
|
||||
},
|
||||
Linkage::Import => b,
|
||||
}
|
||||
}
|
||||
@@ -94,7 +89,6 @@ impl Linkage {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// A declared name may refer to either a function or data declaration
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
|
||||
pub enum FuncOrDataId {
|
||||
@@ -360,19 +354,17 @@ where
|
||||
// TODO: Can we avoid allocating names so often?
|
||||
use std::collections::hash_map::Entry::*;
|
||||
match self.names.entry(name.to_owned()) {
|
||||
Occupied(entry) => {
|
||||
match *entry.get() {
|
||||
FuncOrDataId::Func(id) => {
|
||||
let existing = &mut self.contents.functions[id];
|
||||
existing.merge(linkage);
|
||||
self.backend.declare_function(name, existing.decl.linkage);
|
||||
Ok(id)
|
||||
}
|
||||
FuncOrDataId::Data(..) => Err(
|
||||
ModuleError::IncompatibleDeclaration(name.to_owned()),
|
||||
),
|
||||
Occupied(entry) => match *entry.get() {
|
||||
FuncOrDataId::Func(id) => {
|
||||
let existing = &mut self.contents.functions[id];
|
||||
existing.merge(linkage);
|
||||
self.backend.declare_function(name, existing.decl.linkage);
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
FuncOrDataId::Data(..) => {
|
||||
Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
|
||||
}
|
||||
},
|
||||
Vacant(entry) => {
|
||||
let id = self.contents.functions.push(ModuleFunction {
|
||||
decl: FunctionDeclaration {
|
||||
@@ -400,24 +392,19 @@ where
|
||||
// TODO: Can we avoid allocating names so often?
|
||||
use std::collections::hash_map::Entry::*;
|
||||
match self.names.entry(name.to_owned()) {
|
||||
Occupied(entry) => {
|
||||
match *entry.get() {
|
||||
FuncOrDataId::Data(id) => {
|
||||
let existing = &mut self.contents.data_objects[id];
|
||||
existing.merge(linkage, writable);
|
||||
self.backend.declare_data(
|
||||
name,
|
||||
existing.decl.linkage,
|
||||
existing.decl.writable,
|
||||
);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
FuncOrDataId::Func(..) => Err(
|
||||
ModuleError::IncompatibleDeclaration(name.to_owned()),
|
||||
),
|
||||
Occupied(entry) => match *entry.get() {
|
||||
FuncOrDataId::Data(id) => {
|
||||
let existing = &mut self.contents.data_objects[id];
|
||||
existing.merge(linkage, writable);
|
||||
self.backend
|
||||
.declare_data(name, existing.decl.linkage, existing.decl.writable);
|
||||
Ok(id)
|
||||
}
|
||||
}
|
||||
|
||||
FuncOrDataId::Func(..) => {
|
||||
Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
|
||||
}
|
||||
},
|
||||
Vacant(entry) => {
|
||||
let id = self.contents.data_objects.push(ModuleData {
|
||||
decl: DataDeclaration {
|
||||
@@ -535,9 +522,9 @@ where
|
||||
"imported data cannot contain references"
|
||||
);
|
||||
self.backend.write_data_funcaddr(
|
||||
&mut info.compiled.as_mut().expect(
|
||||
"`data` must refer to a defined data object",
|
||||
),
|
||||
&mut info.compiled
|
||||
.as_mut()
|
||||
.expect("`data` must refer to a defined data object"),
|
||||
offset,
|
||||
what,
|
||||
);
|
||||
@@ -558,9 +545,9 @@ where
|
||||
"imported data cannot contain references"
|
||||
);
|
||||
self.backend.write_data_dataaddr(
|
||||
&mut info.compiled.as_mut().expect(
|
||||
"`data` must refer to a defined data object",
|
||||
),
|
||||
&mut info.compiled
|
||||
.as_mut()
|
||||
.expect("`data` must refer to a defined data object"),
|
||||
offset,
|
||||
what,
|
||||
addend,
|
||||
@@ -577,10 +564,12 @@ where
|
||||
"imported function cannot be finalized"
|
||||
);
|
||||
self.backend.finalize_function(
|
||||
info.compiled.as_ref().expect(
|
||||
"function must be compiled before it can be finalized",
|
||||
),
|
||||
&ModuleNamespace::<B> { contents: &self.contents },
|
||||
info.compiled
|
||||
.as_ref()
|
||||
.expect("function must be compiled before it can be finalized"),
|
||||
&ModuleNamespace::<B> {
|
||||
contents: &self.contents,
|
||||
},
|
||||
)
|
||||
};
|
||||
self.contents.functions[func].finalized = true;
|
||||
@@ -597,10 +586,12 @@ where
|
||||
"imported data cannot be finalized"
|
||||
);
|
||||
self.backend.finalize_data(
|
||||
info.compiled.as_ref().expect(
|
||||
"data object must be compiled before it can be finalized",
|
||||
),
|
||||
&ModuleNamespace::<B> { contents: &self.contents },
|
||||
info.compiled
|
||||
.as_ref()
|
||||
.expect("data object must be compiled before it can be finalized"),
|
||||
&ModuleNamespace::<B> {
|
||||
contents: &self.contents,
|
||||
},
|
||||
)
|
||||
};
|
||||
self.contents.data_objects[data].finalized = true;
|
||||
@@ -614,20 +605,24 @@ where
|
||||
for info in self.contents.functions.values() {
|
||||
if info.decl.linkage.is_definable() && !info.finalized {
|
||||
self.backend.finalize_function(
|
||||
info.compiled.as_ref().expect(
|
||||
"function must be compiled before it can be finalized",
|
||||
),
|
||||
&ModuleNamespace::<B> { contents: &self.contents },
|
||||
info.compiled
|
||||
.as_ref()
|
||||
.expect("function must be compiled before it can be finalized"),
|
||||
&ModuleNamespace::<B> {
|
||||
contents: &self.contents,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
for info in self.contents.data_objects.values() {
|
||||
if info.decl.linkage.is_definable() && !info.finalized {
|
||||
self.backend.finalize_data(
|
||||
info.compiled.as_ref().expect(
|
||||
"data object must be compiled before it can be finalized",
|
||||
),
|
||||
&ModuleNamespace::<B> { contents: &self.contents },
|
||||
info.compiled
|
||||
.as_ref()
|
||||
.expect("data object must be compiled before it can be finalized"),
|
||||
&ModuleNamespace::<B> {
|
||||
contents: &self.contents,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user