@@ -2,9 +2,17 @@ use base64::display::Base64Display;
22use base64:: engine:: general_purpose:: STANDARD ;
33use clap:: { Arg , ArgAction , Command } ;
44
5- use simplicityhl:: { AbiMeta , TemplateProgram , WarnCategory } ;
5+ use simplicityhl:: { get_line_col , AbiMeta , TemplateProgram , WarnCategory } ;
66use std:: { env, fmt} ;
77
8+ #[ cfg_attr( feature = "serde" , derive( serde:: Serialize ) ) ]
9+ struct OutputWarning {
10+ message : String ,
11+ file : String ,
12+ line : usize ,
13+ column : usize ,
14+ }
15+
816#[ cfg_attr( feature = "serde" , derive( serde:: Serialize ) ) ]
917/// The compilation output.
1018struct Output {
@@ -16,6 +24,8 @@ struct Output {
1624 abi_meta : Option < AbiMeta > ,
1725 /// Commitment Merkle Root (CMR) of the program, hex encoded.
1826 cmr : String ,
27+ /// Compiler warnings produced during compilation.
28+ warnings : Vec < OutputWarning > ,
1929}
2030
2131impl fmt:: Display for Output {
@@ -155,7 +165,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
155165 std:: process:: exit ( 1 ) ;
156166 } ) ;
157167
158- let template = match TemplateProgram :: new_with_path ( prog_text, prog_file. as_str ( ) ) {
168+ let template = match TemplateProgram :: new_with_path ( prog_text. clone ( ) , prog_file. as_str ( ) ) {
159169 Ok ( t) => t,
160170 Err ( e) => {
161171 eprintln ! ( "{}" , e) ;
@@ -176,17 +186,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
176186 } ) ;
177187
178188 let n_warnings = template. warnings ( ) . len ( ) ;
189+ let warning_strings: Vec < OutputWarning > = template
190+ . warnings ( )
191+ . iter ( )
192+ . map ( |w| {
193+ let ( line, column) = get_line_col ( & prog_text, w. span . start ) ;
194+ OutputWarning {
195+ message : w. canonical_name . to_string ( ) ,
196+ file : prog_file. clone ( ) ,
197+ line,
198+ column,
199+ }
200+ } )
201+ . collect ( ) ;
179202 if n_warnings > 0 {
180- eprint ! ( "{}" , template. format_warnings( prog_file) ) ;
181- let word = if n_warnings == 1 {
182- "warning"
183- } else {
184- "warnings"
185- } ;
186- eprintln ! (
187- "\x1b [1;33mwarning\x1b [0m: `{}` generated {} {}" ,
188- prog_file, n_warnings, word,
189- ) ;
203+ if !output_json {
204+ eprint ! ( "{}" , template. format_warnings( prog_file) ) ;
205+ let word = if n_warnings == 1 { "warning" } else { "warnings" } ;
206+ eprintln ! (
207+ "\x1b [1;33mwarning\x1b [0m: `{}` generated {} {}" ,
208+ prog_file, n_warnings, word,
209+ ) ;
210+ }
190211 if deny_warnings {
191212 eprintln ! ( "\x1b [1;31merror\x1b [0m: warnings treated as errors (--deny-warnings)" ) ;
192213 std:: process:: exit ( 1 ) ;
@@ -244,6 +265,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
244265 witness : witness_bytes. map ( |bytes| Base64Display :: new ( & bytes, & STANDARD ) . to_string ( ) ) ,
245266 abi_meta : abi_opt,
246267 cmr : cmr_hex,
268+ warnings : warning_strings,
247269 } ;
248270
249271 if output_json {
0 commit comments