-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//! LEB1128 encoding. Reference: https://en.wikipedia.org/wiki/LEB128 | ||
|
||
#[no_mangle] | ||
unsafe extern "C" fn leb128_encode(mut val: u32, mut buf: *mut u8) { | ||
loop { | ||
let byte = (val & 0b0111_1111) as u8; | ||
val >>= 7; | ||
if val == 0 { | ||
*buf = byte; | ||
break; | ||
} else { | ||
*buf = byte | 0b1000_0000; | ||
buf = buf.add(1); | ||
} | ||
} | ||
} | ||
|
||
#[no_mangle] | ||
unsafe extern "C" fn sleb128_encode(mut val: i32, mut buf: *mut u8) { | ||
loop { | ||
let byte = (val & 0b0111_1111) as u8; | ||
val >>= 7; | ||
if (val == 0 && byte & 0b0100_0000 == 0) || (val == -1 && byte & 0b0100_0000 == 0b0100_0000) | ||
{ | ||
*buf = byte; | ||
break; | ||
} else { | ||
*buf = byte | 0b1000_0000; | ||
buf = buf.add(1); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ mod buf; | |
mod char; | ||
pub mod closure_table; | ||
mod debug; | ||
mod leb128; | ||
mod mem; | ||
mod text; | ||
mod text_iter; | ||
|
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