From ed83ddcc36bc2e4d35a14600590e3810d1b3c803 Mon Sep 17 00:00:00 2001 From: "Peter S. Housel" Date: Mon, 17 Jun 2024 21:59:18 -0700 Subject: [PATCH] llvm: Improve bitcode writer method dispatch * sources/lib/llvm/llvm-bitcode.dylan (write-module): Declare the proper type of llvm-module-functions elements. * sources/lib/llvm/bitcode.dylan (stream-record-id): Add type declarations for bitcode-records elements. (write-abbrev-record): Add type declarations for bitcode-abbrev-definitions entries and abbrev-ops elements. --- sources/lib/llvm/bitcode.dylan | 18 ++++++++++-------- sources/lib/llvm/llvm-bitcode.dylan | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sources/lib/llvm/bitcode.dylan b/sources/lib/llvm/bitcode.dylan index 6b4d69cc8..67b4b2830 100644 --- a/sources/lib/llvm/bitcode.dylan +++ b/sources/lib/llvm/bitcode.dylan @@ -348,14 +348,15 @@ end bitcode-block; define method stream-record-id (stream :: , record :: ) => (id :: ) - let record-definition = element(stream.bitcode-records, record, default: #f); - if (~record-definition) + let record-definition :: false-or() + = element(stream.bitcode-records, record, default: #f); + if (record-definition) + record-definition.record-id + else error("record %= not defined for this block type", record); - end if; - record-definition.record-id + end if end method; - /// Abbreviations define class () @@ -493,7 +494,8 @@ end method; define method write-abbrev-record (stream :: , name :: , #rest operands) => (); - let definition = stream.bitcode-abbrev-definitions[name]; + let definition :: + = stream.bitcode-abbrev-definitions[name]; // Output the abbreviation id write-abbrev-id(stream, definition.abbrev-id); @@ -503,7 +505,7 @@ define method write-abbrev-record for (value in operands, op-index = 0 then begin - let op = ops[op-index]; + let op :: = ops[op-index]; select (op.op-kind) #"fixed" => write-fixed(stream, op.op-data, value); @@ -513,7 +515,7 @@ define method write-abbrev-record op-index + 1; #"array" => write-vbr(stream, 6, value.size); - let aop = ops[op-index + 1]; + let aop :: = ops[op-index + 1]; select (aop.op-kind) #"fixed" => do(curry(write-fixed, stream, aop.op-data), value); diff --git a/sources/lib/llvm/llvm-bitcode.dylan b/sources/lib/llvm/llvm-bitcode.dylan index a9a925fc3..0d7d9e1af 100644 --- a/sources/lib/llvm/llvm-bitcode.dylan +++ b/sources/lib/llvm/llvm-bitcode.dylan @@ -2823,7 +2823,7 @@ define function write-module write-record(stream, #"GCNAME", gc-name); end if; end method; - for (global :: in m.llvm-module-functions) + for (global :: in m.llvm-module-functions) if (global.llvm-function-garbage-collector) do-gc(global.llvm-function-garbage-collector); end if;