Rename CallConv::Native to CallConv::SystemV. (#291)
To keep cross-compiling straightforward, Cretonne shouldn't have any behavior that depends on the host. This renames the "Native" calling convention to "SystemV", which has a defined meaning for each target, so that it's clear that the calling convention doesn't change depending on what host Cretonne is running on.
This commit is contained in:
@@ -343,10 +343,11 @@ impl fmt::Display for ExtFuncData {
|
||||
/// determined by a `(TargetIsa, CallConv)` tuple.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum CallConv {
|
||||
/// The C calling convention.
|
||||
/// The System V-style calling convention.
|
||||
///
|
||||
/// This is the native calling convention that a C compiler would use on the platform.
|
||||
Native,
|
||||
/// This is the System V-style calling convention that a C compiler would
|
||||
/// use on many platforms.
|
||||
SystemV,
|
||||
|
||||
/// A JIT-compiled WebAssembly function in the SpiderMonkey VM.
|
||||
SpiderWASM,
|
||||
@@ -356,7 +357,7 @@ impl fmt::Display for CallConv {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::CallConv::*;
|
||||
f.write_str(match *self {
|
||||
Native => "native",
|
||||
SystemV => "system_v",
|
||||
SpiderWASM => "spiderwasm",
|
||||
})
|
||||
}
|
||||
@@ -368,7 +369,7 @@ impl FromStr for CallConv {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
use self::CallConv::*;
|
||||
match s {
|
||||
"native" => Ok(Native),
|
||||
"system_v" => Ok(SystemV),
|
||||
"spiderwasm" => Ok(SpiderWASM),
|
||||
_ => Err(()),
|
||||
}
|
||||
@@ -410,7 +411,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn call_conv() {
|
||||
for &cc in &[CallConv::Native, CallConv::SpiderWASM] {
|
||||
for &cc in &[CallConv::SystemV, CallConv::SpiderWASM] {
|
||||
assert_eq!(Ok(cc), cc.to_string().parse())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ impl Function {
|
||||
|
||||
/// Clear all data structures in this function.
|
||||
pub fn clear(&mut self) {
|
||||
self.signature.clear(ir::CallConv::Native);
|
||||
self.signature.clear(ir::CallConv::SystemV);
|
||||
self.stack_slots.clear();
|
||||
self.global_vars.clear();
|
||||
self.heaps.clear();
|
||||
@@ -99,9 +99,9 @@ impl Function {
|
||||
self.srclocs.clear();
|
||||
}
|
||||
|
||||
/// Create a new empty, anonymous function with a native calling convention.
|
||||
/// Create a new empty, anonymous function with a SystemV calling convention.
|
||||
pub fn new() -> Self {
|
||||
Self::with_name_signature(ExternalName::default(), Signature::new(CallConv::Native))
|
||||
Self::with_name_signature(ExternalName::default(), Signature::new(CallConv::SystemV))
|
||||
}
|
||||
|
||||
/// Creates a jump table in the function, to be used by `br_table` instructions.
|
||||
|
||||
@@ -171,7 +171,7 @@ pub fn callee_saved_registers(flags: &shared_settings::Flags) -> &'static [RU] {
|
||||
|
||||
pub fn prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
match func.signature.call_conv {
|
||||
ir::CallConv::Native => native_prologue_epilogue(func, isa),
|
||||
ir::CallConv::SystemV => system_v_prologue_epilogue(func, isa),
|
||||
ir::CallConv::SpiderWASM => spiderwasm_prologue_epilogue(func, isa),
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ pub fn spiderwasm_prologue_epilogue(
|
||||
}
|
||||
|
||||
/// Insert a System V-compatible prologue and epilogue.
|
||||
pub fn native_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
pub fn system_v_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> result::CtonResult {
|
||||
// The original 32-bit x86 ELF ABI had a 4-byte aligned stack pointer, but
|
||||
// newer versions use a 16-byte aligned stack pointer.
|
||||
let stack_align = 16;
|
||||
@@ -242,17 +242,17 @@ pub fn native_prologue_epilogue(func: &mut ir::Function, isa: &TargetIsa) -> res
|
||||
// Set up the cursor and insert the prologue
|
||||
let entry_ebb = func.layout.entry_block().expect("missing entry block");
|
||||
let mut pos = EncCursor::new(func, isa).at_first_insertion_point(entry_ebb);
|
||||
insert_native_prologue(&mut pos, local_stack_size, csr_type, csrs);
|
||||
insert_system_v_prologue(&mut pos, local_stack_size, csr_type, csrs);
|
||||
|
||||
// Reset the cursor and insert the epilogue
|
||||
let mut pos = pos.at_position(CursorPosition::Nowhere);
|
||||
insert_native_epilogues(&mut pos, local_stack_size, csr_type, csrs);
|
||||
insert_system_v_epilogues(&mut pos, local_stack_size, csr_type, csrs);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Insert the prologue for a given function.
|
||||
fn insert_native_prologue(
|
||||
fn insert_system_v_prologue(
|
||||
pos: &mut EncCursor,
|
||||
stack_size: i64,
|
||||
csr_type: ir::types::Type,
|
||||
@@ -286,7 +286,7 @@ fn insert_native_prologue(
|
||||
}
|
||||
|
||||
/// Find all `return` instructions and insert epilogues before them.
|
||||
fn insert_native_epilogues(
|
||||
fn insert_system_v_epilogues(
|
||||
pos: &mut EncCursor,
|
||||
stack_size: i64,
|
||||
csr_type: ir::types::Type,
|
||||
@@ -296,14 +296,14 @@ fn insert_native_epilogues(
|
||||
pos.goto_last_inst(ebb);
|
||||
if let Some(inst) = pos.current_inst() {
|
||||
if pos.func.dfg[inst].opcode().is_return() {
|
||||
insert_native_epilogue(inst, stack_size, pos, csr_type, csrs);
|
||||
insert_system_v_epilogue(inst, stack_size, pos, csr_type, csrs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert an epilogue given a specific `return` instruction.
|
||||
fn insert_native_epilogue(
|
||||
fn insert_system_v_epilogue(
|
||||
inst: ir::Inst,
|
||||
stack_size: i64,
|
||||
pos: &mut EncCursor,
|
||||
|
||||
@@ -44,8 +44,8 @@ fn find_funcref(libcall: ir::LibCall, func: &ir::Function) -> Option<ir::FuncRef
|
||||
|
||||
/// Create a funcref for `libcall` with a signature matching `inst`.
|
||||
fn make_funcref(libcall: ir::LibCall, inst: ir::Inst, func: &mut ir::Function) -> ir::FuncRef {
|
||||
// Start with a native calling convention. We'll give the ISA a chance to change it.
|
||||
let mut sig = ir::Signature::new(ir::CallConv::Native);
|
||||
// Start with a system_v calling convention. We'll give the ISA a chance to change it.
|
||||
let mut sig = ir::Signature::new(ir::CallConv::SystemV);
|
||||
for &v in func.dfg.inst_args(inst) {
|
||||
sig.params.push(ir::AbiParam::new(func.dfg.value_type(v)));
|
||||
}
|
||||
|
||||
@@ -465,34 +465,34 @@ mod tests {
|
||||
#[test]
|
||||
fn basic() {
|
||||
let mut f = Function::new();
|
||||
assert_eq!(f.to_string(), "function u0:0() native {\n}\n");
|
||||
assert_eq!(f.to_string(), "function u0:0() system_v {\n}\n");
|
||||
|
||||
f.name = ExternalName::testcase("foo");
|
||||
assert_eq!(f.to_string(), "function %foo() native {\n}\n");
|
||||
assert_eq!(f.to_string(), "function %foo() system_v {\n}\n");
|
||||
|
||||
f.create_stack_slot(StackSlotData::new(StackSlotKind::ExplicitSlot, 4));
|
||||
assert_eq!(
|
||||
f.to_string(),
|
||||
"function %foo() native {\n ss0 = explicit_slot 4\n}\n"
|
||||
"function %foo() system_v {\n ss0 = explicit_slot 4\n}\n"
|
||||
);
|
||||
|
||||
let ebb = f.dfg.make_ebb();
|
||||
f.layout.append_ebb(ebb);
|
||||
assert_eq!(
|
||||
f.to_string(),
|
||||
"function %foo() native {\n ss0 = explicit_slot 4\n\nebb0:\n}\n"
|
||||
"function %foo() system_v {\n ss0 = explicit_slot 4\n\nebb0:\n}\n"
|
||||
);
|
||||
|
||||
f.dfg.append_ebb_param(ebb, types::I8);
|
||||
assert_eq!(
|
||||
f.to_string(),
|
||||
"function %foo() native {\n ss0 = explicit_slot 4\n\nebb0(v0: i8):\n}\n"
|
||||
"function %foo() system_v {\n ss0 = explicit_slot 4\n\nebb0(v0: i8):\n}\n"
|
||||
);
|
||||
|
||||
f.dfg.append_ebb_param(ebb, types::F32.by(4).unwrap());
|
||||
assert_eq!(
|
||||
f.to_string(),
|
||||
"function %foo() native {\n ss0 = explicit_slot 4\n\nebb0(v0: i8, v1: f32x4):\n}\n"
|
||||
"function %foo() system_v {\n ss0 = explicit_slot 4\n\nebb0(v0: i8, v1: f32x4):\n}\n"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ mod tests {
|
||||
use Variable;
|
||||
|
||||
fn sample_function(lazy_seal: bool) {
|
||||
let mut sig = Signature::new(CallConv::Native);
|
||||
let mut sig = Signature::new(CallConv::SystemV);
|
||||
sig.returns.push(AbiParam::new(I32));
|
||||
sig.params.push(AbiParam::new(I32));
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
//! use cretonne::verifier::verify_function;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut sig = Signature::new(CallConv::Native);
|
||||
//! let mut sig = Signature::new(CallConv::SystemV);
|
||||
//! sig.returns.push(AbiParam::new(I32));
|
||||
//! sig.params.push(AbiParam::new(I32));
|
||||
//! let mut fn_builder_ctx = FunctionBuilderContext::<Variable>::new();
|
||||
|
||||
@@ -187,7 +187,7 @@ impl<'a> Context<'a> {
|
||||
fn add_sig(&mut self, sig: SigRef, data: Signature, loc: &Location) -> Result<()> {
|
||||
while self.function.dfg.signatures.next_key().index() <= sig.index() {
|
||||
self.function.import_signature(
|
||||
Signature::new(CallConv::Native),
|
||||
Signature::new(CallConv::SystemV),
|
||||
);
|
||||
}
|
||||
self.function.dfg.signatures[sig] = data;
|
||||
@@ -871,8 +871,8 @@ impl<'a> Parser<'a> {
|
||||
// signature ::= * "(" [paramlist] ")" ["->" retlist] [callconv]
|
||||
//
|
||||
fn parse_signature(&mut self, unique_isa: Option<&TargetIsa>) -> Result<Signature> {
|
||||
// Calling convention defaults to `native`, but can be changed.
|
||||
let mut sig = Signature::new(CallConv::Native);
|
||||
// Calling convention defaults to `system_v`, but can be changed.
|
||||
let mut sig = Signature::new(CallConv::SystemV);
|
||||
|
||||
self.match_token(
|
||||
Token::LPar,
|
||||
@@ -2429,7 +2429,7 @@ mod tests {
|
||||
#[test]
|
||||
fn aliases() {
|
||||
let (func, details) = Parser::new(
|
||||
"function %qux() native {
|
||||
"function %qux() system_v {
|
||||
ebb0:
|
||||
v4 = iconst.i8 6
|
||||
v3 -> v4
|
||||
@@ -2453,10 +2453,10 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn signature() {
|
||||
let sig = Parser::new("()native").parse_signature(None).unwrap();
|
||||
let sig = Parser::new("()system_v").parse_signature(None).unwrap();
|
||||
assert_eq!(sig.params.len(), 0);
|
||||
assert_eq!(sig.returns.len(), 0);
|
||||
assert_eq!(sig.call_conv, CallConv::Native);
|
||||
assert_eq!(sig.call_conv, CallConv::SystemV);
|
||||
|
||||
let sig2 = Parser::new("(i8 uext, f32, f64, i32 sret) -> i32 sext, f64 spiderwasm")
|
||||
.parse_signature(None)
|
||||
@@ -2470,7 +2470,7 @@ mod tests {
|
||||
// Old-style signature without a calling convention.
|
||||
assert_eq!(
|
||||
Parser::new("()").parse_signature(None).unwrap().to_string(),
|
||||
"() native"
|
||||
"() system_v"
|
||||
);
|
||||
assert_eq!(
|
||||
Parser::new("() notacc")
|
||||
@@ -2507,7 +2507,7 @@ mod tests {
|
||||
#[test]
|
||||
fn stack_slot_decl() {
|
||||
let (func, _) = Parser::new(
|
||||
"function %foo() native {
|
||||
"function %foo() system_v {
|
||||
ss3 = incoming_arg 13
|
||||
ss1 = spill_slot 1
|
||||
}",
|
||||
@@ -2530,7 +2530,7 @@ mod tests {
|
||||
// Catch duplicate definitions.
|
||||
assert_eq!(
|
||||
Parser::new(
|
||||
"function %bar() native {
|
||||
"function %bar() system_v {
|
||||
ss1 = spill_slot 13
|
||||
ss1 = spill_slot 1
|
||||
}",
|
||||
@@ -2544,7 +2544,7 @@ mod tests {
|
||||
#[test]
|
||||
fn ebb_header() {
|
||||
let (func, _) = Parser::new(
|
||||
"function %ebbs() native {
|
||||
"function %ebbs() system_v {
|
||||
ebb0:
|
||||
ebb4(v3: i32):
|
||||
}",
|
||||
@@ -2567,7 +2567,7 @@ mod tests {
|
||||
fn comments() {
|
||||
let (func, Details { comments, .. }) = Parser::new(
|
||||
"; before
|
||||
function %comment() native { ; decl
|
||||
function %comment() system_v { ; decl
|
||||
ss10 = outgoing_arg 13 ; stackslot.
|
||||
; Still stackslot.
|
||||
jt10 = jump_table ebb0
|
||||
@@ -2610,7 +2610,7 @@ mod tests {
|
||||
test verify
|
||||
set enable_float=false
|
||||
; still preamble
|
||||
function %comment() native {}",
|
||||
function %comment() system_v {}",
|
||||
).unwrap();
|
||||
assert_eq!(tf.commands.len(), 2);
|
||||
assert_eq!(tf.commands[0].command, "cfg");
|
||||
@@ -2635,7 +2635,7 @@ mod tests {
|
||||
assert!(
|
||||
parse_test(
|
||||
"isa
|
||||
function %foo() native {}",
|
||||
function %foo() system_v {}",
|
||||
).is_err()
|
||||
);
|
||||
|
||||
@@ -2643,14 +2643,14 @@ mod tests {
|
||||
parse_test(
|
||||
"isa riscv
|
||||
set enable_float=false
|
||||
function %foo() native {}",
|
||||
function %foo() system_v {}",
|
||||
).is_err()
|
||||
);
|
||||
|
||||
match parse_test(
|
||||
"set enable_float=false
|
||||
isa riscv
|
||||
function %foo() native {}",
|
||||
function %foo() system_v {}",
|
||||
).unwrap()
|
||||
.isa_spec {
|
||||
IsaSpec::None(_) => panic!("Expected some ISA"),
|
||||
@@ -2665,7 +2665,7 @@ mod tests {
|
||||
fn user_function_name() {
|
||||
// Valid characters in the name:
|
||||
let func = Parser::new(
|
||||
"function u1:2() native {
|
||||
"function u1:2() system_v {
|
||||
ebb0:
|
||||
trap int_divz
|
||||
}",
|
||||
@@ -2676,7 +2676,7 @@ mod tests {
|
||||
|
||||
// Invalid characters in the name:
|
||||
let mut parser = Parser::new(
|
||||
"function u123:abc() native {
|
||||
"function u123:abc() system_v {
|
||||
ebb0:
|
||||
trap stk_ovf
|
||||
}",
|
||||
@@ -2685,7 +2685,7 @@ mod tests {
|
||||
|
||||
// Incomplete function names should not be valid:
|
||||
let mut parser = Parser::new(
|
||||
"function u() native {
|
||||
"function u() system_v {
|
||||
ebb0:
|
||||
trap int_ovf
|
||||
}",
|
||||
@@ -2693,7 +2693,7 @@ mod tests {
|
||||
assert!(parser.parse_function(None).is_err());
|
||||
|
||||
let mut parser = Parser::new(
|
||||
"function u0() native {
|
||||
"function u0() system_v {
|
||||
ebb0:
|
||||
trap int_ovf
|
||||
}",
|
||||
@@ -2701,7 +2701,7 @@ mod tests {
|
||||
assert!(parser.parse_function(None).is_err());
|
||||
|
||||
let mut parser = Parser::new(
|
||||
"function u0:() native {
|
||||
"function u0:() system_v {
|
||||
ebb0:
|
||||
trap int_ovf
|
||||
}",
|
||||
|
||||
@@ -36,7 +36,7 @@ pub fn parse_function_signatures(
|
||||
ref params,
|
||||
ref returns,
|
||||
}) => {
|
||||
let mut sig = Signature::new(CallConv::Native);
|
||||
let mut sig = Signature::new(CallConv::SystemV);
|
||||
sig.params.extend(params.iter().map(|ty| {
|
||||
let cret_arg: cretonne::ir::Type = type_to_type(ty).expect(
|
||||
"only numeric types are supported in function signatures",
|
||||
|
||||
Reference in New Issue
Block a user