From 5bb568e455b6d0c90a24bc73cfcce255caefd4cc Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Wed, 23 Dec 2020 14:38:38 +0100 Subject: [PATCH] mescc: Change --align to --align=functions, --align=globals. This makes function alignment optional and disables function alignment when using MesCC-Tools 0.5.2 (numbered architecture). * module/mescc.scm (parse-opts): Make --align take a value. * module/mescc/mescc.scm (mescc:compile, infos->hex2): Parse it and pass it as renamed #:align keyword argument to ... * module/mescc/M1.scm (infos->M1): ...here. Rename parameter align? to align, pass it to... (info->M1): ...here. Likewise. Use it to make function alignment optional. --- doc/mes.texi | 5 +++-- module/mescc.scm | 4 ++-- module/mescc/M1.scm | 19 ++++++++++++------- module/mescc/mescc.scm | 20 +++++++++++++++----- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/doc/mes.texi b/doc/mes.texi index a5306a99..8494df8f 100644 --- a/doc/mes.texi +++ b/doc/mes.texi @@ -876,8 +876,9 @@ The @var{option}s can be among the following: @table @code -@item --align -align globals +@item --align=@var{symbol} +align @var{symbol}, the default is @code{functions}; other valid values +are: @code{globals}. @item --base-address=ADRRESS use BaseAddress ADDRESS [0x1000000] diff --git a/module/mescc.scm b/module/mescc.scm index e74ce0ae..e2319a28 100644 --- a/module/mescc.scm +++ b/module/mescc.scm @@ -58,7 +58,7 @@ (define (parse-opts args) (let* ((option-spec - '((align) + '((align (value #t)) (arch (value #t)) (assemble (single-char #\c)) (base-address (value #t)) @@ -103,7 +103,7 @@ Usage: mescc [OPTION]... FILE... C99 compiler in Scheme for bootstrapping the GNU system. Options: - --align align globals + --align=SYMBOL align SYMBOL {functions,globals,none} [functions] --arch=ARCH compile for ARCH [~a] --kernel=ARCH compile for KERNEL [~a] -dumpmachine display the compiler's target machine diff --git a/module/mescc/M1.scm b/module/mescc/M1.scm index 766621e0..d7a9b1d6 100644 --- a/module/mescc/M1.scm +++ b/module/mescc/M1.scm @@ -35,9 +35,9 @@ infos->M1 M1:merge-infos)) -(define* (infos->M1 file-name infos #:key align? verbose?) +(define* (infos->M1 file-name infos #:key align verbose?) (let ((info (fold M1:merge-infos (make ) infos))) - (info->M1 file-name info #:align? align? #:verbose? verbose?))) + (info->M1 file-name info #:align align #:verbose? verbose?))) (define (M1:merge-infos o info) (clone info @@ -113,14 +113,16 @@ (define (global-extern? o) (and=> (global:storage o) (cut eq? <> 'extern))) -(define* (info->M1 file-name o #:key align? verbose?) +(define* (info->M1 file-name o #:key align verbose?) (let* ((functions (.functions o)) (function-names (map car functions)) (globals (.globals o)) (globals (filter (negate (compose global-extern? cdr)) globals)) (strings (filter global-string? globals)) (strings (map car strings)) - (reg-size (type:size (assoc-ref (.types o) "*")))) + (reg-size (type:size (assoc-ref (.types o) "*"))) + (align-functions? (memq 'functions align)) + (align-globals? (memq 'globals align))) (define (string->label o) (let ((index (list-index (lambda (s) (equal? s o)) strings))) (if index @@ -207,8 +209,11 @@ (newline)) (when verbose? (display (string-append " :" name "\n") (current-error-port))) - ;; "<" aligns to multiple of 4 Bytes. - (display (string-append "\n\n<\n:" name "\n")) + (display "\n\n") + (when align-functions? + ;; "<" aligns to multiple of 4 Bytes. + (display "<\n")) + (display (string-append ":" name "\n")) (for-each line->M1 (apply append text)))) (define (write-global o) (define (labelize o) @@ -223,7 +228,7 @@ (else (string-append "&" label)))))) (define (display-align size) (let ((alignment (- reg-size (modulo size reg-size)))) - (when (and align? (> reg-size alignment 0)) + (when (and align-globals? (> reg-size alignment 0)) (display " ") (display-join (map text->M1 (map (const 0) (iota alignment))) " ")) #t)) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 518e4b33..bb2bd6ae 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -79,11 +79,16 @@ (else (replace-suffix input-base ".s")))) (infos (map (cut file->info options <>) files)) (verbose? (count-opt options 'verbose)) - (align? (option-ref options 'align #f))) + (numbered-arch? (option-ref options 'numbered-arch? #f)) + (align (filter-map (multi-opt 'align) options)) + (align (if (null? align) '(functions) (map string->symbol align))) + (align (if (not numbered-arch?) align + ;; function alignment not supported by MesCC-Tools 0.5.2 + (filter (negate (cut eq? <> 'functions)) align)))) (when verbose? (stderr "dumping: ~a\n" M1-file-name)) (with-output-to-file M1-file-name - (cut infos->M1 M1-file-name infos #:align? align? #:verbose? verbose?)) + (cut infos->M1 M1-file-name infos #:align align #:verbose? verbose?)) M1-file-name)) (define (file->info options file-name) @@ -168,11 +173,16 @@ (options (acons 'compile #t options)) ; ugh (options (acons 'output hex2-file-name options)) (verbose? (count-opt options 'verbose)) - (align? (option-ref options 'align #f))) + (numbered-arch? (option-ref options 'numbered-arch? #f)) + (align (filter-map (multi-opt 'align) options)) + (align (if (null? align) '(functions) (map string->symbol align))) + (align (if (not numbered-arch?) align + ;; function alignment not supported by MesCC-Tools 0.5.2 + (filter (negate (cut eq? <> 'functions)) align)))) (when verbose? (stderr "dumping: ~a\n" M1-file-name)) (with-output-to-file M1-file-name - (cut infos->M1 M1-file-name infos #:align? align?)) + (cut infos->M1 M1-file-name infos #:align align)) (or (M1->hex2 options (list M1-file-name)) (exit 1)))) @@ -362,7 +372,7 @@ (define (arch-get-architecture options) (let* ((arch (arch-get options)) - (numbered-arch? (option-ref options 'numbered-arch? #f)) + (numbered-arch? (option-ref options 'numbered-arch? #f)) (flag (if numbered-arch? "--Architecture" "--architecture"))) (list flag (cond ((equal? arch "arm") (if numbered-arch? "40" "armv7l"))