mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-28 21:47:57 +03:00
Also report unrecognized directives
This commit is contained in:
parent
848398ea15
commit
454ed3cc0d
1 changed files with 81 additions and 18 deletions
|
@ -9,7 +9,7 @@ use winnow::ascii::dec_uint;
|
||||||
use winnow::combinator::*;
|
use winnow::combinator::*;
|
||||||
use winnow::error::{ErrMode, ErrorKind};
|
use winnow::error::{ErrMode, ErrorKind};
|
||||||
use winnow::stream::Accumulate;
|
use winnow::stream::Accumulate;
|
||||||
use winnow::token::any;
|
use winnow::token::{any, take_till};
|
||||||
use winnow::{
|
use winnow::{
|
||||||
error::{ContextError, ParserError},
|
error::{ContextError, ParserError},
|
||||||
stream::{Offset, Stream, StreamIsPartial},
|
stream::{Offset, Stream, StreamIsPartial},
|
||||||
|
@ -398,13 +398,21 @@ fn shader_model<'a>(stream: &mut &str) -> PResult<(u32, Option<char>)> {
|
||||||
fn directive<'a, 'input>(
|
fn directive<'a, 'input>(
|
||||||
stream: &mut PtxParser<'a, 'input>,
|
stream: &mut PtxParser<'a, 'input>,
|
||||||
) -> PResult<Option<ast::Directive<'input, ast::ParsedOperand<&'input str>>>> {
|
) -> PResult<Option<ast::Directive<'input, ast::ParsedOperand<&'input str>>>> {
|
||||||
alt((
|
with_recovery(
|
||||||
function.map(|(linking, func)| Some(ast::Directive::Method(linking, func))),
|
alt((
|
||||||
file.map(|_| None),
|
function.map(|(linking, func)| Some(ast::Directive::Method(linking, func))),
|
||||||
section.map(|_| None),
|
file.map(|_| None),
|
||||||
(module_variable, Token::Semicolon)
|
section.map(|_| None),
|
||||||
.map(|((linking, var), _)| Some(ast::Directive::Variable(linking, var))),
|
(module_variable, Token::Semicolon)
|
||||||
))
|
.map(|((linking, var), _)| Some(ast::Directive::Variable(linking, var))),
|
||||||
|
)),
|
||||||
|
take_till(1.., |(token, _)| match token {
|
||||||
|
Token::DotVisible | Token::DotFile | Token::DotSection => true,
|
||||||
|
_ => false,
|
||||||
|
}),
|
||||||
|
PtxError::UnrecognizedDirective,
|
||||||
|
)
|
||||||
|
.map(Option::flatten)
|
||||||
.parse_next(stream)
|
.parse_next(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -649,12 +657,8 @@ fn statement<'a, 'input>(
|
||||||
Token::Semicolon | Token::Colon => true,
|
Token::Semicolon | Token::Colon => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
), /*
|
),
|
||||||
take_till(0.., |(t, _)| match t {
|
PtxError::UnrecognizedStatement,
|
||||||
Token::Semicolon | Token::Colon => true,
|
|
||||||
_ => false,
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
)
|
)
|
||||||
.map(Option::flatten)
|
.map(Option::flatten)
|
||||||
.parse_next(stream)
|
.parse_next(stream)
|
||||||
|
@ -702,9 +706,28 @@ fn take_till_inclusive<I: Stream, E: ParserError<I>>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
pub fn take_till_or_backtrack_eof<Set, Input, Error>(
|
||||||
|
set: Set,
|
||||||
|
) -> impl Parser<Input, <Input as Stream>::Slice, Error>
|
||||||
|
where
|
||||||
|
Input: StreamIsPartial + Stream,
|
||||||
|
Set: winnow::stream::ContainsToken<<Input as Stream>::Token>,
|
||||||
|
Error: ParserError<Input>,
|
||||||
|
{
|
||||||
|
move |stream: &mut Input| {
|
||||||
|
if stream.eof_offset() == 0 {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
take_till(0.., set)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
fn with_recovery<'a, 'input: 'a, T>(
|
fn with_recovery<'a, 'input: 'a, T>(
|
||||||
mut parser: impl Parser<PtxParser<'a, 'input>, T, ContextError>,
|
mut parser: impl Parser<PtxParser<'a, 'input>, T, ContextError>,
|
||||||
mut recovery: impl Parser<PtxParser<'a, 'input>, &'a [(Token<'input>, logos::Span)], ContextError>,
|
mut recovery: impl Parser<PtxParser<'a, 'input>, &'a [(Token<'input>, logos::Span)], ContextError>,
|
||||||
|
mut error: impl FnMut(Option<&'input str>) -> PtxError<'input>,
|
||||||
) -> impl Parser<PtxParser<'a, 'input>, Option<T>, ContextError> {
|
) -> impl Parser<PtxParser<'a, 'input>, Option<T>, ContextError> {
|
||||||
move |stream: &mut PtxParser<'a, 'input>| {
|
move |stream: &mut PtxParser<'a, 'input>| {
|
||||||
let input_start = stream.input.first().map(|(_, s)| s).cloned();
|
let input_start = stream.input.first().map(|(_, s)| s).cloned();
|
||||||
|
@ -722,10 +745,7 @@ fn with_recovery<'a, 'input: 'a, T>(
|
||||||
// recover from unknown instructions, so we don't care about early end of stream
|
// recover from unknown instructions, so we don't care about early end of stream
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
stream
|
stream.state.errors.push(error(range));
|
||||||
.state
|
|
||||||
.errors
|
|
||||||
.push(PtxError::UnrecognizedStatement(range));
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
|
@ -1250,6 +1270,8 @@ pub enum PtxError<'input> {
|
||||||
NonExternPointer,
|
NonExternPointer,
|
||||||
#[error("{0:?}")]
|
#[error("{0:?}")]
|
||||||
UnrecognizedStatement(Option<&'input str>),
|
UnrecognizedStatement(Option<&'input str>),
|
||||||
|
#[error("{0:?}")]
|
||||||
|
UnrecognizedDirective(Option<&'input str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -3420,4 +3442,45 @@ mod tests {
|
||||||
PtxError::UnrecognizedStatement(Some("unknown_op2 temp2, temp;"))
|
PtxError::UnrecognizedStatement(Some("unknown_op2 temp2, temp;"))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn report_unknown_directive() {
|
||||||
|
let text = "
|
||||||
|
.version 6.5
|
||||||
|
.target sm_30
|
||||||
|
.address_size 64
|
||||||
|
|
||||||
|
.broken_directive_fail; 34; {
|
||||||
|
|
||||||
|
.visible .entry add(
|
||||||
|
.param .u64 input,
|
||||||
|
.param .u64 output
|
||||||
|
)
|
||||||
|
{
|
||||||
|
.reg .u64 in_addr;
|
||||||
|
.reg .u64 out_addr;
|
||||||
|
.reg .u64 temp;
|
||||||
|
.reg .u64 temp2;
|
||||||
|
|
||||||
|
ld.param.u64 in_addr, [input];
|
||||||
|
ld.param.u64 out_addr, [output];
|
||||||
|
|
||||||
|
ld.u64 temp, [in_addr];
|
||||||
|
add.u64 temp2, temp, 1;
|
||||||
|
st.u64 [out_addr], temp2;
|
||||||
|
ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
section foobar }";
|
||||||
|
let errors = parse_module_checked(text).err().unwrap();
|
||||||
|
assert_eq!(errors.len(), 2);
|
||||||
|
assert!(matches!(
|
||||||
|
errors[0],
|
||||||
|
PtxError::UnrecognizedDirective(Some(".broken_directive_fail; 34; {"))
|
||||||
|
));
|
||||||
|
assert!(matches!(
|
||||||
|
errors[1],
|
||||||
|
PtxError::UnrecognizedDirective(Some("section foobar }"))
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue