Skip to content

Commit

Permalink
Merge pull request #1469 from housel/bitcode-2022
Browse files Browse the repository at this point in the history
Bitcode fixes and improvements
  • Loading branch information
housel committed Jan 2, 2023
2 parents 5603ebe + 4913855 commit d2685b1
Show file tree
Hide file tree
Showing 3 changed files with 295 additions and 265 deletions.
1 change: 1 addition & 0 deletions sources/common-dylan/darwin-common-extensions-helper.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <limits.h>
#include <mach-o/dyld.h>
#include <stdlib.h>
#include <string.h>

extern void *MMAllocMisc(size_t size);
extern void MMFreeMisc(void *p, size_t size);
Expand Down
47 changes: 38 additions & 9 deletions sources/lib/llvm/bitcode.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,14 @@ end method;
define method write-record
(stream :: <bitcode-stream>, record :: <symbol>, #rest operands)
=> ();
// Output the unabbreviated record code
write-abbrev-id(stream, $ABBREV-UNABBREV-RECORD);

// Output the record code
write-vbr(stream, 6, stream-record-id(stream, record));

// Output the total number of arguments
let operand-count
let operand-count :: <integer>
= operands.size
+ if (~empty?(operands) & instance?(operands.last, <sequence>))
operands.last.size - 1
else
0
end if;
write-vbr(stream, 6, operand-count);
write-record-head(stream, record, operand-count);

// Output the arguments
for (operand in operands)
Expand All @@ -482,6 +475,19 @@ define method write-record
end for;
end method;

define method write-record-head
(stream :: <bitcode-stream>, record :: <symbol>, count :: <integer>)
=> ();
// Output the unabbreviated record code
write-abbrev-id(stream, $ABBREV-UNABBREV-RECORD);

// Output the record code
write-vbr(stream, 6, stream-record-id(stream, record));

// Output the total number of arguments
write-vbr(stream, 6, count);
end method;

define method write-abbrev-record
(stream :: <bitcode-stream>, name :: <symbol>, #rest operands)
=> ();
Expand Down Expand Up @@ -525,3 +531,26 @@ define method write-abbrev-record
end)
end for;
end method;

define macro write-record*
{ write-record*(?stream:expression, ?record:expression, ?operands:*) }
=> { let stream = ?stream;
write-record-head(stream, ?record, %count-operands(?operands));
%write-operands(stream, ?operands); }
end macro;

define macro %count-operands
{ %count-operands() }
=> { 0 }
{ %count-operands(?operand:*, ?rest:*) }
=> { 1 + %count-operands(?rest) }
end macro;

define macro %write-operands
{ %write-operands(?stream:expression) }
=> { }
{ %write-operands(?stream:expression, ?operand:expression, ?rest:*) }
=> { write-vbr(?stream, 6, ?operand);
%write-operands(?stream, ?rest); }
end macro;

0 comments on commit d2685b1

Please sign in to comment.