-
Notifications
You must be signed in to change notification settings - Fork 59
Interpreter: Make function calls and basic instructions working #1753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 45 commits
bd7e162
79b3c0c
fc08a71
8930fc0
03fae32
5540797
cd3312f
97df887
844594f
644c565
e1b3b1d
36eb17f
7d5c065
329a953
b70ed18
038a88f
1e258ed
eb3f50d
46f173f
78f918b
c19ee8c
d03877e
2d8b8aa
b003955
605bba1
3a78ffd
19ddb56
22624ed
9119a7d
875c1a6
8eaaa86
1e740da
cf5f430
160255d
f3085d5
5a41037
c0e4e17
918f632
2e66e09
415c1f9
807209d
1a89883
bf24841
6d1a4b6
9e4854c
e7f854d
fbd247c
ceeb73b
9cfa91a
c2b44ab
7e76b30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import IR | ||
|
|
||
| /// The value of a `Builtin` type instance, stripped of type information. | ||
| struct UntypedBuiltinValue { | ||
|
||
|
|
||
| /// The result of reinterpretation as an unsigned integer value. | ||
| /// | ||
| /// Equivalent to `UInt128(unsafeBitCast<T>(x))`, where `x` is the represented value | ||
| /// and `T` is an unsigned integer of the same size as `x`. Stores the unsigned | ||
| /// representation of integer types. | ||
| private let asUInt128: UInt128 | ||
|
|
||
| /// The size of the value in bytes. | ||
| private let size: Int | ||
|
|
||
| /// Creates instance of builtin value with unsigned reinterpretation `v` and size `s`. | ||
| fileprivate init(asUInt128 v: UInt128, size s: Int) { | ||
| asUInt128 = v | ||
| size = s | ||
| } | ||
|
|
||
| /// Creates instance of builtin value with 8-bit integer. | ||
| static func i8(_ v: UInt8) -> Self { | ||
| Self(asUInt128: UInt128(v), size: 1) | ||
| } | ||
|
|
||
| /// Creates instance of builtin value with 16-bit integer. | ||
| public static func i16(_ v: UInt16) -> Self { | ||
| Self(asUInt128: UInt128(v), size: 2) | ||
| } | ||
|
|
||
| /// Creates instance of builtin value with 32-bit integer. | ||
| public static func i32(_ v: UInt32) -> Self { | ||
| Self(asUInt128: UInt128(v), size: 4) | ||
| } | ||
|
|
||
| /// Creates instance of builtin value with 64-bit integer. | ||
| public static func i64(_ v: UInt64) -> Self { | ||
| Self(asUInt128: UInt128(v), size: 8) | ||
| } | ||
|
|
||
| /// Creates instance of builtin value with 128-bit integer. | ||
| public static func i128(_ v: UInt128) -> Self { | ||
| Self(asUInt128: UInt128(v), size: 16) | ||
| } | ||
|
|
||
| /// Bool value, if present. | ||
| public var bool: Bool? { | ||
| if asUInt128 != 0 && asUInt128 != 1 { return nil } | ||
| return asUInt128 != 0 | ||
| } | ||
|
|
||
| /// 8-bit integer value, if present. | ||
| public var i8: UInt8? { size == 1 ? UInt8(truncatingIfNeeded: asUInt128) : nil } | ||
|
|
||
| /// 16-bit integer value, if present | ||
| public var i16: UInt16? { size == 2 ? UInt16(truncatingIfNeeded: asUInt128) : nil } | ||
|
|
||
| /// 32-bit integer value, if present | ||
| public var i32: UInt32? { size == 4 ? UInt32(truncatingIfNeeded: asUInt128) : nil } | ||
|
|
||
| /// 64-bit integer value, if present | ||
| public var i64: UInt64? { size == 8 ? UInt64(truncatingIfNeeded: asUInt128) : nil } | ||
|
|
||
| /// 128-bit integer value, if present | ||
| public var i128: UInt128? { size == 16 ? asUInt128 : nil } | ||
|
|
||
| } | ||
|
|
||
| /// Methods to create builtin value from IR constants. | ||
| extension UntypedBuiltinValue { | ||
|
|
||
| /// Creates instance of builtin value with integer constant `c`. | ||
| public init(withIntegerConstant c: IntegerConstant) { | ||
| self.init(asUInt128: UInt128(truncatingIfNeeded: c.value), size: (c.value.bitWidth + 7) / 8) | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nis not the bytes. However, you could: