Partial continuations are RTL stubs
[bpt/guile.git] / module / language / rtl.scm
CommitLineData
43f768f4
AW
1;;; Register Transfer Language (RTL)
2
3;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5;;;; This library is free software; you can redistribute it and/or
6;;;; modify it under the terms of the GNU Lesser General Public
7;;;; License as published by the Free Software Foundation; either
8;;;; version 3 of the License, or (at your option) any later version.
9;;;;
10;;;; This library is distributed in the hope that it will be useful,
11;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13;;;; Lesser General Public License for more details.
14;;;;
15;;;; You should have received a copy of the GNU Lesser General Public
16;;;; License along with this library; if not, write to the Free Software
17;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19;;; Code:
20
21(define-module (language rtl)
22 #:use-module (ice-9 match)
23 #:use-module ((srfi srfi-1) #:select (fold))
24 #:use-module (system vm instruction)
25 #:re-export (rtl-instruction-list)
26 #:export (rtl-instruction-arity))
27
28(define (compute-rtl-instruction-arity name args)
29 (define (first-word-arity word)
30 (case word
31 ((U8_X24) 0)
32 ((U8_U24) 1)
33 ((U8_L24) 1)
34 ((U8_U8_I16) 2)
35 ((U8_U12_U12) 2)
36 ((U8_U8_U8_U8) 3)))
37 (define (tail-word-arity word)
38 (case word
39 ((U8_U24) 2)
40 ((U8_L24) 2)
41 ((U8_U8_I16) 3)
42 ((U8_U12_U12) 3)
43 ((U8_U8_U8_U8) 4)
44 ((U32) 1)
45 ((I32) 1)
46 ((A32) 1)
47 ((B32) 0)
48 ((N32) 1)
49 ((S32) 1)
50 ((L32) 1)
51 ((LO32) 1)
52 ((X8_U24) 1)
53 ((X8_U12_U12) 2)
54 ((X8_L24) 1)
55 ((B1_X7_L24) 2)
56 ((B1_U7_L24) 3)
57 ((B1_X31) 1)
58 ((B1_X7_U24) 2)))
59 (match args
60 ((arg0 . args)
61 (fold (lambda (arg arity)
62 (+ (tail-word-arity arg) arity))
63 (first-word-arity arg0)
64 args))))
65
66(define *macro-instruction-arities*
67 '((cache-current-module! . (0 . 2))
68 (cached-toplevel-box . (1 . 3))
69 (cached-module-box . (1 . 4))))
70
71(define (compute-rtl-instruction-arities)
72 (let ((table (make-hash-table)))
73 (for-each
74 (match-lambda
75 ;; Put special cases here.
76 ((name op '! . args)
77 (hashq-set! table name
78 (cons 0 (compute-rtl-instruction-arity name args))))
79 ((name op '<- . args)
80 (hashq-set! table name
81 (cons 1 (1- (compute-rtl-instruction-arity name args))))))
82 (rtl-instruction-list))
83 (for-each (match-lambda
84 ((name . arity)
85 (hashq-set! table name arity)))
86 *macro-instruction-arities*)
87 table))
88
89(define *rtl-instruction-arities* (delay (compute-rtl-instruction-arities)))
90
91(define (rtl-instruction-arity name)
92 (hashq-ref (force *rtl-instruction-arities*) name))