00001 //
00002 // -------------------------------------------------------------
00003 // Copyright 2004-2008 Synopsys, Inc.
00004 // All Rights Reserved Worldwide
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the
00007 // "License"); you may not use this file except in
00008 // compliance with the License. You may obtain a copy of
00009 // the License at
00010 //
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 //
00013 // Unless required by applicable law or agreed to in
00014 // writing, software distributed under the License is
00015 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00016 // CONDITIONS OF ANY KIND, either express or implied. See
00017 // the License for the specific language governing
00018 // permissions and limitations under the License.
00019 // -------------------------------------------------------------
00020 //
00021
00022
00023 `ifndef VMM_SQL_DB_ASCII__SV
00024 `define VMM_SQL_DB_ASCII__SV
00025
00026
00027 class vmm_sql_db_ascii extends vmm_sql_db;
00028
00029 local bit last_failed;
00030 local int fp;
00031
00032 extern function new(string dbname,
00033 bit append = 0);
00034 extern virtual function int status();
00035 extern virtual function int statement(string sql_stmt);
00036 extern virtual function void close();
00037
00038 // Return an ID that is unique in the DB
00039 extern local virtual function int get_unique_id();
00040 endclass: vmm_sql_db_ascii
00041
00042 //------------------------------------------------------------------
00043 //
00044 // Implementation
00045 //
00046
00047 function vmm_sql_db_ascii::new(string dbname,
00048 bit append);
00049 string expanded_name;
00050
00051 super.new();
00052
00053 expanded_name = Xexpand_nameX(dbname);
00054 this.last_failed = 0;
00055 this.log = new("SQLdb", expanded_name);
00056 this.fp = $fopen(expanded_name, (append) ? "a" : "w");
00057 if (!this.fp) begin
00058 `vmm_error(this.log, {"Unable to open ", expanded_name, " for writing."});
00059 this.last_failed = 1;
00060 end else begin
00061 Xcreate_system_tablesX();
00062 end
00063 endfunction: new
00064
00065 function int vmm_sql_db_ascii::status();
00066 return(this.last_failed);
00067 endfunction: status
00068
00069 function int vmm_sql_db_ascii::statement(string sql_stmt);
00070 if (!this.fp) begin
00071 `vmm_error(this.log,
00072 {"File ",
00073 this.log.get_instance(),
00074 " not open for writing."});
00075 this.last_failed = 1;
00076 end else begin
00077 $fwrite(this.fp, "%s\n", sql_stmt);
00078 this.last_failed = 0;
00079 end
00080 return(this.last_failed);
00081 endfunction: statement
00082
00083 function void vmm_sql_db_ascii::close();
00084 $fclose(this.fp);
00085 endfunction: close
00086
00087
00088 function int vmm_sql_db_ascii::get_unique_id();
00089 return $ftell(this.fp);
00090 endfunction: get_unique_id
00091
00092 `endif