Exemple #1
0
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by `codegen/create_gen_op.py`
//! Maps genop table from Erlang/OTP source to Rust
//! Config used: {otp}
#![allow(dead_code)]

use rt_defs::Word;
use emulator::code::opcode::RawOpcode;


pub const OPCODE_MAX: RawOpcode = {op_max};
""".format(op_max=conf.max_opcode, otp=conf.__class__.__name__))

    # print arity map
    print("pub static ARITY_MAP: &'static [RawOpcode] = &[\n"
          "    0, // opcode 0 does not exist")
    for opcode in range(conf.min_opcode, conf.max_opcode + 1):
        op = tables.ops[opcode]
        print("    %d, // opcode: %d (%s)" % (op.arity, opcode, op.name))
    print("""\
];

#[inline]
pub fn opcode_arity(opcode: RawOpcode) -> u8 {
  ARITY_MAP[opcode as usize]
}
""")

    #
    # ------ print opcode names map ------
    #

    # print("#[cfg(debug)]")
    print("""const OPCODE_NAME_MAP: &[&str] = &[
        \"\", // opcode 0 does not exist""")
    for opcode in range(conf.min_opcode, conf.max_opcode + 1):
        op = tables.ops[opcode]
        print("    \"%s\", // opcode: %d" % (op.name, opcode))
    print("""\
];

pub fn opcode_name(opcode: RawOpcode) -> &'static str {
  OPCODE_NAME_MAP[opcode as Word]
}
""")

    #
    # ------ print opcode enum ------
    #

    for opcode in range(conf.min_opcode, conf.max_opcode + 1):
        op = tables.ops[opcode]
        print("pub const OPCODE_%s: RawOpcode = %d;"
              % (op.name.upper(), opcode))
    print("\n")
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by codegen/create_gen_atoms.py
//! Creates array of predefined atoms
//! Config used: {otp} 
#![allow(dead_code)]

use term::immediate;
use term::lterm::LTerm;

""".format(otp=conf.__class__.__name__))

    all_atoms = []
    uniq_atoms = set()
    i = 0

    for a in tables.atom_tab:
        a_name = a.text
        if a_name in uniq_atoms:
            continue
        uniq_atoms.add(a_name)
        all_atoms.append(
            AddAtom(atom=a_name, cname=genop.enum_name(a_name), atom_id=i))
        i += 1

    for a in tables.bif_tab:
        a_name = a.atom
        if a_name in uniq_atoms:
            continue
        uniq_atoms.add(a_name)
        all_atoms.append(
            AddAtom(atom=a_name,
                    cname=genop.enum_name(a.cname).upper(),
                    atom_id=i))
        i += 1

    #
    # Print convenient atom constants
    #
    for a in all_atoms:
        print("pub const {cname}: LTerm = LTerm {{ "
              "value: immediate::make_atom_raw_const({index}) }};"
              "".format(cname=a.cname, index=a.atom_id))

    #
    # Print initialization vector
    #
    print("\npub static ATOM_INIT_NAMES: &'static [&'static str] = &[")
    for a in all_atoms:
        print('  "{atext}", // id={aid}'.format(atext=a.atom, aid=a.atom_id))
    print("];")
Exemple #3
0
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by `codegen/create_gen_atoms.py`
//! Creates array of predefined atoms
//! Config used: {otp}
#![allow(dead_code)]

use term::immediate::{{make_atom_raw_const}};
use term::lterm::*;

""".format(otp=conf.__class__.__name__))

    # all_atoms = []  # type: Dict[str, genop.Atom]
    # uniq_atoms = set()

    #
    # Print convenient atom constants
    #
    atom_keys = list(tables.atom_dict.keys())
    atom_keys.sort()

    i = 0
    for akey in atom_keys:
        a = tables.atom_dict[akey]
        print("pub const {cname}: LTerm = LTerm {{ "
              "value: make_atom_raw_const({index}) }};"
              "".format(cname=a.cname, index=i))
        i += 1

    #
    # Print initialization vector
    #
    i = 0
    print("\npub static ATOM_INIT_NAMES: &'static [&'static str] = &[")
    for akey in atom_keys:
        a = tables.atom_dict[akey]
        print('  "{atext}", // id={aid}'.format(atext=a.text, aid=i))
        i += 1

    print("];")
