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

Fail to write global variable #12

Closed
eecheng87 opened this issue Oct 13, 2020 · 1 comment
Closed

Fail to write global variable #12

eecheng87 opened this issue Oct 13, 2020 · 1 comment

Comments

@eecheng87
Copy link
Collaborator

Hi, I am trying to add feature: global variable initialization.
I modify some code and it seems good when I dump IR, following is simple sample

...
0x000122d4         x1 := 44
0x000122d8         x0 = &a
0x000122e0         *x0 = x1 (4)
0x000122e4     main:
0x000122fc         {
0x000122fc             x0 := &data[36]
0x00012304             x1 = &a
0x0001230c             x1 = *x1 (4)
0x00012310             x0 := printf() @ 978
0x00012314             x0 := 0
0x00012318             return (from main)
0x0001231c         }
0x0001231c         exit main

corresponding C code

int a = 44;
int main(int argc, char *argv[])
{
    printf("%d\n", a);
    return 0;
}

As I mention, it seems good for assigning initial value to a in IR, but the value printed is 0. This weird stuff stuck me a few day. Anything I ignore about writing value to global variable? Thanks!

@jserv
Copy link
Collaborator

jserv commented Oct 14, 2020

It is a known issue that global variable initialization is not supported. Therefore, you can not initialize a global such as int i = [expr]. In order to resolve this issue, we have to implement a pointer to bss/data section in code generation.

eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 14, 2020
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 15, 2020
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 15, 2020
Close sysprog21#12

Change test bench

Support global expression for initialization
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 16, 2020
Close sysprog21#12

Change test bench

Support global expression for initialization

Pass code review
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 16, 2020
Close sysprog21#12

Change test bench

Support global expression for initialization

Pass code review

Change for code review
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 16, 2020
Close sysprog21#12

1. To initialize global variable, we need to decide the value before
   execution time. `read_global_assignment` help us evaluate this
   immediate value and store it in .data section where store the
   initial value of variable in generated ELF.

2. This commit doesn't support pointer and array initialization.

3. Add correspond test bench in line 250 of driver.sh.
eecheng87 added a commit to eecheng87/shecc that referenced this issue Oct 16, 2020
Close sysprog21#12

1. To initialize global variable, we need to decide the value before
   execution time. `read_global_assignment` help us evaluate this
   immediate value and store it in .data section where store the
   initial value of variable in generated ELF.

2. This commit doesn't support pointer and array initialization.

3. Add global initialization item in test driver.
@jserv jserv closed this as completed in 12a38bc Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants