-
-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement packed structures (RFC 32)
This change adds program annotations allowing programmers to declare packed structures, i.e. structures without implementation-specific padding between members. Closes #1523.
- Loading branch information
Benoit Vey
committed
Jan 26, 2017
1 parent
9739cad
commit 2fdbd13
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <gtest/gtest.h> | ||
#include <platform.h> | ||
|
||
#include <reach/reach.h> | ||
|
||
#include "util.h" | ||
|
||
|
||
#define TEST_COMPILE(src) DO(test_compile(src, "ir")) | ||
|
||
|
||
class CodegenTest : public PassTest | ||
{}; | ||
|
||
|
||
TEST_F(CodegenTest, PackedStructIsPacked) | ||
{ | ||
const char* src = | ||
"struct \\packed\\ Foo\n" | ||
" var a: U8 = 0\n" | ||
" var b: U32 = 0\n" | ||
|
||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" Foo"; | ||
|
||
TEST_COMPILE(src); | ||
|
||
reach_t* reach = compile->reach; | ||
reach_type_t* foo = reach_type_name(reach, "Foo"); | ||
ASSERT_TRUE(foo != NULL); | ||
|
||
LLVMTypeRef type = foo->structure; | ||
ASSERT_TRUE(LLVMIsPackedStruct(type)); | ||
} | ||
|
||
|
||
TEST_F(CodegenTest, NonPackedStructIsntPacked) | ||
{ | ||
const char* src = | ||
"struct Foo\n" | ||
" var a: U8 = 0\n" | ||
" var b: U32 = 0\n" | ||
|
||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" Foo"; | ||
|
||
TEST_COMPILE(src); | ||
|
||
reach_t* reach = compile->reach; | ||
reach_type_t* foo = reach_type_name(reach, "Foo"); | ||
ASSERT_TRUE(foo != NULL); | ||
|
||
LLVMTypeRef type = foo->structure; | ||
ASSERT_TRUE(!LLVMIsPackedStruct(type)); | ||
} | ||
|
||
|
||
TEST_F(CodegenTest, ClassCannotBePacked) | ||
{ | ||
const char* src = | ||
"class \\packed\\ Foo\n" | ||
" var a: U8 = 0\n" | ||
" var b: U32 = 0\n" | ||
|
||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" Foo"; | ||
|
||
TEST_COMPILE(src); | ||
|
||
reach_t* reach = compile->reach; | ||
reach_type_t* foo = reach_type_name(reach, "Foo"); | ||
ASSERT_TRUE(foo != NULL); | ||
|
||
LLVMTypeRef type = foo->structure; | ||
ASSERT_TRUE(!LLVMIsPackedStruct(type)); | ||
} | ||
|
||
|
||
TEST_F(CodegenTest, ActorCannotBePacked) | ||
{ | ||
const char* src = | ||
"actor \\packed\\ Foo\n" | ||
" var a: U8 = 0\n" | ||
" var b: U32 = 0\n" | ||
|
||
"actor Main\n" | ||
" new create(env: Env) =>\n" | ||
" Foo"; | ||
|
||
TEST_COMPILE(src); | ||
|
||
reach_t* reach = compile->reach; | ||
reach_type_t* foo = reach_type_name(reach, "Foo"); | ||
ASSERT_TRUE(foo != NULL); | ||
|
||
LLVMTypeRef type = foo->structure; | ||
ASSERT_TRUE(!LLVMIsPackedStruct(type)); | ||
} |