From f1d19b06d14e8fc22915e8e100b5df396f155fe3 Mon Sep 17 00:00:00 2001 From: SimplyTheOther Date: Wed, 17 Jun 2020 14:26:42 +0800 Subject: Added CR16 target hook (or provisional one at least) --- gcc/config.gcc | 1 + gcc/config/cr16/cr16-protos.h | 3 +++ gcc/config/cr16/cr16-rust.c | 54 +++++++++++++++++++++++++++++++++++++++++++ gcc/config/cr16/cr16.h | 2 ++ gcc/config/cr16/t-cr16 | 3 +++ 5 files changed, 63 insertions(+) create mode 100644 gcc/config/cr16/cr16-rust.c (limited to 'gcc') diff --git a/gcc/config.gcc b/gcc/config.gcc index c5c9d8a..f564320 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -1529,6 +1529,7 @@ cr16-*-elf) tm_file="elfos.h ${tm_file} newlib-stdint.h" tmake_file="${tmake_file} cr16/t-cr16 " use_collect2=no + rust_target_objs="cr16-rust.o" ;; cris-*-elf | cris-*-none) tm_file="dbxelf.h elfos.h newlib-stdint.h ${tm_file}" diff --git a/gcc/config/cr16/cr16-protos.h b/gcc/config/cr16/cr16-protos.h index 6ebc0b3..00fa0aa 100644 --- a/gcc/config/cr16/cr16-protos.h +++ b/gcc/config/cr16/cr16-protos.h @@ -45,6 +45,9 @@ enum data_model_type ILLEGAL_DM /* Illegal data model. */ }; +/* Defined in cr16-rust.c */ +extern void cr16_rust_target_cpu_info (void); + #ifdef RTX_CODE /* Addressing Modes. */ diff --git a/gcc/config/cr16/cr16-rust.c b/gcc/config/cr16/cr16-rust.c new file mode 100644 index 0000000..3b9efe3 --- /dev/null +++ b/gcc/config/cr16/cr16-rust.c @@ -0,0 +1,54 @@ +/* Subroutines for the Rust front end on the CR16 architecture. + Copyright (C) 2020 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tm_p.h" +#include "rust/rust-target.h" +#include "rust/rust-target-def.h" + +/* Implement TARGET_RUST_CPU_INFO for CR16 targets. */ + +void cr16_rust_target_cpu_info(void) { + rust_add_target_info("target_arch", "cr16"); + + // llvm seems to have no support for cr16 (nor historical support), so names are made up by me + // TODO: very subject to change + // TODO maybe put in sub-arches as features? idk + if (TARGET_BIT_OPS) + rust_add_target_info("target_feature", "bit-ops"); + if (TARGET_MAC) + rust_add_target_info("target_feature", "mac"); + if (TARGET_DEBUG_ADDR) + rust_add_target_info("target_feature", "debug-addr"); + if (TARGET_INT32) + rust_add_target_info("target_feature", "int32"); + + if (CR16_TARGET_DATA_NEAR) + rust_add_target_info("target_feature", "data-model-near"); + if (CR16_TARGET_DATA_MEDIUM) + rust_add_target_info("target_feature", "data-model-medium"); + if (CR16_TARGET_DATA_FAR) + rust_add_target_info("target_feature", "data-model-far"); + + if (TARGET_CR16C) + rust_add_target_info("target_feature", "cr16c"); + if (TARGET_CR16CP) + rust_add_target_info("target_feature", "cr16cplus"); +} diff --git a/gcc/config/cr16/cr16.h b/gcc/config/cr16/cr16.h index 4af90bf..b90cce1 100644 --- a/gcc/config/cr16/cr16.h +++ b/gcc/config/cr16/cr16.h @@ -67,6 +67,8 @@ do \ while (0) #endif +#define TARGET_RUST_CPU_INFO cr16_rust_target_cpu_info + /* Force the generation of dwarf .debug_frame sections even if not compiling -g. This guarantees that we can unwind the stack. */ #define DWARF2_FRAME_INFO 1 diff --git a/gcc/config/cr16/t-cr16 b/gcc/config/cr16/t-cr16 index e18a15a..eccff6d 100644 --- a/gcc/config/cr16/t-cr16 +++ b/gcc/config/cr16/t-cr16 @@ -23,3 +23,6 @@ MULTILIB_DIRNAMES = far-pic int32 MULTILIB_MATCHES = MULTILIB_EXTRA_OPTS = mcr16cplus mdata-model=far +cr16-rust.o: $(srcdir)/config/cr16/cr16-rust.c \ + $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_COMMON_H) + $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< -- cgit v1.1