Skip to content

Commit 47181f7

Browse files
authored
Merge pull request #763 from Nadrieril/version
Add `charon version`
2 parents ab4076b + dab55c3 commit 47181f7

6 files changed

Lines changed: 20 additions & 24 deletions

File tree

charon/src/ast/types_utils.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -428,25 +428,6 @@ impl IntegerTy {
428428
!(self.is_signed())
429429
}
430430

431-
/// Return the size (in bytes) of an integer of the proper type
432-
pub fn size(&self) -> usize {
433-
use std::mem::size_of;
434-
match self {
435-
IntegerTy::Isize => size_of::<isize>(),
436-
IntegerTy::I8 => size_of::<i8>(),
437-
IntegerTy::I16 => size_of::<i16>(),
438-
IntegerTy::I32 => size_of::<i32>(),
439-
IntegerTy::I64 => size_of::<i64>(),
440-
IntegerTy::I128 => size_of::<i128>(),
441-
IntegerTy::Usize => size_of::<isize>(),
442-
IntegerTy::U8 => size_of::<u8>(),
443-
IntegerTy::U16 => size_of::<u16>(),
444-
IntegerTy::U32 => size_of::<u32>(),
445-
IntegerTy::U64 => size_of::<u64>(),
446-
IntegerTy::U128 => size_of::<u128>(),
447-
}
448-
}
449-
450431
pub fn to_unsigned(&self) -> Self {
451432
match self {
452433
IntegerTy::Isize => IntegerTy::Usize,

charon/src/bin/charon-driver/translate/translate_types.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,7 @@ impl<'tcx, 'ctx> ItemTransCtx<'tcx, 'ctx> {
485485
None
486486
} else {
487487
tcx.tag_for_variant(ty_env.as_query_input((ty, id)))
488-
.map(|s| {
489-
assert_eq!(s.size(), r_abi::Size::from_bytes(tag_ty.size()));
490-
ScalarValue::from_bits(tag_ty, s.to_bits(s.size()))
491-
})
488+
.map(|s| ScalarValue::from_bits(tag_ty, s.to_bits(s.size())))
492489
};
493490
variant_layouts.push(translate_variant_layout(variant_layout, tag));
494491
}

charon/src/bin/charon/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub enum Charon {
2424
ToolchainPath(ToolchainPathArgs),
2525
/// Pretty-print the given llbc file.
2626
PrettyPrint(PrettyPrintArgs),
27+
/// Print the version.
28+
Version,
2729
}
2830

2931
/// Read a llbc or ullbc file and pretty print it.

charon/src/bin/charon/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ pub fn main() -> Result<()> {
7979
println!("{}", path.display());
8080
ExitStatus::default()
8181
}
82+
Some(Charon::Version) => {
83+
println!("{}", charon_lib::VERSION);
84+
ExitStatus::default()
85+
}
8286
// Legacy calling syntax.
8387
None => {
8488
let options = cli.opts;

charon/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use pretty::formatter;
4444
pub use transform::{graphs, reorder_decls, ullbc_to_llbc};
4545

4646
/// The version of the crate, as defined in `Cargo.toml`.
47-
const VERSION: &str = env!("CARGO_PKG_VERSION");
47+
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
4848

4949
/// Read a `.llbc` file.
5050
pub fn deserialize_llbc(path: &std::path::Path) -> anyhow::Result<ast::TranslatedCrate> {

charon/tests/cli.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ fn charon_pretty_print() -> Result<()> {
4848
)
4949
}
5050

51+
#[test]
52+
fn charon_version() -> Result<()> {
53+
charon(&["version"], ".", |stdout, cmd| {
54+
let version = charon_lib::VERSION;
55+
ensure!(
56+
stdout.trim() == version,
57+
"Output of `{cmd}` is:\n{stdout:?}\nIt should be {version}."
58+
);
59+
Ok(())
60+
})
61+
}
62+
5163
#[test]
5264
fn charon_cargo_p_crate2() -> Result<()> {
5365
charon(

0 commit comments

Comments
 (0)