-
Notifications
You must be signed in to change notification settings - Fork 1
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
Format improvements (WIP) #63
base: main
Are you sure you want to change the base?
Changes from 2 commits
2ed6200
a8b2ad4
e66c92d
f3de737
b1eae57
96c1d4c
7fe31f4
4d089ac
9605ae3
5ff6724
b3e8508
b70b2ed
17ce209
92292d5
3d32e3b
88e5a47
26f14dc
6e5e625
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,19 +224,34 @@ fn decode_args_with_abi( | |
|
||
let reg_style = hooks.register_style(); | ||
for (arg_index, enc) in siggy.arg_encodings().enumerate() { | ||
// Padding produces values for the sake of verifying the bytes are 0. TODO: Implement! | ||
// They're filtered out later on after dealing with @arg0 in the argument-raising pass. | ||
if let ArgEncoding::Padding { size } = enc { | ||
decrease_len(emitter, &mut remaining_len, *size as usize)?; | ||
let raw_value = match size { | ||
1 => args_blob.read_u8().expect("already checked len") as i32, | ||
4 => args_blob.read_u32().expect("already checked len") as i32, | ||
_ => unreachable!(), | ||
}; | ||
args.push(SimpleArg { value: ScalarValue::Int(raw_value), is_reg: false } ); | ||
continue; | ||
} | ||
let ref emitter = add_argument_context(emitter, arg_index); | ||
|
||
// TODO: Add a way to fallback to @mask for | ||
// "bad" mask bits to allow roundtripping | ||
let can_be_param = if enc.contributes_to_param_mask() { | ||
let value = !enc.is_immediate() && param_mask & 1 == 1; | ||
let value = !enc.is_always_immediate() && param_mask & 1 == 1; | ||
param_mask >>= 1; | ||
value | ||
} else { | ||
false | ||
}; | ||
|
||
let value = match *enc { | ||
| ArgEncoding::Padding { .. } | ||
=> unreachable!(), | ||
|
||
| ArgEncoding::Integer { arg0: true, .. } | ||
=> { | ||
// a check that non-timeline languages don't have timeline args in their signature | ||
|
@@ -250,7 +265,7 @@ fn decode_args_with_abi( | |
| ArgEncoding::Integer { arg0: false, size: 4, format: ast::IntFormat { unsigned: false, radix: _ }, .. } | ||
=> { | ||
decrease_len(emitter, &mut remaining_len, 4)?; | ||
ScalarValue::Int(args_blob.read_i32().expect("already checked len") as i32) | ||
ScalarValue::Int(args_blob.read_i32().expect("already checked len")) | ||
}, | ||
|
||
| ArgEncoding::Integer { arg0: false, size: 2, format: ast::IntFormat { unsigned: false, radix: _ }, .. } | ||
|
@@ -277,7 +292,6 @@ fn decode_args_with_abi( | |
ScalarValue::Int(args_blob.read_u16().expect("already checked len") as i32) | ||
}, | ||
|
||
| ArgEncoding::Padding | ||
| ArgEncoding::Integer { arg0: false, size: 1, format: ast::IntFormat { unsigned: true, radix: _ }, .. } | ||
=> { | ||
decrease_len(emitter, &mut remaining_len, 1)?; | ||
|
@@ -556,7 +570,7 @@ impl AtomRaiser<'_, '_> { | |
// | ||
// IMPORTANT: this is looking at the original arg list because the new lengths may differ due to arg0. | ||
let mut arg_iter = abi.arg_encodings(); | ||
raised_args.retain(|_| !matches!(arg_iter.next().unwrap(), ArgEncoding::Padding)); | ||
raised_args.retain(|_| !matches!(arg_iter.next().unwrap(), ArgEncoding::Padding { .. })); | ||
|
||
Ok(RaisedIntrinsicParts { | ||
opcode: Some(instr.opcode), | ||
|
@@ -665,7 +679,7 @@ impl AtomRaiser<'_, '_> { | |
| ArgEncoding::Integer { ty_color: None, format, .. } | ||
=> Ok(ast::Expr::LitInt { value: raw.expect_int(), format: *format }), | ||
|
||
| ArgEncoding::Padding | ||
| ArgEncoding::Padding { .. } | ||
=> Ok(ast::Expr::from(raw.expect_int())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this is unreachable now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's definitely not unreachable since the padding args are only dropped after being raised thanks to some sort of logic with |
||
|
||
| ArgEncoding::Integer { ty_color: Some(ty_color), format, .. } | ||
|
@@ -677,7 +691,7 @@ impl AtomRaiser<'_, '_> { | |
&lookup_table, | ||
raw.expect_int(), | ||
ty_color, | ||
format, | ||
*format, | ||
)) | ||
} | ||
|
||
|
@@ -750,7 +764,7 @@ impl AtomRaiser<'_, '_> { | |
} | ||
} | ||
|
||
fn raise_to_possibly_named_constant(names: &IdMap<i32, Sp<Ident>>, id: i32, ty_color: &TypeColor, format: &ast::IntFormat) -> ast::Expr { | ||
fn raise_to_possibly_named_constant(names: &IdMap<i32, Sp<Ident>>, id: i32, ty_color: &TypeColor, format: ast::IntFormat) -> ast::Expr { | ||
match names.get(&id) { | ||
Some(ident) => { | ||
match ty_color { | ||
|
@@ -762,7 +776,7 @@ fn raise_to_possibly_named_constant(names: &IdMap<i32, Sp<Ident>>, id: i32, ty_c | |
}, | ||
} | ||
}, | ||
None => ast::Expr::LitInt { value: id, format: *format }, | ||
None => ast::Expr::LitInt { value: id, format: format }, | ||
} | ||
} | ||
|
||
|
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.
Might prefer
signed
rather thanunsigned
to avoid double negativesThere 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.
I went with
unsigned
since it's more of an exception to the norm than anything. I tend to structure my bools withtrue
as the "do something different" value so that they don't need to be negated whenever being read, but I guess that doesn't matter as much withmatch
since you have to be explicit in both cases.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.
true
as "do something different" makes sense in C-likes where it's easy to zero-initialize things. It doesn't make so much sense in rust.