Skip to content

Commit

Permalink
feat(xlang)!: Do not pass target names to plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
chorman0773 committed Jul 28, 2023
1 parent 82628a8 commit 1a1a275
Show file tree
Hide file tree
Showing 23 changed files with 128 additions and 569 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use parse::{
use xlang::abi::string::StringView;
use xlang::ir;
use xlang::plugin::{Error, XLangFrontend, XLangPlugin};
use xlang::targets::properties::TargetProperties;

#[allow(clippy::missing_const_for_fn)] // b/c 1.54.0 doesn't support panic in const fns
fn diagnostic() -> ! {
Expand Down Expand Up @@ -251,7 +252,7 @@ impl XLangPlugin for CFrontend {
Result::Ok(())
}

fn set_target(&mut self, _targ: xlang::targets::Target) {}
fn set_target(&mut self, _targ: &'static TargetProperties<'static>) {}
}

xlang::host::rustcall! {
Expand Down
18 changes: 6 additions & 12 deletions codegen-clever/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,6 @@ impl CleverFunctionCodegen {
}

pub struct CleverCodegenPlugin {
target: Option<Target>,
fns: Option<std::collections::HashMap<String, FunctionCodegen<CleverFunctionCodegen>>>,
strings: Rc<RefCell<StringMap>>,
properties: Option<&'static TargetProperties<'static>>,
Expand All @@ -949,7 +948,7 @@ pub struct CleverCodegenPlugin {

impl CleverCodegenPlugin {
fn write_output_impl<W: std::io::Write>(&mut self, mut x: W) -> std::io::Result<()> {
let fmt = binfmt::def_vec_for(self.target.as_ref().unwrap());
let fmt = binfmt::format_by_name(&self.properties.unwrap().link.obj_binfmt).unwrap();
let mut file = fmt.create_file(FileType::Relocatable);
let mut text = Section {
name: String::from(".text"),
Expand Down Expand Up @@ -1108,13 +1107,9 @@ impl XLangPlugin for CleverCodegenPlugin {
}

#[allow(clippy::needless_borrow)] // Incorrect lint
fn set_target(&mut self, targ: xlang::targets::Target) {
self.target = Some((&targ).into());
self.properties = xlang::targets::properties::get_properties(&targ);
self.features = get_features_from_properties(
self.properties.unwrap(),
self.properties.unwrap().arch.default_machine,
);
fn set_target(&mut self, targ: &'static TargetProperties<'static>) {
self.properties = Some(targ);
self.features = get_features_from_properties(targ, targ.arch.default_machine);
}
}

Expand Down Expand Up @@ -1143,8 +1138,8 @@ fn get_features_from_properties(
}

impl XLangCodegen for CleverCodegenPlugin {
fn target_matches(&self, x: &xlang::targets::Target) -> bool {
let target: target_tuples::Target = x.into();
fn target_matches(&self, x: StringView) -> bool {
let target: target_tuples::Target = x.parse().unwrap();

matches!(target.arch(), Architecture::Clever)
}
Expand Down Expand Up @@ -1176,7 +1171,6 @@ xlang::host::rustcall! {
pub extern "rustcall" fn xlang_backend_main() -> DynBox<dyn XLangCodegen> {
DynBox::unsize_box(xlang::prelude::v1::Box::new(CleverCodegenPlugin {
fns: Some(std::collections::HashMap::new()),
target: None,
strings: Rc::new(RefCell::new(StringMap::new())),
properties: None,
features: HashSet::new()
Expand Down
13 changes: 5 additions & 8 deletions codegen-w65/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,15 +823,14 @@ impl W65FunctionCodegen {
}

pub struct W65CodegenPlugin {
target: Option<Target>,
fns: Option<std::collections::HashMap<String, FunctionCodegen<W65FunctionCodegen>>>,
strings: Rc<RefCell<StringMap>>,
properties: Option<&'static TargetProperties<'static>>,
}

impl W65CodegenPlugin {
fn write_output_impl<W: std::io::Write>(&mut self, mut x: W) -> std::io::Result<()> {
let fmt = binfmt::def_vec_for(self.target.as_ref().unwrap());
let fmt = binfmt::format_by_name(&self.properties.unwrap().link.obj_binfmt).unwrap();
let mut file = fmt.create_file(FileType::Relocatable);
let mut text = Section {
name: String::from(".text"),
Expand Down Expand Up @@ -986,15 +985,14 @@ impl XLangPlugin for W65CodegenPlugin {
}

#[allow(clippy::needless_borrow)] // Incorrect lint
fn set_target(&mut self, targ: xlang::targets::Target) {
self.target = Some((&targ).into());
self.properties = xlang::targets::properties::get_properties(&targ);
fn set_target(&mut self, targ: &'static TargetProperties<'static>) {
self.properties = Some(targ);
}
}

impl XLangCodegen for W65CodegenPlugin {
fn target_matches(&self, x: &xlang::targets::Target) -> bool {
let target: target_tuples::Target = x.into();
fn target_matches(&self, x: StringView) -> bool {
let target: target_tuples::Target = x.parse().unwrap();

matches!(target.arch(), Architecture::Wc65c816)
}
Expand All @@ -1019,7 +1017,6 @@ xlang::host::rustcall! {
pub extern "rustcall" fn xlang_backend_main() -> DynBox<dyn XLangCodegen> {
DynBox::unsize_box(xlang::prelude::v1::Box::new(W65CodegenPlugin {
fns: Some(std::collections::HashMap::new()),
target: None,
strings: Rc::new(RefCell::new(StringMap::new())),
properties: None,
}))
Expand Down
11 changes: 3 additions & 8 deletions codegen-x86/src/callconv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashSet, rc::Rc};

use arch_ops::x86::{features::X86Feature, X86Register, X86RegisterClass};
use target_tuples::Target;

use xlang::{
prelude::v1::{Pair, Some as XLangSome},
targets::properties::TargetProperties,
Expand Down Expand Up @@ -282,14 +282,9 @@ impl<'a> CallingConvention for dyn X86CallConv + 'a {
#[allow(clippy::module_name_repetitions)]
pub fn get_callconv<S: std::hash::BuildHasher + Clone + 'static>(
_tag: Abi,
target: Target,
target: &'static TargetProperties<'static>,
features: HashSet<X86Feature, S>,
tys: Rc<TypeInformation>,
) -> Option<Box<dyn X86CallConv>> {
target_tuples::match_targets! {
match (target){
x86_64-*-linux-gnu => Some(Box::new(SysV64CC(xlang::targets::properties::get_properties(&target.into())?,features,tys))),
x86_64-*-linux-gnux32 => Some(Box::new(SysV64CC(xlang::targets::properties::get_properties(&target.into())?,features,tys)))
}
}
Some(Box::new(SysV64CC(target, features, tys)))
}
Loading

0 comments on commit 1a1a275

Please sign in to comment.