-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #803 from nojb/make_opcodes_in_ml
ocaml tool to extract opcode information
- Loading branch information
Showing
8 changed files
with
75 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
(***********************************************************************) | ||
(* *) | ||
(* OCaml *) | ||
(* *) | ||
(* Nicolas Ojeda Bar, LexiFi *) | ||
(* *) | ||
(* Copyright 2016 Institut National de Recherche en Informatique et *) | ||
(* en Automatique. All rights reserved. This file is distributed *) | ||
(* under the terms of the Q Public License version 1.0. *) | ||
(* *) | ||
(***********************************************************************) | ||
|
||
let ident = ['a'-'z''A'-'Z''_']['a'-'z''A'-'Z''0'-'9''_']* | ||
let space = [' ''\n''\t']* | ||
|
||
rule find_enum = parse | ||
| "enum" space (ident as id) space '{' { id, opnames lexbuf } | ||
| _ { find_enum lexbuf } | ||
|
||
and opnames = parse | ||
| space (ident as op) space ',' { op :: opnames lexbuf } | ||
| space ident space '}' { [] } | ||
|
||
{ | ||
let print_opnames = ref false | ||
let print_opcodes = ref false | ||
|
||
open Printf | ||
|
||
let () = | ||
let spec = | ||
[ | ||
"-opnames", Arg.Set print_opnames, " Dump opcode names"; | ||
"-opcodes", Arg.Set print_opcodes, " Dump opcode numbers"; | ||
] | ||
in | ||
Arg.parse (Arg.align spec) ignore "Extract opcode info from instruct.h"; | ||
let lexbuf = Lexing.from_channel stdin in | ||
let id, opnames = find_enum lexbuf in | ||
if !print_opnames then begin | ||
printf "let names_of_%s = [|\n" id; | ||
List.iter (fun s -> printf " %S;\n" s) opnames; | ||
printf "|]\n" | ||
end; | ||
if !print_opcodes then | ||
List.iteri (fun i op -> printf "let op%s = %i\n" op i) opnames | ||
} |