// The types of return expressions shall match the declared // return type of the function. void Elaborator::elaborate(Function_decl* d) { d->type_ = elaborate(d->type_); // Declare the function. stack.declare(d); // Remember if we've seen a function named main(). // // FIXME: Compare symbols, not strings. if (d->name()->spelling() == "main") main = d; // Enter the function scope and declare all // of the parameters (by way of elaboration). // // TODO: Handle failed parameter elaborations. Scope_sentinel scope(*this, d); for (Decl* p : d->parameters()) elaborate(p); // Check the body of the function. elaborate(d->body()); // TODO: Build a control flow graph and ensure that // every branch returns a value. }
// The condition must must be a boolean expression. void Elaborator::elaborate(If_else_stmt* s) { Expr* c = require_converted(*this, s->first, get_boolean_type()); if (!c) throw Type_error({}, "if condition does not have type 'bool'"); elaborate(s->true_branch()); elaborate(s->false_branch()); }
// Elaborate each type in the function type. Type const* Elaborator::elaborate(Function_type const* t) { Type_seq ts; ts.reserve(t->parameter_types().size()); for (Type const* t1 : t->parameter_types()) ts.push_back(elaborate(t1)); Type const* r = elaborate(t->return_type()); return get_function_type(ts, r); }
void Elaborator::elaborate(Block_stmt* s) { Scope_sentinel scope = *this; for (Stmt* s1 : s->statements()) elaborate(s1); }
// Elaborate the module. Returns true if successful and // false otherwise. void Elaborator::elaborate(Module_decl* m) { Scope_sentinel scope(*this, m); for (Decl* d : m->declarations()) elaborate(d); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); createActions(); createMenus(); initDirectories(&dirModel_confs, QStringList("*.xml"), ui->treeView_configs); initDirectories(&dirModel_elabs, QStringList("*.java"), ui->treeView_elaborations); connect(ui->elaborateButton, SIGNAL(clicked()), this, SLOT(elaborate())); ui->elaborateButton->setHidden(true); ui->tabWidget->setHidden(true); ui->treeView_configs->setVisible(true); ui->treeView_configs->setExpandsOnDoubleClick(false); ui->openFolder->setEnabled(false); setAcceptDrops( true); //Drag & Drop setWindowTitle(tr("ELCI (EL Configuration Interface)")); setMinimumSize(300, WIND_HEIGHT); resize(WIND_WIDTH, WIND_HEIGHT); setWindowIcon(QIcon(":/icon.ico")); loadDirectory(); }
bool Compiler::process_file(const Path& path, const Flags& flags) { FlagsManager new_flags(*this, flags); cxx::Backend backend(*this); Path output_path = get_cxx_output_path(flags, path) + "cpp"; std::ofstream output(output_path.c_str()); add_header(output); const SourceFileAst* src = reader()->read_file(path, flags); FormatterContext ctx; for (auto ast : src->asts) { const Expression* expr = elaborate(ast).code(); if (auto imp = is<Import>(expr)) process_import(backend, output, *imp); else if (expr != nullptr) { if (auto tl = backend.translate_top_level(expr)) push_top_level(ctx, tl); } } for (auto x: get_specializations()) { auto decl = specs_to_decl(backend, x); if (auto fundef = dynamic_cast<const cxx::FunDef*>(decl)) ctx.fun_defs.push_back(fundef); else push_decl(ctx, decl); } format_cxx(ctx, output); if (not compile_cxx_file(output_path)) internal_error("intermediate C++ translation failed to compile"); return true; }
static int process_command(int argc, char **argv) { static struct option long_options[] = { { "dump", no_argument, 0, 'd' }, { "codegen", no_argument, 0, 'c' }, { "make", no_argument, 0, 'm' }, { 0, 0, 0, 0 } }; opterr = 0; optind = 1; int index = 0; const char *spec = "aer"; switch (getopt_long(MIN(argc, 2), argv, spec, long_options, &index)) { case 'a': return analyse(argc, argv); case 'e': return elaborate(argc, argv); case 'r': return run(argc, argv); case 'd': return dump_cmd(argc, argv); case 'c': return codegen(argc, argv); case 'm': return make_cmd(argc, argv); default: fatal("missing command, try %s --help for usage", PACKAGE); return EXIT_FAILURE; } }
void Elaborator::elaborate(Record_decl* d) { stack.declare(d); Scope_sentinel scope(*this, d); for (Decl* d1 : d->fields()) elaborate(d1); }
void Elaborator::elaborate(While_stmt* s) { Expr* c = require_converted(*this, s->first, get_boolean_type()); if (!c) throw Type_error({}, "loop condition does not have type 'bool'"); elaborate(s->body()); }
void sc_simcontext::initialize( bool no_crunch ) { m_in_simulator_control = true; elaborate(); prepare_to_simulate(); initial_crunch(no_crunch); m_in_simulator_control = false; }
// The type of the initializer shall match the declared type // of the variable. // // The variable is declared prior to the elaboration of its // initializer. void Elaborator::elaborate(Variable_decl* d) { d->type_ = elaborate(d->type_); // Declare the variable. stack.declare(d); // Elaborate the initializer. Note that the initializers // type must be the same as that of the declaration. elaborate(d->init()); // Annotate the initializer with the declared // object. // // TODO: This will probably be an expression in // the future. cast<Initializer>(d->init())->decl_ = d; }
/** \brief Parse an expression. */ expr parser_imp::parse_expr_main() { try { auto p = elaborate(parse_expr()); check_no_metavar(p, "invalid expression, it still contains metavariables after elaboration"); return p.first; } catch (parser_error & ex) { throw parser_exception(ex.what(), m_strm_name.c_str(), ex.m_pos.first, ex.m_pos.second); } catch (exception & ex) { throw parser_nested_exception(std::shared_ptr<exception>(ex.clone()), std::shared_ptr<pos_info_provider>(new lean_pos_info_provider(m_this.lock(), m_last_cmd_pos))); } }
const uint32_t V3NtkElaborate::elaborateLTLFormula(V3LTLFormula* const ltlFormula, const bool& l2s) { // Make Sure Mapping Tables are Maintained, or NO properties can be proliferated if (!isMutable() || (_ntk && (!_p2cMap.size()))) return V3NtkUD; // Elaborate LTL Formula into Ntk assert (ltlFormula); assert (_handler == ltlFormula->getHandler()); elaborate(ltlFormula); // Create Formula for this Ntk, and Perform LTL Formula Rewriting if Enabled V3LTLFormula* const formula = ltlFormula->createSuccessor(this); // Currently Support ONLY AG(p) and AF(p) const uint32_t rootIndex = formula->getRoot(); assert (!formula->isLeaf(rootIndex)); V3NetId id = elaborateLTLFormula(formula, rootIndex); if (V3NetUD == id) return V3NtkUD; id = (l2s && V3_LTL_T_F == formula->getOpType(rootIndex)) ? elaborateL2S(id) : ~id; // Record LTL Formula and Set to Output _pOutput.push_back(formula); _ntk->createOutput(id); assert (_pOutput.size() == _ntk->getOutputSize()); return _ntk->getOutputSize() - 1; }
Expr* Elaborator::elaborate(Copy_init* e) { // Elaborate the type. e->type_ = elaborate(e->type_); // Convert the value to the resulting type. Expr* c = require_converted(*this, e->first, e->type_); if (!c) { std::stringstream ss; ss << "type mismatch in copy initializer (expected " << e->value() << " but got " << e->value()->type() << ')'; throw Type_error({}, ss.str()); } return e; }
struct inst *elaborate(struct param *context,char *inst_name,struct param *defparams,struct param *pdp,struct module *m,struct expr *connections,struct inst *mom) { struct inst *i=malloc(sizeof(struct inst)); struct inst *j; struct inst *last=0; i->next=0; i->name=strdup(inst_name); i->module=strdup(m->name); i->mod=m; i->insts=0; i->connections=connections; i->decls=0; i->mom=mom; // Copy parameters from module (list of params is its own context). i->params=copy_params(NULL,m->params); // Apply defparams apply_defparams(i->params,inst_name,context,defparams); // Apply positional defparams apply_positional(i->params,context,pdp); // Evaluate parameters simp_params(i->params); // Copy and simplify declarations i->decls=copy_decls(i->params,m->decls); // Recurse for(j=i->mod->insts;j;j=j->next) if(j->mod) { struct inst *q=elaborate(i->params,j->name,m->defparams,j->pos_defparams,j->mod,j->connections,i); if(i->insts) { last->next=q; last=q; } else last=i->insts=q; } return i; }
// In an assignment expression, the left operand shall // refer to a mutable object. The types of the left and // right operands shall match. // // TODO: If we have const types, then we'd have to add this // checking. void Elaborator::elaborate(Assign_stmt* s) { // FIXME: Write a better predicate? Expr* lhs = elaborate(s->object()); if (!is<Reference_type>(lhs->type())) throw Type_error({}, "assignment to rvalue"); // Apply rvalue conversion to the value and update the // expression. Expr *rhs = require_value(*this, s->second); // The types shall match. Compare t1 using the non-reference // type of the object. Type const* t1 = lhs->type()->nonref(); Type const* t2 = rhs->type(); if (t1 != t2) throw Type_error({}, "assignment to an object of a different type"); }
Type const* Elaborator::elaborate(Reference_type const* t) { Type const* t1 = elaborate(t->type()); return get_reference_type(t1); }
int main(int argc, char **argv) { term_init(); set_default_opts(); if (getenv("NVC_GDB") != NULL) register_gdb_signal_handlers(); else register_trace_signal_handlers(); atexit(fbuf_cleanup); static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "work", required_argument, 0, 'w' }, { "dump", no_argument, 0, 'd' }, { "codegen", no_argument, 0, 'c' }, { "make", no_argument, 0, 'm' }, { "std", required_argument, 0, 's' }, { 0, 0, 0, 0 } }; int c, index = 0; const char *spec = "aehrvL:"; while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) { switch (c) { case 0: // Set a flag break; case 'h': usage(); exit(EXIT_SUCCESS); case 'v': printf("%s\n%s\n", version_string, copy_string); exit(EXIT_SUCCESS); case 'w': opt_set_str("work-name", optarg); break; case 'L': lib_add_search_path(optarg); break; case 's': set_standard(parse_standard(optarg)); break; case 'a': case 'e': case 'd': case 'r': case 'c': case 'm': // Subcommand options are parsed later argc -= (optind - 1); argv += (optind - 1); goto getopt_out; case '?': // getopt_long already printed an error message exit(EXIT_FAILURE); default: abort(); } } getopt_out: switch (c) { case 'a': return analyse(argc, argv); case 'e': return elaborate(argc, argv); case 'r': return run(argc, argv); case 'd': return dump_cmd(argc, argv); case 'c': return codegen(argc, argv); case 'm': return make_cmd(argc, argv); default: fprintf(stderr, "%s: missing command\n", PACKAGE); return EXIT_FAILURE; } }
// TODO: I probably need to elaborate the type. Expr* Elaborator::elaborate(Default_init* e) { e->type_ = elaborate(e->type_); return e; }
Control Evaluator::evaluate_declaration(Declaration_stmt const& s, Value& r) { elaborate(s.declaration()); return next_ctl; }
void Elaborator::elaborate(Declaration_stmt* s) { elaborate(s->declaration()); }
void Elaborator::elaborate(Expression_stmt* s) { elaborate(s->expression()); }
// Elaborate a parameter declaration. This simply declares // the parameter in the current scope. void Elaborator::elaborate(Parameter_decl* d) { d->type_ = elaborate(d->type_); stack.declare(d); }
void Elaborator::elaborate(Field_decl* d) { d->type_ = elaborate(d->type_); stack.declare(d); }