Skip to content

Commit

Permalink
[YCC] starting ycc
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Nov 7, 2024
1 parent d4e9452 commit 6ab9eb2
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [
"tools/simplelang",
"tools/ytest",
"tools/ylc",
"src/proc",
"src/proc", "tools/ycc",
]

[workspace.dependencies]
Expand Down
150 changes: 149 additions & 1 deletion src/Target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod x64;
pub mod wasm;
mod registry;
mod whitelist;

pub use x64::initializeX64Target;
pub use wasm::initializeWasmTarget;
pub use whitelist::*;
Expand Down Expand Up @@ -318,4 +319,151 @@ pub enum ObjFormat {
XCoff,
/// Platforms default (e.g: Windows -> Coff)
Default
}
}

impl std::fmt::Display for Arch {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Arch::Unknown => "unknown",
Arch::Arm => "arm",
Arch::ArmEB => "armeb",
Arch::Aarch64 => "aarch64",
Arch::Aarch64BE => "aarch64_be",
Arch::Arc => "arc",
Arch::Avr => "avr",
Arch::Bpfel => "bpfel",
Arch::Bpfeb => "bpfeb",
Arch::Hexagon => "hexagon",
Arch::Mips => "mips",
Arch::Mipsel => "mipsel",
Arch::Mips64 => "mips64",
Arch::Mips64EL => "mips64el",
Arch::Msp420 => "msp430",
Arch::Ppc => "ppc",
Arch::Ppc64 => "ppc64",
Arch::Ppc64LE => "ppc64le",
Arch::R600 => "r600",
Arch::AmdGCN => "amdgcn",
Arch::Riscv32 => "riscv32",
Arch::Riscv64 => "riscv64",
Arch::Sparc => "sparc",
Arch::Sparcv9 => "sparcv9",
Arch::Sparcel => "sparcel",
Arch::SystemZ => "systemz",
Arch::Tce => "tce",
Arch::TceLe => "tcele",
Arch::Thumb => "thumb",
Arch::Thumbeb => "thumbeb",
Arch::X86 => "x86",
Arch::X86_64 => "x86_64",
Arch::Xcore => "xcore",
Arch::Nvptx => "nvptx",
Arch::Nvptx64 => "nvptx64",
Arch::Le32 => "le32",
Arch::Le64 => "le64",
Arch::AmdIL => "amdil",
Arch::AmdIL64 => "amdil64",
Arch::Hsail => "hsail",
Arch::Hsail64 => "hsail64",
Arch::Spir => "spir",
Arch::Spir64 => "spir64",
Arch::Kalimba => "kalimba",
Arch::Shave => "shave",
Arch::Lanai => "lanai",
Arch::Wasm32 => "wasm32",
Arch::Wasm64 => "wasm64",
Arch::Renderscript32 => "renderscript32",
Arch::Renderscript64 => "renderscript64",
})
}
}

impl std::fmt::Display for Vendor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Vendor::Unknown => "unknown",
Vendor::Apple => "apple",
Vendor::Pc => "pc",
Vendor::Scei => "scei",
Vendor::Bgp => "bgp",
Vendor::Freescale => "freescale",
Vendor::Ibm => "ibm",
Vendor::ImaginationTechnologies => "imagination",
Vendor::MipsTechnologies => "mips",
Vendor::Nvidia => "nvidia",
Vendor::Csr => "csr",
Vendor::Myriad => "myriad",
Vendor::Amd => "amd",
Vendor::Mesa => "mesa",
Vendor::Suse => "suse",
Vendor::OpenEmbedded => "oe",
})
}
}
impl std::fmt::Display for OS {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
OS::Unknown => "unknown",
OS::Ananas => "ananas",
OS::CloudABI => "cloudabi",
OS::Darwin => "darwin",
OS::DragonFly => "dragonfly",
OS::FreeBSD => "freebsd",
OS::Fuchsia => "fuchsia",
OS::Ios => "ios",
OS::KFreeBSD => "kfreebsd",
OS::Linux => "linux",
OS::Lv2 => "lv2",
OS::MacOS => "macos",
OS::NetBSD => "netbsd",
OS::OpenBSD => "openbsd",
OS::Solaris => "solaris",
OS::Win32 => "windows",
OS::Haiku => "haiku",
OS::Minix => "minix",
OS::Rtems => "rtems",
OS::NaCl => "nacl",
OS::Cnk => "cnk",
OS::Aix => "aix",
OS::Cuda => "cuda",
OS::Nvcl => "nvcl",
OS::AmdHSA => "amdhsa",
OS::Ps4 => "ps4",
OS::ElfIAMCU => "elfiamcu",
OS::TvOS => "tvos",
OS::WatchOS => "watchos",
OS::Mesa3D => "mesa3d",
OS::Contiki => "contiki",
OS::AmdPAL => "amdpal",
OS::HermitCore => "hermitcore",
OS::Hurd => "hurd",
OS::Wasi => "wasi",
})
}
}

impl std::fmt::Display for Environment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", match self {
Environment::Unknown => "unknown",
Environment::Gnu => "gnu",
Environment::GnuABIN32 => "gnun32",
Environment::GnuABI64 => "gnuabi64",
Environment::GnuEABI => "gnueabi",
Environment::GnuEABIHF => "gnueabihf",
Environment::GnuX32 => "gnux32",
Environment::Code16 => "code16",
Environment::Eabi => "eabi",
Environment::EabiHF => "eabihf",
Environment::Android => "android",
Environment::Musl => "musl",
Environment::MuslEABI => "musleabi",
Environment::MuslEABIHF => "musleabihf",
Environment::Msvc => "msvc",
Environment::Itanium => "itanium",
Environment::Cygnus => "cygnus",
Environment::CoreCLR => "coreclr",
Environment::Simulator => "simulator",
})
}
}
15 changes: 15 additions & 0 deletions src/Target/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ impl Display for TripleError {

impl Error for TripleError {}

impl Display for Triple {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut vendor = format!("-{}", self.vendor);
if self.vendor == Vendor::Unknown { vendor = String::new() };

let mut os = format!("-{}", self.os);
if self.os == OS::Unknown { os = String::new() };

let mut env = format!("-{}", self.env);
if self.env == Environment::Unknown { env = String::new() };

write!(f, "{}{}{}{}", self.arch, vendor, os, env)
}
}

impl Triple {
/// Parses the target triple string.
/// Returns the target triple or TripleError
Expand Down
7 changes: 7 additions & 0 deletions tools/ycc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "ycc"
version = "0.1.0"
edition = "2021"

[dependencies]
ygen = { workspace = true }
Empty file added tools/ycc/src/ast.rs
Empty file.
Empty file added tools/ycc/src/codegen.rs
Empty file.
32 changes: 32 additions & 0 deletions tools/ycc/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ErrorLoc {
pub line: u64,
pub col: u64,
pub length: u64,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct YccError {
loc: ErrorLoc,

head: &'static str,

where_string: String,
}

impl YccError {
pub fn print(&self, code: &str, file_name: &str) {
let mut fab = ygen::Support::Error::new(
self.head,
file_name,
self.loc.line.to_string(),
self.loc.col.to_string()
);

fab.setCodeLine(code.to_string());

fab.addWhere(self.where_string.to_owned(), self.loc.col, self.loc.length);

fab.print();
}
}
Loading

0 comments on commit 6ab9eb2

Please sign in to comment.