@@ -15,7 +15,7 @@ use std::ffi::OsString;
15
15
16
16
#[ derive( Parser ) ]
17
17
#[ clap( name = "Cambridge Pseudoassembly Interpreter" ) ]
18
- #[ clap( version = env!( "CARGO_PKG_VERSION" ) ) ]
18
+ #[ clap( version = concat! ( env!( "CARGO_PKG_VERSION" ) , " \n " , "Library version 0.18.0 ") ) ]
19
19
#[ clap( author = "Saadi Save <github.com/SaadiSave>" ) ]
20
20
#[ clap( about = "Run pseudoassembly from Cambridge International syllabus 9618 (2021)" ) ]
21
21
enum Commands {
@@ -60,6 +60,10 @@ enum Commands {
60
60
/// Minify output
61
61
#[ clap( short = 'm' , long = "minify" ) ]
62
62
minify : bool ,
63
+
64
+ /// Include debuginfo
65
+ #[ clap( short, long) ]
66
+ debug : bool ,
63
67
} ,
64
68
}
65
69
@@ -80,7 +84,7 @@ enum OutFormats {
80
84
Bin ,
81
85
}
82
86
83
- fn main ( ) -> std :: io :: Result < ( ) > {
87
+ fn main ( ) -> anyhow :: Result < ( ) > {
84
88
#[ cfg( not( debug_assertions) ) ]
85
89
std:: panic:: set_hook ( Box :: new ( handle_panic) ) ;
86
90
@@ -101,7 +105,8 @@ fn main() -> std::io::Result<()> {
101
105
verbosity,
102
106
format,
103
107
minify,
104
- } => compile ( input, output, verbosity, format, minify) ?,
108
+ debug,
109
+ } => compile ( input, output, verbosity, format, minify, debug) ?,
105
110
}
106
111
107
112
Ok ( ( ) )
@@ -114,7 +119,7 @@ fn run(
114
119
bench : bool ,
115
120
format : InFormats ,
116
121
io : Io ,
117
- ) -> std :: io :: Result < ( ) > {
122
+ ) -> anyhow :: Result < ( ) > {
118
123
use InFormats :: * ;
119
124
120
125
init_logger ( verbosity) ;
@@ -124,19 +129,15 @@ fn run(
124
129
let mut timer = bench. then ( std:: time:: Instant :: now) ;
125
130
126
131
let mut executor = match format {
127
- Pasm => parse:: jit :: < DefaultSet , _ > ( String :: from_utf8_lossy ( & prog_bytes) , io) ,
128
- Json => serde_json:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) )
129
- . unwrap ( )
132
+ Pasm => parse:: jit :: < DefaultSet > ( String :: from_utf8_lossy ( & prog_bytes) , io) . unwrap ( ) ,
133
+ Json => serde_json:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) ) ?
130
134
. to_executor :: < DefaultSet > ( io) ,
131
- Ron => ron:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) )
132
- . unwrap ( )
135
+ Ron => ron:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) ) ?
133
136
. to_executor :: < DefaultSet > ( io) ,
134
- Yaml => serde_yaml:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) )
135
- . unwrap ( )
137
+ Yaml => serde_yaml:: from_str :: < CompiledProg > ( & String :: from_utf8_lossy ( & prog_bytes) ) ?
136
138
. to_executor :: < DefaultSet > ( io) ,
137
139
Bin => {
138
- bincode:: decode_from_slice :: < CompiledProg , _ > ( & prog_bytes, bincode:: config:: standard ( ) )
139
- . unwrap ( )
140
+ bincode:: decode_from_slice :: < CompiledProg , _ > ( & prog_bytes, bincode:: config:: standard ( ) ) ?
140
141
. 0
141
142
. to_executor :: < DefaultSet > ( io)
142
143
}
@@ -146,13 +147,16 @@ fn run(
146
147
println ! ( "Total parse time: {:?}" , t. elapsed( ) ) ;
147
148
std:: time:: Instant :: now ( )
148
149
} ) ;
150
+
149
151
if timer. is_some ( ) || verbosity > 0 {
150
152
println ! ( "Execution starts on next line" ) ;
151
153
}
152
154
153
155
executor. exec :: < DefaultSet > ( ) ;
154
156
155
- let _ = timer. map ( |t| println ! ( "Execution done\n Execution time: {:?}" , t. elapsed( ) ) ) ;
157
+ if let Some ( t) = timer {
158
+ println ! ( "Execution done\n Execution time: {:?}" , t. elapsed( ) ) ;
159
+ }
156
160
157
161
Ok ( ( ) )
158
162
}
@@ -164,14 +168,15 @@ fn compile(
164
168
verbosity : usize ,
165
169
format : OutFormats ,
166
170
minify : bool ,
171
+ debug : bool ,
167
172
) -> std:: io:: Result < ( ) > {
168
173
use OutFormats :: * ;
169
174
170
175
init_logger ( verbosity) ;
171
176
172
177
let prog = std:: fs:: read_to_string ( & input) ?;
173
178
174
- let compiled = compile:: compile :: < DefaultSet , _ > ( prog) ;
179
+ let compiled = compile:: compile :: < DefaultSet > ( prog, debug ) . unwrap ( ) ;
175
180
176
181
let output_path = output. unwrap_or_else ( || {
177
182
input. push ( match format {
0 commit comments