Exemple #4
0
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by `codegen/create_gen_bif.py`
//! Creates a lookup table of BIF functions
//! Config used: {otp} 
#![allow(dead_code)]

use rt_defs::Arity;
use emulator::gen_atoms;
use term::lterm::*;
use bif;


pub struct BifTabItem {{
    pub m: LTerm, 
    pub f: LTerm, 
    pub arity: Arity, 
    pub func: bif::BifFn
}}


pub static BIF_TABLE: &'static [BifTabItem] = &[
""".format(otp=conf.__class__.__name__))

    for bif in tables.bif_tab:
        fun_atom = tables.atom_dict[bif.atom_str]  # type: genop.Atom
        print("    BifTabItem {{ m: gen_atoms::{mod}, "
              "f: gen_atoms::{fun}, arity: {arity},"
              "\n        func: bif::{biftype}_{fun_name}_{arity} }},"
              "".format(cname=bif.cname,
                        mod=genop.enum_name(bif.mod).upper(),
                        fun=fun_atom.cname.upper(),
                        fun_name=genop.c_fun_name(bif.cname),
                        biftype=bif.biftype,
                        arity=bif.arity))

    print("];\n")
Exemple #5
0
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by codegen/create_gen_bif.py
//! Creates a lookup table of BIF functions
//! Config used: {otp} 
#![allow(dead_code)]

use term::immediate;
use term::lterm::LTerm;
use emulator::funarity::FunArity;

""".format(otp=conf.__class__.__name__))

    print("pub static BIF_MAP: HashMap<LTerm, Vec<FunArity>> = &[\n")

    for a in tables.atom_tab:
        print("pub const {name}: LTerm = LTerm {{ "
              "value: immediate::make_atom_raw_const({index}) }};"
              "".format(name=a.cname, index=a.id))
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by `codegen/create_vm_dispatch.py`
//! Dispatch for all opcode types.
//! Config used: {otp}
#![allow(dead_code)]

use emulator::vm::VM;
use beam::gen_op;
use beam::opcodes::*;
use beam::disp_result::{{DispatchResult}};
use emulator::code::opcode::RawOpcode;
use emulator::process::Process;
use emulator::runtime_ctx::Context;


#[inline]
pub fn dispatch_op_inline(vm: &VM, op: RawOpcode, ctx: &mut Context, \
curr_p: &mut Process) -> DispatchResult {{
  match op {{""".format(op_max=conf.max_opcode, otp=conf.__class__.__name__))

    for opcode in range(conf.min_opcode, conf.max_opcode + 1):
        op = tables.ops[opcode]
        if op.name in tables.implemented_ops:
            print("    gen_op::OPCODE_{opcode} => "
                  "return opcode_{lowercase}(vm, ctx, curr_p),"
                  "".format(opcode=op.name.upper(), lowercase=op.name))

    print("""\
    other => unknown_opcode(other, ctx),
  }
  DispatchResult::Yield
}
""")
def main():
    conf = genop.OTP20()
    tables = genop.OTPTables(conf)

    print("""\
//! Generated by codegen/create_vm_dispatch.py
//! Dispatch for all opcode types.
//! Config used: {otp} 
#![allow(dead_code)]

use beam::gen_op;
use beam::opcodes::*;
use defs::{{Word, DispatchResult}};
use emulator::code::opcode::RawOpcode;
use emulator::heap::Heap;
use emulator::runtime_ctx::Context;


#[inline(always)]
pub fn dispatch_op_inline(op: RawOpcode, ctx: &mut Context, \
heap: &mut Heap) -> DispatchResult {{
  match op {{
""".format(op_max=conf.max_opcode, otp=conf.__class__.__name__))

    for opcode in range(conf.min_opcode, conf.max_opcode + 1):
        op = tables.ops[opcode]
        if op.name in tables.implemented_ops:
            print("    gen_op::OPCODE_{opcode} => "
                  "{{ return opcode_{lowercase}(ctx, heap) }},"
                  "".format(opcode=op.name.upper(), lowercase=op.name))

    print("""\
    other => unknown_opcode(other, ctx),   
  }
  DispatchResult::Yield
}
""")