[decompiler] fix (gpr->fpr when an integer arg is converted to float (#482)

* fix gpr fpr bug

* remove unused variable
This commit is contained in:
water111
2021-05-14 14:33:08 -04:00
committed by GitHub
parent 60c670df3a
commit b3eb05e37f
12 changed files with 95 additions and 42 deletions
@@ -97,9 +97,6 @@
'(none)
)
(defmacro gpr->fpr (in)
in)
(define-extern get-current-time (function uint))
(define-extern get-integral-current-time (function uint))
@@ -119,18 +119,14 @@
;; definition for method 10 of type font-context
(defmethod set-origin! font-context ((obj font-context) (x int) (y int))
(let ((x (gpr->fpr x)))
(set! (-> obj origin x) (the float x))
)
(set! (-> obj origin x) (the float x))
(set! (-> obj origin y) (the float y))
obj
)
;; definition for method 11 of type font-context
(defmethod set-depth! font-context ((obj font-context) (z int))
(let ((z (gpr->fpr z)))
(set! (-> obj origin z) (the float z))
)
(set! (-> obj origin z) (the float z))
obj
)
@@ -142,17 +138,13 @@
;; definition for method 13 of type font-context
(defmethod set-width! font-context ((obj font-context) (width int))
(let ((width (gpr->fpr width)))
(set! (-> obj width) (the float width))
)
(set! (-> obj width) (the float width))
obj
)
;; definition for method 14 of type font-context
(defmethod set-height! font-context ((obj font-context) (height int))
(let ((height (gpr->fpr height)))
(set! (-> obj height) (the float height))
)
(set! (-> obj height) (the float height))
obj
)
@@ -1159,15 +1159,9 @@
;; definition for function draw-context-set-xy
;; INFO: Return type mismatch int vs none.
(defun draw-context-set-xy ((ctxt draw-context) (x int) (y int))
(let* ((y (gpr->fpr y))
(v0-0 (the int (* (the float y) (-> *video-parms* relative-y-scale))))
)
(let ((v0-0 (the int (* (the float y) (-> *video-parms* relative-y-scale)))))
(set! (-> ctxt orgx) x)
(set! (-> ctxt orgy) v0-0)
)
(none)
)
@@ -46,9 +46,7 @@
;; definition for function log2
(defun log2 ((arg0 int))
(let ((arg0 (gpr->fpr arg0)))
(+ (sar (the-as int (the float arg0)) 23) -127)
)
(+ (sar (the-as int (the float arg0)) 23) -127)
)
;; definition for function seek
@@ -226,4 +224,3 @@
;; failed to figure out what this is:
(let ((v0-6 0))
)
@@ -180,8 +180,7 @@
(defun
analog-input
((in int) (offset float) (center-val float) (max-val float) (out-range float))
(let* ((in (gpr->fpr in))
(offset-in (- (the float in) offset))
(let* ((offset-in (- (the float in) offset))
(magnitude (- (fabs offset-in) center-val))
(max-magnitude (- max-val center-val))
)
@@ -367,7 +366,3 @@
;; failed to figure out what this is:
(let ((v0-4 0))
)
@@ -1135,3 +1135,22 @@ TEST_F(FormRegressionTest, StupidFloatMove) {
" )";
test_with_expr(func, type, expected);
}
// gpr->fpr not being propagated
TEST_F(FormRegressionTest, Method11FontContext) {
std::string func =
"sll r0, r0, 0\n"
" mtc1 f0, a1\n"
" cvt.s.w f0, f0\n"
" swc1 f0, 20(a0)\n"
" or v0, a0, r0\n"
" jr ra\n"
" daddu sp, sp, r0";
std::string type = "(function font-context int font-context)";
std::string expected =
"(begin\n"
" (set! (-> arg0 origin z) (the float arg1))\n"
" arg0\n"
" )";
test_with_expr(func, type, expected);
}