1signature arm_parserLib = 2sig 3 4 datatype arm_code 5 = Ascii of string 6 | Byte of Abbrev.term list 7 | Short of Abbrev.term list 8 | Word of Abbrev.term list 9 | Instruction of Abbrev.term * Abbrev.term * Abbrev.term 10 11 val expr : int -> string 12 val calc_itstate : string * string -> int 13 14(*val arm_lex_from_file : string -> Substring.substring list *) 15 16 val arm_parse_from_file : string -> (Arbnum.num * arm_code) list * 17 (string, Arbnum.num) Redblackmap.dict 18 19 val arm_parse_from_string : string -> (Arbnum.num * arm_code) list * 20 (string, Arbnum.num) Redblackmap.dict 21 22 val arm_parse_from_quote : string frag list -> 23 (Arbnum.num * arm_code) list * 24 (string, Arbnum.num) Redblackmap.dict 25 26(* .......................................................................... 27 28 Comments are: 29 30 /* ... */ 31 (* ... *) 32 @ ... 33 ; ... 34 // ... 35 36 Source lines are: 37 38 {label:} {instruction | directive} 39 40 where 41 42 - a label is [a-zA-Z._][a-zA-Z0-9._]* 43 44 - an instruction is in ARM UAL (Unified Assembler Language) syntax 45 46 - the directives are 47 48 ARCH (ARMv4 | ARMv4T | ARMv5T | ARMv5TE | ARMv6 | ARMv6K | ARMv6T2 49 ARMv7 | ARMv7-A | ARMv7-M | ARMv7-R) 50 51 THUMB 52 CODE16 53 CODE 16 54 55 ARM 56 CODE32 57 CODE 32 58 59 ASCII <string> 60 BYTE <v1>{,<v2>,...} 61 SHORT <v1>{,<v2>,...} 62 WORD <v1>{,<v2>,...} 63 64 (values are excepted in standard bases e.g. 0b1100, 0xC, 014 and 12) 65 66 ALIGN (2 | 4 | 8) 67 68 SPACE <bytes> 69 70 71 72 Examples: 73 74 arm_parse_from_string "thumb\n add r1,r2" 75 76 arm_parse_from_quote 77 `// this is an example 78 ARCH ARMv6T2 79 THUMB @ enter thumb code (does an ALIGN 2 too) 80 81 label: add r1,r2 82 add.w r1,r8,r3 83 b.n +#4 ; branch to the next instruction 84 b -#8 /* branches to the labelled instruction 85 (assumes the first add is narrow) */ 86 87 ARM @ enter ARM code (does an ALIGN 4 too) 88 89 ASCII "a" 90 BYTE 0b1011 91 ALIGN 4 ; ensures next short is in the following word 92 SHORT 0xABCD (* no need for another ALIGN because 93 instructions are always aligned *) 94 blx label ; branch to thumb code 95 96 SPACE 40 ; skip 10 instructions 97 98 mov r1,#^(expr (~8 + 4 - 2)) 99 ; can use expr for int arith 100 ; will covert to mvn r1,#5 101 pop {r1-r6,pc}` 102 103 ......................................................................... *) 104 105end 106