Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitcode fixes and improvements #1469

Merged
merged 3 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn’t recognize this was an integer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't recall if this was needed, or if it was just for documentation purposes.

= 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;