#include <cctype>
#include <cstdlib>
+void set_scan_file(FILE * F){
+ yy_switch_to_buffer(yy_create_buffer( F, YY_BUF_SIZE ) );
+}
+void set_scan_string (const char * str) {
+ yy_scan_string (str);
+}
+
#define RET_TOK(type, Enum, sym) \
llvmAsmlval.type = Instruction::Enum; return sym
#include "llvm/Assembly/Parser.h"
#include "llvm/ADT/StringExtras.h"
+
// Global variables exported from the lexer...
-extern std::FILE *llvmAsmin;
+
extern int llvmAsmlineno;
+extern std::string &llvmAsmTextin;
+
+// functions exported from the lexer
+void set_scan_file(FILE * F);
+void set_scan_string (const char * str);
+
// Globals exported by the parser...
extern char* llvmAsmtext;
extern int llvmAsmleng;
class Module;
Module *RunVMAsmParser(const std::string &Filename, FILE *F);
+// Parse a string directly
+Module *RunVMAsmParser(const char * AsmString, Module * M);
+
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
// appropriate character. If AllowNull is set to false, a \00 value will cause
}
-//===----------------------------------------------------------------------===//
-// RunVMAsmParser - Define an interface to this parser
-//===----------------------------------------------------------------------===//
-//
-Module *llvm::RunVMAsmParser(const std::string &Filename, FILE *F) {
- llvmAsmin = F;
- CurFilename = Filename;
- llvmAsmlineno = 1; // Reset the current line number...
+// common code from the two 'RunVMAsmParser' functions
+ static Module * RunParser(Module * M) {
- // Allocate a new module to read
- CurModule.CurrentModule = new Module(Filename);
+ llvmAsmlineno = 1; // Reset the current line number...
+ CurModule.CurrentModule = M;
yyparse(); // Parse the file, potentially throwing exception
Module *Result = ParserResult;
-
- llvmAsmin = stdin; // F is about to go away, don't use it anymore...
ParserResult = 0;
return Result;
+
+ }
+
+//===----------------------------------------------------------------------===//
+// RunVMAsmParser - Define an interface to this parser
+//===----------------------------------------------------------------------===//
+//
+Module *llvm::RunVMAsmParser(const std::string &Filename, FILE *F) {
+ set_scan_file(F);
+
+ CurFilename = Filename;
+ return RunParser(new Module(CurFilename));
+}
+
+Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
+ set_scan_string(AsmString);
+
+ CurFilename = "from_memory";
+ if (M == NULL) {
+ return RunParser(new Module (CurFilename));
+ } else {
+ return RunParser(M);
+ }
}
%}