Skip to content

Commit

Permalink
llvm: Improve bitcode writer method dispatch
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
housel committed Jun 20, 2024
1 parent def1232 commit ed83ddc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions sources/lib/llvm/bitcode.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,15 @@ end bitcode-block;
define method stream-record-id
(stream :: <bitcode-stream>, record :: <symbol>)
=> (id :: <integer>)
let record-definition = element(stream.bitcode-records, record, default: #f);
if (~record-definition)
let record-definition :: false-or(<bitcode-record-definition>)
= 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 <abbrev-op> (<object>)
Expand Down Expand Up @@ -493,7 +494,8 @@ end method;
define method write-abbrev-record
(stream :: <bitcode-stream>, name :: <symbol>, #rest operands)
=> ();
let definition = stream.bitcode-abbrev-definitions[name];
let definition :: <bitcode-abbrev-definition>
= stream.bitcode-abbrev-definitions[name];

// Output the abbreviation id
write-abbrev-id(stream, definition.abbrev-id);
Expand All @@ -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 :: <abbrev-op> = ops[op-index];
select (op.op-kind)
#"fixed" =>
write-fixed(stream, op.op-data, value);
Expand All @@ -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 :: <abbrev-op> = ops[op-index + 1];
select (aop.op-kind)
#"fixed" =>
do(curry(write-fixed, stream, aop.op-data), value);
Expand Down
2 changes: 1 addition & 1 deletion sources/lib/llvm/llvm-bitcode.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ define function write-module
write-record(stream, #"GCNAME", gc-name);
end if;
end method;
for (global :: <llvm-global-value> in m.llvm-module-functions)
for (global :: <llvm-function> in m.llvm-module-functions)
if (global.llvm-function-garbage-collector)
do-gc(global.llvm-function-garbage-collector);
end if;
Expand Down

0 comments on commit ed83ddc

Please sign in to comment.