ejrgilbert / whamm

5 stars 2 forks source link

print global stmts #69

Closed ahuoguo closed 1 week ago

ahuoguo commented 1 week ago

deals with #66

@wavid-b can you check the output for test_global_stmts? The script

        i32 a;
        a = 1;
        dummy_fn() {
            a = strcmp((arg0, arg1), "bookings");
            strcmp((arg0, arg1), "bookings");
        }
        BEGIN{
            strcmp((arg0, arg1), "bookings");
        }
        a = 10;
        END {
            a = 2;
        }

Gives me the following AST:

---- parser::tests::test_global_stmts stdout ----
Whamm functions:
-- strcmp (str_addr: (int, int), value: str) -> bool {
-- }

Scripts:
-- `script0`:
---- user defined functions:
------ dummy_fn () -> () {
-------- a = strcmp((arg0, arg1), "bookings");
-------- strcmp((arg0, arg1), "bookings");
-------- return ();
------ }

---- script global statements:
------ a = 10;
---- script providers:
------ `whamm` {
-------- packages:
---------- `` {
------------ package events:
-------------- `` {
---------------- event probe_map:
------------------ begin: (
------------------ `BEGIN` probe {
-------------------- `predicate`:
---------------------- / None /
-------------------- `body`:
---------------------- strcmp((arg0, arg1), "bookings");
------------------ }
------------------ `BEGIN` probe {
-------------------- `predicate`:
---------------------- / None /
-------------------- `body`:
---------------------- a = 2;
------------------ }
)
-------------- }
---------- }
------ }

I also have a question on

pub struct Script {
    pub name: String,
    /// The providers of the probes that have been used in the Script.
    pub providers: HashMap<String, Provider>,
    pub fns: Vec<Fn>,                     // User-provided
    pub globals: HashMap<String, Global>, // User-provided, should be VarId
    pub global_stmts: Vec<Statement>,
}

What does user-provided global means? What is the different between globals and global_stmts? Since declaring a global in front of script is Statement::Decl

ahuoguo commented 1 week ago

Now: https://github.com/wavid-b/whamm/pull/5