示例#1
0
int main(){
	printf("******* INTIATING COMPILER ***********\n");
	//printf("Choose Relevant stage of compiler:\n");
	//printf("1. Lexical Analysis\n");
	//printf("2. Parsing\n");
	//printf("3. Semantic Analysis\n");
	//printf("4. Code Generation\n");
	
	int choice,i;
	char c;
	if(1){
		
		hashTable* T = build_hash();   	        // build the hash table to maintain state of tokens
		printStoreHash(T); 			// store hashTable in a file
		Dnode* DFA = buildDFA();
		memset(LexicalUnits,'\0',sizeof(LexicalUnits));

		lexerCode(DFA,T,LexicalUnits,tokenValue,line);
		printf("\nLexer tokens have been generated in Lexer Tokens.txt\n");
		pnode* root=NULL;
		root=parse(LexicalUnits,tokenValue,line);
		printf("\nParse tree generated in parseTree.txt\n");
		pnode* ast=getAST(root);
		printf("\nAbstarct Syntax Tree Generated in AbstractSyntaxTree.txt\n");
		Master *sym = (Master*)malloc(sizeof (Master)); 
		getSymbolTable(sym,ast);
		printf("\nSymbol Table Generated in symbolTable.txt\n");
		GenerateCode(sym,ast);
		printf("\nCode Generation Successfull\n\n");
	} 
	return 0;

}
示例#2
0
文件: main.cpp 项目: Raekye/hmmm
void run_code(const char* code) {
	NExpression* root_expr = getAST(code);
	if (root_expr == NULL) {
		std::cout << "Root expression was null! Ahhhhhhhhhhhhh!" << std::endl;
		return;
	}

	std::string error_str;
	llvm::Module* module = new llvm::Module("top", llvm::getGlobalContext());
	llvm::ExecutionEngine* execution_engine = llvm::EngineBuilder(module).setErrorStr(&error_str).setEngineKind(llvm::EngineKind::JIT).create();
	CodeGen code_gen(module);

	std::cout << "execution engine " << execution_engine << std::endl;
	if (execution_engine == NULL) {
		std::cout << "Unable to create execution engine." << std::endl;
		return;
	}

	NFunction main_fn(root_expr, NType::int_ty());

	// llvm::Value* root_val = root_expr->gen_code(&code_gen);

	// std::cout << "Root val code:" << std::endl;
	// root_val->dump();

	llvm::Function* main_fn_val = (llvm::Function*) main_fn.gen_code(&code_gen);
	std::cout << "Main fn code:" << std::endl;
	main_fn_val->dump();
	void* fn_ptr = execution_engine->getPointerToFunction(main_fn_val);
	int32_t (*fn_ptr_native)() = (int32_t (*)()) fn_ptr;
	int32_t ret = fn_ptr_native();
	std::cout << "Main fn at " << fn_ptr << "; executed: " << ret << std::endl;
}
示例#3
0
void MallocState::print(llvm::raw_ostream &Out,
                        seec::util::IndentationGuide &Indentation) const
{
  std::string AddressString;
  
  {
    llvm::raw_string_ostream AddressStringStream(AddressString);
    seec::util::write_hex_padded(AddressStringStream, this->getAddress());
  }
  
  auto const LazyDescription =
    seec::LazyMessageByRef::create("SeeCClang",
                                   {"states", "MallocState"},
                                   std::make_pair("size",
                                                  int64_t(this->getSize())),
                                   std::make_pair("address",
                                                  AddressString.c_str()));
  
  UErrorCode ICUStatus = U_ZERO_ERROR;
  auto const Description = LazyDescription->get(ICUStatus, Locale());
  
  if (U_FAILURE(ICUStatus))
    return;
  
  Out << Indentation.getString() << Description << "\n";
  
  auto const Mapping = this->getAllocatorInstMapping();
  if (auto const Stmt = Mapping.getStmt()) {
    Indentation.indent();
    
    auto const &AST = Mapping.getAST()->getASTUnit();
    auto const &SrcManager = AST.getSourceManager();
    
    auto const LocStart = Stmt->getLocStart();
    auto const Filename = SrcManager.getFilename(LocStart);
    auto const Line = SrcManager.getSpellingLineNumber(LocStart);
    auto const Column = SrcManager.getSpellingColumnNumber(LocStart);
    
    auto const LazyLocation =
      seec::LazyMessageByRef::create("SeeCClang",
                                     {"states", "MallocStateAllocatedAt"},
                                     std::make_pair("filename",
                                                    Filename.str().c_str()),
                                     std::make_pair("line", int64_t(Line)),
                                     std::make_pair("column", int64_t(Column)));
    
    auto const Location = LazyLocation->get(ICUStatus, Locale());
    
    if (U_SUCCESS(ICUStatus))
      Out << Indentation.getString() << Location << "\n";
    
    Indentation.unindent();
  }
}
示例#4
0
int
main (int argc, char** argv)
{
  while (gets (in))
    {
      ltl_formula *formula = getAST(in);
      print_formula(formula);
      puts("");
      destroy_formula(formula);
    }

  return (EXIT_SUCCESS);
}
示例#5
0
int main(void)
{
    std::string str;

    getFileContents(str, "test.d");

//    yydebug = 1;

    ModuleNode* e;
    e = getAST(str.c_str());
    if (!e)
    {
        std::cerr << "MainError" << std::endl;
        exit(1);
    }

    std::cout << *e << std::endl;

    return 0;
}