about summary refs log tree commit diff
path: root/cmd/vm/main.go
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-08-22 23:55:57 +0000
committerMel <einebeere@gmail.com>2022-08-22 23:55:57 +0000
commit0b227d990f56b3ea059d13584ff9102ee5039a0b (patch)
tree738f99368cbfd47b02290f53f2876faaae4dbd75 /cmd/vm/main.go
parente22df631c4428f8dea4d5784a8a7840d2f84c6be (diff)
downloadjinx-0b227d990f56b3ea059d13584ff9102ee5039a0b.tar.zst
jinx-0b227d990f56b3ea059d13584ff9102ee5039a0b.zip
Add flag to generate PCs markers when decompiling
Diffstat (limited to 'cmd/vm/main.go')
-rw-r--r--cmd/vm/main.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/cmd/vm/main.go b/cmd/vm/main.go
index bb8f142..d58dae1 100644
--- a/cmd/vm/main.go
+++ b/cmd/vm/main.go
@@ -15,6 +15,7 @@ func main() {
 	// Take the first argument as the path to the file to be parsed.
 	compile := flag.String("c", "", "compile to file (if not bytecode)")
 	decompile := flag.String("d", "", "decompile bytecode to file")
+	generatePCs := flag.Bool("p", false, "if decompiling, generate PC information")
 	run := flag.Bool("r", false, "run")
 	bytecode := flag.Bool("b", false, "interpret bytecode, without this flag the program will be interpreted in Lang VM text format.")
 
@@ -36,6 +37,10 @@ func main() {
 		exit("nothing to do, either -c, -d or -r is required")
 	}
 
+	if *decompile == "" && *generatePCs {
+		exit("-p requires -d")
+	}
+
 	path := flag.Arg(0)
 	if path == "" {
 		exit("no file specified")
@@ -75,7 +80,7 @@ func main() {
 		bc = code.New(content, code.NewDebugInfo(path))
 
 		if *decompile != "" {
-			decomp := text.NewDecompiler(bc)
+			decomp := text.NewDecompiler(bc, *generatePCs)
 			result := decomp.Decompile()
 
 			output, err := os.Create(*decompile)