Skip to content

Commit c5ec548

Browse files
committed
Added support for tcc, sdcc.
1 parent 20fe5f0 commit c5ec548

File tree

22 files changed

+343
-427
lines changed

22 files changed

+343
-427
lines changed

Diff for: cilly/src/asm.rs

-1
This file was deleted.

Diff for: cilly/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub fn calculate_hash<T: std::hash::Hash>(t: &T) -> u64 {
1717
}
1818

1919
pub mod access_modifier;
20-
pub mod asm;
2120

2221
pub mod basic_block;
2322

Diff for: cilly/src/libc_fns.rs

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ pub const LIBC_FNS: &[&str] = &[
1616
"atol",
1717
"atoll",
1818
"bcopy",
19+
"backtrace",
20+
"backtrace_symbols_fd",
1921
"bind",
2022
"bindresvport",
2123
"bsearch",
@@ -45,6 +47,7 @@ pub const LIBC_FNS: &[&str] = &[
4547
"closedir",
4648
"sigemptyset",
4749
"sigaction",
50+
"sigaltstack",
4851
"closelog",
4952
"confstr",
5053
"connect",
@@ -60,6 +63,15 @@ pub const LIBC_FNS: &[&str] = &[
6063
"dlsym",
6164
"dup",
6265
"dprintf",
66+
"dlerror",
67+
"dladdr",
68+
"dup2",
69+
"dlopen",
70+
"dl_iterate_phdr",
71+
"dlclose",
72+
"dlerror",
73+
"fstat",
74+
"flock",
6375
"drand48",
6476
"dysize",
6577
"ecvt",
@@ -140,6 +152,11 @@ pub const LIBC_FNS: &[&str] = &[
140152
"getaddrinfo",
141153
"getaliasbyname",
142154
"getaliasent",
155+
"getauxval",
156+
"mmap",
157+
"mprotect",
158+
"mmap64",
159+
"munmap",
143160
"getchar",
144161
"getcwd",
145162
"getdate",
@@ -317,6 +334,9 @@ pub const LIBC_FNS: &[&str] = &[
317334
"opendir",
318335
"openlog",
319336
"perror",
337+
"pipe",
338+
"pthread_mutex_unlock",
339+
"pause",
320340
"pidfd_getpid",
321341
"posix_spawn_file_actions_init",
322342
"posix_spawnattr_init",
@@ -392,6 +412,11 @@ pub const LIBC_FNS: &[&str] = &[
392412
"ruserok",
393413
"ruserpass",
394414
"scandir",
415+
"setgid",
416+
"setuid",
417+
"setpgid",
418+
"signal",
419+
"sysconf",
395420
"scandirat64",
396421
"scanf",
397422
"sched_getaffinity",

Diff for: cilly/src/v2/asm.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ impl Assembly {
10861086
/// Preforms a "shallow" GC pass on all method defs, removing them if and only if:
10871087
/// 1. They are not referenced by anything inside this assembly
10881088
/// 2. They are not accessible from outside of it.
1089-
///
1089+
///
10901090
/// **WARNING**: This gc is highly conservative, and will often not collect some things.
10911091
/// To improve its accuracy, first do `link_gc`.
10921092
pub fn shallow_methodef_gc(&mut self) {
@@ -1177,7 +1177,8 @@ impl Assembly {
11771177
}
11781178
pub fn split_to_parts(&self, parts: u32) -> impl Iterator<Item = Self> + use<'_> {
11791179
let lib_name = StringIdx::from_index(std::num::NonZeroU32::new(1).unwrap());
1180-
let div = (self.method_refs.len().div_ceil(parts as usize)) as u32;
1180+
// Since 1st part is dedicated to methods which access statics, split the rest into n-1 parts.
1181+
let div = (self.method_refs.len().div_ceil(parts as usize - 1)) as u32;
11811182
// Into 1st. Only split out the methods where it is known, for sure, that they don't access any statics.
11821183
(0..parts).map(move |rem| {
11831184
let mut part = self.clone();
@@ -1189,7 +1190,7 @@ impl Assembly {
11891190
preserve_errno: false,
11901191
}
11911192
}
1192-
} else if idx.as_bimap_index().get() / div != rem {
1193+
} else if idx.as_bimap_index().get() / div + 1 != rem {
11931194
*def.implementation_mut() = MethodImpl::Extern {
11941195
lib: lib_name,
11951196
preserve_errno: false,
@@ -1297,7 +1298,7 @@ impl Assembly {
12971298
Type::PlatformObject => self.ptr_size(),
12981299
Type::Bool => 1,
12991300
Type::Void => 0,
1300-
Type::PlatformArray {.. } => todo!(),
1301+
Type::PlatformArray { .. } => todo!(),
13011302
Type::FnPtr(_) => self.ptr_size(),
13021303
Type::SIMDVector(simdvector) => (simdvector.bits() / 8).into(),
13031304
}

Diff for: cilly/src/v2/basic_block.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use super::{
4-
opt,
5-
Assembly, CILNode, CILRoot, RootIdx,
6-
};
3+
use super::{opt, Assembly, CILNode, CILRoot, RootIdx};
74
use crate::basic_block::BasicBlock as V1Block;
85
pub type BlockId = u32;
96
#[derive(Hash, PartialEq, Eq, Clone, Debug, Serialize, Deserialize)]
@@ -188,11 +185,11 @@ impl BasicBlock {
188185
/// ```
189186
pub fn remove_handler(&mut self, asm: &mut Assembly) {
190187
self.handler = None;
191-
self.roots_mut()
192-
.iter_mut()
193-
.for_each(|root| if let CILRoot::ExitSpecialRegion { target, source: _ } = asm[*root] {
188+
self.roots_mut().iter_mut().for_each(|root| {
189+
if let CILRoot::ExitSpecialRegion { target, source: _ } = asm[*root] {
194190
*root = asm.alloc_root(CILRoot::Branch(Box::new((target, 0, None))));
195-
});
191+
}
192+
});
196193
}
197194
}
198195
impl BasicBlock {

0 commit comments

Comments
 (0)