Last active
August 29, 2015 13:56
-
-
Save antonijn/9156463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aqua.std; | |
private class Program { | |
private static int getch(byte[] buf, ref int idx, ref int cp) { | |
int remunits; | |
byte nxt; | |
byte msk; | |
if (idx > buf.size()) { | |
return -1; | |
} | |
nxt = buf[idx++]; | |
if ((nxt & 0x80) != 0) { | |
msk = 0xe0; | |
for (remunits = 1; (nxt & msk) != (msk << 1); ++remunits) { | |
msk >>= 1; | |
msk |= 0x80; | |
} | |
} else { | |
remunits = 0; | |
msk = 0; | |
} | |
cp = nxt ^ msk; | |
while (remunits-- > 0) { | |
cp <<= 6; | |
if (idx >= buf.size()) { | |
return -1; | |
} | |
cp |= buf[idx++] & 0x3f; | |
} | |
return 0; | |
} | |
private static void main() { | |
int idx = 0; | |
int cp = 0; | |
getch(null, ref idx, ref cp); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%vtable.class.aqua.std.Iterator.0.1char.2 = type { i8* (%class.aqua.std.Iterator.0.1char.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, i1 (%class.aqua.std.Iterator.0.1char.2*)*, i8 (%class.aqua.std.Iterator.0.1char.2*)*, void (%class.aqua.std.Iterator.0.1char.2*)* } | |
%class.aqua.std.Iterator.0.1char.2 = type { %vtable.class.aqua.std.Iterator.0.1char.2* } | |
%vtable.class.aqua.std.IndexedCollection.0.1char.2 = type { i8* (%class.aqua.std.IndexedCollection.0.1char.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.Collection.0.1char.2*)*, %class.aqua.std.Array.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1char.2*,i32)* } | |
%class.aqua.std.IndexedCollection.0.1char.2 = type { %vtable.class.aqua.std.IndexedCollection.0.1char.2* } | |
%vtable.class.aqua.std.MutableIndexedCollection.0.1char.2 = type { i8* (%class.aqua.std.MutableIndexedCollection.0.1char.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.Collection.0.1char.2*)*, %class.aqua.std.Array.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1char.2*,i32)*, i8 (%class.aqua.std.MutableIndexedCollection.0.1char.2*,i32)* } | |
%class.aqua.std.MutableIndexedCollection.0.1char.2 = type { %vtable.class.aqua.std.MutableIndexedCollection.0.1char.2* } | |
%vtable.class.aqua.std.Array.0.1char.2 = type { i8* (%class.aqua.std.Array.0.1char.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.Collection.0.1char.2*)*, %class.aqua.std.Array.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1char.2*,i32)*, i8 (%class.aqua.std.MutableIndexedCollection.0.1char.2*,i32)* } | |
%class.aqua.std.Array.0.1char.2 = type { %vtable.class.aqua.std.Array.0.1char.2*, i32, i64 } | |
%vtable.class.aqua.std.Collection.0.1char.2 = type { i8* (%class.aqua.std.Collection.0.1char.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.Collection.0.1char.2*)*, %class.aqua.std.Array.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)* } | |
%class.aqua.std.Collection.0.1char.2 = type { %vtable.class.aqua.std.Collection.0.1char.2* } | |
%vtable.class.aqua.std.String = type { i8* (%class.aqua.std.String*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.Collection.0.1char.2*)*, %class.aqua.std.Array.0.1char.2* (%class.aqua.std.Collection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1char.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1char.2*,i32)* } | |
%class.aqua.std.String = type { %vtable.class.aqua.std.String*, i32, i32, i8* } | |
%vtable.class.aqua.std.Object = type { i8* (%class.aqua.std.Object*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)* } | |
%class.aqua.std.Object = type { %vtable.class.aqua.std.Object* } | |
%vtable.class.aqua.std.Type = type { i8* (%class.aqua.std.Type*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Type*)*, i1 (%class.aqua.std.Type*,%class.aqua.std.Type*)* } | |
%class.aqua.std.Type = type { %vtable.class.aqua.std.Type*, %class.aqua.std.String*, %class.aqua.std.Type* } | |
%vtable.class.aqua.std.Iterator.0.1byte.2 = type { i8* (%class.aqua.std.Iterator.0.1byte.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, i1 (%class.aqua.std.Iterator.0.1byte.2*)*, i8 (%class.aqua.std.Iterator.0.1byte.2*)*, void (%class.aqua.std.Iterator.0.1byte.2*)* } | |
%class.aqua.std.Iterator.0.1byte.2 = type { %vtable.class.aqua.std.Iterator.0.1byte.2* } | |
%vtable.class.aqua.std.Collection.0.1byte.2 = type { i8* (%class.aqua.std.Collection.0.1byte.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.Collection.0.1byte.2*)*, %class.aqua.std.Array.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)* } | |
%class.aqua.std.Collection.0.1byte.2 = type { %vtable.class.aqua.std.Collection.0.1byte.2* } | |
%vtable.class.aqua.std.IndexedCollection.0.1byte.2 = type { i8* (%class.aqua.std.IndexedCollection.0.1byte.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.Collection.0.1byte.2*)*, %class.aqua.std.Array.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1byte.2*,i32)* } | |
%class.aqua.std.IndexedCollection.0.1byte.2 = type { %vtable.class.aqua.std.IndexedCollection.0.1byte.2* } | |
%vtable.class.aqua.std.MutableIndexedCollection.0.1byte.2 = type { i8* (%class.aqua.std.MutableIndexedCollection.0.1byte.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.Collection.0.1byte.2*)*, %class.aqua.std.Array.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1byte.2*,i32)*, i8 (%class.aqua.std.MutableIndexedCollection.0.1byte.2*,i32)* } | |
%class.aqua.std.MutableIndexedCollection.0.1byte.2 = type { %vtable.class.aqua.std.MutableIndexedCollection.0.1byte.2* } | |
%vtable.class.aqua.std.Array.0.1byte.2 = type { i8* (%class.aqua.std.Array.0.1byte.2*,%class.aqua.std.Type*)*, i1 (%class.aqua.std.Object*,%class.aqua.std.Object*)*, i64 (%class.aqua.std.Object*)*, %class.aqua.std.Type* (%class.aqua.std.Object*)*, %class.aqua.std.String* (%class.aqua.std.Object*)*, %class.aqua.std.Iterator.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.Collection.0.1byte.2*)*, %class.aqua.std.Array.0.1byte.2* (%class.aqua.std.Collection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i32 (%class.aqua.std.IndexedCollection.0.1byte.2*)*, i8 (%class.aqua.std.IndexedCollection.0.1byte.2*,i32)*, i8 (%class.aqua.std.MutableIndexedCollection.0.1byte.2*,i32)* } | |
%class.aqua.std.Array.0.1byte.2 = type { %vtable.class.aqua.std.Array.0.1byte.2*, i32, i64 } | |
declare void @aqua_init(i32, i8**) | |
declare void @aqua_throw_null_ptr_ex(i8*) | |
@.str0 = private unnamed_addr constant [4 x i8] c"buf\00" | |
@.str1 = private unnamed_addr constant [4 x i8] c"buf\00" | |
@.str2 = private unnamed_addr constant [4 x i8] c"buf\00" | |
@.str3 = private unnamed_addr constant [4 x i8] c"buf\00" | |
define i32 @class.aqua.std.Array.0.1byte.2.size.3526476(%class.aqua.std.Array.0.1byte.2* %this) { | |
%1 = getelementptr inbounds %class.aqua.std.Array.0.1byte.2* %this, i32 0, i32 1 | |
%2 = load i32* %1 | |
ret i32 %2 | |
; <label>:%3 | |
} | |
define i8 @ig.class.aqua.std.Array.0.1byte.2.indexer.1978133948(%class.aqua.std.Array.0.1byte.2* %this, i32 %i) { | |
%1 = alloca i32 | |
store i32 %i, i32* %1 | |
%2 = getelementptr inbounds %class.aqua.std.Array.0.1byte.2* %this, i32 0, i32 2 | |
%3 = load i64* %2 | |
%4 = inttoptr i64 %3 to i8* | |
%5 = load i32* %1 | |
%6 = sext i32 %5 to i64 | |
%7 = getelementptr inbounds i8* %4, i64 %6 | |
%8 = load i8* %7 | |
ret i8 %8 | |
; <label>:%9 | |
} | |
define internal i32 @class.Program.getch.577725869(i8* %this, %class.aqua.std.Array.0.1byte.2* %buf, i32* %idx, i32* %cp) { | |
%1 = alloca %class.aqua.std.Array.0.1byte.2* | |
store %class.aqua.std.Array.0.1byte.2* %buf, %class.aqua.std.Array.0.1byte.2** %1 | |
%2 = alloca i32 | |
%3 = alloca i8 | |
%4 = alloca i8 | |
%5 = load i32* %idx | |
%6 = load %class.aqua.std.Array.0.1byte.2** %1 | |
%7 = icmp eq %class.aqua.std.Array.0.1byte.2* %6, null | |
br i1 %7, label %72, label %8 | |
; <label>:%8 | |
%9 = call i32 @class.aqua.std.Array.0.1byte.2.size.3526476(%class.aqua.std.Array.0.1byte.2* %6) | |
%10 = icmp sgt i32 %5, %9 | |
br i1 %10, label %11, label %13 | |
; <label>:%11 | |
ret i32 -1 | |
; <label>:%12 | |
br label %13 | |
; <label>:%13 | |
%14 = load %class.aqua.std.Array.0.1byte.2** %1 | |
%15 = icmp eq %class.aqua.std.Array.0.1byte.2* %14, null | |
br i1 %15, label %72, label %16 | |
; <label>:%16 | |
%17 = load i32* %idx | |
%18 = add i32 %17, 1 | |
store i32 %18, i32* %idx | |
%19 = call i8 @ig.class.aqua.std.Array.0.1byte.2.indexer.1978133948(%class.aqua.std.Array.0.1byte.2* %14, i32 %17) | |
store i8 %19, i8* %3 | |
%20 = load i8* %3 | |
%21 = and i8 %20, 128 | |
%22 = icmp ne i8 %21, 0 | |
br i1 %22, label %23, label %39 | |
; <label>:%23 | |
store i8 224, i8* %4 | |
store i32 1, i32* %2 | |
br label %24 | |
; <label>:%24 | |
%25 = load i8* %3 | |
%26 = load i8* %4 | |
%27 = and i8 %25, %26 | |
%28 = load i8* %4 | |
%29 = shl i8 %28, 1 | |
%30 = icmp ne i8 %27, %29 | |
br i1 %30, label %31, label %38 | |
; <label>:%31 | |
%32 = load i8* %4 | |
%33 = lshr i8 %32, 1 | |
store i8 %33, i8* %4 | |
%34 = load i8* %4 | |
%35 = and i8 %34, 128 | |
store i8 %35, i8* %4 | |
%36 = load i32* %2 | |
%37 = add i32 %36, 1 | |
store i32 %37, i32* %2 | |
br label %24 | |
; <label>:%38 | |
br label %40 | |
; <label>:%39 | |
store i32 0, i32* %2 | |
store i8 0, i8* %4 | |
br label %40 | |
; <label>:%40 | |
%41 = load i8* %3 | |
%42 = load i8* %4 | |
%43 = and i8 %41, %42 | |
%44 = zext i8 %43 to i32 | |
store i32 %44, i32* %cp | |
br label %45 | |
; <label>:%45 | |
%46 = load i32* %2 | |
%47 = sub i32 %46, 1 | |
store i32 %47, i32* %2 | |
%48 = icmp sgt i32 %46, 0 | |
br i1 %48, label %49, label %71 | |
; <label>:%49 | |
%50 = load i32* %cp | |
%51 = shl i32 %50, 6 | |
store i32 %51, i32* %cp | |
%52 = load i32* %idx | |
%53 = load %class.aqua.std.Array.0.1byte.2** %1 | |
%54 = icmp eq %class.aqua.std.Array.0.1byte.2* %53, null | |
br i1 %54, label %72, label %55 | |
; <label>:%55 | |
%56 = call i32 @class.aqua.std.Array.0.1byte.2.size.3526476(%class.aqua.std.Array.0.1byte.2* %53) | |
%57 = icmp sge i32 %52, %56 | |
br i1 %57, label %58, label %60 | |
; <label>:%58 | |
ret i32 -1 | |
; <label>:%59 | |
br label %60 | |
; <label>:%60 | |
%61 = load i32* %cp | |
%62 = load %class.aqua.std.Array.0.1byte.2** %1 | |
%63 = icmp eq %class.aqua.std.Array.0.1byte.2* %62, null | |
br i1 %63, label %72, label %64 | |
; <label>:%64 | |
%65 = load i32* %idx | |
%66 = add i32 %65, 1 | |
store i32 %66, i32* %idx | |
%67 = call i8 @ig.class.aqua.std.Array.0.1byte.2.indexer.1978133948(%class.aqua.std.Array.0.1byte.2* %62, i32 %65) | |
%68 = and i8 %67, 63 | |
%69 = zext i8 %68 to i32 | |
%70 = or i32 %61, %69 | |
store i32 %70, i32* %cp | |
br label %45 | |
; <label>:%71 | |
ret i32 0 | |
; <label>:%72 | |
%73 = phi i8* [ getelementptr inbounds ([4 x i8]* @.str0, i32 0, i32 0), %0 ], [ getelementptr inbounds ([4 x i8]* @.str1, i32 0, i32 0), %13 ], [ getelementptr inbounds ([4 x i8]* @.str2, i32 0, i32 0), %49 ], [ getelementptr inbounds ([4 x i8]* @.str3, i32 0, i32 0), %60 ] | |
call void @aqua_throw_null_ptr_ex(i8* %73) | |
unreachable | |
; <label>:%74 | |
} | |
define internal void @class.Program.main.0(i8* %this) { | |
%1 = alloca i32 | |
%2 = alloca i32 | |
store i32 0, i32* %1 | |
store i32 0, i32* %2 | |
%3 = call i32 @class.Program.getch.577725869(i8* undef, %class.aqua.std.Array.0.1byte.2* null, i32* %1, i32* %2) | |
ret void | |
; <label>:%4 | |
} | |
define i32 @main(i32 %argc, i8** %argv) { | |
call void @aqua_init(i32 %argc, i8** %argv) | |
call void @class.Program.main.0(i8* undef) | |
ret i32 0 | |
; <label>:%1 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment