Add wii rename and strange_size script

This commit is contained in:
Artemis Tosini 2019-04-25 02:58:36 +00:00
parent a8d4c65179
commit 15572c8319
Signed by: artemist
GPG key ID: EE5227935FE3FF18
6 changed files with 210 additions and 0 deletions

1
C/strange_size/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
i8388607.s.s

47
C/strange_size/i8388607.s Normal file
View file

@ -0,0 +1,47 @@
; ModuleID = 'i8388607.c'
source_filename = "i8388607.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@.str = private unnamed_addr constant [24 x i8] c"(%lu + %lu) >> 1 = %lu\0A\00", align 1
; Function Attrs: noinline nounwind optnone sspstrong uwtable
define dso_local i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i8388607, align 8
%7 = alloca i8388607, align 8
%8 = alloca i8388607, align 8
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
store i8388607 -9223372036854775808, i8388607* %6, align 8
store i8388607 -9223372036854775808, i8388607* %7, align 8
%9 = load i8388607, i8388607* %6, align 8
%10 = load i8388607, i8388607* %7, align 8
%11 = add i8388607 %9, %10
%12 = lshr i8388607 %11, 1
store i8388607 %12, i8388607* %8, align 8
%13 = load i8388607, i8388607* %6, align 8
%14 = load i8388607, i8388607* %7, align 8
%15 = load i8388607, i8388607* %8, align 8
%16 = trunc i8388607 %13 to i64
%17 = trunc i8388607 %14 to i64
%18 = trunc i8388607 %15 to i64
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i32 0, i32 0), i64 %16, i64 %17, i64 %18)
ret i32 0
}
declare i32 @printf(i8*, ...) #1
attributes #0 = { noinline nounwind optnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!"clang version 7.0.0 (tags/RELEASE_700/final)"}

10
C/strange_size/sadd.c Normal file
View file

@ -0,0 +1,10 @@
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv) {
uint32_t i = 1 << 31;
uint32_t j = 3 << 30;
uint32_t k = i + j;
printf("%d + %d = %d\n", i, j, k);
return 0;
}

44
C/strange_size/sadd.s Normal file
View file

@ -0,0 +1,44 @@
; ModuleID = 'sadd.c'
source_filename = "sadd.c"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
@.str = private unnamed_addr constant [14 x i8] c"%d + %d = %d\0A\00", align 1
declare i32 @llvm.sadd.sat.i32(i32, i32)
; Function Attrs: noinline nounwind optnone sspstrong uwtable
define dso_local i32 @main(i32, i8**) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i32, align 4
%7 = alloca i32, align 4
%8 = alloca i32, align 4
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
store i32 -2147483648, i32* %6, align 4
store i32 -1073741824, i32* %7, align 4
%9 = load i32, i32* %6, align 4
%10 = load i32, i32* %7, align 4
%11 = call i32 @llvm.sadd.sat.i32(i32 %9, i32 %10)
store i32 %11, i32* %8, align 4
%12 = load i32, i32* %6, align 4
%13 = load i32, i32* %7, align 4
%14 = load i32, i32* %8, align 4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i32 0, i32 0), i32 %12, i32 %13, i32 %14)
ret i32 0
}
declare i32 @printf(i8*, ...) #1
attributes #0 = { noinline nounwind optnone sspstrong uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!"clang version 7.0.0 (tags/RELEASE_700/final)"}

48
C/strange_size/sadd.s.s Normal file
View file

@ -0,0 +1,48 @@
.text
.intel_syntax noprefix
.file "sadd.c"
.globl main # -- Begin function main
.p2align 4, 0x90
.type main,@function
main: # @main
.cfi_startproc
# %bb.0:
push rbp
.cfi_def_cfa_offset 16
.cfi_offset rbp, -16
mov rbp, rsp
.cfi_def_cfa_register rbp
sub rsp, 32
mov dword ptr [rbp - 20], 0
mov dword ptr [rbp - 16], edi
mov qword ptr [rbp - 32], rsi
mov dword ptr [rbp - 8], -2147483648
mov dword ptr [rbp - 4], -1073741824
mov edi, dword ptr [rbp - 8]
mov esi, dword ptr [rbp - 4]
call llvm.sadd.sat.i32
mov dword ptr [rbp - 12], eax
mov esi, dword ptr [rbp - 8]
mov edx, dword ptr [rbp - 4]
mov ecx, dword ptr [rbp - 12]
movabs rdi, offset .L.str
mov al, 0
call printf
xor eax, eax
add rsp, 32
pop rbp
.cfi_def_cfa rsp, 8
ret
.Lfunc_end0:
.size main, .Lfunc_end0-main
.cfi_endproc
# -- End function
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "%d + %d = %d\n"
.size .L.str, 14
.ident "clang version 7.0.0 (tags/RELEASE_700/final)"
.section ".note.GNU-stack","",@progbits

60
scripts/rename_wii.py Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env python3
import os
import os.path
import hashlib
import html
orig_path = '../'
new_path = '.'
def format_name(name):
name = html.unescape(name)
name = name.replace('The - ', 'The ')
return name
processed = [name.strip() for name in open(os.path.join(orig_path, "processed.txt")).readlines()]
games = dict()
for dfile in 'gc.dat', 'wii.dat':
lines = open(os.path.join(orig_path, dfile)).readlines()
lines = [line.strip() for line in lines if line.strip().startswith('<rom name=')]
for line in lines:
ns = line.find("name=\"") + len("name=\"")
ne = line.find('"', ns)
hs = line.find("sha1=\"") + len("sha1=\"")
he = line.find('"', hs)
name = line[ns:ne]
hsh = line[hs:he]
games[hsh] = format_name(name)
isos = [fn for fn in os.listdir(orig_path) if fn.endswith('.iso')]
for iso_name in isos:
if iso_name in processed:
print(f'Already processed {iso_name}, skipping')
continue
iso = os.path.join(orig_path, iso_name)
h = hashlib.sha1()
with open(iso, 'rb') as isof:
buf = isof.read(2**16)
while len(buf) > 0:
h.update(buf)
buf = isof.read(2**16)
hsh = h.hexdigest()
print(hsh)
if hsh not in games:
print(f"Warning! File {iso_name} with hash {hsh} was not found in game database")
print("Not counting as processed, will be processed next time")
isos.remove(iso_name)
continue
name = games[hsh]
print(name)
path = os.path.join(new_path, name)
if os.path.exists(path):
print(f"'{path}' already exists, skipping")
else:
os.link(iso, os.path.join(new_path, name))
f = open(os.path.join(orig_path, "processed.txt"), "w")
f.write("\n".join(isos))
f.close()