Files
ManDude cd68cb671e deftype and defmethod syntax major changes (#3094)
Major change to how `deftype` shows up in our code:
- the decompiler will no longer emit the `offset-assert`,
`method-count-assert`, `size-assert` and `flag-assert` parameters. There
are extremely few cases where having this in the decompiled code is
helpful, as the types there come from `all-types` which already has
those parameters. This also doesn't break type consistency because:
  - the asserts aren't compared.
- the first step of the test uses `all-types`, which has the asserts,
which will throw an error if they're bad.
- the decompiler won't emit the `heap-base` parameter unless necessary
now.
- the decompiler will try its hardest to turn a fixed-offset field into
an `overlay-at` field. It falls back to the old offset if all else
fails.
- `overlay-at` now supports field "dereferencing" to specify the offset
that's within a field that's a structure, e.g.:
```lisp
(deftype foobar (structure)
  ((vec    vector  :inline)
   (flags  int32   :overlay-at (-> vec w))
   )
  )
```
in this structure, the offset of `flags` will be 12 because that is the
final offset of `vec`'s `w` field within this structure.
- **removed ID from all method declarations.** IDs are only ever
automatically assigned now. Fixes #3068.
- added an `:overlay` parameter to method declarations, in order to
declare a new method that goes on top of a previously-defined method.
Syntax is `:overlay <method-name>`. Please do not ever use this.
- added `state-methods` list parameter. This lets you quickly specify a
list of states to be put in the method table. Same syntax as the
`states` list parameter. The decompiler will try to put as many states
in this as it can without messing with the method ID order.

Also changes `defmethod` to make the first type definition (before the
arguments) optional. The type can now be inferred from the first
argument. Fixes #3093.

---------

Co-authored-by: Hat Kid <6624576+Hat-Kid@users.noreply.github.com>
2023-10-30 03:20:02 +00:00

128 lines
2.7 KiB
Common Lisp

;;-*-Lisp-*-
(in-package goal)
;; name: stats-h.gc
;; name in dgo: stats-h
;; dgos: GAME, ENGINE
;; DECOMP BEGINS
(deftype tr-stat (structure)
((groups uint16)
(fragments uint16)
(tris uint32)
(dverts uint32)
(instances uint16)
(pad uint16)
)
)
(deftype merc-global-stats (structure)
((merc tr-stat :inline)
(mercneric tr-stat :inline)
)
)
(deftype perf-stat (structure)
((frame-number uint32)
(count uint32)
(cycles uint32)
(instructions uint32)
(icache uint32)
(dcache uint32)
(select uint32)
(ctrl uint32)
(accum0 uint32)
(accum1 uint32)
(to-vu0-waits uint32)
(to-spr-waits uint32)
(from-spr-waits uint32)
)
:pack-me
(:methods
(perf-stat-method-9 (_type_) none)
(print-to-stream (_type_ string basic) none)
(reset! (_type_) none)
(read! (_type_) none)
(update-wait-stats (_type_ uint uint uint) none)
)
)
(deftype perf-stat-array (inline-array-class)
((data perf-stat :inline :dynamic)
)
)
(set! (-> perf-stat-array heap-base) (the-as uint 52))
(define *pc-perf-stat-counter* (the-as uint 0))
(defmethod reset! ((this perf-stat))
"Perfomance counters are partially implemented, they just count cycles."
(+! (-> this count) 1)
(when (nonzero? (-> this ctrl))
(set! *pc-perf-stat-counter* (get-cpu-clock))
)
#|
(let ((v1-0 (-> this ctrl)))
(+! (-> this count) 1)
(b! (zero? v1-0) cfg-2 :delay (nop!))
(.mtc0 Perf 0)
(.sync.l)
(.sync.p)
(.mtpc pcr0 0)
(.mtpc pcr1 0)
(.sync.l)
(.sync.p)
(.mtc0 Perf v1-0)
)
(.sync.l)
(.sync.p)
(label cfg-2)
|#
0
(none)
)
(defmethod read! ((this perf-stat))
"Perfomance counters are partially implemented, they just count cycles."
(when (nonzero? (-> this ctrl))
(+! (-> this accum0) (- (get-cpu-clock) *pc-perf-stat-counter*))
(set! (-> this accum1) 0)
)
#|
(local-vars (v1-1 int) (v1-3 int))
(b! (zero? (-> this ctrl)) cfg-2 :delay (nop!))
(.mtc0 Perf 0)
(.sync.l)
(.sync.p)
(.mfpc v1-1 pcr0)
(+! (-> this accum0) v1-1)
(.mfpc v1-3 pcr1)
(+! (-> this accum1) v1-3)
(label cfg-2)
|#
0
(none)
)
(defmethod update-wait-stats ((this perf-stat) (arg0 uint) (arg1 uint) (arg2 uint))
(when (nonzero? (-> this ctrl))
(+! (-> this to-vu0-waits) arg0)
(+! (-> this to-spr-waits) arg1)
(+! (-> this from-spr-waits) arg2)
)
0
(none)
)
(when (not *debug-segment*)
(set! (-> perf-stat method-table 11) nothing)
(set! (-> perf-stat method-table 12) nothing)
(set! (-> perf-stat method-table 13) nothing)
)