11use anstream:: StripStream ;
2+ use lowerer:: lower;
23use std:: {
34 env:: args,
45 error:: Error ,
@@ -12,6 +13,8 @@ use unicode_width::UnicodeWidthStr;
1213use crate :: cli:: { Command , DebugSubcommand , parse_args, print_help} ;
1314use common:: source:: Source ;
1415use diag:: { DiagPrinter , DiagSink } ;
16+ // use hir::*;
17+ // use ast2hir::lower_ast;
1518use lexer:: { lex, parse_token_tree} ;
1619use locale:: tr;
1720use parser:: parse;
@@ -124,6 +127,31 @@ impl Driver {
124127 Ok ( ( ) )
125128 }
126129
130+ fn hir ( & mut self , args : DebugSubcommand ) -> Result < ( ) , Box < dyn Error > > {
131+ let DebugSubcommand {
132+ file,
133+ output,
134+ show_recovery,
135+ } = args;
136+
137+ let mut sink = DiagSink :: default ( ) ;
138+ let src = self . load ( file) ?;
139+
140+ let tokens = lex ( & src, & mut sink) ;
141+ let ts = parse_token_tree ( & tokens, & mut sink) ;
142+ let ast = parse ( & ts, & mut sink) ;
143+ let hir = lower ( & ast, & mut sink) ;
144+
145+ let printer = DiagPrinter :: new ( & src) ;
146+ printer. print ( sink, show_recovery) ?;
147+
148+ let output = output. unwrap_or_else ( || format ! ( "{}.out" , src. file) ) ;
149+ let out = get_out ! ( Some ( output) ) ;
150+ write ! ( out, "{hir:#?}" ) ?;
151+
152+ Ok ( ( ) )
153+ }
154+
127155 fn drive ( mut self ) -> Result < ( ) , Box < dyn Error > > {
128156 use Command :: * ;
129157
@@ -137,6 +165,7 @@ impl Driver {
137165 Lex ( args) => self . lex ( args) ?,
138166 Tt ( args) => self . tt ( args) ?,
139167 Parse ( args) => self . parse ( args) ?,
168+ Hir ( args) => self . hir ( args) ?,
140169 }
141170
142171 Ok ( ( ) )
0 commit comments