Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion backend/PrintAsmaux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ let print_inline_asm print_preg oc txt sg args res =
List.iter print_fragment (Str.full_split re_asm_param_1 txt);
fprintf oc "\n"

(** Print command-line argument, with quoting if needed.
We quote using double quotes if the argument contains whitespace,
control characters, or double quotes. *)

let re_unquoted = Str.regexp "[^ \x00-\x1F\"]*$"

let quote_argument s =
if Str.string_match re_unquoted s 0
then s
else "\"" ^ String.escaped s ^ "\""

(** Print CompCert version and command-line as asm comment *)

Expand All @@ -301,7 +311,7 @@ let print_version_and_options oc comment =
fprintf oc "%s File generated by CompCert %s\n" comment version_string;
fprintf oc "%s Command line:" comment;
for i = 1 to Array.length Commandline.argv - 1 do
fprintf oc " %s" Commandline.argv.(i)
fprintf oc " %s" (quote_argument Commandline.argv.(i))
done;
fprintf oc "\n"

Expand Down
Loading