-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.fs
More file actions
90 lines (70 loc) · 3.56 KB
/
Copy pathMain.fs
File metadata and controls
90 lines (70 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
namespace Ufrgs.Inf.ArchSims.CmdLine
open System
open System.IO
open Ufrgs.Inf.ArchSims.CmdLine.Common
module Main =
[<EntryPoint>]
let Main args =
try
let pArgs = args |> ParseArguments
let exeName = Path.GetFileNameWithoutExtension(Environment.GetCommandLineArgs().[0])
let cpuFromExe = DecodeCpuType (exeName)
let showHelp = pArgs ? ("h")
let sourceArgument = pArgs ? ("")
if showHelp.IsSome || sourceArgument.IsNone then
printfn "Usage: %s <source> %s" exeName (if cpuFromExe.IsNone then "-Cpu <cpu> " else "")
printfn " [ -Run [-Mode <mode>] [-Output <output>] [-Speed <speed>] ]"
printfn " [ -Save <target> ]"
printfn ""
printfn " <source> Source file name (.txt) (required)"
if cpuFromExe.IsNone then
printfn " <cpu> Neander, Ahmes, Ramses, Cesar (required)"
printfn ""
printfn " -Run Run program (default)"
printfn " <mode> LastStep, AllSteps, Interactive (default: Interactive)"
printfn " <output> Binary, Decimal, Hexadecimal (default: Decimal)"
printfn " <speed> instructions per second (default: 10, only for Interactive)"
printfn ""
printfn " -Save Save memory to file"
printfn " <target> Target file name (.mem) (required)"
exit 1
let sourceFileName = Seq.head sourceArgument.Value
let cpuFromArgs = match pArgs ? cpu with
| Some c -> DecodeCpuType (Seq.head c)
| None -> None
let cpuType = match cpuFromExe with
| Some c -> Some c
| None -> cpuFromArgs
let runOptions = {
SourceFileName = sourceFileName
ExecutionMode = match pArgs ? mode with
| Some m -> DecodeExecutionMode (Seq.head m)
| None -> ExecutionMode.Interactive
OutputFormat = match pArgs ? output with
| Some f -> DecodeOutputFormat (Seq.head f)
| None -> OutputFormat.Decimal
Speed = match pArgs ? speed with
| Some s -> Some (Int32.Parse (Seq.head s))
| None -> None
}
let saveOptions targetFileName = {
SourceFileName = sourceFileName;
TargetFileName = targetFileName
}
let action = match pArgs ? save with
| Some file -> Save (saveOptions (Seq.head file))
| None -> Run runOptions
match cpuType with
| Some CpuType.Neander -> failwith "Not implemented: Neander"
| Some CpuType.Ahmes -> failwith "Not implemented: Ahmes"
| Some CpuType.Ramses -> RamsesCmdLine.Execute action
| Some CpuType.Cesar -> CesarCmdLine.Execute action
| None -> failwith "You must inform a -Cpu option."
exit 0
with
| Failure message ->
printfn "Error: %s" message
exit 1
| :? System.IO.FileNotFoundException as ex ->
printfn "File not found: %s" ex.FileName
exit 1