aboutsummaryrefslogtreecommitdiffhomepage
path: root/ptx_parser
diff options
context:
space:
mode:
authorAndrzej Janik <[email protected]>2024-12-02 00:29:57 +0100
committerGitHub <[email protected]>2024-12-02 00:29:57 +0100
commit7a6df9dcbf59edef371e7f63c16c64916ddb0c0b (patch)
tree7800524ba25d38c514f1c769c9c1b665542c5500 /ptx_parser
parent870fed4bb69d919a10822032d65ec20f385df9d7 (diff)
downloadZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.tar.gz
ZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.zip
Fix host code and update to CUDA 12.4 (#299)
Diffstat (limited to 'ptx_parser')
-rw-r--r--ptx_parser/src/lib.rs55
1 files changed, 32 insertions, 23 deletions
diff --git a/ptx_parser/src/lib.rs b/ptx_parser/src/lib.rs
index 1ea2d71..f2c376d 100644
--- a/ptx_parser/src/lib.rs
+++ b/ptx_parser/src/lib.rs
@@ -284,20 +284,40 @@ fn immediate_value<'a, 'input>(stream: &mut PtxParser<'a, 'input>) -> PResult<as
.parse_next(stream)
}
-pub fn parse_module_unchecked<'input>(text: &'input str) -> Option<ast::Module<'input>> {
- let input = lex_with_span(text).ok()?;
- let mut errors = Vec::new();
- let state = PtxParserState::new(text, &mut errors);
- let parser = PtxParser {
- state,
- input: &input[..],
+pub fn parse_for_errors<'input>(text: &'input str) -> Vec<PtxError> {
+ let (tokens, mut errors) = lex_with_span_unchecked(text);
+ let parse_result = {
+ let state = PtxParserState::new(text, &mut errors);
+ let parser = PtxParser {
+ state,
+ input: &tokens[..],
+ };
+ module
+ .parse(parser)
+ .map_err(|err| PtxError::Parser(err.into_inner()))
};
- let parsing_result = module.parse(parser).ok();
- if !errors.is_empty() {
- None
- } else {
- parsing_result
+ match parse_result {
+ Ok(_) => {}
+ Err(err) => {
+ errors.push(err);
+ }
}
+ errors
+}
+
+fn lex_with_span_unchecked<'input>(
+ text: &'input str,
+) -> (Vec<(Token<'input>, logos::Span)>, Vec<PtxError>) {
+ let lexer = Token::lexer(text);
+ let mut result = Vec::new();
+ let mut errors = Vec::new();
+ for (token, span) in lexer.spanned() {
+ match token {
+ Ok(t) => result.push((t, span)),
+ Err(err) => errors.push(PtxError::Lexer { source: err }),
+ }
+ }
+ (result, errors)
}
pub fn parse_module_checked<'input>(
@@ -342,17 +362,6 @@ pub fn parse_module_checked<'input>(
}
}
-fn lex_with_span<'input>(
- text: &'input str,
-) -> Result<Vec<(Token<'input>, logos::Span)>, TokenError> {
- let lexer = Token::lexer(text);
- let mut result = Vec::new();
- for (token, span) in lexer.spanned() {
- result.push((token?, span));
- }
- Ok(result)
-}
-
fn module<'a, 'input>(stream: &mut PtxParser<'a, 'input>) -> PResult<ast::Module<'input>> {
(
version,