Introduce a TargetFrontendConfig type. (#570)

* Introduce a `TargetFrontendConfig` type.

`TargetFrontendConfig` is information specific to the target which is
provided to frontends to allow them to produce Cranelift IR for the
target. Currently this includes the pointer size and the default calling
convention.

The default calling convention is now inferred from the target, rather
than being a setting. cranelift-native is now just a provider of target
information, rather than also being a provider of settings, which gives
it a clearer role.

And instead of having cranelift-frontend routines require the whole
`TargetIsa`, just require the `TargetFrontendConfig`, and add a way to
get the `TargetFrontendConfig` from a `Module`.

Fixes #529.
Fixes #555.
This commit is contained in:
Dan Gohman
2018-11-02 13:51:42 -07:00
committed by GitHub
parent 7094d9f470
commit d4f8eb7453
27 changed files with 297 additions and 168 deletions

View File

@@ -236,11 +236,11 @@ fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
#[cfg(test)]
mod tests {
use super::FuncTranslator;
use super::{FuncTranslator, ReturnMode};
use cranelift_codegen::ir::types::I32;
use cranelift_codegen::{ir, Context};
use environ::{DummyEnvironment, FuncEnvironment};
use target_lexicon::Triple;
use cranelift_codegen::{ir, isa, settings, Context};
use environ::DummyEnvironment;
use target_lexicon::PointerWidth;
#[test]
fn small1() {
@@ -258,7 +258,15 @@ mod tests {
];
let mut trans = FuncTranslator::new();
let runtime = DummyEnvironment::with_triple(Triple::default());
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
},
ReturnMode::NormalReturns,
);
let mut ctx = Context::new();
ctx.func.name = ir::ExternalName::testcase("small1");
@@ -269,7 +277,7 @@ mod tests {
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(runtime.func_env().flags()).unwrap();
ctx.verify(&flags).unwrap();
}
#[test]
@@ -289,7 +297,14 @@ mod tests {
];
let mut trans = FuncTranslator::new();
let runtime = DummyEnvironment::with_triple(Triple::default());
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
},
ReturnMode::NormalReturns,
);
let mut ctx = Context::new();
ctx.func.name = ir::ExternalName::testcase("small2");
@@ -300,7 +315,7 @@ mod tests {
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(runtime.func_env().flags()).unwrap();
ctx.verify(&flags).unwrap();
}
#[test]
@@ -329,7 +344,14 @@ mod tests {
];
let mut trans = FuncTranslator::new();
let runtime = DummyEnvironment::with_triple(Triple::default());
let flags = settings::Flags::new(settings::builder());
let runtime = DummyEnvironment::new(
isa::TargetFrontendConfig {
default_call_conv: isa::CallConv::Fast,
pointer_width: PointerWidth::U64,
},
ReturnMode::NormalReturns,
);
let mut ctx = Context::new();
ctx.func.name = ir::ExternalName::testcase("infloop");
@@ -339,6 +361,6 @@ mod tests {
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(runtime.func_env().flags()).unwrap();
ctx.verify(&flags).unwrap();
}
}